home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / nrtable / elbat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  5.3 KB  |  213 lines

  1. /* elbat:  a program to de-compile nroff drive tables so they can
  2. **         be fiddled with.
  3. **
  4. ** usage:  elbat tabXXX > tabXXX.c
  5. **
  6. ** Matt Crawford, University of Chicago, 10 May 1984
  7. ** ihnp4!oddjob!matt           crawford@anl-mcs.arpa
  8. **
  9. ** Modified by: Bruce Townsend, Bell Northern-Research, March 6 1985
  10. **       - Changed for USG UNIX systems.
  11. **
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <ctype.h>
  16. #include <fcntl.h>
  17. #include "term.h"
  18.  
  19. void    loadtab(), vprint();
  20. char    *codelabel[] = {
  21.     "space",    "!",    "\"",    "#",    "$",    "%",    "&",
  22.     "' close",    "(",    ")",    "*",    "+",    ",",    "- hyphen",
  23.     ".",    "/",    "0",    "1",    "2",    "3",    "4",    "5",
  24.     "6",    "7",    "8",    "9",    ":",    ";",    "<",    "=",
  25.     ">",    "?",    "@",    "A",    "B",    "C",    "D",    "E",
  26.     "F",    "G",    "H",    "I",    "J",    "K",    "L",    "M",
  27.     "N",    "O",    "P",    "Q",    "R",    "S",    "T",    "U",
  28.     "V",    "W",    "X",    "Y",    "Z",    "[",    "\\",    "]",
  29.     "^",    "_ dash",    "` open",    "a",    "b",    "c",
  30.     "d",    "e",    "f",    "g",    "h",    "i",    "j",    "k",
  31.     "l",    "m",    "n",    "o",    "p",    "q",    "r",    "s",
  32.     "t",    "u",    "v",    "w",    "x",    "y",    "z",    "{",
  33.     "|",    "}",    "~",    "narrow sp",    "hyphen",    "bullet",
  34.     "square",    "3/4 em",    "rule",    "1/4",    "1/2",    "3/4",
  35.     "minus",    "fi",    "fl",    "ff",    "ffi",    "ffl",    "degree",
  36.     "dagger",    "section",    "foot mark",    "acute accent",
  37.     "grave accent",    "underrule",    "slash (longer)",
  38.     "half narrow space",    "unpaddable space",    "alpha",
  39.     "beta",    "gamma",    "delta",    "epsilon",    "zeta",
  40.     "eta",    "theta",    "iota",    "kappa",    "lambda",
  41.     "mu",    "nu",    "xi",    "omicron",    "pi",    "rho",    "sigma",
  42.     "tau",    "upsilon",    "phi",    "chi",    "psi",    "omega",
  43.     "Gamma",    "Delta",    "Theta",    "Lambda",
  44.     "Xi",    "Pi",    "Sigma",    "Tau",    "Upsilon",    "Phi",
  45.     "Psi",    "Omega",    "square root",    "terminal sigma",
  46.     "root en",    ">=",    "<=",    "identically equal",
  47.     "equation minus",    "approx =",    "approximates",
  48.     "not equal",    "right arrow",    "left arrow",    "up arrow",
  49.     "down arrow",    "eqn equals",    "multiply",    "divide",
  50.     "plus-minus",    "cup (union)",    "cap (intersection)",    "subset of",
  51.     "superset of",    "improper subset",    " improper superset",
  52.     "infinity",    "pt deriv",    "gradient",    "not",    "integral",
  53.     "proportional to",    "empty set",    "member of",
  54.     "equation plus",    "registration mk",    "copyright mk",
  55.     "box rule",    "cent sign",    "dbl dagger",    "right hand",
  56.     "left hand",    "math * ",    "bell system sign",
  57.     "or (was star)",    "circle",    "left top of big curly",
  58.     "left bottom of big curly",    "right top of big curly",
  59.     "right bottom of big curly",    "left center of big curly",
  60.     "right center of big curly",    "bold vertical rule",
  61.     "left bottom of big bracket",    "right bottom of big bracket",
  62.     "left top of big bracket",    "right top of big bracket",
  63.     "???",    "???",    "???",    "???",    "???",    "???",    "???",    "???",
  64.     "???",    "???",    "???",    "???",    "???",    /* No idea what these are */
  65. };
  66.  
  67. struct t t;
  68. struct t_stor t_stor;
  69.  
  70. main(argc, argv)
  71. char    **argv;
  72. {
  73.     register int    c;
  74.     register char    **endptr = &t.zzz;
  75.     register FILE    *twfp;
  76.     char        labelbuf[64];
  77.  
  78.     if (argc != 2) {
  79.         fprintf (stderr, "Usage: elbat tabXXX > tabXXX.c\n");
  80.         exit(1);
  81.         }
  82.  
  83.     loadtab(argv[1]);
  84.     if ( (twfp = fopen("term.h", "r")) == NULL ) {
  85.         perror("term.h");
  86.         exit(1);
  87.     }
  88.     
  89.     while ( (c = getc(twfp)) != EOF && c != /*{*/ '}')
  90.         putc(c, stdout);
  91.     fclose(twfp);
  92.     printf(/*{*/ "} t = {\n" /*}*/);    /* Stupid emacs! */
  93.     printf("/*bset    */\t\t0%o,\n", t.bset);
  94.     printf("/*breset  */\t\t0%o,\n", t.breset);
  95. #define intshow(memb) \
  96.         printf("/*%-8s*/\t\t%d,\n", "memb", t.memb)
  97.     intshow(Hor);
  98.     intshow(Vert);
  99.     intshow(Newline);
  100.     intshow(Char);
  101.     intshow(Em);
  102.     intshow(Halfline);
  103.     intshow(Adj);
  104. #define show(memb) \
  105.         printf("/*%-8s*/\t\t\"", "memb");\
  106.         vprint(t.memb);\
  107.         printf("\",\n")
  108.     show(twinit);
  109.     show(twrest);
  110.     show(twnl);
  111.     show(hlr);
  112.     show(hlf);
  113.     show(flr);
  114.     show(bdon);
  115.     show(bdoff);
  116.     show(iton);
  117.     show(itoff);
  118.     show(ploton);
  119.     show(plotoff);
  120.     show(up);
  121.     show(down);
  122.     show(right);
  123.     show(left);
  124.     while ( **--endptr == '\0' )
  125.         ;
  126.     for ( c = 0; c < 256-32        /* Not all 256-32 chars are in use */
  127.         && &t.codetab[c] <= endptr; c++ ) {
  128.         sprintf(labelbuf, "/* %s */", codelabel[c]);
  129.         printf("%-20s\t\"", labelbuf);
  130.         if ( t.codetab[c][0] )
  131.             vprint(t.codetab[c]);
  132.         else if ( t.codetab[c][1] ) {
  133.             printf("\\000");
  134.             vprint(t.codetab[c]+1);
  135.             }
  136.         else
  137.             printf("\\000\\0");
  138.         printf("\",\n");
  139.     }
  140.     printf(/*{*/ "};\n");
  141.     exit(0);
  142. }
  143.  
  144. void
  145. vprint(str)
  146. register char    *str;
  147. {
  148.     while ( str && *str ) {
  149.         char    c[5];
  150.  
  151.         if ( isascii(*str) && isprint(*str)
  152.                 && *str != '\\' && *str != '"' ) {
  153.             c[0] = *str;
  154.             c[1] = '\0';
  155.         } else
  156.             switch ( *str ) {
  157.             case '\\':
  158.             case '"':
  159.                 c[0] = '\\';
  160.                 c[1] = *str;
  161.                 c[2] = '\0';
  162.                     break;
  163.             case '\b':
  164.                     strcpy(c, "\\b");
  165.                     break;
  166.             case '\t':
  167.                     strcpy(c, "\\t");
  168.                     break;
  169.             case '\n':
  170.                     strcpy(c, "\\n");
  171.                     break;
  172.             case '\r':
  173.                     strcpy(c, "\\r");
  174.                     break;
  175.             default:
  176.                 sprintf(c, "\\%03.3o", (int)*str & 0377);
  177.                     break;
  178.             }
  179.         fputs(c, stdout);
  180.         str++;
  181.     }
  182. }
  183.  
  184. void
  185. loadtab( tname )
  186. char    *tname;
  187. {
  188.     register int    tfd;
  189.     int        c_size, *ip;
  190.     register char    **pp, *mptr;
  191.     extern char    *malloc();
  192.  
  193.     if( (tfd=open(tname, O_RDONLY)) < 0 ) {
  194.         perror( tname );
  195.         exit(1);
  196.     }
  197.     read(tfd, &c_size, sizeof(int));
  198.     read(tfd, &t_stor, sizeof(t_stor));
  199.     mptr = malloc (c_size);
  200.     read(tfd, mptr, c_size);
  201.     t.bset = t_stor.bset;
  202.     t.breset = t_stor.breset;
  203.     t.Hor = t_stor.Hor;
  204.     t.Vert = t_stor.Vert;
  205.     t.Newline = t_stor.Newline;
  206.     t.Char = t_stor.Char;
  207.     t.Em = t_stor.Em;
  208.     t.Halfline = t_stor.Halfline;
  209.     t.Adj = t_stor.Adj;
  210.     ip = &t_stor.twinit;
  211.     for ( pp = &t.twinit; pp < &t.zzz;) *pp++ = mptr + *ip++;
  212. }
  213.