You've already forked bash-ini-parser
mirror of
https://github.com/albfan/bash-ini-parser.git
synced 2025-08-06 07:02:37 +03:00
unset function
clear previous definition (if exist) before load it closes #6
This commit is contained in:
@@ -89,7 +89,6 @@ Outputs:
|
|||||||
This is more a hack than a reliable parser, so keep in mind things like
|
This is more a hack than a reliable parser, so keep in mind things like
|
||||||
|
|
||||||
- multiword value vars will be arrays so you must access it as `${var[*]}`
|
- multiword value vars will be arrays so you must access it as `${var[*]}`
|
||||||
- changing from section to section will not erase previous var declarations
|
|
||||||
|
|
||||||
For a trusted parser (but based on python) checkout [crudini](https://github.com/pixelb/crudini)
|
For a trusted parser (but based on python) checkout [crudini](https://github.com/pixelb/crudini)
|
||||||
|
|
||||||
|
@@ -46,6 +46,7 @@ function cfg_parser {
|
|||||||
ini=( ${ini[*]/%\( \)/\(\) \{} ) # convert text2function (2)
|
ini=( ${ini[*]/%\( \)/\(\) \{} ) # convert text2function (2)
|
||||||
debug
|
debug
|
||||||
ini=( ${ini[*]/%\} \)/\}} ) # remove extra parenthesis
|
ini=( ${ini[*]/%\} \)/\}} ) # remove extra parenthesis
|
||||||
|
ini=( ${ini[*]/%\{/\{$'\n''cfg_unset ${FUNCNAME/#'$PREFIX'}'$'\n'} ) # clean previous definition of section
|
||||||
debug
|
debug
|
||||||
ini[0]="" # remove first element
|
ini[0]="" # remove first element
|
||||||
debug
|
debug
|
||||||
@@ -68,6 +69,7 @@ function cfg_writer {
|
|||||||
[ "${f#$PREFIX}" == "${f}" ] && continue
|
[ "${f#$PREFIX}" == "${f}" ] && continue
|
||||||
item="$(declare -f ${f})"
|
item="$(declare -f ${f})"
|
||||||
item="${item##*\{}" # remove function definition
|
item="${item##*\{}" # remove function definition
|
||||||
|
item="${item##*FUNCNAME*$PREFIX\};}" # remove clear section
|
||||||
item="${item/\}}" # remove function close
|
item="${item/\}}" # remove function close
|
||||||
item="${item%)*}" # remove everything after parenthesis
|
item="${item%)*}" # remove everything after parenthesis
|
||||||
item="${item});" # add close parenthesis
|
item="${item});" # add close parenthesis
|
||||||
@@ -94,6 +96,44 @@ function cfg_writer {
|
|||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cfg_unset {
|
||||||
|
SECTION=$1
|
||||||
|
OLDIFS="$IFS"
|
||||||
|
IFS=' '$'\n'
|
||||||
|
if [ -z "$SECTION" ]
|
||||||
|
then
|
||||||
|
fun="$(declare -F)"
|
||||||
|
else
|
||||||
|
fun="$(declare -F $PREFIX$SECTION)"
|
||||||
|
if [ -z "$fun" ]
|
||||||
|
then
|
||||||
|
echo "section $SECTION not found" >2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fun="${fun//declare -f/}"
|
||||||
|
for f in $fun; do
|
||||||
|
[ "${f#$PREFIX}" == "${f}" ] && continue
|
||||||
|
item="$(declare -f ${f})"
|
||||||
|
item="${item##*\{}" # remove function definition
|
||||||
|
item="${item##*FUNCNAME*$PREFIX\};}" # remove clear section
|
||||||
|
item="${item/\}}" # remove function close
|
||||||
|
item="${item%)*}" # remove everything after parenthesis
|
||||||
|
item="${item});" # add close parenthesis
|
||||||
|
vars=""
|
||||||
|
while [ "$item" != "" ]
|
||||||
|
do
|
||||||
|
newvar="${item%%=*}" # get item name
|
||||||
|
vars="$vars $newvar" # add name to collection
|
||||||
|
item="${item#*;}" # remove readed line
|
||||||
|
done
|
||||||
|
for var in $vars; do
|
||||||
|
unset $var
|
||||||
|
done
|
||||||
|
done
|
||||||
|
IFS="$OLDIFS"
|
||||||
|
}
|
||||||
|
|
||||||
function cfg_clear {
|
function cfg_clear {
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=' '$'\n'
|
IFS=' '$'\n'
|
||||||
|
Reference in New Issue
Block a user