From: nhmall Date: Thu, 10 May 2018 14:05:29 +0000 (-0400) Subject: provide some debug developer controls - part 1 X-Git-Tag: NetHack-3.6.2_Released~280^2~7^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=702154529fb69af17972d0292d305acaf3a54eca;p=nethack provide some debug developer controls - part 1 --- diff --git a/include/extern.h b/include/extern.h index b6f482515..4535f8769 100644 --- a/include/extern.h +++ b/include/extern.h @@ -26,7 +26,7 @@ E void NDECL(display_gamewindows); E void NDECL(newgame); E void FDECL(welcome, (BOOLEAN_P)); E time_t NDECL(get_realtime); -E boolean FDECL(argcheck, (int, char **, enum earlyarg)); +E int FDECL(argcheck, (int, char **, enum earlyarg)); /* ### apply.c ### */ diff --git a/include/flag.h b/include/flag.h index 5dd13b2ec..277b42cfe 100644 --- a/include/flag.h +++ b/include/flag.h @@ -221,6 +221,16 @@ enum getloc_filters { NUM_GFILTER }; +struct debug_flags { + boolean test; +#ifdef TTY_GRAPHICS + boolean ttystatus; +#endif +#ifdef WIN32 + boolean immediateflips; +#endif +}; + struct instance_flags { /* stuff that really isn't option or platform related. They are * set and cleared during the game to control the internal @@ -423,6 +433,7 @@ struct instance_flags { short mines_prize_type; /* luckstone */ short soko_prize_type1; /* bag of holding or */ short soko_prize_type2; /* amulet of reflection */ + struct debug_flags debug; }; /* diff --git a/src/allmain.c b/src/allmain.c index 6942aa232..569c6e456 100644 --- a/src/allmain.c +++ b/src/allmain.c @@ -6,6 +6,7 @@ /* various code that was replicated in *main.c */ #include "hack.h" +#include #ifndef NO_SIGNAL #include @@ -16,6 +17,7 @@ STATIC_DCL void NDECL(do_positionbar); #endif STATIC_DCL void FDECL(regen_hp, (int)); STATIC_DCL void FDECL(interrupt_multi, (const char *)); +STATIC_DCL void FDECL(debug_fields, (const char *)); void moveloop(resuming) @@ -752,11 +754,18 @@ const char *msg; */ static struct early_opt earlyopts[] = { - {ARG_DEBUG, "debug", 5, FALSE}, + {ARG_DEBUG, "debug", 5, TRUE}, {ARG_VERSION, "version", 4, TRUE}, }; -boolean +/* + * Returns: + * 0 = no match + * 1 = found and skip past this argument + * 2 = found and trigger immediate exit + */ + +int argcheck(argc, argv, e_arg) int argc; char *argv[]; @@ -774,7 +783,7 @@ enum earlyarg e_arg; if ((idx >= SIZE(earlyopts)) || (argc <= 1)) return FALSE; - for (i = 1; i < argc; ++i) { + for (i = 0; i < argc; ++i) { if (argv[i][0] != '-') continue; if (argv[i][1] == '-') { @@ -789,15 +798,20 @@ enum earlyarg e_arg; } if (match) { + const char *extended_opt = index(userea,':'); + + if (!extended_opt) + extended_opt = index(userea, '='); switch(e_arg) { case ARG_DEBUG: + if (extended_opt) { + extended_opt++; + debug_fields(extended_opt); + } + return 1; break; case ARG_VERSION: { boolean insert_into_pastebuf = FALSE; - const char *extended_opt = index(userea,':'); - - if (!extended_opt) - extended_opt = index(userea, '='); if (extended_opt) { extended_opt++; @@ -812,7 +826,7 @@ enum earlyarg e_arg; } } early_version_info(insert_into_pastebuf); - return TRUE; + return 2; break; } default: @@ -822,4 +836,63 @@ enum earlyarg e_arg; return FALSE; } +/* + * These are internal controls to aid developers with + * testing and debugging particular aspects of the code. + * They are not player options and the only place they + * are documented is right here. No gameplay is altered. + * + * test - test whether this parser is working + * ttystatus - TTY: + * immediateflips - WIN32: turn off display performance + * optimization so that display output + * can be debugged without buffering. + */ +void +debug_fields(opts) +const char *opts; +{ + char *op; + boolean negated = FALSE; + boolean retval = TRUE; + + while ((op = index(opts, ',')) != 0) { + *op++ = 0; + /* recurse */ + debug_fields(op); + } + if (strlen(opts) > BUFSZ / 2) + return; + + + /* strip leading and trailing white space */ + while (isspace((uchar) *opts)) + opts++; + op = eos((char *) opts); + while (--op >= opts && isspace((uchar) *op)) + *op = '\0'; + + if (!*opts) { + /* empty */ + return; + } + while ((*opts == '!') || !strncmpi(opts, "no", 2)) { + if (*opts == '!') + opts++; + else + opts += 2; + negated = !negated; + } + if (match_optname(opts, "test", 4, FALSE)) + iflags.debug.test = negated ? FALSE : TRUE; +#ifdef TTY_GRAPHICS + if (match_optname(opts, "ttystatus", 9, FALSE)) + iflags.debug.ttystatus = negated ? FALSE : TRUE; +#endif +#ifdef WIN32 + if (match_optname(opts, "immediateflips", 14, FALSE)) + iflags.debug.immediateflips = negated ? FALSE : TRUE; +#endif + return; +} /*allmain.c*/ diff --git a/sys/share/pcmain.c b/sys/share/pcmain.c index eea29f8de..6bb6cfc29 100644 --- a/sys/share/pcmain.c +++ b/sys/share/pcmain.c @@ -331,9 +331,14 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/ Strcpy(hackdir, HACKDIR); #endif if (argc > 1) { - if (argcheck(argc, argv, ARG_VERSION)) + if (argcheck(argc, argv, ARG_VERSION) == 2) nethack_exit(EXIT_SUCCESS); + if (argcheck(argc, argv, ARG_DEBUG) == 1) { + argc--; + argv++; + } + if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { /* avoid matching "-dec" for DECgraphics; since the man page * says -d directory, hope nobody's using -desomething_else diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index c856e758b..3c91b3e55 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -111,9 +111,14 @@ char *argv[]; dir = nh_getenv("HACKDIR"); if (argc > 1) { - if (argcheck(argc, argv, ARG_VERSION)) + if (argcheck(argc, argv, ARG_VERSION) == 2) exit(EXIT_SUCCESS); + if (argcheck(argc, argv, ARG_DEBUG) == 1) { + argc--; + argv++; + } + if (!strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { /* avoid matching "-dec" for DECgraphics; since the man page * says -d directory, hope nobody's using -desomething_else diff --git a/sys/winnt/nttty.c b/sys/winnt/nttty.c index 9d1114498..4fbc11c63 100644 --- a/sys/winnt/nttty.c +++ b/sys/winnt/nttty.c @@ -252,8 +252,6 @@ cell_t undefined_cell; static boolean buffer_flipping_initialized = FALSE; -boolean do_immediate_flips = FALSE; - static void check_buffer_size(int width, int height); static cell_t * buffer_get_cell(console_buffer_t * buffer, int x, int y); @@ -370,7 +368,7 @@ static void buffer_fill_to_end(console_buffer_t * buffer, cell_t * src, while (dst != sentinel) *dst++ = clear_cell; - if (do_immediate_flips && buffer == &back_buffer) + if (iflags.debug.immediateflips && buffer == &back_buffer) back_buffer_flip(); } @@ -379,7 +377,7 @@ static void back_buffer_write(cell_t * cell, int x, int y) cell_t * dst = buffer_get_cell(&back_buffer, x, y); *dst = *cell; - if (do_immediate_flips) + if (iflags.debug.immediateflips) back_buffer_flip(); } @@ -393,7 +391,7 @@ static void back_buffer_clear_to_end_of_line(int x, int y) while (cell != sentinel) *cell++ = clear_cell; - if (do_immediate_flips) + if (iflags.debug.immediateflips) back_buffer_flip(); }