Debian Codegraph @

test/getfile.awk

raw
1 function basename(x) {
2 return gensub(/^.*\//, "", 1, x)
3 }
4
5 BEGIN {
6 print "BEGIN"
7
8 cmd = "echo hello; echo goodbye"
9 rc = get_file(cmd, "<<", -1, res)
10 print "expected error result", rc, ERRNO
11 print "get_file returned", get_file(cmd, "|<", -1, res)
12 print "input_name", basename(res["input_name"])
13 print (cmd | getline x)
14 print x
15
16 # check that calling get_file on "" triggers the BEGINFILE rule
17 print "get_file returned", get_file("", "", -1, res)
18 print "input_name", basename(res["input_name"])
19 print "end BEGIN"
20 }
21
22 BEGINFILE {
23 printf "BEGINFILE (%s) ERRNO (%s)\n", basename(FILENAME), ERRNO
24 }
25
26 ENDFILE {
27 printf "ENDFILE (%s) ERRNO (%s)\n", basename(FILENAME), ERRNO
28 }
29
30 END {
31 print "END"
32 print (cmd | getline x)
33 print x
34 print close(cmd)
35 }