From a89af8c64d6153f21a98fe4942b75cca952f63fb Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 21 Jan 2012 16:48:53 +0100 Subject: [PATCH] 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. --- src/lib/subs/journal.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lib/subs/journal.c b/src/lib/subs/journal.c index 88f372046..ea795df58 100644 --- a/src/lib/subs/journal.c +++ b/src/lib/subs/journal.c @@ -102,20 +102,19 @@ journal_entry_start(char *fmt, ...) } 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) return; - for (p = (unsigned char *)s; *p && n; p++) { + for (p = s; p < s + n; p++) { if (*p == '\\') fprintf(journal, "\\\\"); - else if (isprint(*p) || *p == '\t') + else if (isprint(*(unsigned char *)p) || *p == '\t') putc(*p, journal); else 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)) { journal_output_start(bpl, bid); - journal_entry_pr(buf, bp - buf); + journal_entry_write(buf, bp - buf); journal_entry_end(0, 0); bp = buf; } for (s = output; (e = strchr(s, '\n')); s = e + 1) { journal_output_start(pl, id); - journal_entry_pr(buf, bp - buf); - journal_entry_pr(s, e - s); + journal_entry_write(buf, bp - buf); + journal_entry_write(s, e - s); journal_entry_end(1, 0); bp = buf; } @@ -240,8 +239,8 @@ journal_output(struct player *pl, int id, char *output) bid = id; } else { journal_output_start(pl, id); - journal_entry_pr(buf, bp - buf); - journal_entry_pr(s, e - s); + journal_entry_write(buf, bp - buf); + journal_entry_write(s, e - s); journal_entry_end(0, 0); bp = buf; } @@ -257,7 +256,7 @@ void journal_input(char *input) { journal_entry_start("input "); - journal_entry_pr(input, -1); + journal_entry_write(input, strlen(input)); journal_entry_end(1, 1); } -- 2.43.0