diff --git a/include/prototypes.h b/include/prototypes.h index 2cf82278..7e6986cd 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -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); diff --git a/src/lib/commands/flash.c b/src/lib/commands/flash.c index 2f31d337..98c7e9f7 100644 --- a/src/lib/commands/flash.c +++ b/src/lib/commands/flash.c @@ -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; -} diff --git a/src/lib/commands/play.c b/src/lib/commands/play.c index 59109e00..0350919b 100644 --- a/src/lib/commands/play.c +++ b/src/lib/commands/play.c @@ -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; } diff --git a/src/lib/subs/pr.c b/src/lib/subs/pr.c index a5dd8c7f..f6dcd1c9 100644 --- a/src/lib/subs/pr.c +++ b/src/lib/subs/pr.c @@ -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; +}