Skip to content
Snippets Groups Projects
Commit 89a9d1e9 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

ini class: fix arrays

parent e078010e
No related branches found
No related tags found
1 merge request!129Db Profiles
...@@ -251,6 +251,10 @@ function ini.validate(){ ...@@ -251,6 +251,10 @@ function ini.validate(){
local ERROR="\e[1;31mERROR\e[0m" local ERROR="\e[1;31mERROR\e[0m"
local iErr; typeset -i iErr=0 local iErr; typeset -i iErr=0
if [ ! -f "${myinifile}" ]; then
return 1
fi
if [ ! -f "${myvalidationfile}" ]; then if [ ! -f "${myvalidationfile}" ]; then
echo -e "$ERROR: Validation file '${myvalidationfile}' does not exist." echo -e "$ERROR: Validation file '${myvalidationfile}' does not exist."
return 1 return 1
...@@ -277,11 +281,12 @@ function ini.validate(){ ...@@ -277,11 +281,12 @@ function ini.validate(){
echo -e "$ERROR: unknown section name: [$section]" echo -e "$ERROR: unknown section name: [$section]"
iErr+=1 iErr+=1
else else
test $bShowAll -ne 0 && echo "OK: [$section] ... checking its keys..." test $bShowAll -ne 0 && echo "OK: section [$section] is valid... checking its keys..."
# TODO: verify values # TODO: verify values
for mustkey in $( echo "${varsMust}" | grep "^[/t ]*${section}\." | cut -f 2 -d '.' | cut -f 1 -d ':' ); do for mustkey in $( echo "${varsMust}" | grep "^[/t ]*${section}\." | cut -f 2 -d '.' | cut -f 1 -d ':' ); do
if ini.keys "$myinifile" "$section" | grep "^${mustkey}$"; then keyregex="$( echo $mustkey | sed -e's,\[,\\[,g' )"
if ini.keys "$myinifile" "$section" | grep "^${keyregex}$"; then
test $bShowAll -ne 0 && echo " OK: $section.$mustkey" test $bShowAll -ne 0 && echo " OK: $section.$mustkey"
else else
echo -e " $ERROR: A MUST key '$mustkey' was not found im section [$section]." echo -e " $ERROR: A MUST key '$mustkey' was not found im section [$section]."
...@@ -290,10 +295,12 @@ function ini.validate(){ ...@@ -290,10 +295,12 @@ function ini.validate(){
done done
for mykey in $(ini.keys "$myinifile" "$section"); do for mykey in $(ini.keys "$myinifile" "$section"); do
# we need a regex for keys as array eg "file[] = ..."
keyregex="$( echo "${mykey}" | sed -e's,\[,\\[,g' | sed -e's,\],\\],g' )"
if ! echo " if ! echo "
${varsMust} ${varsMust}
${varsCan} ${varsCan}
" | cut -f 1 -d ':' | grep -q "^[/t ]*${section}\.${mykey}$"; then " | cut -f 1 -d ':' | grep -q "^[/t ]*${section}\.${keyregex}$"; then
echo -e " $ERROR: invald key name: $section.$mykey" echo -e " $ERROR: invald key name: $section.$mykey"
iErr+=1 iErr+=1
else else
...@@ -301,7 +308,7 @@ function ini.validate(){ ...@@ -301,7 +308,7 @@ function ini.validate(){
check=$(echo " check=$(echo "
${varsMust} ${varsMust}
${varsCan} ${varsCan}
" | grep "^[/t ]*${section}\.${mykey}[:$]" | cut -f 2 -d ':' ) " | grep "^[/t ]*${section}\.${keyregex}[:$]" | cut -f 2 -d ':' )
if [ -n "$check" ]; then if [ -n "$check" ]; then
value="$(ini.value "$myinifile" "$section" "$mykey")" value="$(ini.value "$myinifile" "$section" "$mykey")"
if ! grep -Eq "^${check}$" <<< "$value" ; then if ! grep -Eq "^${check}$" <<< "$value" ; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment