From: Jason S. Ninneman Date: Sat, 1 Jul 2017 13:51:00 +0000 (-0700) Subject: Replace linenoise with libedit in code and build. X-Git-Tag: takebird~152 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=ad3b097c9e587c1474cc1cac93f89ada853902ff;p=open-adventure.git Replace linenoise with libedit in code and build. --- diff --git a/Makefile b/Makefile index 43f1f95..a6d39b6 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,6 @@ # Makefile for the open-source release of adventure 2.5 -# Note: If you're building from the repository rather than the source tarball, -# do this to get the linenoise library where you can use it: -# -# git submodule update --recursive --remote --init -# -# Therafter, you can update it like this: -# -# git submodule update --recursive --remote -# -# but this should seldom be necessary as that library is pretty stable. -# -# You will also need Python 3 YAML. Under Debian or ubuntu: +# You will need Python 3 YAML. Under Debian or ubuntu: # # apt-get install python3-yaml # @@ -31,23 +20,23 @@ VERS=$(shell sed -n #include #include "advent.h" -#include "linenoise/linenoise.h" #include "dungeon.h" FILE *logfp = NULL, *rfp = NULL; diff --git a/main.c b/main.c index 84eca57..ce383a0 100644 --- a/main.c +++ b/main.c @@ -21,7 +21,6 @@ #include #include #include "advent.h" -#include "linenoise/linenoise.h" #include "dungeon.h" #define DIM(a) (sizeof(a)/sizeof(a[0])) @@ -115,8 +114,6 @@ int main(int argc, char *argv[]) } } - linenoiseHistorySetMaxLen(350); - /* Initialize game variables */ long seedval = initialise(); @@ -1036,7 +1033,7 @@ L2600: } strncpy(inputbuf, input, LINESIZE - 1); - linenoiseFree(input); + free(input); long tokens[4]; tokenize(inputbuf, tokens); diff --git a/misc.c b/misc.c index 7cc26fc..c907d12 100644 --- a/misc.c +++ b/misc.c @@ -5,9 +5,9 @@ #include #include #include +#include #include "advent.h" -#include "linenoise/linenoise.h" #include "dungeon.h" char* xstrdup(const char* s) @@ -334,27 +334,12 @@ char* get_input() 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. - free(input); - return (NULL); - } - } + input = readline(input_prompt); if (input == NULL) // Got EOF; return with it. return (input); else if (input[0] == '#') { // Ignore comments. - linenoiseFree(input); + free(input); continue; } else // We have a 'normal' line; leave the loop. break; @@ -363,7 +348,7 @@ char* get_input() // Strip trailing newlines from the input input[strcspn(input, "\n")] = 0; - linenoiseHistoryAdd(input); + add_history(input); if (!isatty(0)) echo_input(stdout, input_prompt, input); @@ -384,7 +369,7 @@ bool silent_yes() if (reply == NULL) { // LCOV_EXCL_START // Should be unreachable. Reply should never be NULL - linenoiseFree(reply); + free(reply); exit(EXIT_SUCCESS); // LCOV_EXCL_STOP } @@ -392,7 +377,7 @@ bool silent_yes() char* firstword = (char*) xmalloc(strlen(reply) + 1); sscanf(reply, "%s", firstword); - linenoiseFree(reply); + free(reply); for (int i = 0; i < (int)strlen(firstword); ++i) firstword[i] = tolower(firstword[i]); @@ -431,7 +416,7 @@ bool yes(const char* question, const char* yes_response, const char* no_response if (reply == NULL) { // LCOV_EXCL_START // Should be unreachable. Reply should never be NULL - linenoiseFree(reply); + free(reply); exit(EXIT_SUCCESS); // LCOV_EXCL_STOP } @@ -439,7 +424,7 @@ bool yes(const char* question, const char* yes_response, const char* no_response char* firstword = (char*) xmalloc(strlen(reply) + 1); sscanf(reply, "%s", firstword); - linenoiseFree(reply); + free(reply); for (int i = 0; i < (int)strlen(firstword); ++i) firstword[i] = tolower(firstword[i]); diff --git a/saveresume.c b/saveresume.c index 3ec4ebd..c275986 100644 --- a/saveresume.c +++ b/saveresume.c @@ -1,9 +1,9 @@ #include #include +#include #include "advent.h" #include "dungeon.h" -#include "linenoise/linenoise.h" /* * (ESR) This replaces a bunch of particularly nasty FORTRAN-derived code; @@ -63,13 +63,13 @@ int suspend(void) game.saved = game.saved + 5; while (fp == NULL) { - char* name = linenoise("\nFile name: "); + char* name = readline("\nFile name: "); if (name == NULL) return GO_TOP; fp = fopen(name, WRITE_MODE); if (fp == NULL) printf("Can't open file %s, try again.\n", name); - linenoiseFree(name); + free(name); } savefile(fp, VRSION); @@ -95,13 +95,13 @@ int resume(void) } while (fp == NULL) { - char* name = linenoise("\nFile name: "); + char* name = readline("\nFile name: "); if (name == NULL) return GO_TOP; fp = fopen(name, READ_MODE); if (fp == NULL) printf("Can't open file %s, try again.\n", name); - linenoiseFree(name); + free(name); } return restore(fp);