diff options
Diffstat (limited to 'pc/awklib')
-rw-r--r-- | pc/awklib/igawk | 85 | ||||
-rw-r--r-- | pc/awklib/igawk.awk | 51 | ||||
-rw-r--r-- | pc/awklib/igawk.bat | 1 |
3 files changed, 137 insertions, 0 deletions
diff --git a/pc/awklib/igawk b/pc/awklib/igawk new file mode 100644 index 00000000..7c599dca --- /dev/null +++ b/pc/awklib/igawk @@ -0,0 +1,85 @@ +#! /bin/sh + +# igawk --- like gawk but do @include processing +# Arnold Robbins, arnold@gnu.ai.mit.edu, Public Domain +# July 1993 + +igs=${TMP:-/tmp}/igs$$ +ige=${TMP:-/tmp}/ige$$ + +if [ "$1" = debug ] +then + set -x + shift +else + # cleanup on exit, hangup, interrupt, quit, termination + #trap 'rm -f $igs $ige' 0 1 2 3 15 + trap 'rm -f $igs $ige' 0 2 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" >> $igs + shift;; + + -f*) f=`echo "$1" | sed 's/-f//'` + echo @include "$f" >> $igs ;; + + -?file=*) # -Wfile or --file + f=`echo "$1" | sed 's/-.file=//'` + echo @include "$f" >> $igs ;; + + -?file) # get arg, $2 + echo @include "$2" >> $igs + shift;; + + -?source=*) # -Wsource or --source + t=`echo "$1" | sed 's/-.source=//'` + echo "$t" >> $igs ;; + + -?source) # get arg, $2 + echo "$2" >> $igs + shift;; + + -?version) + echo igawk: version 1.0 1>&2 + gawk --version + exit 0 ;; + + -[W-]*) opts="$opts '$1'" ;; + + *) break;; + esac + + shift +done + +if [ ! -s $igs ] +then + if [ -z "$1" ] + then + echo igawk: no program! 1>&2 + exit 1 + else + echo "$1" > $igs + shift + fi +fi + +# at this point, $igs has the program +gawk -f igawk.awk $igs > $ige +eval gawk -f '$ige' $opts -- "$@" + +exit $? diff --git a/pc/awklib/igawk.awk b/pc/awklib/igawk.awk new file mode 100644 index 00000000..dc0ba405 --- /dev/null +++ b/pc/awklib/igawk.awk @@ -0,0 +1,51 @@ +# igawk.awk +# 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]) + } +} diff --git a/pc/awklib/igawk.bat b/pc/awklib/igawk.bat new file mode 100644 index 00000000..bfc9b2a3 --- /dev/null +++ b/pc/awklib/igawk.bat @@ -0,0 +1 @@ +@sh igawk %1 %2 %3 %4 %5 %6 %7 %8 %9
\ No newline at end of file |