From: Eric S. Raymond Date: Wed, 29 Mar 2023 20:04:36 +0000 (-0400) Subject: Add -d option X-Git-Tag: 1.15~28 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=ff46cf7faccbc8a887c033c34681c526ca740747;p=open-adventure.git Add -d option --- diff --git a/advent.h b/advent.h index 4d1c9f3..8a31a9c 100644 --- a/advent.h +++ b/advent.h @@ -200,6 +200,7 @@ struct settings_t { int argc; int optind; FILE *scriptfp; + int debug; }; typedef struct { diff --git a/main.c b/main.c index f83c4e0..ab23ad9 100644 --- a/main.c +++ b/main.c @@ -1261,20 +1261,23 @@ int main(int argc, char *argv[]) /* Options. */ #if defined ADVENT_AUTOSAVE - const char* opts = "l:oa:"; + const char* opts = "dl:oa:"; const char* usage = "Usage: %s [-l logfilename] [-o] [-a filename] [script...]\n"; FILE *rfp = NULL; const char* autosave_filename = NULL; #elif !defined ADVENT_NOSAVE - const char* opts = "l:or:"; + const char* opts = "dl:or:"; const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [script...]\n"; FILE *rfp = NULL; #else - const char* opts = "l:o"; + const char* opts = "dl:o"; const char* usage = "Usage: %s [-l logfilename] [-o] [script...]\n"; #endif while ((ch = getopt(argc, argv, opts)) != EOF) { switch (ch) { + case 'd': + settings.debug +=1; + break; case 'l': settings.logfp = fopen(optarg, "w"); if (settings.logfp == NULL) diff --git a/misc.c b/misc.c index c6733d5..34d045c 100644 --- a/misc.c +++ b/misc.c @@ -699,7 +699,7 @@ bool tstbit(int mask, int bit) } void set_seed(int32_t seedval) -/* Set the LCG seed */ +/* Set the LCG1 seed */ { game.lcg_x = seedval % LCG_M; if (game.lcg_x < 0) { @@ -718,6 +718,9 @@ static int32_t get_next_lcg_value(void) { int32_t old_x = game.lcg_x; game.lcg_x = (LCG_A * game.lcg_x + LCG_C) % LCG_M; + if (settings.debug) { + printf("# random %d\n", old_x); + } return old_x; }