aboutsummaryrefslogtreecommitdiff
path: root/src/shell.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-02-25 14:02:53 +0000
committerdrh <drh@noemail.net>2015-02-25 14:02:53 +0000
commit2f82071478261a63280dec5c954f59c3dbdf90ca (patch)
tree7ca160401e4989273331267f6a7c47659f1b225b /src/shell.c
parent878acb32efa879e0b680cce08f63e65f89fa4f77 (diff)
parentb492e23b42c504b72c4cb2ecc431abacae216847 (diff)
downloadsqlite-2f82071478261a63280dec5c954f59c3dbdf90ca.tar.gz
sqlite-2f82071478261a63280dec5c954f59c3dbdf90ca.zip
Merge the latest trunk fixes into the sessions branch.
FossilOrigin-Name: 131a2d3116436ca6304777c9c5d46b7c4051d949
Diffstat (limited to 'src/shell.c')
-rw-r--r--src/shell.c52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/shell.c b/src/shell.c
index 4b05c1984..05c79d4fa 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -59,18 +59,38 @@
# include <readline/readline.h>
# include <readline/history.h>
#endif
+
#if HAVE_EDITLINE
-# undef HAVE_READLINE
-# define HAVE_READLINE 1
# include <editline/readline.h>
#endif
-#if !HAVE_READLINE
-# define add_history(X)
-# define read_history(X)
-# define write_history(X)
-# define stifle_history(X)
+
+#if HAVE_EDITLINE || HAVE_READLINE
+
+# define shell_add_history(X) add_history(X)
+# define shell_read_history(X) read_history(X)
+# define shell_write_history(X) write_history(X)
+# define shell_stifle_history(X) stifle_history(X)
+# define shell_readline(X) readline(X)
+
+#elif HAVE_LINENOISE
+
+# include "linenoise.h"
+# define shell_add_history(X) linenoiseHistoryAdd(X)
+# define shell_read_history(X) linenoiseHistoryLoad(X)
+# define shell_write_history(X) linenoiseHistorySave(X)
+# define shell_stifle_history(X) linenoiseHistorySetMaxLen(X)
+# define shell_readline(X) linenoise(X)
+
+#else
+
+# define shell_read_history(X)
+# define shell_write_history(X)
+# define shell_stifle_history(X)
+
+# define SHELL_USE_LOCAL_GETLINE 1
#endif
+
#if defined(_WIN32) || defined(WIN32)
# include <io.h>
# include <fcntl.h>
@@ -451,14 +471,14 @@ static char *one_input_line(FILE *in, char *zPrior, int isContinuation){
zResult = local_getline(zPrior, in);
}else{
zPrompt = isContinuation ? continuePrompt : mainPrompt;
-#if HAVE_READLINE
- free(zPrior);
- zResult = readline(zPrompt);
- if( zResult && *zResult ) add_history(zResult);
-#else
+#if SHELL_USE_LOCAL_GETLINE
printf("%s", zPrompt);
fflush(stdout);
zResult = local_getline(zPrior, stdin);
+#else
+ free(zPrior);
+ zResult = shell_readline(zPrompt);
+ if( zResult && *zResult ) shell_add_history(zResult);
#endif
}
return zResult;
@@ -4917,13 +4937,11 @@ int main(int argc, char **argv){
sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
}
}
-#if HAVE_READLINE
- if( zHistory ) read_history(zHistory);
-#endif
+ if( zHistory ) shell_read_history(zHistory);
rc = process_input(&data, 0);
if( zHistory ){
- stifle_history(100);
- write_history(zHistory);
+ shell_stifle_history(100);
+ shell_write_history(zHistory);
free(zHistory);
}
}else{