+
+int
+is_true (const char *str)
+{
+ return
+ strcasecmp (str, "0") != 0 &&
+ strcasecmp (str, "f") != 0 &&
+ strcasecmp (str, "false") != 0 &&
+ strcasecmp (str, "n") != 0 &&
+ strcasecmp (str, "no") != 0;
+}
+
+/* XXX We could improve list parsing. */
+char **
+parse_string_list (const char *str)
+{
+ char **argv;
+ const char *p, *pend;
+ int argc, i;
+
+ argc = 1;
+ for (i = 0; str[i]; ++i)
+ if (str[i] == ' ') argc++;
+
+ argv = malloc (sizeof (char *) * (argc+1));
+ if (argv == NULL) { perror ("malloc"); exit (1); }
+
+ p = str;
+ i = 0;
+ while (*p) {
+ pend = strchrnul (p, ' ');
+ argv[i] = strndup (p, pend-p);
+ i++;
+ p = *pend == ' ' ? pend+1 : pend;
+ }
+ argv[i] = NULL;
+
+ return argv;
+}
+
+#ifdef HAVE_LIBREADLINE
+static char histfile[1024];
+static int nr_history_lines = 0;
+#endif
+
+static void
+initialize_readline (void)
+{
+#ifdef HAVE_LIBREADLINE
+ const char *home;
+
+ home = getenv ("HOME");
+ if (home) {
+ snprintf (histfile, sizeof histfile, "%s/.guestfish", home);
+ using_history ();
+ (void) read_history (histfile);
+ }
+
+ rl_readline_name = "guestfish";
+ rl_attempted_completion_function = do_completion;
+#endif
+}
+
+static void
+cleanup_readline (void)
+{
+#ifdef HAVE_LIBREADLINE
+ int fd;
+
+ if (histfile[0] != '\0') {
+ fd = open (histfile, O_WRONLY|O_CREAT, 0644);
+ if (fd == -1) {
+ perror (histfile);
+ return;
+ }
+ close (fd);
+
+ (void) append_history (nr_history_lines, histfile);
+ }
+#endif
+}
+
+static void
+add_history_line (const char *line)
+{
+#ifdef HAVE_LIBREADLINE
+ add_history (line);
+ nr_history_lines++;
+#endif
+}