?? batch.c
字號:
}
return(total);
}
MLOCAL BOOLEAN CDECL test_cond(cptr)
BYTE **cptr;
{
BYTE *cmd,*str1, *str2, *ptr;
DTA search;
BOOLEAN not, cond, neg,is_user;
BYTE level;
BYTE c[]=" \n";
WORD attr;
UWORD userid;
LONG val1,val2;
cmd=*cptr;
not = cond = NO; /* Initialise the Flags */
if(!strnicmp(cmd = deblank(cmd), "not", 3)) {
not = YES;
cmd = deblank(cmd+3);
}
switch(if_index(&cmd)) {
/*
* EXIST Option extract the possibly ambiguous filename
* and check if it exists.
*/
case 0:
cmd = deblank(get_filename(heap(), cmd, YES));
cond = !ms_x_first(heap(), ATTR_STD|ATTR_HID, &search);
break;
/*
* DIREXIST Option checks if the given directory exists
*/
case 1:
cmd = deblank(get_filename(heap(), cmd, YES));
attr = ms_x_chmod(heap(), ATTR_ALL, 0);
if (attr < 0) cond = FALSE;
else cond = (attr & 0x10);
break;
/*
* ERRORLEVEL Option extract the decimal number from the
* command line.
*/
case 2:
level = 0;
neg = FALSE;
if(*cmd =='-') {
neg = TRUE;
cmd++;
}
if(!isdigit(*cmd)) { /* SYNTAX error if the */
syntax(); /* first character is not a */
return FALSE; /* digit. */
}
while(isdigit(*cmd))
level = level * 10 + (*cmd++ - '0');
level = level & 0x00FF;
if (neg) level = -level;
cond = (level<=(err_ret & 0x00FF));
break;
/*RG-02*/
#if !defined(NOXBATCH)
#if (defined(CDOSTMP) || defined(CDOS))
/*
* KEY ["string"] [==] [""] Search for the string "string" and
* display it if it exists, then read a key and echo it.
* However, if the string to match is null "" then do a keyboard
* status check and return TRUE if there is no key there
*/
case 3:
cmd = deblank(cmd);
ptr=cmd;
if (display_string(&ptr)!=0)
return FALSE;
cmd = deblank(ptr);
while(*cmd == '=') /* Remove any "=" string */
cmd++;
cmd = deblank(cmd);
if ((*cmd==0)||(*(cmd+1)!=' ')) { /* check for condition */
syntax();
return FALSE;
}
/* read a character from the keyboard */
c[0]=bdos(C_RAWIO, 0xFD); /* Get a character from console */
/* echo the char typed */
if (echoflg) /* echo to screen if wanted */
putc(c[0]);
crlf(); /* print cr/lf */
/* check if it matches */
if((tolower(c[0])==*cmd)||(toupper(c[0])==*cmd))
cond=TRUE;
else
cond=FALSE;
/* skip the condition */
while (*cmd!=' ')
cmd++; /* skip the char */
break;
#endif
#if !defined (NOSECURITY) && (defined(CDOSTMP) || defined(CDOS))
/*
* USERID Option extract the 4 digit hex user id
* and check if it is us.
*/
case 4:
if (!login_enabled())
return FALSE;
cmd = deblank(cmd);
if(aschextobin(cmd)==get_user_on_station())
cond=TRUE;
else
cond=FALSE;
do { /* skip past the user id */
if ((*cmd>='0' && *cmd<='9')
||(tolower(*cmd)>='a' && tolower(*cmd)<='f'))
cmd++; /* skip the hex digit */
else {
syntax();
return FALSE;
}
} while (*cmd!=' ');
break;
/*
* LOGINNAME Option extract the loginname and check if it is us.
*/
case 5:
if (!login_enabled())
return FALSE;
is_user=TRUE;
/*
* GROUPNAME Option extract the loginname and check if it is us.
*/
case 6:
if (!login_enabled())
return FALSE;
cmd = deblank(cmd);
if(aschextobin(user_info.userid)!=get_user_on_station()) {
if(get_user_info(get_user_on_station())!=0) {
syntax();
is_user=cond=FALSE;
return FALSE;
}
}
if((is_user==TRUE)&&(strncmp(strlwr(cmd),strlwr(user_info.loginname),strlen(user_info.loginname))==0)) {
cond=TRUE;
cmd+=strlen(user_info.loginname);
}
else if((is_user!=TRUE)&&(strncmp(strlwr(cmd),strlwr(user_info.groupname),strlen(user_info.groupname))==0)) {
cond=TRUE;
cmd+=strlen(user_info.groupname);
}
else {
cond=FALSE;
while (*cmd!=' ')
cmd++; /* skip the name */
}
if (*cmd!=' ') {
is_user=cond=FALSE;
}
is_user=FALSE;
break;
#endif
#endif /*NOXBATCH*/
/*RG-02-end*/
/*
* String comparison option.
*/
default:
str1 = cmd; /* Extract String 1 */
while ((!is_blank(cmd)) && (*cmd != '=') &&
((*cmd != '!') || (cmd[1]!= '=')) &&
(*cmd != '<') && (*cmd != '>')) {
cmd = skip_char(cmd);
}
str2 = cmd;
cmd = deblank(cmd);
attr = get_operator(cmd++);
if (attr == -1) {
syntax();
return(FALSE);
}
*str2 = 0;
if (*cmd == '=' || *cmd == '>') cmd++;
cmd = deblank(cmd);
str2 = cmd;
while (!is_blank(cmd)) cmd = skip_char(cmd);
*cmd++ = 0;
if (*str1 == '#') {
val1 = get_decimal(str1);
val2 = get_decimal(str2);
switch(attr) {
case OP_EQ: cond = (val1==val2); break;
case OP_NE: cond = (val1!=val2); break;
case OP_LT: cond = (val1<val2); break;
case OP_LE: cond = (val1<=val2); break;
case OP_GT: cond = (val1>val2); break;
case OP_GE: cond = (val1>=val2); break;
}
}
else switch(attr) {
case OP_EQ:
cond = (strcmp(str1,str2) == 0);
break;
case OP_NE:
cond = (strcmp(str1,str2) != 0);
break;
case OP_LT:
cond = (strcmp(str1,str2) < 0);
break;
case OP_LE:
cond = (strcmp(str1,str2) <= 0);
break;
case OP_GT:
cond = (strcmp(str1,str2) > 0);
break;
case OP_GE:
cond = (strcmp(str1,str2) >= 0);
break;
}
break;
}
if(not) /* if negated condition */
cond = !cond;
*cptr=cmd;
return cond; /* write result back */
}
#if !defined(NOXBATCH)
BOOLEAN is_it_or(BYTE *cmd)
{
cmd--;
if ((*cmd != 0) && (*cmd != '\t') && (*cmd != ' '))
return FALSE;
cmd++;
if (strnicmp(cmd, "or", 2) != 0)
return FALSE;
cmd+=2;
if ((*cmd != '\t') && (*cmd != ' '))
return FALSE;
return TRUE;
}
#endif
GLOBAL VOID CDECL cmd_if(cmd)
BYTE *cmd;
{
BOOLEAN cond;
ifcond=cond=test_cond(&cmd);
if(!*deblank(cmd)) { /* and return a SYNTAX error*/
syntax(); /* if it is empty. */
return;
}
if(!cond) {
#if !defined(NOXBATCH)
while (!is_it_or(cmd) &&
(*cmd != 0)) {
if (strnicmp(cmd,"ECHO",4)==0) return;
cmd++;
}
if (*cmd==0) return; /* no OR's so quit now */
if_context = TRUE;
docmd(deblank(cmd), YES); /* New command starts at "or" */
#endif
}
else {
cmd = deblank(cmd);
if (strnicmp(cmd,"AND",3)) {
if (parse(cmd)) return; /* IF won't have been 'parsed' for */
/* > or < redirectors so do it now */
}
if_context = TRUE;
/* Execute command if the */
docmd(cmd, YES); /* condition flag is TRUE */
}
if_context=FALSE;
}
/*RG-03*/
#if !defined(NOXBATCH)
GLOBAL VOID CDECL cmd_or(cmd)
BYTE *cmd;
{
BOOLEAN cond;
BYTE *org_cmd;
cond=test_cond(&cmd);
if(!*deblank(cmd)) { /* and return a SYNTAX error*/
syntax(); /* if it is empty. */
return;
}
if(!cond) {
org_cmd = cmd; /* now look for "OR" */
while (!is_it_or(cmd) &&
(*cmd != 0)) {
if (strnicmp(cmd,"ECHO",4)==0) while(*cmd) cmd++;
else cmd++;
}
if (*cmd==0) { /* oh dear, no ORs */
if (ifcond) /* but so far so good, so do command anyway */
docmd(deblank(org_cmd), YES);
return;
}
docmd(deblank(cmd), YES); /* New command starts at "or" */
return;
}
else {
cmd = deblank(cmd);
if (strnicmp(cmd,"AND",3)) {
if (parse(cmd)) return; /* IF won't have been 'parsed' for */
/* > or < redirectors so do it now */
}
ifcond=cond; /* Execute command if the */
docmd(cmd, YES); /* condition flag is TRUE */
}
}
#endif /*NOXBATCH*/
/*RG-03-end*/
GLOBAL VOID CDECL cmd_for(s)
BYTE *s;
{
FCONTROL *fc;
BYTE *bp1;
fc = (FCONTROL *) heap_get(sizeof(FCONTROL));
/* Allocate Control Struct */
if(forptr) /* and prevent nesting of */
goto for_error; /* FOR Command. */
s = deblank(s); /* Remove leading blanks */
if ((*s++ != '%') || /* Get the FOR variable */
(fc->forvar = *s++) < ' ') /* character and save */
goto for_error;
if(strnicmp(s = deblank(s), "in", 2)) /* Check for the correct */
goto for_error; /* command syntax. */
s = deblank(s+2);
if (*s++ != '(')
goto for_error;
fc->files = (BYTE *)heap(); /* Allocate FOR parameter */
while(*s && *s != ')') { /* buffer and scan the */
bp1 = (BYTE *)heap(); /* command line generating */
/* zero terminated strings */
while(strchr(batch_sep, *s)) /* Skip any separators */
s = skip_char(s);
while( *s != ')' && /* then copy all valid */
!strchr(batch_sep, *s)) /* characters into buffer */
/* then zero terminate */
copy_char(&bp1, &s);
*bp1++ = '\0';
heap_get(strlen(heap()) + 1); /* Preserve String */
}
*(BYTE *)heap_get(1) = '\0'; /* Final String is zero */
/* bytes in length */
s = deblank(s);
if(*s++ != ')')
goto for_error;
if(strnicmp(s = deblank(s), "do", 2))
goto for_error;
if(in_flag & REDIR_ACTIVE) /* If Input redirection has been */
in_flag |= REDIR_FOR; /* enabled for this command force*/
/* it on for the complete command*/
if(out_flag & REDIR_ACTIVE) /* If Output redirection has been*/
out_flag |= REDIR_FOR; /* enabled for this command force*/
/* it on for the complete command*/
fc->cmd = (BYTE *)heap_get(strlen(s = deblank(s+2)) +1);
strcpy(fc->cmd, s);
fc->sflg = NO; /* File matching inactive */
for_flag = YES; /* Turn FOR processing ON */
forptr = fc; /* Save control Structure */
return;
for_error: /* When a Syntax error occurs */
heap_set((BYTE *) fc); /* restore the heap and print */
syntax(); /* an error message. */
return;
}
GLOBAL VOID for_end()
{
if(for_flag) {
heap_set((BYTE *) forptr); /* Terminate FOR processing */
forptr = (FCONTROL *) NULL; /* restore the HEAP and reset */
for_flag = NO; /* control flags. */
}
}
/*.pa*/
/*
* This command generates the displayed prompt based on the contents
* of the string PROMPT= in the environment. Otherwise the default
* prompt string DEFAULT_PROMPT is used.
*/
MLOCAL BOOLEAN prompt_flg = FALSE; /* Prompt Flag */
MLOCAL VOID prompt() /* display command line prompt */
{
REG BYTE *cp;
BYTE buf[MAX_PATHLEN];
BYTE c;
#if !STACK
BYTE cpbuf[MAX_ENVLEN];
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -