Deleted Added
full compact
complete.c (119614) complete.c (136758)
1/* $FreeBSD: head/contrib/libreadline/complete.c 119614 2003-08-31 18:29:38Z ache $ */
1/* $FreeBSD: head/contrib/libreadline/complete.c 136758 2004-10-21 20:02:02Z peter $ */
2
2/* complete.c -- filename completion for readline. */
3
3/* complete.c -- filename completion for readline. */
4
4/* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
5/* Copyright (C) 1987-2004 Free Software Foundation, Inc.
5
6 This file is part of the GNU Readline Library, a library for
7 reading lines of text with interactive input and history editing.
8
9 The GNU Readline Library is free software; you can redistribute it
10 and/or modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2, or
12 (at your option) any later version.

--- 11 unchanged lines hidden (view full) ---

24
25#if defined (HAVE_CONFIG_H)
26# include <config.h>
27#endif
28
29#include <sys/types.h>
30#include <fcntl.h>
31#if defined (HAVE_SYS_FILE_H)
6
7 This file is part of the GNU Readline Library, a library for
8 reading lines of text with interactive input and history editing.
9
10 The GNU Readline Library is free software; you can redistribute it
11 and/or modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2, or
13 (at your option) any later version.

--- 11 unchanged lines hidden (view full) ---

25
26#if defined (HAVE_CONFIG_H)
27# include <config.h>
28#endif
29
30#include <sys/types.h>
31#include <fcntl.h>
32#if defined (HAVE_SYS_FILE_H)
32#include
33# include <sys/file.h>
33#endif
34
35#if defined (HAVE_UNISTD_H)
36# include <unistd.h>
37#endif /* HAVE_UNISTD_H */
38
39#if defined (HAVE_STDLIB_H)
40# include <stdlib.h>

--- 54 unchanged lines hidden (view full) ---

95
96#if defined (VISIBLE_STATS)
97# if !defined (X_OK)
98# define X_OK 1
99# endif
100static int stat_char PARAMS((char *));
101#endif
102
34#endif
35
36#if defined (HAVE_UNISTD_H)
37# include <unistd.h>
38#endif /* HAVE_UNISTD_H */
39
40#if defined (HAVE_STDLIB_H)
41# include <stdlib.h>

--- 54 unchanged lines hidden (view full) ---

96
97#if defined (VISIBLE_STATS)
98# if !defined (X_OK)
99# define X_OK 1
100# endif
101static int stat_char PARAMS((char *));
102#endif
103
104static int path_isdir PARAMS((const char *));
105
103static char *rl_quote_filename PARAMS((char *, int, char *));
104
105static void set_completion_defaults PARAMS((int));
106static int get_y_or_n PARAMS((int));
107static int _rl_internal_pager PARAMS((int));
108static char *printable_part PARAMS((char *));
106static char *rl_quote_filename PARAMS((char *, int, char *));
107
108static void set_completion_defaults PARAMS((int));
109static int get_y_or_n PARAMS((int));
110static int _rl_internal_pager PARAMS((int));
111static char *printable_part PARAMS((char *));
112static int fnwidth PARAMS((const char *));
113static int fnprint PARAMS((const char *));
109static int print_filename PARAMS((char *, char *));
110
111static char **gen_completion_matches PARAMS((char *, int, int, rl_compentry_func_t *, int, int));
112
113static char **remove_duplicate_matches PARAMS((char **));
114static void insert_match PARAMS((char *, int, int, char *));
115static int append_to_match PARAMS((char *, int, int, int));
116static void insert_all_matches PARAMS((char **, int, char *));

--- 9 unchanged lines hidden (view full) ---

126/* */
127/* **************************************************************** */
128
129/* Variables known only to the readline library. */
130
131/* If non-zero, non-unique completions always show the list of matches. */
132int _rl_complete_show_all = 0;
133
114static int print_filename PARAMS((char *, char *));
115
116static char **gen_completion_matches PARAMS((char *, int, int, rl_compentry_func_t *, int, int));
117
118static char **remove_duplicate_matches PARAMS((char **));
119static void insert_match PARAMS((char *, int, int, char *));
120static int append_to_match PARAMS((char *, int, int, int));
121static void insert_all_matches PARAMS((char **, int, char *));

--- 9 unchanged lines hidden (view full) ---

131/* */
132/* **************************************************************** */
133
134/* Variables known only to the readline library. */
135
136/* If non-zero, non-unique completions always show the list of matches. */
137int _rl_complete_show_all = 0;
138
139/* If non-zero, non-unique completions show the list of matches, unless it
140 is not possible to do partial completion and modify the line. */
141int _rl_complete_show_unmodified = 0;
142
134/* If non-zero, completed directory names have a slash appended. */
135int _rl_complete_mark_directories = 1;
136
137/* If non-zero, the symlinked directory completion behavior introduced in
138 readline-4.2a is disabled, and symlinks that point to directories have
139 a slash appended (subject to the value of _rl_complete_mark_directories).
140 This is user-settable via the mark-symlinked-directories variable. */
141int _rl_complete_mark_symlink_dirs = 0;

--- 68 unchanged lines hidden (view full) ---

210const char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{("; /* }) */
211
212/* List of basic quoting characters. */
213const char *rl_basic_quote_characters = "\"'";
214
215/* The list of characters that signal a break between words for
216 rl_complete_internal. The default list is the contents of
217 rl_basic_word_break_characters. */
143/* If non-zero, completed directory names have a slash appended. */
144int _rl_complete_mark_directories = 1;
145
146/* If non-zero, the symlinked directory completion behavior introduced in
147 readline-4.2a is disabled, and symlinks that point to directories have
148 a slash appended (subject to the value of _rl_complete_mark_directories).
149 This is user-settable via the mark-symlinked-directories variable. */
150int _rl_complete_mark_symlink_dirs = 0;

--- 68 unchanged lines hidden (view full) ---

219const char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{("; /* }) */
220
221/* List of basic quoting characters. */
222const char *rl_basic_quote_characters = "\"'";
223
224/* The list of characters that signal a break between words for
225 rl_complete_internal. The default list is the contents of
226 rl_basic_word_break_characters. */
218const char *rl_completer_word_break_characters = (const char *)NULL;
227/*const*/ char *rl_completer_word_break_characters = (/*const*/ char *)NULL;
219
228
229/* Hook function to allow an application to set the completion word
230 break characters before readline breaks up the line. Allows
231 position-dependent word break characters. */
232rl_cpvfunc_t *rl_completion_word_break_hook = (rl_cpvfunc_t *)NULL;
233
220/* List of characters which can be used to quote a substring of the line.
221 Completion occurs on the entire substring, and within the substring
222 rl_completer_word_break_characters are treated as any other character,
223 unless they also appear within this list. */
224const char *rl_completer_quote_characters = (const char *)NULL;
225
226/* List of characters that should be quoted in filenames by the completer. */
227const char *rl_filename_quote_characters = (const char *)NULL;

--- 50 unchanged lines hidden (view full) ---

278 possible closing quote. This is set to 0 by rl_complete_internal and
279 may be changed by an application-specific completion function. */
280int rl_completion_suppress_append = 0;
281
282/* Character appended to completed words when at the end of the line. The
283 default is a space. */
284int rl_completion_append_character = ' ';
285
234/* List of characters which can be used to quote a substring of the line.
235 Completion occurs on the entire substring, and within the substring
236 rl_completer_word_break_characters are treated as any other character,
237 unless they also appear within this list. */
238const char *rl_completer_quote_characters = (const char *)NULL;
239
240/* List of characters that should be quoted in filenames by the completer. */
241const char *rl_filename_quote_characters = (const char *)NULL;

--- 50 unchanged lines hidden (view full) ---

292 possible closing quote. This is set to 0 by rl_complete_internal and
293 may be changed by an application-specific completion function. */
294int rl_completion_suppress_append = 0;
295
296/* Character appended to completed words when at the end of the line. The
297 default is a space. */
298int rl_completion_append_character = ' ';
299
300/* If non-zero, the completion functions don't append any closing quote.
301 This is set to 0 by rl_complete_internal and may be changed by an
302 application-specific completion function. */
303int rl_completion_suppress_quote = 0;
304
305/* Set to any quote character readline thinks it finds before any application
306 completion function is called. */
307int rl_completion_quote_character;
308
309/* Set to a non-zero value if readline found quoting anywhere in the word to
310 be completed; set before any application completion function is called. */
311int rl_completion_found_quote;
312
286/* If non-zero, a slash will be appended to completed filenames that are
287 symbolic links to directory names, subject to the value of the
288 mark-directories variable (which is user-settable). This exists so
289 that application completion functions can override the user's preference
290 (set via the mark-symlinked-directories variable) if appropriate.
291 It's set to the value of _rl_complete_mark_symlink_dirs in
292 rl_complete_internal before any application-specific completion
293 function is called, so without that function doing anything, the user's

--- 22 unchanged lines hidden (view full) ---

316 int ignore, invoking_key;
317{
318 if (rl_inhibit_completion)
319 return (_rl_insert_char (ignore, invoking_key));
320 else if (rl_last_func == rl_complete && !completion_changed_buffer)
321 return (rl_complete_internal ('?'));
322 else if (_rl_complete_show_all)
323 return (rl_complete_internal ('!'));
313/* If non-zero, a slash will be appended to completed filenames that are
314 symbolic links to directory names, subject to the value of the
315 mark-directories variable (which is user-settable). This exists so
316 that application completion functions can override the user's preference
317 (set via the mark-symlinked-directories variable) if appropriate.
318 It's set to the value of _rl_complete_mark_symlink_dirs in
319 rl_complete_internal before any application-specific completion
320 function is called, so without that function doing anything, the user's

--- 22 unchanged lines hidden (view full) ---

343 int ignore, invoking_key;
344{
345 if (rl_inhibit_completion)
346 return (_rl_insert_char (ignore, invoking_key));
347 else if (rl_last_func == rl_complete && !completion_changed_buffer)
348 return (rl_complete_internal ('?'));
349 else if (_rl_complete_show_all)
350 return (rl_complete_internal ('!'));
351 else if (_rl_complete_show_unmodified)
352 return (rl_complete_internal ('@'));
324 else
325 return (rl_complete_internal (TAB));
326}
327
328/* List the possible completions. See description of rl_complete (). */
329int
330rl_possible_completions (ignore, invoking_key)
331 int ignore, invoking_key;

--- 16 unchanged lines hidden (view full) ---

348int
349rl_completion_mode (cfunc)
350 rl_command_func_t *cfunc;
351{
352 if (rl_last_func == cfunc && !completion_changed_buffer)
353 return '?';
354 else if (_rl_complete_show_all)
355 return '!';
353 else
354 return (rl_complete_internal (TAB));
355}
356
357/* List the possible completions. See description of rl_complete (). */
358int
359rl_possible_completions (ignore, invoking_key)
360 int ignore, invoking_key;

--- 16 unchanged lines hidden (view full) ---

377int
378rl_completion_mode (cfunc)
379 rl_command_func_t *cfunc;
380{
381 if (rl_last_func == cfunc && !completion_changed_buffer)
382 return '?';
383 else if (_rl_complete_show_all)
384 return '!';
385 else if (_rl_complete_show_unmodified)
386 return '@';
356 else
357 return TAB;
358}
359
360/************************************/
361/* */
362/* Completion utility functions */
363/* */

--- 4 unchanged lines hidden (view full) ---

368static void
369set_completion_defaults (what_to_do)
370 int what_to_do;
371{
372 /* Only the completion entry function can change these. */
373 rl_filename_completion_desired = 0;
374 rl_filename_quoting_desired = 1;
375 rl_completion_type = what_to_do;
387 else
388 return TAB;
389}
390
391/************************************/
392/* */
393/* Completion utility functions */
394/* */

--- 4 unchanged lines hidden (view full) ---

399static void
400set_completion_defaults (what_to_do)
401 int what_to_do;
402{
403 /* Only the completion entry function can change these. */
404 rl_filename_completion_desired = 0;
405 rl_filename_quoting_desired = 1;
406 rl_completion_type = what_to_do;
376 rl_completion_suppress_append = 0;
407 rl_completion_suppress_append = rl_completion_suppress_quote = 0;
377
378 /* The completion entry function may optionally change this. */
379 rl_completion_mark_symlink_dirs = _rl_complete_mark_symlink_dirs;
380}
381
382/* The user must press "y" or "n". Non-zero return means "y" pressed. */
383static int
384get_y_or_n (for_pager)

--- 34 unchanged lines hidden (view full) ---

419 if (i == 0)
420 return -1;
421 else if (i == 2)
422 return (lines - 1);
423 else
424 return 0;
425}
426
408
409 /* The completion entry function may optionally change this. */
410 rl_completion_mark_symlink_dirs = _rl_complete_mark_symlink_dirs;
411}
412
413/* The user must press "y" or "n". Non-zero return means "y" pressed. */
414static int
415get_y_or_n (for_pager)

--- 34 unchanged lines hidden (view full) ---

450 if (i == 0)
451 return -1;
452 else if (i == 2)
453 return (lines - 1);
454 else
455 return 0;
456}
457
458static int
459path_isdir (filename)
460 const char *filename;
461{
462 struct stat finfo;
463
464 return (stat (filename, &finfo) == 0 && S_ISDIR (finfo.st_mode));
465}
466
427#if defined (VISIBLE_STATS)
428/* Return the character which best describes FILENAME.
429 `@' for symbolic links
430 `/' for directories
431 `*' for executables
432 `=' for sockets
433 `|' for FIFOs
434 `%' for character special devices

--- 81 unchanged lines hidden (view full) ---

516 if (*x == '/')
517 break;
518 return ((*x == '/') ? x + 1 : pathname);
519 }
520 else
521 return ++temp;
522}
523
467#if defined (VISIBLE_STATS)
468/* Return the character which best describes FILENAME.
469 `@' for symbolic links
470 `/' for directories
471 `*' for executables
472 `=' for sockets
473 `|' for FIFOs
474 `%' for character special devices

--- 81 unchanged lines hidden (view full) ---

556 if (*x == '/')
557 break;
558 return ((*x == '/') ? x + 1 : pathname);
559 }
560 else
561 return ++temp;
562}
563
564/* Compute width of STRING when displayed on screen by print_filename */
565static int
566fnwidth (string)
567 const char *string;
568{
569 int width, pos;
570#if defined (HANDLE_MULTIBYTE)
571 mbstate_t ps;
572 int left, w;
573 size_t clen;
574 wchar_t wc;
575
576 left = strlen (string) + 1;
577 memset (&ps, 0, sizeof (mbstate_t));
578#endif
579
580 width = pos = 0;
581 while (string[pos])
582 {
583 if (CTRL_CHAR (*string) || *string == RUBOUT)
584 {
585 width += 2;
586 pos++;
587 }
588 else
589 {
590#if defined (HANDLE_MULTIBYTE)
591 clen = mbrtowc (&wc, string + pos, left - pos, &ps);
592 if (MB_INVALIDCH (clen))
593 {
594 width++;
595 pos++;
596 memset (&ps, 0, sizeof (mbstate_t));
597 }
598 else if (MB_NULLWCH (clen))
599 break;
600 else
601 {
602 pos += clen;
603 w = wcwidth (wc);
604 width += (w >= 0) ? w : 1;
605 }
606#else
607 width++;
608 pos++;
609#endif
610 }
611 }
612
613 return width;
614}
615
616static int
617fnprint (to_print)
618 const char *to_print;
619{
620 int printed_len;
621 const char *s;
622#if defined (HANDLE_MULTIBYTE)
623 mbstate_t ps;
624 const char *end;
625 size_t tlen;
626
627 end = to_print + strlen (to_print) + 1;
628 memset (&ps, 0, sizeof (mbstate_t));
629#endif
630
631 printed_len = 0;
632 s = to_print;
633 while (*s)
634 {
635 if (CTRL_CHAR (*s))
636 {
637 putc ('^', rl_outstream);
638 putc (UNCTRL (*s), rl_outstream);
639 printed_len += 2;
640 s++;
641#if defined (HANDLE_MULTIBYTE)
642 memset (&ps, 0, sizeof (mbstate_t));
643#endif
644 }
645 else if (*s == RUBOUT)
646 {
647 putc ('^', rl_outstream);
648 putc ('?', rl_outstream);
649 printed_len += 2;
650 s++;
651#if defined (HANDLE_MULTIBYTE)
652 memset (&ps, 0, sizeof (mbstate_t));
653#endif
654 }
655 else
656 {
657#if defined (HANDLE_MULTIBYTE)
658 tlen = mbrlen (s, end - s, &ps);
659 if (MB_INVALIDCH (tlen))
660 {
661 tlen = 1;
662 memset (&ps, 0, sizeof (mbstate_t));
663 }
664 else if (MB_NULLWCH (tlen))
665 break;
666 fwrite (s, 1, tlen, rl_outstream);
667 s += tlen;
668#else
669 putc (*s, rl_outstream);
670 s++;
671#endif
672 printed_len++;
673 }
674 }
675
676 return printed_len;
677}
678
524/* Output TO_PRINT to rl_outstream. If VISIBLE_STATS is defined and we
525 are using it, check for and output a single character for `special'
526 filenames. Return the number of characters we output. */
527
679/* Output TO_PRINT to rl_outstream. If VISIBLE_STATS is defined and we
680 are using it, check for and output a single character for `special'
681 filenames. Return the number of characters we output. */
682
528#define PUTX(c) \
529 do { \
530 if (CTRL_CHAR (c)) \
531 { \
532 putc ('^', rl_outstream); \
533 putc (UNCTRL (c), rl_outstream); \
534 printed_len += 2; \
535 } \
536 else if (c == RUBOUT) \
537 { \
538 putc ('^', rl_outstream); \
539 putc ('?', rl_outstream); \
540 printed_len += 2; \
541 } \
542 else \
543 { \
544 putc (c, rl_outstream); \
545 printed_len++; \
546 } \
547 } while (0)
548
549static int
550print_filename (to_print, full_pathname)
551 char *to_print, *full_pathname;
552{
683static int
684print_filename (to_print, full_pathname)
685 char *to_print, *full_pathname;
686{
553 int printed_len = 0;
554#if !defined (VISIBLE_STATS)
555 char *s;
556
557 for (s = to_print; *s; s++)
558 {
559 PUTX (*s);
560 }
561#else
687 int printed_len, extension_char, slen, tlen;
562 char *s, c, *new_full_pathname;
688 char *s, c, *new_full_pathname;
563 int extension_char, slen, tlen;
564
689
565 for (s = to_print; *s; s++)
566 {
567 PUTX (*s);
568 }
690 extension_char = 0;
691 printed_len = fnprint (to_print);
569
692
570 if (rl_filename_completion_desired && rl_visible_stats)
693#if defined (VISIBLE_STATS)
694 if (rl_filename_completion_desired && (rl_visible_stats || _rl_complete_mark_directories))
695#else
696 if (rl_filename_completion_desired && _rl_complete_mark_directories)
697#endif
571 {
572 /* If to_print != full_pathname, to_print is the basename of the
573 path passed. In this case, we try to expand the directory
574 name before checking for the stat character. */
575 if (to_print != full_pathname)
576 {
577 /* Terminate the directory name. */
578 c = to_print[-1];

--- 10 unchanged lines hidden (view full) ---

589
590 slen = strlen (s);
591 tlen = strlen (to_print);
592 new_full_pathname = (char *)xmalloc (slen + tlen + 2);
593 strcpy (new_full_pathname, s);
594 new_full_pathname[slen] = '/';
595 strcpy (new_full_pathname + slen + 1, to_print);
596
698 {
699 /* If to_print != full_pathname, to_print is the basename of the
700 path passed. In this case, we try to expand the directory
701 name before checking for the stat character. */
702 if (to_print != full_pathname)
703 {
704 /* Terminate the directory name. */
705 c = to_print[-1];

--- 10 unchanged lines hidden (view full) ---

716
717 slen = strlen (s);
718 tlen = strlen (to_print);
719 new_full_pathname = (char *)xmalloc (slen + tlen + 2);
720 strcpy (new_full_pathname, s);
721 new_full_pathname[slen] = '/';
722 strcpy (new_full_pathname + slen + 1, to_print);
723
597 extension_char = stat_char (new_full_pathname);
724#if defined (VISIBLE_STATS)
725 if (rl_visible_stats)
726 extension_char = stat_char (new_full_pathname);
727 else
728#endif
729 if (path_isdir (new_full_pathname))
730 extension_char = '/';
598
599 free (new_full_pathname);
600 to_print[-1] = c;
601 }
602 else
603 {
604 s = tilde_expand (full_pathname);
731
732 free (new_full_pathname);
733 to_print[-1] = c;
734 }
735 else
736 {
737 s = tilde_expand (full_pathname);
605 extension_char = stat_char (s);
738#if defined (VISIBLE_STATS)
739 if (rl_visible_stats)
740 extension_char = stat_char (s);
741 else
742#endif
743 if (path_isdir (s))
744 extension_char = '/';
606 }
607
608 free (s);
609 if (extension_char)
610 {
611 putc (extension_char, rl_outstream);
612 printed_len++;
613 }
614 }
745 }
746
747 free (s);
748 if (extension_char)
749 {
750 putc (extension_char, rl_outstream);
751 printed_len++;
752 }
753 }
615#endif /* VISIBLE_STATS */
754
616 return printed_len;
617}
618
619static char *
620rl_quote_filename (s, rtype, qcp)
621 char *s;
622 int rtype;
623 char *qcp;

--- 23 unchanged lines hidden (view full) ---

647 quote, or backslash) anywhere in the string. DP, if non-null, is set to
648 the value of the delimiter character that caused a word break. */
649
650char
651_rl_find_completion_word (fp, dp)
652 int *fp, *dp;
653{
654 int scan, end, found_quote, delimiter, pass_next, isbrk;
755 return printed_len;
756}
757
758static char *
759rl_quote_filename (s, rtype, qcp)
760 char *s;
761 int rtype;
762 char *qcp;

--- 23 unchanged lines hidden (view full) ---

786 quote, or backslash) anywhere in the string. DP, if non-null, is set to
787 the value of the delimiter character that caused a word break. */
788
789char
790_rl_find_completion_word (fp, dp)
791 int *fp, *dp;
792{
793 int scan, end, found_quote, delimiter, pass_next, isbrk;
655 char quote_char;
794 char quote_char, *brkchars;
656
657 end = rl_point;
658 found_quote = delimiter = 0;
659 quote_char = '\0';
660
795
796 end = rl_point;
797 found_quote = delimiter = 0;
798 quote_char = '\0';
799
800 brkchars = 0;
801 if (rl_completion_word_break_hook)
802 brkchars = (*rl_completion_word_break_hook) ();
803 if (brkchars == 0)
804 brkchars = rl_completer_word_break_characters;
805
661 if (rl_completer_quote_characters)
662 {
663 /* We have a list of characters which can be used in pairs to
664 quote substrings for the completer. Try to find the start
665 of an unclosed quoted substring. */
666 /* FOUND_QUOTE is set so we know what kind of quotes we found. */
806 if (rl_completer_quote_characters)
807 {
808 /* We have a list of characters which can be used in pairs to
809 quote substrings for the completer. Try to find the start
810 of an unclosed quoted substring. */
811 /* FOUND_QUOTE is set so we know what kind of quotes we found. */
812#if defined (HANDLE_MULTIBYTE)
813 for (scan = pass_next = 0; scan < end;
814 scan = ((MB_CUR_MAX == 1 || rl_byte_oriented)
815 ? (scan + 1)
816 : _rl_find_next_mbchar (rl_line_buffer, scan, 1, MB_FIND_ANY)))
817#else
667 for (scan = pass_next = 0; scan < end; scan++)
818 for (scan = pass_next = 0; scan < end; scan++)
819#endif
668 {
669 if (pass_next)
670 {
671 pass_next = 0;
672 continue;
673 }
674
675 /* Shell-like semantics for single quotes -- don't allow backslash

--- 41 unchanged lines hidden (view full) ---

717#if defined (HANDLE_MULTIBYTE)
718 while (rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_ANY))
719#else
720 while (--rl_point)
721#endif
722 {
723 scan = rl_line_buffer[rl_point];
724
820 {
821 if (pass_next)
822 {
823 pass_next = 0;
824 continue;
825 }
826
827 /* Shell-like semantics for single quotes -- don't allow backslash

--- 41 unchanged lines hidden (view full) ---

869#if defined (HANDLE_MULTIBYTE)
870 while (rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_ANY))
871#else
872 while (--rl_point)
873#endif
874 {
875 scan = rl_line_buffer[rl_point];
876
725 if (strchr (rl_completer_word_break_characters, scan) == 0)
877 if (strchr (brkchars, scan) == 0)
726 continue;
727
728 /* Call the application-specific function to tell us whether
729 this word break character is quoted and should be skipped. */
730 if (rl_char_is_quoted_p && found_quote &&
731 (*rl_char_is_quoted_p) (rl_line_buffer, rl_point))
732 continue;
733

--- 11 unchanged lines hidden (view full) ---

745 function decide whether or not a character is a word break, even
746 if it is found in rl_completer_word_break_characters. Don't bother
747 if we're at the end of the line, though. */
748 if (scan)
749 {
750 if (rl_char_is_quoted_p)
751 isbrk = (found_quote == 0 ||
752 (*rl_char_is_quoted_p) (rl_line_buffer, rl_point) == 0) &&
878 continue;
879
880 /* Call the application-specific function to tell us whether
881 this word break character is quoted and should be skipped. */
882 if (rl_char_is_quoted_p && found_quote &&
883 (*rl_char_is_quoted_p) (rl_line_buffer, rl_point))
884 continue;
885

--- 11 unchanged lines hidden (view full) ---

897 function decide whether or not a character is a word break, even
898 if it is found in rl_completer_word_break_characters. Don't bother
899 if we're at the end of the line, though. */
900 if (scan)
901 {
902 if (rl_char_is_quoted_p)
903 isbrk = (found_quote == 0 ||
904 (*rl_char_is_quoted_p) (rl_line_buffer, rl_point) == 0) &&
753 strchr (rl_completer_word_break_characters, scan) != 0;
905 strchr (brkchars, scan) != 0;
754 else
906 else
755 isbrk = strchr (rl_completer_word_break_characters, scan) != 0;
907 isbrk = strchr (brkchars, scan) != 0;
756
757 if (isbrk)
758 {
759 /* If the character that caused the word break was a quoting
760 character, then remember it as the delimiter. */
761 if (rl_basic_quote_characters &&
762 strchr (rl_basic_quote_characters, scan) &&
763 (end - rl_point) > 1)

--- 18 unchanged lines hidden (view full) ---

782gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
783 char *text;
784 int start, end;
785 rl_compentry_func_t *our_func;
786 int found_quote, quote_char;
787{
788 char **matches, *temp;
789
908
909 if (isbrk)
910 {
911 /* If the character that caused the word break was a quoting
912 character, then remember it as the delimiter. */
913 if (rl_basic_quote_characters &&
914 strchr (rl_basic_quote_characters, scan) &&
915 (end - rl_point) > 1)

--- 18 unchanged lines hidden (view full) ---

934gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
935 char *text;
936 int start, end;
937 rl_compentry_func_t *our_func;
938 int found_quote, quote_char;
939{
940 char **matches, *temp;
941
942 rl_completion_found_quote = found_quote;
943 rl_completion_quote_character = quote_char;
944
790 /* If the user wants to TRY to complete, but then wants to give
791 up and use the default completion function, they set the
792 variable rl_attempted_completion_function. */
793 if (rl_attempted_completion_function)
794 {
795 matches = (*rl_attempted_completion_function) (text, start, end);
796
797 if (matches || rl_attempted_completion_over)

--- 87 unchanged lines hidden (view full) ---

885static int
886compute_lcd_of_matches (match_list, matches, text)
887 char **match_list;
888 int matches;
889 const char *text;
890{
891 register int i, c1, c2, si;
892 int low; /* Count of max-matched characters. */
945 /* If the user wants to TRY to complete, but then wants to give
946 up and use the default completion function, they set the
947 variable rl_attempted_completion_function. */
948 if (rl_attempted_completion_function)
949 {
950 matches = (*rl_attempted_completion_function) (text, start, end);
951
952 if (matches || rl_attempted_completion_over)

--- 87 unchanged lines hidden (view full) ---

1040static int
1041compute_lcd_of_matches (match_list, matches, text)
1042 char **match_list;
1043 int matches;
1044 const char *text;
1045{
1046 register int i, c1, c2, si;
1047 int low; /* Count of max-matched characters. */
1048 char *dtext; /* dequoted TEXT, if needed */
893#if defined (HANDLE_MULTIBYTE)
894 int v;
895 mbstate_t ps1, ps2;
896 wchar_t wc1, wc2;
897#endif
898
899 /* If only one match, just use that. Otherwise, compare each
900 member of the list with the next, finding out where they

--- 75 unchanged lines hidden (view full) ---

976 match_list[0] = (char *)xmalloc (low + 1);
977
978 /* XXX - this might need changes in the presence of multibyte chars */
979
980 /* If we are ignoring case, try to preserve the case of the string
981 the user typed in the face of multiple matches differing in case. */
982 if (_rl_completion_case_fold)
983 {
1049#if defined (HANDLE_MULTIBYTE)
1050 int v;
1051 mbstate_t ps1, ps2;
1052 wchar_t wc1, wc2;
1053#endif
1054
1055 /* If only one match, just use that. Otherwise, compare each
1056 member of the list with the next, finding out where they

--- 75 unchanged lines hidden (view full) ---

1132 match_list[0] = (char *)xmalloc (low + 1);
1133
1134 /* XXX - this might need changes in the presence of multibyte chars */
1135
1136 /* If we are ignoring case, try to preserve the case of the string
1137 the user typed in the face of multiple matches differing in case. */
1138 if (_rl_completion_case_fold)
1139 {
1140 /* We're making an assumption here:
1141 IF we're completing filenames AND
1142 the application has defined a filename dequoting function AND
1143 we found a quote character AND
1144 the application has requested filename quoting
1145 THEN
1146 we assume that TEXT was dequoted before checking against
1147 the file system and needs to be dequoted here before we
1148 check against the list of matches
1149 FI */
1150 dtext = (char *)NULL;
1151 if (rl_filename_completion_desired &&
1152 rl_filename_dequoting_function &&
1153 rl_completion_found_quote &&
1154 rl_filename_quoting_desired)
1155 {
1156 dtext = (*rl_filename_dequoting_function) (text, rl_completion_quote_character);
1157 text = dtext;
1158 }
1159
984 /* sort the list to get consistent answers. */
985 qsort (match_list+1, matches, sizeof(char *), (QSFUNC *)_rl_qsort_string_compare);
986
987 si = strlen (text);
988 if (si <= low)
989 {
990 for (i = 1; i <= matches; i++)
991 if (strncmp (match_list[i], text, si) == 0)
992 {
993 strncpy (match_list[0], match_list[i], low);
994 break;
995 }
996 /* no casematch, use first entry */
997 if (i > matches)
998 strncpy (match_list[0], match_list[1], low);
999 }
1000 else
1001 /* otherwise, just use the text the user typed. */
1002 strncpy (match_list[0], text, low);
1160 /* sort the list to get consistent answers. */
1161 qsort (match_list+1, matches, sizeof(char *), (QSFUNC *)_rl_qsort_string_compare);
1162
1163 si = strlen (text);
1164 if (si <= low)
1165 {
1166 for (i = 1; i <= matches; i++)
1167 if (strncmp (match_list[i], text, si) == 0)
1168 {
1169 strncpy (match_list[0], match_list[i], low);
1170 break;
1171 }
1172 /* no casematch, use first entry */
1173 if (i > matches)
1174 strncpy (match_list[0], match_list[1], low);
1175 }
1176 else
1177 /* otherwise, just use the text the user typed. */
1178 strncpy (match_list[0], text, low);
1179
1180 FREE (dtext);
1003 }
1004 else
1005 strncpy (match_list[0], match_list[1], low);
1006
1007 match_list[0][low] = '\0';
1008 }
1009
1010 return matches;

--- 188 unchanged lines hidden (view full) ---

1199 return;
1200 }
1201
1202 /* There is more than one answer. Find out how many there are,
1203 and find the maximum printed length of a single entry. */
1204 for (max = 0, i = 1; matches[i]; i++)
1205 {
1206 temp = printable_part (matches[i]);
1181 }
1182 else
1183 strncpy (match_list[0], match_list[1], low);
1184
1185 match_list[0][low] = '\0';
1186 }
1187
1188 return matches;

--- 188 unchanged lines hidden (view full) ---

1377 return;
1378 }
1379
1380 /* There is more than one answer. Find out how many there are,
1381 and find the maximum printed length of a single entry. */
1382 for (max = 0, i = 1; matches[i]; i++)
1383 {
1384 temp = printable_part (matches[i]);
1207 len = strlen (temp);
1385 len = fnwidth (temp);
1208
1209 if (len > max)
1210 max = len;
1211 }
1212
1213 len = i - 1;
1214
1215 /* If the caller has defined a display hook, then call that now. */

--- 118 unchanged lines hidden (view full) ---

1334 char *text;
1335 int delimiter, quote_char, nontrivial_match;
1336{
1337 char temp_string[4], *filename;
1338 int temp_string_index, s;
1339 struct stat finfo;
1340
1341 temp_string_index = 0;
1386
1387 if (len > max)
1388 max = len;
1389 }
1390
1391 len = i - 1;
1392
1393 /* If the caller has defined a display hook, then call that now. */

--- 118 unchanged lines hidden (view full) ---

1512 char *text;
1513 int delimiter, quote_char, nontrivial_match;
1514{
1515 char temp_string[4], *filename;
1516 int temp_string_index, s;
1517 struct stat finfo;
1518
1519 temp_string_index = 0;
1342 if (quote_char && rl_point && rl_line_buffer[rl_point - 1] != quote_char)
1520 if (quote_char && rl_point && rl_completion_suppress_quote == 0 &&
1521 rl_line_buffer[rl_point - 1] != quote_char)
1343 temp_string[temp_string_index++] = quote_char;
1344
1345 if (delimiter)
1346 temp_string[temp_string_index++] = delimiter;
1347 else if (rl_completion_suppress_append == 0 && rl_completion_append_character)
1348 temp_string[temp_string_index++] = rl_completion_append_character;
1349
1350 temp_string[temp_string_index++] = '\0';

--- 94 unchanged lines hidden (view full) ---

1445}
1446
1447/* Complete the word at or before point.
1448 WHAT_TO_DO says what to do with the completion.
1449 `?' means list the possible completions.
1450 TAB means do standard completion.
1451 `*' means insert all of the possible completions.
1452 `!' means to do standard completion, and list all possible completions if
1522 temp_string[temp_string_index++] = quote_char;
1523
1524 if (delimiter)
1525 temp_string[temp_string_index++] = delimiter;
1526 else if (rl_completion_suppress_append == 0 && rl_completion_append_character)
1527 temp_string[temp_string_index++] = rl_completion_append_character;
1528
1529 temp_string[temp_string_index++] = '\0';

--- 94 unchanged lines hidden (view full) ---

1624}
1625
1626/* Complete the word at or before point.
1627 WHAT_TO_DO says what to do with the completion.
1628 `?' means list the possible completions.
1629 TAB means do standard completion.
1630 `*' means insert all of the possible completions.
1631 `!' means to do standard completion, and list all possible completions if
1453 there is more than one. */
1632 there is more than one.
1633 `@' means to do standard completion, and list all possible completions if
1634 there is more than one and partial completion is not possible. */
1454int
1455rl_complete_internal (what_to_do)
1456 int what_to_do;
1457{
1458 char **matches;
1459 rl_compentry_func_t *our_func;
1460 int start, end, delimiter, found_quote, i, nontrivial_lcd;
1461 char *text, *saved_line_buffer;
1462 char quote_char;
1463
1464 RL_SETSTATE(RL_STATE_COMPLETING);
1465
1466 set_completion_defaults (what_to_do);
1467
1468 saved_line_buffer = rl_line_buffer ? savestring (rl_line_buffer) : (char *)NULL;
1469 our_func = rl_completion_entry_function
1470 ? rl_completion_entry_function
1471 : rl_filename_completion_function;
1635int
1636rl_complete_internal (what_to_do)
1637 int what_to_do;
1638{
1639 char **matches;
1640 rl_compentry_func_t *our_func;
1641 int start, end, delimiter, found_quote, i, nontrivial_lcd;
1642 char *text, *saved_line_buffer;
1643 char quote_char;
1644
1645 RL_SETSTATE(RL_STATE_COMPLETING);
1646
1647 set_completion_defaults (what_to_do);
1648
1649 saved_line_buffer = rl_line_buffer ? savestring (rl_line_buffer) : (char *)NULL;
1650 our_func = rl_completion_entry_function
1651 ? rl_completion_entry_function
1652 : rl_filename_completion_function;
1472
1473 /* We now look backwards for the start of a filename/variable word. */
1474 end = rl_point;
1475 found_quote = delimiter = 0;
1476 quote_char = '\0';
1477
1478 if (rl_point)
1479 /* This (possibly) changes rl_point. If it returns a non-zero char,
1480 we know we have an open quote. */

--- 31 unchanged lines hidden (view full) ---

1512 RL_UNSETSTATE(RL_STATE_COMPLETING);
1513 return (0);
1514 }
1515
1516 switch (what_to_do)
1517 {
1518 case TAB:
1519 case '!':
1653 /* We now look backwards for the start of a filename/variable word. */
1654 end = rl_point;
1655 found_quote = delimiter = 0;
1656 quote_char = '\0';
1657
1658 if (rl_point)
1659 /* This (possibly) changes rl_point. If it returns a non-zero char,
1660 we know we have an open quote. */

--- 31 unchanged lines hidden (view full) ---

1692 RL_UNSETSTATE(RL_STATE_COMPLETING);
1693 return (0);
1694 }
1695
1696 switch (what_to_do)
1697 {
1698 case TAB:
1699 case '!':
1700 case '@':
1520 /* Insert the first match with proper quoting. */
1521 if (*matches[0])
1522 insert_match (matches[0], start, matches[1] ? MULT_MATCH : SINGLE_MATCH, &quote_char);
1523
1524 /* If there are more matches, ring the bell to indicate.
1525 If we are in vi mode, Posix.2 says to not ring the bell.
1526 If the `show-all-if-ambiguous' variable is set, display
1527 all the matches immediately. Otherwise, if this was the
1528 only match, and we are hacking files, check the file to
1529 see if it was a directory. If so, and the `mark-directories'
1530 variable is set, add a '/' to the name. If not, and we
1531 are at the end of the line, then add a space. */
1532 if (matches[1])
1533 {
1534 if (what_to_do == '!')
1535 {
1536 display_matches (matches);
1537 break;
1538 }
1701 /* Insert the first match with proper quoting. */
1702 if (*matches[0])
1703 insert_match (matches[0], start, matches[1] ? MULT_MATCH : SINGLE_MATCH, &quote_char);
1704
1705 /* If there are more matches, ring the bell to indicate.
1706 If we are in vi mode, Posix.2 says to not ring the bell.
1707 If the `show-all-if-ambiguous' variable is set, display
1708 all the matches immediately. Otherwise, if this was the
1709 only match, and we are hacking files, check the file to
1710 see if it was a directory. If so, and the `mark-directories'
1711 variable is set, add a '/' to the name. If not, and we
1712 are at the end of the line, then add a space. */
1713 if (matches[1])
1714 {
1715 if (what_to_do == '!')
1716 {
1717 display_matches (matches);
1718 break;
1719 }
1720 else if (what_to_do == '@')
1721 {
1722 if (nontrivial_lcd == 0)
1723 display_matches (matches);
1724 break;
1725 }
1539 else if (rl_editing_mode != vi_mode)
1540 rl_ding (); /* There are other matches remaining. */
1541 }
1542 else
1543 append_to_match (matches[0], delimiter, quote_char, nontrivial_lcd);
1544
1545 break;
1546

--- 459 unchanged lines hidden ---
1726 else if (rl_editing_mode != vi_mode)
1727 rl_ding (); /* There are other matches remaining. */
1728 }
1729 else
1730 append_to_match (matches[0], delimiter, quote_char, nontrivial_lcd);
1731
1732 break;
1733

--- 459 unchanged lines hidden ---