1
/* A Bison parser, made by GNU Bison 2.3. */
3
/* Skeleton implementation for Bison's Yacc-like parsers in C
5
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6
Free Software Foundation, Inc.
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)
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.
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. */
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.
33
This special exception was added by the Free Software Foundation in
34
version 2.2 of Bison. */
36
/* C LALR(1) parser skeleton written by Richard Stallman, by
37
simplifying the original so-called "semantic" parser. */
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. */
46
/* Identify Bison output. */
50
#define YYBISON_VERSION "2.3"
53
#define YYSKELETON_NAME "yacc.c"
58
/* Using locations. */
59
#define YYLSP_NEEDED 0
66
/* Put the tokens into the symbol table, so that GDB and other debuggers
80
/* Copy the first part of user declarations. */
84
* Copyright (c) 2004-2006 Kungliga Tekniska Högskolan
85
* (Royal Institute of Technology, Stockholm, Sweden).
86
* All rights reserved.
88
* Redistribution and use in source and binary forms, with or without
89
* modification, are permitted provided that the following conditions
92
* 1. Redistributions of source code must retain the above copyright
93
* notice, this list of conditions and the following disclaimer.
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.
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.
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
129
extern struct assignment *assignment;
131
/* Declarations for Bison:
133
#define YYMALLOC malloc
138
/* Enabling traces. */
143
/* Enabling verbose error messages. */
144
#ifdef YYERROR_VERBOSE
145
# undef YYERROR_VERBOSE
146
# define YYERROR_VERBOSE 1
148
# define YYERROR_VERBOSE 0
151
/* Enabling the token table. */
152
#ifndef YYTOKEN_TABLE
153
# define YYTOKEN_TABLE 0
156
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
157
typedef union YYSTYPE
158
#line 57 "slc-gram.y"
161
struct assignment *assignment;
163
/* Line 193 of yacc.c. */
164
#line 165 "slc-gram.c"
166
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
167
# define YYSTYPE_IS_DECLARED 1
168
# define YYSTYPE_IS_TRIVIAL 1
173
/* Copy the second part of user declarations. */
176
/* Line 216 of yacc.c. */
177
#line 178 "slc-gram.c"
184
typedef YYTYPE_UINT8 yytype_uint8;
186
typedef unsigned char yytype_uint8;
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;
195
typedef short int yytype_int8;
199
typedef YYTYPE_UINT16 yytype_uint16;
201
typedef unsigned short int yytype_uint16;
205
typedef YYTYPE_INT16 yytype_int16;
207
typedef short int yytype_int16;
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
220
# define YYSIZE_T unsigned int
224
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
227
# if defined YYENABLE_NLS && YYENABLE_NLS
229
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
230
# define YY_(msgid) dgettext ("bison-runtime", msgid)
234
# define YY_(msgid) msgid
238
/* Suppress unused-variable warnings by "using" E. */
239
#if ! defined lint || defined __GNUC__
240
# define YYUSE(e) ((void) (e))
242
# define YYUSE(e) /* empty */
245
/* Identity function, used to suppress warnings about constant conditions. */
249
#if (defined __STDC__ || defined __C99__FUNC__ \
250
|| defined __cplusplus || defined _MSC_VER)
263
#if ! defined yyoverflow || YYERROR_VERBOSE
265
/* The parser invokes alloca or malloc; define the necessary symbols. */
267
# ifdef YYSTACK_USE_ALLOCA
268
# if YYSTACK_USE_ALLOCA
270
# define YYSTACK_ALLOC __builtin_alloca
271
# elif defined __BUILTIN_VA_ARG_INCR
272
# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
274
# define YYSTACK_ALLOC __alloca
275
# elif defined _MSC_VER
276
# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
277
# define alloca _alloca
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 */
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 */
302
# define YYSTACK_ALLOC YYMALLOC
303
# define YYSTACK_FREE YYFREE
304
# ifndef YYSTACK_ALLOC_MAXIMUM
305
# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
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 */
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 */
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 */
330
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
333
#if (! defined yyoverflow \
334
&& (! defined __cplusplus \
335
|| (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
337
/* A type that is properly aligned for any stack member. */
344
/* The size of the maximum gap between one aligned stack and the next. */
345
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
347
/* The size of an array large to enough to hold all stacks, each with
349
# define YYSTACK_BYTES(N) \
350
((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
351
+ YYSTACK_GAP_MAXIMUM)
353
/* Copy COUNT objects from FROM to TO. The source and destination do
356
# if defined __GNUC__ && 1 < __GNUC__
357
# define YYCOPY(To, From, Count) \
358
__builtin_memcpy (To, From, (Count) * sizeof (*(From)))
360
# define YYCOPY(To, From, Count) \
364
for (yyi = 0; yyi < (Count); yyi++) \
365
(To)[yyi] = (From)[yyi]; \
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
376
# define YYSTACK_RELOCATE(Stack) \
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); \
389
/* YYFINAL -- State number of the termination state. */
391
/* YYLAST -- Last index in YYTABLE. */
394
/* YYNTOKENS -- Number of terminals. */
396
/* YYNNTS -- Number of nonterminals. */
398
/* YYNRULES -- Number of rules. */
400
/* YYNRULES -- Number of states. */
403
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
405
#define YYMAXUTOK 259
407
#define YYTRANSLATE(YYX) \
408
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
410
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
411
static const yytype_uint8 yytranslate[] =
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
442
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
444
static const yytype_uint8 yyprhs[] =
446
0, 0, 3, 5, 8, 10, 14
449
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
450
static const yytype_int8 yyrhs[] =
452
9, 0, -1, 10, -1, 11, 10, -1, 11, -1,
453
3, 5, 4, -1, 3, 5, 6, 10, 7, -1
456
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
457
static const yytype_uint8 yyrline[] =
459
0, 70, 70, 76, 81, 84, 93
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[] =
468
"$end", "error", "$undefined", "LITERAL", "STRING", "'='", "'{'", "'}'",
469
"$accept", "start", "assignments", "assignment", 0
474
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
476
static const yytype_uint16 yytoknum[] =
478
0, 256, 257, 258, 259, 61, 123, 125
482
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
483
static const yytype_uint8 yyr1[] =
485
0, 8, 9, 10, 10, 11, 11
488
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
489
static const yytype_uint8 yyr2[] =
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[] =
499
0, 0, 0, 2, 4, 0, 1, 3, 5, 0,
503
/* YYDEFGOTO[NTERM-NUM]. */
504
static const yytype_int8 yydefgoto[] =
509
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
511
#define YYPACT_NINF -5
512
static const yytype_int8 yypact[] =
514
-1, 1, 4, -5, -1, -3, -5, -5, -5, -1,
518
/* YYPGOTO[NTERM-NUM]. */
519
static const yytype_int8 yypgoto[] =
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[] =
531
7, 8, 1, 9, 6, 10, 5, 11
534
static const yytype_uint8 yycheck[] =
536
4, 4, 3, 6, 0, 9, 5, 7
539
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
540
symbol of state STATE-NUM. */
541
static const yytype_uint8 yystos[] =
543
0, 3, 9, 10, 11, 5, 0, 10, 4, 6,
547
#define yyerrok (yyerrstatus = 0)
548
#define yyclearin (yychar = YYEMPTY)
552
#define YYACCEPT goto yyacceptlab
553
#define YYABORT goto yyabortlab
554
#define YYERROR goto yyerrorlab
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. */
561
#define YYFAIL goto yyerrlab
563
#define YYRECOVERING() (!!yyerrstatus)
565
#define YYBACKUP(Token, Value) \
567
if (yychar == YYEMPTY && yylen == 1) \
571
yytoken = YYTRANSLATE (yychar); \
577
yyerror (YY_("syntax error: cannot back up")); \
584
#define YYERRCODE 256
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). */
591
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
592
#ifndef YYLLOC_DEFAULT
593
# define YYLLOC_DEFAULT(Current, Rhs, N) \
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; \
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; \
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. */
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)
624
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
629
/* YYLEX -- calling `yylex' with the right arguments. */
632
# define YYLEX yylex (YYLEX_PARAM)
634
# define YYLEX yylex ()
637
/* Enable debugging if requested. */
641
# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
642
# define YYFPRINTF fprintf
645
# define YYDPRINTF(Args) \
651
# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
655
YYFPRINTF (stderr, "%s ", Title); \
656
yy_symbol_print (stderr, \
658
YYFPRINTF (stderr, "\n"); \
663
/*--------------------------------.
664
| Print this symbol on YYOUTPUT. |
665
`--------------------------------*/
668
#if (defined __STDC__ || defined __C99__FUNC__ \
669
|| defined __cplusplus || defined _MSC_VER)
671
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
674
yy_symbol_value_print (yyoutput, yytype, yyvaluep)
677
YYSTYPE const * const yyvaluep;
683
if (yytype < YYNTOKENS)
684
YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
696
/*--------------------------------.
697
| Print this symbol on YYOUTPUT. |
698
`--------------------------------*/
700
#if (defined __STDC__ || defined __C99__FUNC__ \
701
|| defined __cplusplus || defined _MSC_VER)
703
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
706
yy_symbol_print (yyoutput, yytype, yyvaluep)
709
YYSTYPE const * const yyvaluep;
712
if (yytype < YYNTOKENS)
713
YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
715
YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
717
yy_symbol_value_print (yyoutput, yytype, yyvaluep);
718
YYFPRINTF (yyoutput, ")");
721
/*------------------------------------------------------------------.
722
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
724
`------------------------------------------------------------------*/
726
#if (defined __STDC__ || defined __C99__FUNC__ \
727
|| defined __cplusplus || defined _MSC_VER)
729
yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
732
yy_stack_print (bottom, top)
733
yytype_int16 *bottom;
737
YYFPRINTF (stderr, "Stack now");
738
for (; bottom <= top; ++bottom)
739
YYFPRINTF (stderr, " %d", *bottom);
740
YYFPRINTF (stderr, "\n");
743
# define YY_STACK_PRINT(Bottom, Top) \
746
yy_stack_print ((Bottom), (Top)); \
750
/*------------------------------------------------.
751
| Report that the YYRULE is going to be reduced. |
752
`------------------------------------------------*/
754
#if (defined __STDC__ || defined __C99__FUNC__ \
755
|| defined __cplusplus || defined _MSC_VER)
757
yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
760
yy_reduce_print (yyvsp, yyrule)
765
int yynrhs = yyr2[yyrule];
767
unsigned long int yylno = yyrline[yyrule];
768
YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
770
/* The symbols being reduced. */
771
for (yyi = 0; yyi < yynrhs; yyi++)
773
fprintf (stderr, " $%d = ", yyi + 1);
774
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
775
&(yyvsp[(yyi + 1) - (yynrhs)])
777
fprintf (stderr, "\n");
781
# define YY_REDUCE_PRINT(Rule) \
784
yy_reduce_print (yyvsp, Rule); \
787
/* Nonzero means print parse trace. It is left uninitialized so that
788
multiple parsers can coexist. */
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 */
798
/* YYINITDEPTH -- initial size of the parser's stacks. */
800
# define YYINITDEPTH 200
803
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
804
if the built-in stack extension method is used).
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. */
811
# define YYMAXDEPTH 10000
819
# if defined __GLIBC__ && defined _STRING_H
820
# define yystrlen strlen
822
/* Return the length of YYSTR. */
823
#if (defined __STDC__ || defined __C99__FUNC__ \
824
|| defined __cplusplus || defined _MSC_VER)
826
yystrlen (const char *yystr)
834
for (yylen = 0; yystr[yylen]; yylen++)
842
# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
843
# define yystpcpy stpcpy
845
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
847
#if (defined __STDC__ || defined __C99__FUNC__ \
848
|| defined __cplusplus || defined _MSC_VER)
850
yystpcpy (char *yydest, const char *yysrc)
853
yystpcpy (yydest, yysrc)
859
const char *yys = yysrc;
861
while ((*yyd++ = *yys++) != '\0')
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
878
yytnamerr (char *yyres, const char *yystr)
883
char const *yyp = yystr;
890
goto do_not_strip_quotes;
894
goto do_not_strip_quotes;
907
do_not_strip_quotes: ;
911
return yystrlen (yystr);
913
return yystpcpy (yyres, yystr) - yyres;
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
925
yysyntax_error (char *yyresult, int yystate, int yychar)
927
int yyn = yypact[yystate];
929
if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
933
int yytype = YYTRANSLATE (yychar);
934
YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
935
YYSIZE_T yysize = yysize0;
937
int yysize_overflow = 0;
938
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
939
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
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");
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;
962
/* Start YYX at -YYN if negative to avoid negative indexes in
964
int yyxbegin = yyn < 0 ? -yyn : 0;
966
/* Stay within bounds of both yycheck and yytname. */
967
int yychecklim = YYLAST - yyn + 1;
968
int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
971
yyarg[0] = yytname[yytype];
972
yyfmt = yystpcpy (yyformat, yyunexpected);
974
for (yyx = yyxbegin; yyx < yyxend; ++yyx)
975
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
977
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
981
yyformat[sizeof yyunexpected - 1] = '\0';
984
yyarg[yycount++] = yytname[yyx];
985
yysize1 = yysize + yytnamerr (0, yytname[yyx]);
986
yysize_overflow |= (yysize1 < yysize);
988
yyfmt = yystpcpy (yyfmt, yyprefix);
993
yysize1 = yysize + yystrlen (yyf);
994
yysize_overflow |= (yysize1 < yysize);
998
return YYSIZE_MAXIMUM;
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;
1007
while ((*yyp = *yyf) != '\0')
1009
if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1011
yyp += yytnamerr (yyp, yyarg[yyi++]);
1024
#endif /* YYERROR_VERBOSE */
1027
/*-----------------------------------------------.
1028
| Release the memory associated to this symbol. |
1029
`-----------------------------------------------*/
1032
#if (defined __STDC__ || defined __C99__FUNC__ \
1033
|| defined __cplusplus || defined _MSC_VER)
1035
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1038
yydestruct (yymsg, yytype, yyvaluep)
1048
YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1059
/* Prevent warnings from -Wmissing-prototypes. */
1061
#ifdef YYPARSE_PARAM
1062
#if defined __STDC__ || defined __cplusplus
1063
int yyparse (void *YYPARSE_PARAM);
1067
#else /* ! YYPARSE_PARAM */
1068
#if defined __STDC__ || defined __cplusplus
1073
#endif /* ! YYPARSE_PARAM */
1077
/* The look-ahead symbol. */
1080
/* The semantic value of the look-ahead symbol. */
1083
/* Number of syntax errors so far. */
1092
#ifdef YYPARSE_PARAM
1093
#if (defined __STDC__ || defined __C99__FUNC__ \
1094
|| defined __cplusplus || defined _MSC_VER)
1096
yyparse (void *YYPARSE_PARAM)
1099
yyparse (YYPARSE_PARAM)
1100
void *YYPARSE_PARAM;
1102
#else /* ! YYPARSE_PARAM */
1103
#if (defined __STDC__ || defined __C99__FUNC__ \
1104
|| defined __cplusplus || defined _MSC_VER)
1118
/* Number of tokens to shift before error messages enabled. */
1120
/* Look-ahead token as an internal (translated) token number. */
1123
/* Buffer for error messages, and its allocated size. */
1125
char *yymsg = yymsgbuf;
1126
YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1129
/* Three stacks and their tools:
1130
`yyss': related to states,
1131
`yyvs': related to semantic values,
1132
`yyls': related to locations.
1134
Refer to the stacks thru separate pointers, to allow yyoverflow
1135
to reallocate them elsewhere. */
1137
/* The state stack. */
1138
yytype_int16 yyssa[YYINITDEPTH];
1139
yytype_int16 *yyss = yyssa;
1140
yytype_int16 *yyssp;
1142
/* The semantic value stack. */
1143
YYSTYPE yyvsa[YYINITDEPTH];
1144
YYSTYPE *yyvs = yyvsa;
1149
#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1151
YYSIZE_T yystacksize = YYINITDEPTH;
1153
/* The variables used to return semantic value and location from the
1158
/* The number of symbols on the RHS of the reduced rule.
1159
Keep to zero when no symbol should be popped. */
1162
YYDPRINTF ((stderr, "Starting parse\n"));
1167
yychar = YYEMPTY; /* Cause a token to be read. */
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. */
1179
/*------------------------------------------------------------.
1180
| yynewstate -- Push a new state, which is found in yystate. |
1181
`------------------------------------------------------------*/
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. */
1190
if (yyss + yystacksize - 1 <= yyssp)
1192
/* Get the current used size of the three stacks, in elements. */
1193
YYSIZE_T yysize = yyssp - yyss + 1;
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
1200
YYSTYPE *yyvs1 = yyvs;
1201
yytype_int16 *yyss1 = yyss;
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),
1217
#else /* no yyoverflow */
1218
# ifndef YYSTACK_RELOCATE
1219
goto yyexhaustedlab;
1221
/* Extend the stack our own way. */
1222
if (YYMAXDEPTH <= yystacksize)
1223
goto yyexhaustedlab;
1225
if (YYMAXDEPTH < yystacksize)
1226
yystacksize = YYMAXDEPTH;
1229
yytype_int16 *yyss1 = yyss;
1230
union yyalloc *yyptr =
1231
(union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1233
goto yyexhaustedlab;
1234
YYSTACK_RELOCATE (yyss);
1235
YYSTACK_RELOCATE (yyvs);
1237
# undef YYSTACK_RELOCATE
1239
YYSTACK_FREE (yyss1);
1242
#endif /* no yyoverflow */
1244
yyssp = yyss + yysize - 1;
1245
yyvsp = yyvs + yysize - 1;
1248
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1249
(unsigned long int) yystacksize));
1251
if (yyss + yystacksize - 1 <= yyssp)
1255
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1264
/* Do appropriate processing given the current state. Read a
1265
look-ahead token if we need one and don't already have one. */
1267
/* First try to decide what to do without reference to look-ahead token. */
1268
yyn = yypact[yystate];
1269
if (yyn == YYPACT_NINF)
1272
/* Not known => get a look-ahead token if don't already have one. */
1274
/* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1275
if (yychar == YYEMPTY)
1277
YYDPRINTF ((stderr, "Reading a token: "));
1281
if (yychar <= YYEOF)
1283
yychar = yytoken = YYEOF;
1284
YYDPRINTF ((stderr, "Now at end of input.\n"));
1288
yytoken = YYTRANSLATE (yychar);
1289
YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1292
/* If the proper action on seeing token YYTOKEN is to reduce or to
1293
detect an error, take that action. */
1295
if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1300
if (yyn == 0 || yyn == YYTABLE_NINF)
1309
/* Count tokens shifted since error; after three, turn off error
1314
/* Shift the look-ahead token. */
1315
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1317
/* Discard the shifted token unless it is eof. */
1318
if (yychar != YYEOF)
1327
/*-----------------------------------------------------------.
1328
| yydefault -- do the default action for the current state. |
1329
`-----------------------------------------------------------*/
1331
yyn = yydefact[yystate];
1337
/*-----------------------------.
1338
| yyreduce -- Do a reduction. |
1339
`-----------------------------*/
1341
/* yyn is the number of a rule to reduce with. */
1344
/* If YYLEN is nonzero, implement the default value of the action:
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];
1355
YY_REDUCE_PRINT (yyn);
1359
#line 71 "slc-gram.y"
1361
assignment = (yyvsp[(1) - (1)].assignment);
1366
#line 77 "slc-gram.y"
1368
(yyvsp[(1) - (2)].assignment)->next = (yyvsp[(2) - (2)].assignment);
1369
(yyval.assignment) = (yyvsp[(1) - (2)].assignment);
1374
#line 85 "slc-gram.y"
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;
1386
#line 94 "slc-gram.y"
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;
1398
/* Line 1267 of yacc.c. */
1399
#line 1400 "slc-gram.c"
1402
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1406
YY_STACK_PRINT (yyss, yyssp);
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. */
1417
yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1418
if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1419
yystate = yytable[yystate];
1421
yystate = yydefgoto[yyn - YYNTOKENS];
1426
/*------------------------------------.
1427
| yyerrlab -- here on detecting error |
1428
`------------------------------------*/
1430
/* If not already recovering from an error, report this error. */
1434
#if ! YYERROR_VERBOSE
1435
yyerror (YY_("syntax error"));
1438
YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1439
if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
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);
1448
yymsg_alloc = yyalloc;
1452
yymsg_alloc = sizeof yymsgbuf;
1456
if (0 < yysize && yysize <= yymsg_alloc)
1458
(void) yysyntax_error (yymsg, yystate, yychar);
1463
yyerror (YY_("syntax error"));
1465
goto yyexhaustedlab;
1473
if (yyerrstatus == 3)
1475
/* If just tried and failed to reuse look-ahead token after an
1476
error, discard it. */
1478
if (yychar <= YYEOF)
1480
/* Return failure if at end of input. */
1481
if (yychar == YYEOF)
1486
yydestruct ("Error: discarding",
1492
/* Else will try to reuse look-ahead token after shifting the error
1497
/*---------------------------------------------------.
1498
| yyerrorlab -- error raised explicitly by YYERROR. |
1499
`---------------------------------------------------*/
1502
/* Pacify compilers like GCC when the user code never invokes
1503
YYERROR and the label yyerrorlab therefore never appears in user
1505
if (/*CONSTCOND*/ 0)
1508
/* Do not reclaim the symbols of the rule which action triggered
1512
YY_STACK_PRINT (yyss, yyssp);
1517
/*-------------------------------------------------------------.
1518
| yyerrlab1 -- common code for both syntax error and YYERROR. |
1519
`-------------------------------------------------------------*/
1521
yyerrstatus = 3; /* Each real token shifted decrements this. */
1525
yyn = yypact[yystate];
1526
if (yyn != YYPACT_NINF)
1529
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1537
/* Pop the current state because it cannot handle the error token. */
1542
yydestruct ("Error: popping",
1543
yystos[yystate], yyvsp);
1546
YY_STACK_PRINT (yyss, yyssp);
1555
/* Shift the error token. */
1556
YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1562
/*-------------------------------------.
1563
| yyacceptlab -- YYACCEPT comes here. |
1564
`-------------------------------------*/
1569
/*-----------------------------------.
1570
| yyabortlab -- YYABORT comes here. |
1571
`-----------------------------------*/
1577
/*-------------------------------------------------.
1578
| yyexhaustedlab -- memory exhaustion comes here. |
1579
`-------------------------------------------------*/
1581
yyerror (YY_("memory exhausted"));
1587
if (yychar != YYEOF && yychar != YYEMPTY)
1588
yydestruct ("Cleanup: discarding lookahead",
1590
/* Do not reclaim the symbols of the rule which action triggered
1591
this YYABORT or YYACCEPT. */
1593
YY_STACK_PRINT (yyss, yyssp);
1594
while (yyssp != yyss)
1596
yydestruct ("Cleanup: popping",
1597
yystos[*yyssp], yyvsp);
1602
YYSTACK_FREE (yyss);
1605
if (yymsg != yymsgbuf)
1606
YYSTACK_FREE (yymsg);
1608
/* Make sure YYID is used. */
1609
return YYID (yyresult);
1613
#line 104 "slc-gram.y"
1616
FILE *cfile, *hfile;
1618
struct assignment *assignment;
1622
ex(struct assignment *a, const char *fmt, ...)
1625
fprintf(stderr, "%s:%d: ", a->name, a->lineno);
1627
vfprintf(stderr, fmt, ap);
1629
fprintf(stderr, "\n");
1635
check_option(struct assignment *as)
1637
struct assignment *a;
1642
int seen_argument = 0;
1644
int seen_default = 0;
1647
for(a = as; a != NULL; a = a->next) {
1648
if(strcmp(a->name, "long") == 0)
1650
else if(strcmp(a->name, "short") == 0)
1652
else if(strcmp(a->name, "name") == 0)
1654
else if(strcmp(a->name, "type") == 0)
1656
else if(strcmp(a->name, "argument") == 0)
1658
else if(strcmp(a->name, "help") == 0)
1660
else if(strcmp(a->name, "default") == 0)
1663
ex(a, "unknown name %s", a->name);
1667
if(seen_long == 0 && seen_short == 0) {
1668
ex(as, "neither long nor short option");
1671
if (seen_long == 0 && seen_name == 0) {
1672
ex(as, "either of long or name option must be used");
1676
ex(as, "multiple long options");
1679
if(seen_short > 1) {
1680
ex(as, "multiple short options");
1684
ex(as, "multiple types");
1687
if(seen_argument > 1) {
1688
ex(as, "multiple arguments");
1692
ex(as, "multiple help strings");
1695
if(seen_default > 1) {
1696
ex(as, "multiple default values");
1703
check_command(struct assignment *as)
1705
struct assignment *a;
1707
int seen_function = 0;
1709
int seen_argument = 0;
1710
int seen_minargs = 0;
1711
int seen_maxargs = 0;
1713
for(a = as; a != NULL; a = a->next) {
1714
if(strcmp(a->name, "name") == 0)
1716
else if(strcmp(a->name, "function") == 0) {
1718
} else if(strcmp(a->name, "option") == 0)
1719
ret += check_option(a->u.assignment);
1720
else if(strcmp(a->name, "help") == 0) {
1722
} else if(strcmp(a->name, "argument") == 0) {
1724
} else if(strcmp(a->name, "min_args") == 0) {
1726
} else if(strcmp(a->name, "max_args") == 0) {
1729
ex(a, "unknown name: %s", a->name);
1733
if(seen_name == 0) {
1734
ex(as, "no command name");
1737
if(seen_function > 1) {
1738
ex(as, "multiple function names");
1742
ex(as, "multiple help strings");
1745
if(seen_argument > 1) {
1746
ex(as, "multiple argument strings");
1749
if(seen_minargs > 1) {
1750
ex(as, "multiple min_args strings");
1753
if(seen_maxargs > 1) {
1754
ex(as, "multiple max_args strings");
1762
check(struct assignment *as)
1764
struct assignment *a;
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);
1772
if(a->type != a_assignment) {
1773
fprintf(stderr, "bad command definition %s line %d\n", a->name, a->lineno);
1777
ret += check_command(a->u.assignment);
1782
static struct assignment *
1783
find_next(struct assignment *as, const char *name)
1785
for(as = as->next; as != NULL; as = as->next) {
1786
if(strcmp(as->name, name) == 0)
1792
static struct assignment *
1793
find(struct assignment *as, const char *name)
1795
for(; as != NULL; as = as->next) {
1796
if(strcmp(as->name, name) == 0)
1803
space(FILE *f, int level)
1805
fprintf(f, "%*.*s", level * 4, level * 4, " ");
1809
cprint(int level, const char *fmt, ...)
1813
space(cfile, level);
1814
vfprintf(cfile, fmt, ap);
1819
hprint(int level, const char *fmt, ...)
1823
space(hfile, level);
1824
vfprintf(hfile, fmt, ap);
1828
static void gen_name(char *str);
1831
gen_command(struct assignment *as)
1833
struct assignment *a, *b;
1835
a = find(as, "name");
1836
f = strdup(a->u.value);
1839
fprintf(cfile, "\"%s\", ", a->u.value);
1840
fprintf(cfile, "%s_wrap, ", f);
1841
b = find(as, "argument");
1843
fprintf(cfile, "\"%s %s\", ", a->u.value, b->u.value);
1845
fprintf(cfile, "\"%s\", ", a->u.value);
1846
b = find(as, "help");
1848
fprintf(cfile, "\"%s\"", b->u.value);
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);
1862
for(p = str; *p != '\0'; p++)
1863
if(!isalnum((unsigned char)*p))
1868
make_name(struct assignment *as)
1870
struct assignment *lopt;
1871
struct assignment *type;
1874
lopt = find(as, "long");
1876
lopt = find(as, "name");
1880
type = find(as, "type");
1881
if(strcmp(type->u.value, "-flag") == 0)
1882
asprintf(&s, "%s_flag", lopt->u.value);
1884
asprintf(&s, "%s_%s", lopt->u.value, type->u.value);
1890
static void defval_int(const char *name, struct assignment *defval)
1893
cprint(1, "opt.%s = %s;\n", name, defval->u.value);
1895
cprint(1, "opt.%s = 0;\n", name);
1897
static void defval_neg_flag(const char *name, struct assignment *defval)
1900
cprint(1, "opt.%s = %s;\n", name, defval->u.value);
1902
cprint(1, "opt.%s = 1;\n", name);
1904
static void defval_string(const char *name, struct assignment *defval)
1907
cprint(1, "opt.%s = (char *)(unsigned long)\"%s\";\n", name, defval->u.value);
1909
cprint(1, "opt.%s = NULL;\n", name);
1911
static void defval_strings(const char *name, struct assignment *defval)
1913
cprint(1, "opt.%s.num_strings = 0;\n", name);
1914
cprint(1, "opt.%s.strings = NULL;\n", name);
1917
static void free_strings(const char *name)
1919
cprint(1, "free_getarg_strings (&opt.%s);\n", name);
1922
struct type_handler {
1923
const char *typename;
1925
const char *getarg_type;
1926
void (*defval)(const char*, struct assignment*);
1927
void (*free)(const char*);
1928
} type_handlers[] = {
1942
"struct getarg_strings",
1955
"arg_negative_flag",
1962
static struct type_handler *find_handler(struct assignment *type)
1964
struct type_handler *th;
1965
for(th = type_handlers; th->typename != NULL; th++)
1966
if(strcmp(type->u.value, th->typename) == 0)
1968
ex(type, "unknown type \"%s\"", type->u.value);
1973
gen_options(struct assignment *opt1, const char *name)
1975
struct assignment *tmp;
1977
hprint(0, "struct %s_options {\n", name);
1981
tmp = find_next(tmp, "option")) {
1982
struct assignment *type;
1983
struct type_handler *th;
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);
1996
gen_wrapper(struct assignment *as)
1998
struct assignment *name;
1999
struct assignment *arg;
2000
struct assignment *opt1;
2001
struct assignment *function;
2002
struct assignment *tmp;
2007
name = find(as, "name");
2008
n = strdup(name->u.value);
2010
arg = find(as, "argument");
2013
opt1 = find(as, "option");
2014
function = find(as, "function");
2016
f = function->u.value;
2022
gen_options(opt1, n);
2023
hprint(0, "int %s(struct %s_options*, int, char **);\n", f, n);
2025
hprint(0, "int %s(void*, int, char **);\n", f);
2028
fprintf(cfile, "static int\n");
2029
fprintf(cfile, "%s_wrap(int argc, char **argv)\n", n);
2030
fprintf(cfile, "{\n");
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");
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");
2045
struct type_handler *th;
2049
fprintf(cfile, "\"%s\", ", lopt->u.value);
2051
fprintf(cfile, "NULL, ");
2053
fprintf(cfile, "'%c', ", *sopt->u.value);
2055
fprintf(cfile, "0, ");
2056
th = find_handler(type);
2057
fprintf(cfile, "%s, ", th->getarg_type);
2058
fprintf(cfile, "NULL, ");
2060
fprintf(cfile, "\"%s\", ", help->u.value);
2062
fprintf(cfile, "NULL, ");
2064
fprintf(cfile, "\"%s\"", aarg->u.value);
2067
fprintf(cfile, "NULL");
2068
fprintf(cfile, " },\n");
2070
cprint(2, "{ \"help\", 'h', arg_flag, NULL, NULL, NULL }\n");
2072
cprint(1, "int help_flag = 0;\n");
2074
for(tmp = find(as, "option");
2076
tmp = find_next(tmp, "option")) {
2078
struct assignment *type = find(tmp->u.assignment, "type");
2080
struct assignment *defval = find(tmp->u.assignment, "default");
2082
struct type_handler *th;
2084
s = make_name(tmp->u.assignment);
2085
th = find_handler(type);
2086
(*th->defval)(s, defval);
2090
for(tmp = find(as, "option");
2092
tmp = find_next(tmp, "option")) {
2094
s = make_name(tmp->u.assignment);
2095
cprint(1, "args[%d].value = &opt.%s;\n", nargs++, s);
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");
2106
if(narguments == 0) {
2109
if((tmp = find(as, "min_args")) != NULL) {
2110
min_args = strtol(tmp->u.value, &end, 0);
2112
ex(tmp, "min_args is not numeric");
2116
ex(tmp, "min_args must be non-negative");
2120
if((tmp = find(as, "max_args")) != NULL) {
2121
max_args = strtol(tmp->u.value, &end, 0);
2123
ex(tmp, "max_args is not numeric");
2127
ex(tmp, "max_args must be non-negative");
2132
if(min_args != -1 || max_args != -1) {
2133
if(min_args == max_args) {
2134
cprint(1, "if(argc - optidx != %d) {\n",
2136
cprint(2, "fprintf(stderr, \"Need exactly %u parameters (%%u given).\\n\\n\", argc - optidx);\n", min_args);
2137
cprint(2, "goto usage;\n");
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");
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");
2156
cprint(1, "if(help_flag)\n");
2157
cprint(2, "goto usage;\n");
2159
cprint(1, "ret = %s(%s, argc - optidx, argv + optidx);\n",
2160
f, opt1 ? "&opt": "NULL");
2162
/* free allocated data */
2163
for(tmp = find(as, "option");
2165
tmp = find_next(tmp, "option")) {
2167
struct assignment *type = find(tmp->u.assignment, "type");
2168
struct type_handler *th;
2169
th = find_handler(type);
2170
if(th->free == NULL)
2172
s = make_name(tmp->u.assignment);
2176
cprint(1, "return ret;\n");
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");
2184
tmp = find_next(tmp, "option")) {
2186
struct assignment *type = find(tmp->u.assignment, "type");
2187
struct type_handler *th;
2188
th = find_handler(type);
2189
if(th->free == NULL)
2191
s = make_name(tmp->u.assignment);
2195
cprint(1, "return 0;\n");
2200
char cname[PATH_MAX];
2201
char hname[PATH_MAX];
2204
gen(struct assignment *as)
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);
2212
hprint(0, "#include <stdio.h>\n");
2213
hprint(0, "#include <sl.h>\n");
2217
for(a = as; a != NULL; a = a->next)
2218
gen_wrapper(a->u.assignment);
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");
2226
hprint(0, "extern SL_cmd commands[];\n");
2231
struct getargs args[] = {
2232
{ "version", 0, arg_flag, &version_flag },
2233
{ "help", 0, arg_flag, &help_flag }
2235
int num_args = sizeof(args) / sizeof(args[0]);
2240
arg_printusage(args, num_args, NULL, "command-table");
2245
main(int argc, char **argv)
2251
setprogname(argv[0]);
2252
if(getarg(args, num_args, argc, argv, &optidx))
2257
print_version(NULL);
2264
filename = argv[optidx];
2265
yyin = fopen(filename, "r");
2267
err(1, "%s", filename);
2268
p = strrchr(filename, '/');
2270
strlcpy(cname, p + 1, sizeof(cname));
2272
strlcpy(cname, filename, sizeof(cname));
2273
p = strrchr(cname, '.');
2276
strlcpy(hname, cname, sizeof(hname));
2277
strlcat(cname, ".c", sizeof(cname));
2278
strlcat(hname, ".h", sizeof(hname));
2282
if(check(assignment) == 0) {
2283
cfile = fopen(cname, "w");
2285
err(1, "%s", cname);
2286
hfile = fopen(hname, "w");
2288
err(1, "%s", hname);