main lex.c
  1#define W(x) (x==' ' || x=='\t' || x=='\n')
  2#define L(x) ('a'<=x&&x<='z')||('A'<=x&&x<='Z')
  3#define D(x) ('0'<=x&&x<='9')
  4#define S(x) (x=='/'||x=='.'||x=='?'||x=='*'||x=='['||x=='-'||x==']'||x=='_')
  5#define NONTERM(x) (x!='\0'&&x!='\n'&&x!=' '&&x!='\t'&&x!=':'&&x!=';'&&x!='&'&&x!='>')
  6
  7char *zznextc;	/* zero if need another line; otherwise points to next char */
  8int yylineno;
  9extern FILE *fin;
 10
 11yylex()
 12{
 13register char *p;
 14register char *q;
 15char word[YYLMAX];
 16
 17if(zznextc == 0)
 18	return( nextlin() );
 19
 20while(W(*zznextc)) ++zznextc;
 21
 22if(*zznextc == '\0')
 23	return( nextlin() );
 24
 25if(*zznextc == ':')
 26	{
 27	if(*++zznextc == ':')
 28		{
 29		++zznextc;
 30		return(DOUBLECOLON);
 31		}
 32	else	return(COLON);
 33	}
 34
 35if(*zznextc == '>')
 36	{
 37	++zznextc;
 38	return(GREATER);
 39	}
 40
 41if(*zznextc == ';')
 42	return( retsh(zznextc) );
 43
 44p = zznextc;
 45q = word;
 46
 47while(NONTERM(*p))
 48	*q++ = *p++;
 49
 50if(p != zznextc)
 51	{
 52	*q = '\0';
 53	if((yylval=srchname(word))==0)
 54		yylval = makename(word);
 55	zznextc = p;
 56	return(NAME);
 57	}
 58
 59else	{
 60	fprintf(stderr,"Bad character %c (octal %o), line %d",
 61		*zznextc,*zznextc,yylineno);
 62	fatal("");
 63	}
 64return(0);	/* never executed */
 65}
 66
 67
 68
 69
 70
 71retsh(q)
 72char *q;
 73{
 74register char *p;
 75struct shblock *sp;
 76char *copys();
 77
 78for(p=q+1 ; *p==' '||*p=='\t' ; ++p)  ;
 79
 80sp = intalloc(sizeof(*sp));
 81sp->nextp = 0;
 82sp->shbp = (fin == NULL ? p : copys(p) );
 83yylval = sp;
 84zznextc = 0;
 85return(SHELLINE);
 86}
 87
 88nextlin()
 89{
 90static char yytext[YYLMAX];
 91static char *yytextl = yytext+YYLMAX;
 92char *text, templin[YYLMAX];
 93register char c;
 94register char *p, *t;
 95char lastch, *lastchp;
 96extern char **linesptr;
 97int incom;
 98
 99incom = 0;
100zznextc = 0;
101
102if(fin == NULL)
103	{
104	char *src;
105	if( (src = *linesptr++) == 0)
106		return(0);
107	++yylineno;
108	for(p=yytext; p<yytextl && (*p = *src++); ++p) ;
109	*p = '\0';
110	text = yytext;
111	}
112
113else	{
114	for(p=yytext ; ; ++p)
115		{
116		if(p > yytextl) fatal("line too long");
117		*p = getc(fin);
118		if(*p == EOF)
119			{
120			*p = '\0';
121			return(0);
122			}
123		else if(*p == ';') ++incom;
124		else if (*p=='#' && !incom && yytext[0]!='\t')
125			*p = '\0';
126		else if (*p == '\n')
127			{
128			++yylineno;
129			if(p==text || p[-1]!='\\') break;
130			p[-1] = ' ';
131			while( (*p=getc(fin))=='\t' || *p==' ' || *p=='\n') 
132				if(*p == '\n') ++yylineno;
133
134			if(*p == EOF)
135				{
136				*p = '\0';
137				return(0);
138				}
139			}
140		}
141	*p = '\0';
142	text = yytext;
143	}
144
145c = text[0];
146
147if(c == '\t')   return( retsh(text) );
148
149if(L(c)||D(c)||c==' '||c=='.')
150	for(p=text+1; *p!='\0'; )
151		if(*p++ == '=')
152			{
153			eqsign(text);
154			return(MACRODEF);
155			}
156
157/* substtitute for macros on dependency line up to the semicolon if any */
158
159for(t = yytext ; *t!='\0' && *t!=';' ; ++t)
160	;
161
162lastchp = t;
163lastch = *t;
164*t = '\0';
165
166subst(yytext, templin);		/* Substitute for macros on dependency lines */
167
168if(lastch)
169	{
170	for(t = templin ; *t ; ++t)
171		;
172	*t = lastch;
173	while( *++t = *++lastchp ) ;
174	}
175
176p = templin;
177t = yytext;
178while( *t++ = *p++ )
179	;
180
181zznextc = text;
182return(START);
183}