home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / printer / gothic.arc / GOTHIC.C next >
C/C++ Source or Header  |  1988-03-04  |  3KB  |  159 lines

  1.  
  2. /*
  3.  *        G o t h i c   P r i n t e r
  4.  *
  5.  *
  6.  * Compile with gottab.c
  7.  *
  8.  * Prints the arguments, if none, it prompts for an output file and
  9.  * reads stdin.
  10.  *
  11.  *    If the first argument is -h, the display is halved.
  12.  *
  13.  *    / in the text reverses the background
  14.  *
  15.  * The following characters are displayed:
  16.  *
  17.  *    #.(@!$);-,?:'"  A-Z  a-z  0-9
  18.  *
  19.  * All others become blanks.
  20.  *
  21.  */
  22. #include <stdio.h>
  23.  
  24. char        outbuf[133];
  25. char        line[133];
  26. int        background    = 0;        /* Background color    */
  27. int        half        = 0;        /* Set to halve display    */
  28.  
  29. main (argc, argv)
  30. int        argc;
  31. char        *argv[];
  32.  
  33. {
  34.     register int        i;
  35.  
  36.     if (argc > 1 && argv[1][0] == '-' && (argv[1][1] | 040) == 'h') {
  37.         argc--;
  38.         argv++;
  39.         half++;
  40.     }
  41.     if (argc <= 1) {
  42.         printf("Gothic output file <terminal>: ");
  43.         fflush(stdout);
  44.         if (gets(outbuf) == NULL)
  45.             panic("No output file", NULL);
  46.         if (half == 0) {
  47.             printf("Half size (Yes/No) <N>: ");
  48.             fflush(stdout);
  49.             if (gets(line) == NULL)
  50.                 panic("Unexpected EOF", NULL);
  51.             if ((line[0] | 040) == 'y')
  52.                 half++;
  53.         }
  54.         if (outbuf[0] != 0) {
  55.             if (freopen(outbuf, "w", stdout) == NULL)
  56.                 panic("Can't open", outbuf);
  57.         }
  58.         while (gets(line) != NULL) {
  59.             dotext(line);
  60.         }
  61.     }
  62.     else {
  63.         for (i = 1; i < argc; i++) {
  64.             dotext(argv[i]);
  65.         }
  66.         puts("\f");
  67.     }
  68. }
  69.  
  70. dotext(text)
  71. char        *text;
  72. /*
  73.  * Convert text to gothic letters, write them to stdout
  74.  */
  75. {
  76.     register char    *tp;
  77.     register int    c;
  78.  
  79.     for (tp = text; (c = *tp++) != 0;) {
  80.         if (c == '/')
  81.             background = (background) ? 0 : 2;
  82.         else    gothic(c);
  83.     }
  84. }
  85.  
  86. gothic(character)
  87. int        character;
  88. /*
  89.  * Process the character
  90.  */
  91. {
  92.     char            *gp;
  93.     register char        *op;
  94.     register int        i;
  95.     register int        byte;
  96.     int            index;
  97.     extern char        *gottab[];
  98.     int            lhalf;        /* Line half flag    */
  99.     int            chalf;        /* Column half flag    */
  100.         
  101.     index = (background) ? -1 : 0;
  102.     lhalf = chalf = 0;
  103.     gp = gottab[character & 127];
  104.     op = outbuf;
  105.     for (;;) {
  106.         if ((i = (*gp++ & 0377)) >= 254) {
  107.             if (background) {
  108.                 while (op < &outbuf[132])
  109.                     *op++ = 'X';
  110.             }
  111.             *op = 0;
  112.             lhalf = ~lhalf;
  113.             chalf = 0;
  114.             if (half) {
  115.                 if (lhalf) {
  116.                     outbuf[132 / 2] = 0;
  117.                     puts(outbuf);
  118.                 }
  119.             }
  120.             else {
  121.                 puts(outbuf);
  122.             }
  123.             op = outbuf;
  124.             if (i == 255)
  125.                 break;
  126.         }
  127.         else {
  128.             byte = "O X "[background - (index = (-1 - index))];
  129.             while (--i >= 0) {
  130.                 if (half) {
  131.                     chalf = ~chalf;
  132.                     if (chalf) {
  133.                         *op++ = byte;
  134.                     }
  135.                 }
  136.                 else {
  137.                     *op++ = byte;
  138.                 }
  139.             }
  140.             if (op >= &outbuf[132])
  141.                 panic("big line", NULL);
  142.         }
  143.     }
  144. }
  145.  
  146. panic(s, arg)
  147. char        *s;
  148. char        *arg;
  149. /*
  150.  * Fatal error exit
  151.  */
  152. {
  153.     fprintf(stderr, "?Gothic-E-fatal error %s", s);
  154.     if (arg != NULL)
  155.         fprintf(stderr, ": \"%s\"", arg);
  156.     fprintf(stderr, "\n");
  157.     exit(1);
  158. }
  159.