]> gitweb.hhaalo.de Git - scantopdf.git/commitdiff
add includer
authorBastian Dehn <hhaalo@arcor.de>
Thu, 2 Apr 2026 15:07:21 +0000 (17:07 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 2 Apr 2026 15:07:21 +0000 (17:07 +0200)
tools/includer [new file with mode: 0755]

diff --git a/tools/includer b/tools/includer
new file mode 100755 (executable)
index 0000000..1efbafa
--- /dev/null
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+main()
+{
+       local file="$1"
+       local dir=$(dirname "$file")
+       local regex="^#include \"\(.*\)\"$"
+
+       local include_files=$(cat "$file" \
+               | grep --only-matching "$regex" \
+               | sed "s/$regex/\1/")
+
+       local include_file=
+       local out=$(cat $file)
+       for include_file in $include_files; do
+               local include_regex="#include \"$include_file\""
+               out=$(echo "$out" \
+                       | sed "/$include_regex/r $dir/$include_file" \
+                       | sed "/$include_regex/d")
+       done
+
+       echo "$out"
+}
+
+main $*
\ No newline at end of file