Lines Matching refs:cmd

55 	register Cmdarg_t*	cmd;
105 if (!(cmd = newof(0, Cmdarg_t, 1, n + m)))
113 s = cmd->buf;
117 cmd->echo = 1;
121 cmd->echo = 1;
133 free(cmd);
141 cmd->insert = strcpy(s, argpat);
142 cmd->insertlen = m - 1;
145 s += sizeof(char**) - (s - cmd->buf) % sizeof(char**);
148 cmd->argv = p;
155 cmd->insertarg = p;
156 argv = cmd->argv;
157 c = *cmd->insert;
160 while ((s = strchr(s, c)) && strncmp(cmd->insert, s, cmd->insertlen))
167 cmd->firstarg = cmd->nextarg = p;
168 cmd->laststr = cmd->nextstr = cmd->buf + n;
169 cmd->argmax = argmax;
170 cmd->flags = flags;
171 cmd->offset = ((cmd->postarg = post) ? (argc - (post - argv)) : 0) + 3;
172 return cmd;
180 cmdflush(register Cmdarg_t* cmd)
186 if (cmd->flags & CMD_EMPTY)
187 cmd->flags &= ~CMD_EMPTY;
188 else if (cmd->nextarg <= cmd->firstarg)
190 if ((cmd->flags & CMD_MINIMUM) && cmd->argcount < cmd->argmax)
192 if (!(cmd->flags & CMD_SILENT))
193 error(2, "%d arg command would be too long", cmd->argcount);
196 cmd->total.args += cmd->argcount;
197 cmd->total.commands++;
198 cmd->argcount = 0;
199 if (p = cmd->postarg)
200 while (*cmd->nextarg++ = *p++);
202 *cmd->nextarg = 0;
203 if (s = cmd->insert)
213 a = cmd->firstarg[0];
214 b = (char*)&cmd->nextarg[1];
215 e = cmd->nextstr;
217 m = cmd->insertlen;
218 for (n = 1; cmd->argv[n]; n++)
219 if (t = cmd->insertarg[n])
221 cmd->argv[n] = b;
247 if (!(cmd->flags & CMD_SILENT))
252 cmd->nextarg = cmd->firstarg;
253 cmd->nextstr = cmd->laststr;
254 if (cmd->flags & (CMD_QUERY|CMD_TRACE))
256 p = cmd->argv;
260 if (!(cmd->flags & CMD_QUERY))
265 if (cmd->echo)
267 n = (cmd->flags & CMD_NEWLINE) ? '\n' : ' ';
268 for (p = cmd->argv + 1; s = *p++;)
272 else if ((n = procrun(*cmd->argv, cmd->argv, PROC_ARGMOD|PROC_IGNOREPATH)) == -1)
274 if (!(cmd->flags & CMD_SILENT))
276 error(ERROR_SYSTEM|2, "%s: command exec error", *cmd->argv);
283 if (!(cmd->flags & CMD_SILENT))
286 else if (!(cmd->flags & CMD_IGNORE))
288 if (n == EXIT_QUIT && !(cmd->flags & CMD_SILENT))
301 cmdarg(register Cmdarg_t* cmd, const char* file, register int len)
309 while ((cmd->nextstr -= len + 1) < (char*)(cmd->nextarg + cmd->offset))
311 if (cmd->nextarg == cmd->firstarg)
316 if (i = cmdflush(cmd))
320 if (!(cmd->flags & CMD_IGNORE))
324 *cmd->nextarg++ = cmd->nextstr;
325 memcpy(cmd->nextstr, file, len);
326 cmd->nextstr[len] = 0;
327 cmd->argcount++;
328 if (cmd->argcount >= cmd->argmax && (i = cmdflush(cmd)) > r)
339 cmdclose(Cmdarg_t* cmd)
343 if ((cmd->flags & CMD_EXACT) && cmd->argcount < cmd->argmax)
345 if (!(cmd->flags & CMD_SILENT))
346 error(2, "only %d arguments for last command", cmd->argcount);
349 cmd->flags &= ~CMD_MINIMUM;
350 n = cmdflush(cmd);
351 free(cmd);