Add -d option

This commit is contained in:
Eric S. Raymond 2023-03-29 16:04:36 -04:00
parent c80162b467
commit ff46cf7fac
3 changed files with 11 additions and 4 deletions

View file

@ -200,6 +200,7 @@ struct settings_t {
int argc; int argc;
int optind; int optind;
FILE *scriptfp; FILE *scriptfp;
int debug;
}; };
typedef struct { typedef struct {

9
main.c
View file

@ -1261,20 +1261,23 @@ int main(int argc, char *argv[])
/* Options. */ /* Options. */
#if defined ADVENT_AUTOSAVE #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"; const char* usage = "Usage: %s [-l logfilename] [-o] [-a filename] [script...]\n";
FILE *rfp = NULL; FILE *rfp = NULL;
const char* autosave_filename = NULL; const char* autosave_filename = NULL;
#elif !defined ADVENT_NOSAVE #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"; const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [script...]\n";
FILE *rfp = NULL; FILE *rfp = NULL;
#else #else
const char* opts = "l:o"; const char* opts = "dl:o";
const char* usage = "Usage: %s [-l logfilename] [-o] [script...]\n"; const char* usage = "Usage: %s [-l logfilename] [-o] [script...]\n";
#endif #endif
while ((ch = getopt(argc, argv, opts)) != EOF) { while ((ch = getopt(argc, argv, opts)) != EOF) {
switch (ch) { switch (ch) {
case 'd':
settings.debug +=1;
break;
case 'l': case 'l':
settings.logfp = fopen(optarg, "w"); settings.logfp = fopen(optarg, "w");
if (settings.logfp == NULL) if (settings.logfp == NULL)

5
misc.c
View file

@ -699,7 +699,7 @@ bool tstbit(int mask, int bit)
} }
void set_seed(int32_t seedval) void set_seed(int32_t seedval)
/* Set the LCG seed */ /* Set the LCG1 seed */
{ {
game.lcg_x = seedval % LCG_M; game.lcg_x = seedval % LCG_M;
if (game.lcg_x < 0) { if (game.lcg_x < 0) {
@ -718,6 +718,9 @@ static int32_t get_next_lcg_value(void)
{ {
int32_t old_x = game.lcg_x; int32_t old_x = game.lcg_x;
game.lcg_x = (LCG_A * game.lcg_x + LCG_C) % LCG_M; game.lcg_x = (LCG_A * game.lcg_x + LCG_C) % LCG_M;
if (settings.debug) {
printf("# random %d\n", old_x);
}
return old_x; return old_x;
} }