home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume3 / ascii < prev    next >
Text File  |  1989-02-03  |  4KB  |  120 lines

  1. Path: xanth!mcnc!gatech!ukma!husc6!necntc!ncoast!allbery
  2. From: mcgrath%rosemary.Berkeley.EDU@ucbvax.Berkeley.EDU (Roland McGrath)
  3. Newsgroups: comp.sources.misc
  4. Subject: v03i068: print an ASCII table the way I want it
  5. Message-ID: <24896@ucbvax.BERKELEY.EDU>
  6. Date: 30 Jun 88 04:44:31 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: mcgrath%rosemary.Berkeley.EDU@ucbvax.Berkeley.EDU (Roland McGrath)
  9. Organization: Hackers Anonymous International, Ltd., Inc. (Applications welcome)
  10. Lines: 107
  11. Approved: allbery@ncoast.UUCP
  12.  
  13. Posting-number: Volume 3, Issue 68
  14. Submitted-by: "Roland McGrath" <mcgrath%rosemary.Berkeley.EDU@ucbvax.Berkeley.EDU>
  15. Archive-name: ascii
  16.  
  17. This prints an ASCII table.  I'm posting it as source for two reasons:
  18.      1) so no stupid mailers can munge the spacing
  19.      2) so it really belongs in a sources group!
  20.  
  21. Don't me misled by the title.  It is a literal statement: it prints an
  22. ASCII table the way I want it.  If YOU want it some different way,
  23. tough.
  24.  
  25. Dissatisfied with /usr/pub/ascii and other such tables that aren't
  26. quite right, I wrote this today.  Besides, the ASCII table fell off my
  27. wall a while ago and disappeared among the power cords behind the
  28. desk.
  29.  
  30. This table has some advantages over others:
  31.      * It gives ASCII characters, using the ^ convention for control
  32.      chars and the ASCII names for same plus the decimal, hexadecimal
  33.      and octal representations all at once.
  34.      * It has enough whitespace to be easily readable.
  35.      * It fits on one printed page (barely -- it's 65 lines long).
  36.  
  37. This is meant to be printed out and taped to the wall behind your
  38. terminal.  Any other use is allowed but is obviously a sign of
  39. inferior working conditions. ;-)
  40.  
  41. Here's a handmade sharchive:
  42. : sh me
  43. echo x - ascii.c
  44. cat > ascii.c <<eof
  45. #include <ctype.h>
  46. #include <stdio.h>
  47.  
  48. int main()
  49. {
  50.     void printone();
  51.     register int i;
  52.  
  53.     puts("\
  54.       char   | dec | hex | oct    ||     char   | dec | hex | oct\
  55. ");
  56.  
  57.     for (i = 0; i < 64; ++i) {
  58.         fputs("    ", stdout);    
  59.         printone(i);
  60.         fputs("    ||   ", stdout);
  61.         printone(i + 64);
  62.         putchar('\n');
  63.     }
  64.  
  65.     exit(0);
  66. }
  67.  
  68.  
  69. void
  70. printone(i)
  71. int i;
  72. {
  73.     if (isprint(i)) printf("%-8c", i);
  74.     else {
  75.         char *desc;
  76.         switch (i) {
  77.             case 0x00: desc = "NUL"; break;
  78.             case 0x01: desc = "SOH"; break;
  79.             case 0x02: desc = "STX"; break;
  80.             case 0x03: desc = "ETX"; break;
  81.             case 0x04: desc = "EOT"; break;
  82.             case 0x05: desc = "ENQ"; break;
  83.             case 0x06: desc = "ACK"; break;
  84.             case 0x07: desc = "BEL"; break;
  85.             case 0x08: desc = "BS"; break;
  86.             case 0x09: desc = "HT"; break;
  87.             case 0x0a: desc = "LF"; break;
  88.             case 0x0b: desc = "VT"; break;
  89.             case 0x0c: desc = "FF"; break;
  90.             case 0x0d: desc = "CR"; break;
  91.             case 0x0e: desc = "SO"; break;
  92.             case 0x0f: desc = "SI"; break;
  93.             case 0x10: desc = "DLE"; break;
  94.             case 0x11: desc = "DC1"; break;
  95.             case 0x12: desc = "DC2"; break;
  96.             case 0x13: desc = "DC3"; break;
  97.             case 0x14: desc = "DC4"; break;
  98.             case 0x15: desc = "NAK"; break;
  99.             case 0x16: desc = "SYN"; break;
  100.             case 0x17: desc = "ETB"; break;
  101.             case 0x18: desc = "CAN"; break;
  102.             case 0x19: desc = "EM"; break;
  103.             case 0x1A: desc = "SUB"; break;
  104.             case 0x1B: desc = "ESC"; break;
  105.             case 0x1c: desc = "FS";break;
  106.             case 0x1d: desc = "GS"; break;
  107.             case 0x1e: desc = "RS"; break;
  108.             case 0x1f: desc = "US"; break;
  109.             case 0x7F: desc = "DEL"; break;
  110.         }
  111.         printf("^%c (%s)", i == 0x7f ? '?' : i + '@', desc);
  112.         if (!desc[2]) putchar(' ');
  113.     }
  114.     printf(" | %3d | %3.2x | %3.3o", i, i, i);
  115. }
  116. eof
  117.     Roland McGrath
  118.  
  119. roland@wheaties.ai.mit.edu, mit-eddie!wheaties.ai.mit.edu!roland
  120.