1c1,2
< /* $FreeBSD: head/contrib/libreadline/complete.c 119614 2003-08-31 18:29:38Z ache $ */
---
> /* $FreeBSD: head/contrib/libreadline/complete.c 136758 2004-10-21 20:02:02Z peter $ */
>
4c5
< /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
---
> /* Copyright (C) 1987-2004 Free Software Foundation, Inc.
32c33
< #include <sys/file.h>
---
> # include <sys/file.h>
102a104,105
> static int path_isdir PARAMS((const char *));
>
108a112,113
> static int fnwidth PARAMS((const char *));
> static int fnprint PARAMS((const char *));
133a139,142
> /* If non-zero, non-unique completions show the list of matches, unless it
> is not possible to do partial completion and modify the line. */
> int _rl_complete_show_unmodified = 0;
>
218c227
< const char *rl_completer_word_break_characters = (const char *)NULL;
---
> /*const*/ char *rl_completer_word_break_characters = (/*const*/ char *)NULL;
219a229,233
> /* Hook function to allow an application to set the completion word
> break characters before readline breaks up the line. Allows
> position-dependent word break characters. */
> rl_cpvfunc_t *rl_completion_word_break_hook = (rl_cpvfunc_t *)NULL;
>
285a300,312
> /* If non-zero, the completion functions don't append any closing quote.
> This is set to 0 by rl_complete_internal and may be changed by an
> application-specific completion function. */
> int rl_completion_suppress_quote = 0;
>
> /* Set to any quote character readline thinks it finds before any application
> completion function is called. */
> int rl_completion_quote_character;
>
> /* Set to a non-zero value if readline found quoting anywhere in the word to
> be completed; set before any application completion function is called. */
> int rl_completion_found_quote;
>
323a351,352
> else if (_rl_complete_show_unmodified)
> return (rl_complete_internal ('@'));
355a385,386
> else if (_rl_complete_show_unmodified)
> return '@';
376c407
< rl_completion_suppress_append = 0;
---
> rl_completion_suppress_append = rl_completion_suppress_quote = 0;
426a458,466
> static int
> path_isdir (filename)
> const char *filename;
> {
> struct stat finfo;
>
> return (stat (filename, &finfo) == 0 && S_ISDIR (finfo.st_mode));
> }
>
523a564,678
> /* Compute width of STRING when displayed on screen by print_filename */
> static int
> fnwidth (string)
> const char *string;
> {
> int width, pos;
> #if defined (HANDLE_MULTIBYTE)
> mbstate_t ps;
> int left, w;
> size_t clen;
> wchar_t wc;
>
> left = strlen (string) + 1;
> memset (&ps, 0, sizeof (mbstate_t));
> #endif
>
> width = pos = 0;
> while (string[pos])
> {
> if (CTRL_CHAR (*string) || *string == RUBOUT)
> {
> width += 2;
> pos++;
> }
> else
> {
> #if defined (HANDLE_MULTIBYTE)
> clen = mbrtowc (&wc, string + pos, left - pos, &ps);
> if (MB_INVALIDCH (clen))
> {
> width++;
> pos++;
> memset (&ps, 0, sizeof (mbstate_t));
> }
> else if (MB_NULLWCH (clen))
> break;
> else
> {
> pos += clen;
> w = wcwidth (wc);
> width += (w >= 0) ? w : 1;
> }
> #else
> width++;
> pos++;
> #endif
> }
> }
>
> return width;
> }
>
> static int
> fnprint (to_print)
> const char *to_print;
> {
> int printed_len;
> const char *s;
> #if defined (HANDLE_MULTIBYTE)
> mbstate_t ps;
> const char *end;
> size_t tlen;
>
> end = to_print + strlen (to_print) + 1;
> memset (&ps, 0, sizeof (mbstate_t));
> #endif
>
> printed_len = 0;
> s = to_print;
> while (*s)
> {
> if (CTRL_CHAR (*s))
> {
> putc ('^', rl_outstream);
> putc (UNCTRL (*s), rl_outstream);
> printed_len += 2;
> s++;
> #if defined (HANDLE_MULTIBYTE)
> memset (&ps, 0, sizeof (mbstate_t));
> #endif
> }
> else if (*s == RUBOUT)
> {
> putc ('^', rl_outstream);
> putc ('?', rl_outstream);
> printed_len += 2;
> s++;
> #if defined (HANDLE_MULTIBYTE)
> memset (&ps, 0, sizeof (mbstate_t));
> #endif
> }
> else
> {
> #if defined (HANDLE_MULTIBYTE)
> tlen = mbrlen (s, end - s, &ps);
> if (MB_INVALIDCH (tlen))
> {
> tlen = 1;
> memset (&ps, 0, sizeof (mbstate_t));
> }
> else if (MB_NULLWCH (tlen))
> break;
> fwrite (s, 1, tlen, rl_outstream);
> s += tlen;
> #else
> putc (*s, rl_outstream);
> s++;
> #endif
> printed_len++;
> }
> }
>
> return printed_len;
> }
>
528,548d682
< #define PUTX(c) \
< do { \
< if (CTRL_CHAR (c)) \
< { \
< putc ('^', rl_outstream); \
< putc (UNCTRL (c), rl_outstream); \
< printed_len += 2; \
< } \
< else if (c == RUBOUT) \
< { \
< putc ('^', rl_outstream); \
< putc ('?', rl_outstream); \
< printed_len += 2; \
< } \
< else \
< { \
< putc (c, rl_outstream); \
< printed_len++; \
< } \
< } while (0)
<
553,561c687
< int printed_len = 0;
< #if !defined (VISIBLE_STATS)
< char *s;
<
< for (s = to_print; *s; s++)
< {
< PUTX (*s);
< }
< #else
---
> int printed_len, extension_char, slen, tlen;
563d688
< int extension_char, slen, tlen;
565,568c690,691
< for (s = to_print; *s; s++)
< {
< PUTX (*s);
< }
---
> extension_char = 0;
> printed_len = fnprint (to_print);
570c693,697
< if (rl_filename_completion_desired && rl_visible_stats)
---
> #if defined (VISIBLE_STATS)
> if (rl_filename_completion_desired && (rl_visible_stats || _rl_complete_mark_directories))
> #else
> if (rl_filename_completion_desired && _rl_complete_mark_directories)
> #endif
597c724,730
< extension_char = stat_char (new_full_pathname);
---
> #if defined (VISIBLE_STATS)
> if (rl_visible_stats)
> extension_char = stat_char (new_full_pathname);
> else
> #endif
> if (path_isdir (new_full_pathname))
> extension_char = '/';
605c738,744
< extension_char = stat_char (s);
---
> #if defined (VISIBLE_STATS)
> if (rl_visible_stats)
> extension_char = stat_char (s);
> else
> #endif
> if (path_isdir (s))
> extension_char = '/';
615c754
< #endif /* VISIBLE_STATS */
---
>
655c794
< char quote_char;
---
> char quote_char, *brkchars;
660a800,805
> brkchars = 0;
> if (rl_completion_word_break_hook)
> brkchars = (*rl_completion_word_break_hook) ();
> if (brkchars == 0)
> brkchars = rl_completer_word_break_characters;
>
666a812,817
> #if defined (HANDLE_MULTIBYTE)
> for (scan = pass_next = 0; scan < end;
> scan = ((MB_CUR_MAX == 1 || rl_byte_oriented)
> ? (scan + 1)
> : _rl_find_next_mbchar (rl_line_buffer, scan, 1, MB_FIND_ANY)))
> #else
667a819
> #endif
725c877
< if (strchr (rl_completer_word_break_characters, scan) == 0)
---
> if (strchr (brkchars, scan) == 0)
753c905
< strchr (rl_completer_word_break_characters, scan) != 0;
---
> strchr (brkchars, scan) != 0;
755c907
< isbrk = strchr (rl_completer_word_break_characters, scan) != 0;
---
> isbrk = strchr (brkchars, scan) != 0;
789a942,944
> rl_completion_found_quote = found_quote;
> rl_completion_quote_character = quote_char;
>
892a1048
> char *dtext; /* dequoted TEXT, if needed */
983a1140,1159
> /* We're making an assumption here:
> IF we're completing filenames AND
> the application has defined a filename dequoting function AND
> we found a quote character AND
> the application has requested filename quoting
> THEN
> we assume that TEXT was dequoted before checking against
> the file system and needs to be dequoted here before we
> check against the list of matches
> FI */
> dtext = (char *)NULL;
> if (rl_filename_completion_desired &&
> rl_filename_dequoting_function &&
> rl_completion_found_quote &&
> rl_filename_quoting_desired)
> {
> dtext = (*rl_filename_dequoting_function) (text, rl_completion_quote_character);
> text = dtext;
> }
>
1002a1179,1180
>
> FREE (dtext);
1207c1385
< len = strlen (temp);
---
> len = fnwidth (temp);
1342c1520,1521
< if (quote_char && rl_point && rl_line_buffer[rl_point - 1] != quote_char)
---
> if (quote_char && rl_point && rl_completion_suppress_quote == 0 &&
> rl_line_buffer[rl_point - 1] != quote_char)
1453c1632,1634
< there is more than one. */
---
> there is more than one.
> `@' means to do standard completion, and list all possible completions if
> there is more than one and partial completion is not possible. */
1472d1652
<
1519a1700
> case '@':
1538a1720,1725
> else if (what_to_do == '@')
> {
> if (nontrivial_lcd == 0)
> display_matches (matches);
> break;
> }
< /* $FreeBSD: head/contrib/libreadline/complete.c 119614 2003-08-31 18:29:38Z ache $ */
---
> /* $FreeBSD: head/contrib/libreadline/complete.c 136758 2004-10-21 20:02:02Z peter $ */
>
4c5
< /* Copyright (C) 1987, 1989, 1992 Free Software Foundation, Inc.
---
> /* Copyright (C) 1987-2004 Free Software Foundation, Inc.
32c33
< #include <sys/file.h>
---
> # include <sys/file.h>
102a104,105
> static int path_isdir PARAMS((const char *));
>
108a112,113
> static int fnwidth PARAMS((const char *));
> static int fnprint PARAMS((const char *));
133a139,142
> /* If non-zero, non-unique completions show the list of matches, unless it
> is not possible to do partial completion and modify the line. */
> int _rl_complete_show_unmodified = 0;
>
218c227
< const char *rl_completer_word_break_characters = (const char *)NULL;
---
> /*const*/ char *rl_completer_word_break_characters = (/*const*/ char *)NULL;
219a229,233
> /* Hook function to allow an application to set the completion word
> break characters before readline breaks up the line. Allows
> position-dependent word break characters. */
> rl_cpvfunc_t *rl_completion_word_break_hook = (rl_cpvfunc_t *)NULL;
>
285a300,312
> /* If non-zero, the completion functions don't append any closing quote.
> This is set to 0 by rl_complete_internal and may be changed by an
> application-specific completion function. */
> int rl_completion_suppress_quote = 0;
>
> /* Set to any quote character readline thinks it finds before any application
> completion function is called. */
> int rl_completion_quote_character;
>
> /* Set to a non-zero value if readline found quoting anywhere in the word to
> be completed; set before any application completion function is called. */
> int rl_completion_found_quote;
>
323a351,352
> else if (_rl_complete_show_unmodified)
> return (rl_complete_internal ('@'));
355a385,386
> else if (_rl_complete_show_unmodified)
> return '@';
376c407
< rl_completion_suppress_append = 0;
---
> rl_completion_suppress_append = rl_completion_suppress_quote = 0;
426a458,466
> static int
> path_isdir (filename)
> const char *filename;
> {
> struct stat finfo;
>
> return (stat (filename, &finfo) == 0 && S_ISDIR (finfo.st_mode));
> }
>
523a564,678
> /* Compute width of STRING when displayed on screen by print_filename */
> static int
> fnwidth (string)
> const char *string;
> {
> int width, pos;
> #if defined (HANDLE_MULTIBYTE)
> mbstate_t ps;
> int left, w;
> size_t clen;
> wchar_t wc;
>
> left = strlen (string) + 1;
> memset (&ps, 0, sizeof (mbstate_t));
> #endif
>
> width = pos = 0;
> while (string[pos])
> {
> if (CTRL_CHAR (*string) || *string == RUBOUT)
> {
> width += 2;
> pos++;
> }
> else
> {
> #if defined (HANDLE_MULTIBYTE)
> clen = mbrtowc (&wc, string + pos, left - pos, &ps);
> if (MB_INVALIDCH (clen))
> {
> width++;
> pos++;
> memset (&ps, 0, sizeof (mbstate_t));
> }
> else if (MB_NULLWCH (clen))
> break;
> else
> {
> pos += clen;
> w = wcwidth (wc);
> width += (w >= 0) ? w : 1;
> }
> #else
> width++;
> pos++;
> #endif
> }
> }
>
> return width;
> }
>
> static int
> fnprint (to_print)
> const char *to_print;
> {
> int printed_len;
> const char *s;
> #if defined (HANDLE_MULTIBYTE)
> mbstate_t ps;
> const char *end;
> size_t tlen;
>
> end = to_print + strlen (to_print) + 1;
> memset (&ps, 0, sizeof (mbstate_t));
> #endif
>
> printed_len = 0;
> s = to_print;
> while (*s)
> {
> if (CTRL_CHAR (*s))
> {
> putc ('^', rl_outstream);
> putc (UNCTRL (*s), rl_outstream);
> printed_len += 2;
> s++;
> #if defined (HANDLE_MULTIBYTE)
> memset (&ps, 0, sizeof (mbstate_t));
> #endif
> }
> else if (*s == RUBOUT)
> {
> putc ('^', rl_outstream);
> putc ('?', rl_outstream);
> printed_len += 2;
> s++;
> #if defined (HANDLE_MULTIBYTE)
> memset (&ps, 0, sizeof (mbstate_t));
> #endif
> }
> else
> {
> #if defined (HANDLE_MULTIBYTE)
> tlen = mbrlen (s, end - s, &ps);
> if (MB_INVALIDCH (tlen))
> {
> tlen = 1;
> memset (&ps, 0, sizeof (mbstate_t));
> }
> else if (MB_NULLWCH (tlen))
> break;
> fwrite (s, 1, tlen, rl_outstream);
> s += tlen;
> #else
> putc (*s, rl_outstream);
> s++;
> #endif
> printed_len++;
> }
> }
>
> return printed_len;
> }
>
528,548d682
< #define PUTX(c) \
< do { \
< if (CTRL_CHAR (c)) \
< { \
< putc ('^', rl_outstream); \
< putc (UNCTRL (c), rl_outstream); \
< printed_len += 2; \
< } \
< else if (c == RUBOUT) \
< { \
< putc ('^', rl_outstream); \
< putc ('?', rl_outstream); \
< printed_len += 2; \
< } \
< else \
< { \
< putc (c, rl_outstream); \
< printed_len++; \
< } \
< } while (0)
<
553,561c687
< int printed_len = 0;
< #if !defined (VISIBLE_STATS)
< char *s;
<
< for (s = to_print; *s; s++)
< {
< PUTX (*s);
< }
< #else
---
> int printed_len, extension_char, slen, tlen;
563d688
< int extension_char, slen, tlen;
565,568c690,691
< for (s = to_print; *s; s++)
< {
< PUTX (*s);
< }
---
> extension_char = 0;
> printed_len = fnprint (to_print);
570c693,697
< if (rl_filename_completion_desired && rl_visible_stats)
---
> #if defined (VISIBLE_STATS)
> if (rl_filename_completion_desired && (rl_visible_stats || _rl_complete_mark_directories))
> #else
> if (rl_filename_completion_desired && _rl_complete_mark_directories)
> #endif
597c724,730
< extension_char = stat_char (new_full_pathname);
---
> #if defined (VISIBLE_STATS)
> if (rl_visible_stats)
> extension_char = stat_char (new_full_pathname);
> else
> #endif
> if (path_isdir (new_full_pathname))
> extension_char = '/';
605c738,744
< extension_char = stat_char (s);
---
> #if defined (VISIBLE_STATS)
> if (rl_visible_stats)
> extension_char = stat_char (s);
> else
> #endif
> if (path_isdir (s))
> extension_char = '/';
615c754
< #endif /* VISIBLE_STATS */
---
>
655c794
< char quote_char;
---
> char quote_char, *brkchars;
660a800,805
> brkchars = 0;
> if (rl_completion_word_break_hook)
> brkchars = (*rl_completion_word_break_hook) ();
> if (brkchars == 0)
> brkchars = rl_completer_word_break_characters;
>
666a812,817
> #if defined (HANDLE_MULTIBYTE)
> for (scan = pass_next = 0; scan < end;
> scan = ((MB_CUR_MAX == 1 || rl_byte_oriented)
> ? (scan + 1)
> : _rl_find_next_mbchar (rl_line_buffer, scan, 1, MB_FIND_ANY)))
> #else
667a819
> #endif
725c877
< if (strchr (rl_completer_word_break_characters, scan) == 0)
---
> if (strchr (brkchars, scan) == 0)
753c905
< strchr (rl_completer_word_break_characters, scan) != 0;
---
> strchr (brkchars, scan) != 0;
755c907
< isbrk = strchr (rl_completer_word_break_characters, scan) != 0;
---
> isbrk = strchr (brkchars, scan) != 0;
789a942,944
> rl_completion_found_quote = found_quote;
> rl_completion_quote_character = quote_char;
>
892a1048
> char *dtext; /* dequoted TEXT, if needed */
983a1140,1159
> /* We're making an assumption here:
> IF we're completing filenames AND
> the application has defined a filename dequoting function AND
> we found a quote character AND
> the application has requested filename quoting
> THEN
> we assume that TEXT was dequoted before checking against
> the file system and needs to be dequoted here before we
> check against the list of matches
> FI */
> dtext = (char *)NULL;
> if (rl_filename_completion_desired &&
> rl_filename_dequoting_function &&
> rl_completion_found_quote &&
> rl_filename_quoting_desired)
> {
> dtext = (*rl_filename_dequoting_function) (text, rl_completion_quote_character);
> text = dtext;
> }
>
1002a1179,1180
>
> FREE (dtext);
1207c1385
< len = strlen (temp);
---
> len = fnwidth (temp);
1342c1520,1521
< if (quote_char && rl_point && rl_line_buffer[rl_point - 1] != quote_char)
---
> if (quote_char && rl_point && rl_completion_suppress_quote == 0 &&
> rl_line_buffer[rl_point - 1] != quote_char)
1453c1632,1634
< there is more than one. */
---
> there is more than one.
> `@' means to do standard completion, and list all possible completions if
> there is more than one and partial completion is not possible. */
1472d1652
<
1519a1700
> case '@':
1538a1720,1725
> else if (what_to_do == '@')
> {
> if (nontrivial_lcd == 0)
> display_matches (matches);
> break;
> }