2 * Copyright (c) 2003 Nikodemus Siivola
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #include <readline/readline.h>
34 node_t * collection = NULL;
37 add_completion (char * str)
39 node_t * tmp = collection;
44 int cmp = strcmp (str, tmp->str);
51 /* printf ("-skip- (%s)\n", tmp->str);*/
57 node = malloc (sizeof (node_t));
62 node->str = strdup (str);
75 custom_completer (const char * str, int target)
77 size_t len = strlen (str);
81 node_t * tmp = collection;
84 if (0 == strncmp (str, tmp->str, len))
87 return strdup (root->str);
94 else if (root && (0 == strncmp (str, root->str, len)))
98 return strdup (tmp->str);
110 /* printf ("-del- (%s)\n", collection->str); */
111 tmp = collection->next;
112 free (collection->str);
119 use_custom_complete (void)
121 rl_completion_entry_function = custom_completer;
125 use_filename_complete (void)
127 rl_completion_entry_function = rl_filename_completion_function;