From bec0e798901bd86168d39a8f62c32a41cbcc3a5e Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Sat, 20 Apr 2019 13:55:35 +0000 Subject: [PATCH] Don't remove bytes from autoexec.bat when changing settings from autoexec.bat, but replace them instead. This way the location stays valid. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4212 --- src/shell/shell.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index aff8045e..88691abb 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -125,21 +125,29 @@ AutoexecObject::~AutoexecObject(){ // Remove the line from the autoexecbuffer and update environment for(auto_it it = autoexec_strings.begin(); it != autoexec_strings.end(); ) { - if((*it) == buf) { - it = autoexec_strings.erase(it); + if ((*it) == buf) { std::string::size_type n = buf.size(); char* buf2 = new char[n + 1]; safe_strncpy(buf2, buf.c_str(), n + 1); + bool stringset = false; // If it's a environment variable remove it from there as well - if((strncasecmp(buf2,"set ",4) == 0) && (strlen(buf2) > 4)){ + if ((strncasecmp(buf2,"set ",4) == 0) && (strlen(buf2) > 4)){ char* after_set = buf2 + 4;//move to variable that is being set char* test = strpbrk(after_set,"="); - if(!test) continue; + if (!test) continue; *test = 0; + stringset = true; //If the shell is running/exists update the environment - if(first_shell) first_shell->SetEnv(after_set,""); + if (first_shell) first_shell->SetEnv(after_set,""); } delete [] buf2; + if (stringset && first_shell && first_shell->bf && first_shell->bf->filename.find("AUTOEXEC.BAT") != std::string::npos) { + //Replace entry with spaces if it is a set and from autoexec.bat, as else the location counter will be off. + *it = buf.assign(buf.size(),' '); + it++; + } else { + it = autoexec_strings.erase(it); + } } else it++; } this->CreateAutoexec();