1/* $FreeBSD: head/contrib/libreadline/complete.c 157188 2006-03-27 23:11:32Z ache $ */
2/* complete.c -- filename completion for readline. */
3
4/* Copyright (C) 1987-2005 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
--- 936 unchanged lines hidden (view full) ---
946
947static char **
948gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
949 char *text;
950 int start, end;
951 rl_compentry_func_t *our_func;
952 int found_quote, quote_char;
953{
954 char **matches, *temp;
955
956 rl_completion_found_quote = found_quote;
957 rl_completion_quote_character = quote_char;
958
959 /* If the user wants to TRY to complete, but then wants to give
960 up and use the default completion function, they set the
961 variable rl_attempted_completion_function. */
962 if (rl_attempted_completion_function)
963 {
964 matches = (*rl_attempted_completion_function) (text, start, end);
965
966 if (matches || rl_attempted_completion_over)
967 {
968 rl_attempted_completion_over = 0;
969 return (matches);
970 }
971 }
972
973 /* Beware -- we're stripping the quotes here. Do this only if we know
974 we are doing filename completion and the application has defined a
975 filename dequoting function. */
976 temp = (char *)NULL;
977
978 if (found_quote && our_func == rl_filename_completion_function &&
979 rl_filename_dequoting_function)
980 {
981 /* delete single and double quotes */
982 temp = (*rl_filename_dequoting_function) (text, quote_char);
983 text = temp; /* not freeing text is not a memory leak */
984 }
985
986 matches = rl_completion_matches (text, our_func);
987 FREE (temp);
988 return matches;
989}
990
991/* Filter out duplicates in MATCHES. This frees up the strings in
992 MATCHES. */
993static char **
994remove_duplicate_matches (matches)
995 char **matches;
--- 116 unchanged lines hidden (view full) ---
1112 {
1113 for (si = 0;
1114 (c1 = match_list[i][si]) &&
1115 (c2 = match_list[i + 1][si]);
1116 si++)
1117#if defined (HANDLE_MULTIBYTE)
1118 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
1119 {
1120 mbstate_t ps_back = ps1;
1121 if (!_rl_compare_chars (match_list[i], si, &ps1, match_list[i+1], si, &ps2))
1122 break;
1123 else if ((v = _rl_get_char_len (&match_list[i][si], &ps_back)) > 1)
1124 si += v - 1;
1125 }
1126 else
1127#endif
1128 if (c1 != c2)
--- 841 unchanged lines hidden (view full) ---
1970 temp = tilde_expand (dirname);
1971 free (dirname);
1972 dirname = temp;
1973 }
1974
1975 if (rl_directory_rewrite_hook)
1976 (*rl_directory_rewrite_hook) (&dirname);
1977
1978 if (rl_directory_completion_hook && (*rl_directory_completion_hook) (&dirname))
1979 {
1980 free (users_dirname);
1981 users_dirname = savestring (dirname);
1982 }
1983
1984 directory = opendir (dirname);
1985 filename_len = strlen (filename);
1986
1987 rl_filename_completion_desired = 1;
1988 }
1989
1990 /* At this point we should entertain the possibility of hacking wildcarded
1991 filenames, like /usr/man/man<WILD>/te<TAB>. If the directory name
1992 contains globbing characters, then build an array of directories, and
--- 220 unchanged lines hidden ---
2/* complete.c -- filename completion for readline. */
3
4/* Copyright (C) 1987-2005 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
--- 936 unchanged lines hidden (view full) ---
946
947static char **
948gen_completion_matches (text, start, end, our_func, found_quote, quote_char)
949 char *text;
950 int start, end;
951 rl_compentry_func_t *our_func;
952 int found_quote, quote_char;
953{
954 char **matches, *temp;
955
956 rl_completion_found_quote = found_quote;
957 rl_completion_quote_character = quote_char;
958
959 /* If the user wants to TRY to complete, but then wants to give
960 up and use the default completion function, they set the
961 variable rl_attempted_completion_function. */
962 if (rl_attempted_completion_function)
963 {
964 matches = (*rl_attempted_completion_function) (text, start, end);
965
966 if (matches || rl_attempted_completion_over)
967 {
968 rl_attempted_completion_over = 0;
969 return (matches);
970 }
971 }
972
973 /* Beware -- we're stripping the quotes here. Do this only if we know
974 we are doing filename completion and the application has defined a
975 filename dequoting function. */
976 temp = (char *)NULL;
977
978 if (found_quote && our_func == rl_filename_completion_function &&
979 rl_filename_dequoting_function)
980 {
981 /* delete single and double quotes */
982 temp = (*rl_filename_dequoting_function) (text, quote_char);
983 text = temp; /* not freeing text is not a memory leak */
984 }
985
986 matches = rl_completion_matches (text, our_func);
987 FREE (temp);
988 return matches;
989}
990
991/* Filter out duplicates in MATCHES. This frees up the strings in
992 MATCHES. */
993static char **
994remove_duplicate_matches (matches)
995 char **matches;
--- 116 unchanged lines hidden (view full) ---
1112 {
1113 for (si = 0;
1114 (c1 = match_list[i][si]) &&
1115 (c2 = match_list[i + 1][si]);
1116 si++)
1117#if defined (HANDLE_MULTIBYTE)
1118 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
1119 {
1120 mbstate_t ps_back = ps1;
1121 if (!_rl_compare_chars (match_list[i], si, &ps1, match_list[i+1], si, &ps2))
1122 break;
1123 else if ((v = _rl_get_char_len (&match_list[i][si], &ps_back)) > 1)
1124 si += v - 1;
1125 }
1126 else
1127#endif
1128 if (c1 != c2)
--- 841 unchanged lines hidden (view full) ---
1970 temp = tilde_expand (dirname);
1971 free (dirname);
1972 dirname = temp;
1973 }
1974
1975 if (rl_directory_rewrite_hook)
1976 (*rl_directory_rewrite_hook) (&dirname);
1977
1978 if (rl_directory_completion_hook && (*rl_directory_completion_hook) (&dirname))
1979 {
1980 free (users_dirname);
1981 users_dirname = savestring (dirname);
1982 }
1983
1984 directory = opendir (dirname);
1985 filename_len = strlen (filename);
1986
1987 rl_filename_completion_desired = 1;
1988 }
1989
1990 /* At this point we should entertain the possibility of hacking wildcarded
1991 filenames, like /usr/man/man<WILD>/te<TAB>. If the directory name
1992 contains globbing characters, then build an array of directories, and
--- 220 unchanged lines hidden ---