home *** CD-ROM | disk | FTP | other *** search
- Path: xanth!mcnc!gatech!ukma!husc6!necntc!ncoast!allbery
- From: mcgrath%rosemary.Berkeley.EDU@ucbvax.Berkeley.EDU (Roland McGrath)
- Newsgroups: comp.sources.misc
- Subject: v03i068: print an ASCII table the way I want it
- Message-ID: <24896@ucbvax.BERKELEY.EDU>
- Date: 30 Jun 88 04:44:31 GMT
- Sender: allbery@ncoast.UUCP
- Reply-To: mcgrath%rosemary.Berkeley.EDU@ucbvax.Berkeley.EDU (Roland McGrath)
- Organization: Hackers Anonymous International, Ltd., Inc. (Applications welcome)
- Lines: 107
- Approved: allbery@ncoast.UUCP
-
- Posting-number: Volume 3, Issue 68
- Submitted-by: "Roland McGrath" <mcgrath%rosemary.Berkeley.EDU@ucbvax.Berkeley.EDU>
- Archive-name: ascii
-
- This prints an ASCII table. I'm posting it as source for two reasons:
- 1) so no stupid mailers can munge the spacing
- 2) so it really belongs in a sources group!
-
- Don't me misled by the title. It is a literal statement: it prints an
- ASCII table the way I want it. If YOU want it some different way,
- tough.
-
- Dissatisfied with /usr/pub/ascii and other such tables that aren't
- quite right, I wrote this today. Besides, the ASCII table fell off my
- wall a while ago and disappeared among the power cords behind the
- desk.
-
- This table has some advantages over others:
- * It gives ASCII characters, using the ^ convention for control
- chars and the ASCII names for same plus the decimal, hexadecimal
- and octal representations all at once.
- * It has enough whitespace to be easily readable.
- * It fits on one printed page (barely -- it's 65 lines long).
-
- This is meant to be printed out and taped to the wall behind your
- terminal. Any other use is allowed but is obviously a sign of
- inferior working conditions. ;-)
-
- Here's a handmade sharchive:
- : sh me
- echo x - ascii.c
- cat > ascii.c <<eof
- #include <ctype.h>
- #include <stdio.h>
-
- int main()
- {
- void printone();
- register int i;
-
- puts("\
- char | dec | hex | oct || char | dec | hex | oct\
- ");
-
- for (i = 0; i < 64; ++i) {
- fputs(" ", stdout);
- printone(i);
- fputs(" || ", stdout);
- printone(i + 64);
- putchar('\n');
- }
-
- exit(0);
- }
-
-
- void
- printone(i)
- int i;
- {
- if (isprint(i)) printf("%-8c", i);
- else {
- char *desc;
- switch (i) {
- case 0x00: desc = "NUL"; break;
- case 0x01: desc = "SOH"; break;
- case 0x02: desc = "STX"; break;
- case 0x03: desc = "ETX"; break;
- case 0x04: desc = "EOT"; break;
- case 0x05: desc = "ENQ"; break;
- case 0x06: desc = "ACK"; break;
- case 0x07: desc = "BEL"; break;
- case 0x08: desc = "BS"; break;
- case 0x09: desc = "HT"; break;
- case 0x0a: desc = "LF"; break;
- case 0x0b: desc = "VT"; break;
- case 0x0c: desc = "FF"; break;
- case 0x0d: desc = "CR"; break;
- case 0x0e: desc = "SO"; break;
- case 0x0f: desc = "SI"; break;
- case 0x10: desc = "DLE"; break;
- case 0x11: desc = "DC1"; break;
- case 0x12: desc = "DC2"; break;
- case 0x13: desc = "DC3"; break;
- case 0x14: desc = "DC4"; break;
- case 0x15: desc = "NAK"; break;
- case 0x16: desc = "SYN"; break;
- case 0x17: desc = "ETB"; break;
- case 0x18: desc = "CAN"; break;
- case 0x19: desc = "EM"; break;
- case 0x1A: desc = "SUB"; break;
- case 0x1B: desc = "ESC"; break;
- case 0x1c: desc = "FS";break;
- case 0x1d: desc = "GS"; break;
- case 0x1e: desc = "RS"; break;
- case 0x1f: desc = "US"; break;
- case 0x7F: desc = "DEL"; break;
- }
- printf("^%c (%s)", i == 0x7f ? '?' : i + '@', desc);
- if (!desc[2]) putchar(' ');
- }
- printf(" | %3d | %3.2x | %3.3o", i, i, i);
- }
- eof
- Roland McGrath
-
- roland@wheaties.ai.mit.edu, mit-eddie!wheaties.ai.mit.edu!roland
-