home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / othergnu / texinf~1.zoo / texinfo.st / texi2roff / table.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-12  |  2.5 KB  |  109 lines

  1. /*
  2.  * table.c - set up translation tables for texi2roff
  3.  *        Release 1.0a    August 1988
  4.  *        Release 2.0    January 1990
  5.  *
  6.  * Copyright 1988, 1989, 1990  Beverly A.Erlebacher
  7.  * erlebach@cs.toronto.edu    ...uunet!utai!erlebach
  8.  *
  9.  *
  10.  * When adding more commands: 
  11.  *
  12.  * - be sure that gettoken() can recognize not just the ending token
  13.  *   (texend) but also the end of the starting token (texstart) for
  14.  *   the command, if it doesnt already occur in a table.
  15.  *
  16.  * - keep the tables sorted
  17.  *
  18.  * - try to keep all troff strings here and in the table header files
  19.  *
  20.  * - strive diligently to keep the program table-driven
  21.  */
  22.  
  23. #include <stdio.h>    /* just to get NULL */
  24. #include "texi2roff.h"
  25. #include "tablems.h"
  26. #include "tableme.h"
  27. #include "tablemm.h"
  28.  
  29. char indexmacro[] = ".de iX \n.tm \\\\$1   \\\\n%\n..\n";
  30. char trquotes[] = ".tr \\(is'\n.tr \\(if`\n.tr \\(pd\"\n";
  31.  
  32. struct misccmds * cmds;
  33. struct tablerecd * table, * endoftable;
  34.  
  35. void
  36. initialize(macropkg, showInfo, makeindex)
  37. int macropkg;
  38. int showInfo;
  39. int makeindex;
  40. {
  41.     extern void patchtable();
  42.     int tablesize;
  43.  
  44.     switch (macropkg) {
  45.     case MS:
  46.     table = mstable;
  47.     tablesize = sizeof mstable;
  48.     cmds = &mscmds;
  49.     break;
  50.     case MM:
  51.     table = mmtable;
  52.     tablesize = sizeof mmtable;
  53.     cmds = &mmcmds;
  54.     break;
  55.     case ME:
  56.     table = metable;
  57.     tablesize = sizeof metable;
  58.     cmds = &mecmds;
  59.     break;
  60.     }
  61.     endoftable = table + tablesize/sizeof table[0];
  62.     if (showInfo == NO)
  63.        (void) patchtable();
  64.     if (makeindex == YES)
  65.        puts(indexmacro);
  66.     puts(cmds->init);
  67.     puts(trquotes);
  68. }
  69.  
  70.  
  71. /*
  72.  * lookup - linear search for texinfo command in table
  73.  * i used bsearch() for a while but it isnt portable and makes lint squawk.
  74.  */
  75.  
  76. struct tablerecd *
  77. lookup(token)
  78.     char       *token;
  79. {
  80.     register struct tablerecd *tptr;
  81.  
  82.     for (tptr = table; tptr < endoftable; ++tptr) {
  83.     if (STREQ(tptr->texstart, token))
  84.         return tptr;
  85.     }
  86.     return NULL;
  87. }
  88.  
  89. /*
  90.  * real Texinfo has a sort of hypertext feature called Info files,
  91.  * using menus, nodes and 'ifinfo' sections. Although i can't simulate
  92.  * this here, and the material would not normally be printed by Texinfo,
  93.  * it could be useful to the user searching through a machine-readable
  94.  * manual. If the -I option is not specified, patch the table to discard 
  95.  * rather than display this material.
  96.  */
  97.  
  98. static void
  99. patchtable()
  100. {
  101.     struct tablerecd *tp;
  102.     char **p;
  103.     static char *discard[] = { "@menu", "@node", "@ifinfo", "@inforef", 0 };
  104.  
  105.     for (p = discard; *p != NULL; ++p)
  106.         if ((tp = lookup(*p)) != NULL) 
  107.         tp->type = DISCARD;
  108. }
  109.