Consolodate temporary variable usage.

This commit is contained in:
Darren 'Tadgy' Austin 2019-07-20 19:49:52 +01:00
commit e0af3a5da0

View file

@ -259,16 +259,16 @@ 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 ERR IGNORE_SECTION=0 INIFD KEY LINE LINENUMBER=0 PREFIX REPLY SECTION SECTIONS_SEEN=() VALUE local BOOL_VALUE DELIM IGNORE_SECTION=0 INIFD KEY LINE LINENUMBER=0 PREFIX SECTIONS_SEEN=() TEMP VALUE
declare INIFILE declare INIFILE
# Parse options. # Parse options.
parser_getopts "$@" parser_getopts "$@"
ERR=$? TEMP=$?
if ((ERR == 1)); then if ((TEMP == 1)); then
# And error occured. # And error occured.
return 1 return 1
elif ((ERR == 2)); then elif ((TEMP == 2)); then
# Help/version was showed, exit sucessfully. # Help/version was showed, exit sucessfully.
return 0 return 0
fi fi
@ -327,15 +327,15 @@ parse_ini() {
while :; do while :; do
# Read a line of input from the file descriptor. # Read a line of input from the file descriptor.
# The 'read' will do the job of removing leading whitespace from the line. # The 'read' will do the job of removing leading whitespace from the line.
read -r -u "$INIFD" REPLY || break 2 read -r -u "$INIFD" TEMP || break 2
((LINENUMBER++)) ((LINENUMBER++))
# Handle line continuations. # Handle line continuations.
if [[ "${REPLY: -1:1}" == "\\" ]]; then if [[ "${TEMP: -1:1}" == "\\" ]]; then
LINE+="${REPLY:0:-1}" LINE+="${TEMP:0:-1}"
continue continue
else else
LINE+="$REPLY" LINE+="$TEMP"
break break
fi fi
done done
@ -365,6 +365,8 @@ parse_ini() {
# Strip the []s and any whitespace between the []s and the section name. # Strip the []s and any whitespace between the []s and the section name.
LINE="${LINE/#\[*([[:space:]])/}" LINE="${LINE/#\[*([[:space:]])/}"
LINE="${LINE/%*([[:space:]])\]/}" LINE="${LINE/%*([[:space:]])\]/}"
# LINE="${LINE/#*([[:blank:]])\[*([[:blank:]])/}"
# LINE="${LINE/%*([[:blank:]])\]*([[:blank:]])/}"
# Squash multiple consecutive blanks into a single space. # Squash multiple consecutive blanks into a single space.
((SQUASH_SPACES == 1)) && LINE="${LINE//+([[:blank:]])/ }" ((SQUASH_SPACES == 1)) && LINE="${LINE//+([[:blank:]])/ }"
@ -390,8 +392,8 @@ parse_ini() {
# Should we process repeat sections? # Should we process repeat sections?
if ((REPEAT_SECTIONS == 0)); then if ((REPEAT_SECTIONS == 0)); then
for SECTION in "${SECTIONS_SEEN[@]}"; do for TEMP in "${SECTIONS_SEEN[@]}"; do
if [[ "$CURRENT_SECTION" == "$SECTION" ]]; then if [[ "$CURRENT_SECTION" == "$TEMP" ]]; then
# It's a section we've seen before - don't process it. # It's a section we've seen before - don't process it.
echo "${0##*/}: line $LINENUMBER: repeated section name - skipping section" >&2 echo "${0##*/}: line $LINENUMBER: repeated section name - skipping section" >&2
IGNORE_SECTION=1 IGNORE_SECTION=1
@ -437,6 +439,7 @@ 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.
if ((USE_BOOLEANS == 1)); then if ((USE_BOOLEANS == 1)); then
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