#!/bin/rc
# include [file...] - general include processor.
# replace lines starting "include file" with contents of "file".
# the $0 recursion is a bit subtle.
# requires an awk that invokes rc for system().
exec awk 'BEGIN { me = "'$0'" }
$1 == "include" && NF == 2 {
if ($2 == FILENAME) {
print me ": " $2 " infinite recursion" >"/dev/stderr"
exit 1
}
r = system("if (! test -e " $2 ") exit missing; " me " " $2)
if (r) {
print me ": " $2 " missing" >"/dev/stderr"
exit 1
}
next
}
{ print }' $*
|