- case '?':
- {
- int len, count, limit, max;
- int j, k, l;
-
- /* Handle simple case first. What if there is only one answer? */
- if (!matches[1])
- {
- char *temp;
-
- temp = printable_part (matches[0]);
- crlf ();
- print_filename (temp, matches[0]);
- crlf ();
- goto restart;
- }
-
- /* There is more than one answer. Find out how many there are,
- and find out what the maximum printed length of a single entry
- is. */
- display_matches:
- for (max = 0, i = 1; matches[i]; i++)
- {
- char *temp;
- int name_length;
-
- temp = printable_part (matches[i]);
- name_length = strlen (temp);
-
- if (name_length > max)
- max = name_length;
- }
-
- len = i - 1;
-
- /* If there are many items, then ask the user if she
- really wants to see them all. */
- if (len >= rl_completion_query_items)
- {
- crlf ();
- fprintf (rl_outstream,
- "There are %d possibilities. Do you really", len);
- crlf ();
- fprintf (rl_outstream, "wish to see them all? (y or n)");
- fflush (rl_outstream);
- if (!get_y_or_n ())
- {
- crlf ();
- goto restart;
- }
- }
-
- /* How many items of MAX length can we fit in the screen window? */
- max += 2;
- limit = screenwidth / max;
- if (limit != 1 && (limit * max == screenwidth))
- limit--;
-
- /* Avoid a possible floating exception. If max > screenwidth,
- limit will be 0 and a divide-by-zero fault will result. */
- if (limit == 0)
- limit = 1;
-
- /* How many iterations of the printing loop? */
- count = (len + (limit - 1)) / limit;
-
- /* Watch out for special case. If LEN is less than LIMIT, then
- just do the inner printing loop.
- 0 < len <= limit implies count = 1. */
-
- /* Sort the items if they are not already sorted. */
- if (!rl_ignore_completion_duplicates)
- qsort (matches + 1, len - 1, sizeof (char *), compare_strings);
-
- /* Print the sorted items, up-and-down alphabetically, like
- ls might. */
- crlf ();
-
- for (i = 1; i <= count; i++)
- {
- for (j = 0, l = i; j < limit; j++)
- {
- if (l > len || !matches[l])
- break;
- else
- {
- char *temp;
- int printed_length;
-
- temp = printable_part (matches[l]);
- printed_length = strlen (temp);
- printed_length += print_filename (temp, matches[l]);
-
- if (j + 1 < limit)
- {
- for (k = 0; k < max - printed_length; k++)
- putc (' ', rl_outstream);
- }
- }
- l += count;
- }
- crlf ();
- }
- restart:
-
- rl_on_new_line ();
- }
- break;
+ if (delimiter)
+ temp_string[temp_string_index++] = delimiter;
+ else if (rl_completion_append_character)
+ temp_string[temp_string_index++] = rl_completion_append_character;
+
+ temp_string[temp_string_index++] = '\0';
+
+ if (rl_filename_completion_desired)
+ {
+ filename = tilde_expand (text);
+ if (stat (filename, &finfo) == 0 && S_ISDIR (finfo.st_mode))
+ {
+ if (_rl_complete_mark_directories && rl_line_buffer[rl_point] != '/')
+ rl_insert_text ("/");
+ }
+ else
+ {
+ if (rl_point == rl_end)
+ rl_insert_text (temp_string);
+ }
+ free (filename);
+ }
+ else
+ {
+ if (rl_point == rl_end)
+ rl_insert_text (temp_string);
+ }
+}