home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / epf / part01 / epf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-10-24  |  2.2 KB  |  100 lines

  1. /* epf */
  2.  
  3. /*-
  4.  * This filter for Epson LQ-1500 compatibles prints the nroff Non-ASCII 
  5.  * Special Characters.
  6.  *
  7.  * Greek characters and mathematical characters are implemented. 
  8.  *
  9.  * Neqn displays are not bad.
  10.  *
  11.  * Assumes the nroff driver tables were written for representations
  12.  * compatible with "col", ie SO-<single printable char>-SI and 
  13.  * ESC-[789] for line movements.
  14.  *
  15.  * The table of user-defined-character strings is in matrix.h.
  16.  *
  17.  * Author:
  18.  * John Nellen, Delft Univ. of Technology 
  19.  * ..!{decvax,philabs}!mcvax!dutesta!john 
  20.  *
  21.  * Source:
  22.  * Newsgroups: net.sources
  23.  * Subject: Epson filter to type nroff Non-ASCII char's (no 1 of 4)
  24.  * Message-ID: <371@dutesta.UUCP>
  25.  * Date: 30 Oct 85 09:54:20 GMT
  26.  *
  27.  * Rewritten Jul 1, 1989:
  28.  * J.A. Rupley
  29.  * rupley!local@megaron.arizona.edu
  30.  */
  31.  
  32.  
  33. #include    <stdio.h>
  34.  
  35. #define        LINE        30    /* 180 / 6 -- Epson ESC-J scale */
  36. #define        HALFLINE    15    /* LINE / 2 */
  37.  
  38. #define        NORMAL        0
  39. #define        GRAPHICS    1
  40.  
  41. #define        ESC    27
  42. #define        SO    '\016'        /* shift out to alternate char set */
  43. #define        SI    '\017'
  44.  
  45. #include    "matrix.h"
  46.  
  47. int
  48. main()
  49. {
  50.     int             j, cnt, state;
  51.     int             c, curchar;
  52.  
  53.     state = NORMAL;
  54.     curchar = getchar();
  55.     while (curchar != EOF) {
  56.         if (curchar == ESC) {
  57.             if ((c = getchar()) == EOF)
  58.                 break;
  59.             switch (c) {
  60.             case '8':
  61.                 putchar(ESC);    /* reverse half line feed */
  62.                 putchar('j');    /* not passed by "col" */
  63.                 putchar(HALFLINE); /* therefore useless? */
  64.                 break;
  65.             case '9':
  66.                 putchar(ESC);    /* forward half line feed */
  67.                 putchar('J');
  68.                 putchar(HALFLINE);
  69.                 break;
  70.             case '7':
  71.                 putchar(ESC);    /* reverse full line feed */
  72.                 putchar('j');    /* not passed by "col" */
  73.                 putchar(LINE);    /* therefore useless? */
  74.                 break;
  75.             default:
  76.                 putchar(ESC);    /* put ESC back on line */
  77.                 putchar(c);
  78.             }
  79.         } else if (curchar == SI) {
  80.             state = NORMAL;
  81.         } else if (curchar == SO) {
  82.             state = GRAPHICS;
  83.         } else if (state == GRAPHICS) {
  84.             cnt = (curchar - '!');
  85.             if (cnt < 0 || cnt >= TABLE_ARRAY_SIZE) {
  86.                 putchar(curchar);
  87.             } else {
  88.                 for (j = 0; j < TABLE_ELEM_SIZE; j++) {
  89.                     putchar(table[cnt][j]);
  90.                 }
  91.             }
  92.         } else {
  93.             putchar(curchar);
  94.         }
  95.         curchar = getchar();
  96.     }
  97.  
  98.     return 0;
  99. }
  100.