diff options
Diffstat (limited to 'pc/awklib/igawk.awk')
-rw-r--r-- | pc/awklib/igawk.awk | 51 |
1 files changed, 51 insertions, 0 deletions
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]) + } +} |