Annotation of 43BSD/ingres/source/equel/string.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.