Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 1022 → Rev 1023

/svarcom/trunk/cmd/for.c
56,7 → 56,15
*/
 
static enum cmd_result cmd_for(struct cmd_funcparam *p) {
struct forctx *f = (void *)(p->BUFFER);
unsigned short i;
 
/* forbid nested FORs */
if (p->rmod->forloop) {
nls_outputnl(18,7); /* FOR cannot be nested */
return(CMD_FAIL);
}
 
/* help screen ONLY if /? is the only argument */
if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
nls_outputnl(18,0); /* "Runs a specified command for each file in a set of files" */
72,7 → 80,56
return(CMD_OK);
}
 
outputnl("FOR IS NOT IMPLEMENTED YET");
/* clear out struct and copy command line to it */
bzero(f, sizeof(*f));
strcpy(f->cmd, p->cmdline);
 
/* locate the %varname */
i = p->argoffset;
while (f->cmd[i] == ' ') i++;
if (f->cmd[i] != '%') goto INVALID_SYNTAX;
f->varname = i;
/* find the end of varname (space) */
while ((f->cmd[i] != ' ') && (f->cmd[i] != 0)) i++;
if (f->cmd[i] != ' ') goto INVALID_SYNTAX;
f->cmd[i++] = 0; /* terminate varname and move to next field */
 
/* look (and skip) the "IN" part */
while (f->cmd[i] == ' ') i++;
if (((f->cmd[i] & 0xDF) != 'I') && ((f->cmd[i+1] & 0xDF) != 'N') && (f->cmd[i+2] != ' ')) goto INVALID_SYNTAX;
i += 3;
 
/* look for patterns start */
while (f->cmd[i] == ' ') i++;
if (f->cmd[i] != '(') goto INVALID_SYNTAX;
i++;
while (f->cmd[i] == ' ') i++;
f->curpat = i;
/* look for patterns end */
while ((f->cmd[i] != ')') && (f->cmd[i] != 0)) i++;
if (f->cmd[i] != ')') goto INVALID_SYNTAX;
f->cmd[i++] = 0; /* terminate patterns and move to next field */
 
/* look (and skip) the "DO" part */
while (f->cmd[i] == ' ') i++;
if (((f->cmd[i] & 0xDF) != 'D') && ((f->cmd[i+1] & 0xDF) != 'O') && (f->cmd[i+2] != ' ')) goto INVALID_SYNTAX;
i += 3;
while (f->cmd[i] == ' ') i++;
 
/* rest is the exec string */
f->exec = i;
 
/* alloc memory for the forctx context and copy f to it */
p->rmod->forloop = rmod_fcalloc(sizeof(*f), p->rmod->rmodseg, "SVFORCTX");
if (p->rmod->forloop == NULL) {
nls_outputnl_doserr(8);
return(CMD_FAIL);
}
_fmemcpy(p->rmod->forloop, f, sizeof(*f));
 
return(CMD_OK);
 
INVALID_SYNTAX:
nls_outputnl(0,1); /* "Invalid syntax" */
return(CMD_FAIL);
}
/svarcom/trunk/command.c
45,7 → 45,7
* RMOD should not be accessed as its structure might no longer be in sync
* with what I think it is.
* *** INCREMENT THIS AT EACH NEW SVARCOM RELEASE! *** */
#define BYTE_VERSION 3
#define BYTE_VERSION 4
 
 
struct config {
821,6 → 821,17
}
 
do {
/* am I inside a FOR loop? */
if (rmod->forloop) {
outputnl("FOR IS NOT IMPLEMENTED YET");
/* TODO dta_inited: FindFirst() or FindNext()? */
/* TODO read result */
/* TODO end of results? move to next pattern */
/* free used memory */
rmod_ffree(rmod->forloop);
rmod->forloop = NULL;
}
 
/* terminate previous command with a CR/LF if ECHO ON (but not during BAT processing) */
if ((rmod->flags & FLAG_ECHOFLAG) && (rmod->bat == NULL)) outputnl("");
 
/svarcom/trunk/lang/en-utf8.txt
90,6 → 90,7
18.4:command the command to carry out for each matched file.
18.5:parameters parameters or switches for the specified command.
18.6:To use FOR in a batch program, use %%variable instead of %variable.
18.7:FOR cannot be nested
 
# VERIFY
19.0:Tells DOS whether to verify that files are written correctly to disk.
/svarcom/trunk/rmodinit.h
25,6 → 25,8
#ifndef RMODINIT_H
#define RMODINIT_H
 
#include "helpers.h" /* struct DTA definition */
 
#define FLAG_EXEC_AND_QUIT 1
#define FLAG_PERMANENT 2
#define FLAG_ECHOFLAG 4
43,6 → 45,16
struct batctx far *parent; /* parent context if this batch was CALLed */
};
 
/* for context structure used to track the execution of the ongoing FOR loop */
struct forctx {
char cmd[130]; /* copy of the original FOR command */
unsigned short varname; /* cmd offset of the replaceable variable name */
unsigned short curpat; /* cmd offset of currently processed pattern */
unsigned short exec; /* cmd offset of the command to be executed */
struct DTA dta; /* DTA for FindNext on current pattern */
unsigned char dta_inited; /* 0=requires FindFirst 1=FindNext */
};
 
struct rmod_props {
unsigned short rmodseg; /* segment where rmod is loaded */
unsigned long origparent; /* original parent (far ptr) of the shell */
50,7 → 62,8
unsigned char flags; /* command line parameters */
unsigned char version; /* used to detect mismatch between rmod and SvarCOM */
char awaitingcmd[130]; /* command to exec next time (if any) */
struct batctx far *bat;
struct batctx far *bat; /* linked list of bat contexts, if BAT ongoing */
struct forctx far *forloop; /* a single FOR loop structure, if FOR ongoing */
};
 
#define RMOD_OFFSET_ENVSEG 0x2C /* stored in rmod's PSP */