Subversion Repositories SvarDOS

Rev

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

Rev 982 Rev 1023
Line 54... Line 54...
54
 * This file only provides the help screen of FOR, as well as the FOR-context
54
 * This file only provides the help screen of FOR, as well as the FOR-context
55
 * initialization. Actual execution happens within command.c.
55
 * initialization. Actual execution happens within command.c.
56
 */
56
 */
57
 
57
 
58
static enum cmd_result cmd_for(struct cmd_funcparam *p) {
58
static enum cmd_result cmd_for(struct cmd_funcparam *p) {
-
 
59
  struct forctx *f = (void *)(p->BUFFER);
-
 
60
  unsigned short i;
-
 
61
 
-
 
62
  /* forbid nested FORs */
-
 
63
  if (p->rmod->forloop) {
-
 
64
    nls_outputnl(18,7); /* FOR cannot be nested */
-
 
65
    return(CMD_FAIL);
-
 
66
  }
59
 
67
 
60
  /* help screen ONLY if /? is the only argument */
68
  /* help screen ONLY if /? is the only argument */
61
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
69
  if ((p->argc == 1) && (imatch(p->argv[0], "/?"))) {
62
    nls_outputnl(18,0); /* "Runs a specified command for each file in a set of files" */
70
    nls_outputnl(18,0); /* "Runs a specified command for each file in a set of files" */
63
    outputnl("");
71
    outputnl("");
Line 70... Line 78...
70
    outputnl("");
78
    outputnl("");
71
    nls_outputnl(18,6); /* "To use FOR in a batch program, use %%variable instead of %variable" */
79
    nls_outputnl(18,6); /* "To use FOR in a batch program, use %%variable instead of %variable" */
72
    return(CMD_OK);
80
    return(CMD_OK);
73
  }
81
  }
74
 
82
 
-
 
83
  /* clear out struct and copy command line to it */
-
 
84
  bzero(f, sizeof(*f));
-
 
85
  strcpy(f->cmd, p->cmdline);
-
 
86
 
-
 
87
  /* locate the %varname */
-
 
88
  i = p->argoffset;
-
 
89
  while (f->cmd[i] == ' ') i++;
75
  outputnl("FOR IS NOT IMPLEMENTED YET");
90
  if (f->cmd[i] != '%') goto INVALID_SYNTAX;
-
 
91
  f->varname = i;
-
 
92
  /* find the end of varname (space) */
-
 
93
  while ((f->cmd[i] != ' ') && (f->cmd[i] != 0)) i++;
-
 
94
  if (f->cmd[i] != ' ') goto INVALID_SYNTAX;
-
 
95
  f->cmd[i++] = 0; /* terminate varname and move to next field */
-
 
96
 
-
 
97
  /* look (and skip) the "IN" part */
-
 
98
  while (f->cmd[i] == ' ') i++;
-
 
99
  if (((f->cmd[i] & 0xDF) != 'I') && ((f->cmd[i+1] & 0xDF) != 'N') && (f->cmd[i+2] != ' ')) goto INVALID_SYNTAX;
-
 
100
  i += 3;
-
 
101
 
-
 
102
  /* look for patterns start */
-
 
103
  while (f->cmd[i] == ' ') i++;
-
 
104
  if (f->cmd[i] != '(') goto INVALID_SYNTAX;
-
 
105
  i++;
-
 
106
  while (f->cmd[i] == ' ') i++;
-
 
107
  f->curpat = i;
-
 
108
  /* look for patterns end */
-
 
109
  while ((f->cmd[i] != ')') && (f->cmd[i] != 0)) i++;
-
 
110
  if (f->cmd[i] != ')') goto INVALID_SYNTAX;
-
 
111
  f->cmd[i++] = 0; /* terminate patterns and move to next field */
-
 
112
 
-
 
113
  /* look (and skip) the "DO" part */
-
 
114
  while (f->cmd[i] == ' ') i++;
-
 
115
  if (((f->cmd[i] & 0xDF) != 'D') && ((f->cmd[i+1] & 0xDF) != 'O') && (f->cmd[i+2] != ' ')) goto INVALID_SYNTAX;
-
 
116
  i += 3;
-
 
117
  while (f->cmd[i] == ' ') i++;
-
 
118
 
-
 
119
  /* rest is the exec string */
-
 
120
  f->exec = i;
-
 
121
 
-
 
122
  /* alloc memory for the forctx context and copy f to it */
-
 
123
  p->rmod->forloop = rmod_fcalloc(sizeof(*f), p->rmod->rmodseg, "SVFORCTX");
-
 
124
  if (p->rmod->forloop == NULL) {
-
 
125
    nls_outputnl_doserr(8);
-
 
126
    return(CMD_FAIL);
-
 
127
  }
-
 
128
  _fmemcpy(p->rmod->forloop, f, sizeof(*f));
76
 
129
 
77
  return(CMD_OK);
130
  return(CMD_OK);
-
 
131
 
-
 
132
  INVALID_SYNTAX:
-
 
133
  nls_outputnl(0,1); /* "Invalid syntax" */
-
 
134
  return(CMD_FAIL);
78
}
135
}