#!/usr/bin/awk -f # SHIN: include files in shell scripts # by Case Duckworth # usage: shin -- FILE.shin... # each FILE.shin will output to FILE.sh in the same directory BEGIN { if (ENVIRON["SHINPATH"]) { split(ENVIRON["SHINPATH"], SHINPATH, ":") } else { SHINPATH[1] = "." } } FNR == 1 { outfile = FILENAME sub(/in$/, "", outfile) } { print($0) > outfile } /^# outfile } close(inclfile) sub(/", $0) print > outfile } function shin_resolve(filename) { if (match(filename, "^/")) { return shin_test(filename) } if (match(filename, "^~")) { return shin_test(ENVIRON["HOME"] "/" substr(filename, 2)) } sub(/^[ \t]*/, "", filename) sub(/[ \t]*$/, "", filename) sp = "" for (p in SHINPATH) { sp = sp (sp ? ", " : "") "\"" SHINPATH[p] "\"" f = SHINPATH[p] "/" filename gsub("//", "/", f) return shin_test(f) } } function shin_test(filename) { if (! system("test -f \"" f "\"")) { return filename } print("Cannot find \"" filename "\" in " sp) > (STDERR ? STDERR : "/dev/stderr") exit 1 }