Subversion Repositories SvarDOS

Rev

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

Rev 532 Rev 533
Line 35... Line 35...
35
 
35
 
36
 
36
 
37
#define JMP_NEXT_ARG(s) while ((*s != ' ') && (*s != 0)) s++; while (*s == ' ') s++;
37
#define JMP_NEXT_ARG(s) while ((*s != ' ') && (*s != 0)) s++; while (*s == ' ') s++;
38
 
38
 
39
 
39
 
40
static int cmd_if(struct cmd_funcparam *p) {
40
static enum cmd_result cmd_if(struct cmd_funcparam *p) {
41
  unsigned char negflag = 0;
41
  unsigned char negflag = 0;
42
  unsigned short i;
42
  unsigned short i;
43
  const char *s = p->cmdline + p->argoffset;
43
  const char *s = p->cmdline + p->argoffset;
44
 
44
 
45
  /* help screen ONLY if /? is the only argument - I do not want to output
45
  /* help screen ONLY if /? is the only argument - I do not want to output
Line 54... Line 54...
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");
58
    outputnl("command           command to carry out if condition is met.");
58
    outputnl("command           command to carry out if condition is met.");
59
    return(-1);
59
    return(CMD_OK);
60
  }
60
  }
61
 
61
 
62
  /* negation? */
62
  /* negation? */
63
  if (imatchlim(s, "NOT ", 4)) {
63
  if (imatchlim(s, "NOT ", 4)) {
64
    negflag = 1;
64
    negflag = 1;
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) {
83
    if (negflag) { /* let's exec command (write it to start of cmdline and exec again) */
84
      output("EXEC (TO BE IMPLEMENTED): ");
84
      memmove((void *)(p->cmdline), s, strlen(s) + 1);  /* cmdline and s share the same memory! */
85
      outputnl(s);
85
      return(CMD_CHANGED);
86
    }
86
    }
87
    return(-1);
87
    return(CMD_OK);
88
  }
88
  }
89
 
89
 
90
  /* TODO IF EXISTS fname */
90
  /* TODO IF EXISTS fname */
91
  /* TODO IF str1==str2 */
91
  /* TODO IF str1==str2 */
92
 
92
 
93
  SYNTAX_ERR:
93
  SYNTAX_ERR:
94
 
94
 
95
  /* invalid syntax */
95
  /* invalid syntax */
96
  outputnl("Syntax error");
96
  outputnl("Syntax error");
97
 
97
 
98
  return(-1);
98
  return(CMD_FAIL);
99
}
99
}