From patchwork Sat Nov 20 15:45:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1557618 X-Patchwork-Delegate: sjg@chromium.org 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=jcI82lf1; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (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 4HxHtt3txLz9s1l for ; Sun, 21 Nov 2021 02:45:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2253F82A68; Sat, 20 Nov 2021 16:45:46 +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="jcI82lf1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 643B2812BB; Sat, 20 Nov 2021 16:45:43 +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=unavailable autolearn_force=no version=3.4.2 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) (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 AAE6782B68 for ; Sat, 20 Nov 2021 16:45:39 +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-ot1-x32d.google.com with SMTP id b5-20020a9d60c5000000b0055c6349ff22so21555556otk.13 for ; Sat, 20 Nov 2021 07:45:39 -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=xudIPQEioX4R5vf8QbotBOyBQZBSgynOGKeSBOs8dUs=; b=jcI82lf1PhP4f6ZTxkVz5/5LiRonuhim/r10hLR/kpJdV9M+8rba9LgtNYk/iQc09p CHU+yKescdhFUX2bkR/3VlBNW9zzXj6bWm2eVij+rSaoN/zULKSKSbpzVsxstzdHhNEt Rlhyilf+fVSaRCqByp9U/taHUNhN8RTPFDIbo= 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=xudIPQEioX4R5vf8QbotBOyBQZBSgynOGKeSBOs8dUs=; b=EyZeStawJH/ECPE/j0669q/ceYDe0tPOGU2U+DYOTIpDz09A6ThgsZY7EFa47Mkh2r AyFhM/w60q8hW6gmM08AMurC6McUCBJD07nzc+EcbSh1nUl9ngPgDErvQRyLf5yo5Nr4 H+/RPPCe4+DqgZ7E2HMLLzX3cK5LyN05FRN/44amUZkUoC24iQMXbf+M4DQhw1KQz7xx iAYsJZ+S6ZMC1b3qW1SfyK9+sS7fhnYgNybj8ckuCgY504S0HmiyUFZt/jYXkLbZtnmr sq1uWU1+FtvEBTyssPcXYtjYJLjlsPrGp5stxxjl7PFF+c3lRtw/vjuBPibCFg4XQS3f EemA== X-Gm-Message-State: AOAM533Fl4m8Nvlj23ubIgaVun16sxlFniP99xbpCWXBe0AkxI/7ZYQz HF8haFfFW6NHNwidV7xQD3vpEZnuxWcohw== X-Google-Smtp-Source: ABdhPJyZa06s6KK/oOogGhtxiSl5pNQgVz0cFJ7J8KqlSNZFTHt6m0Vx/rdbSubmw21VkBSFopxZoA== X-Received: by 2002:a9d:2aa3:: with SMTP id e32mr3689447otb.6.1637423137802; Sat, 20 Nov 2021 07:45:37 -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 w2sm584032ooa.26.2021.11.20.07.45.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Nov 2021 07:45:37 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , Simon Glass , Joe Hershberger , Wolfgang Denk Subject: [PATCH v3] env: Avoid using GNU features in awk Date: Sat, 20 Nov 2021 08:45:34 -0700 Message-Id: <20211120084514.v3.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. Update the code to cope, so that the script is POSIX-compliant. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- Changes in v3: - Reword commit message and comment to avoid casting aspersions 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..e71c46dfb46 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(), by splitting + # the work into several steps. + 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 } }