Преглед на файлове

Support rudimentary INCLUDE directive

Alois Mahdal преди 6 години
родител
ревизия
487881eded
променени са 1 файла, в които са добавени 19 реда и са изтрити 1 реда
  1. 19
    1
      src/include/ini.sh

+ 19
- 1
src/include/ini.sh Целия файл

@@ -112,6 +112,24 @@ __ini_maybe_expand() {
112 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 133
 ini() {
116 134
     #
117 135
     # do ini operation
@@ -128,7 +146,7 @@ ini() {
128 146
         1value) fn=__ini_greppath; limit="tail -1" ;;
129 147
         *)      die "incorrect use of \`ini()\`"
130 148
     esac
131
-    <"$MKIT_INI" $fn "$arg" | $limit
149
+    __ini_body | $fn "$arg" | $limit
132 150
 }
133 151
 
134 152
 update_version() {