]> git.pond.sub.org Git - empserver/blobdiff - src/lib/player/player.c
Revert "Simplify execute(): use getstarg() instead of getstring()"
[empserver] / src / lib / player / player.c
index 7f40b13e07b2873a87828662e8dff3cf7c4e8bfb..eb87f78838c067bffdf2bb8a25da1ac65d0ca01d 100644 (file)
@@ -115,16 +115,18 @@ player_main(struct player *p)
 static int
 command(void)
 {
+    struct natstr *natp = getnatp(player->cnum);
     char *redir;               /* UTF-8 */
     char scanspace[1024];
     time_t now;
 
+    prprompt(natp->nat_timeused / 60, natp->nat_btu);
     if (getcommand(player->combuf) < 0)
        return player->aborted;
 
     now = time(NULL);
     update_timeused(now);
-    if (!player->god && !may_play_now(getnatp(player->cnum), now))
+    if (!player->god && !may_play_now(natp, now))
        return 0;
 
     if (parse(player->combuf, scanspace, player->argp, player->comtail,
@@ -202,6 +204,36 @@ status(void)
     return 1;
 }
 
+/* Is ARG one of the player's last command's arguments?  */
+static int
+is_command_arg(char *arg)
+{
+    int i;
+
+    for (i = 1; i < 128 && player->argp[i]; i++) {
+       if (arg == player->argp[i])
+           return 1;
+    }
+    return 0;
+}
+
+/*
+ * Make all objects stale if ARG is one of the player's command arguments.
+ * See ef_make_stale() for what "making stale" means.
+ * Useful for functions that prompt for missing arguments.
+ * These can yield the processor, so we'd like to call ef_make_stale()
+ * there.  Except that leads to false positives when the caller passes
+ * an argument that is never null, and relies on the fact that the
+ * function doesn't yield then.  We can't know that in general.  But
+ * we do know in the common special case of command arguments.
+ */
+void
+make_stale_if_command_arg(char *arg)
+{
+    if (is_command_arg(arg))
+       ef_make_stale();
+}
+
 /*
  * XXX This whole mess should be redone; execute block should
  * start with "exec start", and should end with "exec end".
@@ -218,21 +250,26 @@ execute(void)
 
     failed = 0;
 
-    p = getstarg(player->comtail[1], "File? ", buf);
+    if (player->comtail[1])
+       p = player->comtail[1];
+    else
+       p = getstring("File? ", buf);
     if (p == NULL || *p == '\0')
        return RET_SYN;
     prexec(p);
 
     while (!failed && status()) {
        player->nstat &= ~EXEC;
-       if (recvclient(buf, sizeof(buf)) < 0)
+       if (getcommand(buf) < 0)
            break;
        if (parse(buf, scanspace, player->argp, player->comtail,
                  &player->condarg, &redir) < 0) {
            failed = 1;
            continue;
        }
-       pr("\nExecute : %s\n", buf);
+       pr("\nExecute : ");
+       uprnf(buf);
+       pr("\n");
        if (redir) {
            pr("Execute : redirection not supported\n");
            failed = 1;