Only output a section array declaration if there's some elements being defined too.
This commit is contained in:
parent
e0af3a5da0
commit
1255adfdbf
1 changed files with 16 additions and 9 deletions
25
parse_ini
25
parse_ini
|
|
@ -259,7 +259,7 @@ parse_ini() {
|
||||||
local VARIABLE_DELIM="_" # Delimiter between prefix and section name, unless VARIABLE_PREFIX is empty.
|
local VARIABLE_DELIM="_" # Delimiter between prefix and section name, unless VARIABLE_PREFIX is empty.
|
||||||
|
|
||||||
# Variables.
|
# Variables.
|
||||||
local BOOL_VALUE DELIM IGNORE_SECTION=0 INIFD KEY LINE LINENUMBER=0 PREFIX SECTIONS_SEEN=() TEMP VALUE
|
local BOOL_VALUE DELIM IGNORE_SECTION=0 INIFD KEY LINE LINENUMBER=0 PREFIX SECTIONS_SEEN=() SHOWN_SEC_HEAD=0 TEMP VALUE
|
||||||
declare INIFILE
|
declare INIFILE
|
||||||
|
|
||||||
# Parse options.
|
# Parse options.
|
||||||
|
|
@ -316,10 +316,6 @@ parse_ini() {
|
||||||
DELIM="$VARIABLE_DELIM"
|
DELIM="$VARIABLE_DELIM"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Output the 'global' section definition.
|
|
||||||
# FIXME: If doing validation only, don't output declaration here.
|
|
||||||
printf "declare %s -A %s%s%s\\n" "$DECLARE_SCOPE" "$PREFIX" "$DELIM" "$CURRENT_SECTION"
|
|
||||||
|
|
||||||
# Parse the INI file.
|
# Parse the INI file.
|
||||||
while :; do
|
while :; do
|
||||||
LINE=""
|
LINE=""
|
||||||
|
|
@ -406,9 +402,8 @@ parse_ini() {
|
||||||
# Reset the ignore flag.
|
# Reset the ignore flag.
|
||||||
IGNORE_SECTION=0
|
IGNORE_SECTION=0
|
||||||
|
|
||||||
# Output the associative array declaration.
|
# Flag that the section header needs to be shown.
|
||||||
# FIXME: If doing validation only, don't output declaration here.
|
SHOWN_SEC_HEAD=0
|
||||||
printf "declare %s -A %s%s%s\\n" "$DECLARE_SCOPE" "$PREFIX" "$DELIM" "$CURRENT_SECTION"
|
|
||||||
fi
|
fi
|
||||||
elif ((IGNORE_SECTION == 0)) && [[ "$LINE" != *$KEYVALUE_DELIM* ]]; then # Process the property definition as if it's a boolean.
|
elif ((IGNORE_SECTION == 0)) && [[ "$LINE" != *$KEYVALUE_DELIM* ]]; then # Process the property definition as if it's a boolean.
|
||||||
# If the value starts with a " or ' it must end with same.
|
# If the value starts with a " or ' it must end with same.
|
||||||
|
|
@ -439,8 +434,13 @@ parse_ini() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Output the associative array element definition.
|
# Output the associative array element definition.
|
||||||
# FIXME: If doing validation only, don't output declaration here.
|
# FIXME: If doing validation only, don't output declarations here.
|
||||||
if ((USE_BOOLEANS == 1)); then
|
if ((USE_BOOLEANS == 1)); then
|
||||||
|
# If required, output the associative array declaration.
|
||||||
|
if ((SHOWN_SEC_HEAD == 0)); then
|
||||||
|
printf "declare %s -A %s%s%s\\n" "$DECLARE_SCOPE" "$PREFIX" "$DELIM" "$CURRENT_SECTION"
|
||||||
|
SHOWN_SEC_HEAD=1
|
||||||
|
fi
|
||||||
printf "%s%s%s[\"%s\"]=\"%s\"\\n" "$PREFIX" "${PREFIX:+$DELIM}" "$CURRENT_SECTION" "$LINE" "$BOOL_VALUE"
|
printf "%s%s%s[\"%s\"]=\"%s\"\\n" "$PREFIX" "${PREFIX:+$DELIM}" "$CURRENT_SECTION" "$LINE" "$BOOL_VALUE"
|
||||||
else
|
else
|
||||||
echo "${0##*/}: line $LINENUMBER: key without a value - skipping property" >&2
|
echo "${0##*/}: line $LINENUMBER: key without a value - skipping property" >&2
|
||||||
|
|
@ -471,6 +471,13 @@ parse_ini() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If required, output the associative array declaration.
|
||||||
|
# FIXME: If doing validation only, don't output declaration here.
|
||||||
|
if ((SHOWN_SEC_HEAD == 0)); then
|
||||||
|
printf "declare %s -A %s%s%s\\n" "$DECLARE_SCOPE" "$PREFIX" "$DELIM" "$CURRENT_SECTION"
|
||||||
|
SHOWN_SEC_HEAD=1
|
||||||
|
fi
|
||||||
|
|
||||||
# Output the associative array element definition.
|
# Output the associative array element definition.
|
||||||
# FIXME: If doing validation only, don't output declaration here.
|
# FIXME: If doing validation only, don't output declaration here.
|
||||||
if ((DUPLICATES_MERGE == 0)); then
|
if ((DUPLICATES_MERGE == 0)); then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue