(player): New member comtail.
(parse): New parameter tail. Reorder parameter list.
(command, execute): Pass player->comtail.
(player_login, emp_config, do_unit_move): Pass NULL. No functional
change.
natid cnum;
int state;
int flags;
- struct cmndstr *command;
+ struct cmndstr *command; /* currently executing command */
struct iop *iop;
char combuf[1024]; /* command input buffer, UTF-8 */
- char *argp[128]; /* arguments, ASCII */
- char *condarg; /* conditional, ASCII */
+ char *argp[128]; /* arguments, ASCII, valid if command */
+ char *condarg; /* conditional, ASCII, valid if command */
+ char *comtail[128]; /* start of args in combuf[] */
time_t lasttime; /* when minleft was last debited */
int ncomstat;
int minleft;
extern int mapdist(int, int, int, int);
extern char *effadv(int);
extern int onearg(char *, char *);
-extern int parse(char *, char **, char **, char *, char **);
+extern int parse(char *, char *, char **, char **, char **, char **);
extern int ldround(double, int);
extern int roundintby(int, int);
extern int scthash(int, int, int);
cp++;
continue;
}
- ac = parse(cp, player->argp, NULL, scanspace, NULL);
+ ac = parse(cp, scanspace, player->argp, NULL, NULL, NULL);
if (ac <= 1) {
sprintf(dp, "%d", leader->uid);
player->argp[1] = dp;
for (i = 0; buf[i] && isspace(buf[i]); ++i) ;
if (!buf[i] || buf[i] == '#')
continue;
- if (parse(buf, av, NULL, scanspace, NULL) < 0) {
+ if (parse(buf, scanspace, av, NULL, NULL, NULL) < 0) {
fprintf(stderr, "%s:%d: Can't parse line %s", file, lno, buf);
errors = 1;
continue;
/*
* Parse user command in BUF.
* BUF is UTF-8.
- * Set ARG[0] to point to the command name.
- * Set ARG[1..N] to point to arguments, where N is the number of
- * arguments. Set ARG[N+1..127] to NULL.
- * If CONDP is not null, recognize conditional argument syntax, and
- * set *CONDP to the conditional argument if present, else NULL.
* Command name and arguments are copied into SPACE[], whose size must
* be at least strlen(BUF) + 1.
+ * Set ARG[0] to the zero-terminated command name.
+ * Set ARG[1..N] to the zero-terminated arguments, where N is the
+ * number of arguments. Set ARG[N+1..127] to NULL.
+ * Set TAIL[0..N] to beginning of ARG[0] in BUF[].
+ * If CONDP is not null, recognize conditional argument syntax, and
+ * set *CONDP to the conditional argument if present, else NULL.
* If REDIR is not null, recognize redirection syntax, and set *REDIR
* to UTF-8 redirection string if present, else NULL.
* Return number of slots used in ARG[], or -1 on error.
*/
int
-parse(char *buf, char **arg, char **condp, char *space, char **redir)
+parse(char *buf, char *space, char **arg,
+ char **tail, char **condp, char **redir)
{
- char *ap;
int i, quoted, argnum;
if (redir)
break;
}
+ if (condp && *buf == '?') {
+ buf++;
+ *condp = space;
+ } else {
+ if (tail)
+ tail[argnum] = buf;
+ arg[argnum++] = space;
+ }
+
/* copy argument */
quoted = 0;
- ap = space;
for (; *buf && (quoted || !isspace(*(unsigned char *)buf)); buf++) {
if (*buf == '"')
quoted = !quoted;
/* else funny character; ignore */
}
*space++ = 0;
-
- /* store copied argument as conditional or regular argument */
- if (condp && *ap == '?')
- *condp = ap + 1;
- else
- arg[argnum++] = ap;
}
- for (i = argnum; i < 128; i++)
+ for (i = argnum; i < 128; i++) {
arg[i] = NULL;
+ if (tail)
+ tail[i] = NULL;
+ }
return argnum;
}
io_input(player->iop, IO_WAIT);
continue;
}
- ac = parse(buf, player->argp, NULL, space, NULL);
+ ac = parse(buf, space, player->argp, NULL, NULL, NULL);
cmd = comtch(player->argp[0], login_coms, 0);
if (cmd < 0) {
pr_id(player, C_BADCMD, "Command %s not found\n", player->argp[0]);
if (getcommand(player->combuf) < 0)
return 0;
- if (parse(player->combuf, player->argp, &player->condarg,
- scanspace, &redir) < 0) {
+ if (parse(player->combuf, scanspace, player->argp, player->comtail,
+ &player->condarg, &redir) < 0) {
pr("See \"info Syntax\"?\n");
} else {
if (dispatch(player->combuf, redir) < 0)
while (!failed && status()) {
if (recvclient(buf, sizeof(buf)) < 0)
break;
- if (parse(buf, player->argp, &player->condarg,
- scanspace, &redir) < 0) {
+ if (parse(buf, scanspace, player->argp, player->comtail,
+ &player->condarg, &redir) < 0) {
failed = 1;
continue;
}