Subversion Repositories SvarDOS

Rev

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

Rev 1065 Rev 1070
Line 766... Line 766...
766
   more things to process) */
766
   more things to process) */
767
static int forloop_process(char *res, struct forctx far *forloop) {
767
static int forloop_process(char *res, struct forctx far *forloop) {
768
  unsigned short i, t;
768
  unsigned short i, t;
769
  struct DTA *dta = (void *)0x80; /* default DTA at 80h in PSP */
769
  struct DTA *dta = (void *)0x80; /* default DTA at 80h in PSP */
770
  char *fnameptr = dta->fname;
770
  char *fnameptr = dta->fname;
-
 
771
  char *pathprefix = BUFFER + 256;
-
 
772
 
-
 
773
  *pathprefix = 0;
771
 
774
 
772
  TRYAGAIN:
775
  TRYAGAIN:
773
 
776
 
774
  /* dta_inited: FindFirst() or FindNext()? */
777
  /* dta_inited: FindFirst() or FindNext()? */
775
  if (forloop->dta_inited == 0) {
778
  if (forloop->dta_inited == 0) {
Line 777... Line 780...
777
    /* copy next awaiting pattern to BUFFER (and skip all delimiters until
780
    /* copy next awaiting pattern to BUFFER (and skip all delimiters until
778
     * next pattern or end of list) */
781
     * next pattern or end of list) */
779
    t = 0;
782
    t = 0;
780
    for (i = 0;; i++) {
783
    for (i = 0;; i++) {
781
      BUFFER[i] = forloop->cmd[forloop->nextpat + i];
784
      BUFFER[i] = forloop->cmd[forloop->nextpat + i];
782
      /* look for a delimiter - the list of valid delimiters has been
785
      /* is this a delimiter? (all delimiters are already normalized to a space here) */
783
       * researched and kindly shared by Robert Riebisch via the ticket
-
 
784
       * at https://osdn.net/projects/svardos/ticket/44058 */
-
 
785
      switch (BUFFER[i]) {
786
      if (BUFFER[i] == ' ') {
786
        case ' ':
-
 
787
        case '\t':
-
 
788
        case ';':
-
 
789
        case ',':
-
 
790
        case '/':
-
 
791
        case '=':
-
 
792
          BUFFER[i] = 0;
787
        BUFFER[i] = 0;
793
          t = 1;
788
        t = 1;
794
          break;
789
      } else if (BUFFER[i] == 0) {
795
        case 0: /* end of patterns list */
790
        /* end of patterns list */
796
          t = 2;
791
        break;
797
          break;
792
      } else {
798
        default: /* quit if I got a pattern already */
793
        /* quit if I got a pattern already */
799
          if (t == 1) t = 2;
794
        if (t == 1) break;
800
          break;
-
 
801
      }
795
      }
802
      if (t == 2) break;
-
 
803
    }
796
    }
804
 
797
 
805
    if (i == 0) return(-1);
798
    if (i == 0) return(-1);
806
 
799
 
807
    /* remember position of current pattern */
800
    /* remember position of current pattern */
Line 837... Line 830...
837
  }
830
  }
838
 
831
 
839
  /* copy updated DTA to rmod */
832
  /* copy updated DTA to rmod */
840
  _fmemcpy(&(forloop->dta), dta, sizeof(*dta));
833
  _fmemcpy(&(forloop->dta), dta, sizeof(*dta));
841
 
834
 
-
 
835
  /* prefill pathprefix with the prefix (path) of the files */
-
 
836
  {
-
 
837
    short lastbk = -1;
-
 
838
    char far *c = forloop->cmd + forloop->curpat;
-
 
839
    for (i = 0;; i++) {
-
 
840
      pathprefix[i] = c[i];
-
 
841
      if (pathprefix[i] == '\\') lastbk = i;
-
 
842
      if ((pathprefix[i] == ' ') || (pathprefix[i] == 0)) break;
-
 
843
    }
-
 
844
    pathprefix[lastbk+1] = 0;
-
 
845
  }
-
 
846
 
842
  SKIP_DTA:
847
  SKIP_DTA:
843
 
848
 
844
  /* fill res with command, replacing varname by actual filename */
849
  /* fill res with command, replacing varname by actual filename */
845
  /* full filename is to be built with path of curpat and fname from dta */
850
  /* full filename is to be built with path of curpat and fname from dta */
846
  t = 0;
851
  t = 0;
847
  i = 0;
852
  i = 0;
848
  for (;;) {
853
  for (;;) {
849
    if ((forloop->cmd[forloop->exec + t] == '%') && (forloop->cmd[forloop->exec + t + 1] == forloop->varname)) {
854
    if ((forloop->cmd[forloop->exec + t] == '%') && (forloop->cmd[forloop->exec + t + 1] == forloop->varname)) {
850
      short lastbk = i;
-
 
851
      char far *c = forloop->cmd + forloop->curpat;
-
 
852
      for (;;) {
-
 
853
        res[i] = *c;
-
 
854
        c++;
-
 
855
        if (res[i] == '\\') lastbk = i;
855
      strcpy(res + i, pathprefix);
856
        if ((res[i] == ' ') || (res[i] == 0)) break;
-
 
857
        i++;
-
 
858
      }
-
 
859
      strcpy(res + lastbk, fnameptr);
856
      strcat(res + i, fnameptr);
860
      for (i = lastbk; res[i] != 0; i++);
857
      for (; res[i] != 0; i++);
861
      t += 2;
858
      t += 2;
862
    } else {
859
    } else {
863
      res[i] = forloop->cmd[forloop->exec + t];
860
      res[i] = forloop->cmd[forloop->exec + t];
864
      t++;
861
      t++;
865
      if (res[i++] == 0) break;
862
      if (res[i++] == 0) break;