Subversion Repositories SvarDOS

Rev

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

Rev 448 Rev 449
Line 77... Line 77...
77
#include "helpers.h"
77
#include "helpers.h"
78
#include "redir.h"
78
#include "redir.h"
79
#include "rmodinit.h"
79
#include "rmodinit.h"
80
#include "sayonara.h"
80
#include "sayonara.h"
81
 
81
 
82
#define FLAG_EXEC_AND_QUIT 1
-
 
83
 
82
 
84
struct config {
83
struct config {
85
  unsigned char flags;
84
  unsigned char flags; /* command.com flags, as defined in rmodinit.h */
86
  char *execcmd;
85
  char *execcmd;
87
  unsigned short envsiz;
86
  unsigned short envsiz;
88
};
87
};
89
 
88
 
90
 
89
 
Line 129... Line 128...
129
          if (cmdline[i] == ':') i++; /* could be /E:size */
128
          if (cmdline[i] == ':') i++; /* could be /E:size */
130
          atous(&(cfg->envsiz), cmdline + i);
129
          atous(&(cfg->envsiz), cmdline + i);
131
          if (cfg->envsiz < 64) cfg->envsiz = 0;
130
          if (cfg->envsiz < 64) cfg->envsiz = 0;
132
          break;
131
          break;
133
 
132
 
-
 
133
        case 'p': /* permanent shell (can't exit) */
-
 
134
        case 'P':
-
 
135
          cfg->flags |= FLAG_PERMANENT;
-
 
136
          break;
-
 
137
 
134
        case '?':
138
        case '?':
135
          outputnl("Starts the SvarCOM command interpreter");
139
          outputnl("Starts the SvarCOM command interpreter");
136
          outputnl("");
140
          outputnl("");
137
          outputnl("COMMAND /E:nnn [/[C|K] command]");
141
          outputnl("COMMAND /E:nnn [/[C|K] command]");
138
          outputnl("");
142
          outputnl("");
139
          outputnl("/E:nnn     Sets the environment size to nnn bytes");
143
          outputnl("/E:nnn     Sets the environment size to nnn bytes");
-
 
144
          outputnl("/P         Makes the new command interpreter permanent (can't exit)");
140
          outputnl("/C         Executes the specified command and returns");
145
          outputnl("/C         Executes the specified command and returns");
141
          outputnl("/K         Executes the specified command and continues running");
146
          outputnl("/K         Executes the specified command and continues running");
142
          exit(1);
147
          exit(1);
143
          break;
148
          break;
144
 
149
 
Line 322... Line 327...
322
  static struct config cfg;
327
  static struct config cfg;
323
  static unsigned short rmod_seg;
328
  static unsigned short rmod_seg;
324
  static unsigned short far *rmod_envseg;
329
  static unsigned short far *rmod_envseg;
325
  static unsigned short far *lastexitcode;
330
  static unsigned short far *lastexitcode;
326
  static unsigned char BUFFER[4096];
331
  static unsigned char BUFFER[4096];
-
 
332
  static struct rmod_props far *rmod;
327
 
333
 
328
  parse_argv(&cfg);
334
  parse_argv(&cfg);
329
 
335
 
330
  rmod_seg = rmod_find();
336
  rmod = rmod_find();
331
  if (rmod_seg == 0xffff) {
337
  if (rmod == NULL) {
332
    rmod_seg = rmod_install(cfg.envsiz);
338
    rmod = rmod_install(cfg.envsiz);
333
    if (rmod_seg == 0xffff) {
339
    if (rmod == NULL) {
334
      outputnl("ERROR: rmod_install() failed");
340
      outputnl("ERROR: rmod_install() failed");
335
      return(1);
341
      return(1);
336
    }
342
    }
-
 
343
    /* copy flags to rmod's storage */
-
 
344
    rmod->flags = cfg.flags;
337
/*    printf("rmod installed at seg 0x%04X\r\n", rmod_seg); */
345
/*    printf("rmod installed at seg 0x%04X\r\n", rmod_seg); */
338
  } else {
346
  } else {
339
/*    printf("rmod found at seg 0x%04x\r\n", rmod_seg); */
347
/*    printf("rmod found at seg 0x%04x\r\n", rmod_seg); */
340
  }
348
  }
341
 
349
 
-
 
350
  rmod_seg = rmod->rmodseg;
342
  rmod_envseg = MK_FP(rmod_seg, RMOD_OFFSET_ENVSEG);
351
  rmod_envseg = MK_FP(rmod_seg, RMOD_OFFSET_ENVSEG);
343
  lastexitcode = MK_FP(rmod_seg, RMOD_OFFSET_LEXITCODE);
352
  lastexitcode = MK_FP(rmod_seg, RMOD_OFFSET_LEXITCODE);
344
 
353
 
345
  /* make COMPSEC point to myself */
354
  /* make COMPSEC point to myself */
346
  set_comspec_to_self(*rmod_envseg);
355
  set_comspec_to_self(*rmod_envseg);
Line 457... Line 466...
457
      outputnl("");
466
      outputnl("");
458
      continue;
467
      continue;
459
    }
468
    }
460
 
469
 
461
    /* try matching (and executing) an internal command */
470
    /* try matching (and executing) an internal command */
462
    if (cmd_process(rmod_seg, *rmod_envseg, cmdline, BUFFER) >= -1) {
471
    if (cmd_process(rmod, *rmod_envseg, cmdline, BUFFER) >= -1) {
463
      /* internal command executed */
472
      /* internal command executed */
464
      redir_revert(); /* revert stdout (in case it was redirected) */
473
      redir_revert(); /* revert stdout (in case it was redirected) */
465
      continue;
474
      continue;
466
    }
475
    }
467
 
476
 
Line 473... Line 482...
473
 
482
 
474
    /* execvp() replaces the current process by the new one
483
    /* execvp() replaces the current process by the new one
475
    if I am still alive then external command failed to execute */
484
    if I am still alive then external command failed to execute */
476
    outputnl("Bad command or file name");
485
    outputnl("Bad command or file name");
477
 
486
 
478
  } while ((cfg.flags & FLAG_EXEC_AND_QUIT) == 0);
487
  } while ((rmod->flags & FLAG_EXEC_AND_QUIT) == 0);
479
 
488
 
480
  sayonara(rmod_seg);
489
  sayonara(rmod);
481
  return(0);
490
  return(0);
482
}
491
}