Subversion Repositories SvarDOS

Rev

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

Rev 572 Rev 576
Line 313... Line 313...
313
  *s = 0;
313
  *s = 0;
314
  output(buff);
314
  output(buff);
315
}
315
}
316
 
316
 
317
 
317
 
318
static void run_as_external(char *buff, const char *cmdline, unsigned short envseg, struct rmod_props far *rmod, struct redir_data *redir) {
318
static void run_as_external(char *buff, const char *cmdline, unsigned short envseg, struct rmod_props far *rmod, struct redir_data *redir, unsigned char delete_stdin_file) {
319
  char *cmdfile = buff + 512;
319
  char *cmdfile = buff + 512;
320
  const char far *pathptr;
320
  const char far *pathptr;
321
  int lookup;
321
  int lookup;
322
  unsigned short i;
322
  unsigned short i;
323
  const char *ext;
323
  const char *ext;
Line 449... Line 449...
449
  _fstrcpy(rmod_execprog, cmdfile);
449
  _fstrcpy(rmod_execprog, cmdfile);
450
 
450
 
451
  /* copy stdin file if a redirection is needed */
451
  /* copy stdin file if a redirection is needed */
452
  if (redir->stdinfile) {
452
  if (redir->stdinfile) {
453
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
453
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
-
 
454
    char far *delstdin = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDIN_DEL);
454
    _fstrcpy(farptr, redir->stdinfile);
455
    _fstrcpy(farptr, redir->stdinfile);
-
 
456
    if (delete_stdin_file) {
-
 
457
      *delstdin = redir->stdinfile[0];
-
 
458
    } else {
-
 
459
      *delstdin = 0;
-
 
460
    }
455
  }
461
  }
456
 
462
 
457
  /* same for stdout file */
463
  /* same for stdout file */
458
  if (redir->stdoutfile) {
464
  if (redir->stdoutfile) {
459
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
465
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
Line 732... Line 738...
732
  static char cmdlinebuf[CMDLINE_MAXLEN + 2]; /* 1 extra byte for 0-terminator and another for memguard */
738
  static char cmdlinebuf[CMDLINE_MAXLEN + 2]; /* 1 extra byte for 0-terminator and another for memguard */
733
  static char *cmdline;
739
  static char *cmdline;
734
  static struct redir_data redirprops;
740
  static struct redir_data redirprops;
735
  static enum cmd_result cmdres;
741
  static enum cmd_result cmdres;
736
  static unsigned short i; /* general-purpose variable for short-lived things */
742
  static unsigned short i; /* general-purpose variable for short-lived things */
-
 
743
  static unsigned char delete_stdin_file;
737
 
744
 
738
  rmod = rmod_find(BUFFER_len);
745
  rmod = rmod_find(BUFFER_len);
739
  if (rmod == NULL) {
746
  if (rmod == NULL) {
740
    /* look at command line parameters (in case env size if set there) */
747
    /* look at command line parameters (in case env size if set there) */
741
    parse_argv(&cfg);
748
    parse_argv(&cfg);
Line 792... Line 799...
792
    /* terminate previous command with a CR/LF if ECHO ON (but not during BAT processing) */
799
    /* terminate previous command with a CR/LF if ECHO ON (but not during BAT processing) */
793
    if ((rmod->flags & FLAG_ECHOFLAG) && (rmod->batfile[0] == 0)) outputnl("");
800
    if ((rmod->flags & FLAG_ECHOFLAG) && (rmod->batfile[0] == 0)) outputnl("");
794
 
801
 
795
    SKIP_NEWLINE:
802
    SKIP_NEWLINE:
796
 
803
 
797
    /* cancel any redirections that may have been set up before */
-
 
798
    redir_revert();
-
 
799
 
-
 
800
    /* memory check */
804
    /* memory check */
801
    memguard_check(rmod->rmodseg, cmdlinebuf);
805
    memguard_check(rmod->rmodseg, cmdlinebuf);
802
 
806
 
803
    /* preset cmdline to point at the dedicated buffer */
807
    /* preset cmdline to point at the dedicated buffer */
804
    cmdline = cmdlinebuf;
808
    cmdline = cmdlinebuf;
Line 808... Line 812...
808
 
812
 
809
    /* load awaiting command, if any (used to run piped commands) */
813
    /* load awaiting command, if any (used to run piped commands) */
810
    if (rmod->awaitingcmd[0] != 0) {
814
    if (rmod->awaitingcmd[0] != 0) {
811
      _fstrcpy(cmdline, rmod->awaitingcmd);
815
      _fstrcpy(cmdline, rmod->awaitingcmd);
812
      rmod->awaitingcmd[0] = 0;
816
      rmod->awaitingcmd[0] = 0;
-
 
817
      delete_stdin_file = 1;
813
      goto EXEC_CMDLINE;
818
      goto EXEC_CMDLINE;
-
 
819
    } else {
-
 
820
      delete_stdin_file = 0;
814
    }
821
    }
815
 
822
 
816
    /* skip user input if I have a command to exec (/C or /K) */
823
    /* skip user input if I have a command to exec (/C or /K) */
817
    if (cfg.execcmd != NULL) {
824
    if (cfg.execcmd != NULL) {
818
      cmdline = cfg.execcmd;
825
      cmdline = cfg.execcmd;
Line 870... Line 877...
870
      rmod->awaitingcmd[0] = 0;
877
      rmod->awaitingcmd[0] = 0;
871
      continue;
878
      continue;
872
    }
879
    }
873
 
880
 
874
    /* try matching (and executing) an internal command */
881
    /* try matching (and executing) an internal command */
875
    cmdres = cmd_process(rmod, *rmod_envseg, cmdline, BUFFER, sizeof(BUFFER), &redirprops);
882
    cmdres = cmd_process(rmod, *rmod_envseg, cmdline, BUFFER, sizeof(BUFFER), &redirprops, delete_stdin_file);
876
    if ((cmdres == CMD_OK) || (cmdres == CMD_FAIL)) {
883
    if ((cmdres == CMD_OK) || (cmdres == CMD_FAIL)) {
877
      /* internal command executed */
884
      /* internal command executed */
878
      continue;
885
      continue;
879
    } else if (cmdres == CMD_CHANGED) { /* cmdline changed, needs to be reprocessed */
886
    } else if (cmdres == CMD_CHANGED) { /* cmdline changed, needs to be reprocessed */
880
      goto EXEC_CMDLINE;
887
      goto EXEC_CMDLINE;
881
    } else if (cmdres == CMD_NOTFOUND) {
888
    } else if (cmdres == CMD_NOTFOUND) {
882
      /* this was not an internal command, try matching an external command */
889
      /* this was not an internal command, try matching an external command */
883
      run_as_external(BUFFER, cmdline, *rmod_envseg, rmod, &redirprops);
890
      run_as_external(BUFFER, cmdline, *rmod_envseg, rmod, &redirprops, delete_stdin_file);
884
      /* perhaps this is a newly launched BAT file */
891
      /* perhaps this is a newly launched BAT file */
885
      if ((rmod->batfile[0] != 0) && (rmod->batnextline == 0)) goto SKIP_NEWLINE;
892
      if ((rmod->batfile[0] != 0) && (rmod->batnextline == 0)) goto SKIP_NEWLINE;
886
      /* run_as_external() does not return on success, if I am still alive then
893
      /* run_as_external() does not return on success, if I am still alive then
887
       * external command failed to execute */
894
       * external command failed to execute */
888
      outputnl("Bad command or file name");
895
      outputnl("Bad command or file name");