Subversion Repositories SvarDOS

Rev

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

Rev 508 Rev 517
Line 348... Line 348...
348
  if (explicitpath) return(-2); /* don't bother trying other paths, the caller had its own path preset anyway */
348
  if (explicitpath) return(-2); /* don't bother trying other paths, the caller had its own path preset anyway */
349
  return(-1);
349
  return(-1);
350
}
350
}
351
 
351
 
352
 
352
 
353
static void run_as_external(char *buff, const char *cmdline, unsigned short envseg, struct rmod_props far *rmod) {
353
static void run_as_external(char *buff, const char *cmdline, unsigned short envseg, struct rmod_props far *rmod, struct redir_data *redir) {
354
  char *cmdfile = buff + 512;
354
  char *cmdfile = buff + 512;
355
  const char far *pathptr;
355
  const char far *pathptr;
356
  int lookup;
356
  int lookup;
357
  unsigned short i;
357
  unsigned short i;
358
  const char *ext;
358
  const char *ext;
Line 427... Line 427...
427
    rmod->flags &= ~FLAG_ECHO_BEFORE_BAT;
427
    rmod->flags &= ~FLAG_ECHO_BEFORE_BAT;
428
    if (rmod->flags & FLAG_ECHOFLAG) rmod->flags |= FLAG_ECHO_BEFORE_BAT;
428
    if (rmod->flags & FLAG_ECHOFLAG) rmod->flags |= FLAG_ECHO_BEFORE_BAT;
429
    return;
429
    return;
430
  }
430
  }
431
 
431
 
432
  /* copy full filename to execute */
432
  /* copy full filename to execute, along with redirected files (if any) */
433
  for (i = 0; cmdfile[i] != 0; i++) rmod_execprog[i] = cmdfile[i];
433
  for (i = 0; cmdfile[i] != 0; i++) rmod_execprog[i] = cmdfile[i];
434
  rmod_execprog[i] = 0;
434
  rmod_execprog[i++] = 0;
-
 
435
  if (redir->stdinfile) {
-
 
436
    unsigned short far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
-
 
437
    unsigned short t;
-
 
438
    *farptr = i;
-
 
439
    for (t = 0;; t++) {
-
 
440
      rmod_execprog[i++] = redir->stdinfile[t];
-
 
441
      if (redir->stdinfile[t] == 0) break;
-
 
442
    }
-
 
443
  }
-
 
444
  if (redir->stdoutfile) {
-
 
445
    unsigned short far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
-
 
446
    unsigned short t;
-
 
447
    *farptr = i;
-
 
448
    for (t = 0;; t++) {
-
 
449
      rmod_execprog[i++] = redir->stdoutfile[t];
-
 
450
      if (redir->stdoutfile[t] == 0) break;
-
 
451
    }
-
 
452
    /* openflag */
-
 
453
    farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
-
 
454
    *farptr = redir->stdout_openflag;
-
 
455
  }
435
 
456
 
436
  /* copy cmdtail to rmod's PSP and compute its len */
457
  /* copy cmdtail to rmod's PSP and compute its len */
437
  for (i = 0; cmdtail[i] != 0; i++) rmod_cmdtail[i] = cmdtail[i];
458
  for (i = 0; cmdtail[i] != 0; i++) rmod_cmdtail[i] = cmdtail[i];
438
  rmod_cmdtail[i] = '\r';
459
  rmod_cmdtail[i] = '\r';
439
  rmod_cmdtail[-1] = i;
460
  rmod_cmdtail[-1] = i;
Line 699... Line 720...
699
  static unsigned short far *rmod_envseg;
720
  static unsigned short far *rmod_envseg;
700
  static unsigned short far *lastexitcode;
721
  static unsigned short far *lastexitcode;
701
  static struct rmod_props far *rmod;
722
  static struct rmod_props far *rmod;
702
  static char cmdlinebuf[CMDLINE_MAXLEN + 2]; /* 1 extra byte for 0-terminator and another for memguard */
723
  static char cmdlinebuf[CMDLINE_MAXLEN + 2]; /* 1 extra byte for 0-terminator and another for memguard */
703
  static char *cmdline;
724
  static char *cmdline;
-
 
725
  static struct redir_data redirprops;
704
 
726
 
705
  rmod = rmod_find(BUFFER_len);
727
  rmod = rmod_find(BUFFER_len);
706
  if (rmod == NULL) {
728
  if (rmod == NULL) {
707
    /* look at command line parameters (in case env size if set there) */
729
    /* look at command line parameters (in case env size if set there) */
708
    parse_argv(&cfg);
730
    parse_argv(&cfg);
Line 812... Line 834...
812
 
834
 
813
    /* update rmod's ptr to COMPSPEC so it is always up to date */
835
    /* update rmod's ptr to COMPSPEC so it is always up to date */
814
    rmod_updatecomspecptr(rmod->rmodseg, *rmod_envseg);
836
    rmod_updatecomspecptr(rmod->rmodseg, *rmod_envseg);
815
 
837
 
816
    /* handle redirections (if any) */
838
    /* handle redirections (if any) */
817
    if (redir_parsecmd(cmdline, BUFFER) != 0) {
839
    redir_parsecmd(&redirprops, cmdline);
818
      outputnl("");
-
 
819
      continue;
-
 
820
    }
-
 
821
 
840
 
822
    /* try matching (and executing) an internal command */
841
    /* try matching (and executing) an internal command */
823
    if (cmd_process(rmod, *rmod_envseg, cmdline, BUFFER, sizeof(BUFFER)) >= -1) {
842
    if (cmd_process(rmod, *rmod_envseg, cmdline, BUFFER, sizeof(BUFFER), &redirprops) >= -1) {
824
      /* internal command executed */
843
      /* internal command executed */
825
      redir_revert(); /* revert stdout (in case it was redirected) */
-
 
826
      continue;
844
      continue;
827
    }
845
    }
828
 
846
 
829
    /* if here, then this was not an internal command */
847
    /* if here, then this was not an internal command */
830
    run_as_external(BUFFER, cmdline, *rmod_envseg, rmod);
848
    run_as_external(BUFFER, cmdline, *rmod_envseg, rmod, &redirprops);
831
    /* perhaps this is a newly launched BAT file */
849
    /* perhaps this is a newly launched BAT file */
832
    if ((rmod->batfile[0] != 0) && (rmod->batnextline == 0)) goto SKIP_NEWLINE;
850
    if ((rmod->batfile[0] != 0) && (rmod->batnextline == 0)) goto SKIP_NEWLINE;
833
 
851
 
834
    /* revert stdout (so the err msg is not redirected) */
-
 
835
    redir_revert();
-
 
836
 
-
 
837
    /* run_as_external() does not return on success, if I am still alive then
852
    /* run_as_external() does not return on success, if I am still alive then
838
     * external command failed to execute */
853
     * external command failed to execute */
839
    outputnl("Bad command or file name");
854
    outputnl("Bad command or file name");
840
 
855
 
841
  } while ((rmod->flags & FLAG_EXEC_AND_QUIT) == 0);
856
  } while ((rmod->flags & FLAG_EXEC_AND_QUIT) == 0);