- if (game.blklin)
- TYPE0();
- if (!MAPLIN(input))
- return false;
- *pword1=GETTXT(true,true,true);
- if (game.blklin && *pword1 < 0)
- continue;
- *pword1x=GETTXT(false,true,true);
- do {
- junk=GETTXT(false,true,true);
- } while
- (junk > 0);
- *pword2=GETTXT(true,true,true);
- *pword2x=GETTXT(false,true,true);
- do {
- junk=GETTXT(false,true,true);
- } while
- (junk > 0);
- if (GETTXT(true,true,true) <= 0)
- return true;
- RSPEAK(53);
+ if (game.blklin)
+ fputc('\n', stdout);;
+ if (!MAPLIN(input))
+ return false;
+ *pword1 = GETTXT(true, true, true);
+ if (game.blklin && *pword1 < 0)
+ continue;
+ *pword1x = GETTXT(false, true, true);
+ do {
+ junk = GETTXT(false, true, true);
+ } while
+ (junk > 0);
+ *pword2 = GETTXT(true, true, true);
+ *pword2x = GETTXT(false, true, true);
+ do {
+ junk = GETTXT(false, true, true);
+ } while
+ (junk > 0);
+ if (GETTXT(true, true, true) <= 0)
+ return true;
+ rspeak(TWO_WORDS);
+ }
+}
+
+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);
+}
+
+int word_count(char* s)
+{
+ char* copy = xstrdup(s);
+ char delims[] = " \t";
+ int count = 0;
+ char* word;
+
+ word = strtok(copy, delims);
+ while(word != NULL)
+ {
+ word = strtok(NULL, delims);
+ ++count;
+ }
+ free(copy);
+ return(count);
+}
+
+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))
+ // LCOV_EXCL_START
+ // Should be unreachable in tests, as they will use a non-interactive shell.
+ printf("%s", input_prompt);
+ // LCOV_EXCL_STOP
+ ssize_t numread = getline(&input, &n, stdin);
+ if (numread == -1) // Got EOF; return with it.
+ return(NULL);
+ }
+
+ if (input == NULL) // Got EOF; return with it.
+ return(input);
+ 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;
+
+ linenoiseHistoryAdd(input);
+
+ if (!isatty(0))
+ echo_input(stdout, input_prompt, input);
+
+ if (logfp)
+ echo_input(logfp, input_prompt, input);
+
+ return (input);
+}
+
+bool silent_yes()
+{
+ char* reply;
+ bool outcome;
+
+ for (;;) {
+ reply = get_input();
+ if (reply == NULL) {
+ // LCOV_EXCL_START
+ // Should be unreachable. Reply should never be NULL
+ linenoiseFree(reply);
+ exit(EXIT_SUCCESS);
+ // LCOV_EXCL_STOP