13 #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 FILE *fd
= ret
? stderr
: stdout
;
44 fprintf (fd
, "usage: %s\n", progname
);
45 fprintf (fd
, " -c : number of columns (%d)\n", nbcols
);
46 fprintf (fd
, " -h : help message\n");
47 fprintf (fd
, " -v : verbose level (%d)\n", verbose
);
54 int main (int argc
, char *argv
[])
61 while ((c
= getopt(argc
, argv
, "c:hv:")) != EOF
) {
64 nbcols
= atoi (optarg
);
67 verbose
= atoi (optarg
);
74 if (argc
- optind
!= 0) {
75 fprintf (stderr
, "%s: invalid option -- %s\n", progname
, argv
[optind
]);
79 for (i
= 0; i
< 256; i
++) {
80 char line
[] = " : : x";
82 if (i
> 99) line
[0] = '0' + i
/ 100;
83 if (i
> 9) line
[1] = '0' + (i
/ 10) % 10;
84 line
[2] = '0' + i
% 10;
85 line
[4] = '0' + i
/ 16;
86 if (line
[4] > '9') line
[4] += 'a' - '0' - 10;
87 line
[5] = '0' + i
% 16;
88 if (line
[5] > '9') line
[5] += 'a' - '0' - 10;
90 if (tablechars
[i
][0] != '\0') {
92 while (tablechars
[i
][j
] != '\0') {
93 line
[8 + j
] = tablechars
[i
][j
];
99 line
[11] = (((i
+ 1) % nbcols
== 0) || (i
== 255)) ? '\n' : ' ';
101 write (STDOUT_FILENO
, line
, 12);
107 // test: ascii.exe -h
108 // test: ascii.exe -h | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
109 // test: ascii.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
110 // test: ascii.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
112 /* vim: set ts=4 sw=4 et: */