From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by sourceware.org (Postfix) with ESMTPS id 684113858418 for ; Sun, 2 Jul 2023 16:32:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 684113858418 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-x72f.google.com with SMTP id af79cd13be357-7659cb9c42aso313316185a.3 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=I7kslJKc3dbcpDsZYUoUSQy18xwUgamzpVh/yjmv1+Ao4sygp+3UHJLTOlvfjKHXAD EUi4Sy4XgBjU65SLHtsbmoRRnexZacvNgeE7F/HICLud3JRCF+6iwpoDIf0ksfiddC4o fVO0UmKF+3OGt5y9HnUWQQOXE4v9oDcJ7D2oFB/nOfPVbG3+u/yR7lcl4FAiUN+e7Cig jhTbi4ETRnxbjjAHaXhNpj7trNvwx8G9VTVy41L4fZR6RyyWegd1bIBuoWau4hHJKJGs qt5wsX0yearqNqQX8AW3Rk2Xh1rcUiFkc7iOWm5Wdx6Llje5koM90OUgD0bkz+LwzE5N NBPA== X-Gm-Message-State: AC+VfDx8Y9ok1J0UarL8CFwUYNLXzDD5zHrO5sB3EGBTwOCt3zKtwD4T q+YncqcgKKBOqAkeU39A76hNVTTqILoBCVakJArWQg== 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=-11.0 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=ham 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