Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 1069 → Rev 1070

/svarcom/trunk/cmd/for.c
55,6 → 55,26
* initialization. Actual execution happens within command.c.
*/
 
 
/* normalizing for-loop pattern-list separators.
* returns a space char if c is a for-pattern separator, c otherwise */
static char cmd_for_sepnorm(char c) {
/* the list of valid delimiters has been researched and kindly shared by Robert
* Riebisch via the ticket at https://osdn.net/projects/svardos/ticket/44058 */
switch (c) {
case ' ':
case '\t':
case ';':
case ',':
case '/':
case '=':
return(' '); /* normalize FOR-loop separators to a space */
default: /* anything else is kept as-is */
return(c);
}
}
 
 
static enum cmd_result cmd_for(struct cmd_funcparam *p) {
struct forctx *f = (void *)(p->BUFFER);
unsigned short i;
100,10 → 120,13
while (f->cmd[i] == ' ') i++;
if (f->cmd[i] != '(') goto INVALID_SYNTAX;
i++;
while (f->cmd[i] == ' ') i++;
while (cmd_for_sepnorm(f->cmd[i]) == ' ') i++;
f->nextpat = i;
/* look for patterns end */
while ((f->cmd[i] != ')') && (f->cmd[i] != 0)) i++;
/* look for patterns end and normalize all separators to a space */
while ((f->cmd[i] != ')') && (f->cmd[i] != 0)) {
f->cmd[i] = cmd_for_sepnorm(f->cmd[i]);
i++;
}
if (f->cmd[i] != ')') goto INVALID_SYNTAX;
f->cmd[i++] = 0; /* terminate patterns and move to next field */
 
/svarcom/trunk/command.c
768,7 → 768,10
unsigned short i, t;
struct DTA *dta = (void *)0x80; /* default DTA at 80h in PSP */
char *fnameptr = dta->fname;
char *pathprefix = BUFFER + 256;
 
*pathprefix = 0;
 
TRYAGAIN:
 
/* dta_inited: FindFirst() or FindNext()? */
779,27 → 782,17
t = 0;
for (i = 0;; i++) {
BUFFER[i] = forloop->cmd[forloop->nextpat + i];
/* look for a delimiter - the list of valid delimiters has been
* researched and kindly shared by Robert Riebisch via the ticket
* at https://osdn.net/projects/svardos/ticket/44058 */
switch (BUFFER[i]) {
case ' ':
case '\t':
case ';':
case ',':
case '/':
case '=':
BUFFER[i] = 0;
t = 1;
break;
case 0: /* end of patterns list */
t = 2;
break;
default: /* quit if I got a pattern already */
if (t == 1) t = 2;
break;
/* is this a delimiter? (all delimiters are already normalized to a space here) */
if (BUFFER[i] == ' ') {
BUFFER[i] = 0;
t = 1;
} else if (BUFFER[i] == 0) {
/* end of patterns list */
break;
} else {
/* quit if I got a pattern already */
if (t == 1) break;
}
if (t == 2) break;
}
 
if (i == 0) return(-1);
839,6 → 832,18
/* copy updated DTA to rmod */
_fmemcpy(&(forloop->dta), dta, sizeof(*dta));
 
/* prefill pathprefix with the prefix (path) of the files */
{
short lastbk = -1;
char far *c = forloop->cmd + forloop->curpat;
for (i = 0;; i++) {
pathprefix[i] = c[i];
if (pathprefix[i] == '\\') lastbk = i;
if ((pathprefix[i] == ' ') || (pathprefix[i] == 0)) break;
}
pathprefix[lastbk+1] = 0;
}
 
SKIP_DTA:
 
/* fill res with command, replacing varname by actual filename */
847,17 → 852,9
i = 0;
for (;;) {
if ((forloop->cmd[forloop->exec + t] == '%') && (forloop->cmd[forloop->exec + t + 1] == forloop->varname)) {
short lastbk = i;
char far *c = forloop->cmd + forloop->curpat;
for (;;) {
res[i] = *c;
c++;
if (res[i] == '\\') lastbk = i;
if ((res[i] == ' ') || (res[i] == 0)) break;
i++;
}
strcpy(res + lastbk, fnameptr);
for (i = lastbk; res[i] != 0; i++);
strcpy(res + i, pathprefix);
strcat(res + i, fnameptr);
for (; res[i] != 0; i++);
t += 2;
} else {
res[i] = forloop->cmd[forloop->exec + t];