long prop[NOBJECTS + 1];
};
+/*
+ * Game application settings - settings, but not state of the game, per se.
+ * This data is not saved in a saved game.
+ */
+struct settings_t {
+ FILE *logfp;
+ bool oldstyle;
+ bool prompt;
+};
+
struct command_t {
enum speechpart part;
vocab_t verb;
};
extern struct game_t game;
-extern FILE *logfp;
-extern bool oldstyle, prompt;
+extern struct settings_t settings;
extern char* xstrdup(const char* s);
extern void* xmalloc(size_t size);
extern long initialise(void);
extern int action(struct command_t *command);
-/* Alas, declaring this static confuses the coverage analyzer */
void bug(enum bugtype, const char *) __attribute__((__noreturn__));
/* end */
#include <stdbool.h>
#include "advent.h"
-FILE *logfp = NULL;
-bool oldstyle = false;
-bool prompt = true;
-
int main(int argc, char *argv[])
{
int ch;
* Initialisation
*/
+struct settings_t settings = {
+ .logfp = NULL,
+ .oldstyle = false,
+ .prompt = true
+};
+
struct game_t game = {
.dloc[1] = LOC_KINGHALL,
.dloc[2] = LOC_WESTBANK,
long initialise(void)
{
- if (oldstyle)
+ if (settings.oldstyle)
printf("Initialising...\n");
srand(time(NULL));
#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);
}
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':
}
#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 (;;) {
{
// Set up the prompt
char input_prompt[] = "> ";
- if (!prompt)
+ if (!settings.prompt)
input_prompt[0] = '\0';
// Print a blank line if game.blklin tells us to.
if (!isatty(0))
echo_input(stdout, input_prompt, input);
- if (logfp)
- echo_input(logfp, "", input);
+ if (settings.logfp)
+ echo_input(settings.logfp, "", input);
return (input);
}
{
for (int i = 0; i < NMOTIONS; ++i) {
for (int j = 0; j < motions[i].words.n; ++j) {
- if (strcasecmp(word, motions[i].words.strs[j]) == 0 && (strlen(word) > 1 || strchr(ignore, word[0]) == NULL || !oldstyle))
+ if (strcasecmp(word, motions[i].words.strs[j]) == 0 && (strlen(word) > 1 || strchr(ignore, word[0]) == NULL || !settings.oldstyle))
return (i);
}
}
{
for (int i = 0; i < NACTIONS; ++i) {
for (int j = 0; j < actions[i].words.n; ++j) {
- if (strcasecmp(word, actions[i].words.strs[j]) == 0 && (strlen(word) > 1 || strchr(ignore, word[0]) == NULL || !oldstyle))
+ if (strcasecmp(word, actions[i].words.strs[j]) == 0 && (strlen(word) > 1 || strchr(ignore, word[0]) == NULL || !settings.oldstyle))
return (i);
}
}