summaryrefslogtreecommitdiffstats
path: root/scripts/awink
blob: 1456c8ba8b0fd59cf28e6805f66a3451d6dc69df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env bash

##
# arguments:
#  $1    In file
#  $2    Out file
build() {
	gawk '{
		if (NF == 2 && $1 == "%include") {
			while ((getline line < $2) > 0) {
				print line;
			}
			close($2);
		} else {
			print;
		}
	}' "$1" > "$2"
}

main() {
	if [[ "$#" != 2 ]]; then
		printf "%s\n" "awink <in file> <out file>"
		exit 2
	fi

	build "$1" "$2"
}
main "$@"