Skip to content

Commit

Permalink
Add SET /ERASE as a way to clear the environment block
Browse files Browse the repository at this point in the history
  • Loading branch information
joncampbell123 committed Aug 11, 2024
1 parent bf5400c commit b3e0e4c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
NEXT
- SET command processing has been cleaned up and streamlined.
Added /ERASE command line switch to clear the environment
block (DOSBox-X extension). (joncampbell123).
- VESA BIOS: Add new option to adjust reported linear framebuffer
address by a specific number of pixels. This is needed by
"Out of Control" by Contract which for whatever reason,
Expand Down
1 change: 1 addition & 0 deletions include/programs.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Program {
bool GetEnvNum(Bitu want_num,std::string & result); //! Return an environment variable by index
Bitu GetEnvCount(void); //! Return the number of environmental variables
bool SetEnv(const char * entry,const char * new_string); //! Set environment variable
bool EraseEnv(void);
virtual void WriteOut(const char *format, const char * arguments);
void WriteOut(const char * format,...); //! Write to standard output
virtual int WriteOut_NoParsing(const char * format, bool dbcs = false); //! Write to standard output, no parsing
Expand Down
20 changes: 20 additions & 0 deletions src/misc/programs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,26 @@ void Program::DebugDumpEnv() {
}
}

bool Program::EraseEnv(void) {
PhysPt env_base,env_fence;
size_t nsl = 0,el = 0,needs;

if (dos_kernel_disabled) {
LOG_MSG("BUG: Program::EraseEnv() called with DOS kernel disabled (such as OS boot).\n");
return false;
}

if (!LocateEnvironmentBlock(env_base,env_fence,psp->GetEnvironment())) {
LOG_MSG("Warning: SetEnv() was not able to locate the program's environment block\n");
return false;
}

for (PhysPt w=env_base;w < env_fence;w++)
mem_writeb(w,0);

return true;
}

/* NTS: "entry" string must have already been converted to uppercase */
bool Program::SetEnv(const char * entry,const char * new_string) {
PhysPt env_base,env_fence,env_scan;
Expand Down
10 changes: 9 additions & 1 deletion src/shell/shell_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,8 @@ void DOS_Shell::CMD_SET(char * args) {
enum op_mode_t {
show_all_env,
set_env,
show_env
show_env,
erase_env
};

op_mode_t op_mode = show_all_env;
Expand All @@ -2753,6 +2754,9 @@ void DOS_Shell::CMD_SET(char * args) {
WriteOut("Set /P is not supported. Use Choice!"); /* TODO: What is SET /P supposed to do? */
return;
}
else if (sw == "ERASE") { /* DOSBox-X extension: Completely erase the environment block */
op_mode = erase_env;
}
else {
WriteOut("Unknown switch /");
WriteOut(sw.c_str());
Expand Down Expand Up @@ -2806,6 +2810,10 @@ void DOS_Shell::CMD_SET(char * args) {
WriteOut(MSG_Get("SHELL_CMD_SET_OUT_OF_SPACE"));

break;
case erase_env:
if (!EraseEnv())
WriteOut("Unable to erase environment block\n");
break;
default:
abort();
break;
Expand Down

0 comments on commit b3e0e4c

Please sign in to comment.