From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30609 invoked by alias); 23 Apr 2010 20:40:08 -0000 Received: (qmail 30593 invoked by uid 22791); 23 Apr 2010 20:40:06 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 23 Apr 2010 20:40:00 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3NKdJMV006197 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Apr 2010 16:39:19 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3NKdJBL006145; Fri, 23 Apr 2010 16:39:19 -0400 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o3NKdHOu030402; Fri, 23 Apr 2010 16:39:18 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 14D7E37849C; Fri, 23 Apr 2010 14:39:17 -0600 (MDT) From: Tom Tromey To: Joel Brobecker Cc: Doug Evans , msnyder@vmware.com, gdb-patches@sourceware.org Subject: Patch: completion -vs- deprecated commands (Was: [RFA] target record_core -> target record-core?) References: <20100419064717.75D476E3DC@sebabeach.org> <20100420181116.GU19194@adacore.com> Reply-To: tromey@redhat.com Date: Fri, 23 Apr 2010 20:40:00 -0000 In-Reply-To: <20100420181116.GU19194@adacore.com> (Joel Brobecker's message of "Tue, 20 Apr 2010 14:11:16 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-04/txt/msg00818.txt.bz2 Tom> One more thing I've wanted is also making it so deprecated commands Tom> don't show up in completion when there is a non-deprecated completion Tom> available. Any comments on that? Joel> I think that would be useful indeed. Here's the patch. It looks big because I had to reindent a loop. I plan to commit this early next week, barring objections or comments. Built and regtested on x86-64 (compile farm). New tests included. Tom 2010-04-23 Tom Tromey * cli/cli-decode.c (complete_on_cmdlist): Make two passes over the command list. 2010-04-23 Tom Tromey * gdb.base/completion.exp: Add tests for completion and deprecated commands. Index: cli/cli-decode.c =================================================================== RCS file: /cvs/src/src/gdb/cli/cli-decode.c,v retrieving revision 1.86 diff -u -r1.86 cli-decode.c --- cli/cli-decode.c 1 Jan 2010 07:31:46 -0000 1.86 +++ cli/cli-decode.c 23 Apr 2010 20:17:41 -0000 @@ -1597,43 +1597,65 @@ int sizeof_matchlist; int matches; int textlen = strlen (text); + int pass; + int saw_deprecated_match = 0; sizeof_matchlist = 10; matchlist = (char **) xmalloc (sizeof_matchlist * sizeof (char *)); matches = 0; - for (ptr = list; ptr; ptr = ptr->next) - if (!strncmp (ptr->name, text, textlen) - && !ptr->abbrev_flag - && (ptr->func - || ptr->prefixlist)) - { - if (matches == sizeof_matchlist) - { - sizeof_matchlist *= 2; - matchlist = (char **) xrealloc ((char *) matchlist, - (sizeof_matchlist - * sizeof (char *))); - } - - matchlist[matches] = (char *) - xmalloc (strlen (word) + strlen (ptr->name) + 1); - if (word == text) - strcpy (matchlist[matches], ptr->name); - else if (word > text) - { - /* Return some portion of ptr->name. */ - strcpy (matchlist[matches], ptr->name + (word - text)); - } - else - { - /* Return some of text plus ptr->name. */ - strncpy (matchlist[matches], word, text - word); - matchlist[matches][text - word] = '\0'; - strcat (matchlist[matches], ptr->name); - } - ++matches; - } + /* We do one or two passes. In the first pass, we skip deprecated + commands. If we see no matching commands in the first pass, and + if we did happen to see a matching deprecated command, we do + another loop to collect those. */ + for (pass = 0; matches == 0 && pass < 2; ++pass) + { + for (ptr = list; ptr; ptr = ptr->next) + if (!strncmp (ptr->name, text, textlen) + && !ptr->abbrev_flag + && (ptr->func + || ptr->prefixlist)) + { + if (pass == 0) + { + if ((ptr->flags & CMD_DEPRECATED) != 0) + { + saw_deprecated_match = 1; + continue; + } + } + + if (matches == sizeof_matchlist) + { + sizeof_matchlist *= 2; + matchlist = (char **) xrealloc ((char *) matchlist, + (sizeof_matchlist + * sizeof (char *))); + } + + matchlist[matches] = (char *) + xmalloc (strlen (word) + strlen (ptr->name) + 1); + if (word == text) + strcpy (matchlist[matches], ptr->name); + else if (word > text) + { + /* Return some portion of ptr->name. */ + strcpy (matchlist[matches], ptr->name + (word - text)); + } + else + { + /* Return some of text plus ptr->name. */ + strncpy (matchlist[matches], word, text - word); + matchlist[matches][text - word] = '\0'; + strcat (matchlist[matches], ptr->name); + } + ++matches; + } + /* If we saw no matching deprecated commands in the first pass, + just bail out. */ + if (!saw_deprecated_match) + break; + } if (matches == 0) { Index: testsuite/gdb.base/completion.exp =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/completion.exp,v retrieving revision 1.44 diff -u -r1.44 completion.exp --- testsuite/gdb.base/completion.exp 4 Apr 2010 23:47:16 -0000 1.44 +++ testsuite/gdb.base/completion.exp 23 Apr 2010 20:17:43 -0000 @@ -847,6 +847,12 @@ eof { fail "(eof) Completing non-existing component #2" } } +# If there is a non-deprecated completion, it should be returned. +gdb_test "complete sav" "save" "test non-deprecated completion" +# If there is only a deprecated completion, then it should be returned. +gdb_test "complete save-t" "save-tracepoints" "test deprecated completion" + + # Restore globals modified in this test... set timeout $oldtimeout1