int usage (int ret)
{
- int fd = ret ? _fd_stderr : _fd_stdout;
+ int fd = ret ? stdfderr : stdfdout;
fdprintf (fd, "usage: %s\n", progname);
fdprintf (fd, " -c : number of columns (%d)\n", nbcols);
fdprintf (fd, " -h : help message\n");
{
int i = 0;
+ /* programm name */
+
progname = argv[0];
while (progname[i] != '\0') {
if ((progname[i] == '/') || (progname[i] == '\\')) {
}
}
+ /* argument processing */
+
while (argc-- > 1) {
char *arg = *(++argv);
if (arg[0] != '-') {
/* main */
- for (i = 0; i < 256; i++) {
+ int n = (256 + nbcols - 1) / nbcols;
+ for (i = 0; i < n * nbcols; i++) {
char line[] = " [ ] x";
+ int j = i / nbcols + (i % nbcols) * n;
- if (i > 99) line[0] = '0' + i / 100;
- if (i > 9) line[1] = '0' + (i / 10) % 10;
- line[2] = '0' + i % 10;
- line[4] = '0' + i / 16;
+ if (j > 255) {
+ PRINTOUT ("\n");
+ continue;
+ }
+
+ if (j > 99) line[0] = '0' + j / 100;
+ if (j > 9) line[1] = '0' + (j / 10) % 10;
+ line[2] = '0' + j % 10;
+ line[4] = '0' + j / 16;
if (line[4] > '9') line[4] += 'a' - '0' - 10;
- line[5] = '0' + i % 16;
+ line[5] = '0' + j % 16;
if (line[5] > '9') line[5] += 'a' - '0' - 10;
- if (tablechars[i][0] != '\0') {
- int j = 0;
- while (tablechars[i][j] != '\0') {
- line[8 + j] = tablechars[i][j];
- j++;
+ if (tablechars[j][0] != '\0') {
+ int k = 0;
+ while (tablechars[j][k] != '\0') {
+ line[8 + k] = tablechars[j][k];
+ k++;
}
} else {
- line[8] = i;
+ line[8] = j;
}
- line[11] = (((i + 1) % nbcols == 0) || (i == 255)) ? '\n' : ' ';
+ line[11] = ((i + 1) % nbcols == 0) ? '\n' : ' ';
- fdprintf (_fd_stdout, "%s", line);
+ PRINTOUT ("%s", line);
}
return 0;
// test: ascii.exe -_ 2> /dev/null | awk 'END { if (NR == 0) { exit(0) } else exit (1) }'
// test: ascii.exe -_ 2>&1 | awk '/usage:/ { rc=1 } END { exit (1-rc) }'
+// test: ascii.exe | awk '/ 64\[40\] @/ { rc=1 } END { exit (1-rc) }'
+// test: ascii.exe | awk '/127\[7f\] DEL/ { rc=1 } END { exit (1-rc) }'
+// test: ascii.exe -c 4 | tail -1 | awk '/63/ { rc=1 } END { exit (1-rc) }'
+// test: ascii.exe -c 5 | tail -1 | awk '/51/ { rc=1 } END { exit (1-rc) }'
+// test: ascii.exe -c 6 | tail -1 | awk '/42/ { rc=1 } END { exit (1-rc) }'
+
/* vim: set ts=4 sw=4 et: */
int fdprintf (int fd, const char *fmt, ...);
-extern int _fd_stdout;
-extern int _fd_stderr;
+extern int stdfdout;
+extern int stdfderr;
-#define PRINTOUT(fmt...) fdprintf (_fd_stdout, fmt)
-#define PRINTERR(fmt...) fdprintf (_fd_stderr, fmt)
+#define PRINTOUT(fmt...) fdprintf (stdfdout, fmt)
+#define PRINTERR(fmt...) fdprintf (stdfderr, fmt)
#endif /* __FDPRINTF_H__ */