]> diplodocus.org Git - nmh/blobdiff - sbr/read_switch_multiword_via_readline.c
scansbr.c: Move interface to own file.
[nmh] / sbr / read_switch_multiword_via_readline.c
index fd6244cd68a8026d3521e9397367ba67c31a38c1..df91701c7872d841b49c756abdd19373a4de601d 100644 (file)
@@ -1,12 +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 <h/mh.h>
+#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 <readline/readline.h>
@@ -50,6 +54,8 @@ 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:
@@ -59,10 +65,8 @@ read_switch_multiword_via_readline(char *prompt, struct swit *ansp)
                printf(" -%s unknown. Hit <CR> for help.\n", *cpp);
                continue;
            default:
-               free(ans);
                return cpp;
        }
-       free(ans);
     }
 }
 
@@ -76,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 *