Moved application settings to settings_t struct

Since logfp, oldstyle, and prompt were application settings, rather than
have them all as global vars, move them to a single global var, seperate
from game state, as they aren't, technically, game state, but are
application settings.
This commit is contained in:
Aaron Traas 2017-07-02 02:46:04 -04:00 committed by Eric S. Raymond
parent d23111daba
commit 7eaefce61d
5 changed files with 31 additions and 25 deletions

20
main.c
View file

@ -25,17 +25,13 @@
#define DIM(a) (sizeof(a)/sizeof(a[0]))
FILE *logfp = NULL;
bool oldstyle = false;
bool prompt = true;
// LCOV_EXCL_START
// exclude from coverage analysis because it requires interactivity to test
static void sig_handler(int signo)
{
if (signo == SIGINT) {
if (logfp != NULL)
fflush(logfp);
if (settings.logfp != NULL)
fflush(settings.logfp);
}
exit(EXIT_FAILURE);
}
@ -71,16 +67,16 @@ int main(int argc, char *argv[])
while ((ch = getopt(argc, argv, opts)) != EOF) {
switch (ch) {
case 'l':
logfp = fopen(optarg, "w");
if (logfp == NULL)
settings.logfp = fopen(optarg, "w");
if (settings.logfp == NULL)
fprintf(stderr,
"advent: can't open logfile %s for write\n",
optarg);
signal(SIGINT, sig_handler);
break;
case 'o':
oldstyle = true;
prompt = false;
settings.oldstyle = true;
settings.prompt = false;
break;
#ifndef ADVENT_NOSAVE
case 'r':
@ -121,8 +117,8 @@ int main(int argc, char *argv[])
}
#endif
if (logfp)
fprintf(logfp, "seed %ld\n", seedval);
if (settings.logfp)
fprintf(settings.logfp, "seed %ld\n", seedval);
/* interpret commands until EOF or interrupt */
for (;;) {