From patchwork Wed Oct 29 08:27:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Prindeville X-Patchwork-Id: 2158688 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=qfsWq+8D; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4cxcjH1nl1z1yHt for ; Thu, 30 Oct 2025 06:28:19 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type:List-Help: Reply-To:List-Archive:List-Unsubscribe:List-Subscribe:From:List-Post:List-Id: Message-ID:MIME-Version:Date:Subject:To:Cc:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=d6hUjIr2QOP5oz33w8BOu9/juU8GYKdAX9AQfqwR1EA=; b=qfsWq+8DknsiENqaCQ0LmPydu7 REw4n8/GaZIUg50ibAO/cRp4Hi+COSp1iqEAKwL4rd7hdCQ3+JM3Yl+k7mzhQcOQQ1nc+GHyKxjo4 fjyxbnc74LBKTc4/9NTI5prfj4w/MHGa6i40lbEp8UwExGI85RnMPnT+2dDdwSIZ3dQj4eU0gn00L xd4OJnKL4asMgI370I2PnukaoCDwiBGDkfPO1yuG1UkQs87fh/b+Zqw0vPK+RXhAqQIVF9M+fgPj6 /EoGN8obywhU+rDqZw7ROPLp4fYA771qnMvsoQ1ahOGIdbg07/HEjoNnjnX5y16hTfSByh5lRzLPe zHrM3zwg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vEBpC-00000002aax-3vkT; Wed, 29 Oct 2025 19:27:14 +0000 To: openwrt-devel@lists.openwrt.org Subject: [PATCH v2 1/1] jshn.sh: Add getters for the cursor and its parent Date: Wed, 29 Oct 2025 13:27:11 -0600 MIME-Version: 1.0 Message-ID: List-Id: OpenWrt Development List List-Post: X-Patchwork-Original-From: Philip Prindeville via openwrt-devel From: Philip Prindeville Precedence: list X-Mailman-Version: 2.1.34 X-BeenThere: openwrt-devel@lists.openwrt.org List-Subscribe: , List-Unsubscribe: , List-Archive: Reply-To: Philip Prindeville List-Help: Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The sender domain has a DMARC Reject/Quarantine policy which disallows sending mailing list messages using the original "From" header. To mitigate this problem, the original message has been wrapped automatically by the mailing list software. From: Philip Prindeville The order that JSON is generated might not be linear with respect to the order that UCI is parsed. Therefore, it's useful to have functions to manipulate the cursor within the object being generated. Signed-off-by: Philip Prindeville --- sh/jshn.sh | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/sh/jshn.sh b/sh/jshn.sh index 1d3055711820e5a21ea59cae49e7bf3f56b626d8..5599c85835d0c81c8d47a9dfd73f32e4db2a7c9b 100644 --- a/sh/jshn.sh +++ b/sh/jshn.sh @@ -197,6 +197,42 @@ json_add_fields() { done } +json_get_position() { + local __dest="$1" + eval "export -- \"$__dest=\${JSON_CUR}\"; [ -n \"\${JSON_CUR+x}\" ]" +} + +json_move_to() { + local cur="$1" + _json_set_var JSON_CUR "$cur" +} + +json_get_parent_position() { + local __dest="$1" cur parent + _json_get_var cur JSON_CUR + parent="U_$cur" + eval "export -- \"$__dest=\${$parent}\"; [ -n \"\${$parent+x}\" ]" +} + +json_get_root_position() { + local __dest="$1" cur="J_V" + eval "export -- \"$__dest=\${cur}\"; [ -n \"\${cur+x}\" ]" +} + +json_get_index() { + local __dest="$1" + local cur parent seq + _json_get_var cur JSON_CUR + _json_get_var parent "U_$cur" + if [ "${parent%%[0-9]*}" != "J_A" ]; then + [ -n "$_json_no_warning" ] || \ + echo "WARNING: Not inside an array" >&2 + return 1 + fi + seq="S_$parent" + eval "export -- \"$__dest=\${$seq}\"; [ -n \"\${$seq+x}\" ]" +} + # functions read access to json variables json_compact() {