]> git.pond.sub.org Git - empserver/commitdiff
Simplify journal_entry_pr(), rename to journal_entry_write()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 21 Jan 2012 15:48:53 +0000 (16:48 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 20 Feb 2012 06:34:34 +0000 (07:34 +0100)
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

index 88f3720463e692090333e475d1a4f45b1b911d92..ea795df581913bd7773eb78e94b880495a7c9816 100644 (file)
@@ -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);
 }