| 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 |
|
|---|
| 817 | #if YYERROR_VERBOSE
|
|---|
| 818 |
|
|---|
| 819 | # ifndef yystrlen
|
|---|
| 820 | # if defined __GLIBC__ && defined _STRING_H
|
|---|
| 821 | # define yystrlen strlen
|
|---|
| 822 | # else
|
|---|
| 823 | /* Return the length of YYSTR. */
|
|---|
| 824 | #if (defined __STDC__ || defined __C99__FUNC__ \
|
|---|
| 825 | || defined __cplusplus || defined _MSC_VER)
|
|---|
| 826 | static YYSIZE_T
|
|---|
| 827 | yystrlen (const char *yystr)
|
|---|
| 828 | #else
|
|---|
| 829 | static YYSIZE_T
|
|---|
| 830 | yystrlen (yystr)
|
|---|
| 831 | const char *yystr;
|
|---|
| 832 | #endif
|
|---|
| 833 | {
|
|---|
| 834 | YYSIZE_T yylen;
|
|---|
| 835 | for (yylen = 0; yystr[yylen]; yylen++)
|
|---|
| 836 | continue;
|
|---|
| 837 | return yylen;
|
|---|
| 838 | }
|
|---|
| 839 | # endif
|
|---|
| 840 | # endif
|
|---|
| 841 |
|
|---|
| 842 | # ifndef yystpcpy
|
|---|
| 843 | # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
|
|---|
| 844 | # define yystpcpy stpcpy
|
|---|
| 845 | # else
|
|---|
| 846 | /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
|
|---|
| 847 | YYDEST. */
|
|---|
| 848 | #if (defined __STDC__ || defined __C99__FUNC__ \
|
|---|
| 849 | || defined __cplusplus || defined _MSC_VER)
|
|---|
| 850 | static char *
|
|---|
| 851 | yystpcpy (char *yydest, const char *yysrc)
|
|---|
| 852 | #else
|
|---|
| 853 | static char *
|
|---|
| 854 | yystpcpy (yydest, yysrc)
|
|---|
| 855 | char *yydest;
|
|---|
| 856 | const char *yysrc;
|
|---|
| 857 | #endif
|
|---|
| 858 | {
|
|---|
| 859 | char *yyd = yydest;
|
|---|
| 860 | const char *yys = yysrc;
|
|---|
| 861 |
|
|---|
| 862 | while ((*yyd++ = *yys++) != '\0')
|
|---|
| 863 | continue;
|
|---|
| 864 |
|
|---|
| 865 | return yyd - 1;
|
|---|
| 866 | }
|
|---|
| 867 | # endif
|
|---|
| 868 | # endif
|
|---|
| 869 |
|
|---|
| 870 | # ifndef yytnamerr
|
|---|
| 871 | /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
|
|---|
| 872 | quotes and backslashes, so that it's suitable for yyerror. The
|
|---|
| 873 | heuristic is that double-quoting is unnecessary unless the string
|
|---|
| 874 | contains an apostrophe, a comma, or backslash (other than
|
|---|
| 875 | backslash-backslash). YYSTR is taken from yytname. If YYRES is
|
|---|
| 876 | null, do not copy; instead, return the length of what the result
|
|---|
| 877 | would have been. */
|
|---|
| 878 | static YYSIZE_T
|
|---|
| 879 | yytnamerr (char *yyres, const char *yystr)
|
|---|
| 880 | {
|
|---|
| 881 | if (*yystr == '"')
|
|---|
| 882 | {
|
|---|
| 883 | YYSIZE_T yyn = 0;
|
|---|
| 884 | char const *yyp = yystr;
|
|---|
| 885 |
|
|---|
| 886 | for (;;)
|
|---|
| 887 | switch (*++yyp)
|
|---|
| 888 | {
|
|---|
| 889 | case '\'':
|
|---|
| 890 | case ',':
|
|---|
| 891 | goto do_not_strip_quotes;
|
|---|
| 892 |
|
|---|
| 893 | case '\\':
|
|---|
| 894 | if (*++yyp != '\\')
|
|---|
| 895 | goto do_not_strip_quotes;
|
|---|
| 896 | /* Fall through. */
|
|---|
| 897 | default:
|
|---|
| 898 | if (yyres)
|
|---|
| 899 | yyres[yyn] = *yyp;
|
|---|
| 900 | yyn++;
|
|---|
| 901 | break;
|
|---|
| 902 |
|
|---|
| 903 | case '"':
|
|---|
| 904 | if (yyres)
|
|---|
| 905 | yyres[yyn] = '\0';
|
|---|
| 906 | return yyn;
|
|---|
| 907 | }
|
|---|
| 908 | do_not_strip_quotes: ;
|
|---|
| 909 | }
|
|---|
| 910 |
|
|---|
| 911 | if (! yyres)
|
|---|
| 912 | return yystrlen (yystr);
|
|---|
| 913 |
|
|---|
| 914 | return yystpcpy (yyres, yystr) - yyres;
|
|---|
| 915 | }
|
|---|
| 916 | # endif
|
|---|
| 917 |
|
|---|
| 918 | /* Copy into YYRESULT an error message about the unexpected token
|
|---|
| 919 | YYCHAR while in state YYSTATE. Return the number of bytes copied,
|
|---|
| 920 | including the terminating null byte. If YYRESULT is null, do not
|
|---|
| 921 | copy anything; just return the number of bytes that would be
|
|---|
| 922 | copied. As a special case, return 0 if an ordinary "syntax error"
|
|---|
| 923 | message will do. Return YYSIZE_MAXIMUM if overflow occurs during
|
|---|
| 924 | size calculation. */
|
|---|
| 925 | static YYSIZE_T
|
|---|
| 926 | yysyntax_error (char *yyresult, int yystate, int yychar)
|
|---|
| 927 | {
|
|---|
| 928 | int yyn = yypact[yystate];
|
|---|
| 929 |
|
|---|
| 930 | if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
|
|---|
| 931 | return 0;
|
|---|
| 932 | else
|
|---|
| 933 | {
|
|---|
| 934 | int yytype = YYTRANSLATE (yychar);
|
|---|
| 935 | YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
|
|---|
| 936 | YYSIZE_T yysize = yysize0;
|
|---|
| 937 | YYSIZE_T yysize1;
|
|---|
| 938 | int yysize_overflow = 0;
|
|---|
| 939 | enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
|
|---|
| 940 | char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
|
|---|
| 941 | int yyx;
|
|---|
| 942 |
|
|---|
| 943 | # if 0
|
|---|
| 944 | /* This is so xgettext sees the translatable formats that are
|
|---|
| 945 | constructed on the fly. */
|
|---|
| 946 | YY_("syntax error, unexpected %s");
|
|---|
| 947 | YY_("syntax error, unexpected %s, expecting %s");
|
|---|
| 948 | YY_("syntax error, unexpected %s, expecting %s or %s");
|
|---|
| 949 | YY_("syntax error, unexpected %s, expecting %s or %s or %s");
|
|---|
| 950 | YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
|
|---|
| 951 | # endif
|
|---|
| 952 | char *yyfmt;
|
|---|
| 953 | char const *yyf;
|
|---|
| 954 | static char const yyunexpected[] = "syntax error, unexpected %s";
|
|---|
| 955 | static char const yyexpecting[] = ", expecting %s";
|
|---|
| 956 | static char const yyor[] = " or %s";
|
|---|
| 957 | char yyformat[sizeof yyunexpected
|
|---|
| 958 | + sizeof yyexpecting - 1
|
|---|
| 959 | + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
|
|---|
| 960 | * (sizeof yyor - 1))];
|
|---|
| 961 | char const *yyprefix = yyexpecting;
|
|---|
| 962 |
|
|---|
| 963 | /* Start YYX at -YYN if negative to avoid negative indexes in
|
|---|
| 964 | YYCHECK. */
|
|---|
| 965 | int yyxbegin = yyn < 0 ? -yyn : 0;
|
|---|
| 966 |
|
|---|
| 967 | /* Stay within bounds of both yycheck and yytname. */
|
|---|
| 968 | int yychecklim = YYLAST - yyn + 1;
|
|---|
| 969 | int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
|
|---|
| 970 | int yycount = 1;
|
|---|
| 971 |
|
|---|
| 972 | yyarg[0] = yytname[yytype];
|
|---|
| 973 | yyfmt = yystpcpy (yyformat, yyunexpected);
|
|---|
| 974 |
|
|---|
| 975 | for (yyx = yyxbegin; yyx < yyxend; ++yyx)
|
|---|
| 976 | if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
|
|---|
| 977 | {
|
|---|
| 978 | if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
|
|---|
| 979 | {
|
|---|
| 980 | yycount = 1;
|
|---|
| 981 | yysize = yysize0;
|
|---|
| 982 | yyformat[sizeof yyunexpected - 1] = '\0';
|
|---|
| 983 | break;
|
|---|
| 984 | }
|
|---|
| 985 | yyarg[yycount++] = yytname[yyx];
|
|---|
| 986 | yysize1 = yysize + yytnamerr (0, yytname[yyx]);
|
|---|
| 987 | yysize_overflow |= (yysize1 < yysize);
|
|---|
| 988 | yysize = yysize1;
|
|---|
| 989 | yyfmt = yystpcpy (yyfmt, yyprefix);
|
|---|
| 990 | yyprefix = yyor;
|
|---|
| 991 | }
|
|---|
| 992 |
|
|---|
| 993 | yyf = YY_(yyformat);
|
|---|
| 994 | yysize1 = yysize + yystrlen (yyf);
|
|---|
| 995 | yysize_overflow |= (yysize1 < yysize);
|
|---|
| 996 | yysize = yysize1;
|
|---|
| 997 |
|
|---|
| 998 | if (yysize_overflow)
|
|---|
| 999 | return YYSIZE_MAXIMUM;
|
|---|
| 1000 |
|
|---|
| 1001 | if (yyresult)
|
|---|
| 1002 | {
|
|---|
| 1003 | /* Avoid sprintf, as that infringes on the user's name space.
|
|---|
| 1004 | Don't have undefined behavior even if the translation
|
|---|
| 1005 | produced a string with the wrong number of "%s"s. */
|
|---|
| 1006 | char *yyp = yyresult;
|
|---|
| 1007 | int yyi = 0;
|
|---|
| 1008 | while ((*yyp = *yyf) != '\0')
|
|---|
| 1009 | {
|
|---|
| 1010 | if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
|
|---|
| 1011 | {
|
|---|
| 1012 | yyp += yytnamerr (yyp, yyarg[yyi++]);
|
|---|
| 1013 | yyf += 2;
|
|---|
| 1014 | }
|
|---|
| 1015 | else
|
|---|
| 1016 | {
|
|---|
| 1017 | yyp++;
|
|---|
| 1018 | yyf++;
|
|---|
| 1019 | }
|
|---|
| 1020 | }
|
|---|
| 1021 | }
|
|---|
| 1022 | return yysize;
|
|---|
| 1023 | }
|
|---|
| 1024 | }
|
|---|
| 1025 | #endif /* YYERROR_VERBOSE */
|
|---|
| 1026 | |
|---|
| 1027 |
|
|---|
| 1028 |
|
|---|
| 1029 | /*-----------------------------------------------.
|
|---|
| 1030 | | Release the memory associated to this symbol. |
|
|---|
| 1031 | `-----------------------------------------------*/
|
|---|
| 1032 |
|
|---|
| 1033 | /*ARGSUSED*/
|
|---|
| 1034 | #if (defined __STDC__ || defined __C99__FUNC__ \
|
|---|
| 1035 | || defined __cplusplus || defined _MSC_VER)
|
|---|
| 1036 | static void
|
|---|
| 1037 | yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
|
|---|
| 1038 | #else
|
|---|
| 1039 | static void
|
|---|
| 1040 | yydestruct (yymsg, yytype, yyvaluep)
|
|---|
| 1041 | const char *yymsg;
|
|---|
| 1042 | int yytype;
|
|---|
| 1043 | YYSTYPE *yyvaluep;
|
|---|
| 1044 | #endif
|
|---|
| 1045 | {
|
|---|
| 1046 | YYUSE (yyvaluep);
|
|---|
| 1047 |
|
|---|
| 1048 | if (!yymsg)
|
|---|
| 1049 | yymsg = "Deleting";
|
|---|
| 1050 | YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
|
|---|
| 1051 |
|
|---|
| 1052 | switch (yytype)
|
|---|
| 1053 | {
|
|---|
| 1054 |
|
|---|
| 1055 | default:
|
|---|
| 1056 | break;
|
|---|
| 1057 | }
|
|---|
| 1058 | }
|
|---|
| 1059 | |
|---|
| 1060 |
|
|---|
| 1061 |
|
|---|
| 1062 | /* Prevent warnings from -Wmissing-prototypes. */
|
|---|
| 1063 |
|
|---|
| 1064 | #ifdef YYPARSE_PARAM
|
|---|
| 1065 | #if defined __STDC__ || defined __cplusplus
|
|---|
| 1066 | int yyparse (void *YYPARSE_PARAM);
|
|---|
| 1067 | #else
|
|---|
| 1068 | int yyparse ();
|
|---|
| 1069 | #endif
|
|---|
| 1070 | #else /* ! YYPARSE_PARAM */
|
|---|
| 1071 | #if defined __STDC__ || defined __cplusplus
|
|---|
| 1072 | int yyparse (void);
|
|---|
| 1073 | #else
|
|---|
| 1074 | int yyparse ();
|
|---|
| 1075 | #endif
|
|---|
| 1076 | #endif /* ! YYPARSE_PARAM */
|
|---|
| 1077 |
|
|---|
| 1078 |
|
|---|
| 1079 |
|
|---|
| 1080 | /* The look-ahead symbol. */
|
|---|
| 1081 | int yychar;
|
|---|
| 1082 |
|
|---|
| 1083 | /* The semantic value of the look-ahead symbol. */
|
|---|
| 1084 | YYSTYPE yylval;
|
|---|
| 1085 |
|
|---|
| 1086 | /* Number of syntax errors so far. */
|
|---|
| 1087 | int yynerrs;
|
|---|
| 1088 |
|
|---|
| 1089 |
|
|---|
| 1090 |
|
|---|
| 1091 | /*----------.
|
|---|
| 1092 | | yyparse. |
|
|---|
| 1093 | `----------*/
|
|---|
| 1094 |
|
|---|
| 1095 | #ifdef YYPARSE_PARAM
|
|---|
| 1096 | #if (defined __STDC__ || defined __C99__FUNC__ \
|
|---|
| 1097 | || defined __cplusplus || defined _MSC_VER)
|
|---|
| 1098 | int
|
|---|
| 1099 | yyparse (void *YYPARSE_PARAM)
|
|---|
| 1100 | #else
|
|---|
| 1101 | int
|
|---|
| 1102 | yyparse (YYPARSE_PARAM)
|
|---|
| 1103 | void *YYPARSE_PARAM;
|
|---|
| 1104 | #endif
|
|---|
| 1105 | #else /* ! YYPARSE_PARAM */
|
|---|
| 1106 | #if (defined __STDC__ || defined __C99__FUNC__ \
|
|---|
| 1107 | || defined __cplusplus || defined _MSC_VER)
|
|---|
| 1108 | int
|
|---|
| 1109 | yyparse (void)
|
|---|
| 1110 | #else
|
|---|
| 1111 | int
|
|---|
| 1112 | yyparse ()
|
|---|
| 1113 |
|
|---|
| 1114 | #endif
|
|---|
| 1115 | #endif
|
|---|
| 1116 | {
|
|---|
| 1117 |
|
|---|
| 1118 | int yystate;
|
|---|
| 1119 | int yyn;
|
|---|
| 1120 | int yyresult;
|
|---|
| 1121 | /* Number of tokens to shift before error messages enabled. */
|
|---|
| 1122 | int yyerrstatus;
|
|---|
| 1123 | /* Look-ahead token as an internal (translated) token number. */
|
|---|
| 1124 | int yytoken = 0;
|
|---|
| 1125 | #if YYERROR_VERBOSE
|
|---|
| 1126 | /* Buffer for error messages, and its allocated size. */
|
|---|
| 1127 | char yymsgbuf[128];
|
|---|
| 1128 | char *yymsg = yymsgbuf;
|
|---|
| 1129 | YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
|
|---|
| 1130 | #endif
|
|---|
| 1131 |
|
|---|
| 1132 | /* Three stacks and their tools:
|
|---|
| 1133 | `yyss': related to states,
|
|---|
| 1134 | `yyvs': related to semantic values,
|
|---|
| 1135 | `yyls': related to locations.
|
|---|
| 1136 |
|
|---|
| 1137 | Refer to the stacks thru separate pointers, to allow yyoverflow
|
|---|
| 1138 | to reallocate them elsewhere. */
|
|---|
| 1139 |
|
|---|
| 1140 | /* The state stack. */
|
|---|
| 1141 | yytype_int16 yyssa[YYINITDEPTH];
|
|---|
| 1142 | yytype_int16 *yyss = yyssa;
|
|---|
| 1143 | yytype_int16 *yyssp;
|
|---|
| 1144 |
|
|---|
| 1145 | /* The semantic value stack. */
|
|---|
| 1146 | YYSTYPE yyvsa[YYINITDEPTH];
|
|---|
| 1147 | YYSTYPE *yyvs = yyvsa;
|
|---|
| 1148 | YYSTYPE *yyvsp;
|
|---|
| 1149 |
|
|---|
| 1150 |
|
|---|
| 1151 |
|
|---|
| 1152 | #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
|
|---|
| 1153 |
|
|---|
| 1154 | YYSIZE_T yystacksize = YYINITDEPTH;
|
|---|
| 1155 |
|
|---|
| 1156 | /* The variables used to return semantic value and location from the
|
|---|
| 1157 | action routines. */
|
|---|
| 1158 | YYSTYPE yyval;
|
|---|
| 1159 |
|
|---|
| 1160 |
|
|---|
| 1161 | /* The number of symbols on the RHS of the reduced rule.
|
|---|
| 1162 | Keep to zero when no symbol should be popped. */
|
|---|
| 1163 | int yylen = 0;
|
|---|
| 1164 |
|
|---|
| 1165 | YYDPRINTF ((stderr, "Starting parse\n"));
|
|---|
| 1166 |
|
|---|
| 1167 | yystate = 0;
|
|---|
| 1168 | yyerrstatus = 0;
|
|---|
| 1169 | yynerrs = 0;
|
|---|
| 1170 | yychar = YYEMPTY; /* Cause a token to be read. */
|
|---|
| 1171 |
|
|---|
| 1172 | /* Initialize stack pointers.
|
|---|
| 1173 | Waste one element of value and location stack
|
|---|
| 1174 | so that they stay on the same level as the state stack.
|
|---|
| 1175 | The wasted elements are never initialized. */
|
|---|
| 1176 |
|
|---|
| 1177 | yyssp = yyss;
|
|---|
| 1178 | yyvsp = yyvs;
|
|---|
| 1179 |
|
|---|
| 1180 | goto yysetstate;
|
|---|
| 1181 |
|
|---|
| 1182 | /*------------------------------------------------------------.
|
|---|
| 1183 | | yynewstate -- Push a new state, which is found in yystate. |
|
|---|
| 1184 | `------------------------------------------------------------*/
|
|---|
| 1185 | yynewstate:
|
|---|
| 1186 | /* In all cases, when you get here, the value and location stacks
|
|---|
| 1187 | have just been pushed. So pushing a state here evens the stacks. */
|
|---|
| 1188 | yyssp++;
|
|---|
| 1189 |
|
|---|
| 1190 | yysetstate:
|
|---|
| 1191 | *yyssp = yystate;
|
|---|
| 1192 |
|
|---|
| 1193 | if (yyss + yystacksize - 1 <= yyssp)
|
|---|
| 1194 | {
|
|---|
| 1195 | /* Get the current used size of the three stacks, in elements. */
|
|---|
| 1196 | YYSIZE_T yysize = yyssp - yyss + 1;
|
|---|
| 1197 |
|
|---|
| 1198 | #ifdef yyoverflow
|
|---|
| 1199 | {
|
|---|
| 1200 | /* Give user a chance to reallocate the stack. Use copies of
|
|---|
| 1201 | these so that the &'s don't force the real ones into
|
|---|
| 1202 | memory. */
|
|---|
| 1203 | YYSTYPE *yyvs1 = yyvs;
|
|---|
| 1204 | yytype_int16 *yyss1 = yyss;
|
|---|
| 1205 |
|
|---|
| 1206 |
|
|---|
| 1207 | /* Each stack pointer address is followed by the size of the
|
|---|
| 1208 | data in use in that stack, in bytes. This used to be a
|
|---|
| 1209 | conditional around just the two extra args, but that might
|
|---|
| 1210 | be undefined if yyoverflow is a macro. */
|
|---|
| 1211 | yyoverflow (YY_("memory exhausted"),
|
|---|
| 1212 | &yyss1, yysize * sizeof (*yyssp),
|
|---|
| 1213 | &yyvs1, yysize * sizeof (*yyvsp),
|
|---|
| 1214 |
|
|---|
| 1215 | &yystacksize);
|
|---|
| 1216 |
|
|---|
| 1217 | yyss = yyss1;
|
|---|
| 1218 | yyvs = yyvs1;
|
|---|
| 1219 | }
|
|---|
| 1220 | #else /* no yyoverflow */
|
|---|
| 1221 | # ifndef YYSTACK_RELOCATE
|
|---|
| 1222 | goto yyexhaustedlab;
|
|---|
| 1223 | # else
|
|---|
| 1224 | /* Extend the stack our own way. */
|
|---|
| 1225 | if (YYMAXDEPTH <= yystacksize)
|
|---|
| 1226 | goto yyexhaustedlab;
|
|---|
| 1227 | yystacksize *= 2;
|
|---|
| 1228 | if (YYMAXDEPTH < yystacksize)
|
|---|
| 1229 | yystacksize = YYMAXDEPTH;
|
|---|
| 1230 |
|
|---|
| 1231 | {
|
|---|
| 1232 | yytype_int16 *yyss1 = yyss;
|
|---|
| 1233 | union yyalloc *yyptr =
|
|---|
| 1234 | (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
|
|---|
| 1235 | if (! yyptr)
|
|---|
| 1236 | goto yyexhaustedlab;
|
|---|
| 1237 | YYSTACK_RELOCATE (yyss);
|
|---|
| 1238 | YYSTACK_RELOCATE (yyvs);
|
|---|
| 1239 |
|
|---|
| 1240 | # undef YYSTACK_RELOCATE
|
|---|
| 1241 | if (yyss1 != yyssa)
|
|---|
| 1242 | YYSTACK_FREE (yyss1);
|
|---|
| 1243 | }
|
|---|
| 1244 | # endif
|
|---|
| 1245 | #endif /* no yyoverflow */
|
|---|
| 1246 |
|
|---|
| 1247 | yyssp = yyss + yysize - 1;
|
|---|
| 1248 | yyvsp = yyvs + yysize - 1;
|
|---|
| 1249 |
|
|---|
| 1250 |
|
|---|
| 1251 | YYDPRINTF ((stderr, "Stack size increased to %lu\n",
|
|---|
| 1252 | (unsigned long int) yystacksize));
|
|---|
| 1253 |
|
|---|
| 1254 | if (yyss + yystacksize - 1 <= yyssp)
|
|---|
| 1255 | YYABORT;
|
|---|
| 1256 | }
|
|---|
| 1257 |
|
|---|
| 1258 | YYDPRINTF ((stderr, "Entering state %d\n", yystate));
|
|---|
| 1259 |
|
|---|
| 1260 | goto yybackup;
|
|---|
| 1261 |
|
|---|
| 1262 | /*-----------.
|
|---|
| 1263 | | yybackup. |
|
|---|
| 1264 | `-----------*/
|
|---|
| 1265 | yybackup:
|
|---|
| 1266 |
|
|---|
| 1267 | /* Do appropriate processing given the current state. Read a
|
|---|
| 1268 | look-ahead token if we need one and don't already have one. */
|
|---|
| 1269 |
|
|---|
| 1270 | /* First try to decide what to do without reference to look-ahead token. */
|
|---|
| 1271 | yyn = yypact[yystate];
|
|---|
| 1272 | if (yyn == YYPACT_NINF)
|
|---|
| 1273 | goto yydefault;
|
|---|
| 1274 |
|
|---|
| 1275 | /* Not known => get a look-ahead token if don't already have one. */
|
|---|
| 1276 |
|
|---|
| 1277 | /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
|
|---|
| 1278 | if (yychar == YYEMPTY)
|
|---|
| 1279 | {
|
|---|
| 1280 | YYDPRINTF ((stderr, "Reading a token: "));
|
|---|
| 1281 | yychar = YYLEX;
|
|---|
| 1282 | }
|
|---|
| 1283 |
|
|---|
| 1284 | if (yychar <= YYEOF)
|
|---|
| 1285 | {
|
|---|
| 1286 | yychar = yytoken = YYEOF;
|
|---|
| 1287 | YYDPRINTF ((stderr, "Now at end of input.\n"));
|
|---|
| 1288 | }
|
|---|
| 1289 | else
|
|---|
| 1290 | {
|
|---|
| 1291 | yytoken = YYTRANSLATE (yychar);
|
|---|
| 1292 | YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
|
|---|
| 1293 | }
|
|---|
| 1294 |
|
|---|
| 1295 | /* If the proper action on seeing token YYTOKEN is to reduce or to
|
|---|
| 1296 | detect an error, take that action. */
|
|---|
| 1297 | yyn += yytoken;
|
|---|
| 1298 | if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
|
|---|
| 1299 | goto yydefault;
|
|---|
| 1300 | yyn = yytable[yyn];
|
|---|
| 1301 | if (yyn <= 0)
|
|---|
| 1302 | {
|
|---|
| 1303 | if (yyn == 0 || yyn == YYTABLE_NINF)
|
|---|
| 1304 | goto yyerrlab;
|
|---|
| 1305 | yyn = -yyn;
|
|---|
| 1306 | goto yyreduce;
|
|---|
| 1307 | }
|
|---|
| 1308 |
|
|---|
| 1309 | if (yyn == YYFINAL)
|
|---|
| 1310 | YYACCEPT;
|
|---|
| 1311 |
|
|---|
| 1312 | /* Count tokens shifted since error; after three, turn off error
|
|---|
| 1313 | status. */
|
|---|
| 1314 | if (yyerrstatus)
|
|---|
| 1315 | yyerrstatus--;
|
|---|
| 1316 |
|
|---|
| 1317 | /* Shift the look-ahead token. */
|
|---|
| 1318 | YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
|
|---|
| 1319 |
|
|---|
| 1320 | /* Discard the shifted token unless it is eof. */
|
|---|
| 1321 | if (yychar != YYEOF)
|
|---|
| 1322 | yychar = YYEMPTY;
|
|---|
| 1323 |
|
|---|
| 1324 | yystate = yyn;
|
|---|
| 1325 | *++yyvsp = yylval;
|
|---|
| 1326 |
|
|---|
| 1327 | goto yynewstate;
|
|---|
| 1328 |
|
|---|
| 1329 |
|
|---|
| 1330 | /*-----------------------------------------------------------.
|
|---|
| 1331 | | yydefault -- do the default action for the current state. |
|
|---|
| 1332 | `-----------------------------------------------------------*/
|
|---|
| 1333 | yydefault:
|
|---|
| 1334 | yyn = yydefact[yystate];
|
|---|
| 1335 | if (yyn == 0)
|
|---|
| 1336 | goto yyerrlab;
|
|---|
| 1337 | goto yyreduce;
|
|---|
| 1338 |
|
|---|
| 1339 |
|
|---|
| 1340 | /*-----------------------------.
|
|---|
| 1341 | | yyreduce -- Do a reduction. |
|
|---|
| 1342 | `-----------------------------*/
|
|---|
| 1343 | yyreduce:
|
|---|
| 1344 | /* yyn is the number of a rule to reduce with. */
|
|---|
| 1345 | yylen = yyr2[yyn];
|
|---|
| 1346 |
|
|---|
| 1347 | /* If YYLEN is nonzero, implement the default value of the action:
|
|---|
| 1348 | `$$ = $1'.
|
|---|
| 1349 |
|
|---|
| 1350 | Otherwise, the following line sets YYVAL to garbage.
|
|---|
| 1351 | This behavior is undocumented and Bison
|
|---|
| 1352 | users should not rely upon it. Assigning to YYVAL
|
|---|
| 1353 | unconditionally makes the parser a bit smaller, and it avoids a
|
|---|
| 1354 | GCC warning that YYVAL may be used uninitialized. */
|
|---|
| 1355 | yyval = yyvsp[1-yylen];
|
|---|
| 1356 |
|
|---|
| 1357 |
|
|---|
| 1358 | YY_REDUCE_PRINT (yyn);
|
|---|
| 1359 | switch (yyn)
|
|---|
| 1360 | {
|
|---|
| 1361 | case 2:
|
|---|
| 1362 | #line 71 "slc-gram.y"
|
|---|
| 1363 | {
|
|---|
| 1364 | assignment = (yyvsp[(1) - (1)].assignment);
|
|---|
| 1365 | }
|
|---|
| 1366 | break;
|
|---|
| 1367 |
|
|---|
| 1368 | case 3:
|
|---|
| 1369 | #line 77 "slc-gram.y"
|
|---|
| 1370 | {
|
|---|
| 1371 | (yyvsp[(1) - (2)].assignment)->next = (yyvsp[(2) - (2)].assignment);
|
|---|
| 1372 | (yyval.assignment) = (yyvsp[(1) - (2)].assignment);
|
|---|
| 1373 | }
|
|---|
| 1374 | break;
|
|---|
| 1375 |
|
|---|
| 1376 | case 5:
|
|---|
| 1377 | #line 85 "slc-gram.y"
|
|---|
| 1378 | {
|
|---|
| 1379 | (yyval.assignment) = malloc(sizeof(*(yyval.assignment)));
|
|---|
| 1380 | (yyval.assignment)->name = (yyvsp[(1) - (3)].string);
|
|---|
| 1381 | (yyval.assignment)->type = a_value;
|
|---|
| 1382 | (yyval.assignment)->lineno = lineno;
|
|---|
| 1383 | (yyval.assignment)->u.value = (yyvsp[(3) - (3)].string);
|
|---|
| 1384 | (yyval.assignment)->next = NULL;
|
|---|
| 1385 | }
|
|---|
| 1386 | break;
|
|---|
| 1387 |
|
|---|
| 1388 | case 6:
|
|---|
| 1389 | #line 94 "slc-gram.y"
|
|---|
| 1390 | {
|
|---|
| 1391 | (yyval.assignment) = malloc(sizeof(*(yyval.assignment)));
|
|---|
| 1392 | (yyval.assignment)->name = (yyvsp[(1) - (5)].string);
|
|---|
| 1393 | (yyval.assignment)->type = a_assignment;
|
|---|
| 1394 | (yyval.assignment)->lineno = lineno;
|
|---|
| 1395 | (yyval.assignment)->u.assignment = (yyvsp[(4) - (5)].assignment);
|
|---|
| 1396 | (yyval.assignment)->next = NULL;
|
|---|
| 1397 | }
|
|---|
| 1398 | break;
|
|---|
| 1399 |
|
|---|
| 1400 |
|
|---|
| 1401 | /* Line 1267 of yacc.c. */
|
|---|
| 1402 | #line 1400 "slc-gram.c"
|
|---|
| 1403 | default: break;
|
|---|
| 1404 | }
|
|---|
| 1405 | YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
|
|---|
| 1406 |
|
|---|
| 1407 | YYPOPSTACK (yylen);
|
|---|
| 1408 | yylen = 0;
|
|---|
| 1409 | YY_STACK_PRINT (yyss, yyssp);
|
|---|
| 1410 |
|
|---|
| 1411 | *++yyvsp = yyval;
|
|---|
| 1412 |
|
|---|
| 1413 |
|
|---|
| 1414 | /* Now `shift' the result of the reduction. Determine what state
|
|---|
| 1415 | that goes to, based on the state we popped back to and the rule
|
|---|
| 1416 | number reduced by. */
|
|---|
| 1417 |
|
|---|
| 1418 | yyn = yyr1[yyn];
|
|---|
| 1419 |
|
|---|
| 1420 | yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
|
|---|
| 1421 | if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
|
|---|
| 1422 | yystate = yytable[yystate];
|
|---|
| 1423 | else
|
|---|
| 1424 | yystate = yydefgoto[yyn - YYNTOKENS];
|
|---|
| 1425 |
|
|---|
| 1426 | goto yynewstate;
|
|---|
| 1427 |
|
|---|
| 1428 |
|
|---|
| 1429 | /*------------------------------------.
|
|---|
| 1430 | | yyerrlab -- here on detecting error |
|
|---|
| 1431 | `------------------------------------*/
|
|---|
| 1432 | yyerrlab:
|
|---|
| 1433 | /* If not already recovering from an error, report this error. */
|
|---|
| 1434 | if (!yyerrstatus)
|
|---|
| 1435 | {
|
|---|
| 1436 | ++yynerrs;
|
|---|
| 1437 | #if ! YYERROR_VERBOSE
|
|---|
| 1438 | yyerror (YY_("syntax error"));
|
|---|
| 1439 | #else
|
|---|
| 1440 | {
|
|---|
| 1441 | YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
|
|---|
| 1442 | if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
|
|---|
| 1443 | {
|
|---|
| 1444 | YYSIZE_T yyalloc = 2 * yysize;
|
|---|
| 1445 | if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
|
|---|
| 1446 | yyalloc = YYSTACK_ALLOC_MAXIMUM;
|
|---|
| 1447 | if (yymsg != yymsgbuf)
|
|---|
| 1448 | YYSTACK_FREE (yymsg);
|
|---|
| 1449 | yymsg = (char *) YYSTACK_ALLOC (yyalloc);
|
|---|
| 1450 | if (yymsg)
|
|---|
| 1451 | yymsg_alloc = yyalloc;
|
|---|
| 1452 | else
|
|---|
| 1453 | {
|
|---|
| 1454 | yymsg = yymsgbuf;
|
|---|
| 1455 | yymsg_alloc = sizeof yymsgbuf;
|
|---|
| 1456 | }
|
|---|
| 1457 | }
|
|---|
| 1458 |
|
|---|
| 1459 | if (0 < yysize && yysize <= yymsg_alloc)
|
|---|
| 1460 | {
|
|---|
| 1461 | (void) yysyntax_error (yymsg, yystate, yychar);
|
|---|
| 1462 | yyerror (yymsg);
|
|---|
| 1463 | }
|
|---|
| 1464 | else
|
|---|
| 1465 | {
|
|---|
| 1466 | yyerror (YY_("syntax error"));
|
|---|
| 1467 | if (yysize != 0)
|
|---|
| 1468 | goto yyexhaustedlab;
|
|---|
| 1469 | }
|
|---|
| 1470 | }
|
|---|
| 1471 | #endif
|
|---|
| 1472 | }
|
|---|
| 1473 |
|
|---|
| 1474 |
|
|---|
| 1475 |
|
|---|
| 1476 | if (yyerrstatus == 3)
|
|---|
| 1477 | {
|
|---|
| 1478 | /* If just tried and failed to reuse look-ahead token after an
|
|---|
| 1479 | error, discard it. */
|
|---|
| 1480 |
|
|---|
| 1481 | if (yychar <= YYEOF)
|
|---|
| 1482 | {
|
|---|
| 1483 | /* Return failure if at end of input. */
|
|---|
| 1484 | if (yychar == YYEOF)
|
|---|
| 1485 | YYABORT;
|
|---|
| 1486 | }
|
|---|
| 1487 | else
|
|---|
| 1488 | {
|
|---|
| 1489 | yydestruct ("Error: discarding",
|
|---|
| 1490 | yytoken, &yylval);
|
|---|
| 1491 | yychar = YYEMPTY;
|
|---|
| 1492 | }
|
|---|
| 1493 | }
|
|---|
| 1494 |
|
|---|
| 1495 | /* Else will try to reuse look-ahead token after shifting the error
|
|---|
| 1496 | token. */
|
|---|
| 1497 | goto yyerrlab1;
|
|---|
| 1498 |
|
|---|
| 1499 |
|
|---|
| 1500 | /*---------------------------------------------------.
|
|---|
| 1501 | | yyerrorlab -- error raised explicitly by YYERROR. |
|
|---|
| 1502 | `---------------------------------------------------*/
|
|---|
| 1503 | yyerrorlab:
|
|---|
| 1504 |
|
|---|
| 1505 | /* Pacify compilers like GCC when the user code never invokes
|
|---|
| 1506 | YYERROR and the label yyerrorlab therefore never appears in user
|
|---|
| 1507 | code. */
|
|---|
| 1508 | if (/*CONSTCOND*/ 0)
|
|---|
| 1509 | goto yyerrorlab;
|
|---|
| 1510 |
|
|---|
| 1511 | /* Do not reclaim the symbols of the rule which action triggered
|
|---|
| 1512 | this YYERROR. */
|
|---|
| 1513 | YYPOPSTACK (yylen);
|
|---|
| 1514 | yylen = 0;
|
|---|
| 1515 | YY_STACK_PRINT (yyss, yyssp);
|
|---|
| 1516 | yystate = *yyssp;
|
|---|
| 1517 | goto yyerrlab1;
|
|---|
| 1518 |
|
|---|
| 1519 |
|
|---|
| 1520 | /*-------------------------------------------------------------.
|
|---|
| 1521 | | yyerrlab1 -- common code for both syntax error and YYERROR. |
|
|---|
| 1522 | `-------------------------------------------------------------*/
|
|---|
| 1523 | yyerrlab1:
|
|---|
| 1524 | yyerrstatus = 3; /* Each real token shifted decrements this. */
|
|---|
| 1525 |
|
|---|
| 1526 | for (;;)
|
|---|
| 1527 | {
|
|---|
| 1528 | yyn = yypact[yystate];
|
|---|
| 1529 | if (yyn != YYPACT_NINF)
|
|---|
| 1530 | {
|
|---|
| 1531 | yyn += YYTERROR;
|
|---|
| 1532 | if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
|
|---|
| 1533 | {
|
|---|
| 1534 | yyn = yytable[yyn];
|
|---|
| 1535 | if (0 < yyn)
|
|---|
| 1536 | break;
|
|---|
| 1537 | }
|
|---|
| 1538 | }
|
|---|
| 1539 |
|
|---|
| 1540 | /* Pop the current state because it cannot handle the error token. */
|
|---|
| 1541 | if (yyssp == yyss)
|
|---|
| 1542 | YYABORT;
|
|---|
| 1543 |
|
|---|
| 1544 |
|
|---|
| 1545 | yydestruct ("Error: popping",
|
|---|
| 1546 | yystos[yystate], yyvsp);
|
|---|
| 1547 | YYPOPSTACK (1);
|
|---|
| 1548 | yystate = *yyssp;
|
|---|
| 1549 | YY_STACK_PRINT (yyss, yyssp);
|
|---|
| 1550 | }
|
|---|
| 1551 |
|
|---|
| 1552 | if (yyn == YYFINAL)
|
|---|
| 1553 | YYACCEPT;
|
|---|
| 1554 |
|
|---|
| 1555 | *++yyvsp = yylval;
|
|---|
| 1556 |
|
|---|
| 1557 |
|
|---|
| 1558 | /* Shift the error token. */
|
|---|
| 1559 | YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
|
|---|
| 1560 |
|
|---|
| 1561 | yystate = yyn;
|
|---|
| 1562 | goto yynewstate;
|
|---|
| 1563 |
|
|---|
| 1564 |
|
|---|
| 1565 | /*-------------------------------------.
|
|---|
| 1566 | | yyacceptlab -- YYACCEPT comes here. |
|
|---|
| 1567 | `-------------------------------------*/
|
|---|
| 1568 | yyacceptlab:
|
|---|
| 1569 | yyresult = 0;
|
|---|
| 1570 | goto yyreturn;
|
|---|
| 1571 |
|
|---|
| 1572 | /*-----------------------------------.
|
|---|
| 1573 | | yyabortlab -- YYABORT comes here. |
|
|---|
| 1574 | `-----------------------------------*/
|
|---|
| 1575 | yyabortlab:
|
|---|
| 1576 | yyresult = 1;
|
|---|
| 1577 | goto yyreturn;
|
|---|
| 1578 |
|
|---|
| 1579 | #ifndef yyoverflow
|
|---|
| 1580 | /*-------------------------------------------------.
|
|---|
| 1581 | | yyexhaustedlab -- memory exhaustion comes here. |
|
|---|
| 1582 | `-------------------------------------------------*/
|
|---|
| 1583 | yyexhaustedlab:
|
|---|
| 1584 | yyerror (YY_("memory exhausted"));
|
|---|
| 1585 | yyresult = 2;
|
|---|
| 1586 | /* Fall through. */
|
|---|
| 1587 | #endif
|
|---|
| 1588 |
|
|---|
| 1589 | yyreturn:
|
|---|
| 1590 | if (yychar != YYEOF && yychar != YYEMPTY)
|
|---|
| 1591 | yydestruct ("Cleanup: discarding lookahead",
|
|---|
| 1592 | yytoken, &yylval);
|
|---|
| 1593 | /* Do not reclaim the symbols of the rule which action triggered
|
|---|
| 1594 | this YYABORT or YYACCEPT. */
|
|---|
| 1595 | YYPOPSTACK (yylen);
|
|---|
| 1596 | YY_STACK_PRINT (yyss, yyssp);
|
|---|
| 1597 | while (yyssp != yyss)
|
|---|
| 1598 | {
|
|---|
| 1599 | yydestruct ("Cleanup: popping",
|
|---|
| 1600 | yystos[*yyssp], yyvsp);
|
|---|
| 1601 | YYPOPSTACK (1);
|
|---|
| 1602 | }
|
|---|
| 1603 | #ifndef yyoverflow
|
|---|
| 1604 | if (yyss != yyssa)
|
|---|
| 1605 | YYSTACK_FREE (yyss);
|
|---|
| 1606 | #endif
|
|---|
| 1607 | #if YYERROR_VERBOSE
|
|---|
| 1608 | if (yymsg != yymsgbuf)
|
|---|
| 1609 | YYSTACK_FREE (yymsg);
|
|---|
| 1610 | #endif
|
|---|
| 1611 | /* Make sure YYID is used. */
|
|---|
| 1612 | return YYID (yyresult);
|
|---|
| 1613 | }
|
|---|
| 1614 |
|
|---|
| 1615 |
|
|---|
| 1616 | #line 104 "slc-gram.y"
|
|---|
| 1617 |
|
|---|
| 1618 | char *filename;
|
|---|
| 1619 | FILE *cfile, *hfile;
|
|---|
| 1620 | int error_flag;
|
|---|
| 1621 | struct assignment *assignment;
|
|---|
| 1622 |
|
|---|
| 1623 |
|
|---|
| 1624 | static void
|
|---|
| 1625 | ex(struct assignment *a, const char *fmt, ...)
|
|---|
| 1626 | {
|
|---|
| 1627 | va_list ap;
|
|---|
| 1628 | fprintf(stderr, "%s:%d: ", a->name, a->lineno);
|
|---|
| 1629 | va_start(ap, fmt);
|
|---|
| 1630 | vfprintf(stderr, fmt, ap);
|
|---|
| 1631 | va_end(ap);
|
|---|
| 1632 | fprintf(stderr, "\n");
|
|---|
| 1633 | }
|
|---|
| 1634 |
|
|---|
| 1635 |
|
|---|
| 1636 |
|
|---|
| 1637 | static int
|
|---|
| 1638 | check_option(struct assignment *as)
|
|---|
| 1639 | {
|
|---|
| 1640 | struct assignment *a;
|
|---|
| 1641 | int seen_long = 0;
|
|---|
| 1642 | int seen_name = 0;
|
|---|
| 1643 | int seen_short = 0;
|
|---|
| 1644 | int seen_type = 0;
|
|---|
| 1645 | int seen_argument = 0;
|
|---|
| 1646 | int seen_help = 0;
|
|---|
| 1647 | int seen_default = 0;
|
|---|
| 1648 | int ret = 0;
|
|---|
| 1649 |
|
|---|
| 1650 | for(a = as; a != NULL; a = a->next) {
|
|---|
| 1651 | if(strcmp(a->name, "long") == 0)
|
|---|
| 1652 | seen_long++;
|
|---|
| 1653 | else if(strcmp(a->name, "short") == 0)
|
|---|
| 1654 | seen_short++;
|
|---|
| 1655 | else if(strcmp(a->name, "name") == 0)
|
|---|
| 1656 | seen_name++;
|
|---|
| 1657 | else if(strcmp(a->name, "type") == 0)
|
|---|
| 1658 | seen_type++;
|
|---|
| 1659 | else if(strcmp(a->name, "argument") == 0)
|
|---|
| 1660 | seen_argument++;
|
|---|
| 1661 | else if(strcmp(a->name, "help") == 0)
|
|---|
| 1662 | seen_help++;
|
|---|
| 1663 | else if(strcmp(a->name, "default") == 0)
|
|---|
| 1664 | seen_default++;
|
|---|
| 1665 | else {
|
|---|
| 1666 | ex(a, "unknown name %s", a->name);
|
|---|
| 1667 | ret++;
|
|---|
| 1668 | }
|
|---|
| 1669 | }
|
|---|
| 1670 | if(seen_long == 0 && seen_short == 0) {
|
|---|
| 1671 | ex(as, "neither long nor short option");
|
|---|
| 1672 | ret++;
|
|---|
| 1673 | }
|
|---|
| 1674 | if (seen_long == 0 && seen_name == 0) {
|
|---|
| 1675 | ex(as, "either of long or name option must be used");
|
|---|
| 1676 | ret++;
|
|---|
| 1677 | }
|
|---|
| 1678 | if(seen_long > 1) {
|
|---|
| 1679 | ex(as, "multiple long options");
|
|---|
| 1680 | ret++;
|
|---|
| 1681 | }
|
|---|
| 1682 | if(seen_short > 1) {
|
|---|
| 1683 | ex(as, "multiple short options");
|
|---|
| 1684 | ret++;
|
|---|
| 1685 | }
|
|---|
| 1686 | if(seen_type > 1) {
|
|---|
| 1687 | ex(as, "multiple types");
|
|---|
| 1688 | ret++;
|
|---|
| 1689 | }
|
|---|
| 1690 | if(seen_argument > 1) {
|
|---|
| 1691 | ex(as, "multiple arguments");
|
|---|
| 1692 | ret++;
|
|---|
| 1693 | }
|
|---|
| 1694 | if(seen_help > 1) {
|
|---|
| 1695 | ex(as, "multiple help strings");
|
|---|
| 1696 | ret++;
|
|---|
| 1697 | }
|
|---|
| 1698 | if(seen_default > 1) {
|
|---|
| 1699 | ex(as, "multiple default values");
|
|---|
| 1700 | ret++;
|
|---|
| 1701 | }
|
|---|
| 1702 | return ret;
|
|---|
| 1703 | }
|
|---|
| 1704 |
|
|---|
| 1705 | static int
|
|---|
| 1706 | check_command(struct assignment *as)
|
|---|
| 1707 | {
|
|---|
| 1708 | struct assignment *a;
|
|---|
| 1709 | int seen_name = 0;
|
|---|
| 1710 | int seen_function = 0;
|
|---|
| 1711 | int seen_help = 0;
|
|---|
| 1712 | int seen_argument = 0;
|
|---|
| 1713 | int seen_minargs = 0;
|
|---|
| 1714 | int seen_maxargs = 0;
|
|---|
| 1715 | int ret = 0;
|
|---|
| 1716 | for(a = as; a != NULL; a = a->next) {
|
|---|
| 1717 | if(strcmp(a->name, "name") == 0)
|
|---|
| 1718 | seen_name++;
|
|---|
| 1719 | else if(strcmp(a->name, "function") == 0) {
|
|---|
| 1720 | seen_function++;
|
|---|
| 1721 | } else if(strcmp(a->name, "option") == 0)
|
|---|
| 1722 | ret += check_option(a->u.assignment);
|
|---|
| 1723 | else if(strcmp(a->name, "help") == 0) {
|
|---|
| 1724 | seen_help++;
|
|---|
| 1725 | } else if(strcmp(a->name, "argument") == 0) {
|
|---|
| 1726 | seen_argument++;
|
|---|
| 1727 | } else if(strcmp(a->name, "min_args") == 0) {
|
|---|
| 1728 | seen_minargs++;
|
|---|
| 1729 | } else if(strcmp(a->name, "max_args") == 0) {
|
|---|
| 1730 | seen_maxargs++;
|
|---|
| 1731 | } else {
|
|---|
| 1732 | ex(a, "unknown name: %s", a->name);
|
|---|
| 1733 | ret++;
|
|---|
| 1734 | }
|
|---|
| 1735 | }
|
|---|
| 1736 | if(seen_name == 0) {
|
|---|
| 1737 | ex(as, "no command name");
|
|---|
| 1738 | ret++;
|
|---|
| 1739 | }
|
|---|
| 1740 | if(seen_function > 1) {
|
|---|
| 1741 | ex(as, "multiple function names");
|
|---|
| 1742 | ret++;
|
|---|
| 1743 | }
|
|---|
| 1744 | if(seen_help > 1) {
|
|---|
| 1745 | ex(as, "multiple help strings");
|
|---|
| 1746 | ret++;
|
|---|
| 1747 | }
|
|---|
| 1748 | if(seen_argument > 1) {
|
|---|
| 1749 | ex(as, "multiple argument strings");
|
|---|
| 1750 | ret++;
|
|---|
| 1751 | }
|
|---|
| 1752 | if(seen_minargs > 1) {
|
|---|
| 1753 | ex(as, "multiple min_args strings");
|
|---|
| 1754 | ret++;
|
|---|
| 1755 | }
|
|---|
| 1756 | if(seen_maxargs > 1) {
|
|---|
| 1757 | ex(as, "multiple max_args strings");
|
|---|
| 1758 | ret++;
|
|---|
| 1759 | }
|
|---|
| 1760 |
|
|---|
| 1761 | return ret;
|
|---|
| 1762 | }
|
|---|
| 1763 |
|
|---|
| 1764 | static int
|
|---|
| 1765 | check(struct assignment *as)
|
|---|
| 1766 | {
|
|---|
| 1767 | struct assignment *a;
|
|---|
| 1768 | int ret = 0;
|
|---|
| 1769 | for(a = as; a != NULL; a = a->next) {
|
|---|
| 1770 | if(strcmp(a->name, "command")) {
|
|---|
| 1771 | fprintf(stderr, "unknown type %s line %d\n", a->name, a->lineno);
|
|---|
| 1772 | ret++;
|
|---|
| 1773 | continue;
|
|---|
| 1774 | }
|
|---|
| 1775 | if(a->type != a_assignment) {
|
|---|
| 1776 | fprintf(stderr, "bad command definition %s line %d\n", a->name, a->lineno);
|
|---|
| 1777 | ret++;
|
|---|
| 1778 | continue;
|
|---|
| 1779 | }
|
|---|
| 1780 | ret += check_command(a->u.assignment);
|
|---|
| 1781 | }
|
|---|
| 1782 | return ret;
|
|---|
| 1783 | }
|
|---|
| 1784 |
|
|---|
| 1785 | static struct assignment *
|
|---|
| 1786 | find_next(struct assignment *as, const char *name)
|
|---|
| 1787 | {
|
|---|
| 1788 | for(as = as->next; as != NULL; as = as->next) {
|
|---|
| 1789 | if(strcmp(as->name, name) == 0)
|
|---|
| 1790 | return as;
|
|---|
| 1791 | }
|
|---|
| 1792 | return NULL;
|
|---|
| 1793 | }
|
|---|
| 1794 |
|
|---|
| 1795 | static struct assignment *
|
|---|
| 1796 | find(struct assignment *as, const char *name)
|
|---|
| 1797 | {
|
|---|
| 1798 | for(; as != NULL; as = as->next) {
|
|---|
| 1799 | if(strcmp(as->name, name) == 0)
|
|---|
| 1800 | return as;
|
|---|
| 1801 | }
|
|---|
| 1802 | return NULL;
|
|---|
| 1803 | }
|
|---|
| 1804 |
|
|---|
| 1805 | static void
|
|---|
| 1806 | space(FILE *f, int level)
|
|---|
| 1807 | {
|
|---|
| 1808 | fprintf(f, "%*.*s", level * 4, level * 4, " ");
|
|---|
| 1809 | }
|
|---|
| 1810 |
|
|---|
| 1811 | static void
|
|---|
| 1812 | cprint(int level, const char *fmt, ...)
|
|---|
| 1813 | {
|
|---|
| 1814 | va_list ap;
|
|---|
| 1815 | va_start(ap, fmt);
|
|---|
| 1816 | space(cfile, level);
|
|---|
| 1817 | vfprintf(cfile, fmt, ap);
|
|---|
| 1818 | va_end(ap);
|
|---|
| 1819 | }
|
|---|
| 1820 |
|
|---|
| 1821 | static void
|
|---|
| 1822 | hprint(int level, const char *fmt, ...)
|
|---|
| 1823 | {
|
|---|
| 1824 | va_list ap;
|
|---|
| 1825 | va_start(ap, fmt);
|
|---|
| 1826 | space(hfile, level);
|
|---|
| 1827 | vfprintf(hfile, fmt, ap);
|
|---|
| 1828 | va_end(ap);
|
|---|
| 1829 | }
|
|---|
| 1830 |
|
|---|
| 1831 | static void gen_name(char *str);
|
|---|
| 1832 |
|
|---|
| 1833 | static void
|
|---|
| 1834 | gen_command(struct assignment *as)
|
|---|
| 1835 | {
|
|---|
| 1836 | struct assignment *a, *b;
|
|---|
| 1837 | char *f;
|
|---|
| 1838 | a = find(as, "name");
|
|---|
| 1839 | f = strdup(a->u.value);
|
|---|
| 1840 | gen_name(f);
|
|---|
| 1841 | cprint(1, " { ");
|
|---|
| 1842 | fprintf(cfile, "\"%s\", ", a->u.value);
|
|---|
| 1843 | fprintf(cfile, "%s_wrap, ", f);
|
|---|
| 1844 | b = find(as, "argument");
|
|---|
| 1845 | if(b)
|
|---|
| 1846 | fprintf(cfile, "\"%s %s\", ", a->u.value, b->u.value);
|
|---|
| 1847 | else
|
|---|
| 1848 | fprintf(cfile, "\"%s\", ", a->u.value);
|
|---|
| 1849 | b = find(as, "help");
|
|---|
| 1850 | if(b)
|
|---|
| 1851 | fprintf(cfile, "\"%s\"", b->u.value);
|
|---|
| 1852 | else
|
|---|
| 1853 | fprintf(cfile, "NULL");
|
|---|
| 1854 | fprintf(cfile, " },\n");
|
|---|
| 1855 | for(a = a->next; a != NULL; a = a->next)
|
|---|
| 1856 | if(strcmp(a->name, "name") == 0)
|
|---|
| 1857 | cprint(1, " { \"%s\" },\n", a->u.value);
|
|---|
| 1858 | cprint(0, "\n");
|
|---|
| 1859 | }
|
|---|
| 1860 |
|
|---|
| 1861 | static void
|
|---|
| 1862 | gen_name(char *str)
|
|---|
| 1863 | {
|
|---|
| 1864 | char *p;
|
|---|
| 1865 | for(p = str; *p != '\0'; p++)
|
|---|
| 1866 | if(!isalnum((unsigned char)*p))
|
|---|
| 1867 | *p = '_';
|
|---|
| 1868 | }
|
|---|
| 1869 |
|
|---|
| 1870 | static char *
|
|---|
| 1871 | make_name(struct assignment *as)
|
|---|
| 1872 | {
|
|---|
| 1873 | struct assignment *lopt;
|
|---|
| 1874 | struct assignment *type;
|
|---|
| 1875 | char *s;
|
|---|
| 1876 |
|
|---|
| 1877 | lopt = find(as, "long");
|
|---|
| 1878 | if(lopt == NULL)
|
|---|
| 1879 | lopt = find(as, "name");
|
|---|
| 1880 | if(lopt == NULL)
|
|---|
| 1881 | return NULL;
|
|---|
| 1882 |
|
|---|
| 1883 | type = find(as, "type");
|
|---|
| 1884 | if(strcmp(type->u.value, "-flag") == 0)
|
|---|
| 1885 | asprintf(&s, "%s_flag", lopt->u.value);
|
|---|
| 1886 | else
|
|---|
| 1887 | asprintf(&s, "%s_%s", lopt->u.value, type->u.value);
|
|---|
| 1888 | gen_name(s);
|
|---|
| 1889 | return s;
|
|---|
| 1890 | }
|
|---|
| 1891 |
|
|---|
| 1892 |
|
|---|
| 1893 | static void defval_int(const char *name, struct assignment *defval)
|
|---|
| 1894 | {
|
|---|
| 1895 | if(defval != NULL)
|
|---|
| 1896 | cprint(1, "opt.%s = %s;\n", name, defval->u.value);
|
|---|
| 1897 | else
|
|---|
| 1898 | cprint(1, "opt.%s = 0;\n", name);
|
|---|
| 1899 | }
|
|---|
| 1900 | static void defval_neg_flag(const char *name, struct assignment *defval)
|
|---|
| 1901 | {
|
|---|
| 1902 | if(defval != NULL)
|
|---|
| 1903 | cprint(1, "opt.%s = %s;\n", name, defval->u.value);
|
|---|
| 1904 | else
|
|---|
| 1905 | cprint(1, "opt.%s = 1;\n", name);
|
|---|
| 1906 | }
|
|---|
| 1907 | static void defval_string(const char *name, struct assignment *defval)
|
|---|
| 1908 | {
|
|---|
| 1909 | if(defval != NULL)
|
|---|
| 1910 | cprint(1, "opt.%s = (char *)(unsigned long)\"%s\";\n", name, defval->u.value);
|
|---|
| 1911 | else
|
|---|
| 1912 | cprint(1, "opt.%s = NULL;\n", name);
|
|---|
| 1913 | }
|
|---|
| 1914 | static void defval_strings(const char *name, struct assignment *defval)
|
|---|
| 1915 | {
|
|---|
| 1916 | cprint(1, "opt.%s.num_strings = 0;\n", name);
|
|---|
| 1917 | cprint(1, "opt.%s.strings = NULL;\n", name);
|
|---|
| 1918 | }
|
|---|
| 1919 |
|
|---|
| 1920 | static void free_strings(const char *name)
|
|---|
| 1921 | {
|
|---|
| 1922 | cprint(1, "free_getarg_strings (&opt.%s);\n", name);
|
|---|
| 1923 | }
|
|---|
| 1924 |
|
|---|
| 1925 | struct type_handler {
|
|---|
| 1926 | const char *typename;
|
|---|
| 1927 | const char *c_type;
|
|---|
| 1928 | const char *getarg_type;
|
|---|
| 1929 | void (*defval)(const char*, struct assignment*);
|
|---|
| 1930 | void (*free)(const char*);
|
|---|
| 1931 | } type_handlers[] = {
|
|---|
| 1932 | { "integer",
|
|---|
| 1933 | "int",
|
|---|
| 1934 | "arg_integer",
|
|---|
| 1935 | defval_int,
|
|---|
| 1936 | NULL
|
|---|
| 1937 | },
|
|---|
| 1938 | { "string",
|
|---|
| 1939 | "char*",
|
|---|
| 1940 | "arg_string",
|
|---|
| 1941 | defval_string,
|
|---|
| 1942 | NULL
|
|---|
| 1943 | },
|
|---|
| 1944 | { "strings",
|
|---|
| 1945 | "struct getarg_strings",
|
|---|
| 1946 | "arg_strings",
|
|---|
| 1947 | defval_strings,
|
|---|
| 1948 | free_strings
|
|---|
| 1949 | },
|
|---|
| 1950 | { "flag",
|
|---|
| 1951 | "int",
|
|---|
| 1952 | "arg_flag",
|
|---|
| 1953 | defval_int,
|
|---|
| 1954 | NULL
|
|---|
| 1955 | },
|
|---|
| 1956 | { "-flag",
|
|---|
| 1957 | "int",
|
|---|
| 1958 | "arg_negative_flag",
|
|---|
| 1959 | defval_neg_flag,
|
|---|
| 1960 | NULL
|
|---|
| 1961 | },
|
|---|
| 1962 | { NULL }
|
|---|
| 1963 | };
|
|---|
| 1964 |
|
|---|
| 1965 | static struct type_handler *find_handler(struct assignment *type)
|
|---|
| 1966 | {
|
|---|
| 1967 | struct type_handler *th;
|
|---|
| 1968 | for(th = type_handlers; th->typename != NULL; th++)
|
|---|
| 1969 | if(strcmp(type->u.value, th->typename) == 0)
|
|---|
| 1970 | return th;
|
|---|
| 1971 | ex(type, "unknown type \"%s\"", type->u.value);
|
|---|
| 1972 | exit(1);
|
|---|
| 1973 | }
|
|---|
| 1974 |
|
|---|
| 1975 | static void
|
|---|
| 1976 | gen_options(struct assignment *opt1, const char *name)
|
|---|
| 1977 | {
|
|---|
| 1978 | struct assignment *tmp;
|
|---|
| 1979 |
|
|---|
| 1980 | hprint(0, "struct %s_options {\n", name);
|
|---|
| 1981 |
|
|---|
| 1982 | for(tmp = opt1;
|
|---|
| 1983 | tmp != NULL;
|
|---|
| 1984 | tmp = find_next(tmp, "option")) {
|
|---|
| 1985 | struct assignment *type;
|
|---|
| 1986 | struct type_handler *th;
|
|---|
| 1987 | char *s;
|
|---|
| 1988 |
|
|---|
| 1989 | s = make_name(tmp->u.assignment);
|
|---|
| 1990 | type = find(tmp->u.assignment, "type");
|
|---|
| 1991 | th = find_handler(type);
|
|---|
| 1992 | hprint(1, "%s %s;\n", th->c_type, s);
|
|---|
| 1993 | free(s);
|
|---|
| 1994 | }
|
|---|
| 1995 | hprint(0, "};\n");
|
|---|
| 1996 | }
|
|---|
| 1997 |
|
|---|
| 1998 | static void
|
|---|
| 1999 | gen_wrapper(struct assignment *as)
|
|---|
| 2000 | {
|
|---|
| 2001 | struct assignment *name;
|
|---|
| 2002 | struct assignment *arg;
|
|---|
| 2003 | struct assignment *opt1;
|
|---|
| 2004 | struct assignment *function;
|
|---|
| 2005 | struct assignment *tmp;
|
|---|
| 2006 | char *n, *f;
|
|---|
| 2007 | int nargs = 0;
|
|---|
| 2008 | int narguments = 0;
|
|---|
| 2009 |
|
|---|
| 2010 | name = find(as, "name");
|
|---|
| 2011 | n = strdup(name->u.value);
|
|---|
| 2012 | gen_name(n);
|
|---|
| 2013 | arg = find(as, "argument");
|
|---|
| 2014 | if (arg)
|
|---|
| 2015 | narguments++;
|
|---|
| 2016 | opt1 = find(as, "option");
|
|---|
| 2017 | function = find(as, "function");
|
|---|
| 2018 | if(function)
|
|---|
| 2019 | f = function->u.value;
|
|---|
| 2020 | else
|
|---|
| 2021 | f = n;
|
|---|
| 2022 |
|
|---|
| 2023 |
|
|---|
| 2024 | if(opt1 != NULL) {
|
|---|
| 2025 | gen_options(opt1, n);
|
|---|
| 2026 | hprint(0, "int %s(struct %s_options*, int, char **);\n", f, n);
|
|---|
| 2027 | } else {
|
|---|
| 2028 | hprint(0, "int %s(void*, int, char **);\n", f);
|
|---|
| 2029 | }
|
|---|
| 2030 |
|
|---|
| 2031 | fprintf(cfile, "static int\n");
|
|---|
| 2032 | fprintf(cfile, "%s_wrap(int argc, char **argv)\n", n);
|
|---|
| 2033 | fprintf(cfile, "{\n");
|
|---|
| 2034 | if(opt1 != NULL)
|
|---|
| 2035 | cprint(1, "struct %s_options opt;\n", n);
|
|---|
| 2036 | cprint(1, "int ret;\n");
|
|---|
| 2037 | cprint(1, "int optidx = 0;\n");
|
|---|
| 2038 | cprint(1, "struct getargs args[] = {\n");
|
|---|
| 2039 | for(tmp = find(as, "option");
|
|---|
| 2040 | tmp != NULL;
|
|---|
| 2041 | tmp = find_next(tmp, "option")) {
|
|---|
| 2042 | struct assignment *type = find(tmp->u.assignment, "type");
|
|---|
| 2043 | struct assignment *lopt = find(tmp->u.assignment, "long");
|
|---|
| 2044 | struct assignment *sopt = find(tmp->u.assignment, "short");
|
|---|
| 2045 | struct assignment *aarg = find(tmp->u.assignment, "argument");
|
|---|
| 2046 | struct assignment *help = find(tmp->u.assignment, "help");
|
|---|
| 2047 |
|
|---|
| 2048 | struct type_handler *th;
|
|---|
| 2049 |
|
|---|
| 2050 | cprint(2, "{ ");
|
|---|
| 2051 | if(lopt)
|
|---|
| 2052 | fprintf(cfile, "\"%s\", ", lopt->u.value);
|
|---|
| 2053 | else
|
|---|
| 2054 | fprintf(cfile, "NULL, ");
|
|---|
| 2055 | if(sopt)
|
|---|
| 2056 | fprintf(cfile, "'%c', ", *sopt->u.value);
|
|---|
| 2057 | else
|
|---|
| 2058 | fprintf(cfile, "0, ");
|
|---|
| 2059 | th = find_handler(type);
|
|---|
| 2060 | fprintf(cfile, "%s, ", th->getarg_type);
|
|---|
| 2061 | fprintf(cfile, "NULL, ");
|
|---|
| 2062 | if(help)
|
|---|
| 2063 | fprintf(cfile, "\"%s\", ", help->u.value);
|
|---|
| 2064 | else
|
|---|
| 2065 | fprintf(cfile, "NULL, ");
|
|---|
| 2066 | if(aarg) {
|
|---|
| 2067 | fprintf(cfile, "\"%s\"", aarg->u.value);
|
|---|
| 2068 | narguments++;
|
|---|
| 2069 | } else
|
|---|
| 2070 | fprintf(cfile, "NULL");
|
|---|
| 2071 | fprintf(cfile, " },\n");
|
|---|
| 2072 | }
|
|---|
| 2073 | cprint(2, "{ \"help\", 'h', arg_flag, NULL, NULL, NULL }\n");
|
|---|
| 2074 | cprint(1, "};\n");
|
|---|
| 2075 | cprint(1, "int help_flag = 0;\n");
|
|---|
| 2076 |
|
|---|
| 2077 | for(tmp = find(as, "option");
|
|---|
| 2078 | tmp != NULL;
|
|---|
| 2079 | tmp = find_next(tmp, "option")) {
|
|---|
| 2080 | char *s;
|
|---|
| 2081 | struct assignment *type = find(tmp->u.assignment, "type");
|
|---|
| 2082 |
|
|---|
| 2083 | struct assignment *defval = find(tmp->u.assignment, "default");
|
|---|
| 2084 |
|
|---|
| 2085 | struct type_handler *th;
|
|---|
| 2086 |
|
|---|
| 2087 | s = make_name(tmp->u.assignment);
|
|---|
| 2088 | th = find_handler(type);
|
|---|
| 2089 | (*th->defval)(s, defval);
|
|---|
| 2090 | free(s);
|
|---|
| 2091 | }
|
|---|
| 2092 |
|
|---|
| 2093 | for(tmp = find(as, "option");
|
|---|
| 2094 | tmp != NULL;
|
|---|
| 2095 | tmp = find_next(tmp, "option")) {
|
|---|
| 2096 | char *s;
|
|---|
| 2097 | s = make_name(tmp->u.assignment);
|
|---|
| 2098 | cprint(1, "args[%d].value = &opt.%s;\n", nargs++, s);
|
|---|
| 2099 | free(s);
|
|---|
| 2100 | }
|
|---|
| 2101 | cprint(1, "args[%d].value = &help_flag;\n", nargs++);
|
|---|
| 2102 | cprint(1, "if(getarg(args, %d, argc, argv, &optidx))\n", nargs);
|
|---|
| 2103 | cprint(2, "goto usage;\n");
|
|---|
| 2104 |
|
|---|
| 2105 | {
|
|---|
| 2106 | int min_args = -1;
|
|---|
| 2107 | int max_args = -1;
|
|---|
| 2108 | char *end;
|
|---|
| 2109 | if(narguments == 0) {
|
|---|
| 2110 | max_args = 0;
|
|---|
| 2111 | } else {
|
|---|
| 2112 | if((tmp = find(as, "min_args")) != NULL) {
|
|---|
| 2113 | min_args = strtol(tmp->u.value, &end, 0);
|
|---|
| 2114 | if(*end != '\0') {
|
|---|
| 2115 | ex(tmp, "min_args is not numeric");
|
|---|
| 2116 | exit(1);
|
|---|
| 2117 | }
|
|---|
| 2118 | if(min_args < 0) {
|
|---|
| 2119 | ex(tmp, "min_args must be non-negative");
|
|---|
| 2120 | exit(1);
|
|---|
| 2121 | }
|
|---|
| 2122 | }
|
|---|
| 2123 | if((tmp = find(as, "max_args")) != NULL) {
|
|---|
| 2124 | max_args = strtol(tmp->u.value, &end, 0);
|
|---|
| 2125 | if(*end != '\0') {
|
|---|
| 2126 | ex(tmp, "max_args is not numeric");
|
|---|
| 2127 | exit(1);
|
|---|
| 2128 | }
|
|---|
| 2129 | if(max_args < 0) {
|
|---|
| 2130 | ex(tmp, "max_args must be non-negative");
|
|---|
| 2131 | exit(1);
|
|---|
| 2132 | }
|
|---|
| 2133 | }
|
|---|
| 2134 | }
|
|---|
| 2135 | if(min_args != -1 || max_args != -1) {
|
|---|
| 2136 | if(min_args == max_args) {
|
|---|
| 2137 | cprint(1, "if(argc - optidx != %d) {\n",
|
|---|
| 2138 | min_args);
|
|---|
| 2139 | cprint(2, "fprintf(stderr, \"Need exactly %u parameters (%%u given).\\n\\n\", argc - optidx);\n", min_args);
|
|---|
| 2140 | cprint(2, "goto usage;\n");
|
|---|
| 2141 | cprint(1, "}\n");
|
|---|
| 2142 | } else {
|
|---|
| 2143 | if(max_args != -1) {
|
|---|
| 2144 | cprint(1, "if(argc - optidx > %d) {\n", max_args);
|
|---|
| 2145 | cprint(2, "fprintf(stderr, \"Arguments given (%%u) are more than expected (%u).\\n\\n\", argc - optidx);\n", max_args);
|
|---|
| 2146 | cprint(2, "goto usage;\n");
|
|---|
| 2147 | cprint(1, "}\n");
|
|---|
| 2148 | }
|
|---|
| 2149 | if(min_args != -1) {
|
|---|
| 2150 | cprint(1, "if(argc - optidx < %d) {\n", min_args);
|
|---|
| 2151 | cprint(2, "fprintf(stderr, \"Arguments given (%%u) are less than expected (%u).\\n\\n\", argc - optidx);\n", min_args);
|
|---|
| 2152 | cprint(2, "goto usage;\n");
|
|---|
| 2153 | cprint(1, "}\n");
|
|---|
| 2154 | }
|
|---|
| 2155 | }
|
|---|
| 2156 | }
|
|---|
| 2157 | }
|
|---|
| 2158 |
|
|---|
| 2159 | cprint(1, "if(help_flag)\n");
|
|---|
| 2160 | cprint(2, "goto usage;\n");
|
|---|
| 2161 |
|
|---|
| 2162 | cprint(1, "ret = %s(%s, argc - optidx, argv + optidx);\n",
|
|---|
| 2163 | f, opt1 ? "&opt": "NULL");
|
|---|
| 2164 |
|
|---|
| 2165 | /* free allocated data */
|
|---|
| 2166 | for(tmp = find(as, "option");
|
|---|
| 2167 | tmp != NULL;
|
|---|
| 2168 | tmp = find_next(tmp, "option")) {
|
|---|
| 2169 | char *s;
|
|---|
| 2170 | struct assignment *type = find(tmp->u.assignment, "type");
|
|---|
| 2171 | struct type_handler *th;
|
|---|
| 2172 | th = find_handler(type);
|
|---|
| 2173 | if(th->free == NULL)
|
|---|
| 2174 | continue;
|
|---|
| 2175 | s = make_name(tmp->u.assignment);
|
|---|
| 2176 | (*th->free)(s);
|
|---|
| 2177 | free(s);
|
|---|
| 2178 | }
|
|---|
| 2179 | cprint(1, "return ret;\n");
|
|---|
| 2180 |
|
|---|
| 2181 | cprint(0, "usage:\n");
|
|---|
| 2182 | cprint(1, "arg_printusage (args, %d, \"%s\", \"%s\");\n", nargs,
|
|---|
| 2183 | name->u.value, arg ? arg->u.value : "");
|
|---|
| 2184 | /* free allocated data */
|
|---|
| 2185 | for(tmp = find(as, "option");
|
|---|
| 2186 | tmp != NULL;
|
|---|
| 2187 | tmp = find_next(tmp, "option")) {
|
|---|
| 2188 | char *s;
|
|---|
| 2189 | struct assignment *type = find(tmp->u.assignment, "type");
|
|---|
| 2190 | struct type_handler *th;
|
|---|
| 2191 | th = find_handler(type);
|
|---|
| 2192 | if(th->free == NULL)
|
|---|
| 2193 | continue;
|
|---|
| 2194 | s = make_name(tmp->u.assignment);
|
|---|
| 2195 | (*th->free)(s);
|
|---|
| 2196 | free(s);
|
|---|
| 2197 | }
|
|---|
| 2198 | cprint(1, "return 0;\n");
|
|---|
| 2199 | cprint(0, "}\n");
|
|---|
| 2200 | cprint(0, "\n");
|
|---|
| 2201 | }
|
|---|
| 2202 |
|
|---|
| 2203 | char cname[PATH_MAX];
|
|---|
| 2204 | char hname[PATH_MAX];
|
|---|
| 2205 |
|
|---|
| 2206 | static void
|
|---|
| 2207 | gen(struct assignment *as)
|
|---|
| 2208 | {
|
|---|
| 2209 | struct assignment *a;
|
|---|
| 2210 | cprint(0, "#include <stdio.h>\n");
|
|---|
| 2211 | cprint(0, "#include <getarg.h>\n");
|
|---|
| 2212 | cprint(0, "#include <sl.h>\n");
|
|---|
| 2213 | cprint(0, "#include \"%s\"\n\n", hname);
|
|---|
| 2214 |
|
|---|
| 2215 | hprint(0, "#include <stdio.h>\n");
|
|---|
| 2216 | hprint(0, "#include <sl.h>\n");
|
|---|
| 2217 | hprint(0, "\n");
|
|---|
| 2218 |
|
|---|
| 2219 |
|
|---|
| 2220 | for(a = as; a != NULL; a = a->next)
|
|---|
| 2221 | gen_wrapper(a->u.assignment);
|
|---|
| 2222 |
|
|---|
| 2223 | cprint(0, "SL_cmd commands[] = {\n");
|
|---|
| 2224 | for(a = as; a != NULL; a = a->next)
|
|---|
| 2225 | gen_command(a->u.assignment);
|
|---|
| 2226 | cprint(1, "{ NULL }\n");
|
|---|
| 2227 | cprint(0, "};\n");
|
|---|
| 2228 |
|
|---|
| 2229 | hprint(0, "extern SL_cmd commands[];\n");
|
|---|
| 2230 | }
|
|---|
| 2231 |
|
|---|
| 2232 | int version_flag;
|
|---|
| 2233 | int help_flag;
|
|---|
| 2234 | struct getargs args[] = {
|
|---|
| 2235 | { "version", 0, arg_flag, &version_flag },
|
|---|
| 2236 | { "help", 0, arg_flag, &help_flag }
|
|---|
| 2237 | };
|
|---|
| 2238 | int num_args = sizeof(args) / sizeof(args[0]);
|
|---|
| 2239 |
|
|---|
| 2240 | static void
|
|---|
| 2241 | usage(int code)
|
|---|
| 2242 | {
|
|---|
| 2243 | arg_printusage(args, num_args, NULL, "command-table");
|
|---|
| 2244 | exit(code);
|
|---|
| 2245 | }
|
|---|
| 2246 |
|
|---|
| 2247 | int
|
|---|
| 2248 | main(int argc, char **argv)
|
|---|
| 2249 | {
|
|---|
| 2250 | char *p;
|
|---|
| 2251 |
|
|---|
| 2252 | int optidx = 0;
|
|---|
| 2253 |
|
|---|
| 2254 | setprogname(argv[0]);
|
|---|
| 2255 | if(getarg(args, num_args, argc, argv, &optidx))
|
|---|
| 2256 | usage(1);
|
|---|
| 2257 | if(help_flag)
|
|---|
| 2258 | usage(0);
|
|---|
| 2259 | if(version_flag) {
|
|---|
| 2260 | print_version(NULL);
|
|---|
| 2261 | exit(0);
|
|---|
| 2262 | }
|
|---|
| 2263 |
|
|---|
| 2264 | if(argc == optidx)
|
|---|
| 2265 | usage(1);
|
|---|
| 2266 |
|
|---|
| 2267 | filename = argv[optidx];
|
|---|
| 2268 | yyin = fopen(filename, "r");
|
|---|
| 2269 | if(yyin == NULL)
|
|---|
| 2270 | err(1, "%s", filename);
|
|---|
| 2271 | p = strrchr(filename, '/');
|
|---|
| 2272 | if(p)
|
|---|
| 2273 | strlcpy(cname, p + 1, sizeof(cname));
|
|---|
| 2274 | else
|
|---|
| 2275 | strlcpy(cname, filename, sizeof(cname));
|
|---|
| 2276 | p = strrchr(cname, '.');
|
|---|
| 2277 | if(p)
|
|---|
| 2278 | *p = '\0';
|
|---|
| 2279 | strlcpy(hname, cname, sizeof(hname));
|
|---|
| 2280 | strlcat(cname, ".c", sizeof(cname));
|
|---|
| 2281 | strlcat(hname, ".h", sizeof(hname));
|
|---|
| 2282 | yyparse();
|
|---|
| 2283 | if(error_flag)
|
|---|
| 2284 | exit(1);
|
|---|
| 2285 | if(check(assignment) == 0) {
|
|---|
| 2286 | cfile = fopen(cname, "w");
|
|---|
| 2287 | if(cfile == NULL)
|
|---|
| 2288 | err(1, "%s", cname);
|
|---|
| 2289 | hfile = fopen(hname, "w");
|
|---|
| 2290 | if(hfile == NULL)
|
|---|
| 2291 | err(1, "%s", hname);
|
|---|
| 2292 | gen(assignment);
|
|---|
| 2293 | fclose(cfile);
|
|---|
| 2294 | fclose(hfile);
|
|---|
| 2295 | }
|
|---|
| 2296 | fclose(yyin);
|
|---|
| 2297 | return 0;
|
|---|
| 2298 | }
|
|---|
| 2299 |
|
|---|