about summary refs log tree commit diff stats
path: root/shin.awk
diff options
context:
space:
mode:
authorCase Duckworth2023-03-15 14:24:10 -0500
committerCase Duckworth2023-03-15 14:24:10 -0500
commit3319d70e4e8fd89fe6140e95504a718717bd4e80 (patch)
tree33e9de59e234ae64141e11a8733c1323b1ad21ab /shin.awk
parentAdd shin.sh (sh library; acts a little differently to shin.awk/shin) (diff)
downloadshin-main.tar.gz
shin-main.zip
Rewrite with sh HEAD main
Diffstat (limited to 'shin.awk')
-rwxr-xr-xshin.awk60
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
6BEGIN {
7 if (ENVIRON["SHINPATH"]) {
8 split(ENVIRON["SHINPATH"], SHINPATH, ":")
9 } else {
10 SHINPATH[1] = "."
11 }
12}
13
14FNR == 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
34function 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
53function 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}