Journal output lines instead of chunks
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.
This commit is contained in:
parent
221471af6f
commit
6be2e3f8c5
3 changed files with 30 additions and 6 deletions
|
@ -42,7 +42,7 @@ int journal_reopen(void);
|
||||||
void journal_login(void);
|
void journal_login(void);
|
||||||
void journal_logout(void);
|
void journal_logout(void);
|
||||||
void journal_prng(unsigned);
|
void journal_prng(unsigned);
|
||||||
void journal_output(struct player *, int, char *);
|
void journal_output(struct player *, char *);
|
||||||
void journal_input(char *);
|
void journal_input(char *);
|
||||||
void journal_command(char *);
|
void journal_command(char *);
|
||||||
void journal_update(int);
|
void journal_update(int);
|
||||||
|
|
|
@ -69,6 +69,7 @@ static FILE *journal;
|
||||||
|
|
||||||
static void journal_entry(char *fmt, ...)
|
static void journal_entry(char *fmt, ...)
|
||||||
ATTRIBUTE((format (printf, 1, 2)));
|
ATTRIBUTE((format (printf, 1, 2)));
|
||||||
|
static void journal_output_1(struct player *, char *, char *, int);
|
||||||
|
|
||||||
static FILE *
|
static FILE *
|
||||||
journal_open(void)
|
journal_open(void)
|
||||||
|
@ -171,14 +172,35 @@ journal_logout(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
if (keep_journal < 2)
|
||||||
return;
|
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)
|
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
|
else
|
||||||
journal_entry("output %p %d %s", pl, id, output);
|
journal_entry("output %p %s%.*s",
|
||||||
|
pl, buf1, buf2prec, buf2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -125,6 +125,7 @@ pr_id(struct player *p, int id, char *format, ...)
|
||||||
|
|
||||||
if (p->curid >= 0) {
|
if (p->curid >= 0) {
|
||||||
io_puts(p->iop, "\n");
|
io_puts(p->iop, "\n");
|
||||||
|
journal_output(p, "\n");
|
||||||
p->curid = -1;
|
p->curid = -1;
|
||||||
}
|
}
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
|
@ -243,7 +244,7 @@ pr_player(struct player *pl, int id, char *buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
journal_output(pl, id, buf);
|
journal_output(pl, buf);
|
||||||
|
|
||||||
if (player == pl) {
|
if (player == pl) {
|
||||||
while (io_output_if_queue_long(pl->iop,
|
while (io_output_if_queue_long(pl->iop,
|
||||||
|
@ -301,7 +302,7 @@ upr_player(struct player *pl, int id, char *buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
journal_output(pl, id, buf);
|
journal_output(pl, buf);
|
||||||
|
|
||||||
if (player == pl) {
|
if (player == pl) {
|
||||||
while (io_output_if_queue_long(pl->iop,
|
while (io_output_if_queue_long(pl->iop,
|
||||||
|
@ -329,6 +330,7 @@ outid(struct player *pl, int n)
|
||||||
buf[1] = ' ';
|
buf[1] = ' ';
|
||||||
buf[2] = '\0';
|
buf[2] = '\0';
|
||||||
io_puts(pl->iop, buf);
|
io_puts(pl->iop, buf);
|
||||||
|
journal_output(pl, buf);
|
||||||
pl->curid = n;
|
pl->curid = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue