Subversion Repositories SvarDOS

Rev

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

Rev 1023 Rev 1024
Line 760... Line 760...
760
 
760
 
761
  res[reslen] = 0;
761
  res[reslen] = 0;
762
}
762
}
763
 
763
 
764
 
764
 
-
 
765
/* process the ongoing forloop, returns 0 on success, non-zero otherwise (no
-
 
766
   more things to process) */
-
 
767
static int forloop_process(char *res, struct forctx far *forloop) {
-
 
768
  unsigned short i, t;
-
 
769
  struct DTA *dta = (void *)0x80; /* default DTA at 80h in PSP */
-
 
770
 
-
 
771
  TRYAGAIN:
-
 
772
 
-
 
773
  /* dta_inited: FindFirst() or FindNext()? */
-
 
774
  if (forloop->dta_inited == 0) {
-
 
775
 
-
 
776
    /* copy next awaiting pattern to BUFFER */
-
 
777
    for (i = 0;; i++) {
-
 
778
      BUFFER[i] = forloop->cmd[forloop->nextpat + i];
-
 
779
      /* end of patterns list */
-
 
780
      if (BUFFER[i] == 0) break;
-
 
781
      /* space found */
-
 
782
      if (BUFFER[i] == ' ') {
-
 
783
        BUFFER[i] = 0;
-
 
784
        break;
-
 
785
      }
-
 
786
    }
-
 
787
 
-
 
788
    if (i == 0) return(-1);
-
 
789
 
-
 
790
    /* remember position of current pattern */
-
 
791
    forloop->curpat = forloop->nextpat;
-
 
792
 
-
 
793
    /* move nextpat forward to next pattern */
-
 
794
    i += forloop->nextpat;
-
 
795
    while (forloop->cmd[i] == ' ') i++;
-
 
796
    forloop->nextpat = i;
-
 
797
 
-
 
798
    /* FOR in MSDOS 6 includes hidden and system files, but not directories nor volumes */
-
 
799
    if (findfirst(dta, BUFFER, DOS_ATTR_RO | DOS_ATTR_HID | DOS_ATTR_SYS | DOS_ATTR_ARC) != 0) {
-
 
800
      goto TRYAGAIN;
-
 
801
    }
-
 
802
    forloop->dta_inited = 1;
-
 
803
  } else { /* dta in progress */
-
 
804
 
-
 
805
    /* copy forloop DTA to my local copy */
-
 
806
    _fmemcpy(dta, &(forloop->dta), sizeof(*dta));
-
 
807
 
-
 
808
    /* findnext() call */
-
 
809
    if (findnext(dta) != 0) {
-
 
810
      forloop->dta_inited = 0;
-
 
811
      goto TRYAGAIN;
-
 
812
    }
-
 
813
  }
-
 
814
 
-
 
815
  /* copy updated DTA to rmod */
-
 
816
  _fmemcpy(&(forloop->dta), dta, sizeof(*dta));
-
 
817
 
-
 
818
  /* fill res with command, replacing varname by actual filename */
-
 
819
  /* full filename is to be built with path of curpat and fname from dta */
-
 
820
  t = 0;
-
 
821
  i = 0;
-
 
822
  for (;;) {
-
 
823
    if ((forloop->cmd[forloop->exec + t] == '%') && (forloop->cmd[forloop->exec + t + 1] == forloop->varname)) {
-
 
824
      short lastbk = i;
-
 
825
      char far *c = forloop->cmd + forloop->curpat;
-
 
826
      for (;;) {
-
 
827
        res[i] = *c;
-
 
828
        c++;
-
 
829
        if (res[i] == '\\') lastbk = i;
-
 
830
        if ((res[i] == ' ') || (res[i] == 0)) break;
-
 
831
        i++;
-
 
832
      }
-
 
833
      _fstrcpy(res + lastbk, dta->fname);
-
 
834
      for (i = lastbk; res[i] != 0; i++);
-
 
835
      t += 2;
-
 
836
    } else {
-
 
837
      res[i] = forloop->cmd[forloop->exec + t];
-
 
838
      t++;
-
 
839
      if (res[i++] == 0) break;
-
 
840
    }
-
 
841
  }
-
 
842
 
-
 
843
  return(0);
-
 
844
}
-
 
845
 
765
 
846
 
766
int main(void) {
847
int main(void) {
767
  static struct config cfg;
848
  static struct config cfg;
768
  static unsigned short far *rmod_envseg;
849
  static unsigned short far *rmod_envseg;
769
  static unsigned short far *lastexitcode;
850
  static unsigned short far *lastexitcode;
Line 819... Line 900...
819
  if ((cfg.flags & (FLAG_PERMANENT | FLAG_SKIP_AUTOEXEC)) == FLAG_PERMANENT) {
900
  if ((cfg.flags & (FLAG_PERMANENT | FLAG_SKIP_AUTOEXEC)) == FLAG_PERMANENT) {
820
    if (file_getattr("AUTOEXEC.BAT") >= 0) cfg.execcmd = "AUTOEXEC.BAT";
901
    if (file_getattr("AUTOEXEC.BAT") >= 0) cfg.execcmd = "AUTOEXEC.BAT";
821
  }
902
  }
822
 
903
 
823
  do {
904
  do {
824
    /* am I inside a FOR loop? */
-
 
825
    if (rmod->forloop) {
-
 
826
      outputnl("FOR IS NOT IMPLEMENTED YET");
-
 
827
      /* TODO dta_inited: FindFirst() or FindNext()? */
-
 
828
      /* TODO read result */
-
 
829
      /* TODO end of results? move to next pattern */
-
 
830
      /* free used memory */
-
 
831
      rmod_ffree(rmod->forloop);
-
 
832
      rmod->forloop = NULL;
-
 
833
    }
-
 
834
 
905
 
835
    /* terminate previous command with a CR/LF if ECHO ON (but not during BAT processing) */
906
    /* terminate previous command with a CR/LF if ECHO ON (but not during BAT processing) */
836
    if ((rmod->flags & FLAG_ECHOFLAG) && (rmod->bat == NULL)) outputnl("");
907
    if ((rmod->flags & FLAG_ECHOFLAG) && (rmod->bat == NULL)) outputnl("");
837
 
908
 
838
    SKIP_NEWLINE:
909
    SKIP_NEWLINE:
Line 844... Line 915...
844
    cmdline = cmdlinebuf;
915
    cmdline = cmdlinebuf;
845
 
916
 
846
    /* (re)load translation strings if needed */
917
    /* (re)load translation strings if needed */
847
    nls_langreload(BUFFER, *rmod_envseg);
918
    nls_langreload(BUFFER, *rmod_envseg);
848
 
919
 
-
 
920
    /* am I inside a FOR loop? */
-
 
921
    if (rmod->forloop) {
-
 
922
      if (forloop_process(cmdlinebuf, rmod->forloop) != 0) {
-
 
923
        rmod_ffree(rmod->forloop);
-
 
924
        rmod->forloop = NULL;
-
 
925
      } else {
-
 
926
        /* output prompt and command on screen if echo on and command is not
-
 
927
         * inhibiting it with the @ prefix */
-
 
928
        if (rmod->flags & FLAG_ECHOFLAG) {
-
 
929
          build_and_display_prompt(BUFFER, *rmod_envseg);
-
 
930
          outputnl(cmdline);
-
 
931
        }
-
 
932
        /* jump to command processing */
-
 
933
        goto EXEC_CMDLINE;
-
 
934
      }
-
 
935
    }
-
 
936
 
849
    /* load awaiting command, if any (used to run piped commands) */
937
    /* load awaiting command, if any (used to run piped commands) */
850
    if (rmod->awaitingcmd[0] != 0) {
938
    if (rmod->awaitingcmd[0] != 0) {
851
      _fstrcpy(cmdline, rmod->awaitingcmd);
939
      _fstrcpy(cmdline, rmod->awaitingcmd);
852
      rmod->awaitingcmd[0] = 0;
940
      rmod->awaitingcmd[0] = 0;
853
      flags |= DELETE_STDIN_FILE;
941
      flags |= DELETE_STDIN_FILE;
Line 971... Line 1059...
971
    flags &= ~CALL_FLAG;
1059
    flags &= ~CALL_FLAG;
972
    flags &= ~FLAG_STEPBYSTEP;
1060
    flags &= ~FLAG_STEPBYSTEP;
973
 
1061
 
974
    /* repeat unless /C was asked - but always finish running an ongoing batch
1062
    /* repeat unless /C was asked - but always finish running an ongoing batch
975
     * file (otherwise only first BAT command would be executed with /C) */
1063
     * file (otherwise only first BAT command would be executed with /C) */
976
  } while (((rmod->flags & FLAG_EXEC_AND_QUIT) == 0) || (rmod->bat != NULL));
1064
  } while (((rmod->flags & FLAG_EXEC_AND_QUIT) == 0) || (rmod->bat != NULL) || (rmod->forloop != NULL));
977
 
1065
 
978
  sayonara(rmod);
1066
  sayonara(rmod);
979
  return(0);
1067
  return(0);
980
}
1068
}