Attachment 'asc.c'
Download 1 #include <stdio.h>
2 #include <string.h>
3 #include <unistd.h>
4
5 int main(int argc, char *argv[])
6 {
7 int i;
8 char *fstr;
9 char *sepstr = isatty(1) ? ("\e(0x\e(B") : ("|");
10
11 if (argc == 1 || (argc == 2 && (!strcmp(argv[1], "-d") || !strcmp(argv[1], "-10"))))
12 fstr = "%s %c %3d ";
13 else if (argc == 2 && (!strcmp(argv[1], "-o") || !strcmp(argv[1], "-8")))
14 fstr = "%s %c %03o ";
15 else if (argc == 2 && (!strcmp(argv[1], "-x") || !strcmp(argv[1], "-16")))
16 fstr = "%s %c %02X ";
17 else {
18 fprintf(stderr, "usage: %s [ -8 | -10 | -16 | -o | -d | -x ]\n", argv[0]);
19 return 1;
20 }
21
22 for (i = 32; i < 256; i++) {
23 if (i == 128) i += 32;
24 printf(fstr, sepstr, (i == 127 ? 68 : i), i);
25 if (i % 8 == 7) printf("%s\n", sepstr);
26 }
27 return 0;
28 }
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.