summaryrefslogtreecommitdiff
path: root/awklib/igawk.save
diff options
context:
space:
mode:
Diffstat (limited to 'awklib/igawk.save')
-rwxr-xr-xawklib/igawk.save120
1 files changed, 120 insertions, 0 deletions
diff --git a/awklib/igawk.save b/awklib/igawk.save
new file mode 100755
index 00000000..87412aa8
--- /dev/null
+++ b/awklib/igawk.save
@@ -0,0 +1,120 @@
+#! /bin/sh
+
+# igawk --- like gawk but do @include processing
+# Arnold Robbins, arnold@gnu.ai.mit.edu, Public Domain
+# July 1993
+
+if [ "$1" = debug ]
+then
+ set -x
+ shift
+else
+ # cleanup on exit, hangup, interrupt, quit, termination
+ trap 'rm -f /tmp/ig.[se].$$' 0 1 2 3 15
+fi
+
+while [ $# -ne 0 ] # loop over arguments
+do
+ case $1 in
+ --) shift; break;;
+
+ -W) shift
+ set -- -W"$@"
+ continue;;
+
+ -[vF]) opts="$opts $1 '$2'"
+ shift;;
+
+ -[vF]*) opts="$opts '$1'" ;;
+
+ -f) echo @include "$2" >> /tmp/ig.s.$$
+ shift;;
+
+ -f*) f=`echo "$1" | sed 's/-f//'`
+ echo @include "$f" >> /tmp/ig.s.$$ ;;
+
+ -?file=*) # -Wfile or --file
+ f=`echo "$1" | sed 's/-.file=//'`
+ echo @include "$f" >> /tmp/ig.s.$$ ;;
+
+ -?file) # get arg, $2
+ echo @include "$2" >> /tmp/ig.s.$$
+ shift;;
+
+ -?source=*) # -Wsource or --source
+ t=`echo "$1" | sed 's/-.source=//'`
+ echo "$t" >> /tmp/ig.s.$$ ;;
+
+ -?source) # get arg, $2
+ echo "$2" >> /tmp/ig.s.$$
+ shift;;
+
+ --*) opts="$opts '$1'" ;;
+
+ *) break;;
+ esac
+
+ shift
+done
+
+if [ ! -s /tmp/ig.s.$$ ]
+then
+ echo "$1" > /tmp/ig.s.$$
+ shift
+fi
+
+# at this point, /tmp/ig.s.$$ has the program
+gawk -- '
+# process @include directives
+
+function pathto(file, i, t, junk)
+{
+ if (index(file, "/") != 0)
+ return file
+
+ for (i = 1; i <= ndirs; i++) {
+ t = (pathlist[i] "/" file)
+ if ((getline junk < t) > 0) {
+ # found it
+ close(t)
+ return t
+ }
+ }
+ return ""
+}
+BEGIN {
+ path = ENVIRON["AWKPATH"]
+ ndirs = split(path, pathlist, ":")
+ for (i = 1; i <= ndirs; i++) {
+ if (pathlist[i] == "")
+ pathlist[i] = "."
+ }
+ stackptr = 0
+ input[stackptr] = ARGV[1] # ARGV[1] is first file
+
+ for (; stackptr >= 0; stackptr--) {
+ while ((getline < input[stackptr]) > 0) {
+ if (tolower($1) != "@include") {
+ print
+ continue
+ }
+ fpath = pathto($2)
+ if (fpath == "") {
+ printf("igawk:%s:%d: cannot find %s\n", \
+ input[stackptr], FNR, $2) > "/dev/stderr"
+ continue
+ }
+ if (! (fpath in processed)) {
+ processed[fpath] = input[stackptr]
+ input[++stackptr] = fpath
+ } else
+ print $2, "included in", input[stackptr], \
+ "already included in", \
+ processed[fpath] > "/dev/stderr"
+ }
+ close(input[stackptr])
+ }
+}' /tmp/ig.s.$$ > /tmp/ig.e.$$
+eval gawk -f /tmp/ig.e.$$ $opts -- "$@"
+
+exit $?