File: rwarray.awk

package info (click to toggle)
gawk 1%3A4.1.4%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 16,836 kB
  • ctags: 5,783
  • sloc: ansic: 48,799; awk: 11,167; yacc: 5,939; sh: 5,579; makefile: 2,554; sed: 121
file content (40 lines) | stat: -rw-r--r-- 951 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
@load "rwarray"

BEGIN {
	while ((getline word) > 0)
		dict[word] = word word

	n = asorti(dict, dictindices)
	for (i = 1; i <= n; i++)
		printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]]) > "orig.out"
	close("orig.out");

	ret = writea("orig.bin", dict)
	printf "writea() returned %d, expecting 1\n", ret

 
	ret = reada("orig.bin", dict)
	printf "reada() returned %d, expecting 1\n", ret

	n = asorti(dict, dictindices)
	for (i = 1; i <= n; i++)
		printf("dict[%s] = %s\n", dictindices[i], dict[dictindices[i]]) > "new.out"
	close("new.out");

	os = ""
	if (ENVIRON["AWKLIBPATH"] == "sys$disk:[-]") {
		os = "VMS"
		# return status from system() on VMS can not be used here
	}
	if (os != "VMS") {
		ret = system("cmp orig.out new.out")

		if (ret == 0)
			print "old and new are equal - GOOD"
		else
			print "old and new are not equal - BAD"

		if (ret == 0 && !("KEEPIT" in ENVIRON))
			system("rm -f orig.bin orig.out new.out")
	}
}