Subversion Repositories Kolibri OS

Rev

Rev 5221 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5199 serge 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
     NAME = 258,
70
     LIBRARY = 259,
71
     DESCRIPTION = 260,
72
     STACKSIZE_K = 261,
73
     HEAPSIZE = 262,
74
     CODE = 263,
75
     DATAU = 264,
76
     DATAL = 265,
77
     SECTIONS = 266,
78
     EXPORTS = 267,
79
     IMPORTS = 268,
80
     VERSIONK = 269,
81
     BASE = 270,
82
     CONSTANTU = 271,
83
     CONSTANTL = 272,
84
     PRIVATEU = 273,
85
     PRIVATEL = 274,
86
     ALIGNCOMM = 275,
87
     READ = 276,
88
     WRITE = 277,
89
     EXECUTE = 278,
90
     SHARED = 279,
91
     NONAMEU = 280,
92
     NONAMEL = 281,
93
     DIRECTIVE = 282,
94
     EQUAL = 283,
95
     ID = 284,
96
     DIGITS = 285
97
   };
98
#endif
99
/* Tokens.  */
100
#define NAME 258
101
#define LIBRARY 259
102
#define DESCRIPTION 260
103
#define STACKSIZE_K 261
104
#define HEAPSIZE 262
105
#define CODE 263
106
#define DATAU 264
107
#define DATAL 265
108
#define SECTIONS 266
109
#define EXPORTS 267
110
#define IMPORTS 268
111
#define VERSIONK 269
112
#define BASE 270
113
#define CONSTANTU 271
114
#define CONSTANTL 272
115
#define PRIVATEU 273
116
#define PRIVATEL 274
117
#define ALIGNCOMM 275
118
#define READ 276
119
#define WRITE 277
120
#define EXECUTE 278
121
#define SHARED 279
122
#define NONAMEU 280
123
#define NONAMEL 281
124
#define DIRECTIVE 282
125
#define EQUAL 283
126
#define ID 284
127
#define DIGITS 285
128
 
129
 
130
 
131
 
132
/* Copy the first part of user declarations.  */
133
#line 1 "deffilep.y"
134
 /* deffilep.y - parser for .def files */
135
 
136
/*   Copyright 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006,
137
     2007, 2009 Free Software Foundation, Inc.
138
 
139
     This file is part of GNU Binutils.
140
 
141
     This program is free software; you can redistribute it and/or modify
142
     it under the terms of the GNU General Public License as published by
143
     the Free Software Foundation; either version 3 of the License, or
144
     (at your option) any later version.
145
 
146
     This program is distributed in the hope that it will be useful,
147
     but WITHOUT ANY WARRANTY; without even the implied warranty of
148
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
149
     GNU General Public License for more details.
150
 
151
     You should have received a copy of the GNU General Public License
152
     along with this program; if not, write to the Free Software
153
     Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
154
     MA 02110-1301, USA.  */
155
 
156
#include "sysdep.h"
157
#include "libiberty.h"
158
#include "safe-ctype.h"
159
#include "bfd.h"
160
#include "ld.h"
161
#include "ldmisc.h"
162
#include "deffile.h"
163
 
164
#define TRACE 0
165
 
166
#define ROUND_UP(a, b) (((a)+((b)-1))&~((b)-1))
167
 
168
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
169
   as well as gratuitiously global symbol names, so we can have multiple
170
   yacc generated parsers in ld.  Note that these are only the variables
171
   produced by yacc.  If other parser generators (bison, byacc, etc) produce
172
   additional global names that conflict at link time, then those parser
173
   generators need to be fixed instead of adding those names to this list.  */
174
 
175
#define	yymaxdepth def_maxdepth
176
#define	yyparse	def_parse
177
#define	yylex	def_lex
178
#define	yyerror	def_error
179
#define	yylval	def_lval
180
#define	yychar	def_char
181
#define	yydebug	def_debug
182
#define	yypact	def_pact
183
#define	yyr1	def_r1
184
#define	yyr2	def_r2
185
#define	yydef	def_def
186
#define	yychk	def_chk
187
#define	yypgo	def_pgo
188
#define	yyact	def_act
189
#define	yyexca	def_exca
190
#define yyerrflag def_errflag
191
#define yynerrs	def_nerrs
192
#define	yyps	def_ps
193
#define	yypv	def_pv
194
#define	yys	def_s
195
#define	yy_yys	def_yys
196
#define	yystate	def_state
197
#define	yytmp	def_tmp
198
#define	yyv	def_v
199
#define	yy_yyv	def_yyv
200
#define	yyval	def_val
201
#define	yylloc	def_lloc
202
#define yyreds	def_reds		/* With YYDEBUG defined.  */
203
#define yytoks	def_toks		/* With YYDEBUG defined.  */
204
#define yylhs	def_yylhs
205
#define yylen	def_yylen
206
#define yydefred def_yydefred
207
#define yydgoto	def_yydgoto
208
#define yysindex def_yysindex
209
#define yyrindex def_yyrindex
210
#define yygindex def_yygindex
211
#define yytable	 def_yytable
212
#define yycheck	 def_yycheck
213
 
214
typedef struct def_pool_str {
215
  struct def_pool_str *next;
216
  char data[1];
217
} def_pool_str;
218
 
219
static def_pool_str *pool_strs = NULL;
220
 
221
static char *def_pool_alloc (size_t sz);
222
static char *def_pool_strdup (const char *str);
223
static void def_pool_free (void);
224
 
225
static void def_description (const char *);
226
static void def_exports (const char *, const char *, int, int, const char *);
227
static void def_heapsize (int, int);
228
static void def_import (const char *, const char *, const char *, const char *,
229
			int, const char *);
230
static void def_image_name (const char *, bfd_vma, int);
231
static void def_section (const char *, int);
232
static void def_section_alt (const char *, const char *);
233
static void def_stacksize (int, int);
234
static void def_version (int, int);
235
static void def_directive (char *);
236
static void def_aligncomm (char *str, int align);
237
static int def_parse (void);
238
static int def_error (const char *);
239
static int def_lex (void);
240
 
241
static int lex_forced_token = 0;
242
static const char *lex_parse_string = 0;
243
static const char *lex_parse_string_end = 0;
244
 
245
 
246
 
247
/* Enabling traces.  */
248
#ifndef YYDEBUG
249
# define YYDEBUG 0
250
#endif
251
 
252
/* Enabling verbose error messages.  */
253
#ifdef YYERROR_VERBOSE
254
# undef YYERROR_VERBOSE
255
# define YYERROR_VERBOSE 1
256
#else
257
# define YYERROR_VERBOSE 0
258
#endif
259
 
260
/* Enabling the token table.  */
261
#ifndef YYTOKEN_TABLE
262
# define YYTOKEN_TABLE 0
263
#endif
264
 
265
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
266
typedef union YYSTYPE
267
#line 114 "deffilep.y"
268
{
269
  char *id;
270
  const char *id_const;
271
  int number;
272
  bfd_vma vma;
273
  char *digits;
274
}
275
/* Line 193 of yacc.c.  */
276
#line 277 "deffilep.c"
277
	YYSTYPE;
278
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
279
# define YYSTYPE_IS_DECLARED 1
280
# define YYSTYPE_IS_TRIVIAL 1
281
#endif
282
 
283
 
284
 
285
/* Copy the second part of user declarations.  */
286
 
287
 
288
/* Line 216 of yacc.c.  */
289
#line 290 "deffilep.c"
290
 
291
#ifdef short
292
# undef short
293
#endif
294
 
295
#ifdef YYTYPE_UINT8
296
typedef YYTYPE_UINT8 yytype_uint8;
297
#else
298
typedef unsigned char yytype_uint8;
299
#endif
300
 
301
#ifdef YYTYPE_INT8
302
typedef YYTYPE_INT8 yytype_int8;
303
#elif (defined __STDC__ || defined __C99__FUNC__ \
304
     || defined __cplusplus || defined _MSC_VER)
305
typedef signed char yytype_int8;
306
#else
307
typedef short int yytype_int8;
308
#endif
309
 
310
#ifdef YYTYPE_UINT16
311
typedef YYTYPE_UINT16 yytype_uint16;
312
#else
313
typedef unsigned short int yytype_uint16;
314
#endif
315
 
316
#ifdef YYTYPE_INT16
317
typedef YYTYPE_INT16 yytype_int16;
318
#else
319
typedef short int yytype_int16;
320
#endif
321
 
322
#ifndef YYSIZE_T
323
# ifdef __SIZE_TYPE__
324
#  define YYSIZE_T __SIZE_TYPE__
325
# elif defined size_t
326
#  define YYSIZE_T size_t
327
# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
328
     || defined __cplusplus || defined _MSC_VER)
329
#  include  /* INFRINGES ON USER NAME SPACE */
330
#  define YYSIZE_T size_t
331
# else
332
#  define YYSIZE_T unsigned int
333
# endif
334
#endif
335
 
336
#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
337
 
338
#ifndef YY_
339
# if defined YYENABLE_NLS && YYENABLE_NLS
340
#  if ENABLE_NLS
341
#   include  /* INFRINGES ON USER NAME SPACE */
342
#   define YY_(msgid) dgettext ("bison-runtime", msgid)
343
#  endif
344
# endif
345
# ifndef YY_
346
#  define YY_(msgid) msgid
347
# endif
348
#endif
349
 
350
/* Suppress unused-variable warnings by "using" E.  */
351
#if ! defined lint || defined __GNUC__
352
# define YYUSE(e) ((void) (e))
353
#else
354
# define YYUSE(e) /* empty */
355
#endif
356
 
357
/* Identity function, used to suppress warnings about constant conditions.  */
358
#ifndef lint
359
# define YYID(n) (n)
360
#else
361
#if (defined __STDC__ || defined __C99__FUNC__ \
362
     || defined __cplusplus || defined _MSC_VER)
363
static int
364
YYID (int i)
365
#else
366
static int
367
YYID (i)
368
    int i;
369
#endif
370
{
371
  return i;
372
}
373
#endif
374
 
375
#if ! defined yyoverflow || YYERROR_VERBOSE
376
 
377
/* The parser invokes alloca or malloc; define the necessary symbols.  */
378
 
379
# ifdef YYSTACK_USE_ALLOCA
380
#  if YYSTACK_USE_ALLOCA
381
#   ifdef __GNUC__
382
#    define YYSTACK_ALLOC __builtin_alloca
383
#   elif defined __BUILTIN_VA_ARG_INCR
384
#    include  /* INFRINGES ON USER NAME SPACE */
385
#   elif defined _AIX
386
#    define YYSTACK_ALLOC __alloca
387
#   elif defined _MSC_VER
388
#    include  /* INFRINGES ON USER NAME SPACE */
389
#    define alloca _alloca
390
#   else
391
#    define YYSTACK_ALLOC alloca
392
#    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
393
     || defined __cplusplus || defined _MSC_VER)
394
#     include  /* INFRINGES ON USER NAME SPACE */
395
#     ifndef _STDLIB_H
396
#      define _STDLIB_H 1
397
#     endif
398
#    endif
399
#   endif
400
#  endif
401
# endif
402
 
403
# ifdef YYSTACK_ALLOC
404
   /* Pacify GCC's `empty if-body' warning.  */
405
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
406
#  ifndef YYSTACK_ALLOC_MAXIMUM
407
    /* The OS might guarantee only one guard page at the bottom of the stack,
408
       and a page size can be as small as 4096 bytes.  So we cannot safely
409
       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
410
       to allow for a few compiler-allocated temporary stack slots.  */
411
#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
412
#  endif
413
# else
414
#  define YYSTACK_ALLOC YYMALLOC
415
#  define YYSTACK_FREE YYFREE
416
#  ifndef YYSTACK_ALLOC_MAXIMUM
417
#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
418
#  endif
419
#  if (defined __cplusplus && ! defined _STDLIB_H \
420
       && ! ((defined YYMALLOC || defined malloc) \
421
	     && (defined YYFREE || defined free)))
422
#   include  /* INFRINGES ON USER NAME SPACE */
423
#   ifndef _STDLIB_H
424
#    define _STDLIB_H 1
425
#   endif
426
#  endif
427
#  ifndef YYMALLOC
428
#   define YYMALLOC malloc
429
#   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
430
     || defined __cplusplus || defined _MSC_VER)
431
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
432
#   endif
433
#  endif
434
#  ifndef YYFREE
435
#   define YYFREE free
436
#   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
437
     || defined __cplusplus || defined _MSC_VER)
438
void free (void *); /* INFRINGES ON USER NAME SPACE */
439
#   endif
440
#  endif
441
# endif
442
#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
443
 
444
 
445
#if (! defined yyoverflow \
446
     && (! defined __cplusplus \
447
	 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
448
 
449
/* A type that is properly aligned for any stack member.  */
450
union yyalloc
451
{
452
  yytype_int16 yyss;
453
  YYSTYPE yyvs;
454
  };
455
 
456
/* The size of the maximum gap between one aligned stack and the next.  */
457
# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
458
 
459
/* The size of an array large to enough to hold all stacks, each with
460
   N elements.  */
461
# define YYSTACK_BYTES(N) \
462
     ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
463
      + YYSTACK_GAP_MAXIMUM)
464
 
465
/* Copy COUNT objects from FROM to TO.  The source and destination do
466
   not overlap.  */
467
# ifndef YYCOPY
468
#  if defined __GNUC__ && 1 < __GNUC__
469
#   define YYCOPY(To, From, Count) \
470
      __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
471
#  else
472
#   define YYCOPY(To, From, Count)		\
473
      do					\
474
	{					\
475
	  YYSIZE_T yyi;				\
476
	  for (yyi = 0; yyi < (Count); yyi++)	\
477
	    (To)[yyi] = (From)[yyi];		\
478
	}					\
479
      while (YYID (0))
480
#  endif
481
# endif
482
 
483
/* Relocate STACK from its old location to the new one.  The
484
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
485
   elements in the stack, and YYPTR gives the new location of the
486
   stack.  Advance YYPTR to a properly aligned location for the next
487
   stack.  */
488
# define YYSTACK_RELOCATE(Stack)					\
489
    do									\
490
      {									\
491
	YYSIZE_T yynewbytes;						\
492
	YYCOPY (&yyptr->Stack, Stack, yysize);				\
493
	Stack = &yyptr->Stack;						\
494
	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
495
	yyptr += yynewbytes / sizeof (*yyptr);				\
496
      }									\
497
    while (YYID (0))
498
 
499
#endif
500
 
501
/* YYFINAL -- State number of the termination state.  */
502
#define YYFINAL  69
503
/* YYLAST -- Last index in YYTABLE.  */
504
#define YYLAST   149
505
 
506
/* YYNTOKENS -- Number of terminals.  */
507
#define YYNTOKENS  35
508
/* YYNNTS -- Number of nonterminals.  */
509
#define YYNNTS  27
510
/* YYNRULES -- Number of rules.  */
511
#define YYNRULES  99
512
/* YYNRULES -- Number of states.  */
513
#define YYNSTATES  146
514
 
515
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
516
#define YYUNDEFTOK  2
517
#define YYMAXUTOK   285
518
 
519
#define YYTRANSLATE(YYX)						\
520
  ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
521
 
522
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
523
static const yytype_uint8 yytranslate[] =
524
{
525
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
526
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
527
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
528
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
529
       2,     2,     2,     2,    32,     2,    31,     2,     2,     2,
530
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
531
       2,    33,     2,     2,    34,     2,     2,     2,     2,     2,
532
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
533
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
534
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
535
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
536
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
537
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
538
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
539
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
540
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
541
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
542
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
543
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
544
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
545
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
546
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
547
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
548
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
549
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
550
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
551
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
552
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
553
      25,    26,    27,    28,    29,    30
554
};
555
 
556
#if YYDEBUG
557
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
558
   YYRHS.  */
559
static const yytype_uint16 yyprhs[] =
560
{
561
       0,     0,     3,     6,     8,    12,    16,    19,    23,    27,
562
      30,    33,    36,    39,    42,    45,    50,    53,    58,    59,
563
      61,    64,    72,    76,    77,    79,    81,    83,    85,    87,
564
      89,    91,    93,    96,    98,   107,   116,   123,   130,   137,
565
     142,   145,   147,   150,   153,   157,   159,   161,   162,   165,
566
     166,   168,   170,   172,   174,   176,   178,   180,   182,   184,
567
     186,   188,   190,   192,   194,   196,   198,   200,   202,   204,
568
     206,   208,   210,   212,   214,   216,   218,   220,   223,   226,
569
     230,   234,   236,   237,   240,   241,   244,   245,   248,   249,
570
     253,   254,   256,   259,   264,   266,   267,   269,   270,   272
571
};
572
 
573
/* YYRHS -- A `-1'-separated list of the rules' RHS.  */
574
static const yytype_int8 yyrhs[] =
575
{
576
      36,     0,    -1,    36,    37,    -1,    37,    -1,     3,    52,
577
      56,    -1,     4,    52,    56,    -1,     5,    29,    -1,     6,
578
      60,    48,    -1,     7,    60,    48,    -1,     8,    46,    -1,
579
       9,    46,    -1,    11,    44,    -1,    12,    38,    -1,    13,
580
      42,    -1,    14,    60,    -1,    14,    60,    31,    60,    -1,
581
      27,    29,    -1,    20,    57,    32,    60,    -1,    -1,    39,
582
      -1,    38,    39,    -1,    51,    55,    54,    47,    40,    47,
583
      53,    -1,    41,    47,    40,    -1,    -1,    25,    -1,    26,
584
      -1,    16,    -1,    17,    -1,     9,    -1,    10,    -1,    18,
585
      -1,    19,    -1,    42,    43,    -1,    43,    -1,    29,    33,
586
      29,    31,    29,    31,    29,    53,    -1,    29,    33,    29,
587
      31,    29,    31,    60,    53,    -1,    29,    33,    29,    31,
588
      29,    53,    -1,    29,    33,    29,    31,    60,    53,    -1,
589
      29,    31,    29,    31,    29,    53,    -1,    29,    31,    29,
590
      53,    -1,    44,    45,    -1,    45,    -1,    29,    46,    -1,
591
      29,    29,    -1,    46,    47,    49,    -1,    49,    -1,    32,
592
      -1,    -1,    32,    60,    -1,    -1,    21,    -1,    22,    -1,
593
      23,    -1,    24,    -1,    15,    -1,     8,    -1,    16,    -1,
594
      17,    -1,     9,    -1,    10,    -1,     5,    -1,    27,    -1,
595
      23,    -1,    12,    -1,     7,    -1,    13,    -1,     3,    -1,
596
      25,    -1,    26,    -1,    18,    -1,    19,    -1,    21,    -1,
597
      24,    -1,     6,    -1,    14,    -1,    22,    -1,    29,    -1,
598
      31,    50,    -1,    31,    51,    -1,    50,    31,    51,    -1,
599
      29,    31,    51,    -1,    51,    -1,    -1,    28,    29,    -1,
600
      -1,    34,    60,    -1,    -1,    33,    51,    -1,    -1,    15,
601
      33,    61,    -1,    -1,    29,    -1,    31,    29,    -1,    57,
602
      31,    58,    59,    -1,    30,    -1,    -1,    29,    -1,    -1,
603
      30,    -1,    30,    -1
604
};
605
 
606
/* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
607
static const yytype_uint16 yyrline[] =
608
{
609
       0,   139,   139,   140,   144,   145,   146,   147,   148,   149,
610
     150,   151,   152,   153,   154,   155,   156,   157,   161,   163,
611
     164,   171,   178,   179,   182,   183,   184,   185,   186,   187,
612
     188,   189,   192,   193,   197,   199,   201,   203,   205,   207,
613
     212,   213,   217,   218,   222,   223,   227,   228,   230,   231,
614
     235,   236,   237,   238,   242,   243,   244,   245,   246,   247,
615
     248,   249,   250,   251,   252,   253,   260,   261,   262,   263,
616
     264,   265,   266,   267,   268,   269,   272,   273,   279,   285,
617
     291,   299,   300,   303,   304,   308,   309,   313,   314,   317,
618
     318,   321,   322,   328,   336,   337,   340,   341,   344,   346
619
};
620
#endif
621
 
622
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
623
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
624
   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
625
static const char *const yytname[] =
626
{
627
  "$end", "error", "$undefined", "NAME", "LIBRARY", "DESCRIPTION",
628
  "STACKSIZE_K", "HEAPSIZE", "CODE", "DATAU", "DATAL", "SECTIONS",
629
  "EXPORTS", "IMPORTS", "VERSIONK", "BASE", "CONSTANTU", "CONSTANTL",
630
  "PRIVATEU", "PRIVATEL", "ALIGNCOMM", "READ", "WRITE", "EXECUTE",
631
  "SHARED", "NONAMEU", "NONAMEL", "DIRECTIVE", "EQUAL", "ID", "DIGITS",
632
  "'.'", "','", "'='", "'@'", "$accept", "start", "command", "explist",
633
  "expline", "exp_opt_list", "exp_opt", "implist", "impline", "seclist",
634
  "secline", "attr_list", "opt_comma", "opt_number", "attr",
635
  "keyword_as_name", "opt_name2", "opt_name", "opt_equalequal_name",
636
  "opt_ordinal", "opt_equal_name", "opt_base", "anylang_id", "opt_digits",
637
  "opt_id", "NUMBER", "VMA", 0
638
};
639
#endif
640
 
641
# ifdef YYPRINT
642
/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
643
   token YYLEX-NUM.  */
644
static const yytype_uint16 yytoknum[] =
645
{
646
       0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
647
     265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
648
     275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
649
     285,    46,    44,    61,    64
650
};
651
# endif
652
 
653
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
654
static const yytype_uint8 yyr1[] =
655
{
656
       0,    35,    36,    36,    37,    37,    37,    37,    37,    37,
657
      37,    37,    37,    37,    37,    37,    37,    37,    38,    38,
658
      38,    39,    40,    40,    41,    41,    41,    41,    41,    41,
659
      41,    41,    42,    42,    43,    43,    43,    43,    43,    43,
660
      44,    44,    45,    45,    46,    46,    47,    47,    48,    48,
661
      49,    49,    49,    49,    50,    50,    50,    50,    50,    50,
662
      50,    50,    50,    50,    50,    50,    50,    50,    50,    50,
663
      50,    50,    50,    50,    50,    50,    51,    51,    51,    51,
664
      51,    52,    52,    53,    53,    54,    54,    55,    55,    56,
665
      56,    57,    57,    57,    58,    58,    59,    59,    60,    61
666
};
667
 
668
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
669
static const yytype_uint8 yyr2[] =
670
{
671
       0,     2,     2,     1,     3,     3,     2,     3,     3,     2,
672
       2,     2,     2,     2,     2,     4,     2,     4,     0,     1,
673
       2,     7,     3,     0,     1,     1,     1,     1,     1,     1,
674
       1,     1,     2,     1,     8,     8,     6,     6,     6,     4,
675
       2,     1,     2,     2,     3,     1,     1,     0,     2,     0,
676
       1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
677
       1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
678
       1,     1,     1,     1,     1,     1,     1,     2,     2,     3,
679
       3,     1,     0,     2,     0,     2,     0,     2,     0,     3,
680
       0,     1,     2,     4,     1,     0,     1,     0,     1,     1
681
};
682
 
683
/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
684
   STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
685
   means the default is an error.  */
686
static const yytype_uint8 yydefact[] =
687
{
688
       0,    82,    82,     0,     0,     0,     0,     0,     0,    18,
689
       0,     0,     0,     0,     0,     3,    66,    60,    73,    64,
690
      55,    58,    59,    63,    65,    74,    54,    56,    57,    69,
691
      70,    71,    75,    62,    72,    67,    68,    61,    76,     0,
692
       0,    81,    90,    90,     6,    98,    49,    49,    50,    51,
693
      52,    53,     9,    45,    10,     0,    11,    41,    12,    19,
694
      88,     0,    13,    33,    14,    91,     0,     0,    16,     1,
695
       2,     0,    77,    78,     0,     0,     4,     5,     0,     7,
696
       8,    46,     0,    43,    42,    40,    20,     0,    86,     0,
697
       0,    32,     0,    92,    95,     0,    80,    79,     0,    48,
698
      44,    87,     0,    47,    84,     0,    15,    94,    97,    17,
699
      99,    89,    85,    23,     0,     0,    39,     0,    96,    93,
700
      28,    29,    26,    27,    30,    31,    24,    25,    47,    47,
701
      83,    84,    84,    84,    84,    23,    38,     0,    36,    37,
702
      21,    22,    84,    84,    34,    35
703
};
704
 
705
/* YYDEFGOTO[NTERM-NUM].  */
706
static const yytype_int16 yydefgoto[] =
707
{
708
      -1,    14,    15,    58,    59,   128,   129,    62,    63,    56,
709
      57,    52,    82,    79,    53,    40,    41,    42,   116,   103,
710
      88,    76,    67,   108,   119,    46,   111
711
};
712
 
713
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
714
   STATE-NUM.  */
715
#define YYPACT_NINF -82
716
static const yytype_int8 yypact[] =
717
{
718
     122,    11,    11,   -25,     9,     9,    53,    53,   -17,    11,
719
      14,     9,   -18,    20,    95,   -82,   -82,   -82,   -82,   -82,
720
     -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,
721
     -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,    29,    11,
722
      47,   -82,    67,    67,   -82,   -82,    54,    54,   -82,   -82,
723
     -82,   -82,    48,   -82,    48,   -14,   -17,   -82,    11,   -82,
724
      58,    50,    14,   -82,    61,   -82,    64,    33,   -82,   -82,
725
     -82,    11,    47,   -82,    11,    63,   -82,   -82,     9,   -82,
726
     -82,   -82,    53,   -82,    48,   -82,   -82,    11,    60,    76,
727
      81,   -82,     9,   -82,    83,     9,   -82,   -82,    84,   -82,
728
     -82,   -82,     9,    79,   -26,    85,   -82,   -82,    88,   -82,
729
     -82,   -82,   -82,    36,    89,    90,   -82,    55,   -82,   -82,
730
     -82,   -82,   -82,   -82,   -82,   -82,   -82,   -82,    79,    79,
731
     -82,    92,    13,    92,    92,    36,   -82,    59,   -82,   -82,
732
     -82,   -82,    92,    92,   -82,   -82
733
};
734
 
735
/* YYPGOTO[NTERM-NUM].  */
736
static const yytype_int16 yypgoto[] =
737
{
738
     -82,   -82,   107,   -82,    65,   -11,   -82,   -82,    75,   -82,
739
      82,    -4,   -81,    93,    57,   102,    -8,   141,   -75,   -82,
740
     -82,   101,   -82,   -82,   -82,    -5,   -82
741
};
742
 
743
/* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
744
   positive, shift that token.  If negative, reduce the rule which
745
   number is the opposite.  If zero, do what YYDEFACT says.
746
   If YYTABLE_NINF, syntax error.  */
747
#define YYTABLE_NINF -48
748
static const yytype_int16 yytable[] =
749
{
750
      47,    60,   114,    54,    44,   115,    64,    48,    49,    50,
751
      51,    65,    55,    66,    16,    83,    17,    18,    19,    20,
752
      21,    22,   113,    23,    24,    25,    26,    27,    28,    29,
753
      30,    73,    31,    32,    33,    34,    35,    36,    37,    45,
754
      38,   114,    39,    61,   137,   120,   121,   134,   135,    68,
755
      60,    84,   122,   123,   124,   125,   136,   138,   139,   140,
756
      71,   126,   127,    96,    94,    95,    97,   144,   145,   -47,
757
     -47,   -47,   -47,    99,    48,    49,    50,    51,    74,   101,
758
      81,    89,    75,    90,   132,    45,    78,   106,   142,    45,
759
     109,    87,    92,    93,   102,    69,    98,   112,     1,     2,
760
       3,     4,     5,     6,     7,   104,     8,     9,    10,    11,
761
     105,    81,   133,   107,   110,    12,   117,   118,   130,   131,
762
     114,    70,    13,    86,   141,     1,     2,     3,     4,     5,
763
       6,     7,   143,     8,     9,    10,    11,    91,    85,   100,
764
      80,    72,    12,    43,    77,     0,     0,     0,     0,    13
765
};
766
 
767
static const yytype_int16 yycheck[] =
768
{
769
       5,     9,    28,     7,    29,    31,    11,    21,    22,    23,
770
      24,    29,    29,    31,     3,    29,     5,     6,     7,     8,
771
       9,    10,   103,    12,    13,    14,    15,    16,    17,    18,
772
      19,    39,    21,    22,    23,    24,    25,    26,    27,    30,
773
      29,    28,    31,    29,    31,     9,    10,   128,   129,    29,
774
      58,    55,    16,    17,    18,    19,   131,   132,   133,   134,
775
      31,    25,    26,    71,    31,    32,    74,   142,   143,    21,
776
      22,    23,    24,    78,    21,    22,    23,    24,    31,    87,
777
      32,    31,    15,    33,    29,    30,    32,    92,    29,    30,
778
      95,    33,    31,    29,    34,     0,    33,   102,     3,     4,
779
       5,     6,     7,     8,     9,    29,    11,    12,    13,    14,
780
      29,    32,   117,    30,    30,    20,    31,    29,    29,    29,
781
      28,    14,    27,    58,   135,     3,     4,     5,     6,     7,
782
       8,     9,   137,    11,    12,    13,    14,    62,    56,    82,
783
      47,    39,    20,     2,    43,    -1,    -1,    -1,    -1,    27
784
};
785
 
786
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
787
   symbol of state STATE-NUM.  */
788
static const yytype_uint8 yystos[] =
789
{
790
       0,     3,     4,     5,     6,     7,     8,     9,    11,    12,
791
      13,    14,    20,    27,    36,    37,     3,     5,     6,     7,
792
       8,     9,    10,    12,    13,    14,    15,    16,    17,    18,
793
      19,    21,    22,    23,    24,    25,    26,    27,    29,    31,
794
      50,    51,    52,    52,    29,    30,    60,    60,    21,    22,
795
      23,    24,    46,    49,    46,    29,    44,    45,    38,    39,
796
      51,    29,    42,    43,    60,    29,    31,    57,    29,     0,
797
      37,    31,    50,    51,    31,    15,    56,    56,    32,    48,
798
      48,    32,    47,    29,    46,    45,    39,    33,    55,    31,
799
      33,    43,    31,    29,    31,    32,    51,    51,    33,    60,
800
      49,    51,    34,    54,    29,    29,    60,    30,    58,    60,
801
      30,    61,    60,    47,    28,    31,    53,    31,    29,    59,
802
       9,    10,    16,    17,    18,    19,    25,    26,    40,    41,
803
      29,    29,    29,    60,    47,    47,    53,    31,    53,    53,
804
      53,    40,    29,    60,    53,    53
805
};
806
 
807
#define yyerrok		(yyerrstatus = 0)
808
#define yyclearin	(yychar = YYEMPTY)
809
#define YYEMPTY		(-2)
810
#define YYEOF		0
811
 
812
#define YYACCEPT	goto yyacceptlab
813
#define YYABORT		goto yyabortlab
814
#define YYERROR		goto yyerrorlab
815
 
816
 
817
/* Like YYERROR except do call yyerror.  This remains here temporarily
818
   to ease the transition to the new meaning of YYERROR, for GCC.
819
   Once GCC version 2 has supplanted version 1, this can go.  */
820
 
821
#define YYFAIL		goto yyerrlab
822
 
823
#define YYRECOVERING()  (!!yyerrstatus)
824
 
825
#define YYBACKUP(Token, Value)					\
826
do								\
827
  if (yychar == YYEMPTY && yylen == 1)				\
828
    {								\
829
      yychar = (Token);						\
830
      yylval = (Value);						\
831
      yytoken = YYTRANSLATE (yychar);				\
832
      YYPOPSTACK (1);						\
833
      goto yybackup;						\
834
    }								\
835
  else								\
836
    {								\
837
      yyerror (YY_("syntax error: cannot back up")); \
838
      YYERROR;							\
839
    }								\
840
while (YYID (0))
841
 
842
 
843
#define YYTERROR	1
844
#define YYERRCODE	256
845
 
846
 
847
/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
848
   If N is 0, then set CURRENT to the empty location which ends
849
   the previous symbol: RHS[0] (always defined).  */
850
 
851
#define YYRHSLOC(Rhs, K) ((Rhs)[K])
852
#ifndef YYLLOC_DEFAULT
853
# define YYLLOC_DEFAULT(Current, Rhs, N)				\
854
    do									\
855
      if (YYID (N))                                                    \
856
	{								\
857
	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
858
	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
859
	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
860
	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
861
	}								\
862
      else								\
863
	{								\
864
	  (Current).first_line   = (Current).last_line   =		\
865
	    YYRHSLOC (Rhs, 0).last_line;				\
866
	  (Current).first_column = (Current).last_column =		\
867
	    YYRHSLOC (Rhs, 0).last_column;				\
868
	}								\
869
    while (YYID (0))
870
#endif
871
 
872
 
873
/* YY_LOCATION_PRINT -- Print the location on the stream.
874
   This macro was not mandated originally: define only if we know
875
   we won't break user code: when these are the locations we know.  */
876
 
877
#ifndef YY_LOCATION_PRINT
878
# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
879
#  define YY_LOCATION_PRINT(File, Loc)			\
880
     fprintf (File, "%d.%d-%d.%d",			\
881
	      (Loc).first_line, (Loc).first_column,	\
882
	      (Loc).last_line,  (Loc).last_column)
883
# else
884
#  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
885
# endif
886
#endif
887
 
888
 
889
/* YYLEX -- calling `yylex' with the right arguments.  */
890
 
891
#ifdef YYLEX_PARAM
892
# define YYLEX yylex (YYLEX_PARAM)
893
#else
894
# define YYLEX yylex ()
895
#endif
896
 
897
/* Enable debugging if requested.  */
898
#if YYDEBUG
899
 
900
# ifndef YYFPRINTF
901
#  include  /* INFRINGES ON USER NAME SPACE */
902
#  define YYFPRINTF fprintf
903
# endif
904
 
905
# define YYDPRINTF(Args)			\
906
do {						\
907
  if (yydebug)					\
908
    YYFPRINTF Args;				\
909
} while (YYID (0))
910
 
911
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \
912
do {									  \
913
  if (yydebug)								  \
914
    {									  \
915
      YYFPRINTF (stderr, "%s ", Title);					  \
916
      yy_symbol_print (stderr,						  \
917
		  Type, Value); \
918
      YYFPRINTF (stderr, "\n");						  \
919
    }									  \
920
} while (YYID (0))
921
 
922
 
923
/*--------------------------------.
924
| Print this symbol on YYOUTPUT.  |
925
`--------------------------------*/
926
 
927
/*ARGSUSED*/
928
#if (defined __STDC__ || defined __C99__FUNC__ \
929
     || defined __cplusplus || defined _MSC_VER)
930
static void
931
yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
932
#else
933
static void
934
yy_symbol_value_print (yyoutput, yytype, yyvaluep)
935
    FILE *yyoutput;
936
    int yytype;
937
    YYSTYPE const * const yyvaluep;
938
#endif
939
{
940
  if (!yyvaluep)
941
    return;
942
# ifdef YYPRINT
943
  if (yytype < YYNTOKENS)
944
    YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
945
# else
946
  YYUSE (yyoutput);
947
# endif
948
  switch (yytype)
949
    {
950
      default:
951
	break;
952
    }
953
}
954
 
955
 
956
/*--------------------------------.
957
| Print this symbol on YYOUTPUT.  |
958
`--------------------------------*/
959
 
960
#if (defined __STDC__ || defined __C99__FUNC__ \
961
     || defined __cplusplus || defined _MSC_VER)
962
static void
963
yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
964
#else
965
static void
966
yy_symbol_print (yyoutput, yytype, yyvaluep)
967
    FILE *yyoutput;
968
    int yytype;
969
    YYSTYPE const * const yyvaluep;
970
#endif
971
{
972
  if (yytype < YYNTOKENS)
973
    YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
974
  else
975
    YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
976
 
977
  yy_symbol_value_print (yyoutput, yytype, yyvaluep);
978
  YYFPRINTF (yyoutput, ")");
979
}
980
 
981
/*------------------------------------------------------------------.
982
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
983
| TOP (included).                                                   |
984
`------------------------------------------------------------------*/
985
 
986
#if (defined __STDC__ || defined __C99__FUNC__ \
987
     || defined __cplusplus || defined _MSC_VER)
988
static void
989
yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
990
#else
991
static void
992
yy_stack_print (bottom, top)
993
    yytype_int16 *bottom;
994
    yytype_int16 *top;
995
#endif
996
{
997
  YYFPRINTF (stderr, "Stack now");
998
  for (; bottom <= top; ++bottom)
999
    YYFPRINTF (stderr, " %d", *bottom);
1000
  YYFPRINTF (stderr, "\n");
1001
}
1002
 
1003
# define YY_STACK_PRINT(Bottom, Top)				\
1004
do {								\
1005
  if (yydebug)							\
1006
    yy_stack_print ((Bottom), (Top));				\
1007
} while (YYID (0))
1008
 
1009
 
1010
/*------------------------------------------------.
1011
| Report that the YYRULE is going to be reduced.  |
1012
`------------------------------------------------*/
1013
 
1014
#if (defined __STDC__ || defined __C99__FUNC__ \
1015
     || defined __cplusplus || defined _MSC_VER)
1016
static void
1017
yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
1018
#else
1019
static void
1020
yy_reduce_print (yyvsp, yyrule)
1021
    YYSTYPE *yyvsp;
1022
    int yyrule;
1023
#endif
1024
{
1025
  int yynrhs = yyr2[yyrule];
1026
  int yyi;
1027
  unsigned long int yylno = yyrline[yyrule];
1028
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1029
	     yyrule - 1, yylno);
1030
  /* The symbols being reduced.  */
1031
  for (yyi = 0; yyi < yynrhs; yyi++)
1032
    {
1033
      fprintf (stderr, "   $%d = ", yyi + 1);
1034
      yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
1035
		       &(yyvsp[(yyi + 1) - (yynrhs)])
1036
		       		       );
1037
      fprintf (stderr, "\n");
1038
    }
1039
}
1040
 
1041
# define YY_REDUCE_PRINT(Rule)		\
1042
do {					\
1043
  if (yydebug)				\
1044
    yy_reduce_print (yyvsp, Rule); \
1045
} while (YYID (0))
1046
 
1047
/* Nonzero means print parse trace.  It is left uninitialized so that
1048
   multiple parsers can coexist.  */
1049
int yydebug;
1050
#else /* !YYDEBUG */
1051
# define YYDPRINTF(Args)
1052
# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1053
# define YY_STACK_PRINT(Bottom, Top)
1054
# define YY_REDUCE_PRINT(Rule)
1055
#endif /* !YYDEBUG */
1056
 
1057
 
1058
/* YYINITDEPTH -- initial size of the parser's stacks.  */
1059
#ifndef	YYINITDEPTH
1060
# define YYINITDEPTH 200
1061
#endif
1062
 
1063
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1064
   if the built-in stack extension method is used).
1065
 
1066
   Do not make this value too large; the results are undefined if
1067
   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1068
   evaluated with infinite-precision integer arithmetic.  */
1069
 
1070
#ifndef YYMAXDEPTH
1071
# define YYMAXDEPTH 10000
1072
#endif
1073
 
1074
 
1075
 
1076
#if YYERROR_VERBOSE
1077
 
1078
# ifndef yystrlen
1079
#  if defined __GLIBC__ && defined _STRING_H
1080
#   define yystrlen strlen
1081
#  else
1082
/* Return the length of YYSTR.  */
1083
#if (defined __STDC__ || defined __C99__FUNC__ \
1084
     || defined __cplusplus || defined _MSC_VER)
1085
static YYSIZE_T
1086
yystrlen (const char *yystr)
1087
#else
1088
static YYSIZE_T
1089
yystrlen (yystr)
1090
    const char *yystr;
1091
#endif
1092
{
1093
  YYSIZE_T yylen;
1094
  for (yylen = 0; yystr[yylen]; yylen++)
1095
    continue;
1096
  return yylen;
1097
}
1098
#  endif
1099
# endif
1100
 
1101
# ifndef yystpcpy
1102
#  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1103
#   define yystpcpy stpcpy
1104
#  else
1105
/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1106
   YYDEST.  */
1107
#if (defined __STDC__ || defined __C99__FUNC__ \
1108
     || defined __cplusplus || defined _MSC_VER)
1109
static char *
1110
yystpcpy (char *yydest, const char *yysrc)
1111
#else
1112
static char *
1113
yystpcpy (yydest, yysrc)
1114
    char *yydest;
1115
    const char *yysrc;
1116
#endif
1117
{
1118
  char *yyd = yydest;
1119
  const char *yys = yysrc;
1120
 
1121
  while ((*yyd++ = *yys++) != '\0')
1122
    continue;
1123
 
1124
  return yyd - 1;
1125
}
1126
#  endif
1127
# endif
1128
 
1129
# ifndef yytnamerr
1130
/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1131
   quotes and backslashes, so that it's suitable for yyerror.  The
1132
   heuristic is that double-quoting is unnecessary unless the string
1133
   contains an apostrophe, a comma, or backslash (other than
1134
   backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1135
   null, do not copy; instead, return the length of what the result
1136
   would have been.  */
1137
static YYSIZE_T
1138
yytnamerr (char *yyres, const char *yystr)
1139
{
1140
  if (*yystr == '"')
1141
    {
1142
      YYSIZE_T yyn = 0;
1143
      char const *yyp = yystr;
1144
 
1145
      for (;;)
1146
	switch (*++yyp)
1147
	  {
1148
	  case '\'':
1149
	  case ',':
1150
	    goto do_not_strip_quotes;
1151
 
1152
	  case '\\':
1153
	    if (*++yyp != '\\')
1154
	      goto do_not_strip_quotes;
1155
	    /* Fall through.  */
1156
	  default:
1157
	    if (yyres)
1158
	      yyres[yyn] = *yyp;
1159
	    yyn++;
1160
	    break;
1161
 
1162
	  case '"':
1163
	    if (yyres)
1164
	      yyres[yyn] = '\0';
1165
	    return yyn;
1166
	  }
1167
    do_not_strip_quotes: ;
1168
    }
1169
 
1170
  if (! yyres)
1171
    return yystrlen (yystr);
1172
 
1173
  return yystpcpy (yyres, yystr) - yyres;
1174
}
1175
# endif
1176
 
1177
/* Copy into YYRESULT an error message about the unexpected token
1178
   YYCHAR while in state YYSTATE.  Return the number of bytes copied,
1179
   including the terminating null byte.  If YYRESULT is null, do not
1180
   copy anything; just return the number of bytes that would be
1181
   copied.  As a special case, return 0 if an ordinary "syntax error"
1182
   message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
1183
   size calculation.  */
1184
static YYSIZE_T
1185
yysyntax_error (char *yyresult, int yystate, int yychar)
1186
{
1187
  int yyn = yypact[yystate];
1188
 
1189
  if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1190
    return 0;
1191
  else
1192
    {
1193
      int yytype = YYTRANSLATE (yychar);
1194
      YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1195
      YYSIZE_T yysize = yysize0;
1196
      YYSIZE_T yysize1;
1197
      int yysize_overflow = 0;
1198
      enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1199
      char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1200
      int yyx;
1201
 
1202
# if 0
1203
      /* This is so xgettext sees the translatable formats that are
1204
	 constructed on the fly.  */
1205
      YY_("syntax error, unexpected %s");
1206
      YY_("syntax error, unexpected %s, expecting %s");
1207
      YY_("syntax error, unexpected %s, expecting %s or %s");
1208
      YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1209
      YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1210
# endif
1211
      char *yyfmt;
1212
      char const *yyf;
1213
      static char const yyunexpected[] = "syntax error, unexpected %s";
1214
      static char const yyexpecting[] = ", expecting %s";
1215
      static char const yyor[] = " or %s";
1216
      char yyformat[sizeof yyunexpected
1217
		    + sizeof yyexpecting - 1
1218
		    + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1219
		       * (sizeof yyor - 1))];
1220
      char const *yyprefix = yyexpecting;
1221
 
1222
      /* Start YYX at -YYN if negative to avoid negative indexes in
1223
	 YYCHECK.  */
1224
      int yyxbegin = yyn < 0 ? -yyn : 0;
1225
 
1226
      /* Stay within bounds of both yycheck and yytname.  */
1227
      int yychecklim = YYLAST - yyn + 1;
1228
      int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1229
      int yycount = 1;
1230
 
1231
      yyarg[0] = yytname[yytype];
1232
      yyfmt = yystpcpy (yyformat, yyunexpected);
1233
 
1234
      for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1235
	if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1236
	  {
1237
	    if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1238
	      {
1239
		yycount = 1;
1240
		yysize = yysize0;
1241
		yyformat[sizeof yyunexpected - 1] = '\0';
1242
		break;
1243
	      }
1244
	    yyarg[yycount++] = yytname[yyx];
1245
	    yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1246
	    yysize_overflow |= (yysize1 < yysize);
1247
	    yysize = yysize1;
1248
	    yyfmt = yystpcpy (yyfmt, yyprefix);
1249
	    yyprefix = yyor;
1250
	  }
1251
 
1252
      yyf = YY_(yyformat);
1253
      yysize1 = yysize + yystrlen (yyf);
1254
      yysize_overflow |= (yysize1 < yysize);
1255
      yysize = yysize1;
1256
 
1257
      if (yysize_overflow)
1258
	return YYSIZE_MAXIMUM;
1259
 
1260
      if (yyresult)
1261
	{
1262
	  /* Avoid sprintf, as that infringes on the user's name space.
1263
	     Don't have undefined behavior even if the translation
1264
	     produced a string with the wrong number of "%s"s.  */
1265
	  char *yyp = yyresult;
1266
	  int yyi = 0;
1267
	  while ((*yyp = *yyf) != '\0')
1268
	    {
1269
	      if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1270
		{
1271
		  yyp += yytnamerr (yyp, yyarg[yyi++]);
1272
		  yyf += 2;
1273
		}
1274
	      else
1275
		{
1276
		  yyp++;
1277
		  yyf++;
1278
		}
1279
	    }
1280
	}
1281
      return yysize;
1282
    }
1283
}
1284
#endif /* YYERROR_VERBOSE */
1285
 
1286
 
1287
/*-----------------------------------------------.
1288
| Release the memory associated to this symbol.  |
1289
`-----------------------------------------------*/
1290
 
1291
/*ARGSUSED*/
1292
#if (defined __STDC__ || defined __C99__FUNC__ \
1293
     || defined __cplusplus || defined _MSC_VER)
1294
static void
1295
yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1296
#else
1297
static void
1298
yydestruct (yymsg, yytype, yyvaluep)
1299
    const char *yymsg;
1300
    int yytype;
1301
    YYSTYPE *yyvaluep;
1302
#endif
1303
{
1304
  YYUSE (yyvaluep);
1305
 
1306
  if (!yymsg)
1307
    yymsg = "Deleting";
1308
  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1309
 
1310
  switch (yytype)
1311
    {
1312
 
1313
      default:
1314
	break;
1315
    }
1316
}
1317
 
1318
 
1319
/* Prevent warnings from -Wmissing-prototypes.  */
1320
 
1321
#ifdef YYPARSE_PARAM
1322
#if defined __STDC__ || defined __cplusplus
1323
int yyparse (void *YYPARSE_PARAM);
1324
#else
1325
int yyparse ();
1326
#endif
1327
#else /* ! YYPARSE_PARAM */
1328
#if defined __STDC__ || defined __cplusplus
1329
int yyparse (void);
1330
#else
1331
int yyparse ();
1332
#endif
1333
#endif /* ! YYPARSE_PARAM */
1334
 
1335
 
1336
 
1337
/* The look-ahead symbol.  */
1338
int yychar;
1339
 
1340
/* The semantic value of the look-ahead symbol.  */
1341
YYSTYPE yylval;
1342
 
1343
/* Number of syntax errors so far.  */
1344
int yynerrs;
1345
 
1346
 
1347
 
1348
/*----------.
1349
| yyparse.  |
1350
`----------*/
1351
 
1352
#ifdef YYPARSE_PARAM
1353
#if (defined __STDC__ || defined __C99__FUNC__ \
1354
     || defined __cplusplus || defined _MSC_VER)
1355
int
1356
yyparse (void *YYPARSE_PARAM)
1357
#else
1358
int
1359
yyparse (YYPARSE_PARAM)
1360
    void *YYPARSE_PARAM;
1361
#endif
1362
#else /* ! YYPARSE_PARAM */
1363
#if (defined __STDC__ || defined __C99__FUNC__ \
1364
     || defined __cplusplus || defined _MSC_VER)
1365
int
1366
yyparse (void)
1367
#else
1368
int
1369
yyparse ()
1370
 
1371
#endif
1372
#endif
1373
{
1374
 
1375
  int yystate;
1376
  int yyn;
1377
  int yyresult;
1378
  /* Number of tokens to shift before error messages enabled.  */
1379
  int yyerrstatus;
1380
  /* Look-ahead token as an internal (translated) token number.  */
1381
  int yytoken = 0;
1382
#if YYERROR_VERBOSE
1383
  /* Buffer for error messages, and its allocated size.  */
1384
  char yymsgbuf[128];
1385
  char *yymsg = yymsgbuf;
1386
  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1387
#endif
1388
 
1389
  /* Three stacks and their tools:
1390
     `yyss': related to states,
1391
     `yyvs': related to semantic values,
1392
     `yyls': related to locations.
1393
 
1394
     Refer to the stacks thru separate pointers, to allow yyoverflow
1395
     to reallocate them elsewhere.  */
1396
 
1397
  /* The state stack.  */
1398
  yytype_int16 yyssa[YYINITDEPTH];
1399
  yytype_int16 *yyss = yyssa;
1400
  yytype_int16 *yyssp;
1401
 
1402
  /* The semantic value stack.  */
1403
  YYSTYPE yyvsa[YYINITDEPTH];
1404
  YYSTYPE *yyvs = yyvsa;
1405
  YYSTYPE *yyvsp;
1406
 
1407
 
1408
 
1409
#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1410
 
1411
  YYSIZE_T yystacksize = YYINITDEPTH;
1412
 
1413
  /* The variables used to return semantic value and location from the
1414
     action routines.  */
1415
  YYSTYPE yyval;
1416
 
1417
 
1418
  /* The number of symbols on the RHS of the reduced rule.
1419
     Keep to zero when no symbol should be popped.  */
1420
  int yylen = 0;
1421
 
1422
  YYDPRINTF ((stderr, "Starting parse\n"));
1423
 
1424
  yystate = 0;
1425
  yyerrstatus = 0;
1426
  yynerrs = 0;
1427
  yychar = YYEMPTY;		/* Cause a token to be read.  */
1428
 
1429
  /* Initialize stack pointers.
1430
     Waste one element of value and location stack
1431
     so that they stay on the same level as the state stack.
1432
     The wasted elements are never initialized.  */
1433
 
1434
  yyssp = yyss;
1435
  yyvsp = yyvs;
1436
 
1437
  goto yysetstate;
1438
 
1439
/*------------------------------------------------------------.
1440
| yynewstate -- Push a new state, which is found in yystate.  |
1441
`------------------------------------------------------------*/
1442
 yynewstate:
1443
  /* In all cases, when you get here, the value and location stacks
1444
     have just been pushed.  So pushing a state here evens the stacks.  */
1445
  yyssp++;
1446
 
1447
 yysetstate:
1448
  *yyssp = yystate;
1449
 
1450
  if (yyss + yystacksize - 1 <= yyssp)
1451
    {
1452
      /* Get the current used size of the three stacks, in elements.  */
1453
      YYSIZE_T yysize = yyssp - yyss + 1;
1454
 
1455
#ifdef yyoverflow
1456
      {
1457
	/* Give user a chance to reallocate the stack.  Use copies of
1458
	   these so that the &'s don't force the real ones into
1459
	   memory.  */
1460
	YYSTYPE *yyvs1 = yyvs;
1461
	yytype_int16 *yyss1 = yyss;
1462
 
1463
 
1464
	/* Each stack pointer address is followed by the size of the
1465
	   data in use in that stack, in bytes.  This used to be a
1466
	   conditional around just the two extra args, but that might
1467
	   be undefined if yyoverflow is a macro.  */
1468
	yyoverflow (YY_("memory exhausted"),
1469
		    &yyss1, yysize * sizeof (*yyssp),
1470
		    &yyvs1, yysize * sizeof (*yyvsp),
1471
 
1472
		    &yystacksize);
1473
 
1474
	yyss = yyss1;
1475
	yyvs = yyvs1;
1476
      }
1477
#else /* no yyoverflow */
1478
# ifndef YYSTACK_RELOCATE
1479
      goto yyexhaustedlab;
1480
# else
1481
      /* Extend the stack our own way.  */
1482
      if (YYMAXDEPTH <= yystacksize)
1483
	goto yyexhaustedlab;
1484
      yystacksize *= 2;
1485
      if (YYMAXDEPTH < yystacksize)
1486
	yystacksize = YYMAXDEPTH;
1487
 
1488
      {
1489
	yytype_int16 *yyss1 = yyss;
1490
	union yyalloc *yyptr =
1491
	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1492
	if (! yyptr)
1493
	  goto yyexhaustedlab;
1494
	YYSTACK_RELOCATE (yyss);
1495
	YYSTACK_RELOCATE (yyvs);
1496
 
1497
#  undef YYSTACK_RELOCATE
1498
	if (yyss1 != yyssa)
1499
	  YYSTACK_FREE (yyss1);
1500
      }
1501
# endif
1502
#endif /* no yyoverflow */
1503
 
1504
      yyssp = yyss + yysize - 1;
1505
      yyvsp = yyvs + yysize - 1;
1506
 
1507
 
1508
      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1509
		  (unsigned long int) yystacksize));
1510
 
1511
      if (yyss + yystacksize - 1 <= yyssp)
1512
	YYABORT;
1513
    }
1514
 
1515
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1516
 
1517
  goto yybackup;
1518
 
1519
/*-----------.
1520
| yybackup.  |
1521
`-----------*/
1522
yybackup:
1523
 
1524
  /* Do appropriate processing given the current state.  Read a
1525
     look-ahead token if we need one and don't already have one.  */
1526
 
1527
  /* First try to decide what to do without reference to look-ahead token.  */
1528
  yyn = yypact[yystate];
1529
  if (yyn == YYPACT_NINF)
1530
    goto yydefault;
1531
 
1532
  /* Not known => get a look-ahead token if don't already have one.  */
1533
 
1534
  /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
1535
  if (yychar == YYEMPTY)
1536
    {
1537
      YYDPRINTF ((stderr, "Reading a token: "));
1538
      yychar = YYLEX;
1539
    }
1540
 
1541
  if (yychar <= YYEOF)
1542
    {
1543
      yychar = yytoken = YYEOF;
1544
      YYDPRINTF ((stderr, "Now at end of input.\n"));
1545
    }
1546
  else
1547
    {
1548
      yytoken = YYTRANSLATE (yychar);
1549
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1550
    }
1551
 
1552
  /* If the proper action on seeing token YYTOKEN is to reduce or to
1553
     detect an error, take that action.  */
1554
  yyn += yytoken;
1555
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1556
    goto yydefault;
1557
  yyn = yytable[yyn];
1558
  if (yyn <= 0)
1559
    {
1560
      if (yyn == 0 || yyn == YYTABLE_NINF)
1561
	goto yyerrlab;
1562
      yyn = -yyn;
1563
      goto yyreduce;
1564
    }
1565
 
1566
  if (yyn == YYFINAL)
1567
    YYACCEPT;
1568
 
1569
  /* Count tokens shifted since error; after three, turn off error
1570
     status.  */
1571
  if (yyerrstatus)
1572
    yyerrstatus--;
1573
 
1574
  /* Shift the look-ahead token.  */
1575
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1576
 
1577
  /* Discard the shifted token unless it is eof.  */
1578
  if (yychar != YYEOF)
1579
    yychar = YYEMPTY;
1580
 
1581
  yystate = yyn;
1582
  *++yyvsp = yylval;
1583
 
1584
  goto yynewstate;
1585
 
1586
 
1587
/*-----------------------------------------------------------.
1588
| yydefault -- do the default action for the current state.  |
1589
`-----------------------------------------------------------*/
1590
yydefault:
1591
  yyn = yydefact[yystate];
1592
  if (yyn == 0)
1593
    goto yyerrlab;
1594
  goto yyreduce;
1595
 
1596
 
1597
/*-----------------------------.
1598
| yyreduce -- Do a reduction.  |
1599
`-----------------------------*/
1600
yyreduce:
1601
  /* yyn is the number of a rule to reduce with.  */
1602
  yylen = yyr2[yyn];
1603
 
1604
  /* If YYLEN is nonzero, implement the default value of the action:
1605
     `$$ = $1'.
1606
 
1607
     Otherwise, the following line sets YYVAL to garbage.
1608
     This behavior is undocumented and Bison
1609
     users should not rely upon it.  Assigning to YYVAL
1610
     unconditionally makes the parser a bit smaller, and it avoids a
1611
     GCC warning that YYVAL may be used uninitialized.  */
1612
  yyval = yyvsp[1-yylen];
1613
 
1614
 
1615
  YY_REDUCE_PRINT (yyn);
1616
  switch (yyn)
1617
    {
1618
        case 4:
1619
#line 144 "deffilep.y"
1620
    { def_image_name ((yyvsp[(2) - (3)].id), (yyvsp[(3) - (3)].vma), 0); }
1621
    break;
1622
 
1623
  case 5:
1624
#line 145 "deffilep.y"
1625
    { def_image_name ((yyvsp[(2) - (3)].id), (yyvsp[(3) - (3)].vma), 1); }
1626
    break;
1627
 
1628
  case 6:
1629
#line 146 "deffilep.y"
1630
    { def_description ((yyvsp[(2) - (2)].id));}
1631
    break;
1632
 
1633
  case 7:
1634
#line 147 "deffilep.y"
1635
    { def_stacksize ((yyvsp[(2) - (3)].number), (yyvsp[(3) - (3)].number));}
1636
    break;
1637
 
1638
  case 8:
1639
#line 148 "deffilep.y"
1640
    { def_heapsize ((yyvsp[(2) - (3)].number), (yyvsp[(3) - (3)].number));}
1641
    break;
1642
 
1643
  case 9:
1644
#line 149 "deffilep.y"
1645
    { def_section ("CODE", (yyvsp[(2) - (2)].number));}
1646
    break;
1647
 
1648
  case 10:
1649
#line 150 "deffilep.y"
1650
    { def_section ("DATA", (yyvsp[(2) - (2)].number));}
1651
    break;
1652
 
1653
  case 14:
1654
#line 154 "deffilep.y"
1655
    { def_version ((yyvsp[(2) - (2)].number), 0);}
1656
    break;
1657
 
1658
  case 15:
1659
#line 155 "deffilep.y"
1660
    { def_version ((yyvsp[(2) - (4)].number), (yyvsp[(4) - (4)].number));}
1661
    break;
1662
 
1663
  case 16:
1664
#line 156 "deffilep.y"
1665
    { def_directive ((yyvsp[(2) - (2)].id));}
1666
    break;
1667
 
1668
  case 17:
1669
#line 157 "deffilep.y"
1670
    { def_aligncomm ((yyvsp[(2) - (4)].id), (yyvsp[(4) - (4)].number));}
1671
    break;
1672
 
1673
  case 21:
1674
#line 172 "deffilep.y"
1675
    { def_exports ((yyvsp[(1) - (7)].id), (yyvsp[(2) - (7)].id), (yyvsp[(3) - (7)].number), (yyvsp[(5) - (7)].number), (yyvsp[(7) - (7)].id)); }
1676
    break;
1677
 
1678
  case 22:
1679
#line 178 "deffilep.y"
1680
    { (yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number); }
1681
    break;
1682
 
1683
  case 23:
1684
#line 179 "deffilep.y"
1685
    { (yyval.number) = 0; }
1686
    break;
1687
 
1688
  case 24:
1689
#line 182 "deffilep.y"
1690
    { (yyval.number) = 1; }
1691
    break;
1692
 
1693
  case 25:
1694
#line 183 "deffilep.y"
1695
    { (yyval.number) = 1; }
1696
    break;
1697
 
1698
  case 26:
1699
#line 184 "deffilep.y"
1700
    { (yyval.number) = 2; }
1701
    break;
1702
 
1703
  case 27:
1704
#line 185 "deffilep.y"
1705
    { (yyval.number) = 2; }
1706
    break;
1707
 
1708
  case 28:
1709
#line 186 "deffilep.y"
1710
    { (yyval.number) = 4; }
1711
    break;
1712
 
1713
  case 29:
1714
#line 187 "deffilep.y"
1715
    { (yyval.number) = 4; }
1716
    break;
1717
 
1718
  case 30:
1719
#line 188 "deffilep.y"
1720
    { (yyval.number) = 8; }
1721
    break;
1722
 
1723
  case 31:
1724
#line 189 "deffilep.y"
1725
    { (yyval.number) = 8; }
1726
    break;
1727
 
1728
  case 34:
1729
#line 198 "deffilep.y"
1730
    { def_import ((yyvsp[(1) - (8)].id), (yyvsp[(3) - (8)].id), (yyvsp[(5) - (8)].id), (yyvsp[(7) - (8)].id), -1, (yyvsp[(8) - (8)].id)); }
1731
    break;
1732
 
1733
  case 35:
1734
#line 200 "deffilep.y"
1735
    { def_import ((yyvsp[(1) - (8)].id), (yyvsp[(3) - (8)].id), (yyvsp[(5) - (8)].id),  0, (yyvsp[(7) - (8)].number), (yyvsp[(8) - (8)].id)); }
1736
    break;
1737
 
1738
  case 36:
1739
#line 202 "deffilep.y"
1740
    { def_import ((yyvsp[(1) - (6)].id), (yyvsp[(3) - (6)].id),  0, (yyvsp[(5) - (6)].id), -1, (yyvsp[(6) - (6)].id)); }
1741
    break;
1742
 
1743
  case 37:
1744
#line 204 "deffilep.y"
1745
    { def_import ((yyvsp[(1) - (6)].id), (yyvsp[(3) - (6)].id),  0,  0, (yyvsp[(5) - (6)].number), (yyvsp[(6) - (6)].id)); }
1746
    break;
1747
 
1748
  case 38:
1749
#line 206 "deffilep.y"
1750
    { def_import( 0, (yyvsp[(1) - (6)].id), (yyvsp[(3) - (6)].id), (yyvsp[(5) - (6)].id), -1, (yyvsp[(6) - (6)].id)); }
1751
    break;
1752
 
1753
  case 39:
1754
#line 208 "deffilep.y"
1755
    { def_import ( 0, (yyvsp[(1) - (4)].id),  0, (yyvsp[(3) - (4)].id), -1, (yyvsp[(4) - (4)].id)); }
1756
    break;
1757
 
1758
  case 42:
1759
#line 217 "deffilep.y"
1760
    { def_section ((yyvsp[(1) - (2)].id), (yyvsp[(2) - (2)].number));}
1761
    break;
1762
 
1763
  case 43:
1764
#line 218 "deffilep.y"
1765
    { def_section_alt ((yyvsp[(1) - (2)].id), (yyvsp[(2) - (2)].id));}
1766
    break;
1767
 
1768
  case 44:
1769
#line 222 "deffilep.y"
1770
    { (yyval.number) = (yyvsp[(1) - (3)].number) | (yyvsp[(3) - (3)].number); }
1771
    break;
1772
 
1773
  case 45:
1774
#line 223 "deffilep.y"
1775
    { (yyval.number) = (yyvsp[(1) - (1)].number); }
1776
    break;
1777
 
1778
  case 48:
1779
#line 230 "deffilep.y"
1780
    { (yyval.number)=(yyvsp[(2) - (2)].number);}
1781
    break;
1782
 
1783
  case 49:
1784
#line 231 "deffilep.y"
1785
    { (yyval.number)=-1;}
1786
    break;
1787
 
1788
  case 50:
1789
#line 235 "deffilep.y"
1790
    { (yyval.number) = 1;}
1791
    break;
1792
 
1793
  case 51:
1794
#line 236 "deffilep.y"
1795
    { (yyval.number) = 2;}
1796
    break;
1797
 
1798
  case 52:
1799
#line 237 "deffilep.y"
1800
    { (yyval.number)=4;}
1801
    break;
1802
 
1803
  case 53:
1804
#line 238 "deffilep.y"
1805
    { (yyval.number)=8;}
1806
    break;
1807
 
1808
  case 54:
1809
#line 242 "deffilep.y"
1810
    { (yyval.id_const) = "BASE"; }
1811
    break;
1812
 
1813
  case 55:
1814
#line 243 "deffilep.y"
1815
    { (yyval.id_const) = "CODE"; }
1816
    break;
1817
 
1818
  case 56:
1819
#line 244 "deffilep.y"
1820
    { (yyval.id_const) = "CONSTANT"; }
1821
    break;
1822
 
1823
  case 57:
1824
#line 245 "deffilep.y"
1825
    { (yyval.id_const) = "constant"; }
1826
    break;
1827
 
1828
  case 58:
1829
#line 246 "deffilep.y"
1830
    { (yyval.id_const) = "DATA"; }
1831
    break;
1832
 
1833
  case 59:
1834
#line 247 "deffilep.y"
1835
    { (yyval.id_const) = "data"; }
1836
    break;
1837
 
1838
  case 60:
1839
#line 248 "deffilep.y"
1840
    { (yyval.id_const) = "DESCRIPTION"; }
1841
    break;
1842
 
1843
  case 61:
1844
#line 249 "deffilep.y"
1845
    { (yyval.id_const) = "DIRECTIVE"; }
1846
    break;
1847
 
1848
  case 62:
1849
#line 250 "deffilep.y"
1850
    { (yyval.id_const) = "EXECUTE"; }
1851
    break;
1852
 
1853
  case 63:
1854
#line 251 "deffilep.y"
1855
    { (yyval.id_const) = "EXPORTS"; }
1856
    break;
1857
 
1858
  case 64:
1859
#line 252 "deffilep.y"
1860
    { (yyval.id_const) = "HEAPSIZE"; }
1861
    break;
1862
 
1863
  case 65:
1864
#line 253 "deffilep.y"
1865
    { (yyval.id_const) = "IMPORTS"; }
1866
    break;
1867
 
1868
  case 66:
1869
#line 260 "deffilep.y"
1870
    { (yyval.id_const) = "NAME"; }
1871
    break;
1872
 
1873
  case 67:
1874
#line 261 "deffilep.y"
1875
    { (yyval.id_const) = "NONAME"; }
1876
    break;
1877
 
1878
  case 68:
1879
#line 262 "deffilep.y"
1880
    { (yyval.id_const) = "noname"; }
1881
    break;
1882
 
1883
  case 69:
1884
#line 263 "deffilep.y"
1885
    { (yyval.id_const) = "PRIVATE"; }
1886
    break;
1887
 
1888
  case 70:
1889
#line 264 "deffilep.y"
1890
    { (yyval.id_const) = "private"; }
1891
    break;
1892
 
1893
  case 71:
1894
#line 265 "deffilep.y"
1895
    { (yyval.id_const) = "READ"; }
1896
    break;
1897
 
1898
  case 72:
1899
#line 266 "deffilep.y"
1900
    { (yyval.id_const) = "SHARED"; }
1901
    break;
1902
 
1903
  case 73:
1904
#line 267 "deffilep.y"
1905
    { (yyval.id_const) = "STACKSIZE"; }
1906
    break;
1907
 
1908
  case 74:
1909
#line 268 "deffilep.y"
1910
    { (yyval.id_const) = "VERSION"; }
1911
    break;
1912
 
1913
  case 75:
1914
#line 269 "deffilep.y"
1915
    { (yyval.id_const) = "WRITE"; }
1916
    break;
1917
 
1918
  case 76:
1919
#line 272 "deffilep.y"
1920
    { (yyval.id) = (yyvsp[(1) - (1)].id); }
1921
    break;
1922
 
1923
  case 77:
1924
#line 274 "deffilep.y"
1925
    {
1926
	    char *name = xmalloc (strlen ((yyvsp[(2) - (2)].id_const)) + 2);
1927
	    sprintf (name, ".%s", (yyvsp[(2) - (2)].id_const));
1928
	    (yyval.id) = name;
1929
	  }
1930
    break;
1931
 
1932
  case 78:
1933
#line 280 "deffilep.y"
1934
    {
1935
	    char *name = def_pool_alloc (strlen ((yyvsp[(2) - (2)].id)) + 2);
1936
	    sprintf (name, ".%s", (yyvsp[(2) - (2)].id));
1937
	    (yyval.id) = name;
1938
	  }
1939
    break;
1940
 
1941
  case 79:
1942
#line 286 "deffilep.y"
1943
    {
1944
	    char *name = def_pool_alloc (strlen ((yyvsp[(1) - (3)].id_const)) + 1 + strlen ((yyvsp[(3) - (3)].id)) + 1);
1945
	    sprintf (name, "%s.%s", (yyvsp[(1) - (3)].id_const), (yyvsp[(3) - (3)].id));
1946
	    (yyval.id) = name;
1947
	  }
1948
    break;
1949
 
1950
  case 80:
1951
#line 292 "deffilep.y"
1952
    {
1953
	    char *name = def_pool_alloc (strlen ((yyvsp[(1) - (3)].id)) + 1 + strlen ((yyvsp[(3) - (3)].id)) + 1);
1954
	    sprintf (name, "%s.%s", (yyvsp[(1) - (3)].id), (yyvsp[(3) - (3)].id));
1955
	    (yyval.id) = name;
1956
	  }
1957
    break;
1958
 
1959
  case 81:
1960
#line 299 "deffilep.y"
1961
    { (yyval.id) = (yyvsp[(1) - (1)].id); }
1962
    break;
1963
 
1964
  case 82:
1965
#line 300 "deffilep.y"
1966
    { (yyval.id) = ""; }
1967
    break;
1968
 
1969
  case 83:
1970
#line 303 "deffilep.y"
1971
    { (yyval.id) = (yyvsp[(2) - (2)].id); }
1972
    break;
1973
 
1974
  case 84:
1975
#line 304 "deffilep.y"
1976
    { (yyval.id) = 0; }
1977
    break;
1978
 
1979
  case 85:
1980
#line 308 "deffilep.y"
1981
    { (yyval.number) = (yyvsp[(2) - (2)].number);}
1982
    break;
1983
 
1984
  case 86:
1985
#line 309 "deffilep.y"
1986
    { (yyval.number) = -1;}
1987
    break;
1988
 
1989
  case 87:
1990
#line 313 "deffilep.y"
1991
    { (yyval.id) = (yyvsp[(2) - (2)].id); }
1992
    break;
1993
 
1994
  case 88:
1995
#line 314 "deffilep.y"
1996
    { (yyval.id) =  0; }
1997
    break;
1998
 
1999
  case 89:
2000
#line 317 "deffilep.y"
2001
    { (yyval.vma) = (yyvsp[(3) - (3)].vma);}
2002
    break;
2003
 
2004
  case 90:
2005
#line 318 "deffilep.y"
2006
    { (yyval.vma) = (bfd_vma) -1;}
2007
    break;
2008
 
2009
  case 91:
2010
#line 321 "deffilep.y"
2011
    { (yyval.id) = (yyvsp[(1) - (1)].id); }
2012
    break;
2013
 
2014
  case 92:
2015
#line 323 "deffilep.y"
2016
    {
2017
	    char *id = def_pool_alloc (strlen ((yyvsp[(2) - (2)].id)) + 2);
2018
	    sprintf (id, ".%s", (yyvsp[(2) - (2)].id));
2019
	    (yyval.id) = id;
2020
	  }
2021
    break;
2022
 
2023
  case 93:
2024
#line 329 "deffilep.y"
2025
    {
2026
	    char *id = def_pool_alloc (strlen ((yyvsp[(1) - (4)].id)) + 1 + strlen ((yyvsp[(3) - (4)].digits)) + strlen ((yyvsp[(4) - (4)].id)) + 1);
2027
	    sprintf (id, "%s.%s%s", (yyvsp[(1) - (4)].id), (yyvsp[(3) - (4)].digits), (yyvsp[(4) - (4)].id));
2028
	    (yyval.id) = id;
2029
	  }
2030
    break;
2031
 
2032
  case 94:
2033
#line 336 "deffilep.y"
2034
    { (yyval.digits) = (yyvsp[(1) - (1)].digits); }
2035
    break;
2036
 
2037
  case 95:
2038
#line 337 "deffilep.y"
2039
    { (yyval.digits) = ""; }
2040
    break;
2041
 
2042
  case 96:
2043
#line 340 "deffilep.y"
2044
    { (yyval.id) = (yyvsp[(1) - (1)].id); }
2045
    break;
2046
 
2047
  case 97:
2048
#line 341 "deffilep.y"
2049
    { (yyval.id) = ""; }
2050
    break;
2051
 
2052
  case 98:
2053
#line 344 "deffilep.y"
2054
    { (yyval.number) = strtoul ((yyvsp[(1) - (1)].digits), 0, 0); }
2055
    break;
2056
 
2057
  case 99:
2058
#line 346 "deffilep.y"
2059
    { (yyval.vma) = (bfd_vma) strtoull ((yyvsp[(1) - (1)].digits), 0, 0); }
2060
    break;
2061
 
2062
 
2063
/* Line 1267 of yacc.c.  */
2064
#line 2065 "deffilep.c"
2065
      default: break;
2066
    }
2067
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2068
 
2069
  YYPOPSTACK (yylen);
2070
  yylen = 0;
2071
  YY_STACK_PRINT (yyss, yyssp);
2072
 
2073
  *++yyvsp = yyval;
2074
 
2075
 
2076
  /* Now `shift' the result of the reduction.  Determine what state
2077
     that goes to, based on the state we popped back to and the rule
2078
     number reduced by.  */
2079
 
2080
  yyn = yyr1[yyn];
2081
 
2082
  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2083
  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2084
    yystate = yytable[yystate];
2085
  else
2086
    yystate = yydefgoto[yyn - YYNTOKENS];
2087
 
2088
  goto yynewstate;
2089
 
2090
 
2091
/*------------------------------------.
2092
| yyerrlab -- here on detecting error |
2093
`------------------------------------*/
2094
yyerrlab:
2095
  /* If not already recovering from an error, report this error.  */
2096
  if (!yyerrstatus)
2097
    {
2098
      ++yynerrs;
2099
#if ! YYERROR_VERBOSE
2100
      yyerror (YY_("syntax error"));
2101
#else
2102
      {
2103
	YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
2104
	if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
2105
	  {
2106
	    YYSIZE_T yyalloc = 2 * yysize;
2107
	    if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
2108
	      yyalloc = YYSTACK_ALLOC_MAXIMUM;
2109
	    if (yymsg != yymsgbuf)
2110
	      YYSTACK_FREE (yymsg);
2111
	    yymsg = (char *) YYSTACK_ALLOC (yyalloc);
2112
	    if (yymsg)
2113
	      yymsg_alloc = yyalloc;
2114
	    else
2115
	      {
2116
		yymsg = yymsgbuf;
2117
		yymsg_alloc = sizeof yymsgbuf;
2118
	      }
2119
	  }
2120
 
2121
	if (0 < yysize && yysize <= yymsg_alloc)
2122
	  {
2123
	    (void) yysyntax_error (yymsg, yystate, yychar);
2124
	    yyerror (yymsg);
2125
	  }
2126
	else
2127
	  {
2128
	    yyerror (YY_("syntax error"));
2129
	    if (yysize != 0)
2130
	      goto yyexhaustedlab;
2131
	  }
2132
      }
2133
#endif
2134
    }
2135
 
2136
 
2137
 
2138
  if (yyerrstatus == 3)
2139
    {
2140
      /* If just tried and failed to reuse look-ahead token after an
2141
	 error, discard it.  */
2142
 
2143
      if (yychar <= YYEOF)
2144
	{
2145
	  /* Return failure if at end of input.  */
2146
	  if (yychar == YYEOF)
2147
	    YYABORT;
2148
	}
2149
      else
2150
	{
2151
	  yydestruct ("Error: discarding",
2152
		      yytoken, &yylval);
2153
	  yychar = YYEMPTY;
2154
	}
2155
    }
2156
 
2157
  /* Else will try to reuse look-ahead token after shifting the error
2158
     token.  */
2159
  goto yyerrlab1;
2160
 
2161
 
2162
/*---------------------------------------------------.
2163
| yyerrorlab -- error raised explicitly by YYERROR.  |
2164
`---------------------------------------------------*/
2165
yyerrorlab:
2166
 
2167
  /* Pacify compilers like GCC when the user code never invokes
2168
     YYERROR and the label yyerrorlab therefore never appears in user
2169
     code.  */
2170
  if (/*CONSTCOND*/ 0)
2171
     goto yyerrorlab;
2172
 
2173
  /* Do not reclaim the symbols of the rule which action triggered
2174
     this YYERROR.  */
2175
  YYPOPSTACK (yylen);
2176
  yylen = 0;
2177
  YY_STACK_PRINT (yyss, yyssp);
2178
  yystate = *yyssp;
2179
  goto yyerrlab1;
2180
 
2181
 
2182
/*-------------------------------------------------------------.
2183
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
2184
`-------------------------------------------------------------*/
2185
yyerrlab1:
2186
  yyerrstatus = 3;	/* Each real token shifted decrements this.  */
2187
 
2188
  for (;;)
2189
    {
2190
      yyn = yypact[yystate];
2191
      if (yyn != YYPACT_NINF)
2192
	{
2193
	  yyn += YYTERROR;
2194
	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2195
	    {
2196
	      yyn = yytable[yyn];
2197
	      if (0 < yyn)
2198
		break;
2199
	    }
2200
	}
2201
 
2202
      /* Pop the current state because it cannot handle the error token.  */
2203
      if (yyssp == yyss)
2204
	YYABORT;
2205
 
2206
 
2207
      yydestruct ("Error: popping",
2208
		  yystos[yystate], yyvsp);
2209
      YYPOPSTACK (1);
2210
      yystate = *yyssp;
2211
      YY_STACK_PRINT (yyss, yyssp);
2212
    }
2213
 
2214
  if (yyn == YYFINAL)
2215
    YYACCEPT;
2216
 
2217
  *++yyvsp = yylval;
2218
 
2219
 
2220
  /* Shift the error token.  */
2221
  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2222
 
2223
  yystate = yyn;
2224
  goto yynewstate;
2225
 
2226
 
2227
/*-------------------------------------.
2228
| yyacceptlab -- YYACCEPT comes here.  |
2229
`-------------------------------------*/
2230
yyacceptlab:
2231
  yyresult = 0;
2232
  goto yyreturn;
2233
 
2234
/*-----------------------------------.
2235
| yyabortlab -- YYABORT comes here.  |
2236
`-----------------------------------*/
2237
yyabortlab:
2238
  yyresult = 1;
2239
  goto yyreturn;
2240
 
2241
#ifndef yyoverflow
2242
/*-------------------------------------------------.
2243
| yyexhaustedlab -- memory exhaustion comes here.  |
2244
`-------------------------------------------------*/
2245
yyexhaustedlab:
2246
  yyerror (YY_("memory exhausted"));
2247
  yyresult = 2;
2248
  /* Fall through.  */
2249
#endif
2250
 
2251
yyreturn:
2252
  if (yychar != YYEOF && yychar != YYEMPTY)
2253
     yydestruct ("Cleanup: discarding lookahead",
2254
		 yytoken, &yylval);
2255
  /* Do not reclaim the symbols of the rule which action triggered
2256
     this YYABORT or YYACCEPT.  */
2257
  YYPOPSTACK (yylen);
2258
  YY_STACK_PRINT (yyss, yyssp);
2259
  while (yyssp != yyss)
2260
    {
2261
      yydestruct ("Cleanup: popping",
2262
		  yystos[*yyssp], yyvsp);
2263
      YYPOPSTACK (1);
2264
    }
2265
#ifndef yyoverflow
2266
  if (yyss != yyssa)
2267
    YYSTACK_FREE (yyss);
2268
#endif
2269
#if YYERROR_VERBOSE
2270
  if (yymsg != yymsgbuf)
2271
    YYSTACK_FREE (yymsg);
2272
#endif
2273
  /* Make sure YYID is used.  */
2274
  return YYID (yyresult);
2275
}
2276
 
2277
 
2278
#line 348 "deffilep.y"
2279
 
2280
 
2281
/*****************************************************************************
2282
 API
2283
 *****************************************************************************/
2284
 
2285
static FILE *the_file;
2286
static const char *def_filename;
2287
static int linenumber;
2288
static def_file *def;
2289
static int saw_newline;
2290
 
2291
struct directive
2292
  {
2293
    struct directive *next;
2294
    char *name;
2295
    int len;
2296
  };
2297
 
2298
static struct directive *directives = 0;
2299
 
2300
def_file *
2301
def_file_empty (void)
2302
{
2303
  def_file *rv = xmalloc (sizeof (def_file));
2304
  memset (rv, 0, sizeof (def_file));
2305
  rv->is_dll = -1;
2306
  rv->base_address = (bfd_vma) -1;
2307
  rv->stack_reserve = rv->stack_commit = -1;
2308
  rv->heap_reserve = rv->heap_commit = -1;
2309
  rv->version_major = rv->version_minor = -1;
2310
  return rv;
2311
}
2312
 
2313
def_file *
2314
def_file_parse (const char *filename, def_file *add_to)
2315
{
2316
  struct directive *d;
2317
 
2318
  the_file = fopen (filename, "r");
2319
  def_filename = filename;
2320
  linenumber = 1;
2321
  if (!the_file)
2322
    {
2323
      //perror (filename);
2324
      printf("Error %s\n", filename);
2325
      return 0;
2326
    }
2327
  if (add_to)
2328
    {
2329
      def = add_to;
2330
    }
2331
  else
2332
    {
2333
      def = def_file_empty ();
2334
    }
2335
 
2336
  saw_newline = 1;
2337
  if (def_parse ())
2338
    {
2339
      def_file_free (def);
2340
      fclose (the_file);
2341
      def_pool_free ();
2342
      return 0;
2343
    }
2344
 
2345
  fclose (the_file);
2346
 
2347
  while ((d = directives) != NULL)
2348
    {
2349
#if TRACE
2350
      printf ("Adding directive %08x `%s'\n", d->name, d->name);
2351
#endif
2352
      def_file_add_directive (def, d->name, d->len);
2353
      directives = d->next;
2354
      free (d->name);
2355
      free (d);
2356
    }
2357
  def_pool_free ();
2358
 
2359
  return def;
2360
}
2361
 
2362
void
2363
def_file_free (def_file *fdef)
2364
{
2365
  int i;
2366
 
2367
  if (!fdef)
2368
    return;
2369
  if (fdef->name)
2370
    free (fdef->name);
2371
  if (fdef->description)
2372
    free (fdef->description);
2373
 
2374
  if (fdef->section_defs)
2375
    {
2376
      for (i = 0; i < fdef->num_section_defs; i++)
2377
	{
2378
	  if (fdef->section_defs[i].name)
2379
	    free (fdef->section_defs[i].name);
2380
	  if (fdef->section_defs[i].class)
2381
	    free (fdef->section_defs[i].class);
2382
	}
2383
      free (fdef->section_defs);
2384
    }
2385
 
2386
  if (fdef->exports)
2387
    {
2388
      for (i = 0; i < fdef->num_exports; i++)
2389
	{
2390
	  if (fdef->exports[i].internal_name
2391
	      && fdef->exports[i].internal_name != fdef->exports[i].name)
2392
	    free (fdef->exports[i].internal_name);
2393
	  if (fdef->exports[i].name)
2394
	    free (fdef->exports[i].name);
2395
	  if (fdef->exports[i].its_name)
2396
	    free (fdef->exports[i].its_name);
2397
	}
2398
      free (fdef->exports);
2399
    }
2400
 
2401
  if (fdef->imports)
2402
    {
2403
      for (i = 0; i < fdef->num_imports; i++)
2404
	{
2405
	  if (fdef->imports[i].internal_name
2406
	      && fdef->imports[i].internal_name != fdef->imports[i].name)
2407
	    free (fdef->imports[i].internal_name);
2408
	  if (fdef->imports[i].name)
2409
	    free (fdef->imports[i].name);
2410
	  if (fdef->imports[i].its_name)
2411
	    free (fdef->imports[i].its_name);
2412
	}
2413
      free (fdef->imports);
2414
    }
2415
 
2416
  while (fdef->modules)
2417
    {
2418
      def_file_module *m = fdef->modules;
2419
 
2420
      fdef->modules = fdef->modules->next;
2421
      free (m);
2422
    }
2423
 
2424
  while (fdef->aligncomms)
2425
    {
2426
      def_file_aligncomm *c = fdef->aligncomms;
2427
 
2428
      fdef->aligncomms = fdef->aligncomms->next;
2429
      free (c->symbol_name);
2430
      free (c);
2431
    }
2432
 
2433
  free (fdef);
2434
}
2435
 
2436
#ifdef DEF_FILE_PRINT
2437
void
2438
def_file_print (FILE *file, def_file *fdef)
2439
{
2440
  int i;
2441
 
2442
  fprintf (file, ">>>> def_file at 0x%08x\n", fdef);
2443
  if (fdef->name)
2444
    fprintf (file, "  name: %s\n", fdef->name ? fdef->name : "(unspecified)");
2445
  if (fdef->is_dll != -1)
2446
    fprintf (file, "  is dll: %s\n", fdef->is_dll ? "yes" : "no");
2447
  if (fdef->base_address != (bfd_vma) -1)
2448
    {
2449
      fprintf (file, "  base address: 0x");
2450
      fprintf_vma (file, fdef->base_address);
2451
      fprintf (file, "\n");
2452
    }
2453
  if (fdef->description)
2454
    fprintf (file, "  description: `%s'\n", fdef->description);
2455
  if (fdef->stack_reserve != -1)
2456
    fprintf (file, "  stack reserve: 0x%08x\n", fdef->stack_reserve);
2457
  if (fdef->stack_commit != -1)
2458
    fprintf (file, "  stack commit: 0x%08x\n", fdef->stack_commit);
2459
  if (fdef->heap_reserve != -1)
2460
    fprintf (file, "  heap reserve: 0x%08x\n", fdef->heap_reserve);
2461
  if (fdef->heap_commit != -1)
2462
    fprintf (file, "  heap commit: 0x%08x\n", fdef->heap_commit);
2463
 
2464
  if (fdef->num_section_defs > 0)
2465
    {
2466
      fprintf (file, "  section defs:\n");
2467
 
2468
      for (i = 0; i < fdef->num_section_defs; i++)
2469
	{
2470
	  fprintf (file, "    name: `%s', class: `%s', flags:",
2471
		   fdef->section_defs[i].name, fdef->section_defs[i].class);
2472
	  if (fdef->section_defs[i].flag_read)
2473
	    fprintf (file, " R");
2474
	  if (fdef->section_defs[i].flag_write)
2475
	    fprintf (file, " W");
2476
	  if (fdef->section_defs[i].flag_execute)
2477
	    fprintf (file, " X");
2478
	  if (fdef->section_defs[i].flag_shared)
2479
	    fprintf (file, " S");
2480
	  fprintf (file, "\n");
2481
	}
2482
    }
2483
 
2484
  if (fdef->num_exports > 0)
2485
    {
2486
      fprintf (file, "  exports:\n");
2487
 
2488
      for (i = 0; i < fdef->num_exports; i++)
2489
	{
2490
	  fprintf (file, "    name: `%s', int: `%s', ordinal: %d, flags:",
2491
		   fdef->exports[i].name, fdef->exports[i].internal_name,
2492
		   fdef->exports[i].ordinal);
2493
	  if (fdef->exports[i].flag_private)
2494
	    fprintf (file, " P");
2495
	  if (fdef->exports[i].flag_constant)
2496
	    fprintf (file, " C");
2497
	  if (fdef->exports[i].flag_noname)
2498
	    fprintf (file, " N");
2499
	  if (fdef->exports[i].flag_data)
2500
	    fprintf (file, " D");
2501
	  fprintf (file, "\n");
2502
	}
2503
    }
2504
 
2505
  if (fdef->num_imports > 0)
2506
    {
2507
      fprintf (file, "  imports:\n");
2508
 
2509
      for (i = 0; i < fdef->num_imports; i++)
2510
	{
2511
	  fprintf (file, "    int: %s, from: `%s', name: `%s', ordinal: %d\n",
2512
		   fdef->imports[i].internal_name,
2513
		   fdef->imports[i].module,
2514
		   fdef->imports[i].name,
2515
		   fdef->imports[i].ordinal);
2516
	}
2517
    }
2518
 
2519
  if (fdef->version_major != -1)
2520
    fprintf (file, "  version: %d.%d\n", fdef->version_major, fdef->version_minor);
2521
 
2522
  fprintf (file, "<<<< def_file at 0x%08x\n", fdef);
2523
}
2524
#endif
2525
 
2526
/* Helper routine to check for identity of string pointers,
2527
   which might be NULL.  */
2528
 
2529
static int
2530
are_names_equal (const char *s1, const char *s2)
2531
{
2532
  if (!s1 && !s2)
2533
    return 0;
2534
  if (!s1 || !s2)
2535
    return (!s1 ? -1 : 1);
2536
  return strcmp (s1, s2);
2537
}
2538
 
2539
static int
2540
cmp_export_elem (const def_file_export *e, const char *ex_name,
2541
		 const char *in_name, const char *its_name,
2542
		 int ord)
2543
{
2544
  int r;
2545
 
2546
  if ((r = are_names_equal (ex_name, e->name)) != 0)
2547
    return r;
2548
  if ((r = are_names_equal (in_name, e->internal_name)) != 0)
2549
    return r;
2550
  if ((r = are_names_equal (its_name, e->its_name)) != 0)
2551
    return r;
2552
  return (ord - e->ordinal);
2553
}
2554
 
2555
/* Search the position of the identical element, or returns the position
2556
   of the next higher element. If last valid element is smaller, then MAX
2557
   is returned.  */
2558
 
2559
static int
2560
find_export_in_list (def_file_export *b, int max,
2561
		     const char *ex_name, const char *in_name,
2562
		     const char *its_name, int ord, int *is_ident)
2563
{
2564
  int e, l, r, p;
2565
 
2566
  *is_ident = 0;
2567
  if (!max)
2568
    return 0;
2569
  if ((e = cmp_export_elem (b, ex_name, in_name, its_name, ord)) <= 0)
2570
    {
2571
      if (!e)
2572
        *is_ident = 1;
2573
      return 0;
2574
    }
2575
  if (max == 1)
2576
    return 1;
2577
  if ((e = cmp_export_elem (b + (max - 1), ex_name, in_name, its_name, ord)) > 0)
2578
    return max;
2579
  else if (!e || max == 2)
2580
    {
2581
      if (!e)
2582
	*is_ident = 1;
2583
      return max - 1;
2584
    }
2585
  l = 0; r = max - 1;
2586
  while (l < r)
2587
    {
2588
      p = (l + r) / 2;
2589
      e = cmp_export_elem (b + p, ex_name, in_name, its_name, ord);
2590
      if (!e)
2591
        {
2592
          *is_ident = 1;
2593
          return p;
2594
        }
2595
      else if (e < 0)
2596
        r = p - 1;
2597
      else if (e > 0)
2598
        l = p + 1;
2599
    }
2600
  if ((e = cmp_export_elem (b + l, ex_name, in_name, its_name, ord)) > 0)
2601
    ++l;
2602
  else if (!e)
2603
    *is_ident = 1;
2604
  return l;
2605
}
2606
 
2607
def_file_export *
2608
def_file_add_export (def_file *fdef,
2609
		     const char *external_name,
2610
		     const char *internal_name,
2611
		     int ordinal,
2612
		     const char *its_name,
2613
		     int *is_dup)
2614
{
2615
  def_file_export *e;
2616
  int pos;
2617
  int max_exports = ROUND_UP(fdef->num_exports, 32);
2618
 
2619
  if (internal_name && !external_name)
2620
    external_name = internal_name;
2621
  if (external_name && !internal_name)
2622
    internal_name = external_name;
2623
 
2624
  /* We need to avoid duplicates.  */
2625
  *is_dup = 0;
2626
  pos = find_export_in_list (fdef->exports, fdef->num_exports,
2627
		     external_name, internal_name,
2628
		     its_name, ordinal, is_dup);
2629
 
2630
  if (*is_dup != 0)
2631
    return (fdef->exports + pos);
2632
 
2633
  if (fdef->num_exports >= max_exports)
2634
    {
2635
      max_exports = ROUND_UP(fdef->num_exports + 1, 32);
2636
      if (fdef->exports)
2637
	fdef->exports = xrealloc (fdef->exports,
2638
				 max_exports * sizeof (def_file_export));
2639
      else
2640
	fdef->exports = xmalloc (max_exports * sizeof (def_file_export));
2641
    }
2642
 
2643
  e = fdef->exports + pos;
2644
  if (pos != fdef->num_exports)
2645
    memmove (&e[1], e, (sizeof (def_file_export) * (fdef->num_exports - pos)));
2646
  memset (e, 0, sizeof (def_file_export));
2647
  e->name = xstrdup (external_name);
2648
  e->internal_name = xstrdup (internal_name);
2649
  e->its_name = (its_name ? xstrdup (its_name) : NULL);
2650
  e->ordinal = ordinal;
2651
  fdef->num_exports++;
2652
  return e;
2653
}
2654
 
2655
def_file_module *
2656
def_get_module (def_file *fdef, const char *name)
2657
{
2658
  def_file_module *s;
2659
 
2660
  for (s = fdef->modules; s; s = s->next)
2661
    if (strcmp (s->name, name) == 0)
2662
      return s;
2663
 
2664
  return NULL;
2665
}
2666
 
2667
static def_file_module *
2668
def_stash_module (def_file *fdef, const char *name)
2669
{
2670
  def_file_module *s;
2671
 
2672
  if ((s = def_get_module (fdef, name)) != NULL)
2673
      return s;
2674
  s = xmalloc (sizeof (def_file_module) + strlen (name));
2675
  s->next = fdef->modules;
2676
  fdef->modules = s;
2677
  s->user_data = 0;
2678
  strcpy (s->name, name);
2679
  return s;
2680
}
2681
 
2682
static int
2683
cmp_import_elem (const def_file_import *e, const char *ex_name,
2684
		 const char *in_name, const char *module,
2685
		 int ord)
2686
{
2687
  int r;
2688
 
2689
  if ((r = are_names_equal (module, (e->module ? e->module->name : NULL))))
2690
    return r;
2691
  if ((r = are_names_equal (ex_name, e->name)) != 0)
2692
    return r;
2693
  if ((r = are_names_equal (in_name, e->internal_name)) != 0)
2694
    return r;
2695
  if (ord != e->ordinal)
2696
    return (ord < e->ordinal ? -1 : 1);
2697
  return 0;
2698
}
2699
 
2700
/* Search the position of the identical element, or returns the position
2701
   of the next higher element. If last valid element is smaller, then MAX
2702
   is returned.  */
2703
 
2704
static int
2705
find_import_in_list (def_file_import *b, int max,
2706
		     const char *ex_name, const char *in_name,
2707
		     const char *module, int ord, int *is_ident)
2708
{
2709
  int e, l, r, p;
2710
 
2711
  *is_ident = 0;
2712
  if (!max)
2713
    return 0;
2714
  if ((e = cmp_import_elem (b, ex_name, in_name, module, ord)) <= 0)
2715
    {
2716
      if (!e)
2717
        *is_ident = 1;
2718
      return 0;
2719
    }
2720
  if (max == 1)
2721
    return 1;
2722
  if ((e = cmp_import_elem (b + (max - 1), ex_name, in_name, module, ord)) > 0)
2723
    return max;
2724
  else if (!e || max == 2)
2725
    {
2726
      if (!e)
2727
        *is_ident = 1;
2728
      return max - 1;
2729
    }
2730
  l = 0; r = max - 1;
2731
  while (l < r)
2732
    {
2733
      p = (l + r) / 2;
2734
      e = cmp_import_elem (b + p, ex_name, in_name, module, ord);
2735
      if (!e)
2736
        {
2737
          *is_ident = 1;
2738
          return p;
2739
        }
2740
      else if (e < 0)
2741
        r = p - 1;
2742
      else if (e > 0)
2743
        l = p + 1;
2744
    }
2745
  if ((e = cmp_import_elem (b + l, ex_name, in_name, module, ord)) > 0)
2746
    ++l;
2747
  else if (!e)
2748
    *is_ident = 1;
2749
  return l;
2750
}
2751
 
2752
def_file_import *
2753
def_file_add_import (def_file *fdef,
2754
		     const char *name,
2755
		     const char *module,
2756
		     int ordinal,
2757
		     const char *internal_name,
2758
		     const char *its_name,
2759
		     int *is_dup)
2760
{
2761
  def_file_import *i;
2762
  int pos;
2763
  int max_imports = ROUND_UP (fdef->num_imports, 16);
2764
 
2765
  /* We need to avoid here duplicates.  */
2766
  *is_dup = 0;
2767
  pos = find_import_in_list (fdef->imports, fdef->num_imports,
2768
			     name,
2769
			     (!internal_name ? name : internal_name),
2770
			     module, ordinal, is_dup);
2771
  if (*is_dup != 0)
2772
    return fdef->imports + pos;
2773
 
2774
  if (fdef->num_imports >= max_imports)
2775
    {
2776
      max_imports = ROUND_UP (fdef->num_imports+1, 16);
2777
 
2778
      if (fdef->imports)
2779
	fdef->imports = xrealloc (fdef->imports,
2780
				 max_imports * sizeof (def_file_import));
2781
      else
2782
	fdef->imports = xmalloc (max_imports * sizeof (def_file_import));
2783
    }
2784
  i = fdef->imports + pos;
2785
  if (pos != fdef->num_imports)
2786
    memmove (&i[1], i, (sizeof (def_file_import) * (fdef->num_imports - pos)));
2787
  memset (i, 0, sizeof (def_file_import));
2788
  if (name)
2789
    i->name = xstrdup (name);
2790
  if (module)
2791
    i->module = def_stash_module (fdef, module);
2792
  i->ordinal = ordinal;
2793
  if (internal_name)
2794
    i->internal_name = xstrdup (internal_name);
2795
  else
2796
    i->internal_name = i->name;
2797
  i->its_name = (its_name ? xstrdup (its_name) : NULL);
2798
  fdef->num_imports++;
2799
 
2800
  return i;
2801
}
2802
 
2803
struct
2804
{
2805
  char *param;
2806
  int token;
2807
}
2808
diropts[] =
2809
{
2810
  { "-heap", HEAPSIZE },
2811
  { "-stack", STACKSIZE_K },
2812
  { "-attr", SECTIONS },
2813
  { "-export", EXPORTS },
2814
  { "-aligncomm", ALIGNCOMM },
2815
  { 0, 0 }
2816
};
2817
 
2818
void
2819
def_file_add_directive (def_file *my_def, const char *param, int len)
2820
{
2821
  def_file *save_def = def;
2822
  const char *pend = param + len;
2823
  char * tend = (char *) param;
2824
  int i;
2825
 
2826
  def = my_def;
2827
 
2828
  while (param < pend)
2829
    {
2830
      while (param < pend
2831
	     && (ISSPACE (*param) || *param == '\n' || *param == 0))
2832
	param++;
2833
 
2834
      if (param == pend)
2835
	break;
2836
 
2837
      /* Scan forward until we encounter any of:
2838
          - the end of the buffer
2839
	  - the start of a new option
2840
	  - a newline seperating options
2841
          - a NUL seperating options.  */
2842
      for (tend = (char *) (param + 1);
2843
	   (tend < pend
2844
	    && !(ISSPACE (tend[-1]) && *tend == '-')
2845
	    && *tend != '\n' && *tend != 0);
2846
	   tend++)
2847
	;
2848
 
2849
      for (i = 0; diropts[i].param; i++)
2850
	{
2851
	  len = strlen (diropts[i].param);
2852
 
2853
	  if (tend - param >= len
2854
	      && strncmp (param, diropts[i].param, len) == 0
2855
	      && (param[len] == ':' || param[len] == ' '))
2856
	    {
2857
	      lex_parse_string_end = tend;
2858
	      lex_parse_string = param + len + 1;
2859
	      lex_forced_token = diropts[i].token;
2860
	      saw_newline = 0;
2861
	      if (def_parse ())
2862
		continue;
2863
	      break;
2864
	    }
2865
	}
2866
 
2867
      if (!diropts[i].param)
2868
	{
2869
	  if (tend < pend)
2870
	    {
2871
	      char saved;
2872
 
2873
	      saved = * tend;
2874
	      * tend = 0;
2875
	      /* xgettext:c-format */
2876
	      einfo (_("Warning: .drectve `%s' unrecognized\n"), param);
2877
	      * tend = saved;
2878
	    }
2879
	  else
2880
	    {
2881
	      einfo (_("Warning: corrupt .drectve at end of def file\n"));
2882
	    }
2883
	}
2884
 
2885
      lex_parse_string = 0;
2886
      param = tend;
2887
    }
2888
 
2889
  def = save_def;
2890
  def_pool_free ();
2891
}
2892
 
2893
/* Parser Callbacks.  */
2894
 
2895
static void
2896
def_image_name (const char *name, bfd_vma base, int is_dll)
2897
{
2898
  /* If a LIBRARY or NAME statement is specified without a name, there is nothing
2899
     to do here.  We retain the output filename specified on command line.  */
2900
  if (*name)
2901
    {
2902
      const char* image_name = lbasename (name);
2903
 
2904
      if (image_name != name)
2905
	einfo ("%s:%d: Warning: path components stripped from %s, '%s'\n",
2906
	       def_filename, linenumber, is_dll ? "LIBRARY" : "NAME",
2907
	       name);
2908
      if (def->name)
2909
	free (def->name);
2910
      /* Append the default suffix, if none specified.  */
2911
      if (strchr (image_name, '.') == 0)
2912
	{
2913
	  const char * suffix = is_dll ? ".dll" : ".exe";
2914
 
2915
	  def->name = xmalloc (strlen (image_name) + strlen (suffix) + 1);
2916
	  sprintf (def->name, "%s%s", image_name, suffix);
2917
        }
2918
      else
2919
	def->name = xstrdup (image_name);
2920
    }
2921
 
2922
  /* Honor a BASE address statement, even if LIBRARY string is empty.  */
2923
  def->base_address = base;
2924
  def->is_dll = is_dll;
2925
}
2926
 
2927
static void
2928
def_description (const char *text)
2929
{
2930
  int len = def->description ? strlen (def->description) : 0;
2931
 
2932
  len += strlen (text) + 1;
2933
  if (def->description)
2934
    {
2935
      def->description = xrealloc (def->description, len);
2936
      strcat (def->description, text);
2937
    }
2938
  else
2939
    {
2940
      def->description = xmalloc (len);
2941
      strcpy (def->description, text);
2942
    }
2943
}
2944
 
2945
static void
2946
def_stacksize (int reserve, int commit)
2947
{
2948
  def->stack_reserve = reserve;
2949
  def->stack_commit = commit;
2950
}
2951
 
2952
static void
2953
def_heapsize (int reserve, int commit)
2954
{
2955
  def->heap_reserve = reserve;
2956
  def->heap_commit = commit;
2957
}
2958
 
2959
static void
2960
def_section (const char *name, int attr)
2961
{
2962
  def_file_section *s;
2963
  int max_sections = ROUND_UP (def->num_section_defs, 4);
2964
 
2965
  if (def->num_section_defs >= max_sections)
2966
    {
2967
      max_sections = ROUND_UP (def->num_section_defs+1, 4);
2968
 
2969
      if (def->section_defs)
2970
	def->section_defs = xrealloc (def->section_defs,
2971
				      max_sections * sizeof (def_file_import));
2972
      else
2973
	def->section_defs = xmalloc (max_sections * sizeof (def_file_import));
2974
    }
2975
  s = def->section_defs + def->num_section_defs;
2976
  memset (s, 0, sizeof (def_file_section));
2977
  s->name = xstrdup (name);
2978
  if (attr & 1)
2979
    s->flag_read = 1;
2980
  if (attr & 2)
2981
    s->flag_write = 1;
2982
  if (attr & 4)
2983
    s->flag_execute = 1;
2984
  if (attr & 8)
2985
    s->flag_shared = 1;
2986
 
2987
  def->num_section_defs++;
2988
}
2989
 
2990
static void
2991
def_section_alt (const char *name, const char *attr)
2992
{
2993
  int aval = 0;
2994
 
2995
  for (; *attr; attr++)
2996
    {
2997
      switch (*attr)
2998
	{
2999
	case 'R':
3000
	case 'r':
3001
	  aval |= 1;
3002
	  break;
3003
	case 'W':
3004
	case 'w':
3005
	  aval |= 2;
3006
	  break;
3007
	case 'X':
3008
	case 'x':
3009
	  aval |= 4;
3010
	  break;
3011
	case 'S':
3012
	case 's':
3013
	  aval |= 8;
3014
	  break;
3015
	}
3016
    }
3017
  def_section (name, aval);
3018
}
3019
 
3020
static void
3021
def_exports (const char *external_name,
3022
	     const char *internal_name,
3023
	     int ordinal,
3024
	     int flags,
3025
	     const char *its_name)
3026
{
3027
  def_file_export *dfe;
3028
  int is_dup = 0;
3029
 
3030
  if (!internal_name && external_name)
3031
    internal_name = external_name;
3032
#if TRACE
3033
  printf ("def_exports, ext=%s int=%s\n", external_name, internal_name);
3034
#endif
3035
 
3036
  dfe = def_file_add_export (def, external_name, internal_name, ordinal,
3037
			     its_name, &is_dup);
3038
 
3039
  /* We might check here for flag redefinition and warn.  For now we
3040
     ignore duplicates silently.  */
3041
  if (is_dup)
3042
    return;
3043
 
3044
  if (flags & 1)
3045
    dfe->flag_noname = 1;
3046
  if (flags & 2)
3047
    dfe->flag_constant = 1;
3048
  if (flags & 4)
3049
    dfe->flag_data = 1;
3050
  if (flags & 8)
3051
    dfe->flag_private = 1;
3052
}
3053
 
3054
static void
3055
def_import (const char *internal_name,
3056
	    const char *module,
3057
	    const char *dllext,
3058
	    const char *name,
3059
	    int ordinal,
3060
	    const char *its_name)
3061
{
3062
  char *buf = 0;
3063
  const char *ext = dllext ? dllext : "dll";
3064
  int is_dup = 0;
3065
 
3066
  buf = xmalloc (strlen (module) + strlen (ext) + 2);
3067
  sprintf (buf, "%s.%s", module, ext);
3068
  module = buf;
3069
 
3070
  def_file_add_import (def, name, module, ordinal, internal_name, its_name,
3071
		       &is_dup);
3072
  free (buf);
3073
}
3074
 
3075
static void
3076
def_version (int major, int minor)
3077
{
3078
  def->version_major = major;
3079
  def->version_minor = minor;
3080
}
3081
 
3082
static void
3083
def_directive (char *str)
3084
{
3085
  struct directive *d = xmalloc (sizeof (struct directive));
3086
 
3087
  d->next = directives;
3088
  directives = d;
3089
  d->name = xstrdup (str);
3090
  d->len = strlen (str);
3091
}
3092
 
3093
static void
3094
def_aligncomm (char *str, int align)
3095
{
3096
  def_file_aligncomm *c, *p;
3097
 
3098
  p = NULL;
3099
  c = def->aligncomms;
3100
  while (c != NULL)
3101
    {
3102
      int e = strcmp (c->symbol_name, str);
3103
      if (!e)
3104
	{
3105
	  /* Not sure if we want to allow here duplicates with
3106
	     different alignments, but for now we keep them.  */
3107
	  e = (int) c->alignment - align;
3108
	  if (!e)
3109
	    return;
3110
	}
3111
      if (e > 0)
3112
        break;
3113
      c = (p = c)->next;
3114
    }
3115
 
3116
  c = xmalloc (sizeof (def_file_aligncomm));
3117
  c->symbol_name = xstrdup (str);
3118
  c->alignment = (unsigned int) align;
3119
  if (!p)
3120
    {
3121
      c->next = def->aligncomms;
3122
      def->aligncomms = c;
3123
    }
3124
  else
3125
    {
3126
      c->next = p->next;
3127
      p->next = c;
3128
    }
3129
}
3130
 
3131
static int
3132
def_error (const char *err)
3133
{
3134
  einfo ("%P: %s:%d: %s\n",
3135
	 def_filename ? def_filename : "", linenumber, err);
3136
  return 0;
3137
}
3138
 
3139
 
3140
/* Lexical Scanner.  */
3141
 
3142
#undef TRACE
3143
#define TRACE 0
3144
 
3145
/* Never freed, but always reused as needed, so no real leak.  */
3146
static char *buffer = 0;
3147
static int buflen = 0;
3148
static int bufptr = 0;
3149
 
3150
static void
3151
put_buf (char c)
3152
{
3153
  if (bufptr == buflen)
3154
    {
3155
      buflen += 50;		/* overly reasonable, eh?  */
3156
      if (buffer)
3157
	buffer = xrealloc (buffer, buflen + 1);
3158
      else
3159
	buffer = xmalloc (buflen + 1);
3160
    }
3161
  buffer[bufptr++] = c;
3162
  buffer[bufptr] = 0;		/* not optimal, but very convenient.  */
3163
}
3164
 
3165
static struct
3166
{
3167
  char *name;
3168
  int token;
3169
}
3170
tokens[] =
3171
{
3172
  { "BASE", BASE },
3173
  { "CODE", CODE },
3174
  { "CONSTANT", CONSTANTU },
3175
  { "constant", CONSTANTL },
3176
  { "DATA", DATAU },
3177
  { "data", DATAL },
3178
  { "DESCRIPTION", DESCRIPTION },
3179
  { "DIRECTIVE", DIRECTIVE },
3180
  { "EXECUTE", EXECUTE },
3181
  { "EXPORTS", EXPORTS },
3182
  { "HEAPSIZE", HEAPSIZE },
3183
  { "IMPORTS", IMPORTS },
3184
  { "LIBRARY", LIBRARY },
3185
  { "NAME", NAME },
3186
  { "NONAME", NONAMEU },
3187
  { "noname", NONAMEL },
3188
  { "PRIVATE", PRIVATEU },
3189
  { "private", PRIVATEL },
3190
  { "READ", READ },
3191
  { "SECTIONS", SECTIONS },
3192
  { "SEGMENTS", SECTIONS },
3193
  { "SHARED", SHARED },
3194
  { "STACKSIZE", STACKSIZE_K },
3195
  { "VERSION", VERSIONK },
3196
  { "WRITE", WRITE },
3197
  { 0, 0 }
3198
};
3199
 
3200
static int
3201
def_getc (void)
3202
{
3203
  int rv;
3204
 
3205
  if (lex_parse_string)
3206
    {
3207
      if (lex_parse_string >= lex_parse_string_end)
3208
	rv = EOF;
3209
      else
3210
	rv = *lex_parse_string++;
3211
    }
3212
  else
3213
    {
3214
      rv = fgetc (the_file);
3215
    }
3216
  if (rv == '\n')
3217
    saw_newline = 1;
3218
  return rv;
3219
}
3220
 
3221
static int
3222
def_ungetc (int c)
3223
{
3224
  if (lex_parse_string)
3225
    {
3226
      lex_parse_string--;
3227
      return c;
3228
    }
3229
  else
3230
    return ungetc (c, the_file);
3231
}
3232
 
3233
static int
3234
def_lex (void)
3235
{
3236
  int c, i, q;
3237
 
3238
  if (lex_forced_token)
3239
    {
3240
      i = lex_forced_token;
3241
      lex_forced_token = 0;
3242
#if TRACE
3243
      printf ("lex: forcing token %d\n", i);
3244
#endif
3245
      return i;
3246
    }
3247
 
3248
  c = def_getc ();
3249
 
3250
  /* Trim leading whitespace.  */
3251
  while (c != EOF && (c == ' ' || c == '\t') && saw_newline)
3252
    c = def_getc ();
3253
 
3254
  if (c == EOF)
3255
    {
3256
#if TRACE
3257
      printf ("lex: EOF\n");
3258
#endif
3259
      return 0;
3260
    }
3261
 
3262
  if (saw_newline && c == ';')
3263
    {
3264
      do
3265
	{
3266
	  c = def_getc ();
3267
	}
3268
      while (c != EOF && c != '\n');
3269
      if (c == '\n')
3270
	return def_lex ();
3271
      return 0;
3272
    }
3273
 
3274
  /* Must be something else.  */
3275
  saw_newline = 0;
3276
 
3277
  if (ISDIGIT (c))
3278
    {
3279
      bufptr = 0;
3280
      while (c != EOF && (ISXDIGIT (c) || (c == 'x')))
3281
	{
3282
	  put_buf (c);
3283
	  c = def_getc ();
3284
	}
3285
      if (c != EOF)
3286
	def_ungetc (c);
3287
      yylval.digits = def_pool_strdup (buffer);
3288
#if TRACE
3289
      printf ("lex: `%s' returns DIGITS\n", buffer);
3290
#endif
3291
      return DIGITS;
3292
    }
3293
 
3294
  if (ISALPHA (c) || strchr ("$:-_?@", c))
3295
    {
3296
      bufptr = 0;
3297
      q = c;
3298
      put_buf (c);
3299
      c = def_getc ();
3300
 
3301
      if (q == '@')
3302
	{
3303
          if (ISBLANK (c) ) /* '@' followed by whitespace.  */
3304
	    return (q);
3305
          else if (ISDIGIT (c)) /* '@' followed by digit.  */
3306
            {
3307
	      def_ungetc (c);
3308
              return (q);
3309
	    }
3310
#if TRACE
3311
	  printf ("lex: @ returns itself\n");
3312
#endif
3313
	}
3314
 
3315
      while (c != EOF && (ISALNUM (c) || strchr ("$:-_?/@<>", c)))
3316
	{
3317
	  put_buf (c);
3318
	  c = def_getc ();
3319
	}
3320
      if (c != EOF)
3321
	def_ungetc (c);
3322
      if (ISALPHA (q)) /* Check for tokens.  */
3323
	{
3324
          for (i = 0; tokens[i].name; i++)
3325
	    if (strcmp (tokens[i].name, buffer) == 0)
3326
	      {
3327
#if TRACE
3328
	        printf ("lex: `%s' is a string token\n", buffer);
3329
#endif
3330
	        return tokens[i].token;
3331
	      }
3332
	}
3333
#if TRACE
3334
      printf ("lex: `%s' returns ID\n", buffer);
3335
#endif
3336
      yylval.id = def_pool_strdup (buffer);
3337
      return ID;
3338
    }
3339
 
3340
  if (c == '\'' || c == '"')
3341
    {
3342
      q = c;
3343
      c = def_getc ();
3344
      bufptr = 0;
3345
 
3346
      while (c != EOF && c != q)
3347
	{
3348
	  put_buf (c);
3349
	  c = def_getc ();
3350
	}
3351
      yylval.id = def_pool_strdup (buffer);
3352
#if TRACE
3353
      printf ("lex: `%s' returns ID\n", buffer);
3354
#endif
3355
      return ID;
3356
    }
3357
 
3358
  if ( c == '=')
3359
    {
3360
      c = def_getc ();
3361
      if (c == '=')
3362
        {
3363
#if TRACE
3364
          printf ("lex: `==' returns EQUAL\n");
3365
#endif
3366
		  return EQUAL;
3367
        }
3368
      def_ungetc (c);
3369
#if TRACE
3370
      printf ("lex: `=' returns itself\n");
3371
#endif
3372
      return '=';
3373
    }
3374
  if (c == '.' || c == ',')
3375
    {
3376
#if TRACE
3377
      printf ("lex: `%c' returns itself\n", c);
3378
#endif
3379
      return c;
3380
    }
3381
 
3382
  if (c == '\n')
3383
    {
3384
      linenumber++;
3385
      saw_newline = 1;
3386
    }
3387
 
3388
  /*printf ("lex: 0x%02x ignored\n", c); */
3389
  return def_lex ();
3390
}
3391
 
3392
static char *
3393
def_pool_alloc (size_t sz)
3394
{
3395
  def_pool_str *e;
3396
 
3397
  e = (def_pool_str *) xmalloc (sizeof (def_pool_str) + sz);
3398
  e->next = pool_strs;
3399
  pool_strs = e;
3400
  return e->data;
3401
}
3402
 
3403
static char *
3404
def_pool_strdup (const char *str)
3405
{
3406
  char *s;
3407
  size_t len;
3408
  if (!str)
3409
    return NULL;
3410
  len = strlen (str) + 1;
3411
  s = def_pool_alloc (len);
3412
  memcpy (s, str, len);
3413
  return s;
3414
}
3415
 
3416
static void
3417
def_pool_free (void)
3418
{
3419
  def_pool_str *p;
3420
  while ((p = pool_strs) != NULL)
3421
    {
3422
      pool_strs = p->next;
3423
      free (p);
3424
    }
3425
}
3426