Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / gpl3 / binutils / dist / ld / deffilep.c
blob57d841b3657e4587ec8b56f09738f3e30b49b665
1 /* A Bison parser, made by GNU Bison 2.1. */
3 /* Skeleton parser for Yacc-like parsing with Bison,
4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
26 /* Written by Richard Stallman by simplifying the original so called
27 ``semantic'' parser. */
29 /* All symbols defined below should begin with yy or YY, to avoid
30 infringing on user name space. This should be done even for local
31 variables, as they might otherwise be expanded by user macros.
32 There are some unavoidable exceptions within include files to
33 define necessary library symbols; they are noted "INFRINGES ON
34 USER NAME SPACE" below. */
36 /* Identify Bison output. */
37 #define YYBISON 1
39 /* Bison version. */
40 #define YYBISON_VERSION "2.1"
42 /* Skeleton name. */
43 #define YYSKELETON_NAME "yacc.c"
45 /* Pure parsers. */
46 #define YYPURE 0
48 /* Using locations. */
49 #define YYLSP_NEEDED 0
53 /* Tokens. */
54 #ifndef YYTOKENTYPE
55 # define YYTOKENTYPE
56 /* Put the tokens into the symbol table, so that GDB and other debuggers
57 know about them. */
58 enum yytokentype {
59 NAME = 258,
60 LIBRARY = 259,
61 DESCRIPTION = 260,
62 STACKSIZE = 261,
63 HEAPSIZE = 262,
64 CODE = 263,
65 DATAU = 264,
66 DATAL = 265,
67 SECTIONS = 266,
68 EXPORTS = 267,
69 IMPORTS = 268,
70 VERSIONK = 269,
71 BASE = 270,
72 CONSTANTU = 271,
73 CONSTANTL = 272,
74 PRIVATEU = 273,
75 PRIVATEL = 274,
76 READ = 275,
77 WRITE = 276,
78 EXECUTE = 277,
79 SHARED = 278,
80 NONAMEU = 279,
81 NONAMEL = 280,
82 DIRECTIVE = 281,
83 ID = 282,
84 NUMBER = 283
86 #endif
87 /* Tokens. */
88 #define NAME 258
89 #define LIBRARY 259
90 #define DESCRIPTION 260
91 #define STACKSIZE 261
92 #define HEAPSIZE 262
93 #define CODE 263
94 #define DATAU 264
95 #define DATAL 265
96 #define SECTIONS 266
97 #define EXPORTS 267
98 #define IMPORTS 268
99 #define VERSIONK 269
100 #define BASE 270
101 #define CONSTANTU 271
102 #define CONSTANTL 272
103 #define PRIVATEU 273
104 #define PRIVATEL 274
105 #define READ 275
106 #define WRITE 276
107 #define EXECUTE 277
108 #define SHARED 278
109 #define NONAMEU 279
110 #define NONAMEL 280
111 #define DIRECTIVE 281
112 #define ID 282
113 #define NUMBER 283
118 /* Copy the first part of user declarations. */
119 #line 1 "deffilep.y"
120 /* deffilep.y - parser for .def files */
122 /* Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2007
123 Free Software Foundation, Inc.
125 This file is part of GNU Binutils.
127 This program is free software; you can redistribute it and/or modify
128 it under the terms of the GNU General Public License as published by
129 the Free Software Foundation; either version 3 of the License, or
130 (at your option) any later version.
132 This program is distributed in the hope that it will be useful,
133 but WITHOUT ANY WARRANTY; without even the implied warranty of
134 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135 GNU General Public License for more details.
137 You should have received a copy of the GNU General Public License
138 along with this program; if not, write to the Free Software
139 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
140 MA 02110-1301, USA. */
142 #include "sysdep.h"
143 #include "libiberty.h"
144 #include "safe-ctype.h"
145 #include "bfd.h"
146 #include "ld.h"
147 #include "ldmisc.h"
148 #include "deffile.h"
150 #define TRACE 0
152 #define ROUND_UP(a, b) (((a)+((b)-1))&~((b)-1))
154 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
155 as well as gratuitiously global symbol names, so we can have multiple
156 yacc generated parsers in ld. Note that these are only the variables
157 produced by yacc. If other parser generators (bison, byacc, etc) produce
158 additional global names that conflict at link time, then those parser
159 generators need to be fixed instead of adding those names to this list. */
161 #define yymaxdepth def_maxdepth
162 #define yyparse def_parse
163 #define yylex def_lex
164 #define yyerror def_error
165 #define yylval def_lval
166 #define yychar def_char
167 #define yydebug def_debug
168 #define yypact def_pact
169 #define yyr1 def_r1
170 #define yyr2 def_r2
171 #define yydef def_def
172 #define yychk def_chk
173 #define yypgo def_pgo
174 #define yyact def_act
175 #define yyexca def_exca
176 #define yyerrflag def_errflag
177 #define yynerrs def_nerrs
178 #define yyps def_ps
179 #define yypv def_pv
180 #define yys def_s
181 #define yy_yys def_yys
182 #define yystate def_state
183 #define yytmp def_tmp
184 #define yyv def_v
185 #define yy_yyv def_yyv
186 #define yyval def_val
187 #define yylloc def_lloc
188 #define yyreds def_reds /* With YYDEBUG defined. */
189 #define yytoks def_toks /* With YYDEBUG defined. */
190 #define yylhs def_yylhs
191 #define yylen def_yylen
192 #define yydefred def_yydefred
193 #define yydgoto def_yydgoto
194 #define yysindex def_yysindex
195 #define yyrindex def_yyrindex
196 #define yygindex def_yygindex
197 #define yytable def_yytable
198 #define yycheck def_yycheck
200 static void def_description (const char *);
201 static void def_exports (const char *, const char *, int, int);
202 static void def_heapsize (int, int);
203 static void def_import (const char *, const char *, const char *, const char *,
204 int);
205 static void def_image_name (const char *, int, int);
206 static void def_section (const char *, int);
207 static void def_section_alt (const char *, const char *);
208 static void def_stacksize (int, int);
209 static void def_version (int, int);
210 static void def_directive (char *);
211 static int def_parse (void);
212 static int def_error (const char *);
213 static int def_lex (void);
215 static int lex_forced_token = 0;
216 static const char *lex_parse_string = 0;
217 static const char *lex_parse_string_end = 0;
221 /* Enabling traces. */
222 #ifndef YYDEBUG
223 # define YYDEBUG 0
224 #endif
226 /* Enabling verbose error messages. */
227 #ifdef YYERROR_VERBOSE
228 # undef YYERROR_VERBOSE
229 # define YYERROR_VERBOSE 1
230 #else
231 # define YYERROR_VERBOSE 0
232 #endif
234 /* Enabling the token table. */
235 #ifndef YYTOKEN_TABLE
236 # define YYTOKEN_TABLE 0
237 #endif
239 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
240 #line 102 "deffilep.y"
241 typedef union YYSTYPE {
242 char *id;
243 int number;
244 } YYSTYPE;
245 /* Line 196 of yacc.c. */
246 #line 247 "deffilep.c"
247 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
248 # define YYSTYPE_IS_DECLARED 1
249 # define YYSTYPE_IS_TRIVIAL 1
250 #endif
254 /* Copy the second part of user declarations. */
257 /* Line 219 of yacc.c. */
258 #line 259 "deffilep.c"
260 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
261 # define YYSIZE_T __SIZE_TYPE__
262 #endif
263 #if ! defined (YYSIZE_T) && defined (size_t)
264 # define YYSIZE_T size_t
265 #endif
266 #if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
267 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
268 # define YYSIZE_T size_t
269 #endif
270 #if ! defined (YYSIZE_T)
271 # define YYSIZE_T unsigned int
272 #endif
274 #ifndef YY_
275 # if YYENABLE_NLS
276 # if ENABLE_NLS
277 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
278 # define YY_(msgid) dgettext ("bison-runtime", msgid)
279 # endif
280 # endif
281 # ifndef YY_
282 # define YY_(msgid) msgid
283 # endif
284 #endif
286 #if ! defined (yyoverflow) || YYERROR_VERBOSE
288 /* The parser invokes alloca or malloc; define the necessary symbols. */
290 # ifdef YYSTACK_USE_ALLOCA
291 # if YYSTACK_USE_ALLOCA
292 # ifdef __GNUC__
293 # define YYSTACK_ALLOC __builtin_alloca
294 # else
295 # define YYSTACK_ALLOC alloca
296 # if defined (__STDC__) || defined (__cplusplus)
297 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
298 # define YYINCLUDED_STDLIB_H
299 # endif
300 # endif
301 # endif
302 # endif
304 # ifdef YYSTACK_ALLOC
305 /* Pacify GCC's `empty if-body' warning. */
306 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
307 # ifndef YYSTACK_ALLOC_MAXIMUM
308 /* The OS might guarantee only one guard page at the bottom of the stack,
309 and a page size can be as small as 4096 bytes. So we cannot safely
310 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
311 to allow for a few compiler-allocated temporary stack slots. */
312 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */
313 # endif
314 # else
315 # define YYSTACK_ALLOC YYMALLOC
316 # define YYSTACK_FREE YYFREE
317 # ifndef YYSTACK_ALLOC_MAXIMUM
318 # define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1)
319 # endif
320 # ifdef __cplusplus
321 extern "C" {
322 # endif
323 # ifndef YYMALLOC
324 # define YYMALLOC malloc
325 # if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \
326 && (defined (__STDC__) || defined (__cplusplus)))
327 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
328 # endif
329 # endif
330 # ifndef YYFREE
331 # define YYFREE free
332 # if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \
333 && (defined (__STDC__) || defined (__cplusplus)))
334 void free (void *); /* INFRINGES ON USER NAME SPACE */
335 # endif
336 # endif
337 # ifdef __cplusplus
339 # endif
340 # endif
341 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
344 #if (! defined (yyoverflow) \
345 && (! defined (__cplusplus) \
346 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
348 /* A type that is properly aligned for any stack member. */
349 union yyalloc
351 short int yyss;
352 YYSTYPE yyvs;
355 /* The size of the maximum gap between one aligned stack and the next. */
356 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
358 /* The size of an array large to enough to hold all stacks, each with
359 N elements. */
360 # define YYSTACK_BYTES(N) \
361 ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \
362 + YYSTACK_GAP_MAXIMUM)
364 /* Copy COUNT objects from FROM to TO. The source and destination do
365 not overlap. */
366 # ifndef YYCOPY
367 # if defined (__GNUC__) && 1 < __GNUC__
368 # define YYCOPY(To, From, Count) \
369 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
370 # else
371 # define YYCOPY(To, From, Count) \
372 do \
374 YYSIZE_T yyi; \
375 for (yyi = 0; yyi < (Count); yyi++) \
376 (To)[yyi] = (From)[yyi]; \
378 while (0)
379 # endif
380 # endif
382 /* Relocate STACK from its old location to the new one. The
383 local variables YYSIZE and YYSTACKSIZE give the old and new number of
384 elements in the stack, and YYPTR gives the new location of the
385 stack. Advance YYPTR to a properly aligned location for the next
386 stack. */
387 # define YYSTACK_RELOCATE(Stack) \
388 do \
390 YYSIZE_T yynewbytes; \
391 YYCOPY (&yyptr->Stack, Stack, yysize); \
392 Stack = &yyptr->Stack; \
393 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
394 yyptr += yynewbytes / sizeof (*yyptr); \
396 while (0)
398 #endif
400 #if defined (__STDC__) || defined (__cplusplus)
401 typedef signed char yysigned_char;
402 #else
403 typedef short int yysigned_char;
404 #endif
406 /* YYFINAL -- State number of the termination state. */
407 #define YYFINAL 40
408 /* YYLAST -- Last index in YYTABLE. */
409 #define YYLAST 121
411 /* YYNTOKENS -- Number of terminals. */
412 #define YYNTOKENS 33
413 /* YYNNTS -- Number of nonterminals. */
414 #define YYNNTS 20
415 /* YYNRULES -- Number of rules. */
416 #define YYNRULES 63
417 /* YYNRULES -- Number of states. */
418 #define YYNSTATES 96
420 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
421 #define YYUNDEFTOK 2
422 #define YYMAXUTOK 283
424 #define YYTRANSLATE(YYX) \
425 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
427 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
428 static const unsigned char yytranslate[] =
430 0, 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, 31, 2, 29, 2, 2, 2,
435 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
436 2, 30, 2, 2, 32, 2, 2, 2, 2, 2,
437 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
438 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
439 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
440 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
441 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
442 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
443 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
444 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
445 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
446 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
447 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
448 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
449 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
450 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
451 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
452 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
453 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
454 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
455 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
456 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
457 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
458 25, 26, 27, 28
461 #if YYDEBUG
462 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
463 YYRHS. */
464 static const unsigned char yyprhs[] =
466 0, 0, 3, 6, 8, 12, 16, 19, 23, 27,
467 30, 33, 36, 39, 42, 45, 50, 53, 54, 56,
468 59, 65, 69, 70, 72, 74, 76, 78, 80, 82,
469 84, 86, 89, 91, 99, 107, 113, 119, 125, 129,
470 132, 134, 137, 140, 144, 146, 148, 149, 152, 153,
471 155, 157, 159, 161, 163, 167, 168, 171, 172, 175,
472 176, 180, 181, 183
475 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
476 static const yysigned_char yyrhs[] =
478 34, 0, -1, 34, 35, -1, 35, -1, 3, 48,
479 51, -1, 4, 48, 51, -1, 5, 27, -1, 6,
480 28, 46, -1, 7, 28, 46, -1, 8, 44, -1,
481 9, 44, -1, 11, 42, -1, 12, 36, -1, 13,
482 40, -1, 14, 28, -1, 14, 28, 29, 28, -1,
483 26, 27, -1, -1, 37, -1, 36, 37, -1, 52,
484 50, 49, 45, 38, -1, 39, 45, 38, -1, -1,
485 24, -1, 25, -1, 16, -1, 17, -1, 9, -1,
486 10, -1, 18, -1, 19, -1, 40, 41, -1, 41,
487 -1, 27, 30, 27, 29, 27, 29, 27, -1, 27,
488 30, 27, 29, 27, 29, 28, -1, 27, 30, 27,
489 29, 27, -1, 27, 30, 27, 29, 28, -1, 27,
490 29, 27, 29, 27, -1, 27, 29, 27, -1, 42,
491 43, -1, 43, -1, 27, 44, -1, 27, 27, -1,
492 44, 45, 47, -1, 47, -1, 31, -1, -1, 31,
493 28, -1, -1, 20, -1, 21, -1, 22, -1, 23,
494 -1, 27, -1, 27, 29, 27, -1, -1, 32, 28,
495 -1, -1, 30, 52, -1, -1, 15, 30, 28, -1,
496 -1, 27, -1, 52, 29, 27, -1
499 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
500 static const unsigned char yyrline[] =
502 0, 119, 119, 120, 124, 125, 126, 127, 128, 129,
503 130, 131, 132, 133, 134, 135, 136, 140, 142, 143,
504 150, 157, 158, 161, 162, 163, 164, 165, 166, 167,
505 168, 171, 172, 176, 177, 178, 179, 180, 181, 185,
506 186, 190, 191, 195, 196, 200, 201, 203, 204, 208,
507 209, 210, 211, 214, 215, 221, 225, 226, 230, 231,
508 234, 235, 238, 239
510 #endif
512 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
513 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
514 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
515 static const char *const yytname[] =
517 "$end", "error", "$undefined", "NAME", "LIBRARY", "DESCRIPTION",
518 "STACKSIZE", "HEAPSIZE", "CODE", "DATAU", "DATAL", "SECTIONS", "EXPORTS",
519 "IMPORTS", "VERSIONK", "BASE", "CONSTANTU", "CONSTANTL", "PRIVATEU",
520 "PRIVATEL", "READ", "WRITE", "EXECUTE", "SHARED", "NONAMEU", "NONAMEL",
521 "DIRECTIVE", "ID", "NUMBER", "'.'", "'='", "','", "'@'", "$accept",
522 "start", "command", "explist", "expline", "exp_opt_list", "exp_opt",
523 "implist", "impline", "seclist", "secline", "attr_list", "opt_comma",
524 "opt_number", "attr", "opt_name", "opt_ordinal", "opt_equal_name",
525 "opt_base", "dot_name", 0
527 #endif
529 # ifdef YYPRINT
530 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
531 token YYLEX-NUM. */
532 static const unsigned short int yytoknum[] =
534 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
535 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
536 275, 276, 277, 278, 279, 280, 281, 282, 283, 46,
537 61, 44, 64
539 # endif
541 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
542 static const unsigned char yyr1[] =
544 0, 33, 34, 34, 35, 35, 35, 35, 35, 35,
545 35, 35, 35, 35, 35, 35, 35, 36, 36, 36,
546 37, 38, 38, 39, 39, 39, 39, 39, 39, 39,
547 39, 40, 40, 41, 41, 41, 41, 41, 41, 42,
548 42, 43, 43, 44, 44, 45, 45, 46, 46, 47,
549 47, 47, 47, 48, 48, 48, 49, 49, 50, 50,
550 51, 51, 52, 52
553 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
554 static const unsigned char yyr2[] =
556 0, 2, 2, 1, 3, 3, 2, 3, 3, 2,
557 2, 2, 2, 2, 2, 4, 2, 0, 1, 2,
558 5, 3, 0, 1, 1, 1, 1, 1, 1, 1,
559 1, 2, 1, 7, 7, 5, 5, 5, 3, 2,
560 1, 2, 2, 3, 1, 1, 0, 2, 0, 1,
561 1, 1, 1, 1, 3, 0, 2, 0, 2, 0,
562 3, 0, 1, 3
565 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
566 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
567 means the default is an error. */
568 static const unsigned char yydefact[] =
570 0, 55, 55, 0, 0, 0, 0, 0, 0, 17,
571 0, 0, 0, 0, 3, 53, 61, 61, 6, 48,
572 48, 49, 50, 51, 52, 9, 44, 10, 0, 11,
573 40, 62, 12, 18, 59, 0, 13, 32, 14, 16,
574 1, 2, 0, 0, 4, 5, 0, 7, 8, 45,
575 0, 42, 41, 39, 19, 0, 0, 57, 0, 0,
576 31, 0, 54, 0, 47, 43, 63, 58, 0, 46,
577 38, 0, 15, 60, 56, 22, 0, 0, 27, 28,
578 25, 26, 29, 30, 23, 24, 20, 46, 37, 35,
579 36, 22, 0, 21, 33, 34
582 /* YYDEFGOTO[NTERM-NUM]. */
583 static const yysigned_char yydefgoto[] =
585 -1, 13, 14, 32, 33, 86, 87, 36, 37, 29,
586 30, 25, 50, 47, 26, 16, 69, 57, 44, 34
589 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
590 STATE-NUM. */
591 #define YYPACT_NINF -55
592 static const yysigned_char yypact[] =
594 16, -9, -9, 5, 22, 29, 41, 41, 31, 32,
595 38, 39, 42, 0, -55, 37, 53, 53, -55, 40,
596 40, -55, -55, -55, -55, 18, -55, 18, 33, 31,
597 -55, -55, 32, -55, -28, -13, 38, -55, 43, -55,
598 -55, -55, 46, 44, -55, -55, 47, -55, -55, -55,
599 41, -55, 18, -55, -55, 49, 32, 45, 51, 52,
600 -55, 54, -55, 55, -55, -55, -55, 56, 58, 50,
601 59, 60, -55, -55, -55, 27, 57, 7, -55, -55,
602 -55, -55, -55, -55, -55, -55, -55, 50, -55, 61,
603 -55, 27, 20, -55, -55, -55
606 /* YYPGOTO[NTERM-NUM]. */
607 static const yysigned_char yypgoto[] =
609 -55, -55, 67, -55, 62, -21, -55, -55, 63, -55,
610 64, 3, -54, 71, 48, 85, -55, -55, 75, 65
613 /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
614 positive, shift that token. If negative, reduce the rule which
615 number is the opposite. If zero, do what YYDEFACT says.
616 If YYTABLE_NINF, syntax error. */
617 #define YYTABLE_NINF -47
618 static const yysigned_char yytable[] =
620 40, 55, 56, 1, 2, 3, 4, 5, 6, 7,
621 27, 8, 9, 10, 11, 75, 58, 59, 15, 1,
622 2, 3, 4, 5, 6, 7, 12, 8, 9, 10,
623 11, 52, 18, 91, 89, 90, 78, 79, -46, -46,
624 -46, -46, 12, 80, 81, 82, 83, 94, 95, 49,
625 19, 84, 85, 21, 22, 23, 24, 20, 28, 31,
626 51, 21, 22, 23, 24, 35, 42, 38, 43, 39,
627 93, 46, 61, 62, 63, 64, 66, 68, 70, 71,
628 41, 49, 72, 73, 88, 55, 74, 17, 76, 77,
629 92, 48, 45, 53, 54, 0, 0, 0, 65, 60,
630 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
631 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
632 0, 67
635 static const yysigned_char yycheck[] =
637 0, 29, 30, 3, 4, 5, 6, 7, 8, 9,
638 7, 11, 12, 13, 14, 69, 29, 30, 27, 3,
639 4, 5, 6, 7, 8, 9, 26, 11, 12, 13,
640 14, 28, 27, 87, 27, 28, 9, 10, 20, 21,
641 22, 23, 26, 16, 17, 18, 19, 27, 28, 31,
642 28, 24, 25, 20, 21, 22, 23, 28, 27, 27,
643 27, 20, 21, 22, 23, 27, 29, 28, 15, 27,
644 91, 31, 29, 27, 30, 28, 27, 32, 27, 27,
645 13, 31, 28, 28, 27, 29, 28, 2, 29, 29,
646 29, 20, 17, 29, 32, -1, -1, -1, 50, 36,
647 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
648 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
649 -1, 56
652 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
653 symbol of state STATE-NUM. */
654 static const unsigned char yystos[] =
656 0, 3, 4, 5, 6, 7, 8, 9, 11, 12,
657 13, 14, 26, 34, 35, 27, 48, 48, 27, 28,
658 28, 20, 21, 22, 23, 44, 47, 44, 27, 42,
659 43, 27, 36, 37, 52, 27, 40, 41, 28, 27,
660 0, 35, 29, 15, 51, 51, 31, 46, 46, 31,
661 45, 27, 44, 43, 37, 29, 30, 50, 29, 30,
662 41, 29, 27, 30, 28, 47, 27, 52, 32, 49,
663 27, 27, 28, 28, 28, 45, 29, 29, 9, 10,
664 16, 17, 18, 19, 24, 25, 38, 39, 27, 27,
665 28, 45, 29, 38, 27, 28
668 #define yyerrok (yyerrstatus = 0)
669 #define yyclearin (yychar = YYEMPTY)
670 #define YYEMPTY (-2)
671 #define YYEOF 0
673 #define YYACCEPT goto yyacceptlab
674 #define YYABORT goto yyabortlab
675 #define YYERROR goto yyerrorlab
678 /* Like YYERROR except do call yyerror. This remains here temporarily
679 to ease the transition to the new meaning of YYERROR, for GCC.
680 Once GCC version 2 has supplanted version 1, this can go. */
682 #define YYFAIL goto yyerrlab
684 #define YYRECOVERING() (!!yyerrstatus)
686 #define YYBACKUP(Token, Value) \
687 do \
688 if (yychar == YYEMPTY && yylen == 1) \
690 yychar = (Token); \
691 yylval = (Value); \
692 yytoken = YYTRANSLATE (yychar); \
693 YYPOPSTACK; \
694 goto yybackup; \
696 else \
698 yyerror (YY_("syntax error: cannot back up")); \
699 YYERROR; \
701 while (0)
704 #define YYTERROR 1
705 #define YYERRCODE 256
708 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
709 If N is 0, then set CURRENT to the empty location which ends
710 the previous symbol: RHS[0] (always defined). */
712 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
713 #ifndef YYLLOC_DEFAULT
714 # define YYLLOC_DEFAULT(Current, Rhs, N) \
715 do \
716 if (N) \
718 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
719 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
720 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
721 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
723 else \
725 (Current).first_line = (Current).last_line = \
726 YYRHSLOC (Rhs, 0).last_line; \
727 (Current).first_column = (Current).last_column = \
728 YYRHSLOC (Rhs, 0).last_column; \
730 while (0)
731 #endif
734 /* YY_LOCATION_PRINT -- Print the location on the stream.
735 This macro was not mandated originally: define only if we know
736 we won't break user code: when these are the locations we know. */
738 #ifndef YY_LOCATION_PRINT
739 # if YYLTYPE_IS_TRIVIAL
740 # define YY_LOCATION_PRINT(File, Loc) \
741 fprintf (File, "%d.%d-%d.%d", \
742 (Loc).first_line, (Loc).first_column, \
743 (Loc).last_line, (Loc).last_column)
744 # else
745 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
746 # endif
747 #endif
750 /* YYLEX -- calling `yylex' with the right arguments. */
752 #ifdef YYLEX_PARAM
753 # define YYLEX yylex (YYLEX_PARAM)
754 #else
755 # define YYLEX yylex ()
756 #endif
758 /* Enable debugging if requested. */
759 #if YYDEBUG
761 # ifndef YYFPRINTF
762 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
763 # define YYFPRINTF fprintf
764 # endif
766 # define YYDPRINTF(Args) \
767 do { \
768 if (yydebug) \
769 YYFPRINTF Args; \
770 } while (0)
772 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
773 do { \
774 if (yydebug) \
776 YYFPRINTF (stderr, "%s ", Title); \
777 yysymprint (stderr, \
778 Type, Value); \
779 YYFPRINTF (stderr, "\n"); \
781 } while (0)
783 /*------------------------------------------------------------------.
784 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
785 | TOP (included). |
786 `------------------------------------------------------------------*/
788 #if defined (__STDC__) || defined (__cplusplus)
789 static void
790 yy_stack_print (short int *bottom, short int *top)
791 #else
792 static void
793 yy_stack_print (bottom, top)
794 short int *bottom;
795 short int *top;
796 #endif
798 YYFPRINTF (stderr, "Stack now");
799 for (/* Nothing. */; bottom <= top; ++bottom)
800 YYFPRINTF (stderr, " %d", *bottom);
801 YYFPRINTF (stderr, "\n");
804 # define YY_STACK_PRINT(Bottom, Top) \
805 do { \
806 if (yydebug) \
807 yy_stack_print ((Bottom), (Top)); \
808 } while (0)
811 /*------------------------------------------------.
812 | Report that the YYRULE is going to be reduced. |
813 `------------------------------------------------*/
815 #if defined (__STDC__) || defined (__cplusplus)
816 static void
817 yy_reduce_print (int yyrule)
818 #else
819 static void
820 yy_reduce_print (yyrule)
821 int yyrule;
822 #endif
824 int yyi;
825 unsigned long int yylno = yyrline[yyrule];
826 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ",
827 yyrule - 1, yylno);
828 /* Print the symbols being reduced, and their result. */
829 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
830 YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
831 YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]);
834 # define YY_REDUCE_PRINT(Rule) \
835 do { \
836 if (yydebug) \
837 yy_reduce_print (Rule); \
838 } while (0)
840 /* Nonzero means print parse trace. It is left uninitialized so that
841 multiple parsers can coexist. */
842 int yydebug;
843 #else /* !YYDEBUG */
844 # define YYDPRINTF(Args)
845 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
846 # define YY_STACK_PRINT(Bottom, Top)
847 # define YY_REDUCE_PRINT(Rule)
848 #endif /* !YYDEBUG */
851 /* YYINITDEPTH -- initial size of the parser's stacks. */
852 #ifndef YYINITDEPTH
853 # define YYINITDEPTH 200
854 #endif
856 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
857 if the built-in stack extension method is used).
859 Do not make this value too large; the results are undefined if
860 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
861 evaluated with infinite-precision integer arithmetic. */
863 #ifndef YYMAXDEPTH
864 # define YYMAXDEPTH 10000
865 #endif
869 #if YYERROR_VERBOSE
871 # ifndef yystrlen
872 # if defined (__GLIBC__) && defined (_STRING_H)
873 # define yystrlen strlen
874 # else
875 /* Return the length of YYSTR. */
876 static YYSIZE_T
877 # if defined (__STDC__) || defined (__cplusplus)
878 yystrlen (const char *yystr)
879 # else
880 yystrlen (yystr)
881 const char *yystr;
882 # endif
884 const char *yys = yystr;
886 while (*yys++ != '\0')
887 continue;
889 return yys - yystr - 1;
891 # endif
892 # endif
894 # ifndef yystpcpy
895 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
896 # define yystpcpy stpcpy
897 # else
898 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
899 YYDEST. */
900 static char *
901 # if defined (__STDC__) || defined (__cplusplus)
902 yystpcpy (char *yydest, const char *yysrc)
903 # else
904 yystpcpy (yydest, yysrc)
905 char *yydest;
906 const char *yysrc;
907 # endif
909 char *yyd = yydest;
910 const char *yys = yysrc;
912 while ((*yyd++ = *yys++) != '\0')
913 continue;
915 return yyd - 1;
917 # endif
918 # endif
920 # ifndef yytnamerr
921 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
922 quotes and backslashes, so that it's suitable for yyerror. The
923 heuristic is that double-quoting is unnecessary unless the string
924 contains an apostrophe, a comma, or backslash (other than
925 backslash-backslash). YYSTR is taken from yytname. If YYRES is
926 null, do not copy; instead, return the length of what the result
927 would have been. */
928 static YYSIZE_T
929 yytnamerr (char *yyres, const char *yystr)
931 if (*yystr == '"')
933 size_t yyn = 0;
934 char const *yyp = yystr;
936 for (;;)
937 switch (*++yyp)
939 case '\'':
940 case ',':
941 goto do_not_strip_quotes;
943 case '\\':
944 if (*++yyp != '\\')
945 goto do_not_strip_quotes;
946 /* Fall through. */
947 default:
948 if (yyres)
949 yyres[yyn] = *yyp;
950 yyn++;
951 break;
953 case '"':
954 if (yyres)
955 yyres[yyn] = '\0';
956 return yyn;
958 do_not_strip_quotes: ;
961 if (! yyres)
962 return yystrlen (yystr);
964 return yystpcpy (yyres, yystr) - yyres;
966 # endif
968 #endif /* YYERROR_VERBOSE */
972 #if YYDEBUG
973 /*--------------------------------.
974 | Print this symbol on YYOUTPUT. |
975 `--------------------------------*/
977 #if defined (__STDC__) || defined (__cplusplus)
978 static void
979 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
980 #else
981 static void
982 yysymprint (yyoutput, yytype, yyvaluep)
983 FILE *yyoutput;
984 int yytype;
985 YYSTYPE *yyvaluep;
986 #endif
988 /* Pacify ``unused variable'' warnings. */
989 (void) yyvaluep;
991 if (yytype < YYNTOKENS)
992 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
993 else
994 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
997 # ifdef YYPRINT
998 if (yytype < YYNTOKENS)
999 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
1000 # endif
1001 switch (yytype)
1003 default:
1004 break;
1006 YYFPRINTF (yyoutput, ")");
1009 #endif /* ! YYDEBUG */
1010 /*-----------------------------------------------.
1011 | Release the memory associated to this symbol. |
1012 `-----------------------------------------------*/
1014 #if defined (__STDC__) || defined (__cplusplus)
1015 static void
1016 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1017 #else
1018 static void
1019 yydestruct (yymsg, yytype, yyvaluep)
1020 const char *yymsg;
1021 int yytype;
1022 YYSTYPE *yyvaluep;
1023 #endif
1025 /* Pacify ``unused variable'' warnings. */
1026 (void) yyvaluep;
1028 if (!yymsg)
1029 yymsg = "Deleting";
1030 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1032 switch (yytype)
1035 default:
1036 break;
1041 /* Prevent warnings from -Wmissing-prototypes. */
1043 #ifdef YYPARSE_PARAM
1044 # if defined (__STDC__) || defined (__cplusplus)
1045 int yyparse (void *YYPARSE_PARAM);
1046 # else
1047 int yyparse ();
1048 # endif
1049 #else /* ! YYPARSE_PARAM */
1050 #if defined (__STDC__) || defined (__cplusplus)
1051 int yyparse (void);
1052 #else
1053 int yyparse ();
1054 #endif
1055 #endif /* ! YYPARSE_PARAM */
1059 /* The look-ahead symbol. */
1060 int yychar;
1062 /* The semantic value of the look-ahead symbol. */
1063 YYSTYPE yylval;
1065 /* Number of syntax errors so far. */
1066 int yynerrs;
1070 /*----------.
1071 | yyparse. |
1072 `----------*/
1074 #ifdef YYPARSE_PARAM
1075 # if defined (__STDC__) || defined (__cplusplus)
1076 int yyparse (void *YYPARSE_PARAM)
1077 # else
1078 int yyparse (YYPARSE_PARAM)
1079 void *YYPARSE_PARAM;
1080 # endif
1081 #else /* ! YYPARSE_PARAM */
1082 #if defined (__STDC__) || defined (__cplusplus)
1084 yyparse (void)
1085 #else
1087 yyparse ()
1089 #endif
1090 #endif
1093 int yystate;
1094 int yyn;
1095 int yyresult;
1096 /* Number of tokens to shift before error messages enabled. */
1097 int yyerrstatus;
1098 /* Look-ahead token as an internal (translated) token number. */
1099 int yytoken = 0;
1101 /* Three stacks and their tools:
1102 `yyss': related to states,
1103 `yyvs': related to semantic values,
1104 `yyls': related to locations.
1106 Refer to the stacks thru separate pointers, to allow yyoverflow
1107 to reallocate them elsewhere. */
1109 /* The state stack. */
1110 short int yyssa[YYINITDEPTH];
1111 short int *yyss = yyssa;
1112 short int *yyssp;
1114 /* The semantic value stack. */
1115 YYSTYPE yyvsa[YYINITDEPTH];
1116 YYSTYPE *yyvs = yyvsa;
1117 YYSTYPE *yyvsp;
1121 #define YYPOPSTACK (yyvsp--, yyssp--)
1123 YYSIZE_T yystacksize = YYINITDEPTH;
1125 /* The variables used to return semantic value and location from the
1126 action routines. */
1127 YYSTYPE yyval;
1130 /* When reducing, the number of symbols on the RHS of the reduced
1131 rule. */
1132 int yylen;
1134 YYDPRINTF ((stderr, "Starting parse\n"));
1136 yystate = 0;
1137 yyerrstatus = 0;
1138 yynerrs = 0;
1139 yychar = YYEMPTY; /* Cause a token to be read. */
1141 /* Initialize stack pointers.
1142 Waste one element of value and location stack
1143 so that they stay on the same level as the state stack.
1144 The wasted elements are never initialized. */
1146 yyssp = yyss;
1147 yyvsp = yyvs;
1149 goto yysetstate;
1151 /*------------------------------------------------------------.
1152 | yynewstate -- Push a new state, which is found in yystate. |
1153 `------------------------------------------------------------*/
1154 yynewstate:
1155 /* In all cases, when you get here, the value and location stacks
1156 have just been pushed. so pushing a state here evens the stacks.
1158 yyssp++;
1160 yysetstate:
1161 *yyssp = yystate;
1163 if (yyss + yystacksize - 1 <= yyssp)
1165 /* Get the current used size of the three stacks, in elements. */
1166 YYSIZE_T yysize = yyssp - yyss + 1;
1168 #ifdef yyoverflow
1170 /* Give user a chance to reallocate the stack. Use copies of
1171 these so that the &'s don't force the real ones into
1172 memory. */
1173 YYSTYPE *yyvs1 = yyvs;
1174 short int *yyss1 = yyss;
1177 /* Each stack pointer address is followed by the size of the
1178 data in use in that stack, in bytes. This used to be a
1179 conditional around just the two extra args, but that might
1180 be undefined if yyoverflow is a macro. */
1181 yyoverflow (YY_("memory exhausted"),
1182 &yyss1, yysize * sizeof (*yyssp),
1183 &yyvs1, yysize * sizeof (*yyvsp),
1185 &yystacksize);
1187 yyss = yyss1;
1188 yyvs = yyvs1;
1190 #else /* no yyoverflow */
1191 # ifndef YYSTACK_RELOCATE
1192 goto yyexhaustedlab;
1193 # else
1194 /* Extend the stack our own way. */
1195 if (YYMAXDEPTH <= yystacksize)
1196 goto yyexhaustedlab;
1197 yystacksize *= 2;
1198 if (YYMAXDEPTH < yystacksize)
1199 yystacksize = YYMAXDEPTH;
1202 short int *yyss1 = yyss;
1203 union yyalloc *yyptr =
1204 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1205 if (! yyptr)
1206 goto yyexhaustedlab;
1207 YYSTACK_RELOCATE (yyss);
1208 YYSTACK_RELOCATE (yyvs);
1210 # undef YYSTACK_RELOCATE
1211 if (yyss1 != yyssa)
1212 YYSTACK_FREE (yyss1);
1214 # endif
1215 #endif /* no yyoverflow */
1217 yyssp = yyss + yysize - 1;
1218 yyvsp = yyvs + yysize - 1;
1221 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1222 (unsigned long int) yystacksize));
1224 if (yyss + yystacksize - 1 <= yyssp)
1225 YYABORT;
1228 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1230 goto yybackup;
1232 /*-----------.
1233 | yybackup. |
1234 `-----------*/
1235 yybackup:
1237 /* Do appropriate processing given the current state. */
1238 /* Read a look-ahead token if we need one and don't already have one. */
1239 /* yyresume: */
1241 /* First try to decide what to do without reference to look-ahead token. */
1243 yyn = yypact[yystate];
1244 if (yyn == YYPACT_NINF)
1245 goto yydefault;
1247 /* Not known => get a look-ahead token if don't already have one. */
1249 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1250 if (yychar == YYEMPTY)
1252 YYDPRINTF ((stderr, "Reading a token: "));
1253 yychar = YYLEX;
1256 if (yychar <= YYEOF)
1258 yychar = yytoken = YYEOF;
1259 YYDPRINTF ((stderr, "Now at end of input.\n"));
1261 else
1263 yytoken = YYTRANSLATE (yychar);
1264 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1267 /* If the proper action on seeing token YYTOKEN is to reduce or to
1268 detect an error, take that action. */
1269 yyn += yytoken;
1270 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1271 goto yydefault;
1272 yyn = yytable[yyn];
1273 if (yyn <= 0)
1275 if (yyn == 0 || yyn == YYTABLE_NINF)
1276 goto yyerrlab;
1277 yyn = -yyn;
1278 goto yyreduce;
1281 if (yyn == YYFINAL)
1282 YYACCEPT;
1284 /* Shift the look-ahead token. */
1285 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1287 /* Discard the token being shifted unless it is eof. */
1288 if (yychar != YYEOF)
1289 yychar = YYEMPTY;
1291 *++yyvsp = yylval;
1294 /* Count tokens shifted since error; after three, turn off error
1295 status. */
1296 if (yyerrstatus)
1297 yyerrstatus--;
1299 yystate = yyn;
1300 goto yynewstate;
1303 /*-----------------------------------------------------------.
1304 | yydefault -- do the default action for the current state. |
1305 `-----------------------------------------------------------*/
1306 yydefault:
1307 yyn = yydefact[yystate];
1308 if (yyn == 0)
1309 goto yyerrlab;
1310 goto yyreduce;
1313 /*-----------------------------.
1314 | yyreduce -- Do a reduction. |
1315 `-----------------------------*/
1316 yyreduce:
1317 /* yyn is the number of a rule to reduce with. */
1318 yylen = yyr2[yyn];
1320 /* If YYLEN is nonzero, implement the default value of the action:
1321 `$$ = $1'.
1323 Otherwise, the following line sets YYVAL to garbage.
1324 This behavior is undocumented and Bison
1325 users should not rely upon it. Assigning to YYVAL
1326 unconditionally makes the parser a bit smaller, and it avoids a
1327 GCC warning that YYVAL may be used uninitialized. */
1328 yyval = yyvsp[1-yylen];
1331 YY_REDUCE_PRINT (yyn);
1332 switch (yyn)
1334 case 4:
1335 #line 124 "deffilep.y"
1336 { def_image_name ((yyvsp[-1].id), (yyvsp[0].number), 0); }
1337 break;
1339 case 5:
1340 #line 125 "deffilep.y"
1341 { def_image_name ((yyvsp[-1].id), (yyvsp[0].number), 1); }
1342 break;
1344 case 6:
1345 #line 126 "deffilep.y"
1346 { def_description ((yyvsp[0].id));}
1347 break;
1349 case 7:
1350 #line 127 "deffilep.y"
1351 { def_stacksize ((yyvsp[-1].number), (yyvsp[0].number));}
1352 break;
1354 case 8:
1355 #line 128 "deffilep.y"
1356 { def_heapsize ((yyvsp[-1].number), (yyvsp[0].number));}
1357 break;
1359 case 9:
1360 #line 129 "deffilep.y"
1361 { def_section ("CODE", (yyvsp[0].number));}
1362 break;
1364 case 10:
1365 #line 130 "deffilep.y"
1366 { def_section ("DATA", (yyvsp[0].number));}
1367 break;
1369 case 14:
1370 #line 134 "deffilep.y"
1371 { def_version ((yyvsp[0].number), 0);}
1372 break;
1374 case 15:
1375 #line 135 "deffilep.y"
1376 { def_version ((yyvsp[-2].number), (yyvsp[0].number));}
1377 break;
1379 case 16:
1380 #line 136 "deffilep.y"
1381 { def_directive ((yyvsp[0].id));}
1382 break;
1384 case 20:
1385 #line 151 "deffilep.y"
1386 { def_exports ((yyvsp[-4].id), (yyvsp[-3].id), (yyvsp[-2].number), (yyvsp[0].number)); }
1387 break;
1389 case 21:
1390 #line 157 "deffilep.y"
1391 { (yyval.number) = (yyvsp[-2].number) | (yyvsp[0].number); }
1392 break;
1394 case 22:
1395 #line 158 "deffilep.y"
1396 { (yyval.number) = 0; }
1397 break;
1399 case 23:
1400 #line 161 "deffilep.y"
1401 { (yyval.number) = 1; }
1402 break;
1404 case 24:
1405 #line 162 "deffilep.y"
1406 { (yyval.number) = 1; }
1407 break;
1409 case 25:
1410 #line 163 "deffilep.y"
1411 { (yyval.number) = 2; }
1412 break;
1414 case 26:
1415 #line 164 "deffilep.y"
1416 { (yyval.number) = 2; }
1417 break;
1419 case 27:
1420 #line 165 "deffilep.y"
1421 { (yyval.number) = 4; }
1422 break;
1424 case 28:
1425 #line 166 "deffilep.y"
1426 { (yyval.number) = 4; }
1427 break;
1429 case 29:
1430 #line 167 "deffilep.y"
1431 { (yyval.number) = 8; }
1432 break;
1434 case 30:
1435 #line 168 "deffilep.y"
1436 { (yyval.number) = 8; }
1437 break;
1439 case 33:
1440 #line 176 "deffilep.y"
1441 { def_import ((yyvsp[-6].id), (yyvsp[-4].id), (yyvsp[-2].id), (yyvsp[0].id), -1); }
1442 break;
1444 case 34:
1445 #line 177 "deffilep.y"
1446 { def_import ((yyvsp[-6].id), (yyvsp[-4].id), (yyvsp[-2].id), 0, (yyvsp[0].number)); }
1447 break;
1449 case 35:
1450 #line 178 "deffilep.y"
1451 { def_import ((yyvsp[-4].id), (yyvsp[-2].id), 0, (yyvsp[0].id), -1); }
1452 break;
1454 case 36:
1455 #line 179 "deffilep.y"
1456 { def_import ((yyvsp[-4].id), (yyvsp[-2].id), 0, 0, (yyvsp[0].number)); }
1457 break;
1459 case 37:
1460 #line 180 "deffilep.y"
1461 { def_import ( 0, (yyvsp[-4].id), (yyvsp[-2].id), (yyvsp[0].id), -1); }
1462 break;
1464 case 38:
1465 #line 181 "deffilep.y"
1466 { def_import ( 0, (yyvsp[-2].id), 0, (yyvsp[0].id), -1); }
1467 break;
1469 case 41:
1470 #line 190 "deffilep.y"
1471 { def_section ((yyvsp[-1].id), (yyvsp[0].number));}
1472 break;
1474 case 42:
1475 #line 191 "deffilep.y"
1476 { def_section_alt ((yyvsp[-1].id), (yyvsp[0].id));}
1477 break;
1479 case 43:
1480 #line 195 "deffilep.y"
1481 { (yyval.number) = (yyvsp[-2].number) | (yyvsp[0].number); }
1482 break;
1484 case 44:
1485 #line 196 "deffilep.y"
1486 { (yyval.number) = (yyvsp[0].number); }
1487 break;
1489 case 47:
1490 #line 203 "deffilep.y"
1491 { (yyval.number)=(yyvsp[0].number);}
1492 break;
1494 case 48:
1495 #line 204 "deffilep.y"
1496 { (yyval.number)=-1;}
1497 break;
1499 case 49:
1500 #line 208 "deffilep.y"
1501 { (yyval.number) = 1;}
1502 break;
1504 case 50:
1505 #line 209 "deffilep.y"
1506 { (yyval.number) = 2;}
1507 break;
1509 case 51:
1510 #line 210 "deffilep.y"
1511 { (yyval.number)=4;}
1512 break;
1514 case 52:
1515 #line 211 "deffilep.y"
1516 { (yyval.number)=8;}
1517 break;
1519 case 53:
1520 #line 214 "deffilep.y"
1521 { (yyval.id) = (yyvsp[0].id); }
1522 break;
1524 case 54:
1525 #line 216 "deffilep.y"
1527 char *name = xmalloc (strlen ((yyvsp[-2].id)) + 1 + strlen ((yyvsp[0].id)) + 1);
1528 sprintf (name, "%s.%s", (yyvsp[-2].id), (yyvsp[0].id));
1529 (yyval.id) = name;
1531 break;
1533 case 55:
1534 #line 221 "deffilep.y"
1535 { (yyval.id) = ""; }
1536 break;
1538 case 56:
1539 #line 225 "deffilep.y"
1540 { (yyval.number) = (yyvsp[0].number);}
1541 break;
1543 case 57:
1544 #line 226 "deffilep.y"
1545 { (yyval.number) = -1;}
1546 break;
1548 case 58:
1549 #line 230 "deffilep.y"
1550 { (yyval.id) = (yyvsp[0].id); }
1551 break;
1553 case 59:
1554 #line 231 "deffilep.y"
1555 { (yyval.id) = 0; }
1556 break;
1558 case 60:
1559 #line 234 "deffilep.y"
1560 { (yyval.number) = (yyvsp[0].number);}
1561 break;
1563 case 61:
1564 #line 235 "deffilep.y"
1565 { (yyval.number) = -1;}
1566 break;
1568 case 62:
1569 #line 238 "deffilep.y"
1570 { (yyval.id) = (yyvsp[0].id); }
1571 break;
1573 case 63:
1574 #line 240 "deffilep.y"
1576 char *name = xmalloc (strlen ((yyvsp[-2].id)) + 1 + strlen ((yyvsp[0].id)) + 1);
1577 sprintf (name, "%s.%s", (yyvsp[-2].id), (yyvsp[0].id));
1578 (yyval.id) = name;
1580 break;
1583 default: break;
1586 /* Line 1126 of yacc.c. */
1587 #line 1588 "deffilep.c"
1589 yyvsp -= yylen;
1590 yyssp -= yylen;
1593 YY_STACK_PRINT (yyss, yyssp);
1595 *++yyvsp = yyval;
1598 /* Now `shift' the result of the reduction. Determine what state
1599 that goes to, based on the state we popped back to and the rule
1600 number reduced by. */
1602 yyn = yyr1[yyn];
1604 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1605 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1606 yystate = yytable[yystate];
1607 else
1608 yystate = yydefgoto[yyn - YYNTOKENS];
1610 goto yynewstate;
1613 /*------------------------------------.
1614 | yyerrlab -- here on detecting error |
1615 `------------------------------------*/
1616 yyerrlab:
1617 /* If not already recovering from an error, report this error. */
1618 if (!yyerrstatus)
1620 ++yynerrs;
1621 #if YYERROR_VERBOSE
1622 yyn = yypact[yystate];
1624 if (YYPACT_NINF < yyn && yyn < YYLAST)
1626 int yytype = YYTRANSLATE (yychar);
1627 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1628 YYSIZE_T yysize = yysize0;
1629 YYSIZE_T yysize1;
1630 int yysize_overflow = 0;
1631 char *yymsg = 0;
1632 # define YYERROR_VERBOSE_ARGS_MAXIMUM 5
1633 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1634 int yyx;
1636 #if 0
1637 /* This is so xgettext sees the translatable formats that are
1638 constructed on the fly. */
1639 YY_("syntax error, unexpected %s");
1640 YY_("syntax error, unexpected %s, expecting %s");
1641 YY_("syntax error, unexpected %s, expecting %s or %s");
1642 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1643 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1644 #endif
1645 char *yyfmt;
1646 char const *yyf;
1647 static char const yyunexpected[] = "syntax error, unexpected %s";
1648 static char const yyexpecting[] = ", expecting %s";
1649 static char const yyor[] = " or %s";
1650 char yyformat[sizeof yyunexpected
1651 + sizeof yyexpecting - 1
1652 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1653 * (sizeof yyor - 1))];
1654 char const *yyprefix = yyexpecting;
1656 /* Start YYX at -YYN if negative to avoid negative indexes in
1657 YYCHECK. */
1658 int yyxbegin = yyn < 0 ? -yyn : 0;
1660 /* Stay within bounds of both yycheck and yytname. */
1661 int yychecklim = YYLAST - yyn;
1662 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1663 int yycount = 1;
1665 yyarg[0] = yytname[yytype];
1666 yyfmt = yystpcpy (yyformat, yyunexpected);
1668 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1669 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1671 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1673 yycount = 1;
1674 yysize = yysize0;
1675 yyformat[sizeof yyunexpected - 1] = '\0';
1676 break;
1678 yyarg[yycount++] = yytname[yyx];
1679 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1680 yysize_overflow |= yysize1 < yysize;
1681 yysize = yysize1;
1682 yyfmt = yystpcpy (yyfmt, yyprefix);
1683 yyprefix = yyor;
1686 yyf = YY_(yyformat);
1687 yysize1 = yysize + yystrlen (yyf);
1688 yysize_overflow |= yysize1 < yysize;
1689 yysize = yysize1;
1691 if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM)
1692 yymsg = (char *) YYSTACK_ALLOC (yysize);
1693 if (yymsg)
1695 /* Avoid sprintf, as that infringes on the user's name space.
1696 Don't have undefined behavior even if the translation
1697 produced a string with the wrong number of "%s"s. */
1698 char *yyp = yymsg;
1699 int yyi = 0;
1700 while ((*yyp = *yyf))
1702 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1704 yyp += yytnamerr (yyp, yyarg[yyi++]);
1705 yyf += 2;
1707 else
1709 yyp++;
1710 yyf++;
1713 yyerror (yymsg);
1714 YYSTACK_FREE (yymsg);
1716 else
1718 yyerror (YY_("syntax error"));
1719 goto yyexhaustedlab;
1722 else
1723 #endif /* YYERROR_VERBOSE */
1724 yyerror (YY_("syntax error"));
1729 if (yyerrstatus == 3)
1731 /* If just tried and failed to reuse look-ahead token after an
1732 error, discard it. */
1734 if (yychar <= YYEOF)
1736 /* Return failure if at end of input. */
1737 if (yychar == YYEOF)
1738 YYABORT;
1740 else
1742 yydestruct ("Error: discarding", yytoken, &yylval);
1743 yychar = YYEMPTY;
1747 /* Else will try to reuse look-ahead token after shifting the error
1748 token. */
1749 goto yyerrlab1;
1752 /*---------------------------------------------------.
1753 | yyerrorlab -- error raised explicitly by YYERROR. |
1754 `---------------------------------------------------*/
1755 yyerrorlab:
1757 /* Pacify compilers like GCC when the user code never invokes
1758 YYERROR and the label yyerrorlab therefore never appears in user
1759 code. */
1760 if (0)
1761 goto yyerrorlab;
1763 yyvsp -= yylen;
1764 yyssp -= yylen;
1765 yystate = *yyssp;
1766 goto yyerrlab1;
1769 /*-------------------------------------------------------------.
1770 | yyerrlab1 -- common code for both syntax error and YYERROR. |
1771 `-------------------------------------------------------------*/
1772 yyerrlab1:
1773 yyerrstatus = 3; /* Each real token shifted decrements this. */
1775 for (;;)
1777 yyn = yypact[yystate];
1778 if (yyn != YYPACT_NINF)
1780 yyn += YYTERROR;
1781 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1783 yyn = yytable[yyn];
1784 if (0 < yyn)
1785 break;
1789 /* Pop the current state because it cannot handle the error token. */
1790 if (yyssp == yyss)
1791 YYABORT;
1794 yydestruct ("Error: popping", yystos[yystate], yyvsp);
1795 YYPOPSTACK;
1796 yystate = *yyssp;
1797 YY_STACK_PRINT (yyss, yyssp);
1800 if (yyn == YYFINAL)
1801 YYACCEPT;
1803 *++yyvsp = yylval;
1806 /* Shift the error token. */
1807 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1809 yystate = yyn;
1810 goto yynewstate;
1813 /*-------------------------------------.
1814 | yyacceptlab -- YYACCEPT comes here. |
1815 `-------------------------------------*/
1816 yyacceptlab:
1817 yyresult = 0;
1818 goto yyreturn;
1820 /*-----------------------------------.
1821 | yyabortlab -- YYABORT comes here. |
1822 `-----------------------------------*/
1823 yyabortlab:
1824 yyresult = 1;
1825 goto yyreturn;
1827 #ifndef yyoverflow
1828 /*-------------------------------------------------.
1829 | yyexhaustedlab -- memory exhaustion comes here. |
1830 `-------------------------------------------------*/
1831 yyexhaustedlab:
1832 yyerror (YY_("memory exhausted"));
1833 yyresult = 2;
1834 /* Fall through. */
1835 #endif
1837 yyreturn:
1838 if (yychar != YYEOF && yychar != YYEMPTY)
1839 yydestruct ("Cleanup: discarding lookahead",
1840 yytoken, &yylval);
1841 while (yyssp != yyss)
1843 yydestruct ("Cleanup: popping",
1844 yystos[*yyssp], yyvsp);
1845 YYPOPSTACK;
1847 #ifndef yyoverflow
1848 if (yyss != yyssa)
1849 YYSTACK_FREE (yyss);
1850 #endif
1851 return yyresult;
1855 #line 248 "deffilep.y"
1858 /*****************************************************************************
1860 *****************************************************************************/
1862 static FILE *the_file;
1863 static const char *def_filename;
1864 static int linenumber;
1865 static def_file *def;
1866 static int saw_newline;
1868 struct directive
1870 struct directive *next;
1871 char *name;
1872 int len;
1875 static struct directive *directives = 0;
1877 def_file *
1878 def_file_empty (void)
1880 def_file *rv = xmalloc (sizeof (def_file));
1881 memset (rv, 0, sizeof (def_file));
1882 rv->is_dll = -1;
1883 rv->base_address = (bfd_vma) -1;
1884 rv->stack_reserve = rv->stack_commit = -1;
1885 rv->heap_reserve = rv->heap_commit = -1;
1886 rv->version_major = rv->version_minor = -1;
1887 return rv;
1890 def_file *
1891 def_file_parse (const char *filename, def_file *add_to)
1893 struct directive *d;
1895 the_file = fopen (filename, "r");
1896 def_filename = filename;
1897 linenumber = 1;
1898 if (!the_file)
1900 perror (filename);
1901 return 0;
1903 if (add_to)
1905 def = add_to;
1907 else
1909 def = def_file_empty ();
1912 saw_newline = 1;
1913 if (def_parse ())
1915 def_file_free (def);
1916 fclose (the_file);
1917 return 0;
1920 fclose (the_file);
1922 for (d = directives; d; d = d->next)
1924 #if TRACE
1925 printf ("Adding directive %08x `%s'\n", d->name, d->name);
1926 #endif
1927 def_file_add_directive (def, d->name, d->len);
1930 return def;
1933 void
1934 def_file_free (def_file *def)
1936 int i;
1938 if (!def)
1939 return;
1940 if (def->name)
1941 free (def->name);
1942 if (def->description)
1943 free (def->description);
1945 if (def->section_defs)
1947 for (i = 0; i < def->num_section_defs; i++)
1949 if (def->section_defs[i].name)
1950 free (def->section_defs[i].name);
1951 if (def->section_defs[i].class)
1952 free (def->section_defs[i].class);
1954 free (def->section_defs);
1957 if (def->exports)
1959 for (i = 0; i < def->num_exports; i++)
1961 if (def->exports[i].internal_name
1962 && def->exports[i].internal_name != def->exports[i].name)
1963 free (def->exports[i].internal_name);
1964 if (def->exports[i].name)
1965 free (def->exports[i].name);
1967 free (def->exports);
1970 if (def->imports)
1972 for (i = 0; i < def->num_imports; i++)
1974 if (def->imports[i].internal_name
1975 && def->imports[i].internal_name != def->imports[i].name)
1976 free (def->imports[i].internal_name);
1977 if (def->imports[i].name)
1978 free (def->imports[i].name);
1980 free (def->imports);
1983 while (def->modules)
1985 def_file_module *m = def->modules;
1986 def->modules = def->modules->next;
1987 free (m);
1990 free (def);
1993 #ifdef DEF_FILE_PRINT
1994 void
1995 def_file_print (FILE *file, def_file *def)
1997 int i;
1999 fprintf (file, ">>>> def_file at 0x%08x\n", def);
2000 if (def->name)
2001 fprintf (file, " name: %s\n", def->name ? def->name : "(unspecified)");
2002 if (def->is_dll != -1)
2003 fprintf (file, " is dll: %s\n", def->is_dll ? "yes" : "no");
2004 if (def->base_address != (bfd_vma) -1)
2005 fprintf (file, " base address: 0x%08x\n", def->base_address);
2006 if (def->description)
2007 fprintf (file, " description: `%s'\n", def->description);
2008 if (def->stack_reserve != -1)
2009 fprintf (file, " stack reserve: 0x%08x\n", def->stack_reserve);
2010 if (def->stack_commit != -1)
2011 fprintf (file, " stack commit: 0x%08x\n", def->stack_commit);
2012 if (def->heap_reserve != -1)
2013 fprintf (file, " heap reserve: 0x%08x\n", def->heap_reserve);
2014 if (def->heap_commit != -1)
2015 fprintf (file, " heap commit: 0x%08x\n", def->heap_commit);
2017 if (def->num_section_defs > 0)
2019 fprintf (file, " section defs:\n");
2021 for (i = 0; i < def->num_section_defs; i++)
2023 fprintf (file, " name: `%s', class: `%s', flags:",
2024 def->section_defs[i].name, def->section_defs[i].class);
2025 if (def->section_defs[i].flag_read)
2026 fprintf (file, " R");
2027 if (def->section_defs[i].flag_write)
2028 fprintf (file, " W");
2029 if (def->section_defs[i].flag_execute)
2030 fprintf (file, " X");
2031 if (def->section_defs[i].flag_shared)
2032 fprintf (file, " S");
2033 fprintf (file, "\n");
2037 if (def->num_exports > 0)
2039 fprintf (file, " exports:\n");
2041 for (i = 0; i < def->num_exports; i++)
2043 fprintf (file, " name: `%s', int: `%s', ordinal: %d, flags:",
2044 def->exports[i].name, def->exports[i].internal_name,
2045 def->exports[i].ordinal);
2046 if (def->exports[i].flag_private)
2047 fprintf (file, " P");
2048 if (def->exports[i].flag_constant)
2049 fprintf (file, " C");
2050 if (def->exports[i].flag_noname)
2051 fprintf (file, " N");
2052 if (def->exports[i].flag_data)
2053 fprintf (file, " D");
2054 fprintf (file, "\n");
2058 if (def->num_imports > 0)
2060 fprintf (file, " imports:\n");
2062 for (i = 0; i < def->num_imports; i++)
2064 fprintf (file, " int: %s, from: `%s', name: `%s', ordinal: %d\n",
2065 def->imports[i].internal_name,
2066 def->imports[i].module,
2067 def->imports[i].name,
2068 def->imports[i].ordinal);
2072 if (def->version_major != -1)
2073 fprintf (file, " version: %d.%d\n", def->version_major, def->version_minor);
2075 fprintf (file, "<<<< def_file at 0x%08x\n", def);
2077 #endif
2079 def_file_export *
2080 def_file_add_export (def_file *def,
2081 const char *external_name,
2082 const char *internal_name,
2083 int ordinal)
2085 def_file_export *e;
2086 int max_exports = ROUND_UP(def->num_exports, 32);
2088 if (def->num_exports >= max_exports)
2090 max_exports = ROUND_UP(def->num_exports + 1, 32);
2091 if (def->exports)
2092 def->exports = xrealloc (def->exports,
2093 max_exports * sizeof (def_file_export));
2094 else
2095 def->exports = xmalloc (max_exports * sizeof (def_file_export));
2097 e = def->exports + def->num_exports;
2098 memset (e, 0, sizeof (def_file_export));
2099 if (internal_name && !external_name)
2100 external_name = internal_name;
2101 if (external_name && !internal_name)
2102 internal_name = external_name;
2103 e->name = xstrdup (external_name);
2104 e->internal_name = xstrdup (internal_name);
2105 e->ordinal = ordinal;
2106 def->num_exports++;
2107 return e;
2110 def_file_module *
2111 def_get_module (def_file *def, const char *name)
2113 def_file_module *s;
2115 for (s = def->modules; s; s = s->next)
2116 if (strcmp (s->name, name) == 0)
2117 return s;
2119 return NULL;
2122 static def_file_module *
2123 def_stash_module (def_file *def, const char *name)
2125 def_file_module *s;
2127 if ((s = def_get_module (def, name)) != NULL)
2128 return s;
2129 s = xmalloc (sizeof (def_file_module) + strlen (name));
2130 s->next = def->modules;
2131 def->modules = s;
2132 s->user_data = 0;
2133 strcpy (s->name, name);
2134 return s;
2137 def_file_import *
2138 def_file_add_import (def_file *def,
2139 const char *name,
2140 const char *module,
2141 int ordinal,
2142 const char *internal_name)
2144 def_file_import *i;
2145 int max_imports = ROUND_UP (def->num_imports, 16);
2147 if (def->num_imports >= max_imports)
2149 max_imports = ROUND_UP (def->num_imports+1, 16);
2151 if (def->imports)
2152 def->imports = xrealloc (def->imports,
2153 max_imports * sizeof (def_file_import));
2154 else
2155 def->imports = xmalloc (max_imports * sizeof (def_file_import));
2157 i = def->imports + def->num_imports;
2158 memset (i, 0, sizeof (def_file_import));
2159 if (name)
2160 i->name = xstrdup (name);
2161 if (module)
2162 i->module = def_stash_module (def, module);
2163 i->ordinal = ordinal;
2164 if (internal_name)
2165 i->internal_name = xstrdup (internal_name);
2166 else
2167 i->internal_name = i->name;
2168 def->num_imports++;
2170 return i;
2173 struct
2175 char *param;
2176 int token;
2178 diropts[] =
2180 { "-heap", HEAPSIZE },
2181 { "-stack", STACKSIZE },
2182 { "-attr", SECTIONS },
2183 { "-export", EXPORTS },
2184 { 0, 0 }
2187 void
2188 def_file_add_directive (def_file *my_def, const char *param, int len)
2190 def_file *save_def = def;
2191 const char *pend = param + len;
2192 char * tend = (char *) param;
2193 int i;
2195 def = my_def;
2197 while (param < pend)
2199 while (param < pend
2200 && (ISSPACE (*param) || *param == '\n' || *param == 0))
2201 param++;
2203 if (param == pend)
2204 break;
2206 /* Scan forward until we encounter any of:
2207 - the end of the buffer
2208 - the start of a new option
2209 - a newline seperating options
2210 - a NUL seperating options. */
2211 for (tend = (char *) (param + 1);
2212 (tend < pend
2213 && !(ISSPACE (tend[-1]) && *tend == '-')
2214 && *tend != '\n' && *tend != 0);
2215 tend++)
2218 for (i = 0; diropts[i].param; i++)
2220 int len = strlen (diropts[i].param);
2222 if (tend - param >= len
2223 && strncmp (param, diropts[i].param, len) == 0
2224 && (param[len] == ':' || param[len] == ' '))
2226 lex_parse_string_end = tend;
2227 lex_parse_string = param + len + 1;
2228 lex_forced_token = diropts[i].token;
2229 saw_newline = 0;
2230 if (def_parse ())
2231 continue;
2232 break;
2236 if (!diropts[i].param)
2238 char saved;
2240 saved = * tend;
2241 * tend = 0;
2242 /* xgettext:c-format */
2243 einfo (_("Warning: .drectve `%s' unrecognized\n"), param);
2244 * tend = saved;
2247 lex_parse_string = 0;
2248 param = tend;
2251 def = save_def;
2254 /* Parser Callbacks. */
2256 static void
2257 def_image_name (const char *name, int base, int is_dll)
2259 /* If a LIBRARY or NAME statement is specified without a name, there is nothing
2260 to do here. We retain the output filename specified on command line. */
2261 if (*name)
2263 const char* image_name = lbasename (name);
2264 if (image_name != name)
2265 einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
2266 def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
2267 name);
2268 if (def->name)
2269 free (def->name);
2270 /* Append the default suffix, if none specified. */
2271 if (strchr (image_name, '.') == 0)
2273 const char * suffix = is_dll ? ".dll" : ".exe";
2275 def->name = xmalloc (strlen (image_name) + strlen (suffix) + 1);
2276 sprintf (def->name, "%s%s", image_name, suffix);
2278 else
2279 def->name = xstrdup (image_name);
2282 /* Honor a BASE address statement, even if LIBRARY string is empty. */
2283 def->base_address = base;
2284 def->is_dll = is_dll;
2287 static void
2288 def_description (const char *text)
2290 int len = def->description ? strlen (def->description) : 0;
2292 len += strlen (text) + 1;
2293 if (def->description)
2295 def->description = xrealloc (def->description, len);
2296 strcat (def->description, text);
2298 else
2300 def->description = xmalloc (len);
2301 strcpy (def->description, text);
2305 static void
2306 def_stacksize (int reserve, int commit)
2308 def->stack_reserve = reserve;
2309 def->stack_commit = commit;
2312 static void
2313 def_heapsize (int reserve, int commit)
2315 def->heap_reserve = reserve;
2316 def->heap_commit = commit;
2319 static void
2320 def_section (const char *name, int attr)
2322 def_file_section *s;
2323 int max_sections = ROUND_UP (def->num_section_defs, 4);
2325 if (def->num_section_defs >= max_sections)
2327 max_sections = ROUND_UP (def->num_section_defs+1, 4);
2329 if (def->section_defs)
2330 def->section_defs = xrealloc (def->section_defs,
2331 max_sections * sizeof (def_file_import));
2332 else
2333 def->section_defs = xmalloc (max_sections * sizeof (def_file_import));
2335 s = def->section_defs + def->num_section_defs;
2336 memset (s, 0, sizeof (def_file_section));
2337 s->name = xstrdup (name);
2338 if (attr & 1)
2339 s->flag_read = 1;
2340 if (attr & 2)
2341 s->flag_write = 1;
2342 if (attr & 4)
2343 s->flag_execute = 1;
2344 if (attr & 8)
2345 s->flag_shared = 1;
2347 def->num_section_defs++;
2350 static void
2351 def_section_alt (const char *name, const char *attr)
2353 int aval = 0;
2355 for (; *attr; attr++)
2357 switch (*attr)
2359 case 'R':
2360 case 'r':
2361 aval |= 1;
2362 break;
2363 case 'W':
2364 case 'w':
2365 aval |= 2;
2366 break;
2367 case 'X':
2368 case 'x':
2369 aval |= 4;
2370 break;
2371 case 'S':
2372 case 's':
2373 aval |= 8;
2374 break;
2377 def_section (name, aval);
2380 static void
2381 def_exports (const char *external_name,
2382 const char *internal_name,
2383 int ordinal,
2384 int flags)
2386 def_file_export *dfe;
2388 if (!internal_name && external_name)
2389 internal_name = external_name;
2390 #if TRACE
2391 printf ("def_exports, ext=%s int=%s\n", external_name, internal_name);
2392 #endif
2394 dfe = def_file_add_export (def, external_name, internal_name, ordinal);
2395 if (flags & 1)
2396 dfe->flag_noname = 1;
2397 if (flags & 2)
2398 dfe->flag_constant = 1;
2399 if (flags & 4)
2400 dfe->flag_data = 1;
2401 if (flags & 8)
2402 dfe->flag_private = 1;
2405 static void
2406 def_import (const char *internal_name,
2407 const char *module,
2408 const char *dllext,
2409 const char *name,
2410 int ordinal)
2412 char *buf = 0;
2413 const char *ext = dllext ? dllext : "dll";
2415 buf = xmalloc (strlen (module) + strlen (ext) + 2);
2416 sprintf (buf, "%s.%s", module, ext);
2417 module = buf;
2419 def_file_add_import (def, name, module, ordinal, internal_name);
2420 if (buf)
2421 free (buf);
2424 static void
2425 def_version (int major, int minor)
2427 def->version_major = major;
2428 def->version_minor = minor;
2431 static void
2432 def_directive (char *str)
2434 struct directive *d = xmalloc (sizeof (struct directive));
2436 d->next = directives;
2437 directives = d;
2438 d->name = xstrdup (str);
2439 d->len = strlen (str);
2442 static int
2443 def_error (const char *err)
2445 einfo ("%P: %s:%d: %s\n",
2446 def_filename ? def_filename : "<unknown-file>", linenumber, err);
2447 return 0;
2451 /* Lexical Scanner. */
2453 #undef TRACE
2454 #define TRACE 0
2456 /* Never freed, but always reused as needed, so no real leak. */
2457 static char *buffer = 0;
2458 static int buflen = 0;
2459 static int bufptr = 0;
2461 static void
2462 put_buf (char c)
2464 if (bufptr == buflen)
2466 buflen += 50; /* overly reasonable, eh? */
2467 if (buffer)
2468 buffer = xrealloc (buffer, buflen + 1);
2469 else
2470 buffer = xmalloc (buflen + 1);
2472 buffer[bufptr++] = c;
2473 buffer[bufptr] = 0; /* not optimal, but very convenient. */
2476 static struct
2478 char *name;
2479 int token;
2481 tokens[] =
2483 { "BASE", BASE },
2484 { "CODE", CODE },
2485 { "CONSTANT", CONSTANTU },
2486 { "constant", CONSTANTL },
2487 { "DATA", DATAU },
2488 { "data", DATAL },
2489 { "DESCRIPTION", DESCRIPTION },
2490 { "DIRECTIVE", DIRECTIVE },
2491 { "EXECUTE", EXECUTE },
2492 { "EXPORTS", EXPORTS },
2493 { "HEAPSIZE", HEAPSIZE },
2494 { "IMPORTS", IMPORTS },
2495 { "LIBRARY", LIBRARY },
2496 { "NAME", NAME },
2497 { "NONAME", NONAMEU },
2498 { "noname", NONAMEL },
2499 { "PRIVATE", PRIVATEU },
2500 { "private", PRIVATEL },
2501 { "READ", READ },
2502 { "SECTIONS", SECTIONS },
2503 { "SEGMENTS", SECTIONS },
2504 { "SHARED", SHARED },
2505 { "STACKSIZE", STACKSIZE },
2506 { "VERSION", VERSIONK },
2507 { "WRITE", WRITE },
2508 { 0, 0 }
2511 static int
2512 def_getc (void)
2514 int rv;
2516 if (lex_parse_string)
2518 if (lex_parse_string >= lex_parse_string_end)
2519 rv = EOF;
2520 else
2521 rv = *lex_parse_string++;
2523 else
2525 rv = fgetc (the_file);
2527 if (rv == '\n')
2528 saw_newline = 1;
2529 return rv;
2532 static int
2533 def_ungetc (int c)
2535 if (lex_parse_string)
2537 lex_parse_string--;
2538 return c;
2540 else
2541 return ungetc (c, the_file);
2544 static int
2545 def_lex (void)
2547 int c, i, q;
2549 if (lex_forced_token)
2551 i = lex_forced_token;
2552 lex_forced_token = 0;
2553 #if TRACE
2554 printf ("lex: forcing token %d\n", i);
2555 #endif
2556 return i;
2559 c = def_getc ();
2561 /* Trim leading whitespace. */
2562 while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
2563 c = def_getc ();
2565 if (c == EOF)
2567 #if TRACE
2568 printf ("lex: EOF\n");
2569 #endif
2570 return 0;
2573 if (saw_newline && c == ';')
2577 c = def_getc ();
2579 while (c != EOF && c != '\n');
2580 if (c == '\n')
2581 return def_lex ();
2582 return 0;
2585 /* Must be something else. */
2586 saw_newline = 0;
2588 if (ISDIGIT (c))
2590 bufptr = 0;
2591 while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
2593 put_buf (c);
2594 c = def_getc ();
2596 if (c != EOF)
2597 def_ungetc (c);
2598 yylval.number = strtoul (buffer, 0, 0);
2599 #if TRACE
2600 printf ("lex: `%s' returns NUMBER %d\n", buffer, yylval.number);
2601 #endif
2602 return NUMBER;
2605 if (ISALPHA (c) || strchr ("$:-_?@", c))
2607 bufptr = 0;
2608 q = c;
2609 put_buf (c);
2610 c = def_getc ();
2612 if (q == '@')
2614 if (ISBLANK (c) ) /* '@' followed by whitespace. */
2615 return (q);
2616 else if (ISDIGIT (c)) /* '@' followed by digit. */
2618 def_ungetc (c);
2619 return (q);
2621 #if TRACE
2622 printf ("lex: @ returns itself\n");
2623 #endif
2626 while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@", c)))
2628 put_buf (c);
2629 c = def_getc ();
2631 if (c != EOF)
2632 def_ungetc (c);
2633 if (ISALPHA (q)) /* Check for tokens. */
2635 for (i = 0; tokens[i].name; i++)
2636 if (strcmp (tokens[i].name, buffer) == 0)
2638 #if TRACE
2639 printf ("lex: `%s' is a string token\n", buffer);
2640 #endif
2641 return tokens[i].token;
2644 #if TRACE
2645 printf ("lex: `%s' returns ID\n", buffer);
2646 #endif
2647 yylval.id = xstrdup (buffer);
2648 return ID;
2651 if (c == '\'' || c == '"')
2653 q = c;
2654 c = def_getc ();
2655 bufptr = 0;
2657 while (c != EOF && c != q)
2659 put_buf (c);
2660 c = def_getc ();
2662 yylval.id = xstrdup (buffer);
2663 #if TRACE
2664 printf ("lex: `%s' returns ID\n", buffer);
2665 #endif
2666 return ID;
2669 if (c == '=' || c == '.' || c == ',')
2671 #if TRACE
2672 printf ("lex: `%c' returns itself\n", c);
2673 #endif
2674 return c;
2677 if (c == '\n')
2679 linenumber++;
2680 saw_newline = 1;
2683 /*printf ("lex: 0x%02x ignored\n", c); */
2684 return def_lex ();