From patchwork Mon Jul 17 14:36:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 21647 Received: (qmail 85567 invoked by alias); 17 Jul 2017 14:36:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 84860 invoked by uid 89); 17 Jul 2017 14:36:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:5107 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Jul 2017 14:36:20 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFD857CB8C for ; Mon, 17 Jul 2017 14:36:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AFD857CB8C Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AFD857CB8C Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FFF57EA25; Mon, 17 Jul 2017 14:36:17 +0000 (UTC) Subject: Re: [PATCH 12/40] "complete" command and completion word break characters To: Keith Seitz , gdb-patches@sourceware.org References: <1496406158-12663-1-git-send-email-palves@redhat.com> <1496406158-12663-13-git-send-email-palves@redhat.com> <59690443.3080306@redhat.com> From: Pedro Alves Message-ID: <1561162f-3d08-64bc-3f24-ee9ef63ed40a@redhat.com> Date: Mon, 17 Jul 2017 15:36:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <59690443.3080306@redhat.com> On 07/14/2017 06:49 PM, Keith Seitz wrote: > On 06/02/2017 05:22 AM, Pedro Alves wrote: >> First, the complete command has a too-simple approximation of what >> readline's TAB-completion code does to find the completion word point. >> Unfortunately, readline doesn't expose the functionality it uses >> internally, so to fix this this patch copies over the relevant code, >> and adjusts it a bit to better fit the use cases we need it for. >> (Specifically, our version avoids relying on the >> rl_word_break_characters, etc. globals, and instead takes those as >> arguments.) > > re: "copies over the relevant code" > Is it possible to mention this in/around the copied code? That might make it easier to track differences in the future, e.g., if someone found a problem with the copied code, he could look upstream for a fix (or report a bug). Indeed. See delta diff below. > >> >> diff --git a/gdb/completer.h b/gdb/completer.h >> index e554bff..207781d 100644 >> --- a/gdb/completer.h >> +++ b/gdb/completer.h >> @@ -203,6 +203,10 @@ extern void complete_line (completion_tracker &tracker, >> const char *line_buffer, >> int point); >> >> +extern const char *completion_find_completion_word (completion_tracker &tracker, >> + const char *text, >> + int *quote_char); >> + > > Missing comment? Good catch. I've pushed in the patch with the below squashed in. There was another comment that was not relevant for gdb's copy. diff --git i/gdb/completer.c w/gdb/completer.c index 3f25261..196610d 100644 --- i/gdb/completer.c +++ w/gdb/completer.c @@ -220,20 +220,19 @@ filename_completer_handle_brkchars (struct cmd_list_element *ignore, #define RL_QF_BACKSLASH 0x04 #define RL_QF_OTHER_QUOTE 0x08 -/* Find the bounds of the current word for completion purposes, and leave - rl_point set to the end of the word. This function skips quoted - substrings (characters between matched pairs of characters in - rl_completer_quote_characters). First we try to find an unclosed - quoted substring on which to do matching. If one is not found, we use - the word break characters to find the boundaries of the current word. - We call an application-specific function to decide whether or not a - particular word break character is quoted; if that function returns a - non-zero result, the character does not break a word. This function - returns the opening quote character if we found an unclosed quoted - substring, '\0' otherwise. FP, if non-null, is set to a value saying - which (shell-like) quote characters we found (single quote, double - quote, or backslash) anywhere in the string. DP, if non-null, is set to - the value of the delimiter character that caused a word break. */ +/* Find the bounds of the current word for completion purposes, and + return a pointer to the end of the word. This mimics (and is a + modified version of) readline's _rl_find_completion_word internal + function. + + This function skips quoted substrings (characters between matched + pairs of characters in rl_completer_quote_characters). We try to + find an unclosed quoted substring on which to do matching. If one + is not found, we use the word break characters to find the + boundaries of the current word. QC, if non-null, is set to the + opening quote character if we found an unclosed quoted substring, + '\0' otherwise. DP, if non-null, is set to the value of the + delimiter character that caused a word break. */ struct gdb_rl_completion_word_info { @@ -342,11 +341,6 @@ gdb_rl_find_completion_word (struct gdb_rl_completion_word_info *info, /* If we are at an unquoted word break, then advance past it. */ scan = line_buffer[point]; - /* If there is an application-specific function to say whether or - not a character is quoted and we found a quote character, let - that function decide whether or not a character is a word break, - even if it is found in rl_completer_word_break_characters. Don't - bother if we're at the end of the line, though. */ if (scan) { isbrk = strchr (brkchars, scan) != 0; @@ -1464,8 +1458,7 @@ gdb_completion_word_break_characters () return NULL; } -/* Get the list of chars that are considered as word breaks - for the current command. */ +/* See completer.h. */ const char * completion_find_completion_word (completion_tracker &tracker, const char *text, diff --git i/gdb/completer.h w/gdb/completer.h index 1f375f8..cf93cf0 100644 --- i/gdb/completer.h +++ w/gdb/completer.h @@ -203,6 +203,12 @@ extern void complete_line (completion_tracker &tracker, const char *line_buffer, int point); +/* Find the bounds of the word in TEXT for completion purposes, and + return a pointer to the end of the word. Calls the completion + machinery for a handle_brkchars phase (using TRACKER) to figure out + the right work break characters for the command in TEXT. + QUOTE_CHAR, if non-null, is set to the opening quote character if + we found an unclosed quoted substring, '\0' otherwise. */ extern const char *completion_find_completion_word (completion_tracker &tracker, const char *text, int *quote_char);