github.com/benhoyt/goawk@v1.8.1/testdata/gawk/hsprint.awk (about) 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 - michal@phys.ualberta.ca 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 44 for (r = 0; r < 12; r += 6) { 45 for (j = 2; j > 0; --j) { 46 for (p = 2; p > 0; --p) { 47 for (s = 2; s > 0; --s) { 48 for (a = 2; a > 0; --a) { 49 for (z = 2; z > 0; --z) { 50 fmt = "%" substr(just,j,1) substr(plus,p,1) \ 51 substr(spc,s,1) substr(alt,a,1) substr(zero,z,1); 52 fstr = sprintf(\ 53 "%6s|%s%s|%s%s|%s%s|%s%s|%s%s|%s%s|\n", 54 "%" fmt, 55 fmt, oper[r], 56 fmt, oper[r+1], 57 fmt, oper[r+2], 58 fmt, oper[r+3], 59 fmt, oper[r+4], 60 fmt, oper[r+5]); 61 printf(fstr, value[r], value[r+1], 62 value[r+2], value[r+3], 63 value[r+4], value[r+5]); 64 } 65 } 66 } 67 } 68 } 69 print ""; 70 } 71 }