Debian Codegraph @

test/hsprint.awk

raw
1 # Test which attempts to repeat examples of formatted output
2 # from "C a reference manual" by Harbison and Steele.
3 #
4 # In the second series of outputs formats of a type "%5%" are skipped
5 # since my old copy of H&S explicitely requires padding ("...%05% will
6 # print 0000%..."), whereas Standard says "...the complete conversion
7 # specification shall be %%".
8 #
9 # Michal Jaegermann - [email protected]
10
11
12 BEGIN {
13 zero = "0"
14 alt = "#"
15 spc = " "
16 plus = "+"
17 just = "-"
18 value[0] = 45
19 value[1] = 45
20 value[2] = 45
21 value[3] = 12.678
22 value[4] = 12.678
23 value[5] = 12.678
24 value[6] = "zap"
25 value[7] = "*"
26 value[8] = -3.4567
27 value[9] = -3.4567
28 value[10]= -3.4567
29 value[11]= -3.4567
30 oper[0] = "5d"
31 oper[1] = "5o"
32 oper[2] = "5x"
33 oper[3] = "7.2f"
34 oper[4] = "10.2e"
35 oper[5] = "10.4g"
36 oper[6] = "5s"
37 oper[7] = "5c"
38 oper[8] = "7.1G"
39 oper[9] = "7.2f"
40 oper[10] = "10.2e"
41 oper[11] = "10.4g"
42
43 header_fmt[0] = "fl\\fmt|%5s|%5s|%5s|%7s|%10s|%10s|\n"
44 header_fmt[1] = "fl\\fmt|%5s|%5s|%7s|%7s|%10s|%10s|\n"
45 header_sep[0] = "------+-----+-----+-----+-------+----------+----------+\n"
46 header_sep[1] = "------+-----+-----+-------+-------+----------+----------+\n"
47
48
49 for (r = 0; r < 12; r += 6) {
50 printf(header_fmt[int(r / 6)],
51 oper[r], oper[r+1], oper[r+2], oper[r+3], oper[r+4], oper[r+5])
52 printf(header_sep[int(r / 6)])
53 for (j = 2; j > 0; --j) {
54 for (p = 2; p > 0; --p) {
55 for (s = 2; s > 0; --s) {
56 for (a = 2; a > 0; --a) {
57 for (z = 2; z > 0; --z) {
58 fmt = "%" substr(just,j,1) substr(plus,p,1) \
59 substr(spc,s,1) substr(alt,a,1) substr(zero,z,1)
60 fstr = sprintf(\
61 "%6s|%s%s|%s%s|%s%s|%s%s|%s%s|%s%s|\n",
62 # "%" fmt,
63 fmt,
64 fmt, oper[r],
65 fmt, oper[r+1],
66 fmt, oper[r+2],
67 fmt, oper[r+3],
68 fmt, oper[r+4],
69 fmt, oper[r+5])
70 # xstr = fstr; sub("\n", " +++\n", xstr)
71 # printf("%s", xstr)
72 printf(fstr, value[r], value[r+1],
73 value[r+2], value[r+3],
74 value[r+4], value[r+5])
75 }
76 }
77 }
78 }
79 }
80 print ""
81 }
82 }