|
@@ -8,7 +8,7 @@ __ini_cat() {
|
8
|
8
|
#
|
9
|
9
|
local line # each line
|
10
|
10
|
while read -r line; do
|
11
|
|
- printf -- "%s\n" "$line"
|
|
11
|
+ printf -- '%s\n' "$line"
|
12
|
12
|
done
|
13
|
13
|
}
|
14
|
14
|
|
|
@@ -17,19 +17,58 @@ __ini_expand() {
|
17
|
17
|
# Expand reference value (prefix only)
|
18
|
18
|
#
|
19
|
19
|
local line # each input line
|
20
|
|
- local suffix # tail of the line
|
21
|
|
- local ref # reference
|
22
|
|
- local value # value if reference
|
23
|
20
|
while read -r line; do # [foo:bar]/path
|
24
|
|
- suffix="${line#\[*\]}" # /path
|
25
|
|
- ref="${line%$suffix}" # [foo:bar]
|
26
|
|
- ref="${ref%\]}" # [foo:bar
|
27
|
|
- ref="${ref#\[}" # foo:bar
|
28
|
|
- value="$(ini 1value "$ref")" # foo_bar_value
|
29
|
|
- printf -- "%s\n" "$value$suffix" # foo_bar_value/path
|
|
21
|
+ __ini_expandln "$line"
|
30
|
22
|
done
|
31
|
23
|
}
|
32
|
24
|
|
|
25
|
+__ini_expandln() {
|
|
26
|
+ #
|
|
27
|
+ # Fully expand references in line $1
|
|
28
|
+ #
|
|
29
|
+ local line_orig=$1 # original line
|
|
30
|
+ local line_todo=$line_orig # current state
|
|
31
|
+ local line_done # next state
|
|
32
|
+ local Depth=0 # current depth
|
|
33
|
+ local MaxDepth=10 # maximum depth
|
|
34
|
+ while true; do
|
|
35
|
+ ((Depth++))
|
|
36
|
+ debug_var line_todo
|
|
37
|
+ test "$Depth" -le "$MaxDepth" || {
|
|
38
|
+ warn "expansion error: reached maximum depth: $Depth > $MaxDepth"
|
|
39
|
+ warn " original line: $line_orig"
|
|
40
|
+ warn " expanded line: $line_todo"
|
|
41
|
+ return 3
|
|
42
|
+ }
|
|
43
|
+ line_done=$(__ini_expandln_once "$line_todo")
|
|
44
|
+ debug_var line_done
|
|
45
|
+ test "$line_done" == "$line_todo" && break
|
|
46
|
+ line_todo=$line_done
|
|
47
|
+ done
|
|
48
|
+ echo "$line_done"
|
|
49
|
+}
|
|
50
|
+
|
|
51
|
+__ini_expandln_once() {
|
|
52
|
+ #
|
|
53
|
+ # Run through line $1 once and replace all references
|
|
54
|
+ #
|
|
55
|
+ local line=$1 # line to expand
|
|
56
|
+ local ref # full reference (incl. brackets)
|
|
57
|
+ local ipath # just ini path from ^^ (stripped brackets)
|
|
58
|
+ local value # value of reference
|
|
59
|
+ local refs=() # all references found in line
|
|
60
|
+ mapfile -t refs <<<"$(grep -Eo '[[][^]]+[]]' <<< "$line_todo")"
|
|
61
|
+ debug_var refs
|
|
62
|
+ for ref in "${refs[@]}"; do
|
|
63
|
+ test -n "$ref" || continue
|
|
64
|
+ ipath=${ref#[}; ipath=${ipath%]}
|
|
65
|
+ value=$(ini 1value "$ipath")
|
|
66
|
+ debug_var line ref ipath value
|
|
67
|
+ line=$(sed "s|\\[$ipath\\]|$value|" <<<"$line")
|
|
68
|
+ done
|
|
69
|
+ echo "$line"
|
|
70
|
+}
|
|
71
|
+
|
33
|
72
|
__ini_grepcmt() {
|
34
|
73
|
#
|
35
|
74
|
# Remove comments from INI file on stdin
|
|
@@ -85,7 +124,7 @@ __ini_grepsec() {
|
85
|
124
|
\[*\]) ok=false; continue ;;
|
86
|
125
|
esac
|
87
|
126
|
$ok || continue
|
88
|
|
- printf -- "%s\n" "$line"
|
|
127
|
+ printf -- '%s\n' "$line"
|
89
|
128
|
done \
|
90
|
129
|
| sed -e 's/ *= */=/; s/ +$//; s/^//;'
|
91
|
130
|
}
|
|
@@ -102,7 +141,6 @@ __ini_lssect() {
|
102
|
141
|
#
|
103
|
142
|
# List all section names
|
104
|
143
|
#
|
105
|
|
- local arg=$1 # unused argument
|
106
|
144
|
grep -x '\[.*\]' | sed 's/^.//; s/.$//'
|
107
|
145
|
}
|
108
|
146
|
|