3 /* linker: atoi.o fdprintf.o */
12 #define VERBOSE(level, statement...) do { if (level <= verbose) { statement; } } while(0)
17 char *progname
= NULL
;
21 char tablechars
[256][4] = {
22 "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "DEL",
23 "DS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
24 "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
25 "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US",
26 "SP", "", "", "", "", "", "", "",
27 "", "", "", "", "", "", "", "",
28 "", "", "", "", "", "", "", "",
29 "", "", "", "", "", "", "", "",
30 "", "", "", "", "", "", "", "",
31 "", "", "", "", "", "", "", "",
32 "", "", "", "", "", "", "", "",
33 "", "", "", "", "", "", "", "",
34 "", "", "", "", "", "", "", "",
35 "", "", "", "", "", "", "", "",
36 "", "", "", "", "", "", "", "",
37 "", "", "", "", "", "", "", "DEL"};
43 int fd
= ret
? stdfderr
: stdfdout
;
44 fdprintf (fd
, "usage: %s\n", progname
);
45 fdprintf (fd
, " -c : number of columns (%d)\n", nbcols
);
46 fdprintf (fd
, " -h : help message\n");
47 fdprintf (fd
, " -v : show version\n");
54 int main (int argc
, char *argv
[])
61 while (progname
[i
] != '\0') {
62 if ((progname
[i
] == '/') || (progname
[i
] == '\\')) {
70 /* argument processing */
73 char *arg
= *(++argv
);
75 PRINTERR ("%s: invalid option -- %s\n", progname
, arg
);
81 arg
= (arg
[2]) ? arg
+ 2 : (--argc
> 0) ? *(++argv
) : NULL
;
83 PRINTERR ("%s: missing number of columns\n", progname
);
89 PRINTOUT ("%s: version %s\n", progname
, VERSION
);
94 return usage (c
!= 'h');
100 int n
= (256 + nbcols
- 1) / nbcols
;
101 for (i
= 0; i
< n
* nbcols
; i
++) {
102 char line
[] = " [ ] x";
103 int j
= i
/ nbcols
+ (i
% nbcols
) * n
;
110 if (j
> 99) line
[0] = '0' + j
/ 100;
111 if (j
> 9) line
[1] = '0' + (j
/ 10) % 10;
112 line
[2] = '0' + j
% 10;
113 line
[4] = '0' + j
/ 16;
114 if (line
[4] > '9') line
[4] += 'a' - '0' - 10;
115 line
[5] = '0' + j
% 16;
116 if (line
[5] > '9') line
[5] += 'a' - '0' - 10;
118 if (tablechars
[j
][0] != '\0') {
120 while (tablechars
[j
][k
] != '\0') {
121 line
[8 + k
] = tablechars
[j
][k
];
127 line
[11] = ((i
+ 1) % nbcols
== 0) ? '\n' : ' ';
129 PRINTOUT ("%s", line
);
135 // test: ascii.exe -h
136 // test: ascii.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
137 // test: ascii.exe -_ 2>/dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
138 // test: ascii.exe error 2>&1 | grep -q 'invalid option'
139 // test: ascii.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
141 // test: ascii.exe | awk '/ 64\[40\] @/ { rc=1 } END { exit (1-rc) }'
142 // test: ascii.exe | awk '/127\[7f\] DEL/ { rc=1 } END { exit (1-rc) }'
143 // test: ascii.exe -v | grep -q version
144 // test: ascii.exe -c 4 | tail -1 | awk '/63/ { rc=1 } END { exit (1-rc) }'
145 // test: ascii.exe -c 5 | tail -1 | awk '/51/ { rc=1 } END { exit (1-rc) }'
146 // test: ascii.exe -c 6 | tail -1 | awk '/42/ { rc=1 } END { exit (1-rc) }'
147 // test: ascii.exe -c 2>&1 | grep -q 'missing number of columns'
149 /* vim: set ts=4 sw=4 et: */