]> git.pond.sub.org Git - empserver/commitdiff
(play_list): player->combuf[] is user text and must be printed as
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 13 Jun 2005 08:42:27 +0000 (08:42 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 13 Jun 2005 08:42:27 +0000 (08:42 +0000)
such.
(ufindbreak, ufindpfx): Rename, move to pr.c, external linkage.

include/prototypes.h
src/lib/commands/flash.c
src/lib/commands/play.c
src/lib/subs/pr.c

index 2cf822786da1f804322718a914e28413f1047c7d..7e6986cd4b4c61c0db6d8671a8e2786059ecbf2d 100644 (file)
@@ -621,6 +621,7 @@ extern void PRdate(natid cn);
 extern void pr_beep(void);
 extern void mpr(int, s_char *, ...) ATTRIBUTE((format (printf, 2, 3)));
 extern void prtoascii(char *buf /* buf is message text */);
+extern int ufindpfx(char *, int);
 
 /* radmap.c */
 extern int deltx(struct range *, coord);
index 2f31d337118b85487e832e293be610a782636b27..98c7e9f7901b70c8ee1ee201249016368c348885 100644 (file)
@@ -39,9 +39,6 @@
 #include "file.h"
 #include "commands.h"
 
-static int ufindbreak(char *message /* message is message text */,
-                     int num_chars);
-
 int
 flash(void)
 {
@@ -143,7 +140,7 @@ sendmessage(struct natstr *us, struct natstr *to, char *message
     char c; /* c is message text */
     int pos;
 
-    pos = ufindbreak(message, 60);
+    pos = ufindpfx(message, 60);
     c = message[pos];
     if (c)
         message[pos] = '\0';
@@ -206,22 +203,3 @@ sendmessage(struct natstr *us, struct natstr *to, char *message
     }
     return 0;
 }
-
-/*
- * Return byte-index of the N-th UTF-8 character in UTF-8 string S.
- * If S doesn't have that many characters, return its length instead.
- */
-int
-ufindbreak(char *s /* s is message text */, int n)
-{
-    int i = 0;
-
-    while (n && s[i])
-    {
-       if ((s[i++] & 0xc0) == 0xc0)
-            while ((s[i] & 0xc0) == 0x80)
-               i++;
-        --n;
-    }
-    return i;
-}
index 59109e00ee6c7782fd3b6e1b4229e304cff31e9f..0350919b5888878bf5abe2e53f00d2864123407b 100644 (file)
@@ -70,9 +70,10 @@ static int
 play_list(struct player *joe)
 {
     time_t now;
-    s_char *com;
+    char com[1 + 6*20 + 2];    /* user text */
     struct natstr *natp;
     struct natstr *us;
+    int n;
 
     if (joe->cnum >= MAXNOC || !(natp = getnatp(joe->cnum)))
        return 0;
@@ -98,22 +99,28 @@ play_list(struct player *joe)
     }
 
     time(&now);
-    if (player->god) {
-       if (!joe->combuf || !*joe->combuf)
-           com = "NULL";
-       else
-           com = joe->combuf;
-    } else
-       com = "";
-
-
-    pr("%-9.9s %3d %32.32s %2d:%02d %4lds %-20.20s\n",
+    pr("%-9.9s %3d %32.32s %2d:%02d %4lds",
        cname(joe->cnum),
        joe->cnum,
        player->god || joe->cnum == player->cnum ? praddr(joe) : "",
        natp->nat_minused / 60,
        natp->nat_minused % 60,
-       (long)(now - joe->curup),
-       com);
+       (long)(now - joe->curup));
+
+    if (player->god) {
+       if (!joe->combuf || !*joe->combuf)
+           pr(" NULL\n");
+       else {
+           n = ufindpfx(joe->combuf, 20);
+           if (CANT_HAPPEN(n + 3u > sizeof(com))) {
+               pr(" BUGGY\n");
+               return 1;
+           }
+           sprintf(com, " %.*s\n", n, joe->combuf);
+           uprnf(com);
+       }
+    } else
+       pr("\n");
+
     return 1;
 }
index a5dd8c7f38cabdeb73c951640a9920f14e7f38b8..f6dcd1c9db63e4b1c41a90c2dfd02cebe98b97c4 100644 (file)
@@ -441,3 +441,22 @@ prtoascii(char *buf /* buf is message text */)
            pbuf--;
        }
 }
+
+/*
+ * Return byte-index of the N-th UTF-8 character in UTF-8 string S.
+ * If S doesn't have that many characters, return its length instead.
+ */
+int
+ufindpfx(char *s, int n)
+{
+    int i = 0;
+
+    while (n && s[i])
+    {
+       if ((s[i++] & 0xc0) == 0xc0)
+            while ((s[i] & 0xc0) == 0x80)
+               i++;
+        --n;
+    }
+    return i;
+}