From d017f22b89573bfebb0fbde02ce1224b25824ca5 Mon Sep 17 00:00:00 2001 From: Sjoerd van der Berg Date: Sat, 26 Jul 2003 10:47:47 +0000 Subject: [PATCH] Initial checking for redirection, will need more changes in dos to allow this too work. Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1161 --- src/shell/shell.cpp | 86 ++++++++++++++++++++++++++++++++----------- src/shell/shell_inc.h | 2 +- 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/src/shell/shell.cpp b/src/shell/shell.cpp index 1af2b57d..f82fcb77 100644 --- a/src/shell/shell.cpp +++ b/src/shell/shell.cpp @@ -19,6 +19,7 @@ #include #include +#include #include "setup.h" #include "shell_inc.h" @@ -62,31 +63,75 @@ DOS_Shell::DOS_Shell():Program(){ -Bit32u DOS_Shell::GetRedirection(char *s, char **ifn, char **ofn) { +Bitu DOS_Shell::GetRedirection(char *s, char **ifn, char **ofn,bool * append) { - char *output = strrchr(s, '>'); - if (output) { - *output = 0; - // while (!isalnum(*output)) output++; + char * lr=s; + char * lw=s; + char ch; + Bitu num=0; + + while (ch=*lr++) { + switch (ch) { + case '>': + *append=(*lr)=='>'; + if (append) lr++; + lr=ltrim(lr); + if (*ofn) free(*ofn); + *ofn=lr; + while (*lr && *lr!=' ') lr++; + *lr=0; + *ofn=strdup(*ofn); + continue; + case '<': + if (*ifn) free(*ifn); + lr=ltrim(lr); + *ifn=lr; + while (*lr && *lr!=' ') lr++; + *lr=0; + *ifn=strdup(*ifn); + continue; + case '|': + ch=0; + num++; + } + *lw++=ch; } - - return 1; -} + *lw=0; + return num; +} void DOS_Shell::ParseLine(char * line) { - char * in=0; - char * out=0; - /* Check for a leading @ */ if (line[0]=='@') line[0]=' '; line=trim(line); - Bit32u num=0; /* Number of commands in this line */ - num = GetRedirection(line, &in, &out); +#if 1 + /* Do redirection and pipe checks */ + + char * in=0; + char * out=0; + + Bit16u old_in,old_out; + + Bitu num=0; /* Number of commands in this line */ + bool append; + + num = GetRedirection(line,&in, &out,&append); + if (num>1) LOG_MSG("SHELL:Multiple command on 1 line not supported"); +// if (in || num>1) DOS_DuplicateEntry(0,&old_in); + + if (in) { + LOG_MSG("SHELL:Redirect input from %s",in); + DOS_CloseFile(0); + free(in); + } + if (out) { + LOG_MSG("SHELL:Redirect output to %s",out); + free(out); + } +#endif -/* TODO in and out redirection */ - DoCommand(line); } @@ -159,15 +204,10 @@ void DOS_Shell::SyntaxError(void) { void AUTOEXEC_Init(Section * sec) { MSG_Add("AUTOEXEC_CONFIGFILE_HELP","Add here the lines you want to execute on startup.\n"); /* Register a virtual AUOEXEC.BAT file */ - + std::string line; Section_line * section=static_cast(sec); char * extra=(char *)section->data.c_str(); if (extra) SHELL_AddAutoexec(extra); - /* Check to see for extra command line options to be added */ - std::string line; - while (control->cmdline->FindString("-c",line,true)) { - SHELL_AddAutoexec((char *)line.c_str()); - } /* Check for first command being a directory or file */ char buffer[CROSS_LEN]; if (control->cmdline->FindCommand(1,line)) { @@ -191,6 +231,10 @@ void AUTOEXEC_Init(Section * sec) { SHELL_AddAutoexec(name); } } + /* Check to see for extra command line options to be added */ + while (control->cmdline->FindString("-c",line,true)) { + SHELL_AddAutoexec((char *)line.c_str()); + } nomount: VFILE_Register("AUTOEXEC.BAT",(Bit8u *)autoexec_data,strlen(autoexec_data)); } diff --git a/src/shell/shell_inc.h b/src/shell/shell_inc.h index a50b263c..725b9695 100644 --- a/src/shell/shell_inc.h +++ b/src/shell/shell_inc.h @@ -66,7 +66,7 @@ public: void RunInternal(void); //for command /C /* A load of subfunctions */ void ParseLine(char * line); - Bit32u GetRedirection(char *s, char **ifn, char **ofn); + Bitu GetRedirection(char *s, char **ifn, char **ofn,bool * append); void InputCommand(char * line); void ShowPrompt(); void DoCommand(char * cmd);