1: #
   2: # include   <stdio.h>
   3: 
   4: # include   "constants.h"
   5: # include   "globals.h"
   6: 
   7: /*
   8: **  STRING -- processes a string constant
   9: **	Strings are kept internally exactly as their external
  10: **	appearance, except for the outermost '"'.
  11: **	A string may be at most MAXSTRING characters
  12: **	long, and may have escaped newlines.
  13: **
  14: **	Parameters:
  15: **		op -- pointer to string quote operator
  16: **			table entry.
  17: **
  18: **	Returns:
  19: **		SCONST
  20: **
  21: **	Called By:
  22: **		operator() -- [operator.c]
  23: **
  24: **	History:
  25: **		6/1/78 -- (marc) written
  26: **
  27: */
  28: 
  29: 
  30: string(op)
  31: struct optab    *op;
  32: {
  33:     char        buf [MAXSTRING + 1];
  34:     register char   c, *cp;
  35:     int     error;
  36:     register int    escape;
  37: 
  38:     error = escape = 0;
  39:     cp = buf;
  40:     for ( ; ; )
  41:     {
  42:         c = getch();
  43:         switch (c)
  44:         {
  45: 
  46:           case '\\' :
  47:             if (!escape)
  48:                 escape = 2;
  49:             goto regchar;
  50: 
  51:           case '\n' :
  52:             if (escape)
  53:                 goto regchar;
  54:             *cp = '\0';
  55:             yysemerr("non-terminated string",
  56:               !error ? buf : 0);
  57:             break;
  58: 
  59:           case EOF_TOK :
  60:             backup(c);
  61:             *cp = '\0';
  62:             yysemerr("EOF in string",
  63:               !error ? buf : 0);
  64:             break;
  65: 
  66:           default :
  67: regchar :
  68:             if (c == *op->op_term && !escape)
  69:             {
  70:                 /* end of string */
  71:                 *cp = '\0';
  72:                 break;
  73:             }
  74:             if (!error)
  75:             {
  76:                 if (cp - buf < MAXSTRING)
  77:                 {
  78:                     if (Cmap [c] == CNTRL)
  79:                         yysemerr("control character in string eliminated",
  80:                         0);
  81:                     else
  82:                         *cp++ = c;
  83:                 }
  84:                 else
  85:                 {
  86:                     yysemerr("string too long, rest discarded",
  87:                     0);
  88:                     error = 1;
  89:                 }
  90:             }
  91:             if (escape)
  92:                 --escape;
  93:             continue;
  94:         }
  95:         break;
  96:     }
  97:     yylval = addsym(salloc(buf));
  98:     return (Tokens.sp_sconst);
  99: }

Defined functions

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