Subversion Repositories SvarDOS

Rev

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

Rev 506 Rev 507
Line 615... Line 615...
615
  rmod->batnextline = 0;
615
  rmod->batnextline = 0;
616
  return(-1);
616
  return(-1);
617
}
617
}
618
 
618
 
619
 
619
 
-
 
620
/* replaces %-variables in a BAT line with resolved values:
-
 
621
 * %PATH%       -> replaced by the contend of the PATH env variable
-
 
622
 * %UNDEFINED%  -> undefined variables are replaced by nothing ("")
-
 
623
 * %NOTCLOSED   -> NOTCLOSED
-
 
624
 * %1           -> first argument of the batch file (or nothing if no arg) */
-
 
625
static void batpercrepl(char *res, unsigned short ressz, const char *line, const struct rmod_props far *rmod, unsigned short envseg) {
-
 
626
  unsigned short lastperc = 0xffff;
-
 
627
  unsigned short reslen = 0;
-
 
628
 
-
 
629
  if (ressz == 0) return;
-
 
630
  ressz--; /* reserve one byte for the NULL terminator */
-
 
631
 
-
 
632
  for (; (reslen < ressz) && (*line != 0); line++) {
-
 
633
    /* if not a percent, I don't care */
-
 
634
    if (*line != '%') {
-
 
635
      res[reslen++] = *line;
-
 
636
      continue;
-
 
637
    }
-
 
638
 
-
 
639
    /* *** perc char handling *** */
-
 
640
 
-
 
641
    /* closing perc? */
-
 
642
    if (lastperc != 0xffff) {
-
 
643
      /* %% is '%' */
-
 
644
      if (lastperc == reslen) {
-
 
645
        res[reslen++] = '%';
-
 
646
      } else {   /* otherwise variable name */
-
 
647
        const char far *ptr;
-
 
648
        res[reslen] = 0;
-
 
649
        reslen = lastperc;
-
 
650
        ptr = env_lookup_val(envseg, res + reslen);
-
 
651
        if (ptr != NULL) {
-
 
652
          while ((*ptr != 0) && (reslen < ressz)) {
-
 
653
            res[reslen++] = *ptr;
-
 
654
            ptr++;
-
 
655
          }
-
 
656
        }
-
 
657
      }
-
 
658
      lastperc = 0xffff;
-
 
659
      continue;
-
 
660
    }
-
 
661
 
-
 
662
    /* digit? (bat arg) */
-
 
663
    if ((line[1] >= '0') && (line[1] <= '9')) {
-
 
664
      /* TODO */
-
 
665
      line++;  /* skip the digit */
-
 
666
      continue;
-
 
667
    }
-
 
668
 
-
 
669
    /* opening perc */
-
 
670
    lastperc = reslen;
-
 
671
 
-
 
672
  }
-
 
673
 
-
 
674
  res[reslen] = 0;
-
 
675
}
-
 
676
 
-
 
677
 
620
int main(void) {
678
int main(void) {
621
  static struct config cfg;
679
  static struct config cfg;
622
  static unsigned short far *rmod_envseg;
680
  static unsigned short far *rmod_envseg;
623
  static unsigned short far *lastexitcode;
681
  static unsigned short far *lastexitcode;
624
  static struct rmod_props far *rmod;
682
  static struct rmod_props far *rmod;
Line 693... Line 751...
693
      goto EXEC_CMDLINE;
751
      goto EXEC_CMDLINE;
694
    }
752
    }
695
 
753
 
696
    /* if batch file is being executed -> fetch next line */
754
    /* if batch file is being executed -> fetch next line */
697
    if (rmod->batfile[0] != 0) {
755
    if (rmod->batfile[0] != 0) {
698
      if (getbatcmd(cmdline, CMDLINE_MAXLEN, rmod) != 0) { /* end of batch */
756
      if (getbatcmd(BUFFER, CMDLINE_MAXLEN, rmod) != 0) { /* end of batch */
699
        /* restore echo flag as it was before running the bat file */
757
        /* restore echo flag as it was before running the bat file */
700
        rmod->flags &= ~FLAG_ECHOFLAG;
758
        rmod->flags &= ~FLAG_ECHOFLAG;
701
        if (rmod->flags & FLAG_ECHO_BEFORE_BAT) rmod->flags |= FLAG_ECHOFLAG;
759
        if (rmod->flags & FLAG_ECHO_BEFORE_BAT) rmod->flags |= FLAG_ECHOFLAG;
702
        continue;
760
        continue;
703
      }
761
      }
-
 
762
      /* %-decoding of variables (%PATH%, %1, %%...), result in cmdline */
-
 
763
      batpercrepl(cmdline, CMDLINE_MAXLEN, BUFFER, rmod, *rmod_envseg);
704
      /* skip any leading spaces */
764
      /* skip any leading spaces */
705
      while (*cmdline == ' ') cmdline++;
765
      while (*cmdline == ' ') cmdline++;
706
      /* output prompt and command on screen if echo on and command is not
766
      /* output prompt and command on screen if echo on and command is not
707
       * inhibiting it with the @ prefix */
767
       * inhibiting it with the @ prefix */
708
      if ((rmod->flags & FLAG_ECHOFLAG) && (cmdline[0] != '@')) {
768
      if ((rmod->flags & FLAG_ECHOFLAG) && (cmdline[0] != '@')) {