The awk script
$1 == "@include" { ARGV[ARGC++] = $2; print $2 }
should function identically to the more complex script
BEGIN {
input[0] = ARGV[1]
for (s = 0; s >= 0; s--)
{
while ((getline < input[s]) > 0)
{
if ($1 == "@include")
{
input[++s] = $2
$2
}
}
close(input[stackptr])
}
}
except that the output will appear in a different order. However,
when the simple script is in use, mawk does not process any of the
files appended to ARGV.
This idiom may be a gawk-ism -- if so, never mind :)
Test case:
$ ls
one two three four
$ cat one
@include two
@include three
$ cat two
@include four
$ mawk -f ../simple.awk one
two
three
$ mawk -f ../complex.awk one
two
four
three
$
zw
The bug is not where I thought it was. mawk correctly processes the simple script as long as all the files that end up in ARGV exist. If a file in that list /doesn't/ exist, it halts processing at that file with an error message. I had assumed the error was non-fatal. It is sometimes reasonable for a missing file to be a fatal error, but in my case it would be better for the file to be treated as if empty. Perhaps this could be made an option? For reference, gawk behaves exactly the same way, except that the error message it produces clearly states that the error is fatal. zw
gawk, mawk and original-awk all exhibit the same behaviour if you try and include a file that doesnt exist in the first example, you get return code 2 This is because the code is trying to launch a non-existant awk script, in just the same way as if you had typed: awk -f idontexist To fix this feature mawk would need a flag to tell it to ignore and not report missing files... Suerly it would make more sense to check the file exited beforehand? suggest this is tagged wishlist,upstream or wontfix
retitle 23001 mawk: add option to ignore missing files severity 23001 wishlist tags 23001 + upstream thanks Zack Weinberg wrote: Yes, it could be a -W option. Not my itch, but maybe some other interested person could implement it. Hope that helps, Jonathan