File: getfile.awk

package info (click to toggle)
gawk 1%3A5.2.1-2
  • links: PTS
  • area: main
  • in suites: bookworm, trixie
  • size: 25,256 kB
  • sloc: ansic: 54,687; awk: 14,521; yacc: 6,814; sh: 6,418; makefile: 3,004; sed: 119; python: 31; csh: 6
file content (35 lines) | stat: -rw-r--r-- 755 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function basename(x) {
	return gensub(/^.*\//, "", 1, x)
}

BEGIN {
	print "BEGIN"

	cmd = "echo hello; echo goodbye"
	rc = get_file(cmd, "<<", -1, res)
	print "expected error result", rc, ERRNO
	print "get_file returned", get_file(cmd, "|<", -1, res)
	print "input_name", basename(res["input_name"])
	print (cmd | getline x)
	print x

	# check that calling get_file on "" triggers the BEGINFILE rule
	print "get_file returned", get_file("", "", -1, res)
	print "input_name", basename(res["input_name"])
	print "end BEGIN"
}

BEGINFILE {
	printf "BEGINFILE (%s) ERRNO (%s)\n", basename(FILENAME), ERRNO
}

ENDFILE {
	printf "ENDFILE (%s) ERRNO (%s)\n", basename(FILENAME), ERRNO
}

END {
	print "END"
	print (cmd | getline x)
	print x
	print close(cmd)
}