]> git.pond.sub.org Git - empserver/commitdiff
Journal output lines instead of chunks hvy-metal-2.11
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 30 Jul 2008 12:26:34 +0000 (08:26 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 30 Jul 2008 12:26:34 +0000 (08:26 -0400)
Output often arrives in chunks other than lines.  Hard to read in the
journal.  Delay journalling until we got a full line or our buffer is
exhausted.  This is less precise, but it'll do for now.

include/journal.h
src/lib/subs/journal.c
src/lib/subs/pr.c

index 7ef10ae1e230ace2f60579dc1a8717f853117947..247e40c3e68966e6926898f48a8303dd56708fd6 100644 (file)
@@ -42,7 +42,7 @@ int journal_reopen(void);
 void journal_login(void);
 void journal_logout(void);
 void journal_prng(unsigned);
-void journal_output(struct player *, int, char *);
+void journal_output(struct player *, char *);
 void journal_input(char *);
 void journal_command(char *);
 void journal_update(int);
index d2521f12902f6aec1879abc49bbeb26bace10703..85f68ce87b9d5ad3d7c10fa1ebc2b5caa1caf0f2 100644 (file)
@@ -66,6 +66,9 @@
 static char journal_fname[] = "journal.log";
 static FILE *journal;
 
+static void journal_entry(char *fmt, ...) ATTRIBUTE((format (printf, 1, 2)));
+static void journal_output_1(struct player *, char *, char *, int);
+
 static FILE *
 journal_open(void)
 {
@@ -170,14 +173,35 @@ journal_logout(void)
 }
 
 void
-journal_output(struct player *pl, int id, char *output)
+journal_output(struct player *pl, char *output)
 {
+    static char buf[1024];
+    char *s, *e;
+
     if (keep_journal < 2)
        return;
+
+    for (s = output; (e = strchr(s, '\n')); s = e + 1) {
+       journal_output_1(pl, buf, s, (int)(e + 1 - s));
+       buf[0] = 0;
+    }
+    if (strlen(buf) + strlen(s) < 1024)
+       strcpy(buf + strlen(buf), s);
+    else {
+       journal_output_1(pl, buf, s, -1);
+       buf[0] = 0;
+    }
+}
+
+void
+journal_output_1(struct player *pl, char *buf1, char *buf2, int buf2prec)
+{
     if (pl && pl->state == PS_PLAYING)
-       journal_entry("output %d %d %s", pl->cnum, id, output);
+       journal_entry("output %d %s%.*s",
+                     pl->cnum, buf1, buf2prec, buf2);
     else
-       journal_entry("output %p %d %s", pl, id, output);
+       journal_entry("output %p %s%.*s",
+                     pl, buf1, buf2prec, buf2);
 }
 
 void
index 44f5aee762b7417bcd762fe01baa0ddc6d33e72c..0b8146efecab309f222d8f8d45c960402218f95d 100644 (file)
@@ -125,6 +125,7 @@ pr_id(struct player *p, int id, char *format, ...)
 
     if (p->curid >= 0) {
        io_puts(p->iop, "\n");
+       journal_output(p, "\n");
        p->curid = -1;
     }
     va_start(ap, format);
@@ -246,7 +247,7 @@ pr_player(struct player *pl, int id, char *buf)
            bp += len;
        }
     }
-    journal_output(pl, id, buf);
+    journal_output(pl, buf);
 }
 
 /*
@@ -301,7 +302,7 @@ upr_player(struct player *pl, int id, char *buf)
            io_puts(pl->iop, printbuf);
        }
     }
-    journal_output(pl, id, buf);
+    journal_output(pl, buf);
 }
 
 /*
@@ -323,6 +324,7 @@ outid(struct player *pl, int n)
     buf[1] = ' ';
     buf[2] = '\0';
     io_puts(pl->iop, buf);
+    journal_output(pl, buf);
     pl->curid = n;
 }