From: Tom Tromey <tromey@redhat.com>
To: gdb-patches@sources.redhat.com
Subject: Patch: completion -vs- duplicates
Date: Fri, 04 Jan 2002 15:55:00 -0000 [thread overview]
Message-ID: <877kqx7j8o.fsf@creche.redhat.com> (raw)
Right now the `complete' command can print duplicates. readline seems
to filter these, so you don't see this using Tab in the CLI, but you
can see it in Insight or by using the complete command.
E.g., run gdb on itself and type "complete b captured_ma".
I see `b captured_main' and `b captured_main_args' repeated many
times.
This patch fixes completion to uniquify the result list.
Ok to commit?
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* completer.c (compare_strings): New function.
(line_completion_function): Make result list have unique
elements.
Index: completer.c
===================================================================
RCS file: /cvs/src/src/gdb/completer.c,v
retrieving revision 1.8
diff -u -r1.8 completer.c
--- completer.c 2001/07/15 18:57:06 1.8
+++ completer.c 2002/01/04 23:52:18
@@ -339,6 +339,15 @@
return list;
}
+/* 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);
+}
+
/* Here are some useful test cases for completion. FIXME: These should
be put in the test suite. They should be tested with both M-? and TAB.
@@ -620,6 +629,30 @@
list = (*c->completer) (p, word);
}
}
+ }
+
+ /* Make sure each item in the list is unique. */
+ if (list)
+ {
+ int src, dest, size;
+
+ for (size = 0; list[size]; ++size)
+ ;
+ qsort (list, size, sizeof (char *), compare_strings);
+
+ src = 0;
+ dest = 0;
+ while (src < size)
+ {
+ list[dest] = list[src++];
+ while (src < size && ! strcmp (list[dest], list[src]))
+ {
+ xfree (list[src]);
+ ++src;
+ }
+ ++dest;
+ }
+ list[dest] = NULL;
}
}
next reply other threads:[~2002-01-04 23:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-01-04 15:55 Tom Tromey [this message]
2002-01-05 0:25 ` Eli Zaretskii
2002-01-05 7:44 ` Daniel Berlin
2002-01-05 10:20 ` Tom Tromey
2002-01-05 10:34 ` Andrew Cagney
2002-01-05 12:37 ` Tom Tromey
2002-01-05 10:30 ` Daniel Jacobowitz
2002-01-05 10:37 ` Daniel Berlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877kqx7j8o.fsf@creche.redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox