Add end-of-game dumplogs
This is based on the "new" dumplog patch for 3.6.0, by Maxime Bacoux. Define DUMPLOG to enable. By default only enabled for the TTY linux.
This commit is contained in:
239
src/windows.c
239
src/windows.c
@@ -1032,4 +1032,243 @@ int behavior UNUSED, under UNUSED, over UNUSED;
|
||||
#endif /* STATUS_HILITES */
|
||||
#endif /* STATUS_VIA_WINDOWPORT */
|
||||
|
||||
STATIC_VAR struct window_procs dumplog_windowprocs_backup;
|
||||
STATIC_PTR FILE* dumplog_file;
|
||||
|
||||
#ifdef DUMPLOG
|
||||
char *
|
||||
dump_fmtstr(fmt, buf)
|
||||
char *fmt;
|
||||
char *buf;
|
||||
{
|
||||
char *fp = fmt, *bp = buf;
|
||||
int slen, len = 0;
|
||||
char tmpbuf[BUFSZ];
|
||||
char verbuf[BUFSZ];
|
||||
|
||||
time_t now = getnow();
|
||||
int uid = getuid();
|
||||
|
||||
while (fp && *fp && len < BUFSZ-1) {
|
||||
if (*fp == '%') {
|
||||
fp++;
|
||||
switch (*fp) {
|
||||
default: goto finish;
|
||||
case '\0': /* fallthrough */
|
||||
case '%': /* literal % */
|
||||
Sprintf(tmpbuf,"%%");
|
||||
break;
|
||||
case 't': /* game start, timestamp */
|
||||
Sprintf(tmpbuf, "%ld", ubirthday);
|
||||
break;
|
||||
case 'T': /* current time, timestamp */
|
||||
Sprintf(tmpbuf, "%ld", now);
|
||||
break;
|
||||
case 'd': /* game start, YYYYMMDDhhmmss */
|
||||
Sprintf(tmpbuf, "%08ld%06ld",
|
||||
yyyymmdd(ubirthday), hhmmss(ubirthday));
|
||||
break;
|
||||
case 'D': /* current time, YYYYMMDDhhmmss */
|
||||
Sprintf(tmpbuf, "%08ld%06ld", yyyymmdd(now), hhmmss(now));
|
||||
break;
|
||||
case 'v': /* version, eg. "3.6.1-0" */
|
||||
Sprintf(tmpbuf, "%s", version_string(verbuf));
|
||||
break;
|
||||
case 'u': /* UID */
|
||||
Sprintf(tmpbuf, "%d", uid);
|
||||
break;
|
||||
case 'n': /* player name */
|
||||
Sprintf(tmpbuf, "%s", (plname ? plname : "unknown"));
|
||||
break;
|
||||
case 'N': /* first character of player name */
|
||||
Sprintf(tmpbuf, "%c", (plname ? *plname : 'u'));
|
||||
break;
|
||||
}
|
||||
|
||||
slen = strlen(tmpbuf);
|
||||
if (len + slen < BUFSZ-1) {
|
||||
len += slen;
|
||||
Sprintf(bp, "%s", tmpbuf);
|
||||
bp += slen;
|
||||
if (*fp) fp++;
|
||||
} else
|
||||
break;
|
||||
} else {
|
||||
*bp = *fp;
|
||||
bp++;
|
||||
fp++;
|
||||
len++;
|
||||
}
|
||||
}
|
||||
finish:
|
||||
*bp = '\0';
|
||||
return buf;
|
||||
}
|
||||
#endif /* DUMPLOG */
|
||||
|
||||
|
||||
void
|
||||
dump_open_log(now)
|
||||
time_t now;
|
||||
{
|
||||
#ifdef DUMPLOG
|
||||
char buf[BUFSZ];
|
||||
char *fname;
|
||||
|
||||
#ifdef SYSCF
|
||||
if (!sysopt.dumplogfile)
|
||||
return;
|
||||
fname = dump_fmtstr(sysopt.dumplogfile, buf);
|
||||
#else
|
||||
fname = dump_fmtstr(DUMPLOG_FILE, buf);
|
||||
#endif
|
||||
|
||||
dumplog_file = fopen(fname, "w");
|
||||
dumplog_windowprocs_backup = windowprocs;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
dump_close_log()
|
||||
{
|
||||
if (dumplog_file) {
|
||||
fclose(dumplog_file);
|
||||
dumplog_file = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
dump_putc(ch)
|
||||
int ch;
|
||||
{
|
||||
/* Not very efficient, but we mostly don't care. */
|
||||
if (dumplog_file)
|
||||
putc(ch, dumplog_file);
|
||||
}
|
||||
|
||||
void
|
||||
dump_forward_putstr(win, attr, str, no_forward)
|
||||
winid win;
|
||||
int attr;
|
||||
const char* str;
|
||||
int no_forward;
|
||||
{
|
||||
if (dumplog_file)
|
||||
fprintf(dumplog_file, "%s\n", str);
|
||||
if (!no_forward)
|
||||
putstr(win, attr, str);
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
dump_putstr(win, attr, str)
|
||||
winid win;
|
||||
int attr;
|
||||
const char* str;
|
||||
{
|
||||
if (dumplog_file)
|
||||
fprintf(dumplog_file, "%s\n", str);
|
||||
}
|
||||
|
||||
STATIC_OVL winid
|
||||
dump_create_nhwindow(dummy)
|
||||
int dummy;
|
||||
{
|
||||
return dummy;
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
dump_clear_nhwindow(win)
|
||||
winid win;
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
dump_display_nhwindow(win, p)
|
||||
winid win;
|
||||
BOOLEAN_P p;
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
dump_destroy_nhwindow(win)
|
||||
winid win;
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
dump_start_menu(win)
|
||||
winid win;
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
dump_add_menu(win, glyph, identifier, ch, gch, attr, str, preselected)
|
||||
winid win;
|
||||
int glyph;
|
||||
const ANY_P* identifier;
|
||||
CHAR_P ch;
|
||||
CHAR_P gch;
|
||||
int attr;
|
||||
const char* str;
|
||||
BOOLEAN_P preselected;
|
||||
{
|
||||
if (dumplog_file) {
|
||||
if (glyph == NO_GLYPH)
|
||||
fprintf(dumplog_file, " %s\n", str);
|
||||
else
|
||||
fprintf(dumplog_file, " %c - %s\n", ch, str);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC_OVL void
|
||||
dump_end_menu(win, str)
|
||||
winid win;
|
||||
const char* str;
|
||||
{
|
||||
if (dumplog_file) {
|
||||
if (str)
|
||||
fprintf(dumplog_file, "%s\n", str);
|
||||
else
|
||||
fputs("\n", dumplog_file);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC_OVL int
|
||||
dump_select_menu(win, index, item)
|
||||
winid win;
|
||||
int index;
|
||||
MENU_ITEM_P** item;
|
||||
{
|
||||
*item = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
dump_redirect(flag)
|
||||
boolean flag;
|
||||
{
|
||||
if (dumplog_file) {
|
||||
if (flag) {
|
||||
windowprocs.win_create_nhwindow = dump_create_nhwindow;
|
||||
windowprocs.win_clear_nhwindow = dump_clear_nhwindow;
|
||||
windowprocs.win_display_nhwindow = dump_display_nhwindow;
|
||||
windowprocs.win_destroy_nhwindow = dump_destroy_nhwindow;
|
||||
windowprocs.win_start_menu = dump_start_menu;
|
||||
windowprocs.win_add_menu = dump_add_menu;
|
||||
windowprocs.win_end_menu = dump_end_menu;
|
||||
windowprocs.win_select_menu = dump_select_menu;
|
||||
windowprocs.win_putstr = dump_putstr;
|
||||
} else {
|
||||
windowprocs = dumplog_windowprocs_backup;
|
||||
}
|
||||
iflags.in_dumplog = flag;
|
||||
} else {
|
||||
iflags.in_dumplog = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/*windows.c*/
|
||||
|
||||
Reference in New Issue
Block a user