1: # include   <stdio.h>
   2: # include   "constants.h"
   3: # include   "globals.h"
   4: # include   <sccs.h>
   5: 
   6: SCCSID(@(#)comment.c	8.1	12/31/84)
   7: 
   8: 
   9: /*
  10: **  COMMENT.C -- routine to scan comments inside an equel statement
  11: **
  12: **	Uses the endcmnt token code to find the endcmnt
  13: **	terminal string, then reads the input until it sees this
  14: **	terminal (must be <= 2 characters), returning EOF_TOK and
  15: **	giving an error diagnostic if end-of-file is encountered.
  16: **
  17: **	Parameters:
  18: **		none
  19: **
  20: **	Returns:
  21: **		CONTINUE -- valid comment
  22: **		EOF_TOK -- EOF in comment
  23: **
  24: **	Side Effects:
  25: **		deletes comments from within an equel statement
  26: */
  27: 
  28: 
  29: comment()
  30: {
  31:     register int        i, l;
  32:     register struct optab   *op;
  33:     char            buf [3];
  34: 
  35:     /* find end of comment operator */
  36:     for (op = Optab; op->op_term; op++)
  37:         if (op->op_token == Tokens.sp_endcmnt)
  38:             break;
  39: 
  40:     if (!op->op_term)
  41:         syserr("no end of comment operator in the parse tables");
  42:     /* scan for the end of comment */
  43:     l = length(op->op_term);
  44:     if (l > sizeof buf - 1)
  45:         syserr("comment : buf too short for endcmnt %s %d",
  46:         op->op_term, l);
  47: 
  48:     /* fill buffer to length of endmnt terminal */
  49:     for (i = 0; i < l; i++)
  50:     {
  51:         if ((buf [i] = getch()) == EOF_TOK)
  52:         {
  53: nontermcom :
  54:             /* non-terminated comment */
  55:             yysemerr("premature EOF encountered in comment", 0);
  56:             return (EOF_TOK);
  57:         }
  58:     }
  59: 
  60:     /* shift on input until endcmnt */
  61:     while (!bequal(buf, op->op_term, l))
  62:     {
  63:         for (i = 0; i < l - 1; i++)
  64:             buf [i] = buf [i + 1];
  65:         if ((buf [l - 1] = getch()) == EOF_TOK)
  66:             goto nontermcom;
  67:     }
  68:     return (CONTINUE);
  69: }

Defined functions

comment defined in line 6; used 1 times
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 824
Valid CSS Valid XHTML 1.0 Strict