]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/journal.c
Update copyright notice
[empserver] / src / lib / subs / journal.c
index 527a83f9f3a273e0e26d43159a90b2069a8cef1e..4012fb7247259067fad4d614d8ffa95ab6fcb4b3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -27,7 +27,7 @@
  *  journal.c: Log a journal of events to a file
  *
  *  Known contributors to this file:
- *     Markus Armbruster, 2004-2011
+ *     Markus Armbruster, 2004-2012
  *     Ron Koenderink, 2008
  */
 
@@ -75,19 +75,21 @@ static void journal_output_start(struct player *, int);
 static FILE *
 journal_open(void)
 {
-    return fopen(journal_fname, "a+");
+    return fopen(journal_fname, "a");
 }
 
 static void
 journal_entry_vstart(char *fmt, va_list ap)
 {
     time_t now;
+    empth_t *self;
 
     if (!journal)
        return;
     time(&now);
+    self = empth_self();
     fprintf(journal, "%.24s %10.10s ",
-           ctime(&now), empth_name(empth_self()));
+           ctime(&now), self ? empth_name(self) : "Main");
     vfprintf(journal, fmt, ap);
 }
 
@@ -102,20 +104,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 +221,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 +241,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 +258,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);
 }