Subversion Repositories SvarDOS

Rev

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

Rev 2212 Rev 2213
Line 20... Line 20...
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
 * DEALINGS IN THE SOFTWARE.
22
 * DEALINGS IN THE SOFTWARE.
23
 */
23
 */
24
 
24
 
25
#include <dos.h>
25
#include <dos.h> /* MK_FP(), FP_SEG(), FP_OFF()... */
26
#include <stdio.h>
-
 
27
#include <string.h>
26
#include <string.h>
28
 
27
 
29
#include "svarlang.lib/svarlang.h"
28
#include "svarlang.lib/svarlang.h"
30
 
29
 
31
#include "cmd.h"
30
#include "cmd.h"
Line 228... Line 227...
228
   *
227
   *
229
   * The cautious approach is therefore to read the tail up until the length
228
   * The cautious approach is therefore to read the tail up until the length
230
   * mentionned at [80h] or to first CR or nul, whichever comes first.
229
   * mentionned at [80h] or to first CR or nul, whichever comes first.
231
   */
230
   */
232
 
231
 
233
  bzero(cfg, sizeof(*cfg));
232
  sv_bzero(cfg, sizeof(*cfg));
234
 
233
 
235
  /* Make sure that the advertised cmdline length is no more than 126 bytes
234
  /* Make sure that the advertised cmdline length is no more than 126 bytes
236
   * because the PSP ends at [0xff] and there ought to be at least 1 byte of
235
   * because the PSP ends at [0xff] and there ought to be at least 1 byte of
237
   * room for the CR-terminator.
236
   * room for the CR-terminator.
238
   * According to Matthias Paul cmdlines longer than 126 (and even longer than
237
   * According to Matthias Paul cmdlines longer than 126 (and even longer than
Line 376... Line 375...
376
      case 't':
375
      case 't':
377
      {
376
      {
378
        struct nls_patterns nls;
377
        struct nls_patterns nls;
379
        unsigned char h, m, sec;
378
        unsigned char h, m, sec;
380
        if (nls_getpatterns(&nls) != 0) {
379
        if (nls_getpatterns(&nls) != 0) {
381
          s += sprintf(s, "ERR");
380
          s += sv_strcpy(s, "ERR");
382
        } else {
381
        } else {
383
          dos_get_time(&h, &m, &sec);
382
          dos_get_time(&h, &m, &sec);
384
          s += nls_format_time(s, h, m, sec, &nls);
383
          s += nls_format_time(s, h, m, sec, &nls);
385
        }
384
        }
386
        break;
385
        break;
Line 390... Line 389...
390
      {
389
      {
391
        struct nls_patterns nls;
390
        struct nls_patterns nls;
392
        unsigned short y;
391
        unsigned short y;
393
        unsigned char m, d;
392
        unsigned char m, d;
394
        if (nls_getpatterns(&nls) != 0) {
393
        if (nls_getpatterns(&nls) != 0) {
395
          s += sprintf(s, "ERR");
394
          s += sv_strcpy(s, "ERR");
396
        } else {
395
        } else {
397
          dos_get_date(&y, &m, &d);
396
          dos_get_date(&y, &m, &d);
398
          s += nls_format_date(s, y, m, d, &nls);
397
          s += nls_format_date(s, y, m, d, &nls);
399
        }
398
        }
400
        break;
399
        break;
Line 411... Line 410...
411
        /* move s ptr forward to end (0-termintor) of pathname */
410
        /* move s ptr forward to end (0-termintor) of pathname */
412
        while (*s != 0) s++;
411
        while (*s != 0) s++;
413
        break;
412
        break;
414
      case 'V':  /* $V = version number */
413
      case 'V':  /* $V = version number */
415
      case 'v':
414
      case 'v':
416
        s += sprintf(s, PVER);
415
        s += sv_strcpy(s, PVER);
417
        break;
416
        break;
418
      case 'N':  /* $N = current drive */
417
      case 'N':  /* $N = current drive */
419
      case 'n':
418
      case 'n':
420
        *s = _dosgetcurdrive() + 'A';
419
        *s = _dosgetcurdrive() + 'A';
421
        s++;
420
        s++;
Line 625... Line 624...
625
      nls_outputnl_doserr(8); /* insufficient memory */
624
      nls_outputnl_doserr(8); /* insufficient memory */
626
      return;
625
      return;
627
    }
626
    }
628
 
627
 
629
    /* fill the newly allocated batctx structure */
628
    /* fill the newly allocated batctx structure */
630
    _fstrcpy(newbat->fname, cmdfile); /* truename of the BAT file */
629
    sv_strcpy_far(newbat->fname, cmdfile); /* truename of the BAT file */
631
    newbat->flags = flags & FLAG_STEPBYSTEP;
630
    newbat->flags = flags & FLAG_STEPBYSTEP;
632
    /* explode args of the bat file and store them in rmod buff */
631
    /* explode args of the bat file and store them in rmod buff */
633
    cmd_explode(buff, cmdline, NULL);
632
    cmd_explode(buff, cmdline, NULL);
634
    _fmemcpy(newbat->argv, buff, sizeof(newbat->argv));
633
    memcpy_ltr_far(newbat->argv, buff, sizeof(newbat->argv));
635
 
634
 
636
    /* push the new bat to the top of rmod's linked list */
635
    /* push the new bat to the top of rmod's linked list */
637
    newbat->parent = rmod->bat;
636
    newbat->parent = rmod->bat;
638
    rmod->bat = newbat;
637
    rmod->bat = newbat;
639
 
638
 
640
    return;
639
    return;
641
  }
640
  }
642
 
641
 
643
  /* copy full filename to execute, along with redirected files (if any) */
642
  /* copy full filename to execute, along with redirected files (if any) */
644
  _fstrcpy(rmod_execprog, cmdfile);
643
  sv_strcpy_far(rmod_execprog, cmdfile);
645
 
644
 
646
  /* copy stdin file if a redirection is needed */
645
  /* copy stdin file if a redirection is needed */
647
  if (redir->stdinfile) {
646
  if (redir->stdinfile) {
648
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
647
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDINFILE);
649
    char far *delstdin = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDIN_DEL);
648
    char far *delstdin = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDIN_DEL);
650
    _fstrcpy(farptr, redir->stdinfile);
649
    sv_strcpy_far(farptr, redir->stdinfile);
651
    if (flags & DELETE_STDIN_FILE) {
650
    if (flags & DELETE_STDIN_FILE) {
652
      *delstdin = redir->stdinfile[0];
651
      *delstdin = redir->stdinfile[0];
653
    } else {
652
    } else {
654
      *delstdin = 0;
653
      *delstdin = 0;
655
    }
654
    }
Line 657... Line 656...
657
 
656
 
658
  /* same for stdout file */
657
  /* same for stdout file */
659
  if (redir->stdoutfile) {
658
  if (redir->stdoutfile) {
660
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
659
    char far *farptr = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTFILE);
661
    unsigned short far *farptr16 = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
660
    unsigned short far *farptr16 = MK_FP(rmod->rmodseg, RMOD_OFFSET_STDOUTAPP);
662
    _fstrcpy(farptr, redir->stdoutfile);
661
    sv_strcpy_far(farptr, redir->stdoutfile);
663
    /* openflag */
662
    /* openflag */
664
    *farptr16 = redir->stdout_openflag;
663
    *farptr16 = redir->stdout_openflag;
665
  }
664
  }
666
 
665
 
667
  /* copy cmdtail to rmod's PSP and compute its len */
666
  /* copy cmdtail to rmod's PSP and compute its len */
Line 682... Line 681...
682
  /* far pointers to unopened FCB entries (stored in RMOD's own PSP) */
681
  /* far pointers to unopened FCB entries (stored in RMOD's own PSP) */
683
  {
682
  {
684
    char far *farptr;
683
    char far *farptr;
685
    /* prep the unopened FCBs */
684
    /* prep the unopened FCBs */
686
    farptr = MK_FP(rmod->rmodseg, 0x5C);
685
    farptr = MK_FP(rmod->rmodseg, 0x5C);
687
    _fmemset(farptr, 0, 36); /* first FCB is 16 bytes long, second is 20 bytes long */
686
    sv_bzero(farptr, 36); /* first FCB is 16 bytes long, second is 20 bytes long */
688
    cmdtail_to_fcb(farptr, farptr + 16, cmdtail);
687
    cmdtail_to_fcb(farptr, farptr + 16, cmdtail);
689
    /* set (far) pointers in the ExecParam block */
688
    /* set (far) pointers in the ExecParam block */
690
    ExecParam->fcb1 = (unsigned long)MK_FP(rmod->rmodseg, 0x5C);
689
    ExecParam->fcb1 = (unsigned long)MK_FP(rmod->rmodseg, 0x5C);
691
    ExecParam->fcb2 = (unsigned long)MK_FP(rmod->rmodseg, 0x6C);
690
    ExecParam->fcb2 = (unsigned long)MK_FP(rmod->rmodseg, 0x6C);
692
  }
691
  }
Line 986... Line 985...
986
    }
985
    }
987
    forloop->dta_inited = 1;
986
    forloop->dta_inited = 1;
988
  } else { /* dta in progress */
987
  } else { /* dta in progress */
989
 
988
 
990
    /* copy forloop DTA to my local copy */
989
    /* copy forloop DTA to my local copy */
991
    _fmemcpy(dta, &(forloop->dta), sizeof(*dta));
990
    memcpy_ltr_far(dta, &(forloop->dta), sizeof(*dta));
992
 
991
 
993
    /* findnext() call */
992
    /* findnext() call */
994
    if (findnext(dta) != 0) {
993
    if (findnext(dta) != 0) {
995
      forloop->dta_inited = 0;
994
      forloop->dta_inited = 0;
996
      goto TRYAGAIN;
995
      goto TRYAGAIN;
997
    }
996
    }
998
  }
997
  }
999
 
998
 
1000
  /* copy updated DTA to rmod */
999
  /* copy updated DTA to rmod */
1001
  _fmemcpy(&(forloop->dta), dta, sizeof(*dta));
1000
  memcpy_ltr_far(&(forloop->dta), dta, sizeof(*dta));
1002
 
1001
 
1003
  /* prefill pathprefix with the prefix (path) of the files */
1002
  /* prefill pathprefix with the prefix (path) of the files */
1004
  {
1003
  {
1005
    short lastbk = -1;
1004
    short lastbk = -1;
1006
    char far *c = forloop->cmd + forloop->curpat;
1005
    char far *c = forloop->cmd + forloop->curpat;
Line 1018... Line 1017...
1018
  /* full filename is to be built with path of curpat and fname from dta */
1017
  /* full filename is to be built with path of curpat and fname from dta */
1019
  t = 0;
1018
  t = 0;
1020
  i = 0;
1019
  i = 0;
1021
  for (;;) {
1020
  for (;;) {
1022
    if ((forloop->cmd[forloop->exec + t] == '%') && (forloop->cmd[forloop->exec + t + 1] == forloop->varname)) {
1021
    if ((forloop->cmd[forloop->exec + t] == '%') && (forloop->cmd[forloop->exec + t + 1] == forloop->varname)) {
1023
      strcpy(res + i, pathprefix);
1022
      sv_strcpy(res + i, pathprefix);
1024
      strcat(res + i, fnameptr);
1023
      sv_strcat(res + i, fnameptr);
1025
      for (; res[i] != 0; i++);
1024
      for (; res[i] != 0; i++);
1026
      t += 2;
1025
      t += 2;
1027
    } else {
1026
    } else {
1028
      res[i] = forloop->cmd[forloop->exec + t];
1027
      res[i] = forloop->cmd[forloop->exec + t];
1029
      t++;
1028
      t++;
Line 1172... Line 1171...
1172
      }
1171
      }
1173
    }
1172
    }
1174
 
1173
 
1175
    /* load awaiting command, if any (used to run piped commands) */
1174
    /* load awaiting command, if any (used to run piped commands) */
1176
    if (rmod->awaitingcmd[0] != 0) {
1175
    if (rmod->awaitingcmd[0] != 0) {
1177
      _fstrcpy(cmdline, rmod->awaitingcmd);
1176
      sv_strcpy_far(cmdline, rmod->awaitingcmd);
1178
      rmod->awaitingcmd[0] = 0;
1177
      rmod->awaitingcmd[0] = 0;
1179
      flags |= DELETE_STDIN_FILE;
1178
      flags |= DELETE_STDIN_FILE;
1180
      goto EXEC_CMDLINE;
1179
      goto EXEC_CMDLINE;
1181
    } else {
1180
    } else {
1182
      flags &= ~DELETE_STDIN_FILE;
1181
      flags &= ~DELETE_STDIN_FILE;
Line 1243... Line 1242...
1243
      cmdline_getinput(rmod->rmodseg, RMOD_OFFSET_INPUTBUF);
1242
      cmdline_getinput(rmod->rmodseg, RMOD_OFFSET_INPUTBUF);
1244
      /* append stack-overflow detection signature to the end of the input buffer */
1243
      /* append stack-overflow detection signature to the end of the input buffer */
1245
      rmod_inputbuf[rmod_inputbuf[1] + 3] = 0xCA; /* trailing signature */
1244
      rmod_inputbuf[rmod_inputbuf[1] + 3] = 0xCA; /* trailing signature */
1246
      rmod_inputbuf[rmod_inputbuf[1] + 4] = 0xFE; /* trailing signature */
1245
      rmod_inputbuf[rmod_inputbuf[1] + 4] = 0xFE; /* trailing signature */
1247
      /* copy it to local cmdline */
1246
      /* copy it to local cmdline */
1248
      if (rmod_inputbuf[1] != 0) _fmemcpy(cmdline, rmod_inputbuf + 2, rmod_inputbuf[1]);
1247
      if (rmod_inputbuf[1] != 0) memcpy_ltr_far(cmdline, rmod_inputbuf + 2, rmod_inputbuf[1]);
1249
      cmdline[rmod_inputbuf[1]] = 0; /* zero-terminate local buff (original is '\r'-terminated) */
1248
      cmdline[rmod_inputbuf[1]] = 0; /* zero-terminate local buff (original is '\r'-terminated) */
1250
    }
1249
    }
1251
 
1250
 
1252
    /* if nothing entered, loop again (but without appending an extra CR/LF) */
1251
    /* if nothing entered, loop again (but without appending an extra CR/LF) */
1253
    if (cmdline[0] == 0) goto SKIP_NEWLINE;
1252
    if (cmdline[0] == 0) goto SKIP_NEWLINE;