Record raw arguments, to be used in the next changesets:
(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.
This commit is contained in:
parent
3fcee8ddd1
commit
90631d56ed
7 changed files with 33 additions and 26 deletions
|
@ -60,11 +60,12 @@ struct player {
|
||||||
natid cnum;
|
natid cnum;
|
||||||
int state;
|
int state;
|
||||||
int flags;
|
int flags;
|
||||||
struct cmndstr *command;
|
struct cmndstr *command; /* currently executing command */
|
||||||
struct iop *iop;
|
struct iop *iop;
|
||||||
char combuf[1024]; /* command input buffer, UTF-8 */
|
char combuf[1024]; /* command input buffer, UTF-8 */
|
||||||
char *argp[128]; /* arguments, ASCII */
|
char *argp[128]; /* arguments, ASCII, valid if command */
|
||||||
char *condarg; /* conditional, ASCII */
|
char *condarg; /* conditional, ASCII, valid if command */
|
||||||
|
char *comtail[128]; /* start of args in combuf[] */
|
||||||
time_t lasttime; /* when minleft was last debited */
|
time_t lasttime; /* when minleft was last debited */
|
||||||
int ncomstat;
|
int ncomstat;
|
||||||
int minleft;
|
int minleft;
|
||||||
|
|
|
@ -368,7 +368,7 @@ extern int deltay(int, int);
|
||||||
extern int mapdist(int, int, int, int);
|
extern int mapdist(int, int, int, int);
|
||||||
extern char *effadv(int);
|
extern char *effadv(int);
|
||||||
extern int onearg(char *, char *);
|
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 ldround(double, int);
|
||||||
extern int roundintby(int, int);
|
extern int roundintby(int, int);
|
||||||
extern int scthash(int, int, int);
|
extern int scthash(int, int, int);
|
||||||
|
|
|
@ -183,7 +183,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
|
||||||
cp++;
|
cp++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ac = parse(cp, player->argp, NULL, scanspace, NULL);
|
ac = parse(cp, scanspace, player->argp, NULL, NULL, NULL);
|
||||||
if (ac <= 1) {
|
if (ac <= 1) {
|
||||||
sprintf(dp, "%d", leader->uid);
|
sprintf(dp, "%d", leader->uid);
|
||||||
player->argp[1] = dp;
|
player->argp[1] = dp;
|
||||||
|
|
|
@ -99,7 +99,7 @@ emp_config(char *file)
|
||||||
for (i = 0; buf[i] && isspace(buf[i]); ++i) ;
|
for (i = 0; buf[i] && isspace(buf[i]); ++i) ;
|
||||||
if (!buf[i] || buf[i] == '#')
|
if (!buf[i] || buf[i] == '#')
|
||||||
continue;
|
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);
|
fprintf(stderr, "%s:%d: Can't parse line %s", file, lno, buf);
|
||||||
errors = 1;
|
errors = 1;
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -39,21 +39,22 @@
|
||||||
/*
|
/*
|
||||||
* Parse user command in BUF.
|
* Parse user command in BUF.
|
||||||
* BUF is UTF-8.
|
* 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
|
* Command name and arguments are copied into SPACE[], whose size must
|
||||||
* be at least strlen(BUF) + 1.
|
* 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
|
* If REDIR is not null, recognize redirection syntax, and set *REDIR
|
||||||
* to UTF-8 redirection string if present, else NULL.
|
* to UTF-8 redirection string if present, else NULL.
|
||||||
* Return number of slots used in ARG[], or -1 on error.
|
* Return number of slots used in ARG[], or -1 on error.
|
||||||
*/
|
*/
|
||||||
int
|
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;
|
int i, quoted, argnum;
|
||||||
|
|
||||||
if (redir)
|
if (redir)
|
||||||
|
@ -72,9 +73,17 @@ parse(char *buf, char **arg, char **condp, char *space, char **redir)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (condp && *buf == '?') {
|
||||||
|
buf++;
|
||||||
|
*condp = space;
|
||||||
|
} else {
|
||||||
|
if (tail)
|
||||||
|
tail[argnum] = buf;
|
||||||
|
arg[argnum++] = space;
|
||||||
|
}
|
||||||
|
|
||||||
/* copy argument */
|
/* copy argument */
|
||||||
quoted = 0;
|
quoted = 0;
|
||||||
ap = space;
|
|
||||||
for (; *buf && (quoted || !isspace(*(unsigned char *)buf)); buf++) {
|
for (; *buf && (quoted || !isspace(*(unsigned char *)buf)); buf++) {
|
||||||
if (*buf == '"')
|
if (*buf == '"')
|
||||||
quoted = !quoted;
|
quoted = !quoted;
|
||||||
|
@ -83,16 +92,13 @@ parse(char *buf, char **arg, char **condp, char *space, char **redir)
|
||||||
/* else funny character; ignore */
|
/* else funny character; ignore */
|
||||||
}
|
}
|
||||||
*space++ = 0;
|
*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;
|
arg[i] = NULL;
|
||||||
|
if (tail)
|
||||||
|
tail[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return argnum;
|
return argnum;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ player_login(void *ud)
|
||||||
io_input(player->iop, IO_WAIT);
|
io_input(player->iop, IO_WAIT);
|
||||||
continue;
|
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);
|
cmd = comtch(player->argp[0], login_coms, 0);
|
||||||
if (cmd < 0) {
|
if (cmd < 0) {
|
||||||
pr_id(player, C_BADCMD, "Command %s not found\n", player->argp[0]);
|
pr_id(player, C_BADCMD, "Command %s not found\n", player->argp[0]);
|
||||||
|
|
|
@ -141,8 +141,8 @@ command(void)
|
||||||
|
|
||||||
if (getcommand(player->combuf) < 0)
|
if (getcommand(player->combuf) < 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (parse(player->combuf, player->argp, &player->condarg,
|
if (parse(player->combuf, scanspace, player->argp, player->comtail,
|
||||||
scanspace, &redir) < 0) {
|
&player->condarg, &redir) < 0) {
|
||||||
pr("See \"info Syntax\"?\n");
|
pr("See \"info Syntax\"?\n");
|
||||||
} else {
|
} else {
|
||||||
if (dispatch(player->combuf, redir) < 0)
|
if (dispatch(player->combuf, redir) < 0)
|
||||||
|
@ -287,8 +287,8 @@ execute(void)
|
||||||
while (!failed && status()) {
|
while (!failed && status()) {
|
||||||
if (recvclient(buf, sizeof(buf)) < 0)
|
if (recvclient(buf, sizeof(buf)) < 0)
|
||||||
break;
|
break;
|
||||||
if (parse(buf, player->argp, &player->condarg,
|
if (parse(buf, scanspace, player->argp, player->comtail,
|
||||||
scanspace, &redir) < 0) {
|
&player->condarg, &redir) < 0) {
|
||||||
failed = 1;
|
failed = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue