Subversion Repositories SvarDOS

Rev

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

Rev 536 Rev 990
Line 1... Line 1...
1
/* This file is part of the SvarCOM project and is published under the terms
1
/* This file is part of the SvarCOM project and is published under the terms
2
 * of the MIT license.
2
 * of the MIT license.
3
 *
3
 *
4
 * Copyright (C) 2021 Mateusz Viste
4
 * Copyright (C) 2021-2022 Mateusz Viste
5
 *
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Line 43... Line 43...
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
46
   * help for ex. for "if %1 == /? echo ..." */
46
   * help for ex. for "if %1 == /? echo ..." */
47
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
47
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
48
    outputnl("Performs conditional processing in batch programs.");
48
    nls_outputnl(35,0); /* "Performs conditional processing in batch programs." */
49
    outputnl("");
49
    outputnl("");
50
    outputnl("IF [NOT] ERRORLEVEL num command");
50
    nls_outputnl(35,1); /* "IF [NOT] ERRORLEVEL num command" */
51
    outputnl("IF [NOT] string1==string2 command");
51
    nls_outputnl(35,2); /* "IF [NOT] string1==string2 command" */
52
    outputnl("IF [NOT] EXIST filename command");
52
    nls_outputnl(35,3); /* "IF [NOT] EXIST filename command" */
53
    outputnl("");
53
    outputnl("");
54
    outputnl("NOT               command is executed only if condition is NOT met");
54
    nls_outputnl(35,4); /* "NOT               command is executed only if condition is NOT met" */
55
    outputnl("ERRORLEVEL num    condition: last program returned an exit code >= num");
55
    nls_outputnl(35,5); /* "ERRORLEVEL num    condition: last program returned an exit code >= num" */
56
    outputnl("string1==string2  condition: both strings must be equal");
56
    nls_outputnl(35,6); /* "string1==string2  condition: both strings must be equal" */
57
    outputnl("EXIST filename    condition: filename exists (wildcards accepted)");
57
    nls_outputnl(35,7); /* "EXIST filename    condition: filename exists (wildcards accepted)" */
58
    outputnl("command           command to carry out if condition is met.");
58
    nls_outputnl(35,8); /* "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? */
63
  if (imatchlim(s, "NOT ", 4)) {
63
  if (imatchlim(s, "NOT ", 4)) {
Line 124... Line 124...
124
    goto EXEC_S_CMD_IF_NEGFLAG_SET;
124
    goto EXEC_S_CMD_IF_NEGFLAG_SET;
125
  }
125
  }
126
 
126
 
127
  /* invalid syntax */
127
  /* invalid syntax */
128
  SYNTAX_ERR:
128
  SYNTAX_ERR:
129
  outputnl("Syntax error");
129
  nls_outputnl(0,1); /* "Invalid syntax" */
130
  return(CMD_FAIL);
130
  return(CMD_FAIL);
131
 
131
 
132
  /* let's exec command (write it to start of cmdline and parse again) */
132
  /* let's exec command (write it to start of cmdline and parse again) */
133
  EXEC_S_CMD_IF_NEGFLAG_SET:
133
  EXEC_S_CMD_IF_NEGFLAG_SET:
134
  if (*s == 0) goto SYNTAX_ERR;
134
  if (*s == 0) goto SYNTAX_ERR;