Subversion Repositories SvarDOS

Rev

Rev 989 | Rev 1007 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 989 Rev 1001
Line 26... Line 26...
26
#include <dos.h>
26
#include <dos.h>
27
#include <stdio.h>
27
#include <stdio.h>
28
#include <stdlib.h>
28
#include <stdlib.h>
29
#include <string.h>
29
#include <string.h>
30
 
30
 
31
#include <process.h>
31
#include "svarlang.lib/svarlang.h"
32
 
32
 
33
#include "cmd.h"
33
#include "cmd.h"
34
#include "env.h"
34
#include "env.h"
35
#include "helpers.h"
35
#include "helpers.h"
36
#include "redir.h"
36
#include "redir.h"
Line 151... Line 151...
151
      case 'C':
151
      case 'C':
152
        cfg->flags |= FLAG_EXEC_AND_QUIT;
152
        cfg->flags |= FLAG_EXEC_AND_QUIT;
153
        /* FALLTHRU */
153
        /* FALLTHRU */
154
      case 'k': /* /K = execute command and keep running */
154
      case 'k': /* /K = execute command and keep running */
155
      case 'K':
155
      case 'K':
-
 
156
        cmdline++;
-
 
157
        while (*cmdline == ' ') cmdline++;
156
        cfg->execcmd = cmdline + 1;
158
        cfg->execcmd = cmdline;
-
 
159
        break;
-
 
160
 
-
 
161
      case 'y': /* /Y = execute batch file step-by-step (with /P, /K or /C) */
-
 
162
      case 'Y':
-
 
163
        cfg->flags |= FLAG_STEPBYSTEP;
157
        return;
164
        break;
158
 
165
 
159
      case 'd': /* /D = skip autoexec.bat processing */
166
      case 'd': /* /D = skip autoexec.bat processing */
160
      case 'D':
167
      case 'D':
161
        cfg->flags |= FLAG_SKIP_AUTOEXEC;
168
        cfg->flags |= FLAG_SKIP_AUTOEXEC;
162
        break;
169
        break;
Line 182... Line 189...
182
        nls_outputnl(1,2); /* "/D      Skip AUTOEXEC.BAT processing (makes sense only with /P)" */
189
        nls_outputnl(1,2); /* "/D      Skip AUTOEXEC.BAT processing (makes sense only with /P)" */
183
        nls_outputnl(1,3); /* "/E:nnn  Sets the environment size to nnn bytes" */
190
        nls_outputnl(1,3); /* "/E:nnn  Sets the environment size to nnn bytes" */
184
        nls_outputnl(1,4); /* "/P      Makes the new command interpreter permanent and run AUTOEXEC.BAT" */
191
        nls_outputnl(1,4); /* "/P      Makes the new command interpreter permanent and run AUTOEXEC.BAT" */
185
        nls_outputnl(1,5); /* "/C      Executes the specified command and returns" */
192
        nls_outputnl(1,5); /* "/C      Executes the specified command and returns" */
186
        nls_outputnl(1,6); /* "/K      Executes the specified command and continues running" */
193
        nls_outputnl(1,6); /* "/K      Executes the specified command and continues running" */
-
 
194
        nls_outputnl(1,7); /* "/Y      Executes the batch program step by step" */
187
        exit(1);
195
        exit(1);
188
        break;
196
        break;
189
 
197
 
190
      default:
198
      default:
191
        nls_output(0,2); /* invalid switch */
199
        nls_output(0,2); /* invalid switch */
Line 454... Line 462...
454
      return;
462
      return;
455
    }
463
    }
456
 
464
 
457
    /* fill the newly allocated batctx structure */
465
    /* fill the newly allocated batctx structure */
458
    _fstrcpy(newbat->fname, cmdfile); /* truename of the BAT file */
466
    _fstrcpy(newbat->fname, cmdfile); /* truename of the BAT file */
-
 
467
    newbat->flags = flags & FLAG_STEPBYSTEP;
459
    /* explode args of the bat file and store them in rmod buff */
468
    /* explode args of the bat file and store them in rmod buff */
460
    cmd_explode(buff, cmdline, NULL);
469
    cmd_explode(buff, cmdline, NULL);
461
    _fmemcpy(newbat->argv, buff, sizeof(newbat->argv));
470
    _fmemcpy(newbat->argv, buff, sizeof(newbat->argv));
462
 
471
 
463
    /* push the new bat to the top of rmod's linked list */
472
    /* push the new bat to the top of rmod's linked list */
Line 834... Line 843...
834
      goto EXEC_CMDLINE;
843
      goto EXEC_CMDLINE;
835
    } else {
844
    } else {
836
      flags &= ~DELETE_STDIN_FILE;
845
      flags &= ~DELETE_STDIN_FILE;
837
    }
846
    }
838
 
847
 
839
    /* skip user input if I have a command to exec (/C or /K) */
848
    /* skip user input if I have a command to exec (/C or /K or /P) */
840
    if (cfg.execcmd != NULL) {
849
    if (cfg.execcmd != NULL) {
841
      cmdline = cfg.execcmd;
850
      cmdline = cfg.execcmd;
842
      cfg.execcmd = NULL;
851
      cfg.execcmd = NULL;
-
 
852
      /* */
-
 
853
      if (cfg.flags & FLAG_STEPBYSTEP) flags |= FLAG_STEPBYSTEP;
843
      goto EXEC_CMDLINE;
854
      goto EXEC_CMDLINE;
844
    }
855
    }
845
 
856
 
846
    /* if batch file is being executed -> fetch next line */
857
    /* if batch file is being executed -> fetch next line */
847
    if (rmod->bat != NULL) {
858
    if (rmod->bat != NULL) {
Line 860... Line 871...
860
      batpercrepl(cmdline, CMDLINE_MAXLEN, BUFFER, rmod, *rmod_envseg);
871
      batpercrepl(cmdline, CMDLINE_MAXLEN, BUFFER, rmod, *rmod_envseg);
861
      /* skip any leading spaces */
872
      /* skip any leading spaces */
862
      while (*cmdline == ' ') cmdline++;
873
      while (*cmdline == ' ') cmdline++;
863
      /* skip batch labels */
874
      /* skip batch labels */
864
      if (*cmdline == ':') continue;
875
      if (*cmdline == ':') continue;
-
 
876
      /* step-by-step execution? */
-
 
877
      if (rmod->bat->flags & FLAG_STEPBYSTEP) {
-
 
878
        if (*cmdline == 0) continue; /* skip empty lines */
-
 
879
        if (askchoice(cmdline, svarlang_str(0,10)) != 0) continue;
-
 
880
      }
865
      /* output prompt and command on screen if echo on and command is not
881
      /* output prompt and command on screen if echo on and command is not
866
       * inhibiting it with the @ prefix */
882
       * inhibiting it with the @ prefix */
867
      if ((rmod->flags & FLAG_ECHOFLAG) && (cmdline[0] != '@')) {
883
      if ((rmod->flags & FLAG_ECHOFLAG) && (cmdline[0] != '@')) {
868
        build_and_display_prompt(BUFFER, *rmod_envseg);
884
        build_and_display_prompt(BUFFER, *rmod_envseg);
869
        outputnl(cmdline);
885
        outputnl(cmdline);
Line 918... Line 934...
918
 
934
 
919
    /* try matching (and executing) an internal command */
935
    /* try matching (and executing) an internal command */
920
    cmdres = cmd_process(rmod, *rmod_envseg, cmdline, BUFFER, sizeof(BUFFER), &redirprops, flags & DELETE_STDIN_FILE);
936
    cmdres = cmd_process(rmod, *rmod_envseg, cmdline, BUFFER, sizeof(BUFFER), &redirprops, flags & DELETE_STDIN_FILE);
921
    if ((cmdres == CMD_OK) || (cmdres == CMD_FAIL)) {
937
    if ((cmdres == CMD_OK) || (cmdres == CMD_FAIL)) {
922
      /* internal command executed */
938
      /* internal command executed */
923
      continue;
-
 
924
    } else if (cmdres == CMD_CHANGED) { /* cmdline changed, needs to be reprocessed */
939
    } else if (cmdres == CMD_CHANGED) { /* cmdline changed, needs to be reprocessed */
925
      goto EXEC_CMDLINE;
940
      goto EXEC_CMDLINE;
926
    } else if (cmdres == CMD_CHANGED_BY_CALL) { /* cmdline changed *specifically* by CALL */
941
    } else if (cmdres == CMD_CHANGED_BY_CALL) { /* cmdline changed *specifically* by CALL */
927
      /* the distinction is important since it changes the way batch files are processed */
942
      /* the distinction is important since it changes the way batch files are processed */
928
      flags |= CALL_FLAG;
943
      flags |= CALL_FLAG;
929
      goto EXEC_CMDLINE;
944
      goto EXEC_CMDLINE;
930
    } else if (cmdres == CMD_NOTFOUND) {
945
    } else if (cmdres == CMD_NOTFOUND) {
931
      /* this was not an internal command, try matching an external command */
946
      /* this was not an internal command, try matching an external command */
932
      run_as_external(BUFFER, cmdline, *rmod_envseg, rmod, &redirprops, flags);
947
      run_as_external(BUFFER, cmdline, *rmod_envseg, rmod, &redirprops, flags);
933
      flags &= ~CALL_FLAG; /* reset callflag to make sure it is processed only once */
-
 
934
 
948
 
935
      /* is it a newly launched BAT file? */
949
      /* is it a newly launched BAT file? */
936
      if ((rmod->bat != NULL) && (rmod->bat->nextline == 0)) goto SKIP_NEWLINE;
950
      if ((rmod->bat != NULL) && (rmod->bat->nextline == 0)) goto SKIP_NEWLINE;
937
      /* run_as_external() does not return on success, if I am still alive then
951
      /* run_as_external() does not return on success, if I am still alive then
938
       * external command failed to execute */
952
       * external command failed to execute */
939
      nls_outputnl(0,5); /* "Bad command or file name" */
953
      nls_outputnl(0,5); /* "Bad command or file name" */
940
      continue;
954
    } else {
-
 
955
      /* I should never ever land here */
-
 
956
      outputnl("INTERNAL ERR: INVALID CMDRES");
941
    }
957
    }
942
 
958
 
943
    /* I should never ever land here */
959
    /* reset one-time only flags */
-
 
960
    flags &= ~CALL_FLAG;
944
    outputnl("INTERNAL ERR: INVALID CMDRES");
961
    flags &= ~FLAG_STEPBYSTEP;
945
 
962
 
946
    /* repeat unless /C was asked - but always finish running an ongoing batch
963
    /* repeat unless /C was asked - but always finish running an ongoing batch
947
     * file (otherwise only first BAT command would be executed with /C) */
964
     * file (otherwise only first BAT command would be executed with /C) */
948
  } while (((rmod->flags & FLAG_EXEC_AND_QUIT) == 0) || (rmod->bat != NULL));
965
  } while (((rmod->flags & FLAG_EXEC_AND_QUIT) == 0) || (rmod->bat != NULL));
949
 
966