diff options
author | Eliot Horowitz <eliot@10gen.com> | 2011-12-24 15:33:26 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2011-12-24 15:33:45 -0500 |
commit | ae1ecd9c786911f9f1f0242f0f7d702b3e5dfeba (patch) | |
tree | 92f8e1649e6f080b251ff5f1763679a72eb59b34 /src/third_party/linenoise/example.c | |
parent | dfa4cd7e2cf109b072440155fabc08a93c8045a0 (diff) | |
download | mongo-ae1ecd9c786911f9f1f0242f0f7d702b3e5dfeba.tar.gz |
bulk move of code to src/ SERVER-4551
Diffstat (limited to 'src/third_party/linenoise/example.c')
-rw-r--r-- | src/third_party/linenoise/example.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/third_party/linenoise/example.c b/src/third_party/linenoise/example.c new file mode 100644 index 00000000000..ea0b515c1fc --- /dev/null +++ b/src/third_party/linenoise/example.c @@ -0,0 +1,27 @@ +#include <stdio.h> +#include <stdlib.h> +#include "linenoise.h" + + +void completion(const char *buf, linenoiseCompletions *lc) { + if (buf[0] == 'h') { + linenoiseAddCompletion(lc,"hello"); + linenoiseAddCompletion(lc,"hello there"); + } +} + +int main(void) { + char *line; + + linenoiseSetCompletionCallback(completion); + linenoiseHistoryLoad("history.txt"); /* Load the history at startup */ + while((line = linenoise("hello> ")) != NULL) { + if (line[0] != '\0') { + printf("echo: '%s'\n", line); + linenoiseHistoryAdd(line); + linenoiseHistorySave("history.txt"); /* Save every new entry */ + } + free(line); + } + return 0; +} |