1: #
   2: /*
   3: **  COMMENT.C -- routine to scan comments inside an equel statement
   4: **
   5: **	Uses the endcmnt token code to find the endcmnt
   6: **	terminal string, then reads the input until it sees this
   7: **	terminal (must be <= 2 characters), returning EOF_TOK and
   8: **	giving an error diagnostic if end-of-file is encountered.
   9: **
  10: **	Parameters:
  11: **		none
  12: **
  13: **	Returns:
  14: **		CONTINUE -- valid comment
  15: **		EOF_TOK -- EOF in comment
  16: **
  17: **	Side Effects:
  18: **		deletes comments from within an equel statement
  19: **
  20: **	Defines:
  21: **		comment()
  22: **
  23: **	Requires:
  24: **		Optab -- for endcomment terminal
  25: **		Tokens -- for endcmnt token code
  26: **		bequal()
  27: **		getch()
  28: **		sequal()
  29: **		yysemerr()
  30: **		syserr()
  31: **
  32: **	Called By:
  33: **		operator()
  34: **
  35: **	Files:
  36: **		"globals.h" -- for globals
  37: **		"constants.h" -- for constants
  38: **
  39: **	Diagnostics:
  40: **		"premature EOF encountered in comment"
  41: **
  42: **	Syserrs:
  43: **		"no end of comment operator in the parse tables" --
  44: **			"end-of-comment" missing from Optab
  45: **		"buf too short for endcmnt %s %d" --
  46: **			the ENDCMNT token is longer than can fit in buf
  47: **
  48: **	History:
  49: **		5/31/78 -- (marc) modified for equel from
  50: **			rick's quel comment routine.
  51: */
  52: 
  53: # include   <stdio.h>
  54: 
  55: # include   "constants.h"
  56: # include   "globals.h"
  57: 
  58: comment()
  59: {
  60:     register int        i, l;
  61:     register struct optab   *op;
  62:     char            buf [3];
  63: 
  64:     /* find end of comment operator */
  65:     for (op = Optab; op->op_term; op++)
  66:         if (op->op_token == Tokens.sp_endcmnt)
  67:             break;
  68: 
  69:     if (!op->op_term)
  70:         syserr("no end of comment operator in the parse tables");
  71:     /* scan for the end of comment */
  72:     l = length(op->op_term);
  73:     if (l > sizeof buf - 1)
  74:         syserr("comment : buf too short for endcmnt %s %d",
  75:         op->op_term, l);
  76: 
  77:     /* fill buffer to length of endmnt terminal */
  78:     for (i = 0; i < l; i++)
  79:     {
  80:         if ((buf [i] = getch()) == EOF_TOK)
  81:         {
  82: nontermcom :
  83:             /* non-terminated comment */
  84:             yysemerr("premature EOF encountered in comment", 0);
  85:             return (EOF_TOK);
  86:         }
  87:     }
  88: 
  89:     /* shift on input until endcmnt */
  90:     while (!bequal(buf, op->op_term, l))
  91:     {
  92:         for (i = 0; i < l - 1; i++)
  93:             buf [i] = buf [i + 1];
  94:         if ((buf [l - 1] = getch()) == EOF_TOK)
  95:             goto nontermcom;
  96:     }
  97:     return (CONTINUE);
  98: }

Defined functions

comment defined in line 58; used 1 times
Last modified: 1995-02-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2326
Valid CSS Valid XHTML 1.0 Strict