Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 535 → Rev 536

/svarcom/trunk/cmd/if.c
76,12 → 76,11
} else {
atous(&i, s);
}
/* move s to command */
JMP_NEXT_ARG(s);
if (*s == 0) goto SYNTAX_ERR;
/* is errorlevel matching? */
if (i <= *rmod_exitcode) negflag ^= 1;
if (negflag) goto EXEC_S_CMD;
return(CMD_OK);
goto EXEC_S_CMD_IF_NEGFLAG_SET;
}
 
/* IF EXIST fname (or wildcard)
93,26 → 92,47
/* copy filename to buffer */
for (i = 0; (s[i] != ' ') && (s[i] != 0); i++) p->BUFFER[i] = s[i];
p->BUFFER[i] = 0;
/* move s to exec command */
/* move s to command */
JMP_NEXT_ARG(s);
if (*s == 0) goto SYNTAX_ERR;
if (*s == 0) goto SYNTAX_ERR; /* check now to avoid moving the diskette drive if syntax bad anyway */
/* does file exist? */
if (findfirst(dta, p->BUFFER, 0) == 0) negflag ^= 1;
if (negflag) goto EXEC_S_CMD;
return(CMD_OK);
goto EXEC_S_CMD_IF_NEGFLAG_SET;
}
 
/* TODO IF str1==str2 */
/* IF str1==str2 ? (and if that's not it, then it's a syntax error) */
if (strstr(s, "==") != NULL) {
/* copy first argument to BUFF, until first '=' or space */
for (i = 0; (s[i] != '=') && (s[i] != ' '); i++) p->BUFFER[i] = s[i];
/* 1st arg cannot be empty */
if (i == 0) goto SYNTAX_ERR;
/* terminate buff string and move s forward to the equality char (or space) */
p->BUFFER[i++] = 0;
s += i;
while (*s == ' ') s++;
/* if second char is not a '=' then syntax error (equality sign is not
* allowed in first string) */
if (*s != '=') goto SYNTAX_ERR;
/* skip all trailing equality chars (MSDOS accepts many of them, ie all
* these are fine: "dupa==dupa", "dupa===dupa", "dupa====dupa", etc) */
while (*s == '=') s++;
while (*s == ' ') s++; /* skip any leading spaces */
/* move along until space or NULL terminator, checking equality */
for (i = 0; (p->BUFFER[i] != 0) && (p->BUFFER[i] == s[i]); i++);
if ((p->BUFFER[i] == 0) && (s[i] == ' ')) negflag ^= 1;
JMP_NEXT_ARG(s);
goto EXEC_S_CMD_IF_NEGFLAG_SET;
}
 
/* invalid syntax */
SYNTAX_ERR:
 
/* invalid syntax */
outputnl("Syntax error");
 
return(CMD_FAIL);
 
/* let's exec command (write it to start of cmdline and parse again) */
EXEC_S_CMD:
EXEC_S_CMD_IF_NEGFLAG_SET:
if (*s == 0) goto SYNTAX_ERR;
if (negflag == 0) return(CMD_OK);
memmove((void *)(p->cmdline), s, strlen(s) + 1); /* cmdline and s share the same memory! */
return(CMD_CHANGED);
}
/svarcom/trunk/history.txt
3,13 → 3,14
=== SvarCOM's history / changelog ===
 
 
=== ver 2021.1 (xxxx.xx.xx) ==================================================
=== ver 2021.1 (xx.xx.2021) ==================================================
 
- prompt fixed when current drive becomes invalid (eg. empty diskette drive)
- DIR: fixed /P pagination in wide mode
- implemented IF command (IF EXIST, IF ERRORLEVEL, IF str==str)
 
 
=== ver 2021.0 (2021.11.24) ==================================================
=== ver 2021.0 (24.11.2021) ==================================================
 
- first public release, after roughly a month of work
 
/svarcom/trunk/todo.txt
11,7 → 11,7
DIR /A
ctrl+break handler
int 24h handler (abort, retry, fail, ignore)
advanced batch constructs: CALL, :labels, FOR, GOTO, IF EXIST/ERRORLEVEL
advanced batch constructs: CALL, FOR, GOTO
IF EXIST on an empty drive should not lead to the 'Abort, Retry, Fail' prompt