Annotation of src/usr.bin/lex/yylex.c, Revision 1.4
1.4 ! deraadt 1: /* $OpenBSD: yylex.c,v 1.3 1996/07/13 22:22:15 millert Exp $ */
1.2 deraadt 2:
1.1 deraadt 3: /* yylex - scanner front-end for flex */
4:
5: /*-
6: * Copyright (c) 1990 The Regents of the University of California.
7: * All rights reserved.
8: *
9: * This code is derived from software contributed to Berkeley by
10: * Vern Paxson.
11: *
12: * The United States Government has rights in this work pursuant
13: * to contract no. DE-AC03-76SF00098 between the United States
14: * Department of Energy and the University of California.
15: *
1.4 ! deraadt 16: * Redistribution and use in source and binary forms, with or without
! 17: * modification, are permitted provided that: (1) source distributions
! 18: * retain this entire copyright notice and comment, and (2) distributions
! 19: * including binaries display the following acknowledgement: ``This product
! 20: * includes software developed by the University of California, Berkeley
! 21: * and its contributors'' in the documentation or other materials provided
! 22: * with the distribution and in all advertising materials mentioning
! 23: * features or use of this software. Neither the name of the University nor
! 24: * the names of its contributors may be used to endorse or promote products
! 25: * derived from this software without specific prior written permission.
1.1 deraadt 26: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
27: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
28: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29: */
30:
1.4 ! deraadt 31: /* $Header: /cvs/src/usr.bin/lex/yylex.c,v 1.3 1996/07/13 22:22:15 millert Exp $ */
1.1 deraadt 32:
33: #include <ctype.h>
34: #include "flexdef.h"
35: #include "parse.h"
36:
37:
38: /* yylex - scan for a regular expression token */
39:
40: int yylex()
41: {
42: int toktype;
43: static int beglin = false;
44: extern char *yytext;
45:
46: if ( eofseen )
47: toktype = EOF;
48: else
49: toktype = flexscan();
50:
51: if ( toktype == EOF || toktype == 0 )
52: {
53: eofseen = 1;
54:
55: if ( sectnum == 1 )
56: {
57: synerr( _( "premature EOF" ) );
58: sectnum = 2;
59: toktype = SECTEND;
60: }
61:
62: else
63: toktype = 0;
64: }
65:
66: if ( trace )
67: {
68: if ( beglin )
69: {
70: fprintf( stderr, "%d\t", num_rules + 1 );
71: beglin = 0;
72: }
73:
74: switch ( toktype )
75: {
76: case '<':
77: case '>':
78: case '^':
79: case '$':
80: case '"':
81: case '[':
82: case ']':
83: case '{':
84: case '}':
85: case '|':
86: case '(':
87: case ')':
88: case '-':
89: case '/':
90: case '\\':
91: case '?':
92: case '.':
93: case '*':
94: case '+':
95: case ',':
96: (void) putc( toktype, stderr );
97: break;
98:
99: case '\n':
100: (void) putc( '\n', stderr );
101:
102: if ( sectnum == 2 )
103: beglin = 1;
104:
105: break;
106:
107: case SCDECL:
108: fputs( "%s", stderr );
109: break;
110:
111: case XSCDECL:
112: fputs( "%x", stderr );
113: break;
114:
115: case SECTEND:
116: fputs( "%%\n", stderr );
117:
118: /* We set beglin to be true so we'll start
119: * writing out numbers as we echo rules.
120: * flexscan() has already assigned sectnum.
121: */
122: if ( sectnum == 2 )
123: beglin = 1;
124:
125: break;
126:
127: case NAME:
128: fprintf( stderr, "'%s'", nmstr );
129: break;
130:
131: case CHAR:
132: switch ( yylval )
133: {
134: case '<':
135: case '>':
136: case '^':
137: case '$':
138: case '"':
139: case '[':
140: case ']':
141: case '{':
142: case '}':
143: case '|':
144: case '(':
145: case ')':
146: case '-':
147: case '/':
148: case '\\':
149: case '?':
150: case '.':
151: case '*':
152: case '+':
153: case ',':
154: fprintf( stderr, "\\%c",
155: yylval );
156: break;
157:
158: default:
159: if ( ! isascii( yylval ) ||
160: ! isprint( yylval ) )
161: fprintf( stderr,
162: "\\%.3o",
163: (unsigned int) yylval );
164: else
165: (void) putc( yylval,
166: stderr );
167: break;
168: }
169:
170: break;
171:
172: case NUMBER:
173: fprintf( stderr, "%d", yylval );
174: break;
175:
176: case PREVCCL:
177: fprintf( stderr, "[%d]", yylval );
178: break;
179:
180: case EOF_OP:
181: fprintf( stderr, "<<EOF>>" );
182: break;
183:
184: case OPTION_OP:
185: fprintf( stderr, "%s ", yytext );
186: break;
187:
188: case OPT_OUTFILE:
189: case OPT_PREFIX:
190: case CCE_ALNUM:
191: case CCE_ALPHA:
192: case CCE_BLANK:
193: case CCE_CNTRL:
194: case CCE_DIGIT:
195: case CCE_GRAPH:
196: case CCE_LOWER:
197: case CCE_PRINT:
198: case CCE_PUNCT:
199: case CCE_SPACE:
200: case CCE_UPPER:
201: case CCE_XDIGIT:
202: fprintf( stderr, "%s", yytext );
203: break;
204:
205: case 0:
206: fprintf( stderr, _( "End Marker\n" ) );
207: break;
208:
209: default:
210: fprintf( stderr,
211: _( "*Something Weird* - tok: %d val: %d\n" ),
212: toktype, yylval );
213: break;
214: }
215: }
216:
217: return toktype;
218: }