Annotation of 42BSD/ingres/source/equel/name.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(@(#)name.c      7.1     2/5/81)
                      8: 
                      9: 
                     10: /*
                     11: **  NAME -- Process an identifier or keyword token.
                     12: **
                     13: **     Name gets the identifier that follows in the std.
                     14: **     input, and checks if it is a keyword.
                     15: **     An identifier is defined as a sequence of
                     16: **     MAXNAME or fewer alphanumerics, starting with an
                     17: **     alphabetic character.
                     18: **
                     19: **     Parameters:
                     20: **             chr - the first character of the identifier
                     21: **
                     22: **     Returns:
                     23: **             Tokens.sp_name - for a user-defined name
                     24: **             Tokens.sp_struct_var -- if the name is declared 
                     25: **                     a structurw variable
                     26: **             other - lexical codes for keys
                     27: **
                     28: **     Side Effects:
                     29: **             Adds a token to the symbol space.
                     30: **             yylval is set to the new node in the space.
                     31: **             If the identifier is a keyword, sets Opcode to
                     32: **             op_code from tokens.y.
                     33: */
                     34: 
                     35: name(chr)
                     36: char           chr;
                     37: {
                     38:        int                     lval;
                     39:        register                i;
                     40:        char                    wbuf [MAXNAME + 1];
                     41:        register char           *cp;
                     42:        register char           c;
                     43:        struct optab            *op;
                     44:        struct optab            *getkey();
                     45:        struct cvar             *getcvar();
                     46: 
                     47:        c = chr;
                     48:        cp = wbuf;
                     49:        for (i = 0; i <= MAXNAME; i++)
                     50:        {
                     51:                lval = Cmap [c];
                     52:                if (i < MAXNAME &&
                     53:                   (lval == ALPHA || lval == NUMBR))
                     54:                {
                     55:                        *cp++ = c;
                     56:                        c = getch();
                     57:                }
                     58:                else if (lval == ALPHA || lval == NUMBR)
                     59:                {
                     60:                        /* {i == MAXNAME && "c is legal" && 
                     61:                         *  cp == &wbuf [MAXNAME]} 
                     62:                         */
                     63:                        *cp = '\0';
                     64:                        yysemerr("name too long", wbuf);
                     65:                        /* chomp to end of identifier */
                     66: 
                     67:                        do
                     68:                        {
                     69:                                c = getch();
                     70:                                lval = Cmap [c];
                     71:                        }  while (lval == ALPHA || lval == NUMBR);
                     72:                        backup(c);
                     73:                        
                     74:                        /* take first MAXNAME characters as IDENTIFIER 
                     75:                         * (non-key)
                     76:                         */
                     77:                        yylval.u_dn = addsym(salloc(wbuf));
                     78:                        return (Tokens.sp_name);
                     79:                }
                     80:                else
                     81:                {
                     82:                        /* {cp <= &wbuf [MAXNAME] && i <= MAXNAME
                     83:                         * && "c is not part of id"}
                     84:                         */
                     85:                        backup(c);
                     86:                        *cp = '\0';
                     87:                        i = 0;
                     88:                        break;
                     89:                }
                     90:        }
                     91:        op = getkey(wbuf);
                     92: 
                     93:        /* Is it a keyword ? */
                     94:        if (op)
                     95:        {
                     96:                yylval.u_dn = addsym(op->op_term);
                     97:                Opcode = op->op_code;
                     98:                return (op->op_token);
                     99:        }
                    100:        /* user-defined name */
                    101:        yylval.u_dn = addsym(salloc(wbuf));
                    102:        if (getcvar(wbuf)->c_type == opSTRUCT)
                    103:                return(Tokens.sp_struct_var);
                    104:        return (Tokens.sp_name);
                    105: }

unix.superglobalmegacorp.com

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