X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/43f8ebf56f22d904af392a2f2a0e402b1fffce8b..e00dc84d4ef84f1b939c8090d49729b41377421d:/sbr/read_switch_multiword_via_readline.c diff --git a/sbr/read_switch_multiword_via_readline.c b/sbr/read_switch_multiword_via_readline.c index 8696c57f..67d405c5 100644 --- a/sbr/read_switch_multiword_via_readline.c +++ b/sbr/read_switch_multiword_via_readline.c @@ -1,13 +1,16 @@ - -/* - * read_switch_multiword_via_readline.c -- get an answer from the user, with readline +/* read_switch_multiword_via_readline.c -- get an answer from the user, with readline * * This code is Copyright (c) 2012, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for * complete copyright information. */ -#include +#include "h/mh.h" +#include "read_switch_multiword_via_readline.h" +#include "smatch.h" +#include "brkstring.h" +#include "ambigsw.h" +#include "print_sw.h" #ifdef READLINE_SUPPORT #include @@ -34,7 +37,7 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp) rl_cmds = ansp; for (;;) { - ans = readline(prompt); + ans = readline(prompt); /* * If we get an EOF, return */ @@ -43,7 +46,7 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp) return NULL; if (ans[0] == '?' || ans[0] == '\0') { - printf("Options are:\n"); + puts("Options are:"); print_sw(ALL, ansp, "", stdout); free(ans); continue; @@ -51,19 +54,19 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp) add_history(ans); strncpy(ansbuf, ans, sizeof(ansbuf)); ansbuf[sizeof(ansbuf) - 1] = '\0'; + free(ans); + cpp = brkstring(ansbuf, " ", NULL); switch (smatch(*cpp, ansp)) { case AMBIGSW: - ambigsw(*cpp, ansp); + ambigsw(*cpp, ansp); continue; case UNKWNSW: - printf(" -%s unknown. Hit for help.\n", *cpp); + printf(" -%s unknown. Hit for help.\n", *cpp); continue; default: - free(ans); return cpp; } - free(ans); } } @@ -77,16 +80,12 @@ initialize_readline(void) static char ** nmh_completion(const char *text, int start, int end) { - char **matches; - NMH_UNUSED (end); - matches = (char **) NULL; - if (start == 0) - matches = rl_completion_matches(text, nmh_command_generator); + return rl_completion_matches(text, nmh_command_generator); - return matches; + return NULL; } static char * @@ -97,12 +96,12 @@ nmh_command_generator(const char *text, int state) char buf[256]; if (!state) { - list_index = 0; + list_index = 0; len = strlen(text); } while ((name = rl_cmds[list_index].sw)) { - list_index++; + list_index++; strncpy(buf, name, sizeof(buf)); buf[sizeof(buf) - 1] = '\0'; p = *brkstring(buf, " ", NULL); @@ -113,4 +112,3 @@ nmh_command_generator(const char *text, int state) return NULL; } #endif /* READLINE_SUPPORT */ -