home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 211.lha / Spiff / comment.c < prev    next >
C/C++ Source or Header  |  1996-02-14  |  5KB  |  308 lines

  1. /*                        Copyright (c) 1988 Bellcore
  2. **                            All Rights Reserved
  3. **       Permission is granted to copy or use this program, EXCEPT that it
  4. **       may not be sold for profit, the copyright notice must be reproduced
  5. **       on copies, and credit should be given to Bellcore where it is due.
  6. **       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7. */
  8.  
  9.  
  10. #ifndef lint
  11. static char rcsid[]= "$Header: comment.c,v 1.1 88/09/15 11:33:58 daniel Rel $";
  12. #endif
  13.  
  14.  
  15. #include "misc.h"
  16. #include "comment.h"
  17. #include "strings.h"
  18.  
  19. /*
  20. **    storage for the comment specifiers that can appear
  21. **        anywhere on a line
  22. */
  23. static int _W_nextcom = 0;
  24. _W_comstruct _W_coms[_W_COMMAX];
  25.  
  26. /*
  27. **    storage for comment specifiers that are examined only at the
  28. **        beginning of each line
  29. */
  30. static int _W_nextbol = 0;
  31. _W_bolstruct _W_bols[_W_BOLMAX];
  32.  
  33. /*
  34. **    storage for delimiters of literal strings
  35. */
  36. static int _W_nextlit = 0;
  37. _W_litstruct _W_lits[_W_LITMAX];
  38.  
  39. /*
  40. **    storage for characters to specify beginning and end of line
  41. **    in the comment and literal commands
  42. */
  43. char _W_bolchar = '^';
  44. char _W_eolchar = '$';
  45.  
  46.  
  47. /*
  48. **    build up a list of comment delimiters
  49. */
  50. void
  51. W_addcom(str,nestflag)
  52. char *str;
  53. int nestflag;
  54. {
  55.     /*
  56.     **    check for comments that begin at the beginning of line
  57.     */
  58.     if (*str ==  _W_bolchar)
  59.     {
  60.         if (_W_nextbol >= _W_BOLMAX)
  61.             Z_fatal("too many beginning of line comment delimiter sets");
  62.  
  63.         str++;    /*skip the bol char */
  64.         S_wordcpy(_W_bols[_W_nextbol].begin,str);
  65.  
  66.         S_nextword(&str);
  67.  
  68.         if (*str == _W_eolchar)
  69.         {
  70.             (void) strcpy(_W_bols[_W_nextbol].end,"\n");
  71.         }
  72.         else
  73.         {
  74.             S_wordcpy(_W_bols[_W_nextbol].end,str);
  75.         }
  76.  
  77.         S_nextword(&str);
  78.         S_wordcpy(_W_bols[_W_nextbol].escape,str);
  79.  
  80.         /*
  81.         **
  82.         */
  83.         if (nestflag)
  84.             Z_complain("begining of line comment won't nest");
  85.  
  86.         _W_nextbol++;
  87.     }
  88.     else
  89.     {
  90.         if (_W_nextcom >= _W_COMMAX)
  91.             Z_fatal("too many comment delimiter sets");
  92.  
  93.         S_wordcpy(_W_coms[_W_nextcom].begin,str);
  94.  
  95.         S_nextword(&str);
  96.  
  97.         if (*str == _W_eolchar)
  98.         {
  99.             (void) strcpy(_W_coms[_W_nextbol].end,"\n");
  100.         }
  101.         else
  102.         {
  103.             S_wordcpy(_W_coms[_W_nextbol].end,str);
  104.         }
  105.  
  106.         S_nextword(&str);
  107.         S_wordcpy(_W_coms[_W_nextcom].escape,str);
  108.  
  109.         _W_coms[_W_nextcom].nestbit = nestflag;
  110.  
  111.         _W_nextcom++;
  112.     }
  113.     return;
  114. }
  115.  
  116.  
  117. /*
  118. **    clear the comment delimiter storage
  119. */
  120. void
  121. W_clearcoms()
  122. {
  123.     _W_nextcom = 0;
  124.     _W_nextbol = 0;
  125.     return;
  126. }
  127.  
  128. /*
  129. **    build up the list of literal delimiters
  130. */
  131. void
  132. W_addlit(str)
  133. char *str;
  134. {
  135.     if (_W_nextlit >= _W_LITMAX)
  136.         Z_fatal("too many literal delimiter sets");
  137.  
  138.     S_wordcpy(_W_lits[_W_nextlit].begin,str);
  139.  
  140.     S_nextword(&str);
  141.     S_wordcpy(_W_lits[_W_nextlit].end,str);
  142.  
  143.     S_nextword(&str);
  144.     S_wordcpy(_W_lits[_W_nextlit].escape,str);
  145.  
  146.     _W_nextlit++;
  147.     return;
  148. }
  149.  
  150. /*
  151. **    clear the literal delimiter storage
  152. */
  153. void
  154. W_clearlits()
  155. {
  156.     _W_nextlit = 0;
  157.     return;
  158. }
  159.  
  160.  
  161.  
  162. static _W_bolstruct bol_scratch;
  163.  
  164. static void
  165. _W_copybol(to,from)
  166. W_bol to,from;
  167. {
  168.     (void) strcpy(to->begin,from->begin);
  169.     (void) strcpy(to->end,from->end);
  170.     (void) strcpy(to->escape,from->escape);
  171. }
  172.  
  173. W_bol
  174. W_isbol(str)
  175. char *str;
  176. {
  177.     int i;
  178.  
  179.     for(i=0;i<_W_nextbol;i++)
  180.     {
  181.         if(!S_wordcmp(str,_W_bols[i].begin))
  182.         {
  183.             _W_copybol(&bol_scratch,&_W_bols[i]);
  184.             return(&bol_scratch);
  185.         }
  186.     }
  187.     return(W_BOLNULL);
  188. }
  189.  
  190. W_is_bol(ptr)
  191. W_bol ptr;
  192. {
  193.     int i;
  194.  
  195.     for(i=0;i<_W_nextbol;i++)
  196.     {
  197.         if(!S_wordcmp(ptr->begin,_W_bols[i].begin) &&
  198.             !S_wordcmp(ptr->end,_W_bols[i].end) &&
  199.             !S_wordcmp(ptr->escape,_W_bols[i].escape))
  200.         {
  201.             return(1);
  202.         }
  203.  
  204.     }
  205.     return(0);
  206. }
  207.  
  208.  
  209. static _W_litstruct lit_scratch;
  210.  
  211. static void
  212. _W_copylit(to,from)
  213. W_lit to,from;
  214. {
  215.     (void) strcpy(to->begin,from->begin);
  216.     (void) strcpy(to->end,from->end);
  217.     (void) strcpy(to->escape,from->escape);
  218. }
  219.  
  220. W_lit
  221. W_islit(str)
  222. char *str;
  223. {
  224.     int i;
  225.  
  226.     for(i=0;i<_W_nextlit;i++)
  227.     {
  228.         if(!S_wordcmp(str,_W_lits[i].begin))
  229.         {
  230.             _W_copylit(&lit_scratch,&_W_lits[i]);
  231.             return(&lit_scratch);
  232.         }
  233.     }
  234.     return(W_LITNULL);
  235. }
  236.  
  237. W_is_lit(ptr)
  238. W_lit ptr;
  239. {
  240.     int i;
  241.  
  242.     for(i=0;i<_W_nextlit;i++)
  243.     {
  244.         if(!S_wordcmp(ptr->begin,_W_lits[i].begin) &&
  245.             !S_wordcmp(ptr->end,_W_lits[i].end) &&
  246.             !S_wordcmp(ptr->escape,_W_lits[i].escape))
  247.         {
  248.             return(1);
  249.         }
  250.  
  251.     }
  252.     return(0);
  253. }
  254.  
  255. static _W_comstruct com_scratch;
  256.  
  257. static void
  258. _W_copycom(to,from)
  259. W_com to,from;
  260. {
  261.     (void) strcpy(to->begin,from->begin);
  262.     (void) strcpy(to->end,from->end);
  263.     (void) strcpy(to->escape,from->escape);
  264.     to->nestbit = from->nestbit;
  265. }
  266.  
  267. W_com
  268. W_iscom(str)
  269. char *str;
  270. {
  271.     int i;
  272.  
  273.     for(i=0;i<_W_nextcom;i++)
  274.     {
  275.         if(!S_wordcmp(str,_W_coms[i].begin))
  276.         {
  277.             _W_copycom(&com_scratch,&_W_coms[i]);
  278.             return(&com_scratch);
  279.         }
  280.     }
  281.     return(W_COMNULL);
  282. }
  283.  
  284. W_is_com(ptr)
  285. W_com ptr;
  286. {
  287.     int i;
  288.  
  289.     for(i=0;i<_W_nextcom;i++)
  290.     {
  291.         if(!S_wordcmp(ptr->begin,_W_coms[i].begin) &&
  292.             !S_wordcmp(ptr->end,_W_coms[i].end) &&
  293.             !S_wordcmp(ptr->escape,_W_coms[i].escape) &&
  294.             ptr->nestbit == _W_coms[i].nestbit)
  295.         {
  296.             return(1);
  297.         }
  298.  
  299.     }
  300.     return(0);
  301. }
  302.  
  303. W_is_nesting(ptr)
  304. W_com ptr;
  305. {
  306.     return(ptr->nestbit);
  307. }
  308.