]> git.pond.sub.org Git - empserver/commitdiff
Record raw arguments, to be used in the next changesets:
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 25 Nov 2007 13:55:52 +0000 (13:55 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 25 Nov 2007 13:55:52 +0000 (13:55 +0000)
(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.

include/player.h
include/prototypes.h
src/lib/commands/navi.c
src/lib/gen/emp_config.c
src/lib/gen/parse.c
src/lib/player/login.c
src/lib/player/player.c

index 78b1a61c05b856879733b0a58e1d52e4c97dccb9..ede5ad729ec653df3d26bf1bcf0216195accb186 100644 (file)
@@ -60,11 +60,12 @@ struct player {
     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;
index 670ea38c40fbe875cfcfdd4711b26087b4d51b34..3c1d3d637f60c45459cc61ab0ada94450b5588d8 100644 (file)
@@ -368,7 +368,7 @@ extern int deltay(int, int);
 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);
index 0d0dcc4031f418de9b7096bc3c7efc1e542c027f..1f589dc18ee30741f15dc67188c4bd68e990918b 100644 (file)
@@ -183,7 +183,7 @@ do_unit_move(struct emp_qelem *ulist, int *together,
            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;
index 37ba63ba35ada648e2272ca21061342dbbc3b4d8..b9651b3ed9d55b4f200d1ddc46f6a7b7df2a6c3b 100644 (file)
@@ -99,7 +99,7 @@ emp_config(char *file)
        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;
index fc8a70034a3035ccd2d7227b37311034dab69ea7..526e4469933851a23ce9fe15cd1e3fa768637346 100644 (file)
 /*
  * 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)
@@ -72,9 +73,17 @@ parse(char *buf, char **arg, char **condp, char *space, char **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;
@@ -83,16 +92,13 @@ parse(char *buf, char **arg, char **condp, char *space, char **redir)
            /* 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;
 }
index bf30d7c6f45e50c85ff2e5caf9a607748d262737..64b24e717dbe05069d365c213afa05bbcd3299ff 100644 (file)
@@ -91,7 +91,7 @@ player_login(void *ud)
            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]);
index 4f925342f30d82e7ec957ac26bbe4c9a7c95bee8..8d3762c450dd11df0f9744450547cb24eda2c642 100644 (file)
@@ -141,8 +141,8 @@ command(void)
 
     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)
@@ -287,8 +287,8 @@ execute(void)
     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;
        }