henesyinit from p9fce6d0435 years agoHistory
1986 lines · 29.9 KB · C
RawDownload
typedef unsigned char Uchar;# include <stdio.h># define U(x) x# define NLSTATE yyprevious=YYNEWLINE# define BEGIN yybgin = yysvec + 1 +# define INITIAL 0# define YYLERR yysvec# define YYSTATE (yyestate-yysvec-1)# define YYOPTIM 1# define YYLMAX 200# define output(c) putc(c,yyout)# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}# define yymore() (yymorfg=1)# define ECHO fprintf(yyout, "%s",yytext)# define REJECT { nstr = yyreject(); goto yyfussy;}int yyleng; extern char yytext[];int yymorfg;extern Uchar *yysptr, yysbuf[];int yytchar;FILE *yyin = {stdin}, *yyout = {stdout};extern int yylineno;struct yysvf { 	struct yywork *yystoff;	struct yysvf *yyother;	int *yystops;};struct yysvf *yyestate;extern struct yysvf yysvec[], *yybgin;int yylook(void), yywrap(void), yyback(int *, int);#define A 2#define str 4#define sc 6#define reg 8#define comment 10/*Copyright (c) 1989 AT&T	All Rights Reserved THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T. The copyright notice above does not evidence anyactual or intended publication of such source code.*/ #undef	input	/* defeat lex */#undef	unput #include <stdlib.h>#include <string.h>#include "awk.h"#include "y.tab.h" extern YYSTYPE	yylval;extern int	infunc; int	lineno	= 1;int	bracecnt = 0;int	brackcnt  = 0;int	parencnt = 0;int	runecnt = 0; #ifdef	DEBUG#	define	RET(x)	{if(dbg)printf("lex %s [%s]\n", tokname(x), yytext); return(x); }#else#	define	RET(x)	return(x)#endif #define	CADD	cbuf[clen++] = yytext[0]; \		if (clen >= CBUFLEN-1) { \			ERROR "string/reg expr %.30s... too long", cbuf SYNTAX; \			BEGIN A; \		} uchar	cbuf[CBUFLEN];uchar	*s;int	clen, cflag;#define YYNEWLINE 10yylex(void){int nstr; extern int yyprevious;switch (yybgin-yysvec-1) {	/* witchcraft */	case 0:		BEGIN A;		break;	case sc:		BEGIN A;		RET('}');	}while((nstr = yylook()) >= 0)yyfussy: switch(nstr){case 0:if(yywrap()) return(0); break;case 1:	{ lineno++; RET(NL); }break;case 2:	{ ; }break;case 3:{ ; }break;case 4:	{ RET(';'); }break;case 5:{ lineno++; }break;case 6:{ RET(XBEGIN); }break;case 7:	{ RET(XEND); }break;case 8:{ if (infunc) ERROR "illegal nested function" SYNTAX; RET(FUNC); }break;case 9:{ if (!infunc) ERROR "return not in function" SYNTAX; RET(RETURN); }break;case 10:	{ RET(AND); }break;case 11:	{ RET(BOR); }break;case 12:	{ RET(NOT); }break;case 13:	{ yylval.i = NE; RET(NE); }break;case 14:	{ yylval.i = MATCH; RET(MATCHOP); }break;case 15:	{ yylval.i = NOTMATCH; RET(MATCHOP); }break;case 16:	{ yylval.i = LT; RET(LT); }break;case 17:	{ yylval.i = LE; RET(LE); }break;case 18:	{ yylval.i = EQ; RET(EQ); }break;case 19:	{ yylval.i = GE; RET(GE); }break;case 20:	{ yylval.i = GT; RET(GT); }break;case 21:	{ yylval.i = APPEND; RET(APPEND); }break;case 22:	{ yylval.i = INCR; RET(INCR); }break;case 23:	{ yylval.i = DECR; RET(DECR); }break;case 24:	{ yylval.i = ADDEQ; RET(ASGNOP); }break;case 25:	{ yylval.i = SUBEQ; RET(ASGNOP); }break;case 26:	{ yylval.i = MULTEQ; RET(ASGNOP); }break;case 27:	{ yylval.i = DIVEQ; RET(ASGNOP); }break;case 28:	{ yylval.i = MODEQ; RET(ASGNOP); }break;case 29:	{ yylval.i = POWEQ; RET(ASGNOP); }break;case 30:{ yylval.i = POWEQ; RET(ASGNOP); }break;case 31:	{ yylval.i = ASSIGN; RET(ASGNOP); }break;case 32:	{ RET(POWER); }break;case 33:	{ RET(POWER); }break;case 34:{ yylval.cp = fieldadr(atoi(yytext+1)); RET(FIELD); }break;case 35:{ unputstr("(NF)"); return(INDIRECT); }break;case 36:{ int c, n;		  c = input(); unput(c);		  if (c == '(' || c == '[' || infunc && (n=isarg(yytext+1)) >= 0) {			unputstr(yytext+1);			return(INDIRECT);		  } else {			yylval.cp = setsymtab(yytext+1,"",0.0,STR|NUM,symtab);			RET(IVAR);		  }		}break;case 37:	{ RET(INDIRECT); }break;case 38:	{ yylval.cp = setsymtab(yytext, "", 0.0, NUM, symtab); RET(VARNF); }break;case 39:{		  yylval.cp = setsymtab(yytext, tostring(yytext), atof(yytext), CON|NUM, symtab);		/* should this also have STR set? */		  RET(NUMBER); }break;case 40:{ RET(WHILE); }break;case 41:	{ RET(FOR); }break;case 42:	{ RET(DO); }break;case 43:	{ RET(IF); }break;case 44:	{ RET(ELSE); }break;case 45:	{ RET(NEXT); }break;case 46:	{ RET(EXIT); }break;case 47:{ RET(BREAK); }break;case 48:{ RET(CONTINUE); }break;case 49:{ yylval.i = PRINT; RET(PRINT); }break;case 50:{ yylval.i = PRINTF; RET(PRINTF); }break;case 51:{ yylval.i = SPRINTF; RET(SPRINTF); }break;case 52:{ yylval.i = SPLIT; RET(SPLIT); }break;case 53:{ RET(SUBSTR); }break;case 54:	{ yylval.i = SUB; RET(SUB); }break;case 55:	{ yylval.i = GSUB; RET(GSUB); }break;case 56:{ RET(INDEX); }break;case 57:{ RET(MATCHFCN); }break;case 58:	{ RET(IN); }break;case 59:{ RET(GETLINE); }break;case 60:{ RET(CLOSE); }break;case 61:{ RET(DELETE); }break;case 62:{ yylval.i = FLENGTH; RET(BLTIN); }break;case 63:	{ yylval.i = FLOG; RET(BLTIN); }break;case 64:	{ yylval.i = FINT; RET(BLTIN); }break;case 65:	{ yylval.i = FEXP; RET(BLTIN); }break;case 66:	{ yylval.i = FSQRT; RET(BLTIN); }break;case 67:	{ yylval.i = FSIN; RET(BLTIN); }break;case 68:	{ yylval.i = FCOS; RET(BLTIN); }break;case 69:{ yylval.i = FATAN; RET(BLTIN); }break;case 70:{ yylval.i = FSYSTEM; RET(BLTIN); }break;case 71:	{ yylval.i = FRAND; RET(BLTIN); }break;case 72:{ yylval.i = FSRAND; RET(BLTIN); }break;case 73:{ yylval.i = FTOUPPER; RET(BLTIN); }break;case 74:{ yylval.i = FTOLOWER; RET(BLTIN); }break;case 75:{ yylval.i = FFLUSH; RET(BLTIN); }break;case 76:{ yylval.i = FUTF; RET(BLTIN); }break;case 77:{ int n, c;		  c = input(); unput(c);	/* look for '(' */		  if (c != '(' && infunc && (n=isarg(yytext)) >= 0) {			yylval.i = n;			RET(ARG);		  } else {			yylval.cp = setsymtab(yytext,"",0.0,STR|NUM,symtab);			if (c == '(') {				RET(CALL);			} else {				RET(VAR);			}		  }		}break;case 78:	{ BEGIN str; clen = 0; }break;case 79:	{ if (--bracecnt < 0) ERROR "extra }" SYNTAX; BEGIN sc; RET(';'); }break;case 80:	{ if (--brackcnt < 0) ERROR "extra ]" SYNTAX; RET(']'); }break;case 81:	{ if (--parencnt < 0) ERROR "extra )" SYNTAX; RET(')'); }break;case 82:	{ if (yytext[0] == '{') bracecnt++;		  else if (yytext[0] == '[') brackcnt++;		  else if (yytext[0] == '(') parencnt++;		  RET(yylval.i = yytext[0]); /* everything else */ }break;case 83:{ cbuf[clen++] = '\\'; cbuf[clen++] = yytext[1]; }break;case 84:	{ ERROR "newline in regular expression %.10s...", cbuf SYNTAX; lineno++; BEGIN A; }break;case 85:{ BEGIN A;		  cbuf[clen] = 0;		  yylval.s = tostring(cbuf);		  unput('/');		  RET(REGEXPR); }break;case 86:	{ int uc, i;		  CADD;		  uc = *((uchar *)yytext)&0xFF;		  if (uc & 0x80) {			i = 0x40;			while (uc&i) {				cbuf[clen++] = input();				i >>= 1;		  	}		  }		}break;case 87:	{ BEGIN A;		  cbuf[clen] = 0; s = tostring(cbuf);		  cbuf[clen] = ' '; cbuf[++clen] = 0;		  yylval.cp = setsymtab(cbuf, s, 0.0, CON|STR, symtab);		  RET(STRING); }break;case 88:	{ ERROR "newline in string %.10s...", cbuf SYNTAX; lineno++; BEGIN A; }break;case 89:{ cbuf[clen++] = '"'; }break;case 90:{ cbuf[clen++] = '\n'; }break;case 91:{ cbuf[clen++] = '\t'; }break;case 92:{ cbuf[clen++] = '\f'; }break;case 93:{ cbuf[clen++] = '\r'; }break;case 94:{ cbuf[clen++] = '\b'; }break;case 95:{ cbuf[clen++] = '\v'; }break;case 96:{ cbuf[clen++] = '\007'; }break;case 97:{ cbuf[clen++] = '\\'; }break;case 98:{ int n;		  sscanf(yytext+1, "%o", &n); cbuf[clen++] = n; }break;case 99:{ int n;	/* ANSI permits any number! */		  sscanf(yytext+2, "%x", &n); cbuf[clen++] = n; }break;case 100:{ cbuf[clen++] = yytext[1]; }break;case 101:	{ int uc, i;		  CADD;		  uc = *((uchar *)yytext)&0xFF;		  if (uc & 0x80) {			i = 0x40;			while (uc&i) {				cbuf[clen++] = input();				i >>= 1;		  	}		  }		}break;case -1:break;default:fprintf(yyout,"bad switch yylook %d",nstr);} return(0); }/* end of yylex */ void startreg(void)	/* start parsing a regular expression */{	BEGIN reg;	clen = 0;} /* input() and unput() are transcriptions of the standard lex   macros for input and output with additions for error message   printing.  God help us all if someone changes how lex works.*/ uchar	ebuf[300];uchar	*ep = ebuf; input(void)	/* get next lexical input character */{	register int c;	extern uchar *lexprog; 	if (yysptr > yysbuf)		c = U(*--yysptr)&0xff;	else if (lexprog != NULL) {	/* awk '...' */		if (c = (*lexprog&0xff))			lexprog++;	} else				/* awk -f ... */		c = pgetc();	if (c == '\n')		yylineno++;	else if (c == EOF)		c = 0;	if (ep >= ebuf + sizeof ebuf)		ep = ebuf;	c &= 0xFF;	*ep++ = c;	return c;} void unput(int c)	/* put lexical character back on input */{	yytchar = c;	if (yytchar == '\n')

Lines 1–500 of 1986.