diff options
author | Andrey A. Chernov <ache@FreeBSD.org> | 2006-03-27 23:11:32 +0000 |
---|---|---|
committer | Andrey A. Chernov <ache@FreeBSD.org> | 2006-03-27 23:11:32 +0000 |
commit | ea3d03fb07fdb2023234ba0e7cbfeab907ef73d1 (patch) | |
tree | dfd673c8ea1e7e53dced92331577c5b595c02543 /contrib/libreadline/complete.c | |
parent | e8f10fd55ce2c408cded44672f17c96d0fd6b034 (diff) | |
download | src-ea3d03fb07fdb2023234ba0e7cbfeab907ef73d1.tar.gz src-ea3d03fb07fdb2023234ba0e7cbfeab907ef73d1.zip |
Resolve conflicts
Notes
Notes:
svn path=/head/; revision=157188
Diffstat (limited to 'contrib/libreadline/complete.c')
-rw-r--r-- | contrib/libreadline/complete.c | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/contrib/libreadline/complete.c b/contrib/libreadline/complete.c index 158de12df462..12da0eeabbcd 100644 --- a/contrib/libreadline/complete.c +++ b/contrib/libreadline/complete.c @@ -1,8 +1,7 @@ /* $FreeBSD$ */ - /* complete.c -- filename completion for readline. */ -/* Copyright (C) 1987-2004 Free Software Foundation, Inc. +/* Copyright (C) 1987-2005 Free Software Foundation, Inc. This file is part of the GNU Readline Library, a library for reading lines of text with interactive input and history editing. @@ -50,7 +49,9 @@ extern int errno; #endif /* !errno */ +#if defined (HAVE_PWD_H) #include <pwd.h> +#endif #include "posixdir.h" #include "posixstat.h" @@ -81,9 +82,9 @@ typedef int QSFUNC (); /* Most systems don't declare getpwent in <pwd.h> if _POSIX_SOURCE is defined. */ -#if !defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE) +#if defined (HAVE_GETPWENT) && (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE)) extern struct passwd *getpwent PARAMS((void)); -#endif /* !HAVE_GETPW_DECLS || _POSIX_SOURCE */ +#endif /* HAVE_GETPWENT && (!HAVE_GETPW_DECLS || _POSIX_SOURCE) */ /* If non-zero, then this is the address of a function to call when completing a word would normally display the list of possible matches. @@ -208,7 +209,8 @@ int rl_completion_type = 0; /* Up to this many items will be displayed in response to a possible-completions call. After that, we ask the user if - she is sure she wants to see them all. */ + she is sure she wants to see them all. A negative value means + don't ask. */ int rl_completion_query_items = 100; int _rl_page_completions = 1; @@ -623,6 +625,8 @@ fnprint (to_print) mbstate_t ps; const char *end; size_t tlen; + int width, w; + wchar_t wc; end = to_print + strlen (to_print) + 1; memset (&ps, 0, sizeof (mbstate_t)); @@ -655,21 +659,28 @@ fnprint (to_print) else { #if defined (HANDLE_MULTIBYTE) - tlen = mbrlen (s, end - s, &ps); + tlen = mbrtowc (&wc, s, end - s, &ps); if (MB_INVALIDCH (tlen)) { tlen = 1; + width = 1; memset (&ps, 0, sizeof (mbstate_t)); } else if (MB_NULLWCH (tlen)) break; + else + { + w = wcwidth (wc); + width = (w >= 0) ? w : 1; + } fwrite (s, 1, tlen, rl_outstream); s += tlen; + printed_len += width; #else putc (*s, rl_outstream); s++; -#endif printed_len++; +#endif } } @@ -685,7 +696,7 @@ print_filename (to_print, full_pathname) char *to_print, *full_pathname; { int printed_len, extension_char, slen, tlen; - char *s, c, *new_full_pathname; + char *s, c, *new_full_pathname, *dn; extension_char = 0; printed_len = fnprint (to_print); @@ -710,7 +721,17 @@ print_filename (to_print, full_pathname) files in the root directory. If we pass a null string to the bash directory completion hook, for example, it will expand it to the current directory. We just want the `/'. */ - s = tilde_expand (full_pathname && *full_pathname ? full_pathname : "/"); + if (full_pathname == 0 || *full_pathname == 0) + dn = "/"; + else if (full_pathname[0] != '/') + dn = full_pathname; + else if (full_pathname[1] == 0) + dn = "//"; /* restore trailing slash to `//' */ + else if (full_pathname[1] == '/' && full_pathname[2] == 0) + dn = "/"; /* don't turn /// into // */ + else + dn = full_pathname; + s = tilde_expand (dn); if (rl_directory_completion_hook) (*rl_directory_completion_hook) (&s); @@ -718,6 +739,10 @@ print_filename (to_print, full_pathname) tlen = strlen (to_print); new_full_pathname = (char *)xmalloc (slen + tlen + 2); strcpy (new_full_pathname, s); + if (s[slen - 1] == '/') + slen--; + else + new_full_pathname[slen] = '/'; new_full_pathname[slen] = '/'; strcpy (new_full_pathname + slen + 1, to_print); @@ -809,14 +834,7 @@ _rl_find_completion_word (fp, dp) quote substrings for the completer. Try to find the start of an unclosed quoted substring. */ /* FOUND_QUOTE is set so we know what kind of quotes we found. */ -#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 - for (scan = pass_next = 0; scan < end; scan++) -#endif + for (scan = pass_next = 0; scan < end; scan = MB_NEXTCHAR (rl_line_buffer, scan, 1, MB_FIND_ANY)) { if (pass_next) { @@ -866,11 +884,7 @@ _rl_find_completion_word (fp, dp) /* We didn't find an unclosed quoted substring upon which to do completion, so use the word break characters to find the substring on which to complete. */ -#if defined (HANDLE_MULTIBYTE) - while (rl_point = _rl_find_prev_mbchar (rl_line_buffer, rl_point, MB_FIND_ANY)) -#else - while (--rl_point) -#endif + while (rl_point = MB_PREVCHAR (rl_line_buffer, rl_point, MB_FIND_ANY)) { scan = rl_line_buffer[rl_point]; @@ -1153,7 +1167,7 @@ compute_lcd_of_matches (match_list, matches, text) rl_completion_found_quote && rl_filename_quoting_desired) { - dtext = (*rl_filename_dequoting_function) (text, rl_completion_quote_character); + dtext = (*rl_filename_dequoting_function) ((char *)text, rl_completion_quote_character); text = dtext; } @@ -1399,7 +1413,7 @@ display_matches (matches) /* If there are many items, then ask the user if she really wants to see them all. */ - if (len >= rl_completion_query_items) + if (rl_completion_query_items > 0 && len >= rl_completion_query_items) { rl_crlf (); fprintf (rl_outstream, "Display all %d possibilities? (y or n)", len); @@ -1536,7 +1550,7 @@ append_to_match (text, delimiter, quote_char, nontrivial_match) : stat (filename, &finfo); if (s == 0 && S_ISDIR (finfo.st_mode)) { - if (_rl_complete_mark_directories) + if (_rl_complete_mark_directories /* && rl_completion_suppress_append == 0 */) { /* This is clumsy. Avoid putting in a double slash if point is at the end of the line and the previous character is a @@ -1850,16 +1864,20 @@ rl_username_completion_function (text, state) setpwent (); } +#if defined (HAVE_GETPWENT) while (entry = getpwent ()) { /* Null usernames should result in all users as possible completions. */ if (namelen == 0 || (STREQN (username, entry->pw_name, namelen))) break; } +#endif if (entry == 0) { +#if defined (HAVE_GETPWENT) endpwent (); +#endif return ((char *)NULL); } else @@ -2171,9 +2189,11 @@ rl_menu_complete (count, ignore) return (0); } - match_list_index = (match_list_index + count) % match_list_size; + match_list_index += count; if (match_list_index < 0) match_list_index += match_list_size; + else + match_list_index %= match_list_size; if (match_list_index == 0 && match_list_size > 1) { |