home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume15 / nroffgraphics / part01 / ditwrite.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-06  |  2.8 KB  |  99 lines

  1. /*
  2.  * ditwrite.c -- dump an internal driver-table representation in ditroff form
  3.  *
  4.  * Dumps a driver-table structure in all-ASCII ditroff format. Uses octal
  5.  * escape and \b, \t, \n, \r for nonprintable characters.
  6.  *
  7.  * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  8.  * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  9.  * freely, but don't try to make money selling it unless you're going to send
  10.  * me a cut. Send bug reports, love letters and death threats to eric@snark
  11.  * aka ...!rutgers!vu-vlsi!snark!eric.
  12.  */
  13. /*LINTLIBRARY*/
  14. #include <stdio.h>
  15. #include <ctype.h>
  16. #include "termtab.h"
  17.  
  18. static void tdump(fp, label, val)
  19. /* dump a string (in quotes) with a given label prepended */
  20. FILE *fp;
  21. char *label;
  22. char *val;
  23. {
  24.     if (val != (char *)NULL)
  25.     {
  26.     char outbuf[BUFSIZ];
  27.  
  28.     (void) expand(val, outbuf);
  29.     (void) fprintf(fp, "%-12s\"%s\"\n", outbuf, label);
  30.     }
  31. }
  32.  
  33. static void cdump(fp, label, width, val)
  34. /* dump a character with its width */
  35. FILE *fp;
  36. char *label;
  37. int width;
  38. char *val;
  39. {
  40.     if (val != (char *)NULL)
  41.     {
  42.     char outbuf[BUFSIZ];
  43.  
  44.     (void) expand(val, outbuf);
  45.     (void) fprintf(fp, "%s %d %s\n", outbuf, label, width);
  46.     }
  47. }
  48.  
  49. void ditwrite(tp, fp)
  50. nrtab_t *tp;
  51. FILE    *fp;
  52. {
  53.     register char **ctab = tp->codetab;
  54.  
  55.     /* first, dump integer parameters */
  56.     (void) fprintf(fp, "bset        %d\n", tp->bset);
  57.     (void) fprintf(fp, "breset      %d\n", tp->breset);
  58.     (void) fprintf(fp, "Hor         %d\n", tp->Hor);
  59.     (void) fprintf(fp, "Vert        %d\n", tp->Vert);
  60.     (void) fprintf(fp, "Newline     %d\n", tp->Newline);
  61.     (void) fprintf(fp, "Char        %d\n", tp->Char);
  62. #ifdef KANJI
  63.     (void) fprintf(fp, "Kchar        %d\n", tp->Kchar);
  64. #endif KANJI
  65.     (void) fprintf(fp, "Em          %d\n", tp->Em);
  66.     (void) fprintf(fp, "Halfline    %d\n", tp->Halfline);
  67.     (void) fprintf(fp, "Adj         %d\n", tp->Adj);
  68.  
  69.     /* next, dump standard control strings */
  70.     tdump(fp, "twinit", tp->twinit);
  71.     tdump(fp, "twrest", tp->twrest);
  72.     tdump(fp, "twnl", tp->twnl);
  73.     tdump(fp, "hlr", tp->hlr);
  74.     tdump(fp, "hlf", tp->hlf);
  75.     tdump(fp, "flr", tp->flr);
  76.     tdump(fp, "bdon", tp->bdon);
  77.     tdump(fp, "bdoff", tp->bdoff);
  78.     tdump(fp, "iton", tp->iton);
  79.     tdump(fp, "itoff", tp->itoff);
  80.     tdump(fp, "ploton", tp->ploton);
  81.     tdump(fp, "plotoff", tp->plotoff);
  82.     tdump(fp, "up", tp->up);
  83.     tdump(fp, "down", tp->down);
  84.     tdump(fp, "right", tp->right);
  85.     tdump(fp, "left", tp->left);
  86.  
  87.     /* finally, dump the character table */
  88.     (void) fputs("\ncharset\n", fp);
  89.     for (ctab = ntnames; ctab[0] != (char *)NULL; ctab++)
  90.     {
  91.     char *cstr = tp->codetab[ctab - ntnames];
  92.  
  93.     if ((cstr[0] || cstr[1]) && strcmp(ctab[0], cstr + 1))
  94.         cdump(fp, ctab[0], cstr[0], cstr + 1);
  95.     }
  96. }
  97.  
  98. /* ditwrite.c ends here */
  99.