(play_list): player->combuf[] is user text and must be printed as
such. (ufindbreak, ufindpfx): Rename, move to pr.c, external linkage.
This commit is contained in:
parent
24672e351b
commit
ddfd5c1699
4 changed files with 41 additions and 36 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue