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

  1. /*
  2.  * termtab.c -- common declarations for nroff table conversion
  3.  *
  4.  * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  5.  * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  6.  * freely, but don't try to make money selling it unless you're going to send
  7.  * me a cut. Send bug reports, love letters and death threats to eric@snark
  8.  * aka ...!rutgers!vu-vlsi!snark!eric.
  9.  */
  10. /*LINTLIBRARY*/
  11. #include <stdio.h>
  12. #include "termtab.h"
  13.  
  14. extern char *strcpy();
  15. extern void exit();
  16.  
  17. char *ntnames[] =    /* [nt]roff character name translation */
  18. {
  19. " ", "!","\"", "#", "$", "%", "&", "'",
  20. "(", ")", "*", "+", ",", "-", ".", "/",
  21. "0", "1", "2", "3", "4", "5", "6", "7",
  22. "8", "9", ":", ";", "<", "=", ">", "?",
  23. "@", "A", "B", "C", "D", "E", "F", "G",
  24. "H", "I", "J", "K", "L", "M", "N", "O",
  25. "P", "Q", "R", "S", "T", "U", "V", "W",
  26. "X", "Y", "Z", "[", "\\","]", "^", "_",
  27. "`", "a", "b", "c", "d", "e", "f", "g",
  28. "h", "i", "j", "k", "l", "m", "n", "o",
  29. "p", "q", "r", "s", "t", "u", "v", "w",
  30. "x", "y", "z", "{", "|", "}", "~","\\|",
  31. "hy", "bu", "sq", "em", "ru", "14", "12", "34", 
  32. "\\-","fi", "fl", "ff", "Fi", "Fl", "de", "dg", 
  33. "sc", "fm", "aa", "ga", "ul", "sl", "\\^", "\\ ", 
  34. "*a", "*b", "*g", "*d", "*e", "*z", "*y", "*h", 
  35. "*i", "*k", "*l", "*m", "*n", "*c", "*o", "*p", 
  36. "*r", "*s", "*t", "*u", "*f", "*x", "*q", "*w", 
  37. "*G", "*D", "*H", "*L", "*C", "*P", "*S", "*T", 
  38. "*U", "*F", "*Q", "*W", "sr", "ts", "rn", ">=", 
  39. "<=", "==", "mi", "~=", "ap", "!=", "->", "<-", 
  40. "ua", "da", "eq", "mu", "di", "+-", "cu", "ca", 
  41. "sb", "sp", "ib", "ip", "if", "pd", "gr", "no", 
  42. "is", "pt", "es", "mo", "pl", "rg", "co", "br", 
  43. "ct", "dd", "rh", "lh", "**", "bs", "or", "ci", 
  44. "lt", "lb", "rt", "rb", "lk", "rk", "bv", "lf", 
  45. "rf", "lc", "rc",
  46. (char *)NULL
  47.  };
  48.  
  49. void newstrings(sp)
  50. strtab *sp;
  51. {
  52.     sp->c_end = sp->c_data;
  53. }
  54.  
  55. char *addstring(string, pp)
  56. strtab    *pp;
  57. char    *string;
  58. {
  59.     pp->c_pointer[pp->n_strings] = pp->c_end;
  60.     pp->c_end += (pp->c_length[pp->n_strings] = strlen(string)) + 1;
  61.     if (pp->c_end >= pp->c_data + C_SIZE)
  62.     {
  63.     (void) fprintf(stderr, "Table size too small, increase it!\n");
  64.     exit(1);
  65.     }
  66.     return(strcpy(pp->c_pointer[pp->n_strings++], string));
  67. }
  68.  
  69. int char_comp(str1, str2, len)
  70. char    *str1, *str2;
  71. int    len;
  72. {
  73.     while (len--)
  74.     if (*str1++ != *str2++)
  75.         return(1);
  76.     return(0);
  77. }
  78.  
  79. int findstring(string, pp)
  80. strtab    *pp;
  81. char    *string;
  82. {
  83.     int    c_len, s_len, i;
  84.  
  85.     for (i = 0; i < pp->n_strings; i++)
  86.     {
  87.     if ((c_len = pp->c_length[i]) >= (s_len = strlen(string))) {
  88.         if (!char_comp (string, pp->c_pointer[i] + c_len - s_len, s_len))
  89.         return (pp->c_pointer[i] + c_len - s_len - pp->c_data);
  90.     }
  91.     }
  92.     (void) fprintf(stderr, "Serious bug! string not found in table\n");
  93.     exit(1);
  94.     /* NOTREACHED */
  95. }
  96.  
  97. /* termtab.c ends here */
  98.