home *** CD-ROM | disk | FTP | other *** search
- /*
- yylex for watcher: this is a simple routine looking for numbers,
- special characters and strings. The special chars are stored in
- 'words' and represent tokens by themselves. In y.tab.h are the
- values to return for the various tokens which are not listed in
- 'words'.
-
- Kenneth Ingham
-
- Copyright (C) 1987 The University of New Mexico
- */
-
- #include "defs.h"
-
- char words[] = "\".*|;:%@$-{}";
-
- yylex()
- {
- extern int yylval, intval, ointval;
- extern char *strval, ostrval[], pipeline[];
- extern FILE *cf;
- int c, value, i;
- static char str[MAX_STR];
-
- while (isspace(c = getc(cf)))
- ;
-
- if (c == EOF)
- return EOF;
-
- if (c == '(') { /* aha, pipeline */
- c = getc(cf);
- for (i=0; c != EOF && c != ')'; i++) {
- str[i] = c;
- c = getc(cf);
- }
- str[i] = '\0';
- if (c == EOF) {
- fprintf(stderr, "Missing ')' to end pipeline.\n");
- return EOF;
- }
- (void) strcpy(pipeline, str);
- return PIPELINE;
- }
-
- if (c == '#') { /* comment to end of line */
- while (c != '\n' && c != EOF)
- c = getc(cf);
- if (c == EOF)
- return EOF;
- return yylex();
- }
-
- if (index(words, c) != 0) {
- yylval = c;
- return c;
- }
-
- if (isdigit(c)) { /* a number */
- value = c - '0';
- while (isdigit(c = getc(cf)))
- value = value * 10 + c - '0';
- ointval = intval;
- intval = value;
- (void) ungetc(c, cf);
- return NUMBER;
- }
-
- (void) strcpy(ostrval, strval);
-
- if (c == '\'') { /* literal string */
- c = getc(cf);
- for (i=0; c != EOF && c != '\''; i++) {
- str[i] = c;
- c = getc(cf);
- }
- str[i] = '\0';
- strval = str;
- return STRING;
- }
-
- /* nothing else matched. Must be plain string (whitespace sep) */
- for (i=1, str[0]=c; c != EOF && !isspace(c) && !index(words,c); i++) {
- c = getc(cf);
- str[i] = c;
- }
- (void) ungetc(c, cf);
- str[i-1] = '\0';
- strval = str;
- return STRING;
- }
-