From 8fdd7fea4f7b75b21a0bf229a4783aa1eebbe8d6 Mon Sep 17 00:00:00 2001 From: Sjoerd van der Berg Date: Fri, 18 Oct 2002 08:45:11 +0000 Subject: [PATCH] Support for variables and command line forwarding Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@325 --- src/shell/shell_batch.cpp | 56 ++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/shell/shell_batch.cpp b/src/shell/shell_batch.cpp index cec7f45d..48c571f7 100644 --- a/src/shell/shell_batch.cpp +++ b/src/shell/shell_batch.cpp @@ -24,19 +24,10 @@ BatchFile::BatchFile(DOS_Shell * host,char * name, char * cmd_line) { - /* Go through the command line */ - char * cmd_write=cmd_buffer; prev=host->bf; echo=host->echo; shell=host; - cmd_count=0; - while (*cmd_line || (cmd_countbf=prev; shell->echo=echo; @@ -77,29 +69,51 @@ emptyline: while (*cmd_read) { env_write=env_name; if (*cmd_read=='%') { - cmd_read++; - /* Find the fullstring of this */ - - - continue; - + cmd_read++; + if (cmd_read[0]=='%') { + cmd_read++; + *cmd_write++='%'; + } + size_t len=strspn(cmd_read,"0123456789"); + if (len) { + memcpy(env_name,cmd_read,len); + env_name[len]=0;cmd_read+=len; + len=atoi(env_name); + if (cmd->GetCount()FindCommand(len,word)) continue; + strcpy(cmd_write,word.c_str()); + cmd_write+=strlen(word.c_str()); + continue; + } else { + /* Not a command line number has to be an environment */ + char * first=strchr(cmd_read,'%'); + if (!first) continue; *first++=0; + std::string temp; + if (shell->GetEnvStr(cmd_read,temp)) { + char * equals=strchr(temp.c_str(),'='); + if (!equals) continue; + equals++; + strcpy(cmd_write,equals); + cmd_write+=strlen(equals); + } + cmd_read=first; + } } else { *cmd_write++=*cmd_read++; } - *cmd_write=0; } - return true; - + *cmd_write=0; + return true; } - bool BatchFile::Goto(char * where) { Bit32u pos=0; char cmd[CMD_MAXLINE]; char * cmd_write; DOS_SeekFile(file_handle,&pos,DOS_SEEK_SET); - /* Scan till we have a match or return false*/ + /* Scan till we have a match or return false */ Bit8u c;Bit16u n; again: cmd_write=cmd;