Annotation of 42BSD/ingres/source/parser/s_string.c, revision 1.1.1.1

1.1       root        1: # include <ingres.h>
                      2: # include "scanner.h"
                      3: # include      <sccs.h>
                      4: 
                      5: SCCSID(@(#)s_string.c  7.2     5/4/83)
                      6: 
                      7: /*
                      8: ** STRING
                      9: ** A string is defined as any sequence of MAXSTRING or fewer characters,
                     10: ** surrounded by string delimiters.  New-line ;characters are purged
                     11: ** from strings unless preceeded by a '\'; QUOTE's must be similarly
                     12: ** prefixed in order to be correctly inserted within a string.  Each
                     13: ** string is entered in the symbol table, indexed by 'yylval'.  A
                     14: ** token or the error condition -1 is returned.
                     15: */
                     16: string(op)
                     17: struct optab   *op;
                     18: {
                     19:        extern char     Cmap[];
                     20:        extern char     *yylval;
                     21:        extern char     *syment();
                     22:        register int    esc;
                     23:        register int    save;
                     24:        register char   *ptr;
                     25:        char            buf[MAXSTRING + 1];
                     26: 
                     27:        /* disable case conversion and fill in string */
                     28:        ptr = buf;
                     29:        save = Lcase;
                     30:        Lcase = 0;
                     31:        do
                     32:        {
                     33:                /* get next character */
                     34:                if ((*ptr = get_scan(NORMAL)) <= 0)
                     35:                {
                     36:                        Lcase = save;
                     37:                        /* non term string */
                     38:                        par_error(STRTERM, FATAL, 0);
                     39:                }
                     40: 
                     41:                /* handle escape characters */
                     42:                esc = (*ptr == '\\');
                     43:                if (*ptr == '\n')
                     44:                {
                     45:                        if ((*ptr = get_scan(NORMAL)) <= 0)
                     46:                        {
                     47:                                Lcase = save;
                     48:                                *ptr = 0;
                     49:                                /* non term string */
                     50:                                par_error(STRTERM, FATAL, 0);
                     51:                        }
                     52:                }
                     53:                if (esc == 1)
                     54:                {
                     55:                        if ((*++ptr = get_scan(NORMAL)) <= 0)
                     56:                        {
                     57:                                Lcase = save;
                     58:                                *ptr = 0;
                     59:                                /* non term string */
                     60:                                par_error(STRTERM, FATAL, 0);
                     61:                        }
                     62:                        if (*ptr == *(op->term))
                     63:                                *--ptr = *(op->term);
                     64:                }
                     65: 
                     66:                /* check length */
                     67:                if ((ptr - buf) > MAXSTRING - 1)
                     68:                {
                     69:                        Lcase = save;
                     70:                        /* string too long */
                     71:                        par_error(STRLONG, WARN, 0);
                     72:                }
                     73:                if (Cmap[*ptr] == CNTRL)
                     74:                        /* cntrl in string from equel */
                     75:                        par_error(CNTRLCHR, WARN, 0);
                     76:        } while (*ptr++ != *(op->term) || esc == 1);
                     77: 
                     78:        /* restore case conversion and return */
                     79:        *--ptr = '\0';
                     80:        Lcase = save;
                     81: #      ifdef   xSTR2
                     82:        tTfp(71, 8, "STRING: %s\n", buf);
                     83: #      endif
                     84:        yylval = syment(buf, (ptr - buf) + 1);
                     85:        Lastok.tok = yylval;
                     86:        Lastok.toktyp = Tokens.sconst;
                     87:        return (Tokens.sconst);
                     88: }

unix.superglobalmegacorp.com

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