Subversion Repositories SvarDOS

Rev

Rev 533 | Rev 536 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 533 Rev 535
Line 52... Line 52...
52
    outputnl("IF [NOT] EXIST filename command");
52
    outputnl("IF [NOT] EXIST filename command");
53
    outputnl("");
53
    outputnl("");
54
    outputnl("NOT               command is executed only if condition is NOT met");
54
    outputnl("NOT               command is executed only if condition is NOT met");
55
    outputnl("ERRORLEVEL num    condition: last program returned an exit code >= num");
55
    outputnl("ERRORLEVEL num    condition: last program returned an exit code >= num");
56
    outputnl("string1==string2  condition: both strings must be equal");
56
    outputnl("string1==string2  condition: both strings must be equal");
57
    outputnl("EXIST filename    condition: filename exists");
57
    outputnl("EXIST filename    condition: filename exists (wildcards accepted)");
58
    outputnl("command           command to carry out if condition is met.");
58
    outputnl("command           command to carry out if condition is met.");
59
    return(CMD_OK);
59
    return(CMD_OK);
60
  }
60
  }
61
 
61
 
62
  /* negation? */
62
  /* negation? */
Line 78... Line 78...
78
    }
78
    }
79
    JMP_NEXT_ARG(s);
79
    JMP_NEXT_ARG(s);
80
    if (*s == 0) goto SYNTAX_ERR;
80
    if (*s == 0) goto SYNTAX_ERR;
81
    /* is errorlevel matching? */
81
    /* is errorlevel matching? */
82
    if (i <= *rmod_exitcode) negflag ^= 1;
82
    if (i <= *rmod_exitcode) negflag ^= 1;
83
    if (negflag) { /* let's exec command (write it to start of cmdline and exec again) */
83
    if (negflag) goto EXEC_S_CMD;
84
      memmove((void *)(p->cmdline), s, strlen(s) + 1);  /* cmdline and s share the same memory! */
-
 
85
      return(CMD_CHANGED);
84
    return(CMD_OK);
86
    }
85
  }
-
 
86
 
-
 
87
  /* IF EXIST fname (or wildcard)
-
 
88
   * TODO: checking for a file on an empty diskette drive should NOT lead bother
-
 
89
   *       the user with the stupid 'retry, abort, fail' query! */
-
 
90
  if (imatchlim(s, "EXIST ", 6)) {
-
 
91
    struct DTA *dta = (void *)(0x80); /* default dta location */
-
 
92
    JMP_NEXT_ARG(s);
-
 
93
    /* copy filename to buffer */
-
 
94
    for (i = 0; (s[i] != ' ') && (s[i] != 0); i++) p->BUFFER[i] = s[i];
-
 
95
    p->BUFFER[i] = 0;
-
 
96
    /* move s to exec command */
-
 
97
    JMP_NEXT_ARG(s);
-
 
98
    if (*s == 0) goto SYNTAX_ERR;
-
 
99
    /* does file exist? */
-
 
100
    if (findfirst(dta, p->BUFFER, 0) == 0) negflag ^= 1;
-
 
101
    if (negflag) goto EXEC_S_CMD;
87
    return(CMD_OK);
102
    return(CMD_OK);
88
  }
103
  }
89
 
104
 
90
  /* TODO IF EXISTS fname */
-
 
91
  /* TODO IF str1==str2 */
105
  /* TODO IF str1==str2 */
92
 
106
 
93
  SYNTAX_ERR:
107
  SYNTAX_ERR:
94
 
108
 
95
  /* invalid syntax */
109
  /* invalid syntax */
96
  outputnl("Syntax error");
110
  outputnl("Syntax error");
97
 
111
 
98
  return(CMD_FAIL);
112
  return(CMD_FAIL);
-
 
113
 
-
 
114
  /* let's exec command (write it to start of cmdline and parse again) */
-
 
115
  EXEC_S_CMD:
-
 
116
  memmove((void *)(p->cmdline), s, strlen(s) + 1);  /* cmdline and s share the same memory! */
-
 
117
  return(CMD_CHANGED);
99
}
118
}