Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 468 → Rev 469

/svarcom/trunk/command.c
400,11 → 400,6
}
 
RUNCMDFILE:
/* TODO special handling of batch files */
if ((ext != NULL) && (imatch(ext, "bat"))) {
outputnl("batch processing not supported yet");
return;
}
 
/* find cmdtail */
cmdtail = cmdline;
413,6 → 408,18
cmdtail++;
}
 
/* special handling of batch files */
if ((ext != NULL) && (imatch(ext, "bat"))) {
/* copy truename of the bat file to rmod buff */
for (i = 0; cmdfile[i] != 0; i++) rmod->batfile[i] = cmdfile[i];
rmod->batfile[i] = 0;
/* copy args of the bat file to rmod buff */
for (i = 0; cmdtail[i] != 0; i++) rmod->batargs[i] = cmdtail[i];
/* reset the 'next line to execute' counter */
rmod->batnextline = 0;
return;
}
 
/* copy full filename to execute */
for (i = 0; cmdfile[i] != 0; i++) rmod_execprog[i] = cmdfile[i];
rmod_execprog[i] = 0;
512,6 → 519,34
}
 
 
/* fetches a line from batch file and write it to buff, increments
* rmod counter on success. returns NULL on failure.
* buff must start with a length byte but the returned pointer must
* skip it. */
char far *getbatcmd(char far *buff, struct rmod_props far *rmod) {
unsigned short i;
buff++; /* make room for the len byte */
/* TODO temporary hack to display a dummy message */
if (rmod->batnextline == 0) {
char *msg = "ECHO batch files not supported yet";
for (i = 0; msg[i] != 0; i++) buff[i] = msg[i];
buff[i] = 0;
buff[-1] = i;
} else {
rmod->batfile[0] = 0;
return(NULL);
}
/* open file */
/* read until awaiting line */
/* copy line to buff */
/* close file */
/* */
rmod->batnextline++;
if (rmod->batnextline == 0) rmod->batfile[0] = 0; /* max line count reached */
return(buff);
}
 
 
int main(void) {
static struct config cfg;
static unsigned short far *rmod_envseg;
536,10 → 571,7
/* if I was spawned by rmod and FLAG_EXEC_AND_QUIT is set, then I should
* die asap, because the command has been executed already, so I no longer
* have a purpose in life */
if (rmod->flags & FLAG_EXEC_AND_QUIT) {
printf("rmod + FLAG_EXEC_AND_QUIT\r\n");
sayonara(rmod);
}
if (rmod->flags & FLAG_EXEC_AND_QUIT) sayonara(rmod);
}
 
rmod_envseg = MK_FP(rmod->rmodseg, RMOD_OFFSET_ENVSEG);
593,8 → 625,14
cmdline[(unsigned short)(cmdline[-1])] = '\r';
}
 
/* wait for user command line */
cmdline_getinput(FP_SEG(rmod->inputbuf), FP_OFF(rmod->inputbuf));
/* if batch file is being executed -> fetch next line */
if (rmod->batfile[0] != 0) {
cmdline = getbatcmd(BUFFER + sizeof(BUFFER) - 130, rmod);
if (cmdline == NULL) continue;
} else {
/* interactive mode: wait for user command line */
cmdline_getinput(FP_SEG(rmod->inputbuf), FP_OFF(rmod->inputbuf));
}
 
/* if nothing entered, loop again (but without appending an extra CR/LF) */
if (cmdline[-1] == 0) goto SKIP_NEWLINE;
626,6 → 664,8
 
/* if here, then this was not an internal command */
run_as_external(BUFFER, cmdline, *rmod_envseg, rmod);
/* perhaps this is a newly launched BAT file */
if ((rmod->batfile[0] != 0) && (rmod->batnextline == 0)) goto SKIP_NEWLINE;
 
/* revert stdout (in case it was redirected) */
redir_revert();
/svarcom/trunk/internal.txt
19,17 → 19,17
=== Batch files support ======================================================
 
When SvarCOM executes a command, it checks first if it has a *.BAT extension.
If so, it switches into 'batch-mode':
- allocates a batch 'node', which is a memory area that contains the
path and filename of the batch file, as well as the number of the "next
line to be executed".
- the batch node is attached to the batch chain (a pointer owned by rmod) if
the batch file was CALLed from within another batch file, and replaced the
current batch if it was simply executed from another batch file.
If so, it switches into 'batch-processing' mode:
 
When the rmod batch pointer is non-NULL, SvarCOM does not ask the user for a
command. Instead, it opens the batch file, jumps to the "line line to be
executed" and loads the command from there, incrementing "next line" in the
- Writes the batch filename into its persistent (rmod-owned) buffer, along
with a line counter that holds the number of "next line to be executed".
- When a batch file CALLs another batch file, then a new SvarCOM instance is
started. This ensures that once the CALLed batch ends, processing will
return to the original batch file at the correct position.
 
When the batch buffer is non-zero, SvarCOM does not ask the user for a
command. Instead, it opens the batch file, jumps to the "next line to be
executed" and loads the command from there, incrementing this counter in the
process. The maximum length of a batch file is of 65535 lines (any lines after
this limit will be ignored).
 
/svarcom/trunk/rmodinit.h
35,6 → 35,9
unsigned short origenvseg; /* original environment segment */
unsigned char flags; /* command line parameters */
unsigned char echoflag; /* ECHO ON / ECHO OFF */
char batfile[130]; /* truename of batch file being processed */
char batargs[130]; /* arguments of the processed batch files */
unsigned short batnextline; /* next line of bat file to be executed */
};
 
#define RMOD_OFFSET_ENVSEG 0x2C /* stored in rmod's PSP */