From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by sourceware.org (Postfix) with ESMTPS id 6F6EC3858422 for ; Sun, 2 Jul 2023 16:32:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F6EC3858422 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=kitware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kitware.com Received: by mail-qk1-x72b.google.com with SMTP id af79cd13be357-765a1690003so315353585a.0 for ; Sun, 02 Jul 2023 09:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kitware.com; s=google; t=1688315539; x=1690907539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mKw+OgoPi2lyCA6hl+X5B0bcGJuQwVs4JXz4ne6ppr4=; b=Ob4e8/heGG2qt3vhIB11XPrNvfTG5yN1YYNL40ZdsTdK6t27aK0q9f0nzwqhFzDrc7 T4O/AAZh0HVqhZOVq/4bnJLsYDb+doEULtBBJWfnrnt8jAhEq2jgE37O59AqTbgZMuT7 C7uswXPMrkeMfScK2mqfSnWKRL/I1lSzra6U4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688315539; x=1690907539; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mKw+OgoPi2lyCA6hl+X5B0bcGJuQwVs4JXz4ne6ppr4=; b=aReQMIbmGq7dtKg/2Jg//1aH8t22rMMymbLbOy0sKdSbiSQNjX8aGiAMxuoRW6JjT+ yyEN4CDRoBfTMxwrvn6kW0yfbMlAu2azp1lpzxDvLZvtmE0kc3n743lt3jJM7B9oW5EW E36ZXj+iyWaeNv7GGrNNgyL1nyof4BbSKxgWRSJfIMlP3e0L+thr219+8Al60ruOIUKl 4OvD5gQwD3y0RTY+dxWwjM/Z/lalxT6z631WlkH37qkTcONajJyVvxYhhvuPT4ejG7FR pNTWrjDrQwGlAfibmjf9sEfXWmwQmt3AAgU8sbPvB7BB9Uo2OPkP8HVG27BOwmO9qDVd NYVg== X-Gm-Message-State: AC+VfDx5zhelWQM4+zYHXbfmRsMwCgz2g8VAh9bFFvV7PQiXzCDBAqH1 YdGQOOiXelx79IBqSk4QNX8fJw== X-Google-Smtp-Source: ACHHUZ603z9H8OtSYWb6yIGLzp/Ga9jhQuM8brwGaW8VTNVViaeVg6jKtmAsZInMKeolXh+r6WFOMw== X-Received: by 2002:a05:620a:8e13:b0:767:1b8e:811e with SMTP id re19-20020a05620a8e1300b007671b8e811emr6686684qkn.17.1688315539761; Sun, 02 Jul 2023 09:32:19 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id k28-20020a05620a143c00b00767660afed5sm708210qkj.99.2023.07.02.09.32.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:32:19 -0700 (PDT) From: Ben Boeckel To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v7 1/4] spec: add a spec function to join arguments Date: Sun, 2 Jul 2023 12:32:08 -0400 Message-Id: <20230702163211.3396210-2-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230702163211.3396210-1-ben.boeckel@kitware.com> References: <20230702163211.3396210-1-ben.boeckel@kitware.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: When passing `-o` flags to other options, the typical `-o foo` spelling leaves a leading whitespace when replacing elsewhere. This ends up creating flags spelled as `-some-option-with-arg= foo.ext` which doesn't parse properly. When attempting to make a spec function to just remove the leading whitespace, the argument splitting ends up masking the whitespace. However, the intended extension *also* ends up being its own argument. To perform the desired behavior, the arguments need to be concatenated together. gcc/: * gcc.cc (join_spec_func): Add a spec function to join all arguments. Signed-off-by: Ben Boeckel --- gcc/gcc.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index fdfac0b4fe4..44433b80d61 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -447,6 +447,7 @@ static const char *greater_than_spec_func (int, const char **); static const char *debug_level_greater_than_spec_func (int, const char **); static const char *dwarf_version_greater_than_spec_func (int, const char **); static const char *find_fortran_preinclude_file (int, const char **); +static const char *join_spec_func (int, const char **); static char *convert_white_space (char *); static char *quote_spec (char *); static char *quote_spec_arg (char *); @@ -1772,6 +1773,7 @@ static const struct spec_function static_spec_functions[] = { "debug-level-gt", debug_level_greater_than_spec_func }, { "dwarf-version-gt", dwarf_version_greater_than_spec_func }, { "fortran-preinclude-file", find_fortran_preinclude_file}, + { "join", join_spec_func}, #ifdef EXTRA_SPEC_FUNCTIONS EXTRA_SPEC_FUNCTIONS #endif @@ -10975,6 +10977,19 @@ find_fortran_preinclude_file (int argc, const char **argv) return result; } +/* The function takes any number of arguments and joins them together. */ + +static const char * +join_spec_func (int argc, const char **argv) +{ + char *result = NULL; + + for (int i = 0; i < argc; ++i) + result = reconcat(result, result ? result : "", argv[i], NULL); + + return result; +} + /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string so as to precede every one of them with a backslash. Return the original string or the reallocated one. */ -- 2.40.1