aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli/cli-cmds.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2002-02-18 01:12:38 +0000
committerTom Tromey <tromey@redhat.com>2002-02-18 01:12:38 +0000
commit83d31a92df84ad938cf24a599c769df5f4bf1206 (patch)
treec2980a06f239ee8a63988fcc285a5f80e9ed03f6 /gdb/cli/cli-cmds.c
parent380caad4f1ae3fe237c3696a8d1a6b69b846b893 (diff)
downloadfsf-binutils-gdb-83d31a92df84ad938cf24a599c769df5f4bf1206.zip
fsf-binutils-gdb-83d31a92df84ad938cf24a599c769df5f4bf1206.tar.gz
fsf-binutils-gdb-83d31a92df84ad938cf24a599c769df5f4bf1206.tar.bz2
* cli/cli-cmds.c (compare_strings): New function.
(complete_command): Only print each unique item once. * completer.h (complete_line): Declare. * completer.c (complete_line): New function. (line_completion_function): Use it.
Diffstat (limited to 'gdb/cli/cli-cmds.c')
-rw-r--r--gdb/cli/cli-cmds.c45
1 files changed, 39 insertions, 6 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index f229a70..9d9d9ce 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -201,6 +201,15 @@ help_command (char *command, int from_tty)
help_cmd (command, gdb_stdout);
}
+/* String compare function for qsort. */
+static int
+compare_strings (const void *arg1, const void *arg2)
+{
+ const char **s1 = (const char **) arg1;
+ const char **s2 = (const char **) arg2;
+ return strcmp (*s1, *s2);
+}
+
/* The "complete" command is used by Emacs to implement completion. */
/* ARGSUSED */
@@ -209,7 +218,7 @@ complete_command (char *arg, int from_tty)
{
int i;
int argpoint;
- char *completion;
+ char **completions;
dont_repeat ();
@@ -217,12 +226,36 @@ complete_command (char *arg, int from_tty)
arg = "";
argpoint = strlen (arg);
- for (completion = line_completion_function (arg, i = 0, arg, argpoint);
- completion;
- completion = line_completion_function (arg, ++i, arg, argpoint))
+ completions = complete_line (arg, arg, argpoint);
+
+ if (completions)
{
- printf_unfiltered ("%s\n", completion);
- xfree (completion);
+ int item, size;
+
+ for (size = 0; completions[size]; ++size)
+ ;
+ qsort (completions, size, sizeof (char *), compare_strings);
+
+ /* We do extra processing here since we only want to print each
+ unique item once. */
+ item = 0;
+ while (item < size)
+ {
+ int next_item;
+ printf_unfiltered ("%s\n", completions[item]);
+ next_item = item + 1;
+ while (next_item < size
+ && ! strcmp (completions[item], completions[next_item]))
+ {
+ xfree (completions[next_item]);
+ ++next_item;
+ }
+
+ xfree (completions[item]);
+ item = next_item;
+ }
+
+ xfree (completions);
}
}