+/*
+ * Copyright (C) 2011 Andre Noll <maan@tuebingen.mpg.de>
+ *
+ * Licensed under the GPL v2. For licencing details see COPYING.
+ */
+
+/** \file interactive.c Readline abstraction for interactive sessions. */
+
+#include "para.h"
+
+#include <regex.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+#include <sys/ioctl.h>
+#include <signal.h>
+
+#include "fd.h"
+#include "buffer_tree.h"
+#include "list.h"
+#include "sched.h"
+#include "interactive.h"
+#include "string.h"
+#include "error.h"
+
+struct i9e_private {
+ struct i9e_client_info *ici;
+ FILE *stderr_stream;
+ int num_columns;
+ char empty_line[1000];
+ struct task *task;
+ struct btr_node *stdout_btrn;
+ bool last_write_was_status;
+ bool line_handler_running;
+ bool input_eof;
+ bool caught_sigint;
+ bool caught_sigterm;
+ Keymap standard_km;
+ Keymap bare_km;
+};
+static struct i9e_private i9e_private, *i9ep = &i9e_private;
+
+/**
+ * Return the error state of the i9e task.
+ *
+ * This is mainly useful for other tasks to tell whether the i9e task is still
+ * running.
+ *
+ * \return A negative return value of zero means the i9e task terminated. Only
+ * in this case it is safe to call ie9_close().
+ */
+int i9e_get_error(void)
+{
+ return task_status(i9ep->task);
+}
+
+static bool is_prefix(const char *partial, const char *full, size_t len)
+{
+ if (len == 0)
+ len = strlen(partial);
+ return !strncmp(partial, full, len);
+}
+
+/*
+ * Generator function for command completion. STATE lets us know whether
+ * to start from scratch; without any state (i.e. STATE == 0), then we
+ * start at the top of the list.
+ */
+static char *command_generator(const char *text, int state)
+{
+ static int list_index, len;
+ const char *name;
+ struct i9e_client_info *ici = i9ep->ici;
+
+ rl_attempted_completion_over = 1; /* disable filename completion */
+ /*
+ * If this is a new word to complete, initialize now. This includes
+ * saving the length of TEXT for efficiency, and initializing the index
+ * variable to 0.
+ */
+ if (state == 0) {
+ list_index = 0;
+ len = strlen(text);
+ }
+ /* Return the next name which partially matches from the command list. */
+ while ((name = ici->completers[list_index].name)) {
+ list_index++;
+ if (is_prefix(text, name, len))
+ return para_strdup(name);
+ }
+ return NULL; /* no names matched */
+}
+
+static void reset_completion_result(struct i9e_completion_result *cr)
+{
+ cr->dont_append_space = false;
+ cr->filename_completion_desired = false;
+ cr->matches = NULL;
+}
+
+static void create_matches(struct i9e_completion_info *ci,
+ struct i9e_completer *completers,
+ struct i9e_completion_result *cr)
+{
+ int i, ret;
+
+ reset_completion_result(cr);
+
+ ret = create_argv(ci->buffer, " ", &ci->argv);
+ if (ret < 0 || !ci->argv[0])
+ return;
+
+ ci->argc = ret;
+ ci->word_num = compute_word_num(ci->buffer, " ", ci->point);
+ for (i = 0; completers[i].name; i++) {
+ if (strcmp(completers[i].name, ci->argv[0]) != 0)
+ continue;
+ completers[i].completer(ci, cr);
+ break;
+ }
+ PARA_DEBUG_LOG("current word: %d (%s)\n", ci->word_num,
+ ci->argv[ci->word_num]);
+ if (cr->matches)
+ for (i = 0; cr->matches[i]; i++)
+ PARA_DEBUG_LOG("match %d: %s\n", i, cr->matches[i]);
+}
+
+static char *completion_generator(const char *word, int state)
+{
+ static int list_index;
+ static char **argv, **matches;
+ struct i9e_completer *completers = i9ep->ici->completers;
+ struct i9e_completion_info ci = {
+ .word = (char *)word,
+ .point = rl_point,
+ .buffer = rl_line_buffer,
+ };
+ struct i9e_completion_result cr = {.matches = NULL};
+
+ if (state != 0)
+ goto out;
+ /* clean up previous matches and set defaults */
+ free(matches);
+ matches = NULL;
+ free_argv(argv);
+ argv = NULL;
+ list_index = 0;
+ rl_completion_append_character = ' ';
+ rl_completion_suppress_append = false;
+ rl_attempted_completion_over = true;
+
+ create_matches(&ci, completers, &cr);
+
+ matches = cr.matches;
+ argv = ci.argv;
+ rl_completion_suppress_append = cr.dont_append_space;
+ rl_attempted_completion_over = !cr.filename_completion_desired;
+out:
+ if (!matches)
+ return NULL;
+ return matches[list_index++];
+}
+
+/*
+ * Attempt to complete on the contents of TEXT. START and END bound the
+ * region of rl_line_buffer that contains the word to complete. TEXT is
+ * the word to complete. We can use the entire contents of rl_line_buffer
+ * in case we want to do some simple parsing. Return the array of matches,
+ * or NULL if there aren't any.
+ */
+static char **i9e_completer(const char *text, int start, __a_unused int end)
+{
+ struct i9e_client_info *ici = i9ep->ici;
+
+ if (!ici->completers)
+ return NULL;
+ /* Complete on command names if this is the first word in the line. */
+ if (start == 0)
+ return rl_completion_matches(text, command_generator);
+ return rl_completion_matches(text, completion_generator);
+}
+
+/**
+ * Prepare writing to stdout.
+ *
+ * \param producer The buffer tree node which produces output.
+ *
+ * The i9e subsystem maintains a buffer tree node which may be attached to
+ * another node which generates output (a "producer"). When attached, the i9e
+ * buffer tree node copies the buffers generated by the producer to stdout.
+ *
+ * This function attaches the i9e input queue to an output queue of \a
+ * producer.
+ *
+ * \return Standard.
+ */
+void i9e_attach_to_stdout(struct btr_node *producer)
+{
+ btr_remove_node(&i9ep->stdout_btrn);
+ i9ep->stdout_btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "interactive_stdout", .parent = producer));
+ rl_set_keymap(i9ep->bare_km);
+}
+
+static void wipe_bottom_line(void)
+{
+ char x[] = " ";
+ int n = i9ep->num_columns;
+
+ /*
+ * For reasons beyond my understanding, writing more than 68 characters
+ * here causes MacOS to mess up the terminal. Writing a line of spaces
+ * in smaller chunks works fine though. Weird.
+ */
+ fprintf(i9ep->stderr_stream, "\r");
+ while (n > 0) {
+ if (n >= sizeof(x)) {
+ fprintf(i9ep->stderr_stream, "%s", x);
+ n -= sizeof(x);
+ continue;
+ }
+ x[n] = '\0';
+ fprintf(i9ep->stderr_stream, "%s", x);
+ break;
+ }
+ fprintf(i9ep->stderr_stream, "\r");
+}
+
+#ifndef RL_FREE_KEYMAP_DECLARED
+/**
+ * Free all storage associated with a keymap.
+ *
+ * This function is not declared in the readline headers although the symbol is
+ * exported and the function is documented in the readline info file. So we
+ * have to declare it here.
+ *
+ * \param keymap The keymap to deallocate.
+ */
+void rl_free_keymap(Keymap keymap);
+#endif
+
+/**
+ * Reset the terminal and save the in-memory command line history.
+ *
+ * This should be called before the caller exits.
+ */
+void i9e_close(void)
+{
+ char *hf = i9ep->ici->history_file;
+
+ rl_free_keymap(i9ep->bare_km);
+ rl_callback_handler_remove();
+ if (hf)
+ write_history(hf);
+ wipe_bottom_line();
+}
+
+static void clear_bottom_line(void)
+{
+ int point;
+ char *text;
+
+ if (rl_point == 0 && rl_end == 0)
+ return wipe_bottom_line();
+ /*
+ * We might have a multi-line input that needs to be wiped here, so the
+ * simple printf("\r<space>\r") is insufficient. To workaround this, we
+ * remove the whole line, redisplay and restore the killed text.
+ */
+ point = rl_point;
+ text = rl_copy_text(0, rl_end);
+ rl_kill_full_line(0, 0);
+ rl_redisplay();
+ wipe_bottom_line(); /* wipe out the prompt */
+ rl_insert_text(text);
+ free(text);
+ rl_point = point;
+}
+
+static bool input_available(void)
+{
+ fd_set rfds;
+ struct timeval tv = {0, 0};
+ int ret;
+
+ FD_ZERO(&rfds);
+ FD_SET(i9ep->ici->fds[0], &rfds);
+ ret = para_select(1, &rfds, NULL, &tv);
+ return ret > 0;
+}
+
+static void i9e_line_handler(char *line)
+{
+ int ret;
+ struct btr_node *dummy;
+
+ if (!line) {
+ i9ep->input_eof = true;
+ return;
+ }
+ if (!*line)
+ goto free_line;
+ rl_set_prompt("");
+ dummy = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "dummy line handler"));
+ i9e_attach_to_stdout(dummy);
+ ret = i9ep->ici->line_handler(line);
+ if (ret < 0)
+ PARA_WARNING_LOG("%s\n", para_strerror(-ret));
+ add_history(line);
+ btr_remove_node(&dummy);
+free_line:
+ free(line);
+}
+
+static int i9e_post_select(__a_unused struct sched *s, __a_unused void *context)
+{
+ int ret;
+ struct i9e_client_info *ici = i9ep->ici;
+ char *buf;
+ size_t sz, consumed = 0;
+
+ ret = -E_I9E_EOF;
+ if (i9ep->input_eof)
+ goto rm_btrn;
+ ret = -E_I9E_TERM_RQ;
+ if (i9ep->caught_sigterm)
+ goto rm_btrn;
+ ret = 0;
+ if (i9ep->caught_sigint)
+ goto rm_btrn;
+ while (input_available())
+ rl_callback_read_char();
+ if (!i9ep->stdout_btrn)
+ goto out;
+ ret = btr_node_status(i9ep->stdout_btrn, 0, BTR_NT_LEAF);
+ if (ret < 0) {
+ ret = 0;
+ goto rm_btrn;
+ }
+ if (ret == 0)
+ goto out;
+again:
+ sz = btr_next_buffer(i9ep->stdout_btrn, &buf);
+ if (sz == 0)
+ goto out;
+ if (i9ep->last_write_was_status)
+ fprintf(i9ep->stderr_stream, "\n");
+ i9ep->last_write_was_status = false;
+ ret = xwrite(ici->fds[1], buf, sz);
+ if (ret < 0)
+ goto rm_btrn;
+ btr_consume(i9ep->stdout_btrn, ret);
+ consumed += ret;
+ if (ret == sz && consumed < 10000)
+ goto again;
+ goto out;
+rm_btrn:
+ if (i9ep->stdout_btrn) {
+ wipe_bottom_line();
+ btr_remove_node(&i9ep->stdout_btrn);
+ rl_set_keymap(i9ep->standard_km);
+ rl_set_prompt(i9ep->ici->prompt);
+ rl_redisplay();
+ }
+ if (ret < 0)
+ wipe_bottom_line();
+out:
+ i9ep->caught_sigint = false;
+ return ret;
+}
+
+static void i9e_pre_select(struct sched *s, __a_unused void *context)
+{
+ int ret;
+
+ if (i9ep->input_eof || i9ep->caught_sigint || i9ep->caught_sigterm) {
+ sched_min_delay(s);
+ return;
+ }
+ if (i9ep->stdout_btrn) {
+ ret = btr_node_status(i9ep->stdout_btrn, 0, BTR_NT_LEAF);
+ if (ret < 0) {
+ sched_min_delay(s);
+ return;
+ }
+ if (ret > 0)
+ para_fd_set(i9ep->ici->fds[1], &s->wfds, &s->max_fileno);
+ }
+ /*
+ * fd[0] might have been reset to blocking mode if our job was moved to
+ * the background due to CTRL-Z or SIGSTOP, so set the fd back to
+ * nonblocking mode.
+ */
+ ret = mark_fd_nonblocking(i9ep->ici->fds[0]);
+ if (ret < 0)
+ PARA_WARNING_LOG("set to nonblock failed: (fd0 %d, %s)\n",
+ i9ep->ici->fds[0], para_strerror(-ret));
+ para_fd_set(i9ep->ici->fds[0], &s->rfds, &s->max_fileno);
+}
+
+static void update_winsize(void)
+{
+ struct winsize w;
+ int ret = ioctl(i9ep->ici->fds[2], TIOCGWINSZ, (char *)&w);
+
+ if (ret >= 0) {
+ assert(w.ws_col < sizeof(i9ep->empty_line));
+ i9ep->num_columns = w.ws_col;
+ } else
+ i9ep->num_columns = 80;
+
+ memset(i9ep->empty_line, ' ', i9ep->num_columns);
+ i9ep->empty_line[i9ep->num_columns] = '\0';
+}
+
+/**
+ * Defined key sequences are mapped to keys starting with this offset. I.e.
+ * pressing the first defined key sequence yields the key number \p KEY_OFFSET.
+ */
+#define KEY_OFFSET 64
+
+static int dispatch_key(__a_unused int count, int key)
+{
+ int ret;
+
+ assert(key >= KEY_OFFSET);
+ ret = i9ep->ici->key_handler(key - KEY_OFFSET);
+ return ret < 0? ret : 0;
+}
+
+/**
+ * Register the i9e task and initialize readline.
+ *
+ * \param ici The i9e configuration parameters set by the caller.
+ * \param s The scheduler instance to add the i9e task to.
+ *
+ * The caller must allocate and initialize the structure \a ici points to.
+ *
+ * \return Standard.
+ */
+int i9e_open(struct i9e_client_info *ici, struct sched *s)
+{
+ int ret;
+
+ if (!isatty(ici->fds[0]))
+ return -E_I9E_SETUPTERM;
+ ret = mark_fd_nonblocking(ici->fds[0]);
+ if (ret < 0)
+ return ret;
+ ret = mark_fd_nonblocking(ici->fds[1]);
+ if (ret < 0)
+ return ret;
+ i9ep->task = task_register(&(struct task_info) {
+ .name = "i9e",
+ .pre_select = i9e_pre_select,
+ .post_select = i9e_post_select,
+ .context = i9ep,
+ }, s);
+
+ rl_readline_name = "para_i9e";
+ rl_basic_word_break_characters = " ";
+ rl_attempted_completion_function = i9e_completer;
+ i9ep->ici = ici;
+ i9ep->stderr_stream = fdopen(ici->fds[2], "w");
+ setvbuf(i9ep->stderr_stream, NULL, _IONBF, 0);
+
+ i9ep->standard_km = rl_get_keymap();
+ i9ep->bare_km = rl_make_bare_keymap();
+ if (ici->bound_keyseqs) {
+ char *seq;
+ int i;
+ /* FIXME: This is an arbitrary constant. */
+ for (i = 0; i < 32 && (seq = ici->bound_keyseqs[i]); i++) {
+ char buf[2] = {KEY_OFFSET + i, '\0'};
+ /* readline needs an allocated buffer for the macro */
+ rl_generic_bind(ISMACR, seq, para_strdup(buf), i9ep->bare_km);
+ rl_bind_key_in_map(KEY_OFFSET + i, dispatch_key, i9ep->bare_km);
+ }
+ }
+ if (ici->history_file)
+ read_history(ici->history_file);
+ update_winsize();
+ if (ici->producer) {
+ rl_callback_handler_install("", i9e_line_handler);
+ i9e_attach_to_stdout(ici->producer);
+ rl_set_keymap(i9ep->bare_km);
+ } else
+ rl_callback_handler_install(i9ep->ici->prompt, i9e_line_handler);
+ return 1;
+}
+
+static void reset_line_state(void)
+{
+ if (i9ep->stdout_btrn)
+ return;
+ rl_on_new_line();
+ rl_reset_line_state();
+ rl_forced_update_display();
+}
+
+/**
+ * The log function of the i9e subsystem.
+ *
+ * \param ll Severity log level.
+ * \param fmt Printf-like format string.
+ *
+ * This clears the bottom line of the terminal if necessary and writes the
+ * string given by \a fmt to fd[2], where fd[] is the array provided earlier in
+ * \ref i9e_open().
+ */
+__printf_2_3 void i9e_log(int ll, const char* fmt,...)
+{
+ va_list argp;
+
+ if (ll < i9ep->ici->loglevel)
+ return;
+ clear_bottom_line();
+ va_start(argp, fmt);
+ vfprintf(i9ep->stderr_stream, fmt, argp);
+ va_end(argp);
+ reset_line_state();
+ i9ep->last_write_was_status = false;
+}
+
+/**
+ * Print the current status to stderr.
+ *
+ * \param buf The text to print.
+ * \param len The number of bytes in \a buf.
+ *
+ * This clears the bottom line, moves to the beginning of the line and prints
+ * the given text. If the length of this text exceeds the width of the
+ * terminal, the text is shortened by leaving out a part in the middle.
+ */
+void ie9_print_status_bar(char *buf, unsigned len)
+{
+ size_t x = i9ep->num_columns, y = (x - 4) / 2;
+
+ assert(x >= 6);
+ if (len > x) {
+ buf[y] = '\0';
+ fprintf(i9ep->stderr_stream, "\r%s", buf);
+ fprintf(i9ep->stderr_stream, " .. ");
+ fprintf(i9ep->stderr_stream, "%s", buf + len - y);
+ } else {
+ char scratch[1000];
+
+ y = x - len;
+ scratch[0] = '\r';
+ strcpy(scratch + 1, buf);
+ memset(scratch + 1 + len, ' ', y);
+ scratch[1 + len + y] = '\r';
+ scratch[2 + len + y] = '\0';
+ fprintf(i9ep->stderr_stream, "\r%s", scratch);
+ }
+ i9ep->last_write_was_status = true;
+}
+
+/**
+ * Tell i9e that the caller received a signal.
+ *
+ * \param sig_num The number of the signal received.
+ *
+ * Currently the function only cares about \p SIGINT, but this may change.
+ */
+void i9e_signal_dispatch(int sig_num)
+{
+ if (sig_num == SIGWINCH)
+ return update_winsize();
+ if (sig_num == SIGINT) {
+ fprintf(i9ep->stderr_stream, "\n");
+ rl_replace_line ("", false /* clear_undo */);
+ reset_line_state();
+ i9ep->caught_sigint = true;
+ }
+ if (sig_num == SIGTERM)
+ i9ep->caught_sigterm = true;
+}
+
+/**
+ * Wrapper for select(2) which does not restart on interrupts.
+ *
+ * \param n \sa \ref para_select().
+ * \param readfds \sa \ref para_select().
+ * \param writefds \sa \ref para_select().
+ * \param timeout_tv \sa \ref para_select().
+ *
+ * \return \sa \ref para_select().
+ *
+ * The only difference between this function and \ref para_select() is that
+ * \ref i9e_select() returns zero if the select call returned \p EINTR.
+ */
+int i9e_select(int n, fd_set *readfds, fd_set *writefds,
+ struct timeval *timeout_tv)
+{
+ int ret = select(n, readfds, writefds, NULL, timeout_tv);
+
+ if (ret < 0) {
+ if (errno == EINTR)
+ ret = 0;
+ else
+ ret = -ERRNO_TO_PARA_ERROR(errno);
+ }
+ return ret;
+}
+
+/**
+ * Return the possible completions for a given word.
+ *
+ * \param word The word to complete.
+ * \param string_list All possible words in this context.
+ * \param result String list is returned here.
+ *
+ * This function never fails. If no completion was found, a string list of
+ * length zero is returned. In any case, the result must be freed by the caller
+ * using \ref free_argv().
+ *
+ * This function is independent of readline and may be called before
+ * i9e_open().
+ *
+ * \return The number of possible completions.
+ */
+int i9e_extract_completions(const char *word, char **string_list,
+ char ***result)
+{
+ char **matches = para_malloc(sizeof(char *));
+ int match_count = 0, matches_len = 1;
+ char **p;
+ int len = strlen(word);
+
+ for (p = string_list; *p; p++) {
+ if (!is_prefix(word, *p, len))
+ continue;
+ match_count++;
+ if (match_count >= matches_len) {
+ matches_len *= 2;
+ matches = para_realloc(matches,
+ matches_len * sizeof(char *));
+ }
+ matches[match_count - 1] = para_strdup(*p);
+ }
+ matches[match_count] = NULL;
+ *result = matches;
+ return match_count;
+}
+
+/**
+ * Return the list of partially matching words.
+ *
+ * \param word The command to complete.
+ * \param completers The array containing all command names.
+ *
+ * This is similar to \ref i9e_extract_completions(), but completes on the
+ * command names in \a completers.
+ *
+ * \return See \ref i9e_extract_completions().
+ */
+char **i9e_complete_commands(const char *word, struct i9e_completer *completers)
+{
+ char **matches;
+ const char *cmd;
+ int i, match_count, len = strlen(word);
+
+ /*
+ * In contrast to completing against an arbitrary string list, here we
+ * know all possible completions and expect that there will not be many
+ * of them. So it should be OK to iterate twice over all commands which
+ * simplifies the code a bit.
+ */
+ for (i = 0, match_count = 0; (cmd = completers[i].name); i++) {
+ if (is_prefix(word, cmd, len))
+ match_count++;
+ }
+ matches = para_malloc((match_count + 1) * sizeof(*matches));
+ for (i = 0, match_count = 0; (cmd = completers[i].name); i++)
+ if (is_prefix(word, cmd, len))
+ matches[match_count++] = para_strdup(cmd);
+ matches[match_count] = NULL;
+ return matches;
+}
+
+/**
+ * Complete according to the given options.
+ *
+ * \param opts All available options.
+ * \param ci Information which was passed to the completer.
+ * \param cr Result pointer.
+ *
+ * This convenience helper can be used to complete an option. The array of all
+ * possible options is passed as the first argument. Flags, i.e. options
+ * without an argument, are expected to be listed as strings of type "-X" in \a
+ * opts while options which require an argument should be passed with a
+ * trailing "=" character like "-X=".
+ *
+ * If the word can be uniquely completed to a flag option, an additional space
+ * character is appended to the output. For non-flag options no space character
+ * is appended.
+ */
+void i9e_complete_option(char **opts, struct i9e_completion_info *ci,
+ struct i9e_completion_result *cr)
+{
+ int num_matches;
+
+ num_matches = i9e_extract_completions(ci->word, opts, &cr->matches);
+ if (num_matches == 1) {
+ char *opt = cr->matches[0];
+ char c = opt[strlen(opt) - 1];
+ if (c == '=')
+ cr->dont_append_space = true;
+ }
+}
+
+/**
+ * Print possible completions to stdout.
+ *
+ * \param completers The array of completion functions.
+ *
+ * At the end of the output a line starting with "-o=", followed by the
+ * (possibly empty) list of completion options is printed. Currently, the only
+ * two completion options are "nospace" and "filenames". The former indicates
+ * that no space should be appended even for a unique match while the latter
+ * indicates that usual filename completion should be performed in addition to
+ * the previously printed options.
+ *
+ * \return Standard.
+ */
+int i9e_print_completions(struct i9e_completer *completers)
+{
+ struct i9e_completion_result cr;
+ struct i9e_completion_info ci;
+ char *buf;
+ const char *end, *p;
+ int i, n, ret;
+
+ reset_completion_result(&cr);
+ buf = getenv("COMP_POINT");
+ ci.point = buf? atoi(buf) : 0;
+ ci.buffer = para_strdup(getenv("COMP_LINE"));
+
+ ci.argc = create_argv(ci.buffer, " ", &ci.argv);
+ ci.word_num = compute_word_num(ci.buffer, " ", ci.point);
+
+ end = ci.buffer + ci.point;
+ for (p = end; p > ci.buffer && *p != ' '; p--)
+ ; /* nothing */
+ if (*p == ' ')
+ p++;
+
+ n = end - p + 1;
+ ci.word = para_malloc(n + 1);
+ strncpy(ci.word, p, n);
+ ci.word[n] = '\0';
+
+ PARA_DEBUG_LOG("line: %s, point: %d (%c), wordnum: %d, word: %s\n",
+ ci.buffer, ci.point, ci.buffer[ci.point], ci.word_num, ci.word);
+ if (ci.word_num == 0)
+ cr.matches = i9e_complete_commands(ci.word, completers);
+ else
+ create_matches(&ci, completers, &cr);
+ ret = 0;
+ if (cr.matches && cr.matches[0]) {
+ for (i = 0; cr.matches[i]; i++)
+ printf("%s\n", cr.matches[i]);
+ ret = 1;
+ }
+ printf("-o=");
+ if (cr.dont_append_space)
+ printf("nospace");
+ if (cr.filename_completion_desired)
+ printf(",filenames");
+ printf("\n");
+ free_argv(cr.matches);
+ free_argv(ci.argv);
+ free(ci.buffer);
+ free(ci.word);
+ return ret;
+}