Lines Matching defs:cmd
97 register Cmdarg_t* cmd;
149 if (!(cmd = newof(0, Cmdarg_t, 1, n + m)))
155 cmd->id = lib;
156 cmd->disc = disc;
157 cmd->errorf = disc->errorf;
158 if (!(cmd->runf = disc->runf))
159 cmd->runf = cmdrun;
163 s = cmd->buf;
167 cmd->echo = 1;
171 cmd->echo = 1;
179 if (cmd->errorf)
180 (*cmd->errorf)(NiL, cmd, ERROR_SYSTEM|2, "%s: command not found", exe);
183 free(cmd);
191 cmd->insert = strcpy(s, argpat);
192 cmd->insertlen = m - 1;
195 s += sizeof(char**) - (s - cmd->buf) % sizeof(char**);
198 cmd->argv = p;
206 cmd->insertarg = p;
207 argv = cmd->argv;
208 c = *cmd->insert;
211 while ((s = strchr(s, c)) && strncmp(cmd->insert, s, cmd->insertlen))
218 cmd->firstarg = cmd->nextarg = p;
219 cmd->laststr = cmd->nextstr = cmd->buf + n;
220 cmd->argmax = argmax;
221 cmd->flags = disc->flags;
222 cmd->offset = ((cmd->postarg = post) ? (argc - (post - argv)) : 0) + 3;
223 return cmd;
231 cmdflush(register Cmdarg_t* cmd)
237 if (cmd->flags & CMD_EMPTY)
238 cmd->flags &= ~CMD_EMPTY;
239 else if (cmd->nextarg <= cmd->firstarg)
241 if ((cmd->flags & CMD_MINIMUM) && cmd->argcount < cmd->argmax)
243 if (cmd->errorf)
244 (*cmd->errorf)(NiL, cmd, 2, "%d arg command would be too long", cmd->argcount);
247 cmd->total.args += cmd->argcount;
248 cmd->total.commands++;
249 cmd->argcount = 0;
250 if (p = cmd->postarg)
251 while (*cmd->nextarg++ = *p++);
253 *cmd->nextarg = 0;
254 if (s = cmd->insert)
264 a = cmd->firstarg[0];
265 b = (char*)&cmd->nextarg[1];
266 e = cmd->nextstr;
268 m = cmd->insertlen;
269 for (n = 1; cmd->argv[n]; n++)
270 if (t = cmd->insertarg[n])
272 cmd->argv[n] = b;
298 if (cmd->errorf)
299 (*cmd->errorf)(NiL, cmd, 2, "%s: command too large after insert", a);
303 n = (int)(cmd->nextarg - cmd->argv);
304 cmd->nextarg = cmd->firstarg;
305 cmd->nextstr = cmd->laststr;
306 if (cmd->flags & (CMD_QUERY|CMD_TRACE))
308 p = cmd->argv;
312 if (!(cmd->flags & CMD_QUERY))
319 if (cmd->echo)
321 n = (cmd->flags & CMD_NEWLINE) ? '\n' : ' ';
322 for (p = cmd->argv + 1; s = *p++;)
326 else if ((n = (*cmd->runf)(n, cmd->argv, cmd->disc)) == -1)
329 if (cmd->errorf)
330 (*cmd->errorf)(NiL, cmd, ERROR_SYSTEM|2, "%s: command exec error", *cmd->argv);
331 if (cmd->flags & CMD_EXIT)
336 if (cmd->flags & CMD_EXIT)
339 else if (!(cmd->flags & CMD_IGNORE))
341 if (n == EXIT_QUIT && (cmd->flags & CMD_EXIT))
354 cmdarg(register Cmdarg_t* cmd, const char* file, register int len)
362 while ((cmd->nextstr -= len + 1) < (char*)(cmd->nextarg + cmd->offset))
364 if (cmd->nextarg == cmd->firstarg)
366 if (cmd->errorf)
367 (*cmd->errorf)(NiL, cmd, 2, "%s: path too long for exec args", file);
370 if (i = cmdflush(cmd))
374 if (!(cmd->flags & CMD_IGNORE))
378 *cmd->nextarg++ = cmd->nextstr;
379 memcpy(cmd->nextstr, file, len);
380 cmd->nextstr[len] = 0;
381 cmd->argcount++;
382 if (cmd->argcount >= cmd->argmax && (i = cmdflush(cmd)) > r)
386 cmd->argcount += len;
395 cmdclose(Cmdarg_t* cmd)
399 if ((cmd->flags & CMD_EXACT) && cmd->argcount < cmd->argmax)
401 if (cmd->errorf)
402 (*cmd->errorf)(NiL, cmd, 2, "only %d arguments for last command", cmd->argcount);
407 cmd->flags &= ~CMD_MINIMUM;
408 n = cmdflush(cmd);
410 free(cmd);