From 837d2a8ad902052d20e2729e7e505d95a593f3b8 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 05 Jan 2019 10:53:01 -0500 Subject: ob_parse_control(): Pass field name and value as args --- (limited to 'lib/control.sh') diff --git a/lib/control.sh b/lib/control.sh index bf3e8fb..da48313 100644 --- a/lib/control.sh +++ b/lib/control.sh @@ -1,6 +1,6 @@ # Functions for parsing control files # -# Copyright (C) 2012, 2018 Patrick McDermott +# Copyright (C) 2012, 2018, 2019 Patrick McDermott # # This file is part of opkbuild. # @@ -19,9 +19,6 @@ _OB_SUBSTVARS_MAX_DEPTH=50 -OB_CONTROL_NAME= -OB_CONTROL_VALUE= - _ob_parse_control_error() { local file= @@ -54,9 +51,8 @@ _ob_parse_control_error() ## @brief Parse a control file ## @details \fBob_parse_control\fP parses a control file of field names and ## values formatted like RFC 822 (or RFC 2822 or RFC 5322) headers. -## For each field, \fBob_parse_control\fP calls \fIfield_cb\fP after -## setting \fIOB_CONTROL_NAME\fP to the field name and -## \fIOB_CONTROL_VALUE\fP to the field value. If \fIreq_fields\fP and +## For each field, \fBob_parse_control\fP calls \fIfield_cb\fP with the +## field name and value as arguments. If \fIreq_fields\fP and ## \fIopt_fields\fP are given, \fBob_parse_control\fP verifies that the ## input control file contains all fields listed in \fIreq_fields\fP ## and no fields that are listed in neither \fIreq_fields\fP nor @@ -70,10 +66,9 @@ _ob_parse_control_error() ## @return Returns 0 after parsing, or 125 if called with an incorrect number of ## arguments. ## @stderr Prints error messages on parse errors. -## @pure maybe This function sets global variables, but they're only intended -## for use by \fIfield_cb\fP, which is called during the lifetime of -## this function. Whether this function is subshell-safe in -## practice depends on whether \fIfield_cb\fP is subshell-safe. +## @pure maybe This function has no side effects. Whether this function is +## subshell-safe in practice depends on whether \fIfield_cb\fP is +## subshell-safe. ob_parse_control() { local file= @@ -118,9 +113,7 @@ ob_parse_control() ;; [!\ ]*':'*) # "Name: Value" line. if [ -n "${name}" ]; then - OB_CONTROL_NAME="${name}" - OB_CONTROL_VALUE="${value}" - "${field_cb}" + "${field_cb}" "${name}" "${value}" if [ ${?} -ne 0 ]; then return 0 fi @@ -172,9 +165,7 @@ ${line# }" EOF if [ -n "${name}" ]; then - OB_CONTROL_NAME="${name}" - OB_CONTROL_VALUE="${value}" - "${field_cb}" + "${field_cb}" "${name}" "${value}" if [ ${?} -ne 0 ]; then return 0 fi -- cgit v0.9.1