Simplify journal_entry_pr(), rename to journal_entry_write()

journal_entry_pr(S, N) writes up to N characters from zero-terminated
string S.  journal_input() passes -1 for N to write all characters.
Unclean.  SIZE_MAX would do, but it's C99, and MSC doesn't provide it.

Simplify journal_entry_pr() to write exactly N characters.  This makes
it more similar to write() than to pr(), therefore rename.
This commit is contained in:
Markus Armbruster 2012-01-21 16:48:53 +01:00
parent f7533451d0
commit a89af8c64d

View file

@ -102,20 +102,19 @@ journal_entry_start(char *fmt, ...)
} }
static void static void
journal_entry_pr(char *s, size_t n) journal_entry_write(char *s, size_t n)
{ {
unsigned char *p; char *p;
if (!journal) if (!journal)
return; return;
for (p = (unsigned char *)s; *p && n; p++) { for (p = s; p < s + n; p++) {
if (*p == '\\') if (*p == '\\')
fprintf(journal, "\\\\"); fprintf(journal, "\\\\");
else if (isprint(*p) || *p == '\t') else if (isprint(*(unsigned char *)p) || *p == '\t')
putc(*p, journal); putc(*p, journal);
else else
fprintf(journal, "\\%03o", *p); fprintf(journal, "\\%03o", *p);
n--;
} }
} }
@ -220,15 +219,15 @@ journal_output(struct player *pl, int id, char *output)
if (bp != buf && (pl != bpl || id != bid)) { if (bp != buf && (pl != bpl || id != bid)) {
journal_output_start(bpl, bid); journal_output_start(bpl, bid);
journal_entry_pr(buf, bp - buf); journal_entry_write(buf, bp - buf);
journal_entry_end(0, 0); journal_entry_end(0, 0);
bp = buf; bp = buf;
} }
for (s = output; (e = strchr(s, '\n')); s = e + 1) { for (s = output; (e = strchr(s, '\n')); s = e + 1) {
journal_output_start(pl, id); journal_output_start(pl, id);
journal_entry_pr(buf, bp - buf); journal_entry_write(buf, bp - buf);
journal_entry_pr(s, e - s); journal_entry_write(s, e - s);
journal_entry_end(1, 0); journal_entry_end(1, 0);
bp = buf; bp = buf;
} }
@ -240,8 +239,8 @@ journal_output(struct player *pl, int id, char *output)
bid = id; bid = id;
} else { } else {
journal_output_start(pl, id); journal_output_start(pl, id);
journal_entry_pr(buf, bp - buf); journal_entry_write(buf, bp - buf);
journal_entry_pr(s, e - s); journal_entry_write(s, e - s);
journal_entry_end(0, 0); journal_entry_end(0, 0);
bp = buf; bp = buf;
} }
@ -257,7 +256,7 @@ void
journal_input(char *input) journal_input(char *input)
{ {
journal_entry_start("input "); journal_entry_start("input ");
journal_entry_pr(input, -1); journal_entry_write(input, strlen(input));
journal_entry_end(1, 1); journal_entry_end(1, 1);
} }