~ubuntu-branches/ubuntu/raring/heimdal/raring

« back to all changes in this revision

Viewing changes to lib/sl/slc-gram.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2011-10-03 23:50:05 UTC
  • mfrom: (1.1.15) (2.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20111003235005-0voibbgdhyqmtp6w
Tags: 1.5.dfsg.1-3
Add conflicts with kcc to heimdal-clients. Closes: #644138

Show diffs side-by-side

added added

removed removed

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