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 / items.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-12  |  2.5 KB  |  123 lines

  1. /*
  2.  * items.c - handles itemized list commands (formerly part of translate.c)
  3.  *        Release 2.0    January 1990
  4.  *
  5.  * Copyright 1988, 1989, 1990  Beverly A.Erlebacher
  6.  * erlebach@cs.toronto.edu    ...uunet!utai!erlebach
  7.  *
  8.  */
  9.  
  10. #include <stdio.h> 
  11. #include "texi2roff.h"
  12.  
  13. #define ITEMIZE        0
  14. #define ENUMERATE   1
  15. #define TABLE        2
  16. #define APPLY        3
  17.  
  18. #define MAXILEVEL    10
  19. int  icount[MAXILEVEL];
  20. int  what[MAXILEVEL];
  21. char item[MAXILEVEL][MAXLINELEN];
  22.  
  23. extern int  ilevel;
  24. extern char * gettoken();
  25. extern char * eatwhitespace();
  26. extern void errormsg();
  27. extern struct tablerecd * lookup();
  28.  
  29. /*
  30.  * itemize - handle the itemizing start commands @enumerate, @itemize
  31.  *    and @table
  32.  */
  33.  
  34. char * itemize(s, token)
  35. char * s;
  36. char * token;
  37. {
  38.     char *tag;
  39.  
  40.     tag = item[ilevel];
  41.     if (STREQ(token,"@itemize")) {
  42.     what[ilevel] = ITEMIZE;
  43.     s = gettoken(eatwhitespace(s),tag);
  44.     if (*tag == '\n') { /* this is an error in the input */
  45.         --s;
  46.         *tag = '-';
  47.         errormsg("missing itemizing argument ","");
  48.     } else {
  49.         if (*tag =='@') {
  50.         if ((lookup(tag)==NULL) && (lookup(strcat(tag,"{"))==NULL))
  51.              errormsg("unrecognized itemizing argument ",tag);
  52.         else
  53.             if (*(tag + strlen(tag) - 1) == '{')
  54.                 (void) strcat(tag,"}");
  55.         }
  56.     }
  57.     (void) strcat(tag, " ");
  58.     } else if (STREQ(token,"@enumerate")) {
  59.     what[ilevel] = ENUMERATE;
  60.     icount[ilevel] = 1;
  61.     } else if (STREQ(token,"@table")) {
  62.     what[ilevel] = TABLE;
  63.     s = gettoken(eatwhitespace(s),tag);
  64.     if (*tag == '\n') {
  65.         *tag = '\0';  /* do nothing special */
  66.         --s;
  67.     } else {
  68.         if (*tag =='@') {
  69.         if ((lookup(tag)==NULL) && (lookup(strcat(tag,"{"))==NULL))
  70.             errormsg("unrecognized itemizing argument ",tag);
  71.         else {
  72.             what[ilevel] = APPLY;
  73.             if (*(tag + strlen(tag) - 1) != '{')
  74.                 (void) strcat(tag,"{");
  75.         }
  76.         }
  77.     }
  78.     }
  79.     while (*s != '\n' && *s != '\0') 
  80.     ++s;  /* flush rest of line */
  81.     return s;
  82. }
  83.  
  84. /*
  85.  * doitem - handle @item and @itemx
  86.  */
  87.  
  88. char *
  89. doitem(s, tag)
  90. char * s;
  91. char *tag;
  92. {
  93.     switch (what[ilevel]) {
  94.     case ITEMIZE:
  95.     (void) strcpy(tag, item[ilevel]);
  96.     break;
  97.     case ENUMERATE:
  98.     (void) sprintf(tag, "%d.", icount[ilevel]++);
  99.     break;
  100.     case TABLE:
  101.     s = eatwhitespace(s);
  102.     if (*s == '\n') {
  103.         *tag++ = '-';
  104.         errormsg("missing table item tag","");
  105.     } else 
  106.         while(*s != '\n')
  107.         *tag++ = *s++;
  108.     *tag = '\0';
  109.     break;
  110.     case APPLY:
  111.     *tag = '\0';
  112.     (void) strcat(tag,item[ilevel]);
  113.     tag += strlen(tag);
  114.     s = eatwhitespace(s);
  115.     while(*s != '\n')
  116.         *tag++ = *s++;
  117.     *tag++ = '}';
  118.     *tag = '\0';
  119.     break;
  120.     }
  121.     return s;
  122. }
  123.