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