Subversion Repositories SvarDOS

Rev

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

Rev 465 Rev 469
Line 398... Line 398...
398
      return;
398
      return;
399
    }
399
    }
400
  }
400
  }
401
 
401
 
402
  RUNCMDFILE:
402
  RUNCMDFILE:
403
  /* TODO special handling of batch files */
-
 
404
  if ((ext != NULL) && (imatch(ext, "bat"))) {
-
 
405
    outputnl("batch processing not supported yet");
-
 
406
    return;
-
 
407
  }
-
 
408
 
403
 
409
  /* find cmdtail */
404
  /* find cmdtail */
410
  cmdtail = cmdline;
405
  cmdtail = cmdline;
411
  while (*cmdtail == ' ') cmdtail++;
406
  while (*cmdtail == ' ') cmdtail++;
412
  while ((*cmdtail != ' ') && (*cmdtail != '/') && (*cmdtail != '+') && (*cmdtail != 0)) {
407
  while ((*cmdtail != ' ') && (*cmdtail != '/') && (*cmdtail != '+') && (*cmdtail != 0)) {
413
    cmdtail++;
408
    cmdtail++;
414
  }
409
  }
415
 
410
 
-
 
411
  /* special handling of batch files */
-
 
412
  if ((ext != NULL) && (imatch(ext, "bat"))) {
-
 
413
    /* copy truename of the bat file to rmod buff */
-
 
414
    for (i = 0; cmdfile[i] != 0; i++) rmod->batfile[i] = cmdfile[i];
-
 
415
    rmod->batfile[i] = 0;
-
 
416
    /* copy args of the bat file to rmod buff */
-
 
417
    for (i = 0; cmdtail[i] != 0; i++) rmod->batargs[i] = cmdtail[i];
-
 
418
    /* reset the 'next line to execute' counter */
-
 
419
    rmod->batnextline = 0;
-
 
420
    return;
-
 
421
  }
-
 
422
 
416
  /* copy full filename to execute */
423
  /* copy full filename to execute */
417
  for (i = 0; cmdfile[i] != 0; i++) rmod_execprog[i] = cmdfile[i];
424
  for (i = 0; cmdfile[i] != 0; i++) rmod_execprog[i] = cmdfile[i];
418
  rmod_execprog[i] = 0;
425
  rmod_execprog[i] = 0;
419
 
426
 
420
  /* copy cmdtail to rmod's PSP and compute its len */
427
  /* copy cmdtail to rmod's PSP and compute its len */
Line 510... Line 517...
510
    pop ax
517
    pop ax
511
  }
518
  }
512
}
519
}
513
 
520
 
514
 
521
 
-
 
522
/* fetches a line from batch file and write it to buff, increments
-
 
523
 * rmod counter on success. returns NULL on failure.
-
 
524
 * buff must start with a length byte but the returned pointer must
-
 
525
 * skip it. */
-
 
526
char far *getbatcmd(char far *buff, struct rmod_props far *rmod) {
-
 
527
  unsigned short i;
-
 
528
  buff++; /* make room for the len byte */
-
 
529
  /* TODO temporary hack to display a dummy message */
-
 
530
  if (rmod->batnextline == 0) {
-
 
531
    char *msg = "ECHO batch files not supported yet";
-
 
532
    for (i = 0; msg[i] != 0; i++) buff[i] = msg[i];
-
 
533
    buff[i] = 0;
-
 
534
    buff[-1] = i;
-
 
535
  } else {
-
 
536
    rmod->batfile[0] = 0;
-
 
537
    return(NULL);
-
 
538
  }
-
 
539
  /* open file */
-
 
540
  /* read until awaiting line */
-
 
541
  /* copy line to buff */
-
 
542
  /* close file */
-
 
543
  /* */
-
 
544
  rmod->batnextline++;
-
 
545
  if (rmod->batnextline == 0) rmod->batfile[0] = 0; /* max line count reached */
-
 
546
  return(buff);
-
 
547
}
-
 
548
 
-
 
549
 
515
int main(void) {
550
int main(void) {
516
  static struct config cfg;
551
  static struct config cfg;
517
  static unsigned short far *rmod_envseg;
552
  static unsigned short far *rmod_envseg;
518
  static unsigned short far *lastexitcode;
553
  static unsigned short far *lastexitcode;
519
  static unsigned char BUFFER[4096];
554
  static unsigned char BUFFER[4096];
Line 534... Line 569...
534
  } else {
569
  } else {
535
    /* printf("rmod found at %Fp\r\n", rmod); */
570
    /* printf("rmod found at %Fp\r\n", rmod); */
536
    /* if I was spawned by rmod and FLAG_EXEC_AND_QUIT is set, then I should
571
    /* if I was spawned by rmod and FLAG_EXEC_AND_QUIT is set, then I should
537
     * die asap, because the command has been executed already, so I no longer
572
     * die asap, because the command has been executed already, so I no longer
538
     * have a purpose in life */
573
     * have a purpose in life */
539
    if (rmod->flags & FLAG_EXEC_AND_QUIT) {
574
    if (rmod->flags & FLAG_EXEC_AND_QUIT) sayonara(rmod);
540
      printf("rmod + FLAG_EXEC_AND_QUIT\r\n");
-
 
541
      sayonara(rmod);
-
 
542
    }
-
 
543
  }
575
  }
544
 
576
 
545
  rmod_envseg = MK_FP(rmod->rmodseg, RMOD_OFFSET_ENVSEG);
577
  rmod_envseg = MK_FP(rmod->rmodseg, RMOD_OFFSET_ENVSEG);
546
  lastexitcode = MK_FP(rmod->rmodseg, RMOD_OFFSET_LEXITCODE);
578
  lastexitcode = MK_FP(rmod->rmodseg, RMOD_OFFSET_LEXITCODE);
547
 
579
 
Line 591... Line 623...
591
    /* revert input history terminator to \r */
623
    /* revert input history terminator to \r */
592
    if (cmdline[-1] != 0) {
624
    if (cmdline[-1] != 0) {
593
      cmdline[(unsigned short)(cmdline[-1])] = '\r';
625
      cmdline[(unsigned short)(cmdline[-1])] = '\r';
594
    }
626
    }
595
 
627
 
-
 
628
    /* if batch file is being executed -> fetch next line */
-
 
629
    if (rmod->batfile[0] != 0) {
-
 
630
      cmdline = getbatcmd(BUFFER + sizeof(BUFFER) - 130, rmod);
-
 
631
      if (cmdline == NULL) continue;
-
 
632
    } else {
596
    /* wait for user command line */
633
      /* interactive mode: wait for user command line */
597
    cmdline_getinput(FP_SEG(rmod->inputbuf), FP_OFF(rmod->inputbuf));
634
      cmdline_getinput(FP_SEG(rmod->inputbuf), FP_OFF(rmod->inputbuf));
-
 
635
    }
598
 
636
 
599
    /* if nothing entered, loop again (but without appending an extra CR/LF) */
637
    /* if nothing entered, loop again (but without appending an extra CR/LF) */
600
    if (cmdline[-1] == 0) goto SKIP_NEWLINE;
638
    if (cmdline[-1] == 0) goto SKIP_NEWLINE;
601
 
639
 
602
    /* replace \r by a zero terminator */
640
    /* replace \r by a zero terminator */
Line 624... Line 662...
624
      continue;
662
      continue;
625
    }
663
    }
626
 
664
 
627
    /* if here, then this was not an internal command */
665
    /* if here, then this was not an internal command */
628
    run_as_external(BUFFER, cmdline, *rmod_envseg, rmod);
666
    run_as_external(BUFFER, cmdline, *rmod_envseg, rmod);
-
 
667
    /* perhaps this is a newly launched BAT file */
-
 
668
    if ((rmod->batfile[0] != 0) && (rmod->batnextline == 0)) goto SKIP_NEWLINE;
629
 
669
 
630
    /* revert stdout (in case it was redirected) */
670
    /* revert stdout (in case it was redirected) */
631
    redir_revert();
671
    redir_revert();
632
 
672
 
633
    /* run_as_external() does not return on success, if I am still alive then
673
    /* run_as_external() does not return on success, if I am still alive then