Subversion Repositories SvarDOS

Rev

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

Rev 464 Rev 465
Line 398... Line 398...
398
      return;
398
      return;
399
    }
399
    }
400
  }
400
  }
401
 
401
 
402
  RUNCMDFILE:
402
  RUNCMDFILE:
403
  /* TODO run command through INT 0x21 */
-
 
404
  /* TODO copy environment and append full exec path */
-
 
405
  /* TODO special handling of batch files */
403
  /* TODO special handling of batch files */
406
  if ((ext != NULL) && (imatch(ext, "bat"))) {
404
  if ((ext != NULL) && (imatch(ext, "bat"))) {
407
    outputnl("batch processing not supported yet");
405
    outputnl("batch processing not supported yet");
408
    return;
406
    return;
409
  }
407
  }
Line 514... Line 512...
514
}
512
}
515
 
513
 
516
 
514
 
517
int main(void) {
515
int main(void) {
518
  static struct config cfg;
516
  static struct config cfg;
519
  static unsigned short rmod_seg;
-
 
520
  static unsigned short far *rmod_envseg;
517
  static unsigned short far *rmod_envseg;
521
  static unsigned short far *lastexitcode;
518
  static unsigned short far *lastexitcode;
522
  static unsigned char BUFFER[4096];
519
  static unsigned char BUFFER[4096];
523
  static struct rmod_props far *rmod;
520
  static struct rmod_props far *rmod;
524
 
521
 
525
  parse_argv(&cfg);
-
 
526
 
-
 
527
  rmod = rmod_find();
522
  rmod = rmod_find();
528
  if (rmod == NULL) {
523
  if (rmod == NULL) {
529
    rmod = rmod_install(cfg.envsiz);
524
    rmod = rmod_install(cfg.envsiz);
530
    if (rmod == NULL) {
525
    if (rmod == NULL) {
531
      outputnl("ERROR: rmod_install() failed");
526
      outputnl("ERROR: rmod_install() failed");
532
      return(1);
527
      return(1);
533
    }
528
    }
-
 
529
    /* look at command line parameters */
-
 
530
    parse_argv(&cfg);
534
    /* copy flags to rmod's storage */
531
    /* copy flags to rmod's storage */
535
    rmod->flags = cfg.flags;
532
    rmod->flags = cfg.flags;
536
/*    printf("rmod installed at seg 0x%04X\r\n", rmod_seg); */
533
    /* printf("rmod installed at %Fp\r\n", rmod); */
537
  } else {
534
  } else {
538
/*    printf("rmod found at seg 0x%04x\r\n", rmod_seg); */
535
    /* 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
-
 
537
     * die asap, because the command has been executed already, so I no longer
-
 
538
     * have a purpose in life */
-
 
539
    if (rmod->flags & FLAG_EXEC_AND_QUIT) {
-
 
540
      printf("rmod + FLAG_EXEC_AND_QUIT\r\n");
-
 
541
      sayonara(rmod);
-
 
542
    }
539
  }
543
  }
540
 
544
 
541
  rmod_seg = rmod->rmodseg;
-
 
542
  rmod_envseg = MK_FP(rmod_seg, RMOD_OFFSET_ENVSEG);
545
  rmod_envseg = MK_FP(rmod->rmodseg, RMOD_OFFSET_ENVSEG);
543
  lastexitcode = MK_FP(rmod_seg, RMOD_OFFSET_LEXITCODE);
546
  lastexitcode = MK_FP(rmod->rmodseg, RMOD_OFFSET_LEXITCODE);
544
 
547
 
545
  /* make COMPSEC point to myself */
548
  /* make COMPSEC point to myself */
546
  set_comspec_to_self(*rmod_envseg);
549
  set_comspec_to_self(*rmod_envseg);
547
 
550
 
548
/*  {
551
/*  {
549
    unsigned short envsiz;
552
    unsigned short envsiz;
550
    unsigned short far *sizptr = MK_FP(*rmod_envseg - 1, 3);
553
    unsigned short far *sizptr = MK_FP(*rmod_envseg - 1, 3);
551
    envsiz = *sizptr;
554
    envsiz = *sizptr;
552
    envsiz *= 16;
555
    envsiz *= 16;
553
    printf("rmod_inpbuff at %04X:%04X, env_seg at %04X:0000 (env_size = %u bytes)\r\n", rmod_seg, RMOD_OFFSET_INPBUFF, *rmod_envseg, envsiz);
556
    printf("rmod_inpbuff at %04X:%04X, env_seg at %04X:0000 (env_size = %u bytes)\r\n", rmod->rmodseg, RMOD_OFFSET_INPBUFF, *rmod_envseg, envsiz);
554
  }*/
557
  }*/
555
 
558
 
556
  do {
559
  do {
557
    char far *cmdline = rmod->inputbuf + 2;
560
    char far *cmdline = rmod->inputbuf + 2;
558
 
561
 
Line 604... Line 607...
604
 
607
 
605
    /* move pointer forward to skip over any leading spaces */
608
    /* move pointer forward to skip over any leading spaces */
606
    while (*cmdline == ' ') cmdline++;
609
    while (*cmdline == ' ') cmdline++;
607
 
610
 
608
    /* update rmod's ptr to COMPSPEC so it is always up to date */
611
    /* update rmod's ptr to COMPSPEC so it is always up to date */
609
    rmod_updatecomspecptr(rmod_seg, *rmod_envseg);
612
    rmod_updatecomspecptr(rmod->rmodseg, *rmod_envseg);
610
 
613
 
611
    /* handle redirections (if any) */
614
    /* handle redirections (if any) */
612
    if (redir_parsecmd(cmdline, BUFFER) != 0) {
615
    if (redir_parsecmd(cmdline, BUFFER) != 0) {
613
      outputnl("");
616
      outputnl("");
614
      continue;
617
      continue;
Line 625... Line 628...
625
    run_as_external(BUFFER, cmdline, *rmod_envseg, rmod);
628
    run_as_external(BUFFER, cmdline, *rmod_envseg, rmod);
626
 
629
 
627
    /* revert stdout (in case it was redirected) */
630
    /* revert stdout (in case it was redirected) */
628
    redir_revert();
631
    redir_revert();
629
 
632
 
630
    /* execvp() replaces the current process by the new one
633
    /* run_as_external() does not return on success, if I am still alive then
631
    if I am still alive then external command failed to execute */
634
     * external command failed to execute */
632
    outputnl("Bad command or file name");
635
    outputnl("Bad command or file name");
633
 
636
 
634
  } while ((rmod->flags & FLAG_EXEC_AND_QUIT) == 0);
637
  } while ((rmod->flags & FLAG_EXEC_AND_QUIT) == 0);
635
 
638
 
636
  sayonara(rmod);
639
  sayonara(rmod);