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