diff options
Diffstat (limited to 'shin.awk')
-rwxr-xr-x | shin.awk | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/shin.awk b/shin.awk deleted file mode 100755 index 80c76aa..0000000 --- a/shin.awk +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | #!/usr/bin/awk -f | ||
2 | # SHIN: include files in shell scripts | ||
3 | # by Case Duckworth <acdw@acdw.net> | ||
4 | # usage: shin -- FILE.shin... | ||
5 | # each FILE.shin will output to FILE.sh in the same directory | ||
6 | BEGIN { | ||
7 | if (ENVIRON["SHINPATH"]) { | ||
8 | split(ENVIRON["SHINPATH"], SHINPATH, ":") | ||
9 | } else { | ||
10 | SHINPATH[1] = "." | ||
11 | } | ||
12 | } | ||
13 | |||
14 | FNR == 1 { | ||
15 | outfile = FILENAME | ||
16 | sub(/in$/, "", outfile) | ||
17 | } | ||
18 | |||
19 | { | ||
20 | print($0) > outfile | ||
21 | } | ||
22 | |||
23 | /^#</ { | ||
24 | inclfile = shin_resolve(substr($0, 3)) | ||
25 | while (getline l < inclfile) { | ||
26 | print(l) > outfile | ||
27 | } | ||
28 | close(inclfile) | ||
29 | sub(/</, ">", $0) | ||
30 | print > outfile | ||
31 | } | ||
32 | |||
33 | |||
34 | function shin_resolve(filename) | ||
35 | { | ||
36 | if (match(filename, "^/")) { | ||
37 | return shin_test(filename) | ||
38 | } | ||
39 | if (match(filename, "^~")) { | ||
40 | return shin_test(ENVIRON["HOME"] "/" substr(filename, 2)) | ||
41 | } | ||
42 | sub(/^[ \t]*/, "", filename) | ||
43 | sub(/[ \t]*$/, "", filename) | ||
44 | sp = "" | ||
45 | for (p in SHINPATH) { | ||
46 | sp = sp (sp ? ", " : "") "\"" SHINPATH[p] "\"" | ||
47 | f = SHINPATH[p] "/" filename | ||
48 | gsub("//", "/", f) | ||
49 | return shin_test(f) | ||
50 | } | ||
51 | } | ||
52 | |||
53 | function shin_test(filename) | ||
54 | { | ||
55 | if (! system("test -f \"" f "\"")) { | ||
56 | return filename | ||
57 | } | ||
58 | print("Cannot find \"" filename "\" in " sp) > (STDERR ? STDERR : "/dev/stderr") | ||
59 | exit 1 | ||
60 | } | ||