Browse Source

Support rudimentary INCLUDE directive

Alois Mahdal 6 years ago
parent
commit
487881eded
1 changed files with 19 additions and 1 deletions
  1. 19
    1
      src/include/ini.sh

+ 19
- 1
src/include/ini.sh View File

112
     fi
112
     fi
113
 }
113
 }
114
 
114
 
115
+__ini_body() {
116
+    #
117
+    # Produce mkit.ini body including INCLUDE
118
+    #
119
+    # Note: recursive includes are not supported.
120
+    #
121
+    local inc                       # file to include
122
+    local incre='\[INCLUDE:.*\]'    # include directive regex
123
+    local iline                     # include directive line
124
+    if iline=$(grep -m1 -x "$incre" "$MKIT_INI"); then
125
+        inc=${iline#*:}; inc=${inc%]}
126
+        grep -vx "$incre" "$inc"
127
+        grep -vx "$incre" "$MKIT_INI"
128
+    else
129
+        cat "$MKIT_INI"
130
+    fi
131
+}
132
+
115
 ini() {
133
 ini() {
116
     #
134
     #
117
     # do ini operation
135
     # do ini operation
128
         1value) fn=__ini_greppath; limit="tail -1" ;;
146
         1value) fn=__ini_greppath; limit="tail -1" ;;
129
         *)      die "incorrect use of \`ini()\`"
147
         *)      die "incorrect use of \`ini()\`"
130
     esac
148
     esac
131
-    <"$MKIT_INI" $fn "$arg" | $limit
149
+    __ini_body | $fn "$arg" | $limit
132
 }
150
 }
133
 
151
 
134
 update_version() {
152
 update_version() {