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