home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume3 / texchk / part2 / verbatim.c < prev   
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.4 KB  |  116 lines

  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. #ifdef TMC
  5. #include <ctools.h>
  6. #else
  7. #include "ctools.h"
  8. #endif
  9.  
  10. #include "texchk.h"
  11.  
  12. extern Bool Verbose_Mode;
  13.  
  14. do_verbatim (keyword) char *keyword;
  15. {
  16.   if (0 == strcmp("verbatim",keyword))
  17.      find_end_verbatim("\\end{verbatim}");
  18.   else if (0 == strcmp("verbatim*",keyword))        
  19.      find_end_verbatim("\\end{verbatim*}");
  20.   else {
  21.      fprintf(stderr,"Fatal error, bad argument to do_verbatim: %s\n",keyword);
  22.      exit(1);
  23.   }
  24.   if (Verbose_Mode) {
  25.      do_indent(--Indent_Level);
  26.      fprintf(stderr,"line %d: \\end{%s}\n",Current_Line,keyword);
  27.   }
  28. }
  29.  
  30.  
  31. do_verb () 
  32.  
  33. /* get the next character after the 'verb' or 'verb*' command, then read */
  34. /* until we find that character again. */
  35.  
  36. {
  37.   char endchar[2];
  38.   int ch;
  39.   ch = get_a_char();
  40.   if (ch == EOF) {
  41.      eof_verbatim_error();
  42.      exit(1);
  43.   }
  44.   else if (isalpha(ch) || ch == '*' || ch == ' ' || ch == '\n') {
  45.      verb_error(ch);
  46.      exit(1);
  47.   }
  48.   endchar[0] = ch;
  49.   endchar[1] = '\0';
  50.   find_end_verbatim(endchar);
  51. }
  52.  
  53.  
  54. find_end_verbatim (matchstring) char *matchstring;
  55.  
  56. /* Read characters until the exact characters constituting matchstring show */
  57. /* up in the input stream, then return.  Matchstring may not contain '\n' */
  58.  
  59. {
  60.   static char Verbatim_Buffer[MAXLL];
  61.   char *vbptr;
  62.   int j,ch;
  63.   int matchlen;
  64.   
  65.   matchlen = strlen(matchstring);
  66.   
  67.   /* matches cannot span lines, since matchstring cannot contain '\n' */
  68.   
  69.   newline:
  70.   
  71.   for (j = 0; j < MAXLL; j++) Verbatim_Buffer[j] = '\0';
  72.   vbptr = Verbatim_Buffer; 
  73.   
  74.   /* Nothing can possibly match until we have read in as many characters as */
  75.   /* there are in matchstring, so read that many in. */
  76.   
  77.   for (j = 0; j < matchlen; j++) {
  78.       switch (ch = get_a_char()) {
  79.         case '\n' :
  80.           goto newline;
  81.           break;
  82.         case EOF :
  83.           eof_verbatim_error();
  84.           exit(1);
  85.           break;
  86.         default :
  87.           Verbatim_Buffer[j] = ch;
  88.           break;
  89.       }
  90.   }
  91.  
  92.   /* check for a match, then read in the next character.  Keep checking */
  93.   /* for a match against the last 'matchlen' characters. */
  94.   
  95.   j = matchlen;
  96.   while (1) {
  97.     if (0 == strcmp(matchstring,vbptr)) {
  98.        return(1);
  99.     }
  100.     switch (ch = get_a_char()) {
  101.       case '\n' :
  102.         goto newline;
  103.         break;
  104.       case EOF :
  105.         eof_verbatim_error();
  106.         exit(1);
  107.         break;
  108.       default :
  109.         Verbatim_Buffer[j] = ch;
  110.         break;
  111.     }
  112.     j++;
  113.     vbptr++;
  114.   }
  115. }
  116.