| ... | ... |
@@ -147,6 +147,21 @@ $option = $value |
| 147 | 147 |
$xtrace |
| 148 | 148 |
} |
| 149 | 149 |
|
| 150 |
+function inidelete {
|
|
| 151 |
+ local xtrace=$(set +o | grep xtrace) |
|
| 152 |
+ set +o xtrace |
|
| 153 |
+ local file=$1 |
|
| 154 |
+ local section=$2 |
|
| 155 |
+ local option=$3 |
|
| 156 |
+ |
|
| 157 |
+ [[ -z $section || -z $option ]] && return |
|
| 158 |
+ |
|
| 159 |
+ # Remove old values |
|
| 160 |
+ sed -i -e "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ d; }" "$file"
|
|
| 161 |
+ |
|
| 162 |
+ $xtrace |
|
| 163 |
+} |
|
| 164 |
+ |
|
| 150 | 165 |
# Set an option in an INI file |
| 151 | 166 |
# iniset config-file section option value |
| 152 | 167 |
function iniset {
|
| ... | ... |
@@ -144,6 +144,7 @@ function merge_config_file {
|
| 144 | 144 |
else {
|
| 145 | 145 |
# For multiline, invoke the ini routines in the reverse order |
| 146 | 146 |
count = cfg_attr_count[section, attr] |
| 147 |
+ print "inidelete " configfile " " section " " attr |
|
| 147 | 148 |
print "iniset " configfile " " section " " attr " \"" cfg_attr[section, attr, count - 1] "\"" |
| 148 | 149 |
for (l = count -2; l >= 0; l--) |
| 149 | 150 |
print "iniadd_literal " configfile " " section " " attr " \"" cfg_attr[section, attr, l] "\"" |
| ... | ... |
@@ -34,6 +34,32 @@ empty = |
| 34 | 34 |
[eee] |
| 35 | 35 |
multi = foo1 |
| 36 | 36 |
multi = foo2 |
| 37 |
+ |
|
| 38 |
+# inidelete(a) |
|
| 39 |
+[del_separate_options] |
|
| 40 |
+a=b |
|
| 41 |
+b=c |
|
| 42 |
+ |
|
| 43 |
+# inidelete(a) |
|
| 44 |
+[del_same_option] |
|
| 45 |
+a=b |
|
| 46 |
+a=c |
|
| 47 |
+ |
|
| 48 |
+# inidelete(a) |
|
| 49 |
+[del_missing_option] |
|
| 50 |
+b=c |
|
| 51 |
+ |
|
| 52 |
+# inidelete(a) |
|
| 53 |
+[del_missing_option_multi] |
|
| 54 |
+b=c |
|
| 55 |
+b=d |
|
| 56 |
+ |
|
| 57 |
+# inidelete(a) |
|
| 58 |
+[del_no_options] |
|
| 59 |
+ |
|
| 60 |
+# inidelete(a) |
|
| 61 |
+# no section - del_no_section |
|
| 62 |
+ |
|
| 37 | 63 |
EOF |
| 38 | 64 |
|
| 39 | 65 |
# Test with missing arguments |
| ... | ... |
@@ -237,4 +263,33 @@ else |
| 237 | 237 |
echo "iniadd with non-exsting failed: $VAL" |
| 238 | 238 |
fi |
| 239 | 239 |
|
| 240 |
+# Test inidelete |
|
| 241 |
+del_cases=" |
|
| 242 |
+ del_separate_options |
|
| 243 |
+ del_same_option |
|
| 244 |
+ del_missing_option |
|
| 245 |
+ del_missing_option_multi |
|
| 246 |
+ del_no_options |
|
| 247 |
+ del_no_section" |
|
| 248 |
+ |
|
| 249 |
+for x in $del_cases; do |
|
| 250 |
+ inidelete test.ini $x a |
|
| 251 |
+ VAL=$(iniget_multiline test.ini $x a) |
|
| 252 |
+ if [ -z "$VAL" ]; then |
|
| 253 |
+ echo "OK: inidelete $x" |
|
| 254 |
+ else |
|
| 255 |
+ echo "inidelete $x failed: $VAL" |
|
| 256 |
+ fi |
|
| 257 |
+ if [ "$x" = "del_separate_options" -o \ |
|
| 258 |
+ "$x" = "del_missing_option" -o \ |
|
| 259 |
+ "$x" = "del_missing_option_multi" ]; then |
|
| 260 |
+ VAL=$(iniget_multiline test.ini $x b) |
|
| 261 |
+ if [ "$VAL" = "c" -o "$VAL" = "c d" ]; then |
|
| 262 |
+ echo "OK: inidelete other_options $x" |
|
| 263 |
+ else |
|
| 264 |
+ echo "inidelete other_option $x failed: $VAL" |
|
| 265 |
+ fi |
|
| 266 |
+ fi |
|
| 267 |
+done |
|
| 268 |
+ |
|
| 240 | 269 |
rm test.ini |