1 /* A Bison parser, made by GNU Bison 3.0.4. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
6
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* As a special exception, you may create a larger work that contains
21 part or all of the Bison parser skeleton and distribute that work
22 under terms of your choice, so long as that work isn't itself a
23 parser generator using the skeleton or a modified version thereof
24 as a parser skeleton. Alternatively, if you modify or redistribute
25 the parser skeleton itself, you may (at your option) remove this
26 special exception, which will cause the skeleton and the resulting
27 Bison output files to be licensed under the GNU General Public
28 License without this special exception.
29
30 This special exception was added by the Free Software Foundation in
31 version 2.2 of Bison. */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34 simplifying the original so-called "semantic" parser. */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37 infringing on user name space. This should be done even for local
38 variables, as they might otherwise be expanded by user macros.
39 There are some unavoidable exceptions within include files to
40 define necessary library symbols; they are noted "INFRINGES ON
41 USER NAME SPACE" below. */
42
43 /* Identify Bison output. */
44 #define YYBISON 1
45
46 /* Bison version. */
47 #define YYBISON_VERSION "3.0.4"
48
49 /* Skeleton name. */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers. */
53 #define YYPURE 0
54
55 /* Push parsers. */
56 #define YYPUSH 0
57
58 /* Pull parsers. */
59 #define YYPULL 1
60
61
62
63
64 /* Copy the first part of user declarations. */
65 #line 1 "../../src/egrep.y" /* yacc.c:339 */
66
67 /*===========================================================================
68 Copyright (c) 1998-2000, The Santa Cruz Operation
69 All rights reserved.
70
71 Redistribution and use in source and binary forms, with or without
72 modification, are permitted provided that the following conditions are met:
73
74 *Redistributions of source code must retain the above copyright notice,
75 this list of conditions and the following disclaimer.
76
77 *Redistributions in binary form must reproduce the above copyright notice,
78 this list of conditions and the following disclaimer in the documentation
79 and/or other materials provided with the distribution.
80
81 *Neither name of The Santa Cruz Operation nor the names of its contributors
82 may be used to endorse or promote products derived from this software
83 without specific prior written permission.
84
85 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
86 IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
87 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
88 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
89 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
90 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
91 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
92 INTERRUPTION)
93 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
94 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
95 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
96 DAMAGE.
97 =========================================================================*/
98
99 /*
100 * egrep -- fine lines containing a regular expression
101 */
102 #line 45 "../../src/egrep.y" /* yacc.c:339 */
103
104 #include "global.h"
105 #include <ctype.h>
106 #include <stdio.h>
107
108 #include <setjmp.h> /* jmp_buf */
109
110 #define nextch() (*input++)
111
112 #define MAXLIN 350
113 #define MAXPOS 4000
114 #define NCHARS 256
115 #define NSTATES 128
116 #define FINAL -1
117 static char gotofn[NSTATES][NCHARS];
118 static int state[NSTATES];
119 static char out[NSTATES];
120 static unsigned int line;
121 static int name[MAXLIN];
122 static unsigned int left[MAXLIN];
123 static unsigned int right[MAXLIN];
124 static unsigned int parent[MAXLIN];
125 static int foll[MAXLIN];
126 static int positions[MAXPOS];
127 static char chars[MAXLIN];
128 static int nxtpos;
129 static int nxtchar;
130 static int tmpstat[MAXLIN];
131 static int initstat[MAXLIN];
132 static int xstate;
133 static int count;
134 static int icount;
135 static char *input;
136 static long lnum;
137 static int iflag;
138 static jmp_buf env; /* setjmp/longjmp buffer */
139 static char *message; /* error message */
140
141 /* Internal prototypes: */
142 static void cfoll(int v);
143 static void cgotofn(void);
144 static int cstate(int v);
145 static int member(int symb, int set, int torf);
146 static int notin(int n);
147 static void synerror(void);
148 static void overflo(void);
149 static void add(int *array, int n);
150 static void follow(unsigned int v);
151 static int unary(int x, int d);
152 static int node(int x, int l, int r);
153 static unsigned int cclenter(int x);
154 static unsigned int enter(int x);
155
156 static int yylex(void);
157 static int yyerror(char *);
158
159 #line 160 "egrep.c" /* yacc.c:339 */
160
161 # ifndef YY_NULLPTR
162 # if defined __cplusplus && 201103L <= __cplusplus
163 # define YY_NULLPTR nullptr
164 # else
165 # define YY_NULLPTR 0
166 # endif
167 # endif
168
169 /* Enabling verbose error messages. */
170 #ifdef YYERROR_VERBOSE
171 # undef YYERROR_VERBOSE
172 # define YYERROR_VERBOSE 1
173 #else
174 # define YYERROR_VERBOSE 0
175 #endif
176
177 /* In a future release of Bison, this section will be replaced
178 by #include "y.tab.h". */
179 #ifndef YY_YY_EGREP_H_INCLUDED
180 # define YY_YY_EGREP_H_INCLUDED
181 /* Debug traces. */
182 #ifndef YYDEBUG
183 # define YYDEBUG 0
184 #endif
185 #if YYDEBUG
186 extern int yydebug;
187 #endif
188
189 /* Token type. */
190 #ifndef YYTOKENTYPE
191 # define YYTOKENTYPE
192 enum yytokentype
193 {
194 CHAR = 258,
195 DOT = 259,
196 CCL = 260,
197 NCCL = 261,
198 OR = 262,
199 CAT = 263,
200 STAR = 264,
201 PLUS = 265,
202 QUEST = 266
203 };
204 #endif
205 /* Tokens. */
206 #define CHAR 258
207 #define DOT 259
208 #define CCL 260
209 #define NCCL 261
210 #define OR 262
211 #define CAT 263
212 #define STAR 264
213 #define PLUS 265
214 #define QUEST 266
215
216 /* Value type. */
217 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
218 typedef int YYSTYPE;
219 # define YYSTYPE_IS_TRIVIAL 1
220 # define YYSTYPE_IS_DECLARED 1
221 #endif
222
223
224 extern YYSTYPE yylval;
225
226 int yyparse (void);
227
228 #endif /* !YY_YY_EGREP_H_INCLUDED */
229
230 /* Copy the second part of user declarations. */
231
232 #line 233 "egrep.c" /* yacc.c:358 */
233
234 #ifdef short
235 # undef short
236 #endif
237
238 #ifdef YYTYPE_UINT8
239 typedef YYTYPE_UINT8 yytype_uint8;
240 #else
241 typedef unsigned char yytype_uint8;
242 #endif
243
244 #ifdef YYTYPE_INT8
245 typedef YYTYPE_INT8 yytype_int8;
246 #else
247 typedef signed char yytype_int8;
248 #endif
249
250 #ifdef YYTYPE_UINT16
251 typedef YYTYPE_UINT16 yytype_uint16;
252 #else
253 typedef unsigned short int yytype_uint16;
254 #endif
255
256 #ifdef YYTYPE_INT16
257 typedef YYTYPE_INT16 yytype_int16;
258 #else
259 typedef short int yytype_int16;
260 #endif
261
262 #ifndef YYSIZE_T
263 # ifdef __SIZE_TYPE__
264 # define YYSIZE_T __SIZE_TYPE__
265 # elif defined size_t
266 # define YYSIZE_T size_t
267 # elif ! defined YYSIZE_T
268 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
269 # define YYSIZE_T size_t
270 # else
271 # define YYSIZE_T unsigned int
272 # endif
273 #endif
274
275 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
276
277 #ifndef YY_
278 # if defined YYENABLE_NLS && YYENABLE_NLS
279 # if ENABLE_NLS
280 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
281 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
282 # endif
283 # endif
284 # ifndef YY_
285 # define YY_(Msgid) Msgid
286 # endif
287 #endif
288
289 #ifndef YY_ATTRIBUTE
290 # if (defined __GNUC__ \
291 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
292 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
293 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
294 # else
295 # define YY_ATTRIBUTE(Spec) /* empty */
296 # endif
297 #endif
298
299 #ifndef YY_ATTRIBUTE_PURE
300 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
301 #endif
302
303 #ifndef YY_ATTRIBUTE_UNUSED
304 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
305 #endif
306
307 #if !defined _Noreturn \
308 && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
309 # if defined _MSC_VER && 1200 <= _MSC_VER
310 # define _Noreturn __declspec (noreturn)
311 # else
312 # define _Noreturn YY_ATTRIBUTE ((__noreturn__))
313 # endif
314 #endif
315
316 /* Suppress unused-variable warnings by "using" E. */
317 #if ! defined lint || defined __GNUC__
318 # define YYUSE(E) ((void) (E))
319 #else
320 # define YYUSE(E) /* empty */
321 #endif
322
323 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
324 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
325 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
326 _Pragma ("GCC diagnostic push") \
327 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
328 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
329 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
330 _Pragma ("GCC diagnostic pop")
331 #else
332 # define YY_INITIAL_VALUE(Value) Value
333 #endif
334 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
335 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
336 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
337 #endif
338 #ifndef YY_INITIAL_VALUE
339 # define YY_INITIAL_VALUE(Value) /* Nothing. */
340 #endif
341
342
343 #if ! defined yyoverflow || YYERROR_VERBOSE
344
345 /* The parser invokes alloca or malloc; define the necessary symbols. */
346
347 # ifdef YYSTACK_USE_ALLOCA
348 # if YYSTACK_USE_ALLOCA
349 # ifdef __GNUC__
350 # define YYSTACK_ALLOC __builtin_alloca
351 # elif defined __BUILTIN_VA_ARG_INCR
352 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
353 # elif defined _AIX
354 # define YYSTACK_ALLOC __alloca
355 # elif defined _MSC_VER
356 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
357 # define alloca _alloca
358 # else
359 # define YYSTACK_ALLOC alloca
360 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
361 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
362 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
363 # ifndef EXIT_SUCCESS
364 # define EXIT_SUCCESS 0
365 # endif
366 # endif
367 # endif
368 # endif
369 # endif
370
371 # ifdef YYSTACK_ALLOC
372 /* Pacify GCC's 'empty if-body' warning. */
373 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
374 # ifndef YYSTACK_ALLOC_MAXIMUM
375 /* The OS might guarantee only one guard page at the bottom of the stack,
376 and a page size can be as small as 4096 bytes. So we cannot safely
377 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
378 to allow for a few compiler-allocated temporary stack slots. */
379 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
380 # endif
381 # else
382 # define YYSTACK_ALLOC YYMALLOC
383 # define YYSTACK_FREE YYFREE
384 # ifndef YYSTACK_ALLOC_MAXIMUM
385 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
386 # endif
387 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
388 && ! ((defined YYMALLOC || defined malloc) \
389 && (defined YYFREE || defined free)))
390 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
391 # ifndef EXIT_SUCCESS
392 # define EXIT_SUCCESS 0
393 # endif
394 # endif
395 # ifndef YYMALLOC
396 # define YYMALLOC malloc
397 # if ! defined malloc && ! defined EXIT_SUCCESS
398 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
399 # endif
400 # endif
401 # ifndef YYFREE
402 # define YYFREE free
403 # if ! defined free && ! defined EXIT_SUCCESS
404 void free (void *); /* INFRINGES ON USER NAME SPACE */
405 # endif
406 # endif
407 # endif
408 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
409
410
411 #if (! defined yyoverflow \
412 && (! defined __cplusplus \
413 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
414
415 /* A type that is properly aligned for any stack member. */
416 union yyalloc
417 {
418 yytype_int16 yyss_alloc;
419 YYSTYPE yyvs_alloc;
420 };
421
422 /* The size of the maximum gap between one aligned stack and the next. */
423 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
424
425 /* The size of an array large to enough to hold all stacks, each with
426 N elements. */
427 # define YYSTACK_BYTES(N) \
428 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
429 + YYSTACK_GAP_MAXIMUM)
430
431 # define YYCOPY_NEEDED 1
432
433 /* Relocate STACK from its old location to the new one. The
434 local variables YYSIZE and YYSTACKSIZE give the old and new number of
435 elements in the stack, and YYPTR gives the new location of the
436 stack. Advance YYPTR to a properly aligned location for the next
437 stack. */
438 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
439 do \
440 { \
441 YYSIZE_T yynewbytes; \
442 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
443 Stack = &yyptr->Stack_alloc; \
444 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
445 yyptr += yynewbytes / sizeof (*yyptr); \
446 } \
447 while (0)
448
449 #endif
450
451 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
452 /* Copy COUNT objects from SRC to DST. The source and destination do
453 not overlap. */
454 # ifndef YYCOPY
455 # if defined __GNUC__ && 1 < __GNUC__
456 # define YYCOPY(Dst, Src, Count) \
457 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
458 # else
459 # define YYCOPY(Dst, Src, Count) \
460 do \
461 { \
462 YYSIZE_T yyi; \
463 for (yyi = 0; yyi < (Count); yyi++) \
464 (Dst)[yyi] = (Src)[yyi]; \
465 } \
466 while (0)
467 # endif
468 # endif
469 #endif /* !YYCOPY_NEEDED */
470
471 /* YYFINAL -- State number of the termination state. */
472 #define YYFINAL 6
473 /* YYLAST -- Last index in YYTABLE. */
474 #define YYLAST 108
475
476 /* YYNTOKENS -- Number of terminals. */
477 #define YYNTOKENS 14
478 /* YYNNTS -- Number of nonterminals. */
479 #define YYNNTS 5
480 /* YYNRULES -- Number of rules. */
481 #define YYNRULES 18
482 /* YYNSTATES -- Number of states. */
483 #define YYNSTATES 25
484
485 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
486 by yylex, with out-of-bounds checking. */
487 #define YYUNDEFTOK 2
488 #define YYMAXUTOK 266
489
490 #define YYTRANSLATE(YYX) \
491 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
492
493 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
494 as returned by yylex, without out-of-bounds checking. */
495 static const yytype_uint8 yytranslate[] =
496 {
497 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
498 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
499 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
500 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
501 12, 13, 2, 2, 2, 2, 2, 2, 2, 2,
502 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
503 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
504 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
505 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
506 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
507 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
508 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
509 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
510 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
511 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
512 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
513 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
514 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
515 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
516 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
517 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
518 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
519 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
520 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
521 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
522 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
523 5, 6, 7, 8, 9, 10, 11
524 };
525
526 #if YYDEBUG
527 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
528 static const yytype_uint8 yyrline[] =
529 {
530 0, 103, 103, 108, 110, 112, 114, 118, 121, 123,
531 125, 127, 131, 133, 135, 137, 139, 141, 143
532 };
533 #endif
534
535 #if YYDEBUG || YYERROR_VERBOSE || 0
536 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
537 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
538 static const char *const yytname[] =
539 {
540 "$end", "error", "$undefined", "CHAR", "DOT", "CCL", "NCCL", "OR",
541 "CAT", "STAR", "PLUS", "QUEST", "'('", "')'", "$accept", "s", "t", "b",
542 "r", YY_NULLPTR
543 };
544 #endif
545
546 # ifdef YYPRINT
547 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
548 (internal) symbol number NUM (which must be that of a token). */
549 static const yytype_uint16 yytoknum[] =
550 {
551 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
552 265, 266, 40, 41
553 };
554 # endif
555
556 #define YYPACT_NINF -5
557
558 #define yypact_value_is_default(Yystate) \
559 (!!((Yystate) == (-5)))
560
561 #define YYTABLE_NINF -14
562
563 #define yytable_value_is_error(Yytable_value) \
564 0
565
566 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
567 STATE-NUM. */
568 static const yytype_int8 yypact[] =
569 {
570 2, -5, 3, -5, 1, 1, -5, -5, -5, -5,
571 -5, -5, 1, 47, 60, 72, 86, -5, -5, -5,
572 19, 96, 1, -5, 33
573 };
574
575 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
576 Performed when YYTABLE does not specify something else to do. Zero
577 means the default is an error. */
578 static const yytype_uint8 yydefact[] =
579 {
580 7, 7, 0, 2, 0, 0, 1, 18, 8, 9,
581 10, 11, 0, 0, 0, 0, 0, 14, 15, 16,
582 0, 0, 0, 17, 0
583 };
584
585 /* YYPGOTO[NTERM-NUM]. */
586 static const yytype_int8 yypgoto[] =
587 {
588 -5, -5, -5, 9, -4
589 };
590
591 /* YYDEFGOTO[NTERM-NUM]. */
592 static const yytype_int8 yydefgoto[] =
593 {
594 -1, 2, 3, 4, 20
595 };
596
597 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
598 positive, shift that token. If negative, reduce the rule whose
599 number is the opposite. If YYTABLE_NINF, syntax error. */
600 static const yytype_int8 yytable[] =
601 {
602 13, 14, 7, 6, 8, 9, 10, 11, 15, 1,
603 5, 0, 24, 12, 0, 0, 0, 24, 24, -13,
604 7, 0, -13, -13, -13, -13, -13, 0, 17, 18,
605 19, -13, -13, -12, 7, 0, 8, 9, 10, 11,
606 -12, 0, 17, 18, 19, 12, -12, -3, 7, 0,
607 8, 9, 10, 11, 16, 0, 17, 18, 19, 12,
608 -5, 7, 0, 8, 9, 10, 11, 21, 0, 17,
609 18, 19, 12, 7, 0, 8, 9, 10, 11, 22,
610 0, 17, 18, 19, 12, 23, -6, 7, 0, 8,
611 9, 10, 11, 0, 0, 0, -4, 7, 12, 8,
612 9, 10, 11, 0, 0, 0, 0, 0, 12
613 };
614
615 static const yytype_int8 yycheck[] =
616 {
617 4, 5, 1, 0, 3, 4, 5, 6, 12, 7,
618 1, -1, 16, 12, -1, -1, -1, 21, 22, 0,
619 1, -1, 3, 4, 5, 6, 7, -1, 9, 10,
620 11, 12, 13, 0, 1, -1, 3, 4, 5, 6,
621 7, -1, 9, 10, 11, 12, 13, 0, 1, -1,
622 3, 4, 5, 6, 7, -1, 9, 10, 11, 12,
623 0, 1, -1, 3, 4, 5, 6, 7, -1, 9,
624 10, 11, 12, 1, -1, 3, 4, 5, 6, 7,
625 -1, 9, 10, 11, 12, 13, 0, 1, -1, 3,
626 4, 5, 6, -1, -1, -1, 0, 1, 12, 3,
627 4, 5, 6, -1, -1, -1, -1, -1, 12
628 };
629
630 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
631 symbol of state STATE-NUM. */
632 static const yytype_uint8 yystos[] =
633 {
634 0, 7, 15, 16, 17, 17, 0, 1, 3, 4,
635 5, 6, 12, 18, 18, 18, 7, 9, 10, 11,
636 18, 7, 7, 13, 18
637 };
638
639 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
640 static const yytype_uint8 yyr1[] =
641 {
642 0, 14, 15, 16, 16, 16, 16, 17, 18, 18,
643 18, 18, 18, 18, 18, 18, 18, 18, 18
644 };
645
646 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
647 static const yytype_uint8 yyr2[] =
648 {
649 0, 2, 1, 2, 4, 3, 3, 0, 1, 1,
650 1, 1, 3, 2, 2, 2, 2, 3, 1
651 };
652
653
654 #define yyerrok (yyerrstatus = 0)
655 #define yyclearin (yychar = YYEMPTY)
656 #define YYEMPTY (-2)
657 #define YYEOF 0
658
659 #define YYACCEPT goto yyacceptlab
660 #define YYABORT goto yyabortlab
661 #define YYERROR goto yyerrorlab
662
663
664 #define YYRECOVERING() (!!yyerrstatus)
665
666 #define YYBACKUP(Token, Value) \
667 do \
668 if (yychar == YYEMPTY) \
669 { \
670 yychar = (Token); \
671 yylval = (Value); \
672 YYPOPSTACK (yylen); \
673 yystate = *yyssp; \
674 goto yybackup; \
675 } \
676 else \
677 { \
678 yyerror (YY_("syntax error: cannot back up")); \
679 YYERROR; \
680 } \
681 while (0)
682
683 /* Error token number */
684 #define YYTERROR 1
685 #define YYERRCODE 256
686
687
688
689 /* Enable debugging if requested. */
690 #if YYDEBUG
691
692 # ifndef YYFPRINTF
693 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
694 # define YYFPRINTF fprintf
695 # endif
696
697 # define YYDPRINTF(Args) \
698 do { \
699 if (yydebug) \
700 YYFPRINTF Args; \
701 } while (0)
702
703 /* This macro is provided for backward compatibility. */
704 #ifndef YY_LOCATION_PRINT
705 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
706 #endif
707
708
709 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
710 do { \
711 if (yydebug) \
712 { \
713 YYFPRINTF (stderr, "%s ", Title); \
714 yy_symbol_print (stderr, \
715 Type, Value); \
716 YYFPRINTF (stderr, "\n"); \
717 } \
718 } while (0)
719
720
721 /*----------------------------------------.
722 | Print this symbol's value on YYOUTPUT. |
723 `----------------------------------------*/
724
725 static void
yy_symbol_value_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep)726 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
727 {
728 FILE *yyo = yyoutput;
729 YYUSE (yyo);
730 if (!yyvaluep)
731 return;
732 # ifdef YYPRINT
733 if (yytype < YYNTOKENS)
734 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
735 # endif
736 YYUSE (yytype);
737 }
738
739
740 /*--------------------------------.
741 | Print this symbol on YYOUTPUT. |
742 `--------------------------------*/
743
744 static void
yy_symbol_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep)745 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
746 {
747 YYFPRINTF (yyoutput, "%s %s (",
748 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
749
750 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
751 YYFPRINTF (yyoutput, ")");
752 }
753
754 /*------------------------------------------------------------------.
755 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
756 | TOP (included). |
757 `------------------------------------------------------------------*/
758
759 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)760 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
761 {
762 YYFPRINTF (stderr, "Stack now");
763 for (; yybottom <= yytop; yybottom++)
764 {
765 int yybot = *yybottom;
766 YYFPRINTF (stderr, " %d", yybot);
767 }
768 YYFPRINTF (stderr, "\n");
769 }
770
771 # define YY_STACK_PRINT(Bottom, Top) \
772 do { \
773 if (yydebug) \
774 yy_stack_print ((Bottom), (Top)); \
775 } while (0)
776
777
778 /*------------------------------------------------.
779 | Report that the YYRULE is going to be reduced. |
780 `------------------------------------------------*/
781
782 static void
yy_reduce_print(yytype_int16 * yyssp,YYSTYPE * yyvsp,int yyrule)783 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
784 {
785 unsigned long int yylno = yyrline[yyrule];
786 int yynrhs = yyr2[yyrule];
787 int yyi;
788 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
789 yyrule - 1, yylno);
790 /* The symbols being reduced. */
791 for (yyi = 0; yyi < yynrhs; yyi++)
792 {
793 YYFPRINTF (stderr, " $%d = ", yyi + 1);
794 yy_symbol_print (stderr,
795 yystos[yyssp[yyi + 1 - yynrhs]],
796 &(yyvsp[(yyi + 1) - (yynrhs)])
797 );
798 YYFPRINTF (stderr, "\n");
799 }
800 }
801
802 # define YY_REDUCE_PRINT(Rule) \
803 do { \
804 if (yydebug) \
805 yy_reduce_print (yyssp, yyvsp, Rule); \
806 } while (0)
807
808 /* Nonzero means print parse trace. It is left uninitialized so that
809 multiple parsers can coexist. */
810 int yydebug;
811 #else /* !YYDEBUG */
812 # define YYDPRINTF(Args)
813 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
814 # define YY_STACK_PRINT(Bottom, Top)
815 # define YY_REDUCE_PRINT(Rule)
816 #endif /* !YYDEBUG */
817
818
819 /* YYINITDEPTH -- initial size of the parser's stacks. */
820 #ifndef YYINITDEPTH
821 # define YYINITDEPTH 200
822 #endif
823
824 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
825 if the built-in stack extension method is used).
826
827 Do not make this value too large; the results are undefined if
828 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
829 evaluated with infinite-precision integer arithmetic. */
830
831 #ifndef YYMAXDEPTH
832 # define YYMAXDEPTH 10000
833 #endif
834
835
836 #if YYERROR_VERBOSE
837
838 # ifndef yystrlen
839 # if defined __GLIBC__ && defined _STRING_H
840 # define yystrlen strlen
841 # else
842 /* Return the length of YYSTR. */
843 static YYSIZE_T
yystrlen(const char * yystr)844 yystrlen (const char *yystr)
845 {
846 YYSIZE_T yylen;
847 for (yylen = 0; yystr[yylen]; yylen++)
848 continue;
849 return yylen;
850 }
851 # endif
852 # endif
853
854 # ifndef yystpcpy
855 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
856 # define yystpcpy stpcpy
857 # else
858 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
859 YYDEST. */
860 static char *
yystpcpy(char * yydest,const char * yysrc)861 yystpcpy (char *yydest, const char *yysrc)
862 {
863 char *yyd = yydest;
864 const char *yys = yysrc;
865
866 while ((*yyd++ = *yys++) != '\0')
867 continue;
868
869 return yyd - 1;
870 }
871 # endif
872 # endif
873
874 # ifndef yytnamerr
875 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
876 quotes and backslashes, so that it's suitable for yyerror. The
877 heuristic is that double-quoting is unnecessary unless the string
878 contains an apostrophe, a comma, or backslash (other than
879 backslash-backslash). YYSTR is taken from yytname. If YYRES is
880 null, do not copy; instead, return the length of what the result
881 would have been. */
882 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)883 yytnamerr (char *yyres, const char *yystr)
884 {
885 if (*yystr == '"')
886 {
887 YYSIZE_T yyn = 0;
888 char const *yyp = yystr;
889
890 for (;;)
891 switch (*++yyp)
892 {
893 case '\'':
894 case ',':
895 goto do_not_strip_quotes;
896
897 case '\\':
898 if (*++yyp != '\\')
899 goto do_not_strip_quotes;
900 /* Fall through. */
901 default:
902 if (yyres)
903 yyres[yyn] = *yyp;
904 yyn++;
905 break;
906
907 case '"':
908 if (yyres)
909 yyres[yyn] = '\0';
910 return yyn;
911 }
912 do_not_strip_quotes: ;
913 }
914
915 if (! yyres)
916 return yystrlen (yystr);
917
918 return yystpcpy (yyres, yystr) - yyres;
919 }
920 # endif
921
922 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
923 about the unexpected token YYTOKEN for the state stack whose top is
924 YYSSP.
925
926 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
927 not large enough to hold the message. In that case, also set
928 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
929 required number of bytes is too large to store. */
930 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)931 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
932 yytype_int16 *yyssp, int yytoken)
933 {
934 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
935 YYSIZE_T yysize = yysize0;
936 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
937 /* Internationalized format string. */
938 const char *yyformat = YY_NULLPTR;
939 /* Arguments of yyformat. */
940 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
941 /* Number of reported tokens (one for the "unexpected", one per
942 "expected"). */
943 int yycount = 0;
944
945 /* There are many possibilities here to consider:
946 - If this state is a consistent state with a default action, then
947 the only way this function was invoked is if the default action
948 is an error action. In that case, don't check for expected
949 tokens because there are none.
950 - The only way there can be no lookahead present (in yychar) is if
951 this state is a consistent state with a default action. Thus,
952 detecting the absence of a lookahead is sufficient to determine
953 that there is no unexpected or expected token to report. In that
954 case, just report a simple "syntax error".
955 - Don't assume there isn't a lookahead just because this state is a
956 consistent state with a default action. There might have been a
957 previous inconsistent state, consistent state with a non-default
958 action, or user semantic action that manipulated yychar.
959 - Of course, the expected token list depends on states to have
960 correct lookahead information, and it depends on the parser not
961 to perform extra reductions after fetching a lookahead from the
962 scanner and before detecting a syntax error. Thus, state merging
963 (from LALR or IELR) and default reductions corrupt the expected
964 token list. However, the list is correct for canonical LR with
965 one exception: it will still contain any token that will not be
966 accepted due to an error action in a later state.
967 */
968 if (yytoken != YYEMPTY)
969 {
970 int yyn = yypact[*yyssp];
971 yyarg[yycount++] = yytname[yytoken];
972 if (!yypact_value_is_default (yyn))
973 {
974 /* Start YYX at -YYN if negative to avoid negative indexes in
975 YYCHECK. In other words, skip the first -YYN actions for
976 this state because they are default actions. */
977 int yyxbegin = yyn < 0 ? -yyn : 0;
978 /* Stay within bounds of both yycheck and yytname. */
979 int yychecklim = YYLAST - yyn + 1;
980 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
981 int yyx;
982
983 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
984 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
985 && !yytable_value_is_error (yytable[yyx + yyn]))
986 {
987 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
988 {
989 yycount = 1;
990 yysize = yysize0;
991 break;
992 }
993 yyarg[yycount++] = yytname[yyx];
994 {
995 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
996 if (! (yysize <= yysize1
997 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
998 return 2;
999 yysize = yysize1;
1000 }
1001 }
1002 }
1003 }
1004
1005 switch (yycount)
1006 {
1007 # define YYCASE_(N, S) \
1008 case N: \
1009 yyformat = S; \
1010 break
1011 YYCASE_(0, YY_("syntax error"));
1012 YYCASE_(1, YY_("syntax error, unexpected %s"));
1013 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1014 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1015 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1016 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1017 # undef YYCASE_
1018 }
1019
1020 {
1021 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1022 if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1023 return 2;
1024 yysize = yysize1;
1025 }
1026
1027 if (*yymsg_alloc < yysize)
1028 {
1029 *yymsg_alloc = 2 * yysize;
1030 if (! (yysize <= *yymsg_alloc
1031 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1032 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1033 return 1;
1034 }
1035
1036 /* Avoid sprintf, as that infringes on the user's name space.
1037 Don't have undefined behavior even if the translation
1038 produced a string with the wrong number of "%s"s. */
1039 {
1040 char *yyp = *yymsg;
1041 int yyi = 0;
1042 while ((*yyp = *yyformat) != '\0')
1043 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1044 {
1045 yyp += yytnamerr (yyp, yyarg[yyi++]);
1046 yyformat += 2;
1047 }
1048 else
1049 {
1050 yyp++;
1051 yyformat++;
1052 }
1053 }
1054 return 0;
1055 }
1056 #endif /* YYERROR_VERBOSE */
1057
1058 /*-----------------------------------------------.
1059 | Release the memory associated to this symbol. |
1060 `-----------------------------------------------*/
1061
1062 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep)1063 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1064 {
1065 YYUSE (yyvaluep);
1066 if (!yymsg)
1067 yymsg = "Deleting";
1068 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1069
1070 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1071 YYUSE (yytype);
1072 YY_IGNORE_MAYBE_UNINITIALIZED_END
1073 }
1074
1075
1076
1077
1078 /* The lookahead symbol. */
1079 int yychar;
1080
1081 /* The semantic value of the lookahead symbol. */
1082 YYSTYPE yylval;
1083 /* Number of syntax errors so far. */
1084 int yynerrs;
1085
1086
1087 /*----------.
1088 | yyparse. |
1089 `----------*/
1090
1091 int
yyparse(void)1092 yyparse (void)
1093 {
1094 int yystate;
1095 /* Number of tokens to shift before error messages enabled. */
1096 int yyerrstatus;
1097
1098 /* The stacks and their tools:
1099 'yyss': related to states.
1100 'yyvs': related to semantic values.
1101
1102 Refer to the stacks through separate pointers, to allow yyoverflow
1103 to reallocate them elsewhere. */
1104
1105 /* The state stack. */
1106 yytype_int16 yyssa[YYINITDEPTH];
1107 yytype_int16 *yyss;
1108 yytype_int16 *yyssp;
1109
1110 /* The semantic value stack. */
1111 YYSTYPE yyvsa[YYINITDEPTH];
1112 YYSTYPE *yyvs;
1113 YYSTYPE *yyvsp;
1114
1115 YYSIZE_T yystacksize;
1116
1117 int yyn;
1118 int yyresult;
1119 /* Lookahead token as an internal (translated) token number. */
1120 int yytoken = 0;
1121 /* The variables used to return semantic value and location from the
1122 action routines. */
1123 YYSTYPE yyval;
1124
1125 #if YYERROR_VERBOSE
1126 /* Buffer for error messages, and its allocated size. */
1127 char yymsgbuf[128];
1128 char *yymsg = yymsgbuf;
1129 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1130 #endif
1131
1132 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1133
1134 /* The number of symbols on the RHS of the reduced rule.
1135 Keep to zero when no symbol should be popped. */
1136 int yylen = 0;
1137
1138 yyssp = yyss = yyssa;
1139 yyvsp = yyvs = yyvsa;
1140 yystacksize = YYINITDEPTH;
1141
1142 YYDPRINTF ((stderr, "Starting parse\n"));
1143
1144 yystate = 0;
1145 yyerrstatus = 0;
1146 yynerrs = 0;
1147 yychar = YYEMPTY; /* Cause a token to be read. */
1148 goto yysetstate;
1149
1150 /*------------------------------------------------------------.
1151 | yynewstate -- Push a new state, which is found in yystate. |
1152 `------------------------------------------------------------*/
1153 yynewstate:
1154 /* In all cases, when you get here, the value and location stacks
1155 have just been pushed. So pushing a state here evens the stacks. */
1156 yyssp++;
1157
1158 yysetstate:
1159 *yyssp = yystate;
1160
1161 if (yyss + yystacksize - 1 <= yyssp)
1162 {
1163 /* Get the current used size of the three stacks, in elements. */
1164 YYSIZE_T yysize = yyssp - yyss + 1;
1165
1166 #ifdef yyoverflow
1167 {
1168 /* Give user a chance to reallocate the stack. Use copies of
1169 these so that the &'s don't force the real ones into
1170 memory. */
1171 YYSTYPE *yyvs1 = yyvs;
1172 yytype_int16 *yyss1 = yyss;
1173
1174 /* Each stack pointer address is followed by the size of the
1175 data in use in that stack, in bytes. This used to be a
1176 conditional around just the two extra args, but that might
1177 be undefined if yyoverflow is a macro. */
1178 yyoverflow (YY_("memory exhausted"),
1179 &yyss1, yysize * sizeof (*yyssp),
1180 &yyvs1, yysize * sizeof (*yyvsp),
1181 &yystacksize);
1182
1183 yyss = yyss1;
1184 yyvs = yyvs1;
1185 }
1186 #else /* no yyoverflow */
1187 # ifndef YYSTACK_RELOCATE
1188 goto yyexhaustedlab;
1189 # else
1190 /* Extend the stack our own way. */
1191 if (YYMAXDEPTH <= yystacksize)
1192 goto yyexhaustedlab;
1193 yystacksize *= 2;
1194 if (YYMAXDEPTH < yystacksize)
1195 yystacksize = YYMAXDEPTH;
1196
1197 {
1198 yytype_int16 *yyss1 = yyss;
1199 union yyalloc *yyptr =
1200 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1201 if (! yyptr)
1202 goto yyexhaustedlab;
1203 YYSTACK_RELOCATE (yyss_alloc, yyss);
1204 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1205 # undef YYSTACK_RELOCATE
1206 if (yyss1 != yyssa)
1207 YYSTACK_FREE (yyss1);
1208 }
1209 # endif
1210 #endif /* no yyoverflow */
1211
1212 yyssp = yyss + yysize - 1;
1213 yyvsp = yyvs + yysize - 1;
1214
1215 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1216 (unsigned long int) yystacksize));
1217
1218 if (yyss + yystacksize - 1 <= yyssp)
1219 YYABORT;
1220 }
1221
1222 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1223
1224 if (yystate == YYFINAL)
1225 YYACCEPT;
1226
1227 goto yybackup;
1228
1229 /*-----------.
1230 | yybackup. |
1231 `-----------*/
1232 yybackup:
1233
1234 /* Do appropriate processing given the current state. Read a
1235 lookahead token if we need one and don't already have one. */
1236
1237 /* First try to decide what to do without reference to lookahead token. */
1238 yyn = yypact[yystate];
1239 if (yypact_value_is_default (yyn))
1240 goto yydefault;
1241
1242 /* Not known => get a lookahead token if don't already have one. */
1243
1244 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1245 if (yychar == YYEMPTY)
1246 {
1247 YYDPRINTF ((stderr, "Reading a token: "));
1248 yychar = yylex ();
1249 }
1250
1251 if (yychar <= YYEOF)
1252 {
1253 yychar = yytoken = YYEOF;
1254 YYDPRINTF ((stderr, "Now at end of input.\n"));
1255 }
1256 else
1257 {
1258 yytoken = YYTRANSLATE (yychar);
1259 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1260 }
1261
1262 /* If the proper action on seeing token YYTOKEN is to reduce or to
1263 detect an error, take that action. */
1264 yyn += yytoken;
1265 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1266 goto yydefault;
1267 yyn = yytable[yyn];
1268 if (yyn <= 0)
1269 {
1270 if (yytable_value_is_error (yyn))
1271 goto yyerrlab;
1272 yyn = -yyn;
1273 goto yyreduce;
1274 }
1275
1276 /* Count tokens shifted since error; after three, turn off error
1277 status. */
1278 if (yyerrstatus)
1279 yyerrstatus--;
1280
1281 /* Shift the lookahead token. */
1282 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1283
1284 /* Discard the shifted token. */
1285 yychar = YYEMPTY;
1286
1287 yystate = yyn;
1288 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1289 *++yyvsp = yylval;
1290 YY_IGNORE_MAYBE_UNINITIALIZED_END
1291
1292 goto yynewstate;
1293
1294
1295 /*-----------------------------------------------------------.
1296 | yydefault -- do the default action for the current state. |
1297 `-----------------------------------------------------------*/
1298 yydefault:
1299 yyn = yydefact[yystate];
1300 if (yyn == 0)
1301 goto yyerrlab;
1302 goto yyreduce;
1303
1304
1305 /*-----------------------------.
1306 | yyreduce -- Do a reduction. |
1307 `-----------------------------*/
1308 yyreduce:
1309 /* yyn is the number of a rule to reduce with. */
1310 yylen = yyr2[yyn];
1311
1312 /* If YYLEN is nonzero, implement the default value of the action:
1313 '$$ = $1'.
1314
1315 Otherwise, the following line sets YYVAL to garbage.
1316 This behavior is undocumented and Bison
1317 users should not rely upon it. Assigning to YYVAL
1318 unconditionally makes the parser a bit smaller, and it avoids a
1319 GCC warning that YYVAL may be used uninitialized. */
1320 yyval = yyvsp[1-yylen];
1321
1322
1323 YY_REDUCE_PRINT (yyn);
1324 switch (yyn)
1325 {
1326 case 2:
1327 #line 104 "../../src/egrep.y" /* yacc.c:1646 */
1328 { unary(FINAL, (yyvsp[0]));
1329 line--;
1330 }
1331 #line 1332 "egrep.c" /* yacc.c:1646 */
1332 break;
1333
1334 case 3:
1335 #line 109 "../../src/egrep.y" /* yacc.c:1646 */
1336 { (yyval) = node(CAT, (yyvsp[-1]), (yyvsp[0])); }
1337 #line 1338 "egrep.c" /* yacc.c:1646 */
1338 break;
1339
1340 case 4:
1341 #line 111 "../../src/egrep.y" /* yacc.c:1646 */
1342 { (yyval) = node(CAT, (yyvsp[-2]), (yyvsp[-1])); }
1343 #line 1344 "egrep.c" /* yacc.c:1646 */
1344 break;
1345
1346 case 5:
1347 #line 113 "../../src/egrep.y" /* yacc.c:1646 */
1348 { (yyval) = node(CAT, (yyvsp[-1]), (yyvsp[0])); }
1349 #line 1350 "egrep.c" /* yacc.c:1646 */
1350 break;
1351
1352 case 6:
1353 #line 115 "../../src/egrep.y" /* yacc.c:1646 */
1354 { (yyval) = node(CAT, (yyvsp[-2]), (yyvsp[-1])); }
1355 #line 1356 "egrep.c" /* yacc.c:1646 */
1356 break;
1357
1358 case 7:
1359 #line 118 "../../src/egrep.y" /* yacc.c:1646 */
1360 { (yyval) = enter(DOT);
1361 (yyval) = unary(STAR, (yyval)); }
1362 #line 1363 "egrep.c" /* yacc.c:1646 */
1363 break;
1364
1365 case 8:
1366 #line 122 "../../src/egrep.y" /* yacc.c:1646 */
1367 { (yyval) = enter((yyvsp[0])); }
1368 #line 1369 "egrep.c" /* yacc.c:1646 */
1369 break;
1370
1371 case 9:
1372 #line 124 "../../src/egrep.y" /* yacc.c:1646 */
1373 { (yyval) = enter(DOT); }
1374 #line 1375 "egrep.c" /* yacc.c:1646 */
1375 break;
1376
1377 case 10:
1378 #line 126 "../../src/egrep.y" /* yacc.c:1646 */
1379 { (yyval) = cclenter(CCL); }
1380 #line 1381 "egrep.c" /* yacc.c:1646 */
1381 break;
1382
1383 case 11:
1384 #line 128 "../../src/egrep.y" /* yacc.c:1646 */
1385 { (yyval) = cclenter(NCCL); }
1386 #line 1387 "egrep.c" /* yacc.c:1646 */
1387 break;
1388
1389 case 12:
1390 #line 132 "../../src/egrep.y" /* yacc.c:1646 */
1391 { (yyval) = node(OR, (yyvsp[-2]), (yyvsp[0])); }
1392 #line 1393 "egrep.c" /* yacc.c:1646 */
1393 break;
1394
1395 case 13:
1396 #line 134 "../../src/egrep.y" /* yacc.c:1646 */
1397 { (yyval) = node(CAT, (yyvsp[-1]), (yyvsp[0])); }
1398 #line 1399 "egrep.c" /* yacc.c:1646 */
1399 break;
1400
1401 case 14:
1402 #line 136 "../../src/egrep.y" /* yacc.c:1646 */
1403 { (yyval) = unary(STAR, (yyvsp[-1])); }
1404 #line 1405 "egrep.c" /* yacc.c:1646 */
1405 break;
1406
1407 case 15:
1408 #line 138 "../../src/egrep.y" /* yacc.c:1646 */
1409 { (yyval) = unary(PLUS, (yyvsp[-1])); }
1410 #line 1411 "egrep.c" /* yacc.c:1646 */
1411 break;
1412
1413 case 16:
1414 #line 140 "../../src/egrep.y" /* yacc.c:1646 */
1415 { (yyval) = unary(QUEST, (yyvsp[-1])); }
1416 #line 1417 "egrep.c" /* yacc.c:1646 */
1417 break;
1418
1419 case 17:
1420 #line 142 "../../src/egrep.y" /* yacc.c:1646 */
1421 { (yyval) = (yyvsp[-1]); }
1422 #line 1423 "egrep.c" /* yacc.c:1646 */
1423 break;
1424
1425
1426 #line 1427 "egrep.c" /* yacc.c:1646 */
1427 default: break;
1428 }
1429 /* User semantic actions sometimes alter yychar, and that requires
1430 that yytoken be updated with the new translation. We take the
1431 approach of translating immediately before every use of yytoken.
1432 One alternative is translating here after every semantic action,
1433 but that translation would be missed if the semantic action invokes
1434 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1435 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
1436 incorrect destructor might then be invoked immediately. In the
1437 case of YYERROR or YYBACKUP, subsequent parser actions might lead
1438 to an incorrect destructor call or verbose syntax error message
1439 before the lookahead is translated. */
1440 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1441
1442 YYPOPSTACK (yylen);
1443 yylen = 0;
1444 YY_STACK_PRINT (yyss, yyssp);
1445
1446 *++yyvsp = yyval;
1447
1448 /* Now 'shift' the result of the reduction. Determine what state
1449 that goes to, based on the state we popped back to and the rule
1450 number reduced by. */
1451
1452 yyn = yyr1[yyn];
1453
1454 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1455 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1456 yystate = yytable[yystate];
1457 else
1458 yystate = yydefgoto[yyn - YYNTOKENS];
1459
1460 goto yynewstate;
1461
1462
1463 /*--------------------------------------.
1464 | yyerrlab -- here on detecting error. |
1465 `--------------------------------------*/
1466 yyerrlab:
1467 /* Make sure we have latest lookahead translation. See comments at
1468 user semantic actions for why this is necessary. */
1469 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1470
1471 /* If not already recovering from an error, report this error. */
1472 if (!yyerrstatus)
1473 {
1474 ++yynerrs;
1475 #if ! YYERROR_VERBOSE
1476 yyerror (YY_("syntax error"));
1477 #else
1478 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1479 yyssp, yytoken)
1480 {
1481 char const *yymsgp = YY_("syntax error");
1482 int yysyntax_error_status;
1483 yysyntax_error_status = YYSYNTAX_ERROR;
1484 if (yysyntax_error_status == 0)
1485 yymsgp = yymsg;
1486 else if (yysyntax_error_status == 1)
1487 {
1488 if (yymsg != yymsgbuf)
1489 YYSTACK_FREE (yymsg);
1490 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1491 if (!yymsg)
1492 {
1493 yymsg = yymsgbuf;
1494 yymsg_alloc = sizeof yymsgbuf;
1495 yysyntax_error_status = 2;
1496 }
1497 else
1498 {
1499 yysyntax_error_status = YYSYNTAX_ERROR;
1500 yymsgp = yymsg;
1501 }
1502 }
1503 yyerror (yymsgp);
1504 if (yysyntax_error_status == 2)
1505 goto yyexhaustedlab;
1506 }
1507 # undef YYSYNTAX_ERROR
1508 #endif
1509 }
1510
1511
1512
1513 if (yyerrstatus == 3)
1514 {
1515 /* If just tried and failed to reuse lookahead token after an
1516 error, discard it. */
1517
1518 if (yychar <= YYEOF)
1519 {
1520 /* Return failure if at end of input. */
1521 if (yychar == YYEOF)
1522 YYABORT;
1523 }
1524 else
1525 {
1526 yydestruct ("Error: discarding",
1527 yytoken, &yylval);
1528 yychar = YYEMPTY;
1529 }
1530 }
1531
1532 /* Else will try to reuse lookahead token after shifting the error
1533 token. */
1534 goto yyerrlab1;
1535
1536
1537 /*---------------------------------------------------.
1538 | yyerrorlab -- error raised explicitly by YYERROR. |
1539 `---------------------------------------------------*/
1540 yyerrorlab:
1541
1542 /* Pacify compilers like GCC when the user code never invokes
1543 YYERROR and the label yyerrorlab therefore never appears in user
1544 code. */
1545 if (/*CONSTCOND*/ 0)
1546 goto yyerrorlab;
1547
1548 /* Do not reclaim the symbols of the rule whose action triggered
1549 this YYERROR. */
1550 YYPOPSTACK (yylen);
1551 yylen = 0;
1552 YY_STACK_PRINT (yyss, yyssp);
1553 yystate = *yyssp;
1554 goto yyerrlab1;
1555
1556
1557 /*-------------------------------------------------------------.
1558 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1559 `-------------------------------------------------------------*/
1560 yyerrlab1:
1561 yyerrstatus = 3; /* Each real token shifted decrements this. */
1562
1563 for (;;)
1564 {
1565 yyn = yypact[yystate];
1566 if (!yypact_value_is_default (yyn))
1567 {
1568 yyn += YYTERROR;
1569 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1570 {
1571 yyn = yytable[yyn];
1572 if (0 < yyn)
1573 break;
1574 }
1575 }
1576
1577 /* Pop the current state because it cannot handle the error token. */
1578 if (yyssp == yyss)
1579 YYABORT;
1580
1581
1582 yydestruct ("Error: popping",
1583 yystos[yystate], yyvsp);
1584 YYPOPSTACK (1);
1585 yystate = *yyssp;
1586 YY_STACK_PRINT (yyss, yyssp);
1587 }
1588
1589 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1590 *++yyvsp = yylval;
1591 YY_IGNORE_MAYBE_UNINITIALIZED_END
1592
1593
1594 /* Shift the error token. */
1595 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1596
1597 yystate = yyn;
1598 goto yynewstate;
1599
1600
1601 /*-------------------------------------.
1602 | yyacceptlab -- YYACCEPT comes here. |
1603 `-------------------------------------*/
1604 yyacceptlab:
1605 yyresult = 0;
1606 goto yyreturn;
1607
1608 /*-----------------------------------.
1609 | yyabortlab -- YYABORT comes here. |
1610 `-----------------------------------*/
1611 yyabortlab:
1612 yyresult = 1;
1613 goto yyreturn;
1614
1615 #if !defined yyoverflow || YYERROR_VERBOSE
1616 /*-------------------------------------------------.
1617 | yyexhaustedlab -- memory exhaustion comes here. |
1618 `-------------------------------------------------*/
1619 yyexhaustedlab:
1620 yyerror (YY_("memory exhausted"));
1621 yyresult = 2;
1622 /* Fall through. */
1623 #endif
1624
1625 yyreturn:
1626 if (yychar != YYEMPTY)
1627 {
1628 /* Make sure we have latest lookahead translation. See comments at
1629 user semantic actions for why this is necessary. */
1630 yytoken = YYTRANSLATE (yychar);
1631 yydestruct ("Cleanup: discarding lookahead",
1632 yytoken, &yylval);
1633 }
1634 /* Do not reclaim the symbols of the rule whose action triggered
1635 this YYABORT or YYACCEPT. */
1636 YYPOPSTACK (yylen);
1637 YY_STACK_PRINT (yyss, yyssp);
1638 while (yyssp != yyss)
1639 {
1640 yydestruct ("Cleanup: popping",
1641 yystos[*yyssp], yyvsp);
1642 YYPOPSTACK (1);
1643 }
1644 #ifndef yyoverflow
1645 if (yyss != yyssa)
1646 YYSTACK_FREE (yyss);
1647 #endif
1648 #if YYERROR_VERBOSE
1649 if (yymsg != yymsgbuf)
1650 YYSTACK_FREE (yymsg);
1651 #endif
1652 return yyresult;
1653 }
1654 #line 146 "../../src/egrep.y" /* yacc.c:1906 */
1655
1656 static int
yyerror(char * s)1657 yyerror(char *s)
1658 {
1659 message = s;
1660 longjmp(env, 1);
1661 return 1; /* silence a warning */
1662 }
1663
1664 static int
yylex(void)1665 yylex(void)
1666 {
1667 int cclcnt, x;
1668 char c, d;
1669
1670 switch(c = nextch()) {
1671 case '|':
1672 case '\n':
1673 return (OR);
1674 case '*':
1675 return (STAR);
1676 case '+':
1677 return (PLUS);
1678 case '?':
1679 return (QUEST);
1680 case '(':
1681 case ')':
1682 return (c);
1683 case '.':
1684 return (DOT);
1685 case '\0':
1686 return (0);
1687 case '[':
1688 x = CCL;
1689 cclcnt = 0;
1690 count = nxtchar++;
1691 if ((c = nextch()) == '^') {
1692 x = NCCL;
1693 c = nextch();
1694 }
1695 do {
1696 if (c == '\0')
1697 synerror();
1698 if ( (c == '-')
1699 && (cclcnt > 0)
1700 && (chars[nxtchar-1] != 0)
1701 ) {
1702 if ((d = nextch()) != 0) {
1703 c = chars[nxtchar-1];
1704 while ((unsigned int)c < (unsigned int)d) {
1705 if (nxtchar >= MAXLIN)
1706 overflo();
1707 chars[nxtchar++] = ++c;
1708 cclcnt++;
1709 }
1710 continue;
1711 } /* if() */
1712 } /* if() */
1713 if (nxtchar >= MAXLIN)
1714 overflo();
1715 chars[nxtchar++] = c;
1716 cclcnt++;
1717 } while ((c = nextch()) != ']');
1718 chars[count] = cclcnt;
1719 return (x);
1720 case '\\':
1721 if ((c = nextch()) == '\0')
1722 synerror();
1723 yylval = c;
1724 return (CHAR);
1725 case '$':
1726 case '^':
1727 c = '\n';
1728 yylval = c;
1729 return (CHAR);
1730 default:
1731 yylval = c;
1732 return (CHAR);
1733 }
1734 }
1735
1736 static void
synerror(void)1737 synerror(void)
1738 {
1739 yyerror("Syntax error");
1740 }
1741
1742 static unsigned int
enter(int x)1743 enter(int x)
1744 {
1745 if(line >= MAXLIN)
1746 overflo();
1747 name[line] = x;
1748 left[line] = 0;
1749 right[line] = 0;
1750 return(line++);
1751 }
1752
1753 static unsigned int
cclenter(int x)1754 cclenter(int x)
1755 {
1756 unsigned int linno;
1757
1758 linno = enter(x);
1759 right[linno] = count;
1760 return (linno);
1761 }
1762
1763 static int
node(int x,int l,int r)1764 node(int x, int l, int r)
1765 {
1766 if(line >= MAXLIN)
1767 overflo();
1768 name[line] = x;
1769 left[line] = l;
1770 right[line] = r;
1771 parent[l] = line;
1772 parent[r] = line;
1773 return(line++);
1774 }
1775
1776 static int
unary(int x,int d)1777 unary(int x, int d)
1778 {
1779 if(line >= MAXLIN)
1780 overflo();
1781 name[line] = x;
1782 left[line] = d;
1783 right[line] = 0;
1784 parent[d] = line;
1785 return(line++);
1786 }
1787
1788 static void
overflo(void)1789 overflo(void)
1790 {
1791 yyerror("internal table overflow");
1792 }
1793
1794 static void
cfoll(int v)1795 cfoll(int v)
1796 {
1797 unsigned int i;
1798
1799 if (left[v] == 0) {
1800 count = 0;
1801 for (i = 1; i <= line; i++)
1802 tmpstat[i] = 0;
1803 follow(v);
1804 add(foll, v);
1805 } else if (right[v] == 0)
1806 cfoll(left[v]);
1807 else {
1808 cfoll(left[v]);
1809 cfoll(right[v]);
1810 }
1811 }
1812
1813 static void
cgotofn(void)1814 cgotofn(void)
1815 {
1816 unsigned int i, n, s;
1817 int c, k;
1818 char symbol[NCHARS];
1819 unsigned int j, l, pc, pos;
1820 unsigned int nc;
1821 int curpos;
1822 unsigned int num, number, newpos;
1823
1824 count = 0;
1825 for (n=3; n<=line; n++)
1826 tmpstat[n] = 0;
1827 if (cstate(line-1)==0) {
1828 tmpstat[line] = 1;
1829 count++;
1830 out[0] = 1;
1831 }
1832 for (n=3; n<=line; n++)
1833 initstat[n] = tmpstat[n];
1834 count--; /*leave out position 1 */
1835 icount = count;
1836 tmpstat[1] = 0;
1837 add(state, 0);
1838 n = 0;
1839 for (s = 0; s <= n; s++) {
1840 if (out[s] == 1)
1841 continue;
1842 for (i = 0; i < NCHARS; i++)
1843 symbol[i] = 0;
1844 num = positions[state[s]];
1845 count = icount;
1846 for (i = 3; i <= line; i++)
1847 tmpstat[i] = initstat[i];
1848 pos = state[s] + 1;
1849 for (i = 0; i < num; i++) {
1850 curpos = positions[pos];
1851 if ((c = name[curpos]) >= 0) {
1852 if (c < NCHARS) {
1853 symbol[c] = 1;
1854 } else if (c == DOT) {
1855 for (k = 0; k < NCHARS; k++)
1856 if (k != '\n')
1857 symbol[k] = 1;
1858 } else if (c == CCL) {
1859 nc = chars[right[curpos]];
1860 pc = right[curpos] + 1;
1861 for (j = 0; j < nc; j++)
1862 symbol[(unsigned char)chars[pc++]] = 1;
1863 } else if (c == NCCL) {
1864 nc = chars[right[curpos]];
1865 for (j = 0; j < NCHARS; j++) {
1866 pc = right[curpos] + 1;
1867 for (l = 0; l < nc; l++)
1868 if (j==(unsigned char)chars[pc++])
1869 goto cont;
1870 if (j != '\n')
1871 symbol[j] = 1;
1872 cont:
1873 ;
1874 }
1875 }
1876 }
1877 pos++;
1878 } /* for (i) */
1879 for (c=0; c<NCHARS; c++) {
1880 if (symbol[c] == 1) {
1881 /* nextstate(s,c) */
1882 count = icount;
1883 for (i=3; i <= line; i++)
1884 tmpstat[i] = initstat[i];
1885 pos = state[s] + 1;
1886 for (i=0; i<num; i++) {
1887 curpos = positions[pos];
1888 if ((k = name[curpos]) >= 0)
1889 if ((k == c)
1890 || (k == DOT)
1891 || (k == CCL && member(c, right[curpos], 1))
1892 || (k == NCCL && member(c, right[curpos], 0))
1893 ) {
1894 number = positions[foll[curpos]];
1895 newpos = foll[curpos] + 1;
1896 for (j = 0; j < number; j++) {
1897 if (tmpstat[positions[newpos]] != 1) {
1898 tmpstat[positions[newpos]] = 1;
1899 count++;
1900 }
1901 newpos++;
1902 }
1903 }
1904 pos++;
1905 } /* end nextstate */
1906 if (notin(n)) {
1907 if (n >= NSTATES)
1908 overflo();
1909 add(state, ++n);
1910 if (tmpstat[line] == 1)
1911 out[n] = 1;
1912 gotofn[s][c] = n;
1913 } else {
1914 gotofn[s][c] = xstate;
1915 }
1916 } /* if (symbol) */
1917 } /* for(c) */
1918 } /* for(s) */
1919 }
1920
1921 static int
cstate(int v)1922 cstate(int v)
1923 {
1924 int b;
1925 if (left[v] == 0) {
1926 if (tmpstat[v] != 1) {
1927 tmpstat[v] = 1;
1928 count++;
1929 }
1930 return(1);
1931 }
1932 else if (right[v] == 0) {
1933 if (cstate(left[v]) == 0) return (0);
1934 else if (name[v] == PLUS) return (1);
1935 else return (0);
1936 }
1937 else if (name[v] == CAT) {
1938 if (cstate(left[v]) == 0 && cstate(right[v]) == 0) return (0);
1939 else return (1);
1940 }
1941 else { /* name[v] == OR */
1942 b = cstate(right[v]);
1943 if (cstate(left[v]) == 0 || b == 0) return (0);
1944 else return (1);
1945 }
1946 }
1947
1948 static int
member(int symb,int set,int torf)1949 member(int symb, int set, int torf)
1950 {
1951 unsigned int i, num, pos;
1952
1953 num = chars[set];
1954 pos = set + 1;
1955 for (i = 0; i < num; i++)
1956 if (symb == (unsigned char)(chars[pos++]))
1957 return (torf);
1958 return (!torf);
1959 }
1960
1961 static int
notin(int n)1962 notin(int n)
1963 {
1964 int i, j, pos;
1965 for (i=0; i<=n; i++) {
1966 if (positions[state[i]] == count) {
1967 pos = state[i] + 1;
1968 for (j=0; j < count; j++)
1969 if (tmpstat[positions[pos++]] != 1) goto nxt;
1970 xstate = i;
1971 return (0);
1972 }
1973 nxt: ;
1974 }
1975 return (1);
1976 }
1977
1978 static void
add(int * array,int n)1979 add(int *array, int n)
1980 {
1981 unsigned int i;
1982
1983 if (nxtpos + count > MAXPOS)
1984 overflo();
1985 array[n] = nxtpos;
1986 positions[nxtpos++] = count;
1987 for (i=3; i <= line; i++) {
1988 if (tmpstat[i] == 1) {
1989 positions[nxtpos++] = i;
1990 }
1991 }
1992 }
1993
1994 static void
follow(unsigned int v)1995 follow(unsigned int v)
1996 {
1997 unsigned int p;
1998
1999 if (v == line)
2000 return;
2001 p = parent[v];
2002 switch(name[p]) {
2003 case STAR:
2004 case PLUS: cstate(v);
2005 follow(p);
2006 return;
2007
2008 case OR:
2009 case QUEST: follow(p);
2010 return;
2011
2012 case CAT:
2013 if (v == left[p]) {
2014 if (cstate(right[p]) == 0) {
2015 follow(p);
2016 return;
2017 }
2018 } else
2019 follow(p);
2020 return;
2021 case FINAL:
2022 if (tmpstat[line] != 1) {
2023 tmpstat[line] = 1;
2024 count++;
2025 }
2026 return;
2027 }
2028 }
2029
2030 char *
egrepinit(char * egreppat)2031 egrepinit(char *egreppat)
2032 {
2033 /* initialize the global data */
2034 memset(gotofn, 0, sizeof(gotofn));
2035 memset(state, 0, sizeof(state));
2036 memset(out, 0, sizeof(out));
2037 line = 1;
2038 memset(name, 0, sizeof(name));
2039 memset(left, 0, sizeof(left));
2040 memset(right, 0, sizeof(right));
2041 memset(parent, 0, sizeof(parent));
2042 memset(foll, 0, sizeof(foll));
2043 memset(positions, 0, sizeof(positions));
2044 memset(chars, 0, sizeof(chars));
2045 nxtpos = 0;
2046 nxtchar = 0;
2047 memset(tmpstat, 0, sizeof(tmpstat));
2048 memset(initstat, 0, sizeof(initstat));
2049 xstate = 0;
2050 count = 0;
2051 icount = 0;
2052 input = egreppat;
2053 message = NULL;
2054 if (setjmp(env) == 0) {
2055 yyparse();
2056 cfoll(line-1);
2057 cgotofn();
2058 }
2059 return(message);
2060 }
2061
2062 static char buf[2 * BUFSIZ];
2063 static const char *buf_end = buf + (sizeof(buf) / sizeof(*buf));
2064
read_next_chunk(char ** p,FILE * fptr)2065 static size_t read_next_chunk(char **p, FILE *fptr)
2066 {
2067 if (*p <= (buf + BUFSIZ)) {
2068 /* bwlow the middle, so enough space left for one entire BUFSIZ */
2069 return fread(*p, sizeof(**p), BUFSIZ, fptr);
2070 } else if (*p == buf_end) {
2071 /* exactly at end ... wrap around and use lower half */
2072 *p = buf;
2073 return fread(*p, sizeof(**p), BUFSIZ, fptr);
2074 }
2075 /* somewhere in second half, so do a limited read */
2076 return fread(*p, sizeof(**p), buf_end - *p, fptr);
2077 }
2078
2079 int
egrep(char * file,FILE * output,char * format)2080 egrep(char *file, FILE *output, char *format)
2081 {
2082 char *p;
2083 unsigned int cstat;
2084 int ccount;
2085 char *nlp;
2086 unsigned int istat;
2087 int in_line;
2088 FILE *fptr;
2089
2090 if ((fptr = myfopen(file, "r")) == NULL)
2091 return(-1);
2092
2093 lnum = 1;
2094 p = buf;
2095 nlp = p;
2096 ccount = read_next_chunk(&p, fptr);
2097
2098 if (ccount <= 0) {
2099 fclose(fptr);
2100 return(0);
2101 }
2102 in_line = 1;
2103 istat = cstat = (unsigned int) gotofn[0]['\n'];
2104 if (out[cstat])
2105 goto found;
2106 for (;;) {
2107 if (!iflag) {
2108 /* all input chars made positive */
2109 cstat = (unsigned int) gotofn[cstat][(unsigned char)*p];
2110 } else {
2111 /* for -i option*/
2112 cstat = (unsigned int) gotofn[cstat][tolower((unsigned char)*p)];
2113 }
2114 if (out[cstat]) {
2115 found:
2116 for(;;) {
2117 if (*p++ == '\n') {
2118 in_line = 0;
2119 succeed:
2120 fprintf(output, format, file, lnum);
2121 if (p <= nlp) {
2122 while (nlp < buf_end)
2123 putc(*nlp++, output);
2124 nlp = buf;
2125 }
2126 while (nlp < p)
2127 putc(*nlp++, output);
2128 lnum++;
2129 nlp = p;
2130 if (out[cstat = istat] == 0)
2131 goto brk2;
2132 } /* if (p++ == \n) */
2133 cfound:
2134 if (--ccount <= 0) {
2135 ccount = read_next_chunk(&p, fptr);
2136 if (ccount <= 0) {
2137 if (in_line) {
2138 in_line = 0;
2139 goto succeed;
2140 }
2141 fclose(fptr);
2142 return(0);
2143 }
2144 } /* if(ccount <= 0) */
2145 in_line = 1;
2146 } /* for(ever) */
2147 } /* if(out[cstat]) */
2148
2149 if (*p++ == '\n') {
2150 in_line = 0;
2151 lnum++;
2152 nlp = p;
2153 if (out[(cstat=istat)])
2154 goto cfound;
2155 }
2156 brk2:
2157 if (--ccount <= 0) {
2158 ccount = read_next_chunk(&p, fptr);
2159 if (ccount <= 0)
2160 break;
2161 }
2162 in_line = 1;
2163 }
2164 fclose(fptr);
2165 return(0);
2166 }
2167
2168 /* FIXME HBB: should export this to a separate file and use
2169 * AC_REPLACE_FUNCS() */
2170 #if !STDC_HEADERS && !defined(HAVE_MEMSET) && !defined(HAVE_MEMORY_H)
2171 /*LINTLIBRARY*/
2172 /*
2173 * Set an array of n chars starting at sp to the character c.
2174 * Return sp.
2175 */
2176 char *
memset(char * sp,char c,int n)2177 memset(char *sp, char c, int n)
2178 {
2179 char *sp0 = sp;
2180
2181 while (--n >= 0)
2182 *sp++ = c;
2183 return (sp0);
2184 }
2185 #endif
2186
2187 void
egrepcaseless(int i)2188 egrepcaseless(int i)
2189 {
2190 iflag = i; /* simulate "egrep -i" */
2191 }
2192