From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20980 invoked by alias); 4 Jan 2002 23:55:42 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 20933 invoked from network); 4 Jan 2002 23:55:36 -0000 Received: from unknown (HELO gash2.peakpeak.com) (207.174.178.17) by sources.redhat.com with SMTP; 4 Jan 2002 23:55:36 -0000 Received: from creche.cygnus.com (ta0198.peakpeak.com [204.144.244.198]) by gash2.peakpeak.com (8.9.3/8.9.3) with ESMTP id QAA22019; Fri, 4 Jan 2002 16:55:34 -0700 Received: (from tromey@localhost) by creche.cygnus.com (8.9.3/8.9.3) id RAA16035; Fri, 4 Jan 2002 17:07:51 -0700 To: gdb-patches@sources.redhat.com Subject: Patch: completion -vs- duplicates From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom X-Zippy: If I had a Q-TIP, I could prevent th'collapse of NEGOTIATIONS!! Date: Fri, 04 Jan 2002 15:55:00 -0000 Message-ID: <877kqx7j8o.fsf@creche.redhat.com> X-Mailer: Gnus v5.7/Emacs 20.5 X-SW-Source: 2002-01/txt/msg00049.txt.bz2 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 * 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; } }