1 
2 /*  A Bison parser, made from nlmheader.y
3     by GNU Bison version 1.28  */
4 
5 #define YYBISON 1  /* Identify Bison output.  */
6 
7 #define	CHECK	257
8 #define	CODESTART	258
9 #define	COPYRIGHT	259
10 #define	CUSTOM	260
11 #define	DATE	261
12 #define	DEBUG	262
13 #define	DESCRIPTION	263
14 #define	EXIT	264
15 #define	EXPORT	265
16 #define	FLAG_ON	266
17 #define	FLAG_OFF	267
18 #define	FULLMAP	268
19 #define	HELP	269
20 #define	IMPORT	270
21 #define	INPUT	271
22 #define	MAP	272
23 #define	MESSAGES	273
24 #define	MODULE	274
25 #define	MULTIPLE	275
26 #define	OS_DOMAIN	276
27 #define	OUTPUT	277
28 #define	PSEUDOPREEMPTION	278
29 #define	REENTRANT	279
30 #define	SCREENNAME	280
31 #define	SHARELIB	281
32 #define	STACK	282
33 #define	START	283
34 #define	SYNCHRONIZE	284
35 #define	THREADNAME	285
36 #define	TYPE	286
37 #define	VERBOSE	287
38 #define	VERSIONK	288
39 #define	XDCDATA	289
40 #define	STRING	290
41 #define	QUOTED_STRING	291
42 
43 #line 1 "nlmheader.y"
44 /* nlmheader.y - parse NLM header specification keywords.
45      Copyright 1993, 1994, 1995, 1997, 1998 Free Software Foundation, Inc.
46 
47 This file is part of GNU Binutils.
48 
49 This program is free software; you can redistribute it and/or modify
50 it under the terms of the GNU General Public License as published by
51 the Free Software Foundation; either version 2 of the License, or
52 (at your option) any later version.
53 
54 This program is distributed in the hope that it will be useful,
55 but WITHOUT ANY WARRANTY; without even the implied warranty of
56 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57 GNU General Public License for more details.
58 
59 You should have received a copy of the GNU General Public License
60 along with this program; if not, write to the Free Software
61 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
62 
63 /* Written by Ian Lance Taylor <ian@cygnus.com>.
64 
65    This bison file parses the commands recognized by the NetWare NLM
66    linker, except for lists of object files.  It stores the
67    information in global variables.
68 
69    This implementation is based on the description in the NetWare Tool
70    Maker Specification manual, edition 1.0.  */
71 
72 #include <ansidecl.h>
73 #include <stdio.h>
74 #include <ctype.h>
75 #include "bfd.h"
76 #include "bucomm.h"
77 #include "nlm/common.h"
78 #include "nlm/internal.h"
79 #include "nlmconv.h"
80 
81 /* Information is stored in the structures pointed to by these
82    variables.  */
83 
84 Nlm_Internal_Fixed_Header *fixed_hdr;
85 Nlm_Internal_Variable_Header *var_hdr;
86 Nlm_Internal_Version_Header *version_hdr;
87 Nlm_Internal_Copyright_Header *copyright_hdr;
88 Nlm_Internal_Extended_Header *extended_hdr;
89 
90 /* Procedure named by CHECK.  */
91 char *check_procedure;
92 /* File named by CUSTOM.  */
93 char *custom_file;
94 /* Whether to generate debugging information (DEBUG).  */
95 boolean debug_info;
96 /* Procedure named by EXIT.  */
97 char *exit_procedure;
98 /* Exported symbols (EXPORT).  */
99 struct string_list *export_symbols;
100 /* List of files from INPUT.  */
101 struct string_list *input_files;
102 /* Map file name (MAP, FULLMAP).  */
103 char *map_file;
104 /* Whether a full map has been requested (FULLMAP).  */
105 boolean full_map;
106 /* File named by HELP.  */
107 char *help_file;
108 /* Imported symbols (IMPORT).  */
109 struct string_list *import_symbols;
110 /* File named by MESSAGES.  */
111 char *message_file;
112 /* Autoload module list (MODULE).  */
113 struct string_list *modules;
114 /* File named by OUTPUT.  */
115 char *output_file;
116 /* File named by SHARELIB.  */
117 char *sharelib_file;
118 /* Start procedure name (START).  */
119 char *start_procedure;
120 /* VERBOSE.  */
121 boolean verbose;
122 /* RPC description file (XDCDATA).  */
123 char *rpc_file;
124 
125 /* The number of serious errors that have occurred.  */
126 int parse_errors;
127 
128 /* The current symbol prefix when reading a list of import or export
129    symbols.  */
130 static char *symbol_prefix;
131 
132 /* Parser error message handler.  */
133 #define yyerror(msg) nlmheader_error (msg);
134 
135 /* Local functions.  */
136 static int yylex PARAMS ((void));
137 static void nlmlex_file_push PARAMS ((const char *));
138 static boolean nlmlex_file_open PARAMS ((const char *));
139 static int nlmlex_buf_init PARAMS ((void));
140 static char nlmlex_buf_add PARAMS ((int));
141 static long nlmlex_get_number PARAMS ((const char *));
142 static void nlmheader_identify PARAMS ((void));
143 static void nlmheader_warn PARAMS ((const char *, int));
144 static void nlmheader_error PARAMS ((const char *));
145 static struct string_list * string_list_cons PARAMS ((char *,
146 						      struct string_list *));
147 static struct string_list * string_list_append PARAMS ((struct string_list *,
148 							struct string_list *));
149 static struct string_list * string_list_append1 PARAMS ((struct string_list *,
150 							 char *));
151 static char *xstrdup PARAMS ((const char *));
152 
153 
154 #line 112 "nlmheader.y"
155 typedef union
156 {
157   char *string;
158   struct string_list *list;
159 } YYSTYPE;
160 #include <stdio.h>
161 
162 #ifndef __cplusplus
163 #ifndef __STDC__
164 #define const
165 #endif
166 #endif
167 
168 
169 
170 #define	YYFINAL		82
171 #define	YYFLAG		-32768
172 #define	YYNTBASE	40
173 
174 #define YYTRANSLATE(x) ((unsigned)(x) <= 291 ? yytranslate[x] : 50)
175 
176 static const char yytranslate[] = {     0,
177      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
178      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
179      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
180      2,     2,     2,     2,     2,     2,     2,     2,     2,    38,
181     39,     2,     2,     2,     2,     2,     2,     2,     2,     2,
182      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
183      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
184      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
185      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
186      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
187      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
188      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
189      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
190      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
191      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
192      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
193      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
194      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
195      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
196      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
197      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
198      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
199      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
200      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
201      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
202      2,     2,     2,     2,     2,     1,     3,     4,     5,     6,
203      7,     8,     9,    10,    11,    12,    13,    14,    15,    16,
204     17,    18,    19,    20,    21,    22,    23,    24,    25,    26,
205     27,    28,    29,    30,    31,    32,    33,    34,    35,    36,
206     37
207 };
208 
209 #if YYDEBUG != 0
210 static const short yyprhs[] = {     0,
211      0,     2,     3,     6,     9,    12,    15,    18,    23,    25,
212     28,    31,    32,    36,    39,    42,    44,    47,    50,    51,
213     55,    58,    60,    63,    66,    69,    71,    73,    76,    78,
214     80,    83,    86,    89,    92,    94,    97,   100,   102,   107,
215    111,   114,   115,   117,   119,   121,   124,   127,   131,   133,
216    134
217 };
218 
219 static const short yyrhs[] = {    41,
220      0,     0,    42,    41,     0,     3,    36,     0,     4,    36,
221      0,     5,    37,     0,     6,    36,     0,     7,    36,    36,
222     36,     0,     8,     0,     9,    37,     0,    10,    36,     0,
223      0,    11,    43,    45,     0,    12,    36,     0,    13,    36,
224      0,    14,     0,    14,    36,     0,    15,    36,     0,     0,
225     16,    44,    45,     0,    17,    49,     0,    18,     0,    18,
226     36,     0,    19,    36,     0,    20,    49,     0,    21,     0,
227     22,     0,    23,    36,     0,    24,     0,    25,     0,    26,
228     37,     0,    27,    36,     0,    28,    36,     0,    29,    36,
229      0,    30,     0,    31,    37,     0,    32,    36,     0,    33,
230      0,    34,    36,    36,    36,     0,    34,    36,    36,     0,
231     35,    36,     0,     0,    46,     0,    48,     0,    47,     0,
232     46,    48,     0,    46,    47,     0,    38,    36,    39,     0,
233     36,     0,     0,    36,    49,     0
234 };
235 
236 #endif
237 
238 #if YYDEBUG != 0
239 static const short yyrline[] = { 0,
240    143,   149,   151,   156,   161,   166,   183,   187,   205,   209,
241    225,   229,   234,   237,   242,   247,   252,   257,   261,   266,
242    269,   273,   277,   281,   285,   289,   293,   297,   304,   308,
243    312,   328,   332,   337,   341,   345,   361,   366,   370,   394,
244    410,   418,   423,   433,   438,   442,   446,   454,   465,   481,
245    486
246 };
247 #endif
248 
249 
250 #if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
251 
252 static const char * const yytname[] = {   "$","error","$undefined.","CHECK",
253 "CODESTART","COPYRIGHT","CUSTOM","DATE","DEBUG","DESCRIPTION","EXIT","EXPORT",
254 "FLAG_ON","FLAG_OFF","FULLMAP","HELP","IMPORT","INPUT","MAP","MESSAGES","MODULE",
255 "MULTIPLE","OS_DOMAIN","OUTPUT","PSEUDOPREEMPTION","REENTRANT","SCREENNAME",
256 "SHARELIB","STACK","START","SYNCHRONIZE","THREADNAME","TYPE","VERBOSE","VERSIONK",
257 "XDCDATA","STRING","QUOTED_STRING","'('","')'","file","commands","command","@1",
258 "@2","symbol_list_opt","symbol_list","symbol_prefix","symbol","string_list", NULL
259 };
260 #endif
261 
262 static const short yyr1[] = {     0,
263     40,    41,    41,    42,    42,    42,    42,    42,    42,    42,
264     42,    43,    42,    42,    42,    42,    42,    42,    44,    42,
265     42,    42,    42,    42,    42,    42,    42,    42,    42,    42,
266     42,    42,    42,    42,    42,    42,    42,    42,    42,    42,
267     42,    45,    45,    46,    46,    46,    46,    47,    48,    49,
268     49
269 };
270 
271 static const short yyr2[] = {     0,
272      1,     0,     2,     2,     2,     2,     2,     4,     1,     2,
273      2,     0,     3,     2,     2,     1,     2,     2,     0,     3,
274      2,     1,     2,     2,     2,     1,     1,     2,     1,     1,
275      2,     2,     2,     2,     1,     2,     2,     1,     4,     3,
276      2,     0,     1,     1,     1,     2,     2,     3,     1,     0,
277      2
278 };
279 
280 static const short yydefact[] = {     2,
281      0,     0,     0,     0,     0,     9,     0,     0,    12,     0,
282      0,    16,     0,    19,    50,    22,     0,    50,    26,    27,
283      0,    29,    30,     0,     0,     0,     0,    35,     0,     0,
284     38,     0,     0,     1,     2,     4,     5,     6,     7,     0,
285     10,    11,    42,    14,    15,    17,    18,    42,    50,    21,
286     23,    24,    25,    28,    31,    32,    33,    34,    36,    37,
287      0,    41,     3,     0,    49,     0,    13,    43,    45,    44,
288     20,    51,    40,     8,     0,    47,    46,    39,    48,     0,
289      0,     0
290 };
291 
292 static const short yydefgoto[] = {    80,
293     34,    35,    43,    48,    67,    68,    69,    70,    50
294 };
295 
296 static const short yypact[] = {    -3,
297     -1,     1,     2,     4,     5,-32768,     6,     8,-32768,     9,
298     10,    11,    12,-32768,    13,    14,    16,    13,-32768,-32768,
299     17,-32768,-32768,    18,    20,    21,    22,-32768,    23,    25,
300 -32768,    26,    27,-32768,    -3,-32768,-32768,-32768,-32768,    29,
301 -32768,-32768,    -2,-32768,-32768,-32768,-32768,    -2,    13,-32768,
302 -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
303     30,-32768,-32768,    31,-32768,    32,-32768,    -2,-32768,-32768,
304 -32768,-32768,    33,-32768,     3,-32768,-32768,-32768,-32768,    38,
305     51,-32768
306 };
307 
308 static const short yypgoto[] = {-32768,
309     19,-32768,-32768,-32768,    24,-32768,    -9,     7,    15
310 };
311 
312 
313 #define	YYLAST		75
314 
315 
316 static const short yytable[] = {     1,
317      2,     3,     4,     5,     6,     7,     8,     9,    10,    11,
318     12,    13,    14,    15,    16,    17,    18,    19,    20,    21,
319     22,    23,    24,    25,    26,    27,    28,    29,    30,    31,
320     32,    33,    53,    65,    36,    66,    37,    81,    38,    39,
321     40,    79,    41,    42,    44,    45,    46,    47,    49,    51,
322     82,    52,    54,    63,    55,    56,    57,    58,    76,    59,
323     60,    61,    62,    72,    64,    73,    74,    75,    78,     0,
324      0,    71,     0,     0,    77
325 };
326 
327 static const short yycheck[] = {     3,
328      4,     5,     6,     7,     8,     9,    10,    11,    12,    13,
329     14,    15,    16,    17,    18,    19,    20,    21,    22,    23,
330     24,    25,    26,    27,    28,    29,    30,    31,    32,    33,
331     34,    35,    18,    36,    36,    38,    36,     0,    37,    36,
332     36,    39,    37,    36,    36,    36,    36,    36,    36,    36,
333      0,    36,    36,    35,    37,    36,    36,    36,    68,    37,
334     36,    36,    36,    49,    36,    36,    36,    36,    36,    -1,
335     -1,    48,    -1,    -1,    68
336 };
337 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
338 #line 3 "/usr/share/bison/bison.simple"
339 /* This file comes from bison-1.28.  */
340 
341 /* Skeleton output parser for bison,
342    Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
343 
344    This program is free software; you can redistribute it and/or modify
345    it under the terms of the GNU General Public License as published by
346    the Free Software Foundation; either version 2, or (at your option)
347    any later version.
348 
349    This program is distributed in the hope that it will be useful,
350    but WITHOUT ANY WARRANTY; without even the implied warranty of
351    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
352    GNU General Public License for more details.
353 
354    You should have received a copy of the GNU General Public License
355    along with this program; if not, write to the Free Software
356    Foundation, Inc., 59 Temple Place - Suite 330,
357    Boston, MA 02111-1307, USA.  */
358 
359 /* As a special exception, when this file is copied by Bison into a
360    Bison output file, you may use that output file without restriction.
361    This special exception was added by the Free Software Foundation
362    in version 1.24 of Bison.  */
363 
364 /* This is the parser code that is written into each bison parser
365   when the %semantic_parser declaration is not specified in the grammar.
366   It was written by Richard Stallman by simplifying the hairy parser
367   used when %semantic_parser is specified.  */
368 
369 #ifndef YYSTACK_USE_ALLOCA
370 #ifdef alloca
371 #define YYSTACK_USE_ALLOCA
372 #else /* alloca not defined */
373 #ifdef __GNUC__
374 #define YYSTACK_USE_ALLOCA
375 #define alloca __builtin_alloca
376 #else /* not GNU C.  */
377 #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
378 #define YYSTACK_USE_ALLOCA
379 #include <alloca.h>
380 #else /* not sparc */
381 /* We think this test detects Watcom and Microsoft C.  */
382 /* This used to test MSDOS, but that is a bad idea
383    since that symbol is in the user namespace.  */
384 #if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
385 #if 0 /* No need for malloc.h, which pollutes the namespace;
386 	 instead, just don't use alloca.  */
387 #include <malloc.h>
388 #endif
389 #else /* not MSDOS, or __TURBOC__ */
390 #if defined(_AIX)
391 /* I don't know what this was needed for, but it pollutes the namespace.
392    So I turned it off.   rms, 2 May 1997.  */
393 /* #include <malloc.h>  */
394  #pragma alloca
395 #define YYSTACK_USE_ALLOCA
396 #else /* not MSDOS, or __TURBOC__, or _AIX */
397 #if 0
398 #ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
399 		 and on HPUX 10.  Eventually we can turn this on.  */
400 #define YYSTACK_USE_ALLOCA
401 #define alloca __builtin_alloca
402 #endif /* __hpux */
403 #endif
404 #endif /* not _AIX */
405 #endif /* not MSDOS, or __TURBOC__ */
406 #endif /* not sparc */
407 #endif /* not GNU C */
408 #endif /* alloca not defined */
409 #endif /* YYSTACK_USE_ALLOCA not defined */
410 
411 #ifdef YYSTACK_USE_ALLOCA
412 #define YYSTACK_ALLOC alloca
413 #else
414 #define YYSTACK_ALLOC malloc
415 #endif
416 
417 /* Note: there must be only one dollar sign in this file.
418    It is replaced by the list of actions, each action
419    as one case of the switch.  */
420 
421 #define yyerrok		(yyerrstatus = 0)
422 #define yyclearin	(yychar = YYEMPTY)
423 #define YYEMPTY		-2
424 #define YYEOF		0
425 #define YYACCEPT	goto yyacceptlab
426 #define YYABORT 	goto yyabortlab
427 #define YYERROR		goto yyerrlab1
428 /* Like YYERROR except do call yyerror.
429    This remains here temporarily to ease the
430    transition to the new meaning of YYERROR, for GCC.
431    Once GCC version 2 has supplanted version 1, this can go.  */
432 #define YYFAIL		goto yyerrlab
433 #define YYRECOVERING()  (!!yyerrstatus)
434 #define YYBACKUP(token, value) \
435 do								\
436   if (yychar == YYEMPTY && yylen == 1)				\
437     { yychar = (token), yylval = (value);			\
438       yychar1 = YYTRANSLATE (yychar);				\
439       YYPOPSTACK;						\
440       goto yybackup;						\
441     }								\
442   else								\
443     { yyerror ("syntax error: cannot back up"); YYERROR; }	\
444 while (0)
445 
446 #define YYTERROR	1
447 #define YYERRCODE	256
448 
449 #ifndef YYPURE
450 #define YYLEX		yylex()
451 #endif
452 
453 #ifdef YYPURE
454 #ifdef YYLSP_NEEDED
455 #ifdef YYLEX_PARAM
456 #define YYLEX		yylex(&yylval, &yylloc, YYLEX_PARAM)
457 #else
458 #define YYLEX		yylex(&yylval, &yylloc)
459 #endif
460 #else /* not YYLSP_NEEDED */
461 #ifdef YYLEX_PARAM
462 #define YYLEX		yylex(&yylval, YYLEX_PARAM)
463 #else
464 #define YYLEX		yylex(&yylval)
465 #endif
466 #endif /* not YYLSP_NEEDED */
467 #endif
468 
469 /* If nonreentrant, generate the variables here */
470 
471 #ifndef YYPURE
472 
473 int	yychar;			/*  the lookahead symbol		*/
474 YYSTYPE	yylval;			/*  the semantic value of the		*/
475 				/*  lookahead symbol			*/
476 
477 #ifdef YYLSP_NEEDED
478 YYLTYPE yylloc;			/*  location data for the lookahead	*/
479 				/*  symbol				*/
480 #endif
481 
482 int yynerrs;			/*  number of parse errors so far       */
483 #endif  /* not YYPURE */
484 
485 #if YYDEBUG != 0
486 int yydebug;			/*  nonzero means print parse trace	*/
487 /* Since this is uninitialized, it does not stop multiple parsers
488    from coexisting.  */
489 #endif
490 
491 /*  YYINITDEPTH indicates the initial size of the parser's stacks	*/
492 
493 #ifndef	YYINITDEPTH
494 #define YYINITDEPTH 200
495 #endif
496 
497 /*  YYMAXDEPTH is the maximum size the stacks can grow to
498     (effective only if the built-in stack extension method is used).  */
499 
500 #if YYMAXDEPTH == 0
501 #undef YYMAXDEPTH
502 #endif
503 
504 #ifndef YYMAXDEPTH
505 #define YYMAXDEPTH 10000
506 #endif
507 
508 /* Define __yy_memcpy.  Note that the size argument
509    should be passed with type unsigned int, because that is what the non-GCC
510    definitions require.  With GCC, __builtin_memcpy takes an arg
511    of type size_t, but it can handle unsigned int.  */
512 
513 #if __GNUC__ > 1		/* GNU C and GNU C++ define this.  */
514 #define __yy_memcpy(TO,FROM,COUNT)	__builtin_memcpy(TO,FROM,COUNT)
515 #else				/* not GNU C or C++ */
516 #ifndef __cplusplus
517 
518 /* This is the most reliable way to avoid incompatibilities
519    in available built-in functions on various systems.  */
520 static void
521 __yy_memcpy (to, from, count)
522      char *to;
523      char *from;
524      unsigned int count;
525 {
526   register char *f = from;
527   register char *t = to;
528   register int i = count;
529 
530   while (i-- > 0)
531     *t++ = *f++;
532 }
533 
534 #else /* __cplusplus */
535 
536 /* This is the most reliable way to avoid incompatibilities
537    in available built-in functions on various systems.  */
538 static void
539 __yy_memcpy (char *to, char *from, unsigned int count)
540 {
541   register char *t = to;
542   register char *f = from;
543   register int i = count;
544 
545   while (i-- > 0)
546     *t++ = *f++;
547 }
548 
549 #endif
550 #endif
551 
552 #line 217 "/usr/share/bison/bison.simple"
553 
554 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
555    into yyparse.  The argument should have type void *.
556    It should actually point to an object.
557    Grammar actions can access the variable by casting it
558    to the proper pointer type.  */
559 
560 #ifdef YYPARSE_PARAM
561 #ifdef __cplusplus
562 #define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
563 #define YYPARSE_PARAM_DECL
564 #else /* not __cplusplus */
565 #define YYPARSE_PARAM_ARG YYPARSE_PARAM
566 #define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
567 #endif /* not __cplusplus */
568 #else /* not YYPARSE_PARAM */
569 #define YYPARSE_PARAM_ARG
570 #define YYPARSE_PARAM_DECL
571 #endif /* not YYPARSE_PARAM */
572 
573 /* Prevent warning if -Wstrict-prototypes.  */
574 #ifdef __GNUC__
575 #ifdef YYPARSE_PARAM
576 int yyparse (void *);
577 #else
578 int yyparse (void);
579 #endif
580 #endif
581 
582 int
583 yyparse(YYPARSE_PARAM_ARG)
584      YYPARSE_PARAM_DECL
585 {
586   register int yystate;
587   register int yyn;
588   register short *yyssp;
589   register YYSTYPE *yyvsp;
590   int yyerrstatus;	/*  number of tokens to shift before error messages enabled */
591   int yychar1 = 0;		/*  lookahead token as an internal (translated) token number */
592 
593   short	yyssa[YYINITDEPTH];	/*  the state stack			*/
594   YYSTYPE yyvsa[YYINITDEPTH];	/*  the semantic value stack		*/
595 
596   short *yyss = yyssa;		/*  refer to the stacks thru separate pointers */
597   YYSTYPE *yyvs = yyvsa;	/*  to allow yyoverflow to reallocate them elsewhere */
598 
599 #ifdef YYLSP_NEEDED
600   YYLTYPE yylsa[YYINITDEPTH];	/*  the location stack			*/
601   YYLTYPE *yyls = yylsa;
602   YYLTYPE *yylsp;
603 
604 #define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
605 #else
606 #define YYPOPSTACK   (yyvsp--, yyssp--)
607 #endif
608 
609   int yystacksize = YYINITDEPTH;
610   int yyfree_stacks = 0;
611 
612 #ifdef YYPURE
613   int yychar;
614   YYSTYPE yylval;
615   int yynerrs;
616 #ifdef YYLSP_NEEDED
617   YYLTYPE yylloc;
618 #endif
619 #endif
620 
621   YYSTYPE yyval;		/*  the variable used to return		*/
622 				/*  semantic values from the action	*/
623 				/*  routines				*/
624 
625   int yylen;
626 
627 #if YYDEBUG != 0
628   if (yydebug)
629     fprintf(stderr, "Starting parse\n");
630 #endif
631 
632   yystate = 0;
633   yyerrstatus = 0;
634   yynerrs = 0;
635   yychar = YYEMPTY;		/* Cause a token to be read.  */
636 
637   /* Initialize stack pointers.
638      Waste one element of value and location stack
639      so that they stay on the same level as the state stack.
640      The wasted elements are never initialized.  */
641 
642   yyssp = yyss - 1;
643   yyvsp = yyvs;
644 #ifdef YYLSP_NEEDED
645   yylsp = yyls;
646 #endif
647 
648 /* Push a new state, which is found in  yystate  .  */
649 /* In all cases, when you get here, the value and location stacks
650    have just been pushed. so pushing a state here evens the stacks.  */
651 yynewstate:
652 
653   *++yyssp = yystate;
654 
655   if (yyssp >= yyss + yystacksize - 1)
656     {
657       /* Give user a chance to reallocate the stack */
658       /* Use copies of these so that the &'s don't force the real ones into memory. */
659       YYSTYPE *yyvs1 = yyvs;
660       short *yyss1 = yyss;
661 #ifdef YYLSP_NEEDED
662       YYLTYPE *yyls1 = yyls;
663 #endif
664 
665       /* Get the current used size of the three stacks, in elements.  */
666       int size = yyssp - yyss + 1;
667 
668 #ifdef yyoverflow
669       /* Each stack pointer address is followed by the size of
670 	 the data in use in that stack, in bytes.  */
671 #ifdef YYLSP_NEEDED
672       /* This used to be a conditional around just the two extra args,
673 	 but that might be undefined if yyoverflow is a macro.  */
674       yyoverflow("parser stack overflow",
675 		 &yyss1, size * sizeof (*yyssp),
676 		 &yyvs1, size * sizeof (*yyvsp),
677 		 &yyls1, size * sizeof (*yylsp),
678 		 &yystacksize);
679 #else
680       yyoverflow("parser stack overflow",
681 		 &yyss1, size * sizeof (*yyssp),
682 		 &yyvs1, size * sizeof (*yyvsp),
683 		 &yystacksize);
684 #endif
685 
686       yyss = yyss1; yyvs = yyvs1;
687 #ifdef YYLSP_NEEDED
688       yyls = yyls1;
689 #endif
690 #else /* no yyoverflow */
691       /* Extend the stack our own way.  */
692       if (yystacksize >= YYMAXDEPTH)
693 	{
694 	  yyerror("parser stack overflow");
695 	  if (yyfree_stacks)
696 	    {
697 	      free (yyss);
698 	      free (yyvs);
699 #ifdef YYLSP_NEEDED
700 	      free (yyls);
701 #endif
702 	    }
703 	  return 2;
704 	}
705       yystacksize *= 2;
706       if (yystacksize > YYMAXDEPTH)
707 	yystacksize = YYMAXDEPTH;
708 #ifndef YYSTACK_USE_ALLOCA
709       yyfree_stacks = 1;
710 #endif
711       yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
712       __yy_memcpy ((char *)yyss, (char *)yyss1,
713 		   size * (unsigned int) sizeof (*yyssp));
714       yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
715       __yy_memcpy ((char *)yyvs, (char *)yyvs1,
716 		   size * (unsigned int) sizeof (*yyvsp));
717 #ifdef YYLSP_NEEDED
718       yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
719       __yy_memcpy ((char *)yyls, (char *)yyls1,
720 		   size * (unsigned int) sizeof (*yylsp));
721 #endif
722 #endif /* no yyoverflow */
723 
724       yyssp = yyss + size - 1;
725       yyvsp = yyvs + size - 1;
726 #ifdef YYLSP_NEEDED
727       yylsp = yyls + size - 1;
728 #endif
729 
730 #if YYDEBUG != 0
731       if (yydebug)
732 	fprintf(stderr, "Stack size increased to %d\n", yystacksize);
733 #endif
734 
735       if (yyssp >= yyss + yystacksize - 1)
736 	YYABORT;
737     }
738 
739 #if YYDEBUG != 0
740   if (yydebug)
741     fprintf(stderr, "Entering state %d\n", yystate);
742 #endif
743 
744   goto yybackup;
745  yybackup:
746 
747 /* Do appropriate processing given the current state.  */
748 /* Read a lookahead token if we need one and don't already have one.  */
749 /* yyresume: */
750 
751   /* First try to decide what to do without reference to lookahead token.  */
752 
753   yyn = yypact[yystate];
754   if (yyn == YYFLAG)
755     goto yydefault;
756 
757   /* Not known => get a lookahead token if don't already have one.  */
758 
759   /* yychar is either YYEMPTY or YYEOF
760      or a valid token in external form.  */
761 
762   if (yychar == YYEMPTY)
763     {
764 #if YYDEBUG != 0
765       if (yydebug)
766 	fprintf(stderr, "Reading a token: ");
767 #endif
768       yychar = YYLEX;
769     }
770 
771   /* Convert token to internal form (in yychar1) for indexing tables with */
772 
773   if (yychar <= 0)		/* This means end of input. */
774     {
775       yychar1 = 0;
776       yychar = YYEOF;		/* Don't call YYLEX any more */
777 
778 #if YYDEBUG != 0
779       if (yydebug)
780 	fprintf(stderr, "Now at end of input.\n");
781 #endif
782     }
783   else
784     {
785       yychar1 = YYTRANSLATE(yychar);
786 
787 #if YYDEBUG != 0
788       if (yydebug)
789 	{
790 	  fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
791 	  /* Give the individual parser a way to print the precise meaning
792 	     of a token, for further debugging info.  */
793 #ifdef YYPRINT
794 	  YYPRINT (stderr, yychar, yylval);
795 #endif
796 	  fprintf (stderr, ")\n");
797 	}
798 #endif
799     }
800 
801   yyn += yychar1;
802   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
803     goto yydefault;
804 
805   yyn = yytable[yyn];
806 
807   /* yyn is what to do for this token type in this state.
808      Negative => reduce, -yyn is rule number.
809      Positive => shift, yyn is new state.
810        New state is final state => don't bother to shift,
811        just return success.
812      0, or most negative number => error.  */
813 
814   if (yyn < 0)
815     {
816       if (yyn == YYFLAG)
817 	goto yyerrlab;
818       yyn = -yyn;
819       goto yyreduce;
820     }
821   else if (yyn == 0)
822     goto yyerrlab;
823 
824   if (yyn == YYFINAL)
825     YYACCEPT;
826 
827   /* Shift the lookahead token.  */
828 
829 #if YYDEBUG != 0
830   if (yydebug)
831     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
832 #endif
833 
834   /* Discard the token being shifted unless it is eof.  */
835   if (yychar != YYEOF)
836     yychar = YYEMPTY;
837 
838   *++yyvsp = yylval;
839 #ifdef YYLSP_NEEDED
840   *++yylsp = yylloc;
841 #endif
842 
843   /* count tokens shifted since error; after three, turn off error status.  */
844   if (yyerrstatus) yyerrstatus--;
845 
846   yystate = yyn;
847   goto yynewstate;
848 
849 /* Do the default action for the current state.  */
850 yydefault:
851 
852   yyn = yydefact[yystate];
853   if (yyn == 0)
854     goto yyerrlab;
855 
856 /* Do a reduction.  yyn is the number of a rule to reduce with.  */
857 yyreduce:
858   yylen = yyr2[yyn];
859   if (yylen > 0)
860     yyval = yyvsp[1-yylen]; /* implement default value of the action */
861 
862 #if YYDEBUG != 0
863   if (yydebug)
864     {
865       int i;
866 
867       fprintf (stderr, "Reducing via rule %d (line %d), ",
868 	       yyn, yyrline[yyn]);
869 
870       /* Print the symbols being reduced, and their result.  */
871       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
872 	fprintf (stderr, "%s ", yytname[yyrhs[i]]);
873       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
874     }
875 #endif
876 
877 
878   switch (yyn) {
879 
880 case 4:
881 #line 158 "nlmheader.y"
882 {
883 	    check_procedure = yyvsp[0].string;
884 	  ;
885     break;}
886 case 5:
887 #line 162 "nlmheader.y"
888 {
889 	    nlmheader_warn (_("CODESTART is not implemented; sorry"), -1);
890 	    free (yyvsp[0].string);
891 	  ;
892     break;}
893 case 6:
894 #line 167 "nlmheader.y"
895 {
896 	    int len;
897 
898 	    strncpy (copyright_hdr->stamp, "CoPyRiGhT=", 10);
899 	    len = strlen (yyvsp[0].string);
900 	    if (len >= NLM_MAX_COPYRIGHT_MESSAGE_LENGTH)
901 	      {
902 		nlmheader_warn (_("copyright string is too long"),
903 				NLM_MAX_COPYRIGHT_MESSAGE_LENGTH - 1);
904 		len = NLM_MAX_COPYRIGHT_MESSAGE_LENGTH - 1;
905 	      }
906 	    copyright_hdr->copyrightMessageLength = len;
907 	    strncpy (copyright_hdr->copyrightMessage, yyvsp[0].string, len);
908 	    copyright_hdr->copyrightMessage[len] = '\0';
909 	    free (yyvsp[0].string);
910 	  ;
911     break;}
912 case 7:
913 #line 184 "nlmheader.y"
914 {
915 	    custom_file = yyvsp[0].string;
916 	  ;
917     break;}
918 case 8:
919 #line 188 "nlmheader.y"
920 {
921 	    /* We don't set the version stamp here, because we use the
922 	       version stamp to detect whether the required VERSION
923 	       keyword was given.  */
924 	    version_hdr->month = nlmlex_get_number (yyvsp[-2].string);
925 	    version_hdr->day = nlmlex_get_number (yyvsp[-1].string);
926 	    version_hdr->year = nlmlex_get_number (yyvsp[0].string);
927 	    free (yyvsp[-2].string);
928 	    free (yyvsp[-1].string);
929 	    free (yyvsp[0].string);
930 	    if (version_hdr->month < 1 || version_hdr->month > 12)
931 	      nlmheader_warn (_("illegal month"), -1);
932 	    if (version_hdr->day < 1 || version_hdr->day > 31)
933 	      nlmheader_warn (_("illegal day"), -1);
934 	    if (version_hdr->year < 1900 || version_hdr->year > 3000)
935 	      nlmheader_warn (_("illegal year"), -1);
936 	  ;
937     break;}
938 case 9:
939 #line 206 "nlmheader.y"
940 {
941 	    debug_info = true;
942 	  ;
943     break;}
944 case 10:
945 #line 210 "nlmheader.y"
946 {
947 	    int len;
948 
949 	    len = strlen (yyvsp[0].string);
950 	    if (len > NLM_MAX_DESCRIPTION_LENGTH)
951 	      {
952 		nlmheader_warn (_("description string is too long"),
953 				NLM_MAX_DESCRIPTION_LENGTH);
954 		len = NLM_MAX_DESCRIPTION_LENGTH;
955 	      }
956 	    var_hdr->descriptionLength = len;
957 	    strncpy (var_hdr->descriptionText, yyvsp[0].string, len);
958 	    var_hdr->descriptionText[len] = '\0';
959 	    free (yyvsp[0].string);
960 	  ;
961     break;}
962 case 11:
963 #line 226 "nlmheader.y"
964 {
965 	    exit_procedure = yyvsp[0].string;
966 	  ;
967     break;}
968 case 12:
969 #line 230 "nlmheader.y"
970 {
971 	    symbol_prefix = NULL;
972 	  ;
973     break;}
974 case 13:
975 #line 234 "nlmheader.y"
976 {
977 	    export_symbols = string_list_append (export_symbols, yyvsp[0].list);
978 	  ;
979     break;}
980 case 14:
981 #line 238 "nlmheader.y"
982 {
983 	    fixed_hdr->flags |= nlmlex_get_number (yyvsp[0].string);
984 	    free (yyvsp[0].string);
985 	  ;
986     break;}
987 case 15:
988 #line 243 "nlmheader.y"
989 {
990 	    fixed_hdr->flags &=~ nlmlex_get_number (yyvsp[0].string);
991 	    free (yyvsp[0].string);
992 	  ;
993     break;}
994 case 16:
995 #line 248 "nlmheader.y"
996 {
997 	    map_file = "";
998 	    full_map = true;
999 	  ;
1000     break;}
1001 case 17:
1002 #line 253 "nlmheader.y"
1003 {
1004 	    map_file = yyvsp[0].string;
1005 	    full_map = true;
1006 	  ;
1007     break;}
1008 case 18:
1009 #line 258 "nlmheader.y"
1010 {
1011 	    help_file = yyvsp[0].string;
1012 	  ;
1013     break;}
1014 case 19:
1015 #line 262 "nlmheader.y"
1016 {
1017 	    symbol_prefix = NULL;
1018 	  ;
1019     break;}
1020 case 20:
1021 #line 266 "nlmheader.y"
1022 {
1023 	    import_symbols = string_list_append (import_symbols, yyvsp[0].list);
1024 	  ;
1025     break;}
1026 case 21:
1027 #line 270 "nlmheader.y"
1028 {
1029 	    input_files = string_list_append (input_files, yyvsp[0].list);
1030 	  ;
1031     break;}
1032 case 22:
1033 #line 274 "nlmheader.y"
1034 {
1035 	    map_file = "";
1036 	  ;
1037     break;}
1038 case 23:
1039 #line 278 "nlmheader.y"
1040 {
1041 	    map_file = yyvsp[0].string;
1042 	  ;
1043     break;}
1044 case 24:
1045 #line 282 "nlmheader.y"
1046 {
1047 	    message_file = yyvsp[0].string;
1048 	  ;
1049     break;}
1050 case 25:
1051 #line 286 "nlmheader.y"
1052 {
1053 	    modules = string_list_append (modules, yyvsp[0].list);
1054 	  ;
1055     break;}
1056 case 26:
1057 #line 290 "nlmheader.y"
1058 {
1059 	    fixed_hdr->flags |= 0x2;
1060 	  ;
1061     break;}
1062 case 27:
1063 #line 294 "nlmheader.y"
1064 {
1065 	    fixed_hdr->flags |= 0x10;
1066 	  ;
1067     break;}
1068 case 28:
1069 #line 298 "nlmheader.y"
1070 {
1071 	    if (output_file == NULL)
1072 	      output_file = yyvsp[0].string;
1073 	    else
1074 	      nlmheader_warn (_("ignoring duplicate OUTPUT statement"), -1);
1075 	  ;
1076     break;}
1077 case 29:
1078 #line 305 "nlmheader.y"
1079 {
1080 	    fixed_hdr->flags |= 0x8;
1081 	  ;
1082     break;}
1083 case 30:
1084 #line 309 "nlmheader.y"
1085 {
1086 	    fixed_hdr->flags |= 0x1;
1087 	  ;
1088     break;}
1089 case 31:
1090 #line 313 "nlmheader.y"
1091 {
1092 	    int len;
1093 
1094 	    len = strlen (yyvsp[0].string);
1095 	    if (len >= NLM_MAX_SCREEN_NAME_LENGTH)
1096 	      {
1097 		nlmheader_warn (_("screen name is too long"),
1098 				NLM_MAX_SCREEN_NAME_LENGTH);
1099 		len = NLM_MAX_SCREEN_NAME_LENGTH;
1100 	      }
1101 	    var_hdr->screenNameLength = len;
1102 	    strncpy (var_hdr->screenName, yyvsp[0].string, len);
1103 	    var_hdr->screenName[NLM_MAX_SCREEN_NAME_LENGTH] = '\0';
1104 	    free (yyvsp[0].string);
1105 	  ;
1106     break;}
1107 case 32:
1108 #line 329 "nlmheader.y"
1109 {
1110 	    sharelib_file = yyvsp[0].string;
1111 	  ;
1112     break;}
1113 case 33:
1114 #line 333 "nlmheader.y"
1115 {
1116 	    var_hdr->stackSize = nlmlex_get_number (yyvsp[0].string);
1117 	    free (yyvsp[0].string);
1118 	  ;
1119     break;}
1120 case 34:
1121 #line 338 "nlmheader.y"
1122 {
1123 	    start_procedure = yyvsp[0].string;
1124 	  ;
1125     break;}
1126 case 35:
1127 #line 342 "nlmheader.y"
1128 {
1129 	    fixed_hdr->flags |= 0x4;
1130 	  ;
1131     break;}
1132 case 36:
1133 #line 346 "nlmheader.y"
1134 {
1135 	    int len;
1136 
1137 	    len = strlen (yyvsp[0].string);
1138 	    if (len >= NLM_MAX_THREAD_NAME_LENGTH)
1139 	      {
1140 		nlmheader_warn (_("thread name is too long"),
1141 				NLM_MAX_THREAD_NAME_LENGTH);
1142 		len = NLM_MAX_THREAD_NAME_LENGTH;
1143 	      }
1144 	    var_hdr->threadNameLength = len;
1145 	    strncpy (var_hdr->threadName, yyvsp[0].string, len);
1146 	    var_hdr->threadName[len] = '\0';
1147 	    free (yyvsp[0].string);
1148 	  ;
1149     break;}
1150 case 37:
1151 #line 362 "nlmheader.y"
1152 {
1153 	    fixed_hdr->moduleType = nlmlex_get_number (yyvsp[0].string);
1154 	    free (yyvsp[0].string);
1155 	  ;
1156     break;}
1157 case 38:
1158 #line 367 "nlmheader.y"
1159 {
1160 	    verbose = true;
1161 	  ;
1162     break;}
1163 case 39:
1164 #line 371 "nlmheader.y"
1165 {
1166 	    long val;
1167 
1168 	    strncpy (version_hdr->stamp, "VeRsIoN#", 8);
1169 	    version_hdr->majorVersion = nlmlex_get_number (yyvsp[-2].string);
1170 	    val = nlmlex_get_number (yyvsp[-1].string);
1171 	    if (val < 0 || val > 99)
1172 	      nlmheader_warn (_("illegal minor version number (must be between 0 and 99)"),
1173 			      -1);
1174 	    else
1175 	      version_hdr->minorVersion = val;
1176 	    val = nlmlex_get_number (yyvsp[0].string);
1177 	    if (val < 0)
1178 	      nlmheader_warn (_("illegal revision number (must be between 0 and 26)"),
1179 			      -1);
1180 	    else if (val > 26)
1181 	      version_hdr->revision = 0;
1182 	    else
1183 	      version_hdr->revision = val;
1184 	    free (yyvsp[-2].string);
1185 	    free (yyvsp[-1].string);
1186 	    free (yyvsp[0].string);
1187 	  ;
1188     break;}
1189 case 40:
1190 #line 395 "nlmheader.y"
1191 {
1192 	    long val;
1193 
1194 	    strncpy (version_hdr->stamp, "VeRsIoN#", 8);
1195 	    version_hdr->majorVersion = nlmlex_get_number (yyvsp[-1].string);
1196 	    val = nlmlex_get_number (yyvsp[0].string);
1197 	    if (val < 0 || val > 99)
1198 	      nlmheader_warn (_("illegal minor version number (must be between 0 and 99)"),
1199 			      -1);
1200 	    else
1201 	      version_hdr->minorVersion = val;
1202 	    version_hdr->revision = 0;
1203 	    free (yyvsp[-1].string);
1204 	    free (yyvsp[0].string);
1205 	  ;
1206     break;}
1207 case 41:
1208 #line 411 "nlmheader.y"
1209 {
1210 	    rpc_file = yyvsp[0].string;
1211 	  ;
1212     break;}
1213 case 42:
1214 #line 420 "nlmheader.y"
1215 {
1216 	    yyval.list = NULL;
1217 	  ;
1218     break;}
1219 case 43:
1220 #line 424 "nlmheader.y"
1221 {
1222 	    yyval.list = yyvsp[0].list;
1223 	  ;
1224     break;}
1225 case 44:
1226 #line 435 "nlmheader.y"
1227 {
1228 	    yyval.list = string_list_cons (yyvsp[0].string, NULL);
1229 	  ;
1230     break;}
1231 case 45:
1232 #line 439 "nlmheader.y"
1233 {
1234 	    yyval.list = NULL;
1235 	  ;
1236     break;}
1237 case 46:
1238 #line 443 "nlmheader.y"
1239 {
1240 	    yyval.list = string_list_append1 (yyvsp[-1].list, yyvsp[0].string);
1241 	  ;
1242     break;}
1243 case 47:
1244 #line 447 "nlmheader.y"
1245 {
1246 	    yyval.list = yyvsp[-1].list;
1247 	  ;
1248     break;}
1249 case 48:
1250 #line 456 "nlmheader.y"
1251 {
1252 	    if (symbol_prefix != NULL)
1253 	      free (symbol_prefix);
1254 	    symbol_prefix = yyvsp[-1].string;
1255 	  ;
1256     break;}
1257 case 49:
1258 #line 467 "nlmheader.y"
1259 {
1260 	    if (symbol_prefix == NULL)
1261 	      yyval.string = yyvsp[0].string;
1262 	    else
1263 	      {
1264 		yyval.string = xmalloc (strlen (symbol_prefix) + strlen (yyvsp[0].string) + 2);
1265 		sprintf (yyval.string, "%s@%s", symbol_prefix, yyvsp[0].string);
1266 		free (yyvsp[0].string);
1267 	      }
1268 	  ;
1269     break;}
1270 case 50:
1271 #line 483 "nlmheader.y"
1272 {
1273 	    yyval.list = NULL;
1274 	  ;
1275     break;}
1276 case 51:
1277 #line 487 "nlmheader.y"
1278 {
1279 	    yyval.list = string_list_cons (yyvsp[-1].string, yyvsp[0].list);
1280 	  ;
1281     break;}
1282 }
1283    /* the action file gets copied in in place of this dollarsign */
1284 #line 543 "/usr/share/bison/bison.simple"
1285 
1286   yyvsp -= yylen;
1287   yyssp -= yylen;
1288 #ifdef YYLSP_NEEDED
1289   yylsp -= yylen;
1290 #endif
1291 
1292 #if YYDEBUG != 0
1293   if (yydebug)
1294     {
1295       short *ssp1 = yyss - 1;
1296       fprintf (stderr, "state stack now");
1297       while (ssp1 != yyssp)
1298 	fprintf (stderr, " %d", *++ssp1);
1299       fprintf (stderr, "\n");
1300     }
1301 #endif
1302 
1303   *++yyvsp = yyval;
1304 
1305 #ifdef YYLSP_NEEDED
1306   yylsp++;
1307   if (yylen == 0)
1308     {
1309       yylsp->first_line = yylloc.first_line;
1310       yylsp->first_column = yylloc.first_column;
1311       yylsp->last_line = (yylsp-1)->last_line;
1312       yylsp->last_column = (yylsp-1)->last_column;
1313       yylsp->text = 0;
1314     }
1315   else
1316     {
1317       yylsp->last_line = (yylsp+yylen-1)->last_line;
1318       yylsp->last_column = (yylsp+yylen-1)->last_column;
1319     }
1320 #endif
1321 
1322   /* Now "shift" the result of the reduction.
1323      Determine what state that goes to,
1324      based on the state we popped back to
1325      and the rule number reduced by.  */
1326 
1327   yyn = yyr1[yyn];
1328 
1329   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1330   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1331     yystate = yytable[yystate];
1332   else
1333     yystate = yydefgoto[yyn - YYNTBASE];
1334 
1335   goto yynewstate;
1336 
1337 yyerrlab:   /* here on detecting error */
1338 
1339   if (! yyerrstatus)
1340     /* If not already recovering from an error, report this error.  */
1341     {
1342       ++yynerrs;
1343 
1344 #ifdef YYERROR_VERBOSE
1345       yyn = yypact[yystate];
1346 
1347       if (yyn > YYFLAG && yyn < YYLAST)
1348 	{
1349 	  int size = 0;
1350 	  char *msg;
1351 	  int x, count;
1352 
1353 	  count = 0;
1354 	  /* Start X at -yyn if nec to avoid negative indexes in yycheck.  */
1355 	  for (x = (yyn < 0 ? -yyn : 0);
1356 	       x < (sizeof(yytname) / sizeof(char *)); x++)
1357 	    if (yycheck[x + yyn] == x)
1358 	      size += strlen(yytname[x]) + 15, count++;
1359 	  msg = (char *) malloc(size + 15);
1360 	  if (msg != 0)
1361 	    {
1362 	      strcpy(msg, "parse error");
1363 
1364 	      if (count < 5)
1365 		{
1366 		  count = 0;
1367 		  for (x = (yyn < 0 ? -yyn : 0);
1368 		       x < (sizeof(yytname) / sizeof(char *)); x++)
1369 		    if (yycheck[x + yyn] == x)
1370 		      {
1371 			strcat(msg, count == 0 ? ", expecting `" : " or `");
1372 			strcat(msg, yytname[x]);
1373 			strcat(msg, "'");
1374 			count++;
1375 		      }
1376 		}
1377 	      yyerror(msg);
1378 	      free(msg);
1379 	    }
1380 	  else
1381 	    yyerror ("parse error; also virtual memory exceeded");
1382 	}
1383       else
1384 #endif /* YYERROR_VERBOSE */
1385 	yyerror("parse error");
1386     }
1387 
1388   goto yyerrlab1;
1389 yyerrlab1:   /* here on error raised explicitly by an action */
1390 
1391   if (yyerrstatus == 3)
1392     {
1393       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
1394 
1395       /* return failure if at end of input */
1396       if (yychar == YYEOF)
1397 	YYABORT;
1398 
1399 #if YYDEBUG != 0
1400       if (yydebug)
1401 	fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
1402 #endif
1403 
1404       yychar = YYEMPTY;
1405     }
1406 
1407   /* Else will try to reuse lookahead token
1408      after shifting the error token.  */
1409 
1410   yyerrstatus = 3;		/* Each real token shifted decrements this */
1411 
1412   goto yyerrhandle;
1413 
1414 yyerrdefault:  /* current state does not do anything special for the error token. */
1415 
1416 #if 0
1417   /* This is wrong; only states that explicitly want error tokens
1418      should shift them.  */
1419   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
1420   if (yyn) goto yydefault;
1421 #endif
1422 
1423 yyerrpop:   /* pop the current state because it cannot handle the error token */
1424 
1425   if (yyssp == yyss) YYABORT;
1426   yyvsp--;
1427   yystate = *--yyssp;
1428 #ifdef YYLSP_NEEDED
1429   yylsp--;
1430 #endif
1431 
1432 #if YYDEBUG != 0
1433   if (yydebug)
1434     {
1435       short *ssp1 = yyss - 1;
1436       fprintf (stderr, "Error: state stack now");
1437       while (ssp1 != yyssp)
1438 	fprintf (stderr, " %d", *++ssp1);
1439       fprintf (stderr, "\n");
1440     }
1441 #endif
1442 
1443 yyerrhandle:
1444 
1445   yyn = yypact[yystate];
1446   if (yyn == YYFLAG)
1447     goto yyerrdefault;
1448 
1449   yyn += YYTERROR;
1450   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1451     goto yyerrdefault;
1452 
1453   yyn = yytable[yyn];
1454   if (yyn < 0)
1455     {
1456       if (yyn == YYFLAG)
1457 	goto yyerrpop;
1458       yyn = -yyn;
1459       goto yyreduce;
1460     }
1461   else if (yyn == 0)
1462     goto yyerrpop;
1463 
1464   if (yyn == YYFINAL)
1465     YYACCEPT;
1466 
1467 #if YYDEBUG != 0
1468   if (yydebug)
1469     fprintf(stderr, "Shifting error token, ");
1470 #endif
1471 
1472   *++yyvsp = yylval;
1473 #ifdef YYLSP_NEEDED
1474   *++yylsp = yylloc;
1475 #endif
1476 
1477   yystate = yyn;
1478   goto yynewstate;
1479 
1480  yyacceptlab:
1481   /* YYACCEPT comes here.  */
1482   if (yyfree_stacks)
1483     {
1484       free (yyss);
1485       free (yyvs);
1486 #ifdef YYLSP_NEEDED
1487       free (yyls);
1488 #endif
1489     }
1490   return 0;
1491 
1492  yyabortlab:
1493   /* YYABORT comes here.  */
1494   if (yyfree_stacks)
1495     {
1496       free (yyss);
1497       free (yyvs);
1498 #ifdef YYLSP_NEEDED
1499       free (yyls);
1500 #endif
1501     }
1502   return 1;
1503 }
1504 #line 492 "nlmheader.y"
1505 
1506 
1507 /* If strerror is just a macro, we want to use the one from libiberty
1508    since it will handle undefined values.  */
1509 #undef strerror
1510 extern char *strerror ();
1511 
1512 /* The lexer is simple, too simple for flex.  Keywords are only
1513    recognized at the start of lines.  Everything else must be an
1514    argument.  A comma is treated as whitespace.  */
1515 
1516 /* The states the lexer can be in.  */
1517 
1518 enum lex_state
1519 {
1520   /* At the beginning of a line.  */
1521   BEGINNING_OF_LINE,
1522   /* In the middle of a line.  */
1523   IN_LINE
1524 };
1525 
1526 /* We need to keep a stack of files to handle file inclusion.  */
1527 
1528 struct input
1529 {
1530   /* The file to read from.  */
1531   FILE *file;
1532   /* The name of the file.  */
1533   char *name;
1534   /* The current line number.  */
1535   int lineno;
1536   /* The current state.  */
1537   enum lex_state state;
1538   /* The next file on the stack.  */
1539   struct input *next;
1540 };
1541 
1542 /* The current input file.  */
1543 
1544 static struct input current;
1545 
1546 /* The character which introduces comments.  */
1547 #define COMMENT_CHAR '#'
1548 
1549 /* Start the lexer going on the main input file.  */
1550 
1551 boolean
1552 nlmlex_file (name)
1553      const char *name;
1554 {
1555   current.next = NULL;
1556   return nlmlex_file_open (name);
1557 }
1558 
1559 /* Start the lexer going on a subsidiary input file.  */
1560 
1561 static void
1562 nlmlex_file_push (name)
1563      const char *name;
1564 {
1565   struct input *push;
1566 
1567   push = (struct input *) xmalloc (sizeof (struct input));
1568   *push = current;
1569   if (nlmlex_file_open (name))
1570     current.next = push;
1571   else
1572     {
1573       current = *push;
1574       free (push);
1575     }
1576 }
1577 
1578 /* Start lexing from a file.  */
1579 
1580 static boolean
1581 nlmlex_file_open (name)
1582      const char *name;
1583 {
1584   current.file = fopen (name, "r");
1585   if (current.file == NULL)
1586     {
1587       fprintf (stderr, "%s:%s: %s\n", program_name, name, strerror (errno));
1588       ++parse_errors;
1589       return false;
1590     }
1591   current.name = xstrdup (name);
1592   current.lineno = 1;
1593   current.state = BEGINNING_OF_LINE;
1594   return true;
1595 }
1596 
1597 /* Table used to turn keywords into tokens.  */
1598 
1599 struct keyword_tokens_struct
1600 {
1601   const char *keyword;
1602   int token;
1603 };
1604 
1605 struct keyword_tokens_struct keyword_tokens[] =
1606 {
1607   { "CHECK", CHECK },
1608   { "CODESTART", CODESTART },
1609   { "COPYRIGHT", COPYRIGHT },
1610   { "CUSTOM", CUSTOM },
1611   { "DATE", DATE },
1612   { "DEBUG", DEBUG },
1613   { "DESCRIPTION", DESCRIPTION },
1614   { "EXIT", EXIT },
1615   { "EXPORT", EXPORT },
1616   { "FLAG_ON", FLAG_ON },
1617   { "FLAG_OFF", FLAG_OFF },
1618   { "FULLMAP", FULLMAP },
1619   { "HELP", HELP },
1620   { "IMPORT", IMPORT },
1621   { "INPUT", INPUT },
1622   { "MAP", MAP },
1623   { "MESSAGES", MESSAGES },
1624   { "MODULE", MODULE },
1625   { "MULTIPLE", MULTIPLE },
1626   { "OS_DOMAIN", OS_DOMAIN },
1627   { "OUTPUT", OUTPUT },
1628   { "PSEUDOPREEMPTION", PSEUDOPREEMPTION },
1629   { "REENTRANT", REENTRANT },
1630   { "SCREENNAME", SCREENNAME },
1631   { "SHARELIB", SHARELIB },
1632   { "STACK", STACK },
1633   { "STACKSIZE", STACK },
1634   { "START", START },
1635   { "SYNCHRONIZE", SYNCHRONIZE },
1636   { "THREADNAME", THREADNAME },
1637   { "TYPE", TYPE },
1638   { "VERBOSE", VERBOSE },
1639   { "VERSION", VERSIONK },
1640   { "XDCDATA", XDCDATA }
1641 };
1642 
1643 #define KEYWORD_COUNT (sizeof (keyword_tokens) / sizeof (keyword_tokens[0]))
1644 
1645 /* The lexer accumulates strings in these variables.  */
1646 static char *lex_buf;
1647 static int lex_size;
1648 static int lex_pos;
1649 
1650 /* Start accumulating strings into the buffer.  */
1651 #define BUF_INIT() \
1652   ((void) (lex_buf != NULL ? lex_pos = 0 : nlmlex_buf_init ()))
1653 
1654 static int
1655 nlmlex_buf_init ()
1656 {
1657   lex_size = 10;
1658   lex_buf = xmalloc (lex_size + 1);
1659   lex_pos = 0;
1660   return 0;
1661 }
1662 
1663 /* Finish a string in the buffer.  */
1664 #define BUF_FINISH() ((void) (lex_buf[lex_pos] = '\0'))
1665 
1666 /* Accumulate a character into the buffer.  */
1667 #define BUF_ADD(c) \
1668   ((void) (lex_pos < lex_size \
1669 	   ? lex_buf[lex_pos++] = (c) \
1670 	   : nlmlex_buf_add (c)))
1671 
1672 static char
1673 nlmlex_buf_add (c)
1674      int c;
1675 {
1676   if (lex_pos >= lex_size)
1677     {
1678       lex_size *= 2;
1679       lex_buf = xrealloc (lex_buf, lex_size + 1);
1680     }
1681 
1682   return lex_buf[lex_pos++] = c;
1683 }
1684 
1685 /* The lexer proper.  This is called by the bison generated parsing
1686    code.  */
1687 
1688 static int
1689 yylex ()
1690 {
1691   int c;
1692 
1693 tail_recurse:
1694 
1695   c = getc (current.file);
1696 
1697   /* Commas are treated as whitespace characters.  */
1698   while (isspace ((unsigned char) c) || c == ',')
1699     {
1700       current.state = IN_LINE;
1701       if (c == '\n')
1702 	{
1703 	  ++current.lineno;
1704 	  current.state = BEGINNING_OF_LINE;
1705 	}
1706       c = getc (current.file);
1707     }
1708 
1709   /* At the end of the file we either pop to the previous file or
1710      finish up.  */
1711   if (c == EOF)
1712     {
1713       fclose (current.file);
1714       free (current.name);
1715       if (current.next == NULL)
1716 	return 0;
1717       else
1718 	{
1719 	  struct input *next;
1720 
1721 	  next = current.next;
1722 	  current = *next;
1723 	  free (next);
1724 	  goto tail_recurse;
1725 	}
1726     }
1727 
1728   /* A comment character always means to drop everything until the
1729      next newline.  */
1730   if (c == COMMENT_CHAR)
1731     {
1732       do
1733 	{
1734 	  c = getc (current.file);
1735 	}
1736       while (c != '\n');
1737       ++current.lineno;
1738       current.state = BEGINNING_OF_LINE;
1739       goto tail_recurse;
1740     }
1741 
1742   /* An '@' introduces an include file.  */
1743   if (c == '@')
1744     {
1745       do
1746 	{
1747 	  c = getc (current.file);
1748 	  if (c == '\n')
1749 	    ++current.lineno;
1750 	}
1751       while (isspace ((unsigned char) c));
1752       BUF_INIT ();
1753       while (! isspace ((unsigned char) c) && c != EOF)
1754 	{
1755 	  BUF_ADD (c);
1756 	  c = getc (current.file);
1757 	}
1758       BUF_FINISH ();
1759 
1760       ungetc (c, current.file);
1761 
1762       nlmlex_file_push (lex_buf);
1763       goto tail_recurse;
1764     }
1765 
1766   /* A non-space character at the start of a line must be the start of
1767      a keyword.  */
1768   if (current.state == BEGINNING_OF_LINE)
1769     {
1770       BUF_INIT ();
1771       while (isalnum ((unsigned char) c) || c == '_')
1772 	{
1773 	  if (islower ((unsigned char) c))
1774 	    BUF_ADD (toupper ((unsigned char) c));
1775 	  else
1776 	    BUF_ADD (c);
1777 	  c = getc (current.file);
1778 	}
1779       BUF_FINISH ();
1780 
1781       if (c != EOF && ! isspace ((unsigned char) c) && c != ',')
1782 	{
1783 	  nlmheader_identify ();
1784 	  fprintf (stderr, _("%s:%d: illegal character in keyword: %c\n"),
1785 		   current.name, current.lineno, c);
1786 	}
1787       else
1788 	{
1789 	  unsigned int i;
1790 
1791 	  for (i = 0; i < KEYWORD_COUNT; i++)
1792 	    {
1793 	      if (lex_buf[0] == keyword_tokens[i].keyword[0]
1794 		  && strcmp (lex_buf, keyword_tokens[i].keyword) == 0)
1795 		{
1796 		  /* Pushing back the final whitespace avoids worrying
1797 		     about \n here.  */
1798 		  ungetc (c, current.file);
1799 		  current.state = IN_LINE;
1800 		  return keyword_tokens[i].token;
1801 		}
1802 	    }
1803 
1804 	  nlmheader_identify ();
1805 	  fprintf (stderr, _("%s:%d: unrecognized keyword: %s\n"),
1806 		   current.name, current.lineno, lex_buf);
1807 	}
1808 
1809       ++parse_errors;
1810       /* Treat the rest of this line as a comment.  */
1811       ungetc (COMMENT_CHAR, current.file);
1812       goto tail_recurse;
1813     }
1814 
1815   /* Parentheses just represent themselves.  */
1816   if (c == '(' || c == ')')
1817     return c;
1818 
1819   /* Handle quoted strings.  */
1820   if (c == '"' || c == '\'')
1821     {
1822       int quote;
1823       int start_lineno;
1824 
1825       quote = c;
1826       start_lineno = current.lineno;
1827 
1828       c = getc (current.file);
1829       BUF_INIT ();
1830       while (c != quote && c != EOF)
1831 	{
1832 	  BUF_ADD (c);
1833 	  if (c == '\n')
1834 	    ++current.lineno;
1835 	  c = getc (current.file);
1836 	}
1837       BUF_FINISH ();
1838 
1839       if (c == EOF)
1840 	{
1841 	  nlmheader_identify ();
1842 	  fprintf (stderr, _("%s:%d: end of file in quoted string\n"),
1843 		   current.name, start_lineno);
1844 	  ++parse_errors;
1845 	}
1846 
1847       /* FIXME: Possible memory leak.  */
1848       yylval.string = xstrdup (lex_buf);
1849       return QUOTED_STRING;
1850     }
1851 
1852   /* Gather a generic argument.  */
1853   BUF_INIT ();
1854   while (! isspace (c)
1855 	 && c != ','
1856 	 && c != COMMENT_CHAR
1857 	 && c != '('
1858 	 && c != ')')
1859     {
1860       BUF_ADD (c);
1861       c = getc (current.file);
1862     }
1863   BUF_FINISH ();
1864 
1865   ungetc (c, current.file);
1866 
1867   /* FIXME: Possible memory leak.  */
1868   yylval.string = xstrdup (lex_buf);
1869   return STRING;
1870 }
1871 
1872 /* Get a number from a string.  */
1873 
1874 static long
1875 nlmlex_get_number (s)
1876      const char *s;
1877 {
1878   long ret;
1879   char *send;
1880 
1881   ret = strtol (s, &send, 10);
1882   if (*send != '\0')
1883     nlmheader_warn (_("bad number"), -1);
1884   return ret;
1885 }
1886 
1887 /* Prefix the nlmconv warnings with a note as to where they come from.
1888    We don't use program_name on every warning, because then some
1889    versions of the emacs next-error function can't recognize the line
1890    number.  */
1891 
1892 static void
1893 nlmheader_identify ()
1894 {
1895   static int done;
1896 
1897   if (! done)
1898     {
1899       fprintf (stderr, _("%s: problems in NLM command language input:\n"),
1900 	       program_name);
1901       done = 1;
1902     }
1903 }
1904 
1905 /* Issue a warning.  */
1906 
1907 static void
1908 nlmheader_warn (s, imax)
1909      const char *s;
1910      int imax;
1911 {
1912   nlmheader_identify ();
1913   fprintf (stderr, "%s:%d: %s", current.name, current.lineno, s);
1914   if (imax != -1)
1915     fprintf (stderr, " (max %d)", imax);
1916   fprintf (stderr, "\n");
1917 }
1918 
1919 /* Report an error.  */
1920 
1921 static void
1922 nlmheader_error (s)
1923      const char *s;
1924 {
1925   nlmheader_warn (s, -1);
1926   ++parse_errors;
1927 }
1928 
1929 /* Add a string to a string list.  */
1930 
1931 static struct string_list *
1932 string_list_cons (s, l)
1933      char *s;
1934      struct string_list *l;
1935 {
1936   struct string_list *ret;
1937 
1938   ret = (struct string_list *) xmalloc (sizeof (struct string_list));
1939   ret->next = l;
1940   ret->string = s;
1941   return ret;
1942 }
1943 
1944 /* Append a string list to another string list.  */
1945 
1946 static struct string_list *
1947 string_list_append (l1, l2)
1948      struct string_list *l1;
1949      struct string_list *l2;
1950 {
1951   register struct string_list **pp;
1952 
1953   for (pp = &l1; *pp != NULL; pp = &(*pp)->next)
1954     ;
1955   *pp = l2;
1956   return l1;
1957 }
1958 
1959 /* Append a string to a string list.  */
1960 
1961 static struct string_list *
1962 string_list_append1 (l, s)
1963      struct string_list *l;
1964      char *s;
1965 {
1966   struct string_list *n;
1967   register struct string_list **pp;
1968 
1969   n = (struct string_list *) xmalloc (sizeof (struct string_list));
1970   n->next = NULL;
1971   n->string = s;
1972   for (pp = &l; *pp != NULL; pp = &(*pp)->next)
1973     ;
1974   *pp = n;
1975   return l;
1976 }
1977 
1978 /* Duplicate a string in memory.  */
1979 
1980 static char *
1981 xstrdup (s)
1982      const char *s;
1983 {
1984   unsigned long len;
1985   char *ret;
1986 
1987   len = strlen (s);
1988   ret = xmalloc (len + 1);
1989   strcpy (ret, s);
1990   return ret;
1991 }
1992