filecomplete.c revision 1.2 1 1.2 dsl /* $NetBSD: filecomplete.c,v 1.2 2005/05/07 16:28:32 dsl Exp $ */
2 1.1 dsl
3 1.1 dsl /*-
4 1.1 dsl * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1 dsl * All rights reserved.
6 1.1 dsl *
7 1.1 dsl * This code is derived from software contributed to The NetBSD Foundation
8 1.1 dsl * by Jaromir Dolecek.
9 1.1 dsl *
10 1.1 dsl * Redistribution and use in source and binary forms, with or without
11 1.1 dsl * modification, are permitted provided that the following conditions
12 1.1 dsl * are met:
13 1.1 dsl * 1. Redistributions of source code must retain the above copyright
14 1.1 dsl * notice, this list of conditions and the following disclaimer.
15 1.1 dsl * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 dsl * notice, this list of conditions and the following disclaimer in the
17 1.1 dsl * documentation and/or other materials provided with the distribution.
18 1.1 dsl * 3. All advertising materials mentioning features or use of this software
19 1.1 dsl * must display the following acknowledgement:
20 1.1 dsl * This product includes software developed by the NetBSD
21 1.1 dsl * Foundation, Inc. and its contributors.
22 1.1 dsl * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 dsl * contributors may be used to endorse or promote products derived
24 1.1 dsl * from this software without specific prior written permission.
25 1.1 dsl *
26 1.1 dsl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 dsl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 dsl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 dsl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 dsl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 dsl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 dsl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 dsl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 dsl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 dsl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 dsl * POSSIBILITY OF SUCH DAMAGE.
37 1.1 dsl */
38 1.1 dsl
39 1.1 dsl #include "config.h"
40 1.1 dsl #if !defined(lint) && !defined(SCCSID)
41 1.2 dsl __RCSID("$NetBSD: filecomplete.c,v 1.2 2005/05/07 16:28:32 dsl Exp $");
42 1.1 dsl #endif /* not lint && not SCCSID */
43 1.1 dsl
44 1.1 dsl #include <sys/types.h>
45 1.1 dsl #include <sys/stat.h>
46 1.1 dsl #include <stdio.h>
47 1.1 dsl #include <dirent.h>
48 1.1 dsl #include <string.h>
49 1.1 dsl #include <pwd.h>
50 1.1 dsl #include <ctype.h>
51 1.1 dsl #include <stdlib.h>
52 1.1 dsl #include <unistd.h>
53 1.1 dsl #include <limits.h>
54 1.1 dsl #include <errno.h>
55 1.1 dsl #include <fcntl.h>
56 1.1 dsl #ifdef HAVE_VIS_H
57 1.1 dsl #include <vis.h>
58 1.1 dsl #else
59 1.1 dsl #include "np/vis.h"
60 1.1 dsl #endif
61 1.1 dsl #ifdef HAVE_ALLOCA_H
62 1.1 dsl #include <alloca.h>
63 1.1 dsl #endif
64 1.1 dsl #include "el.h"
65 1.1 dsl #include "fcns.h" /* for EL_NUM_FCNS */
66 1.1 dsl #include "histedit.h"
67 1.1 dsl #include "filecomplete.h"
68 1.1 dsl
69 1.1 dsl static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$',
70 1.1 dsl '>', '<', '=', ';', '|', '&', '{', '(', '\0' };
71 1.1 dsl
72 1.1 dsl
73 1.1 dsl /********************************/
74 1.1 dsl /* completion functions */
75 1.1 dsl
76 1.1 dsl /*
77 1.1 dsl * does tilde expansion of strings of type ``~user/foo''
78 1.1 dsl * if ``user'' isn't valid user name or ``txt'' doesn't start
79 1.1 dsl * w/ '~', returns pointer to strdup()ed copy of ``txt''
80 1.1 dsl *
81 1.1 dsl * it's callers's responsibility to free() returned string
82 1.1 dsl */
83 1.1 dsl char *
84 1.1 dsl tilde_expand(char *txt)
85 1.1 dsl {
86 1.1 dsl struct passwd pwres, *pass;
87 1.1 dsl char *temp;
88 1.1 dsl size_t len = 0;
89 1.1 dsl char pwbuf[1024];
90 1.1 dsl
91 1.1 dsl if (txt[0] != '~')
92 1.1 dsl return (strdup(txt));
93 1.1 dsl
94 1.1 dsl temp = strchr(txt + 1, '/');
95 1.1 dsl if (temp == NULL) {
96 1.1 dsl temp = strdup(txt + 1);
97 1.1 dsl if (temp == NULL)
98 1.1 dsl return NULL;
99 1.1 dsl } else {
100 1.1 dsl len = temp - txt + 1; /* text until string after slash */
101 1.1 dsl temp = malloc(len);
102 1.1 dsl if (temp == NULL)
103 1.1 dsl return NULL;
104 1.1 dsl (void)strncpy(temp, txt + 1, len - 2);
105 1.1 dsl temp[len - 2] = '\0';
106 1.1 dsl }
107 1.1 dsl if (getpwnam_r(temp, &pwres, pwbuf, sizeof(pwbuf), &pass) != 0)
108 1.1 dsl pass = NULL;
109 1.1 dsl free(temp); /* value no more needed */
110 1.1 dsl if (pass == NULL)
111 1.1 dsl return (strdup(txt));
112 1.1 dsl
113 1.1 dsl /* update pointer txt to point at string immedially following */
114 1.1 dsl /* first slash */
115 1.1 dsl txt += len;
116 1.1 dsl
117 1.1 dsl temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
118 1.1 dsl if (temp == NULL)
119 1.1 dsl return NULL;
120 1.1 dsl (void)sprintf(temp, "%s/%s", pass->pw_dir, txt);
121 1.1 dsl
122 1.1 dsl return (temp);
123 1.1 dsl }
124 1.1 dsl
125 1.1 dsl
126 1.1 dsl /*
127 1.1 dsl * return first found file name starting by the ``text'' or NULL if no
128 1.1 dsl * such file can be found
129 1.1 dsl * value of ``state'' is ignored
130 1.1 dsl *
131 1.1 dsl * it's caller's responsibility to free returned string
132 1.1 dsl */
133 1.2 dsl char *
134 1.1 dsl filename_completion_function(const char *text, int state)
135 1.1 dsl {
136 1.1 dsl static DIR *dir = NULL;
137 1.1 dsl static char *filename = NULL, *dirname = NULL;
138 1.1 dsl static size_t filename_len = 0;
139 1.1 dsl struct dirent *entry;
140 1.1 dsl char *temp;
141 1.1 dsl size_t len;
142 1.1 dsl
143 1.1 dsl if (state == 0 || dir == NULL) {
144 1.1 dsl temp = strrchr(text, '/');
145 1.1 dsl if (temp) {
146 1.1 dsl char *nptr;
147 1.1 dsl temp++;
148 1.1 dsl nptr = realloc(filename, strlen(temp) + 1);
149 1.1 dsl if (nptr == NULL) {
150 1.1 dsl free(filename);
151 1.1 dsl return NULL;
152 1.1 dsl }
153 1.1 dsl filename = nptr;
154 1.1 dsl (void)strcpy(filename, temp);
155 1.1 dsl len = temp - text; /* including last slash */
156 1.1 dsl nptr = realloc(dirname, len + 1);
157 1.1 dsl if (nptr == NULL) {
158 1.1 dsl free(filename);
159 1.1 dsl return NULL;
160 1.1 dsl }
161 1.1 dsl dirname = nptr;
162 1.1 dsl (void)strncpy(dirname, text, len);
163 1.1 dsl dirname[len] = '\0';
164 1.1 dsl } else {
165 1.1 dsl if (*text == 0)
166 1.1 dsl filename = NULL;
167 1.1 dsl else {
168 1.1 dsl filename = strdup(text);
169 1.1 dsl if (filename == NULL)
170 1.1 dsl return NULL;
171 1.1 dsl }
172 1.1 dsl dirname = NULL;
173 1.1 dsl }
174 1.1 dsl
175 1.1 dsl /* support for ``~user'' syntax */
176 1.1 dsl if (dirname && *dirname == '~') {
177 1.1 dsl char *nptr;
178 1.1 dsl temp = tilde_expand(dirname);
179 1.1 dsl if (temp == NULL)
180 1.1 dsl return NULL;
181 1.1 dsl nptr = realloc(dirname, strlen(temp) + 1);
182 1.1 dsl if (nptr == NULL) {
183 1.1 dsl free(dirname);
184 1.1 dsl return NULL;
185 1.1 dsl }
186 1.1 dsl dirname = nptr;
187 1.1 dsl (void)strcpy(dirname, temp); /* safe */
188 1.1 dsl free(temp); /* no longer needed */
189 1.1 dsl }
190 1.1 dsl /* will be used in cycle */
191 1.1 dsl filename_len = filename ? strlen(filename) : 0;
192 1.1 dsl
193 1.1 dsl if (dir != NULL) {
194 1.1 dsl (void)closedir(dir);
195 1.1 dsl dir = NULL;
196 1.1 dsl }
197 1.1 dsl dir = opendir(dirname ? dirname : ".");
198 1.1 dsl if (!dir)
199 1.1 dsl return (NULL); /* cannot open the directory */
200 1.1 dsl }
201 1.1 dsl
202 1.1 dsl /* find the match */
203 1.1 dsl while ((entry = readdir(dir)) != NULL) {
204 1.1 dsl /* skip . and .. */
205 1.1 dsl if (entry->d_name[0] == '.' && (!entry->d_name[1]
206 1.1 dsl || (entry->d_name[1] == '.' && !entry->d_name[2])))
207 1.1 dsl continue;
208 1.1 dsl if (filename_len == 0)
209 1.1 dsl break;
210 1.1 dsl /* otherwise, get first entry where first */
211 1.1 dsl /* filename_len characters are equal */
212 1.1 dsl if (entry->d_name[0] == filename[0]
213 1.1 dsl #if defined(__SVR4) || defined(__linux__)
214 1.1 dsl && strlen(entry->d_name) >= filename_len
215 1.1 dsl #else
216 1.1 dsl && entry->d_namlen >= filename_len
217 1.1 dsl #endif
218 1.1 dsl && strncmp(entry->d_name, filename,
219 1.1 dsl filename_len) == 0)
220 1.1 dsl break;
221 1.1 dsl }
222 1.1 dsl
223 1.1 dsl if (entry) { /* match found */
224 1.1 dsl
225 1.1 dsl struct stat stbuf;
226 1.1 dsl #if defined(__SVR4) || defined(__linux__)
227 1.1 dsl len = strlen(entry->d_name) +
228 1.1 dsl #else
229 1.1 dsl len = entry->d_namlen +
230 1.1 dsl #endif
231 1.1 dsl ((dirname) ? strlen(dirname) : 0) + 1 + 1;
232 1.1 dsl temp = malloc(len);
233 1.1 dsl if (temp == NULL)
234 1.1 dsl return NULL;
235 1.1 dsl (void)sprintf(temp, "%s%s",
236 1.1 dsl dirname ? dirname : "", entry->d_name); /* safe */
237 1.1 dsl
238 1.1 dsl /* test, if it's directory */
239 1.1 dsl if (stat(temp, &stbuf) == 0 && S_ISDIR(stbuf.st_mode))
240 1.1 dsl strcat(temp, "/"); /* safe */
241 1.1 dsl } else {
242 1.1 dsl (void)closedir(dir);
243 1.1 dsl dir = NULL;
244 1.1 dsl temp = NULL;
245 1.1 dsl }
246 1.1 dsl
247 1.1 dsl return (temp);
248 1.1 dsl }
249 1.1 dsl
250 1.1 dsl
251 1.1 dsl
252 1.1 dsl /*
253 1.1 dsl * returns list of completions for text given
254 1.1 dsl */
255 1.1 dsl static char **
256 1.1 dsl completion_matches(const char *text, char *(*genfunc)(const char *, int))
257 1.1 dsl {
258 1.1 dsl char **match_list = NULL, *retstr, *prevstr;
259 1.1 dsl size_t match_list_len, max_equal, which, i;
260 1.1 dsl size_t matches;
261 1.1 dsl
262 1.1 dsl matches = 0;
263 1.1 dsl match_list_len = 1;
264 1.1 dsl while ((retstr = (*genfunc) (text, (int)matches)) != NULL) {
265 1.1 dsl /* allow for list terminator here */
266 1.1 dsl if (matches + 3 >= match_list_len) {
267 1.1 dsl char **nmatch_list;
268 1.1 dsl while (matches + 3 >= match_list_len)
269 1.1 dsl match_list_len <<= 1;
270 1.1 dsl nmatch_list = realloc(match_list,
271 1.1 dsl match_list_len * sizeof(char *));
272 1.1 dsl if (nmatch_list == NULL) {
273 1.1 dsl free(match_list);
274 1.1 dsl return NULL;
275 1.1 dsl }
276 1.1 dsl match_list = nmatch_list;
277 1.1 dsl
278 1.1 dsl }
279 1.1 dsl match_list[++matches] = retstr;
280 1.1 dsl }
281 1.1 dsl
282 1.1 dsl if (!match_list)
283 1.1 dsl return NULL; /* nothing found */
284 1.1 dsl
285 1.1 dsl /* find least denominator and insert it to match_list[0] */
286 1.1 dsl which = 2;
287 1.1 dsl prevstr = match_list[1];
288 1.1 dsl max_equal = strlen(prevstr);
289 1.1 dsl for (; which <= matches; which++) {
290 1.1 dsl for (i = 0; i < max_equal &&
291 1.1 dsl prevstr[i] == match_list[which][i]; i++)
292 1.1 dsl continue;
293 1.1 dsl max_equal = i;
294 1.1 dsl }
295 1.1 dsl
296 1.1 dsl retstr = malloc(max_equal + 1);
297 1.1 dsl if (retstr == NULL) {
298 1.1 dsl free(match_list);
299 1.1 dsl return NULL;
300 1.1 dsl }
301 1.1 dsl (void)strncpy(retstr, match_list[1], max_equal);
302 1.1 dsl retstr[max_equal] = '\0';
303 1.1 dsl match_list[0] = retstr;
304 1.1 dsl
305 1.1 dsl /* add NULL as last pointer to the array */
306 1.1 dsl match_list[matches + 1] = (char *) NULL;
307 1.1 dsl
308 1.1 dsl return (match_list);
309 1.1 dsl }
310 1.1 dsl
311 1.1 dsl /*
312 1.1 dsl * Sort function for qsort(). Just wrapper around strcasecmp().
313 1.1 dsl */
314 1.1 dsl static int
315 1.1 dsl _fn_qsort_string_compare(const void *i1, const void *i2)
316 1.1 dsl {
317 1.1 dsl const char *s1 = ((const char * const *)i1)[0];
318 1.1 dsl const char *s2 = ((const char * const *)i2)[0];
319 1.1 dsl
320 1.1 dsl return strcasecmp(s1, s2);
321 1.1 dsl }
322 1.1 dsl
323 1.1 dsl /*
324 1.1 dsl * Display list of strings in columnar format on readline's output stream.
325 1.1 dsl * 'matches' is list of strings, 'len' is number of strings in 'matches',
326 1.1 dsl * 'max' is maximum length of string in 'matches'.
327 1.1 dsl */
328 1.1 dsl void
329 1.1 dsl fn_display_match_list (EditLine *el, char **matches, int len, int max)
330 1.1 dsl {
331 1.1 dsl int i, idx, limit, count;
332 1.1 dsl int screenwidth = el->el_term.t_size.h;
333 1.1 dsl
334 1.1 dsl /*
335 1.1 dsl * Find out how many entries can be put on one line, count
336 1.1 dsl * with two spaces between strings.
337 1.1 dsl */
338 1.1 dsl limit = screenwidth / (max + 2);
339 1.1 dsl if (limit == 0)
340 1.1 dsl limit = 1;
341 1.1 dsl
342 1.1 dsl /* how many lines of output */
343 1.1 dsl count = len / limit;
344 1.1 dsl if (count * limit < len)
345 1.1 dsl count++;
346 1.1 dsl
347 1.1 dsl /* Sort the items if they are not already sorted. */
348 1.1 dsl qsort(&matches[1], (size_t)(len - 1), sizeof(char *),
349 1.1 dsl _fn_qsort_string_compare);
350 1.1 dsl
351 1.1 dsl idx = 1;
352 1.1 dsl for(; count > 0; count--) {
353 1.1 dsl for(i = 0; i < limit && matches[idx]; i++, idx++)
354 1.1 dsl (void)fprintf(el->el_outfile, "%-*s ", max,
355 1.1 dsl matches[idx]);
356 1.1 dsl (void)fprintf(el->el_outfile, "\n");
357 1.1 dsl }
358 1.1 dsl }
359 1.1 dsl
360 1.1 dsl /*
361 1.1 dsl * Complete the word at or before point,
362 1.1 dsl * 'what_to_do' says what to do with the completion.
363 1.1 dsl * \t means do standard completion.
364 1.1 dsl * `?' means list the possible completions.
365 1.1 dsl * `*' means insert all of the possible completions.
366 1.1 dsl * `!' means to do standard completion, and list all possible completions if
367 1.1 dsl * there is more than one.
368 1.1 dsl *
369 1.1 dsl * Note: '*' support is not implemented
370 1.1 dsl * '!' could never be invoked
371 1.1 dsl */
372 1.1 dsl int
373 1.1 dsl fn_complete(EditLine *el,
374 1.1 dsl char *(*complet_func)(const char *, int),
375 1.1 dsl char **(*attempted_completion_function)(const char *, int, int),
376 1.1 dsl const char *word_break, const char *special_prefixes,
377 1.1 dsl char append_character, int query_items,
378 1.1 dsl int *completion_type, int *over, int *point, int *end)
379 1.1 dsl {
380 1.1 dsl const LineInfo *li;
381 1.1 dsl char *temp, **matches;
382 1.1 dsl const char *ctemp;
383 1.1 dsl size_t len;
384 1.1 dsl int what_to_do = '\t';
385 1.1 dsl
386 1.1 dsl if (el->el_state.lastcmd == el->el_state.thiscmd)
387 1.1 dsl what_to_do = '?';
388 1.1 dsl
389 1.1 dsl /* readline's rl_complete() has to be told what we did... */
390 1.1 dsl if (completion_type != NULL)
391 1.1 dsl *completion_type = what_to_do;
392 1.1 dsl
393 1.1 dsl if (!complet_func)
394 1.1 dsl complet_func = filename_completion_function;
395 1.1 dsl
396 1.1 dsl /* We now look backwards for the start of a filename/variable word */
397 1.1 dsl li = el_line(el);
398 1.1 dsl ctemp = (const char *) li->cursor;
399 1.1 dsl while (ctemp > li->buffer
400 1.1 dsl && !strchr(word_break, ctemp[-1])
401 1.1 dsl && (!special_prefixes || !strchr(special_prefixes, ctemp[-1]) ) )
402 1.1 dsl ctemp--;
403 1.1 dsl
404 1.1 dsl len = li->cursor - ctemp;
405 1.1 dsl temp = alloca(len + 1);
406 1.1 dsl (void)strncpy(temp, ctemp, len);
407 1.1 dsl temp[len] = '\0';
408 1.1 dsl
409 1.1 dsl /* these can be used by function called in completion_matches() */
410 1.1 dsl /* or (*attempted_completion_function)() */
411 1.1 dsl if (point != 0)
412 1.1 dsl *point = li->cursor - li->buffer;
413 1.1 dsl if (end != NULL)
414 1.1 dsl *end = li->lastchar - li->buffer;
415 1.1 dsl
416 1.1 dsl if (attempted_completion_function) {
417 1.1 dsl int cur_off = li->cursor - li->buffer;
418 1.1 dsl matches = (*attempted_completion_function) (temp,
419 1.1 dsl (int)(cur_off - len), cur_off);
420 1.1 dsl } else
421 1.1 dsl matches = 0;
422 1.1 dsl if (!attempted_completion_function ||
423 1.1 dsl (over != NULL && *over && !matches))
424 1.1 dsl matches = completion_matches(temp, complet_func);
425 1.1 dsl
426 1.1 dsl if (over != NULL)
427 1.1 dsl *over = 0;
428 1.1 dsl
429 1.1 dsl if (matches) {
430 1.1 dsl int i, retval = CC_REFRESH;
431 1.1 dsl int matches_num, maxlen, match_len, match_display=1;
432 1.1 dsl
433 1.1 dsl /*
434 1.1 dsl * Only replace the completed string with common part of
435 1.1 dsl * possible matches if there is possible completion.
436 1.1 dsl */
437 1.1 dsl if (matches[0][0] != '\0') {
438 1.1 dsl el_deletestr(el, (int) len);
439 1.1 dsl el_insertstr(el, matches[0]);
440 1.1 dsl }
441 1.1 dsl
442 1.1 dsl if (what_to_do == '?')
443 1.1 dsl goto display_matches;
444 1.1 dsl
445 1.1 dsl if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) {
446 1.1 dsl /*
447 1.1 dsl * We found exact match. Add a space after
448 1.1 dsl * it, unless we do filename completion and the
449 1.1 dsl * object is a directory.
450 1.1 dsl */
451 1.1 dsl size_t alen = strlen(matches[0]);
452 1.1 dsl if ((complet_func != filename_completion_function
453 1.1 dsl || (alen > 0 && (matches[0])[alen - 1] != '/'))
454 1.1 dsl && append_character) {
455 1.1 dsl char buf[2];
456 1.1 dsl buf[0] = append_character;
457 1.1 dsl buf[1] = '\0';
458 1.1 dsl el_insertstr(el, buf);
459 1.1 dsl }
460 1.1 dsl } else if (what_to_do == '!') {
461 1.1 dsl display_matches:
462 1.1 dsl /*
463 1.1 dsl * More than one match and requested to list possible
464 1.1 dsl * matches.
465 1.1 dsl */
466 1.1 dsl
467 1.1 dsl for(i=1, maxlen=0; matches[i]; i++) {
468 1.1 dsl match_len = strlen(matches[i]);
469 1.1 dsl if (match_len > maxlen)
470 1.1 dsl maxlen = match_len;
471 1.1 dsl }
472 1.1 dsl matches_num = i - 1;
473 1.1 dsl
474 1.1 dsl /* newline to get on next line from command line */
475 1.1 dsl (void)fprintf(el->el_outfile, "\n");
476 1.1 dsl
477 1.1 dsl /*
478 1.1 dsl * If there are too many items, ask user for display
479 1.1 dsl * confirmation.
480 1.1 dsl */
481 1.1 dsl if (matches_num > query_items) {
482 1.1 dsl (void)fprintf(el->el_outfile,
483 1.1 dsl "Display all %d possibilities? (y or n) ",
484 1.1 dsl matches_num);
485 1.1 dsl (void)fflush(el->el_outfile);
486 1.1 dsl if (getc(stdin) != 'y')
487 1.1 dsl match_display = 0;
488 1.1 dsl (void)fprintf(el->el_outfile, "\n");
489 1.1 dsl }
490 1.1 dsl
491 1.1 dsl if (match_display)
492 1.1 dsl fn_display_match_list(el, matches, matches_num,
493 1.1 dsl maxlen);
494 1.1 dsl retval = CC_REDISPLAY;
495 1.1 dsl } else if (matches[0][0]) {
496 1.1 dsl /*
497 1.1 dsl * There was some common match, but the name was
498 1.1 dsl * not complete enough. Next tab will print possible
499 1.1 dsl * completions.
500 1.1 dsl */
501 1.1 dsl el_beep(el);
502 1.1 dsl } else {
503 1.1 dsl /* lcd is not a valid object - further specification */
504 1.1 dsl /* is needed */
505 1.1 dsl el_beep(el);
506 1.1 dsl retval = CC_NORM;
507 1.1 dsl }
508 1.1 dsl
509 1.1 dsl /* free elements of array and the array itself */
510 1.1 dsl for (i = 0; matches[i]; i++)
511 1.1 dsl free(matches[i]);
512 1.1 dsl free(matches), matches = NULL;
513 1.1 dsl
514 1.1 dsl return (retval);
515 1.1 dsl }
516 1.1 dsl return (CC_NORM);
517 1.1 dsl }
518 1.1 dsl
519 1.1 dsl /*
520 1.1 dsl * el-compatible wrapper around rl_complete; needed for key binding
521 1.1 dsl */
522 1.1 dsl /* ARGSUSED */
523 1.1 dsl unsigned char
524 1.1 dsl _el_fn_complete(EditLine *el, int ch __attribute__((__unused__)))
525 1.1 dsl {
526 1.1 dsl return (unsigned char)fn_complete(el, NULL, NULL,
527 1.1 dsl break_chars, NULL, ' ', 100,
528 1.1 dsl NULL, NULL, NULL, NULL);
529 1.1 dsl }
530