From patchwork Sat Nov 20 15:20:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1557617 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Oxsuo/6J; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HxHKN4tklz9sS8 for ; Sun, 21 Nov 2021 02:20:24 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D1BD482F5A; Sat, 20 Nov 2021 16:20:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Oxsuo/6J"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5431283007; Sat, 20 Nov 2021 16:20:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd2e.google.com (mail-io1-xd2e.google.com [IPv6:2607:f8b0:4864:20::d2e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A118382F5A for ; Sat, 20 Nov 2021 16:20:11 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2e.google.com with SMTP id v23so16897914iom.12 for ; Sat, 20 Nov 2021 07:20:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J9IsBMlJw9ao+/XNrpNhUtBp1e+RJvNS9/rLMaANLnc=; b=Oxsuo/6JOB9Wqb/kn4txQK7jAtSa5uaApC8N6FLA1yVI3tTbCuoGNSKPtHPWflCU5X Ni3bYmNzLdaN5xhV0ocOje1RTS6xH0n1SuD/vKIUxbFzwvgaSdqot+nXEArc7j0mjU86 EnipzMXQIQfmhzV491z0ZNHadxNMCyVrE+KQA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=J9IsBMlJw9ao+/XNrpNhUtBp1e+RJvNS9/rLMaANLnc=; b=vPoLXwzl5ZavCDUSwfuDsPLnx6Dsq13k2GgufyAy6EeAOrloZoBKpvpDr6x7Z3NPYE 7E+jW1bTyeon0fGGZwP7awEYv4t2q4dJWXX2ilQQwEu5qi94rUIUvdDZT4JfCUfsiOQf 8JYxGHovOVYaFHUZ/N0pnJU6C24YyQ3CT6++B1l3GZpDVrE+RepcbDr2hqjyRRFU+8vK aeHhPt1x9PvT+4CeWD7V2oMWH5CBlLxIs0Bo5kR1fVPZdJbqg25YcnGvZxxnMxMH81mm r5JuyR0iQnWDGUZ5yfRmZbbSqfggQHiFe3Sb6LZ5gAPgeIzAhOKAMevXH1OGmw920fG3 rQpA== X-Gm-Message-State: AOAM5312rFdZEd8YG1pv/FoD5HghxgsB1MNPswoEOrTQgZkp7cA4OK4t thAFvk3xpZdoaUXtJej04V0QFkogyUuQUg== X-Google-Smtp-Source: ABdhPJw9zM9hnb7CgokwAftAY4keRWs29erJqYtDwhm0YdVBoGGxDrIl+Ksbb+91M8UngZilZs2/3Q== X-Received: by 2002:a05:6638:2103:: with SMTP id n3mr35034727jaj.25.1637421609571; Sat, 20 Nov 2021 07:20:09 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id r14sm2297164iov.14.2021.11.20.07.20.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Nov 2021 07:20:09 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Joe Hershberger , Wolfgang Denk Subject: [PATCH v2] env: Avoid using GNU features in awk Date: Sat, 20 Nov 2021 08:20:05 -0700 Message-Id: <20211120081955.v2.1.Ic6fae5a5f882f8c5476e8b4b34650028419cbcde@changeid> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.37 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean GNU has a very useful third argument to match() but this is not supported in the POSIX awk. It is a great shame. Update the code to cope. Signed-off-by: Simon Glass --- Changes in v2: - Fix the has_var match() that had left-over test code scripts/env2string.awk | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/scripts/env2string.awk b/scripts/env2string.awk index 57d0fc8f3ba..e758738df07 100644 --- a/scripts/env2string.awk +++ b/scripts/env2string.awk @@ -24,26 +24,33 @@ NF { # Quote quotes gsub("\"", "\\\"") + # Avoid using the non-POSIX third parameter to match() which is very + # inconvenient + has_var = match($0, "^([^ \t=][^ =]*)=(.*)$") + # Is this the start of a new environment variable? - if (match($0, "^([^ \t=][^ =]*)=(.*)$", arr)) { + if (has_var) { if (length(env) != 0) { # Record the value of the variable now completed vars[var] = env } - var = arr[1] - env = arr[2] + + # Collect the variable name. The value follows the '=' + match($0, "^([^ \t=][^ =]*)=") + var = substr($0, 1, RLENGTH - 1) + env = substr($0, RLENGTH + 1) # Deal with += which concatenates the new string to the existing - # variable - if (length(env) != 0 && match(var, "^(.*)[+]$", var_arr)) - { + # variable. Again we are careful to use POSIX match() + if (length(env) != 0 && match(var, "^(.*)[+]$")) { + plusname = substr(var, RSTART, RLENGTH - 1) # Allow var\+=val to indicate that the variable name is # var+ and this is not actually a concatenation - if (substr(var_arr[1], length(var_arr[1])) == "\\") { + if (substr(plusname, length(plusname)) == "\\") { # Drop the backslash sub(/\\[+]$/, "+", var) } else { - var = var_arr[1] + var = plusname env = vars[var] env } }