extern const char advent_to_ascii[128];
extern const char ascii_to_advent[128];
-enum bug_e {
+enum bugtype {
MESSAGE_LINE_GT_70_CHARACTERS, // 0
NULL_LINE_IN_MESSAGE, // 1
TOO_MANY_WORDS_OF_MESSAGES, // 2
CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION, // 25
LOCATION_HAS_NO_TRAVEL_ENTRIES, // 26
HINT_NUMBER_EXCEEDS_GOTO_LIST, // 27
- INVALID_MOTH_RETURNED_BY_DATA_FUNCTION, // 28
- TOO_MANY_PARAMETERS_GIVEN_TO_SETPRM, // 29
+ TOO_MANY_PARAMETERS_GIVEN_TO_SETPRM, // 28
SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN=99, // 99
ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH, // 100
};
-static inline void bug(enum bug_e num, const char *error_string) __attribute__((__noreturn__));
-static inline void bug(enum bug_e num, const char *error_string)
+static inline void bug(enum bugtype num, const char *error_string) __attribute__((__noreturn__));
+static inline void bug(enum bugtype num, const char *error_string)
{
fprintf(stderr, "Fatal error %d, %s.\n", num, error_string);
exit(EXIT_FAILURE);
break;
default:
fprintf(stderr,
- "Usage: %s [-l logfilename] [-o] [-r restorefilename] [-s] \n", argv[0]);
+ "Usage: %s [-l logfilename] [-o] [-r restorefilename] [-s] \n", argv[0]);
fprintf(stderr,
- " where -l creates a log file of your game named as specified'\n");
+ " where -l creates a log file of your game named as specified'\n");
fprintf(stderr,
- " -o 'oldstyle' (no prompt, no command editing, displays 'Initialising...')\n");
+ " -o 'oldstyle' (no prompt, no command editing, displays 'Initialising...')\n");
fprintf(stderr,
- " -r indicates restoring from specified saved game file\n");
+ " -r indicates restoring from specified saved game file\n");
fprintf(stderr,
- " -s indicates playing with command editing suppressed\n");
+ " -s indicates playing with command editing suppressed\n");
exit(-1);
break;
}
/* else fall through */
} else if (game.prop[motion] != game.newloc / 100 - 3)
break;
- L12:
+L12:
do {
if (TRAVEL[kk] < 0)
- BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION);
+ BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION);
++kk;
game.newloc = labs(TRAVEL[kk]) / 1000;
} while
/* FIXME: Arithmetic on location numbers */
game.newloc = 99 + 100 - game.loc;
if (game.holdng > 1 || (game.holdng == 1 && !TOTING(EMRALD))) {
- game.newloc = game.loc;
- RSPEAK(MUST_DROP);
- }
+ game.newloc = game.loc;
+ RSPEAK(MUST_DROP);
+ }
return true;
case 2:
/* Travel 302. Plover transport. Drop the emerald (only use
* plover-passage to get it out. Having dropped it, go back and
* pretend he wasn't carrying it after all. */
DROP(EMRALD, game.loc);
- goto L12;
+ goto L12;
case 3:
/* Travel 303. Troll bridge. Must be done only as special
* motion so that dwarves won't wander across and encounter
BUG(SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST);
}
} while
- (false);
+ (false);
/* FIXME: Arithmetic on location number, becoming a message number */
RSPEAK(game.newloc - 500);
game.newloc = game.loc;
void* xmalloc(size_t size)
{
- void* ptr = malloc(size);
- if (ptr == NULL)
- {
- fprintf(stderr, "Out of memory!\n");
- exit(EXIT_FAILURE);
+ void* ptr = malloc(size);
+ if (ptr == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ exit(EXIT_FAILURE);
}
- return(ptr);
+ return (ptr);
}
char* xstrdup(const char* s)
void echo_input(FILE* destination, char* input_prompt, char* input)
{
- size_t len = strlen(input_prompt) + strlen(input) + 1;
- char* prompt_and_input = (char*) xmalloc(len);
- strcpy(prompt_and_input, input_prompt);
- strcat(prompt_and_input, input);
- fprintf(destination, "%s\n", prompt_and_input);
- free(prompt_and_input);
+ size_t len = strlen(input_prompt) + strlen(input) + 1;
+ char* prompt_and_input = (char*) xmalloc(len);
+ strcpy(prompt_and_input, input_prompt);
+ strcat(prompt_and_input, input);
+ fprintf(destination, "%s\n", prompt_and_input);
+ free(prompt_and_input);
}
char* get_input()
-{
- // Set up the prompt
- char input_prompt[] = "> ";
- if (!prompt)
- input_prompt[0] = '\0';
-
- // Print a blank line if game.blklin tells us to.
- if (game.blklin == true)
- printf("\n");
-
- char* input;
- while (true)
- {
- if (editline)
- input = linenoise(input_prompt);
- else
- {
- input = NULL;
- size_t n = 0;
- if (isatty(0))
- printf("%s", input_prompt);
- IGNORE(getline(&input, &n, stdin));
- }
-
- if (input == NULL) // Got EOF; quit.
- exit(EXIT_SUCCESS);
- else if (input[0] == '#') // Ignore comments.
- continue;
- else // We have a 'normal' line; leave the loop.
- break;
+{
+ // Set up the prompt
+ char input_prompt[] = "> ";
+ if (!prompt)
+ input_prompt[0] = '\0';
+
+ // Print a blank line if game.blklin tells us to.
+ if (game.blklin == true)
+ printf("\n");
+
+ char* input;
+ while (true) {
+ if (editline)
+ input = linenoise(input_prompt);
+ else {
+ input = NULL;
+ size_t n = 0;
+ if (isatty(0))
+ printf("%s", input_prompt);
+ IGNORE(getline(&input, &n, stdin));
+ }
+
+ if (input == NULL) // Got EOF; quit.
+ exit(EXIT_SUCCESS);
+ else if (input[0] == '#') // Ignore comments.
+ continue;
+ else // We have a 'normal' line; leave the loop.
+ break;
}
- // Strip trailing newlines from the input
- input[strcspn(input, "\n")] = 0;
+ // Strip trailing newlines from the input
+ input[strcspn(input, "\n")] = 0;
+
+ linenoiseHistoryAdd(input);
- linenoiseHistoryAdd(input);
+ if (!isatty(0))
+ echo_input(stdout, input_prompt, input);
- if (!isatty(0))
- echo_input(stdout, input_prompt, input);
+ if (logfp)
+ echo_input(logfp, input_prompt, input);
- if (logfp)
- echo_input(logfp, input_prompt, input);
-
- return(input);
+ return (input);
}
bool YES(vocab_t question, vocab_t yes_response, vocab_t no_response)
{
char* reply;
bool outcome;
-
+
for (;;) {
- RSPEAK(question);
-
- reply = get_input();
-
- char* firstword = (char*) xmalloc(strlen(reply));
- sscanf(reply, "%s", firstword);
-
- for (int i = 0; i < (int)strlen(firstword); ++i)
- firstword[i] = tolower(firstword[i]);
-
- int yes = strncmp("yes", firstword, sizeof("yes") - 1);
- int y = strncmp("y", firstword, sizeof("y") - 1);
- int no = strncmp("no", firstword, sizeof("no") - 1);
- int n = strncmp("n", firstword, sizeof("n") - 1);
-
- free(firstword);
-
- if (yes == 0 || y == 0) {
- RSPEAK(yes_response);
- outcome = true;
- break;
- }
- else if (no == 0 || n == 0) {
- RSPEAK(no_response);
- outcome = false;
- break;
- }
- else
- RSPEAK(PLEASE_ANSWER);
+ RSPEAK(question);
+
+ reply = get_input();
+
+ char* firstword = (char*) xmalloc(strlen(reply));
+ sscanf(reply, "%s", firstword);
+
+ for (int i = 0; i < (int)strlen(firstword); ++i)
+ firstword[i] = tolower(firstword[i]);
+
+ int yes = strncmp("yes", firstword, sizeof("yes") - 1);
+ int y = strncmp("y", firstword, sizeof("y") - 1);
+ int no = strncmp("no", firstword, sizeof("no") - 1);
+ int n = strncmp("n", firstword, sizeof("n") - 1);
+
+ free(firstword);
+
+ if (yes == 0 || y == 0) {
+ RSPEAK(yes_response);
+ outcome = true;
+ break;
+ } else if (no == 0 || n == 0) {
+ RSPEAK(no_response);
+ outcome = false;
+ break;
+ } else
+ RSPEAK(PLEASE_ANSWER);
}
linenoiseFree(reply);
- return(outcome);
+ return (outcome);
}
/* Line-parsing routines (GETTXT, MAKEWD, PUTTXT, SHFTXT) */