Update spec to require automake >= 1.13
[platform/upstream/gawk.git] / command.c
1 /* A Bison parser, made by GNU Bison 3.0.2.  */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5    Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
6
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37    infringing on user name space.  This should be done even for local
38    variables, as they might otherwise be expanded by user macros.
39    There are some unavoidable exceptions within include files to
40    define necessary library symbols; they are noted "INFRINGES ON
41    USER NAME SPACE" below.  */
42
43 /* Identify Bison output.  */
44 #define YYBISON 1
45
46 /* Bison version.  */
47 #define YYBISON_VERSION "3.0.2"
48
49 /* Skeleton name.  */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers.  */
53 #define YYPURE 0
54
55 /* Push parsers.  */
56 #define YYPUSH 0
57
58 /* Pull parsers.  */
59 #define YYPULL 1
60
61
62 /* Substitute the variable and function names.  */
63 #define yyparse         zzparse
64 #define yylex           zzlex
65 #define yyerror         zzerror
66 #define yydebug         zzdebug
67 #define yynerrs         zznerrs
68
69 #define yylval          zzlval
70 #define yychar          zzchar
71
72 /* Copy the first part of user declarations.  */
73 #line 26 "command.y" /* yacc.c:339  */
74
75 #include "awk.h"
76 #include "cmd.h"
77
78 #if 0
79 #define YYDEBUG 12
80 int yydebug = 2;
81 #endif
82
83 static int yylex(void);
84 static void yyerror(const char *mesg, ...);
85
86 static int find_command(const char *token, size_t toklen);
87
88 static bool want_nodeval = false;
89
90 static int cmd_idx = -1;                /* index of current command in cmd table */
91 static int repeat_idx = -1;             /* index of last repeatable command in command table */
92 static CMDARG *arg_list = NULL;         /* list of arguments */ 
93 static long errcount = 0;
94 static char *lexptr_begin = NULL;
95 static bool in_commands = false;
96 static int num_dim;
97
98 static bool in_eval = false;
99 static const char start_EVAL[] = "function @eval(){";
100 static const char end_EVAL[] = "}";     
101 static CMDARG *append_statement(CMDARG *stmt_list, char *stmt);
102 static NODE *concat_args(CMDARG *a, int count);
103
104 #ifdef HAVE_LIBREADLINE
105 static char *next_word(char *p, int len, char **endp);
106 static void history_expand_line(char **line);
107 static char *command_generator(const char *text, int state);
108 static char *srcfile_generator(const char *text, int state);
109 static char *argument_generator(const char *text, int state);
110 static char *variable_generator(const char *text, int state);
111 extern char *option_generator(const char *text, int state);
112 static int this_cmd = D_illegal;
113 #else
114 #define history_expand_line(p)  /* nothing */
115 static int rl_inhibit_completion;       /* dummy variable */
116 #endif
117
118 struct argtoken {
119         const char *name;
120         enum argtype cmd;
121         enum nametypeval value;
122 };
123
124 /*
125  * These two should be static, but there are some compilers that
126  * don't like the static keyword with an empty size. Therefore give
127  * them names that are less likely to conflict with the rest of gawk.
128  */
129 #define argtab zz_debug_argtab
130 #define cmdtab zz_debug_cmdtab
131
132 extern struct argtoken argtab[];
133 extern struct cmdtoken cmdtab[];
134
135 static CMDARG *mk_cmdarg(enum argtype type);
136 static void append_cmdarg(CMDARG *arg);
137 static int find_argument(CMDARG *arg);
138 #define YYSTYPE CMDARG *
139
140 #line 141 "command.c" /* yacc.c:339  */
141
142 # ifndef YY_NULLPTR
143 #  if defined __cplusplus && 201103L <= __cplusplus
144 #   define YY_NULLPTR nullptr
145 #  else
146 #   define YY_NULLPTR 0
147 #  endif
148 # endif
149
150 /* Enabling verbose error messages.  */
151 #ifdef YYERROR_VERBOSE
152 # undef YYERROR_VERBOSE
153 # define YYERROR_VERBOSE 1
154 #else
155 # define YYERROR_VERBOSE 0
156 #endif
157
158
159 /* Debug traces.  */
160 #ifndef YYDEBUG
161 # define YYDEBUG 0
162 #endif
163 #if YYDEBUG
164 extern int zzdebug;
165 #endif
166
167 /* Token type.  */
168 #ifndef YYTOKENTYPE
169 # define YYTOKENTYPE
170   enum yytokentype
171   {
172     D_BACKTRACE = 258,
173     D_BREAK = 259,
174     D_CLEAR = 260,
175     D_CONTINUE = 261,
176     D_DELETE = 262,
177     D_DISABLE = 263,
178     D_DOWN = 264,
179     D_ENABLE = 265,
180     D_FINISH = 266,
181     D_FRAME = 267,
182     D_HELP = 268,
183     D_IGNORE = 269,
184     D_INFO = 270,
185     D_LIST = 271,
186     D_NEXT = 272,
187     D_NEXTI = 273,
188     D_PRINT = 274,
189     D_PRINTF = 275,
190     D_QUIT = 276,
191     D_RETURN = 277,
192     D_RUN = 278,
193     D_SET = 279,
194     D_STEP = 280,
195     D_STEPI = 281,
196     D_TBREAK = 282,
197     D_UP = 283,
198     D_UNTIL = 284,
199     D_DISPLAY = 285,
200     D_UNDISPLAY = 286,
201     D_WATCH = 287,
202     D_UNWATCH = 288,
203     D_DUMP = 289,
204     D_TRACE = 290,
205     D_INT = 291,
206     D_STRING = 292,
207     D_NODE = 293,
208     D_VARIABLE = 294,
209     D_OPTION = 295,
210     D_COMMANDS = 296,
211     D_END = 297,
212     D_SILENT = 298,
213     D_SOURCE = 299,
214     D_SAVE = 300,
215     D_EVAL = 301,
216     D_CONDITION = 302,
217     D_STATEMENT = 303
218   };
219 #endif
220 /* Tokens.  */
221 #define D_BACKTRACE 258
222 #define D_BREAK 259
223 #define D_CLEAR 260
224 #define D_CONTINUE 261
225 #define D_DELETE 262
226 #define D_DISABLE 263
227 #define D_DOWN 264
228 #define D_ENABLE 265
229 #define D_FINISH 266
230 #define D_FRAME 267
231 #define D_HELP 268
232 #define D_IGNORE 269
233 #define D_INFO 270
234 #define D_LIST 271
235 #define D_NEXT 272
236 #define D_NEXTI 273
237 #define D_PRINT 274
238 #define D_PRINTF 275
239 #define D_QUIT 276
240 #define D_RETURN 277
241 #define D_RUN 278
242 #define D_SET 279
243 #define D_STEP 280
244 #define D_STEPI 281
245 #define D_TBREAK 282
246 #define D_UP 283
247 #define D_UNTIL 284
248 #define D_DISPLAY 285
249 #define D_UNDISPLAY 286
250 #define D_WATCH 287
251 #define D_UNWATCH 288
252 #define D_DUMP 289
253 #define D_TRACE 290
254 #define D_INT 291
255 #define D_STRING 292
256 #define D_NODE 293
257 #define D_VARIABLE 294
258 #define D_OPTION 295
259 #define D_COMMANDS 296
260 #define D_END 297
261 #define D_SILENT 298
262 #define D_SOURCE 299
263 #define D_SAVE 300
264 #define D_EVAL 301
265 #define D_CONDITION 302
266 #define D_STATEMENT 303
267
268 /* Value type.  */
269 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
270 typedef int YYSTYPE;
271 # define YYSTYPE_IS_TRIVIAL 1
272 # define YYSTYPE_IS_DECLARED 1
273 #endif
274
275
276 extern YYSTYPE zzlval;
277
278 int zzparse (void);
279
280
281
282 /* Copy the second part of user declarations.  */
283
284 #line 285 "command.c" /* yacc.c:358  */
285
286 #ifdef short
287 # undef short
288 #endif
289
290 #ifdef YYTYPE_UINT8
291 typedef YYTYPE_UINT8 yytype_uint8;
292 #else
293 typedef unsigned char yytype_uint8;
294 #endif
295
296 #ifdef YYTYPE_INT8
297 typedef YYTYPE_INT8 yytype_int8;
298 #else
299 typedef signed char yytype_int8;
300 #endif
301
302 #ifdef YYTYPE_UINT16
303 typedef YYTYPE_UINT16 yytype_uint16;
304 #else
305 typedef unsigned short int yytype_uint16;
306 #endif
307
308 #ifdef YYTYPE_INT16
309 typedef YYTYPE_INT16 yytype_int16;
310 #else
311 typedef short int yytype_int16;
312 #endif
313
314 #ifndef YYSIZE_T
315 # ifdef __SIZE_TYPE__
316 #  define YYSIZE_T __SIZE_TYPE__
317 # elif defined size_t
318 #  define YYSIZE_T size_t
319 # elif ! defined YYSIZE_T
320 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
321 #  define YYSIZE_T size_t
322 # else
323 #  define YYSIZE_T unsigned int
324 # endif
325 #endif
326
327 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
328
329 #ifndef YY_
330 # if defined YYENABLE_NLS && YYENABLE_NLS
331 #  if ENABLE_NLS
332 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
333 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
334 #  endif
335 # endif
336 # ifndef YY_
337 #  define YY_(Msgid) Msgid
338 # endif
339 #endif
340
341 #ifndef YY_ATTRIBUTE
342 # if (defined __GNUC__                                               \
343       && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__)))  \
344      || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
345 #  define YY_ATTRIBUTE(Spec) __attribute__(Spec)
346 # else
347 #  define YY_ATTRIBUTE(Spec) /* empty */
348 # endif
349 #endif
350
351 #ifndef YY_ATTRIBUTE_PURE
352 # define YY_ATTRIBUTE_PURE   YY_ATTRIBUTE ((__pure__))
353 #endif
354
355 #ifndef YY_ATTRIBUTE_UNUSED
356 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
357 #endif
358
359 #if !defined _Noreturn \
360      && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
361 # if defined _MSC_VER && 1200 <= _MSC_VER
362 #  define _Noreturn __declspec (noreturn)
363 # else
364 #  define _Noreturn YY_ATTRIBUTE ((__noreturn__))
365 # endif
366 #endif
367
368 /* Suppress unused-variable warnings by "using" E.  */
369 #if ! defined lint || defined __GNUC__
370 # define YYUSE(E) ((void) (E))
371 #else
372 # define YYUSE(E) /* empty */
373 #endif
374
375 #if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
376 /* Suppress an incorrect diagnostic about yylval being uninitialized.  */
377 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
378     _Pragma ("GCC diagnostic push") \
379     _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
380     _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
381 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
382     _Pragma ("GCC diagnostic pop")
383 #else
384 # define YY_INITIAL_VALUE(Value) Value
385 #endif
386 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
387 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
388 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
389 #endif
390 #ifndef YY_INITIAL_VALUE
391 # define YY_INITIAL_VALUE(Value) /* Nothing. */
392 #endif
393
394
395 #if ! defined yyoverflow || YYERROR_VERBOSE
396
397 /* The parser invokes alloca or malloc; define the necessary symbols.  */
398
399 # ifdef YYSTACK_USE_ALLOCA
400 #  if YYSTACK_USE_ALLOCA
401 #   ifdef __GNUC__
402 #    define YYSTACK_ALLOC __builtin_alloca
403 #   elif defined __BUILTIN_VA_ARG_INCR
404 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
405 #   elif defined _AIX
406 #    define YYSTACK_ALLOC __alloca
407 #   elif defined _MSC_VER
408 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
409 #    define alloca _alloca
410 #   else
411 #    define YYSTACK_ALLOC alloca
412 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
413 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
414       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
415 #     ifndef EXIT_SUCCESS
416 #      define EXIT_SUCCESS 0
417 #     endif
418 #    endif
419 #   endif
420 #  endif
421 # endif
422
423 # ifdef YYSTACK_ALLOC
424    /* Pacify GCC's 'empty if-body' warning.  */
425 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
426 #  ifndef YYSTACK_ALLOC_MAXIMUM
427     /* The OS might guarantee only one guard page at the bottom of the stack,
428        and a page size can be as small as 4096 bytes.  So we cannot safely
429        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
430        to allow for a few compiler-allocated temporary stack slots.  */
431 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
432 #  endif
433 # else
434 #  define YYSTACK_ALLOC YYMALLOC
435 #  define YYSTACK_FREE YYFREE
436 #  ifndef YYSTACK_ALLOC_MAXIMUM
437 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
438 #  endif
439 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
440        && ! ((defined YYMALLOC || defined malloc) \
441              && (defined YYFREE || defined free)))
442 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
443 #   ifndef EXIT_SUCCESS
444 #    define EXIT_SUCCESS 0
445 #   endif
446 #  endif
447 #  ifndef YYMALLOC
448 #   define YYMALLOC malloc
449 #   if ! defined malloc && ! defined EXIT_SUCCESS
450 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
451 #   endif
452 #  endif
453 #  ifndef YYFREE
454 #   define YYFREE free
455 #   if ! defined free && ! defined EXIT_SUCCESS
456 void free (void *); /* INFRINGES ON USER NAME SPACE */
457 #   endif
458 #  endif
459 # endif
460 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
461
462
463 #if (! defined yyoverflow \
464      && (! defined __cplusplus \
465          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
466
467 /* A type that is properly aligned for any stack member.  */
468 union yyalloc
469 {
470   yytype_int16 yyss_alloc;
471   YYSTYPE yyvs_alloc;
472 };
473
474 /* The size of the maximum gap between one aligned stack and the next.  */
475 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
476
477 /* The size of an array large to enough to hold all stacks, each with
478    N elements.  */
479 # define YYSTACK_BYTES(N) \
480      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
481       + YYSTACK_GAP_MAXIMUM)
482
483 # define YYCOPY_NEEDED 1
484
485 /* Relocate STACK from its old location to the new one.  The
486    local variables YYSIZE and YYSTACKSIZE give the old and new number of
487    elements in the stack, and YYPTR gives the new location of the
488    stack.  Advance YYPTR to a properly aligned location for the next
489    stack.  */
490 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
491     do                                                                  \
492       {                                                                 \
493         YYSIZE_T yynewbytes;                                            \
494         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
495         Stack = &yyptr->Stack_alloc;                                    \
496         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
497         yyptr += yynewbytes / sizeof (*yyptr);                          \
498       }                                                                 \
499     while (0)
500
501 #endif
502
503 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
504 /* Copy COUNT objects from SRC to DST.  The source and destination do
505    not overlap.  */
506 # ifndef YYCOPY
507 #  if defined __GNUC__ && 1 < __GNUC__
508 #   define YYCOPY(Dst, Src, Count) \
509       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
510 #  else
511 #   define YYCOPY(Dst, Src, Count)              \
512       do                                        \
513         {                                       \
514           YYSIZE_T yyi;                         \
515           for (yyi = 0; yyi < (Count); yyi++)   \
516             (Dst)[yyi] = (Src)[yyi];            \
517         }                                       \
518       while (0)
519 #  endif
520 # endif
521 #endif /* !YYCOPY_NEEDED */
522
523 /* YYFINAL -- State number of the termination state.  */
524 #define YYFINAL  2
525 /* YYLAST -- Last index in YYTABLE.  */
526 #define YYLAST   203
527
528 /* YYNTOKENS -- Number of terminals.  */
529 #define YYNTOKENS  59
530 /* YYNNTS -- Number of nonterminals.  */
531 #define YYNNTS  55
532 /* YYNRULES -- Number of rules.  */
533 #define YYNRULES  156
534 /* YYNSTATES -- Number of states.  */
535 #define YYNSTATES  203
536
537 /* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned
538    by yylex, with out-of-bounds checking.  */
539 #define YYUNDEFTOK  2
540 #define YYMAXUTOK   303
541
542 #define YYTRANSLATE(YYX)                                                \
543   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
544
545 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
546    as returned by yylex, without out-of-bounds checking.  */
547 static const yytype_uint8 yytranslate[] =
548 {
549        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
550       58,     2,     2,     2,     2,     2,     2,     2,     2,     2,
551        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
552        2,     2,     2,     2,     2,     2,    57,     2,     2,     2,
553        2,     2,     2,    53,    50,    54,     2,     2,     2,     2,
554        2,     2,     2,     2,     2,     2,     2,     2,    51,     2,
555        2,    49,     2,     2,    52,     2,     2,     2,     2,     2,
556        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
557        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
558        2,    55,     2,    56,     2,     2,     2,     2,     2,     2,
559        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
560        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
561        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
562        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
563        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
564        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
565        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
566        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
567        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
568        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
569        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
570        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
571        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
572        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
573        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
574        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
575        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
576       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
577       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
578       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
579       45,    46,    47,    48
580 };
581
582 #if YYDEBUG
583   /* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
584 static const yytype_uint16 yyrline[] =
585 {
586        0,   106,   106,   108,   126,   127,   177,   184,   185,   186,
587      187,   188,   192,   193,   194,   195,   199,   200,   201,   202,
588      206,   207,   212,   216,   236,   243,   243,   250,   266,   280,
589      281,   282,   283,   284,   285,   291,   303,   304,   305,   305,
590      306,   306,   307,   308,   309,   310,   311,   311,   312,   313,
591      313,   314,   314,   315,   315,   316,   317,   318,   323,   328,
592      354,   364,   369,   381,   381,   389,   403,   416,   417,   423,
593      424,   428,   429,   430,   431,   437,   438,   439,   444,   455,
594      456,   461,   469,   486,   487,   488,   489,   490,   495,   496,
595      496,   497,   498,   498,   499,   504,   505,   510,   511,   516,
596      517,   520,   522,   526,   527,   542,   543,   548,   556,   557,
597      558,   559,   563,   564,   568,   569,   570,   575,   576,   578,
598      585,   586,   587,   588,   589,   590,   594,   607,   608,   609,
599      613,   614,   615,   616,   620,   622,   624,   628,   643,   647,
600      649,   654,   655,   664,   674,   676,   683,   696,   697,   703,
601      704,   709,   715,   724,   726,   728,   736
602 };
603 #endif
604
605 #if YYDEBUG || YYERROR_VERBOSE || 0
606 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
607    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
608 static const char *const yytname[] =
609 {
610   "$end", "error", "$undefined", "D_BACKTRACE", "D_BREAK", "D_CLEAR",
611   "D_CONTINUE", "D_DELETE", "D_DISABLE", "D_DOWN", "D_ENABLE", "D_FINISH",
612   "D_FRAME", "D_HELP", "D_IGNORE", "D_INFO", "D_LIST", "D_NEXT", "D_NEXTI",
613   "D_PRINT", "D_PRINTF", "D_QUIT", "D_RETURN", "D_RUN", "D_SET", "D_STEP",
614   "D_STEPI", "D_TBREAK", "D_UP", "D_UNTIL", "D_DISPLAY", "D_UNDISPLAY",
615   "D_WATCH", "D_UNWATCH", "D_DUMP", "D_TRACE", "D_INT", "D_STRING",
616   "D_NODE", "D_VARIABLE", "D_OPTION", "D_COMMANDS", "D_END", "D_SILENT",
617   "D_SOURCE", "D_SAVE", "D_EVAL", "D_CONDITION", "D_STATEMENT", "'='",
618   "','", "':'", "'@'", "'+'", "'-'", "'['", "']'", "'$'", "'\\n'",
619   "$accept", "input", "line", "control_cmd", "d_cmd", "frame_cmd",
620   "break_cmd", "set_want_nodeval", "eval_prologue", "statement_list", "@1",
621   "eval_cmd", "command", "$@2", "$@3", "$@4", "$@5", "$@6", "$@7", "$@8",
622   "condition_exp", "commands_arg", "opt_param_list", "param_list",
623   "opt_string_node", "string_node", "option_args", "func_name", "location",
624   "break_args", "$@9", "$@10", "opt_variable", "opt_string", "opt_node",
625   "help_args", "enable_args", "print_exp", "print_args", "printf_exp",
626   "printf_args", "list_args", "integer_range", "opt_integer_list",
627   "integer_list", "exp_list", "subscript", "subscript_list", "variable",
628   "node", "opt_plus_integer", "opt_integer", "plus_integer", "integer",
629   "nls", YY_NULLPTR
630 };
631 #endif
632
633 # ifdef YYPRINT
634 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
635    (internal) symbol number NUM (which must be that of a token).  */
636 static const yytype_uint16 yytoknum[] =
637 {
638        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
639      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
640      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
641      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
642      295,   296,   297,   298,   299,   300,   301,   302,   303,    61,
643       44,    58,    64,    43,    45,    91,    93,    36,    10
644 };
645 # endif
646
647 #define YYPACT_NINF -151
648
649 #define yypact_value_is_default(Yystate) \
650   (!!((Yystate) == (-151)))
651
652 #define YYTABLE_NINF -148
653
654 #define yytable_value_is_error(Yytable_value) \
655   0
656
657   /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
658      STATE-NUM.  */
659 static const yytype_int16 yypact[] =
660 {
661     -151,   145,  -151,   -34,  -151,  -151,    50,  -151,  -151,  -151,
662     -151,    10,  -151,  -151,   -10,    59,    -9,    43,  -151,  -151,
663     -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,
664       50,  -151,  -151,  -151,  -151,    -8,    -6,    14,    12,  -151,
665     -151,    22,    23,  -151,    59,  -151,  -151,    59,    13,    36,
666       64,  -151,  -151,   -34,  -151,  -151,  -151,    24,    47,  -151,
667     -151,  -151,  -151,    13,  -151,  -151,  -151,    59,    48,  -151,
668     -151,    80,  -151,    67,    47,  -151,  -151,  -151,  -151,    48,
669        4,    19,    69,   -20,  -151,   -20,   -20,  -151,  -151,  -151,
670       70,  -151,  -151,  -151,  -151,  -151,  -151,  -151,    16,  -151,
671     -151,  -151,  -151,    84,    85,  -151,  -151,    73,  -151,  -151,
672     -151,    40,  -151,    74,  -151,  -151,  -151,    48,    59,  -151,
673       74,  -151,    71,    89,    91,  -151,    42,  -151,  -151,  -151,
674     -151,    81,  -151,  -151,    92,    94,  -151,  -151,    86,  -151,
675     -151,     6,    96,  -151,  -151,  -151,   -34,    75,  -151,     6,
676     -151,  -151,    74,     6,  -151,  -151,  -151,  -151,  -151,  -151,
677     -151,  -151,    48,    31,  -151,    71,    71,  -151,    52,  -151,
678      -17,  -151,  -151,    69,  -151,  -151,  -151,  -151,  -151,  -151,
679     -151,    95,  -151,  -151,  -151,  -151,   -34,  -151,    17,  -151,
680     -151,    71,  -151,  -151,  -151,  -151,     6,  -151,  -151,    69,
681     -151,  -151,  -151
682 };
683
684   /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
685      Performed when YYTABLE does not specify something else to do.  Zero
686      means the default is an error.  */
687 static const yytype_uint8 yydefact[] =
688 {
689        2,     0,     1,     0,    18,    20,    83,     7,    15,    14,
690       17,     0,    32,    19,   101,     0,     0,   117,     8,     9,
691       38,    40,    30,    49,    31,    46,    10,    11,    21,    16,
692       83,    51,    12,    53,    13,    97,     0,    79,     0,    60,
693       61,     0,     0,    22,     0,   156,     3,   147,     0,   149,
694       88,    24,    65,     0,     4,     6,   151,    82,     0,    85,
695       44,    84,   129,     0,    37,   131,   103,   128,   130,   102,
696       29,     0,    35,    82,   118,   119,   121,    42,   122,   120,
697        0,     0,    99,     0,    43,    95,     0,    98,    56,    62,
698       80,    48,    68,    59,    67,   148,    57,    58,     0,    63,
699       33,    55,   153,     0,     0,    34,   150,    82,    91,    45,
700       89,     0,     5,     0,   152,   104,   133,   132,     0,    36,
701        0,   111,   141,     0,     0,   108,    39,   105,   116,   112,
702      114,    41,   113,   144,     0,     0,    50,   100,     0,    52,
703       96,     0,     0,    74,    78,    71,     0,    70,    28,     0,
704      154,   155,     0,     0,    27,    25,    82,    87,    86,   126,
705      124,   125,   123,     0,   139,   143,   106,   142,     0,   109,
706        0,   145,   146,     0,    77,    54,    66,    76,    81,    23,
707       72,     0,    64,    94,    92,    90,     0,   136,     0,   134,
708      140,   107,   110,   115,    47,    73,     0,    26,   138,     0,
709      137,    93,   135
710 };
711
712   /* YYPGOTO[NTERM-NUM].  */
713 static const yytype_int16 yypgoto[] =
714 {
715     -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,
716     -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,  -151,
717     -119,  -151,  -151,  -151,  -151,    38,  -151,   -15,   108,  -151,
718     -151,  -151,  -151,  -151,  -151,  -151,  -151,   -90,  -151,   -31,
719     -151,  -151,   -14,   -25,  -151,  -151,  -150,   -26,   -77,  -147,
720       97,  -151,    -5,  -151,    -3
721 };
722
723   /* YYDEFGOTO[NTERM-NUM].  */
724 static const yytype_int16 yydefgoto[] =
725 {
726       -1,     1,    46,    47,    48,    49,    50,    98,    51,   111,
727      186,    52,    53,    80,    81,    83,    82,    85,    86,   149,
728      175,    93,   146,   147,   176,   177,    91,    59,    60,   109,
729      153,   196,   139,    88,   136,    70,    64,   125,   126,   130,
730      131,    77,    65,    66,    67,   188,   164,   165,   127,   137,
731       94,   105,    68,   106,    54
732 };
733
734   /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
735      positive, shift that token.  If negative, reduce the rule whose
736      number is the opposite.  If YYTABLE_NINF, syntax error.  */
737 static const yytype_int16 yytable[] =
738 {
739       55,    61,    76,    78,   132,   121,   138,   174,   140,   141,
740       71,    62,    79,    92,    62,   190,   189,   143,   198,   122,
741      128,   129,   122,   101,    45,    61,   194,    69,    72,    87,
742      182,    89,   187,    95,   185,   108,   169,   124,   115,    99,
743      124,   190,    95,   122,   144,   110,    56,    63,    56,    56,
744      112,    90,   202,   116,   144,   145,   123,   129,   122,    96,
745       97,   124,   117,    58,   -75,    58,    58,   199,  -127,   133,
746     -147,  -127,   102,   200,   -69,   113,   124,   201,   192,    56,
747       73,   122,   154,   114,   134,   135,    56,    57,   155,   103,
748      104,   122,   168,   132,   123,    56,    74,    75,   157,   124,
749       56,   107,   118,    58,   123,   160,   161,   133,   158,   124,
750       56,   156,    58,   159,   180,   162,   119,    58,   120,   142,
751      150,   151,   134,   135,   152,   181,   163,    58,   166,   167,
752      171,   170,   172,   178,   195,   173,   148,   183,    84,   193,
753      191,     0,     0,   179,   100,     2,     3,   184,     4,     5,
754        6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
755       16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
756       26,    27,    28,    29,    30,    31,    32,    33,    34,    35,
757       36,     0,     0,   197,     0,    37,    38,    39,    40,    41,
758       42,    43,    44,     0,     0,     0,     0,     0,     0,     0,
759        0,     0,     0,    45
760 };
761
762 static const yytype_int16 yycheck[] =
763 {
764        3,     6,    17,    17,    81,     1,    83,     1,    85,    86,
765       15,     1,    17,     1,     1,   165,   163,     1,     1,    39,
766        1,    38,    39,    48,    58,    30,   173,    37,    37,    37,
767      149,    37,     1,    38,   153,    50,   126,    57,    63,    44,
768       57,   191,    47,    39,    38,    50,    36,    37,    36,    36,
769       53,    37,   199,    67,    38,    39,    52,    38,    39,    37,
770       37,    57,    67,    53,    58,    53,    53,    50,    58,    38,
771       58,    58,    36,    56,    58,    51,    57,   196,   168,    36,
772       37,    39,    42,    36,    53,    54,    36,    37,    48,    53,
773       54,    39,    50,   170,    52,    36,    53,    54,   113,    57,
774       36,    37,    54,    53,    52,   120,   120,    38,   113,    57,
775       36,    37,    53,   118,    39,   120,    36,    53,    51,    49,
776       36,    36,    53,    54,    51,    50,    55,    53,    39,    38,
777       38,    50,    38,    37,    39,    49,    98,   152,    30,   170,
778      166,    -1,    -1,   146,    47,     0,     1,   152,     3,     4,
779        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
780       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
781       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
782       35,    -1,    -1,   186,    -1,    40,    41,    42,    43,    44,
783       45,    46,    47,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
784       -1,    -1,    -1,    58
785 };
786
787   /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
788      symbol of state STATE-NUM.  */
789 static const yytype_uint8 yystos[] =
790 {
791        0,    60,     0,     1,     3,     4,     5,     6,     7,     8,
792        9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
793       19,    20,    21,    22,    23,    24,    25,    26,    27,    28,
794       29,    30,    31,    32,    33,    34,    35,    40,    41,    42,
795       43,    44,    45,    46,    47,    58,    61,    62,    63,    64,
796       65,    67,    70,    71,   113,   113,    36,    37,    53,    86,
797       87,   111,     1,    37,    95,   101,   102,   103,   111,    37,
798       94,   111,    37,    37,    53,    54,    86,   100,   101,   111,
799       72,    73,    75,    74,    87,    76,    77,    37,    92,    37,
800       37,    85,     1,    80,   109,   111,    37,    37,    66,   111,
801      109,   102,    36,    53,    54,   110,   112,    37,    86,    88,
802      111,    68,   113,    51,    36,   102,   101,   111,    54,    36,
803       51,     1,    39,    52,    57,    96,    97,   107,     1,    38,
804       98,    99,   107,    38,    53,    54,    93,   108,   107,    91,
805      107,   107,    49,     1,    38,    39,    81,    82,    84,    78,
806       36,    36,    51,    89,    42,    48,    37,    86,   111,   111,
807       86,   101,   111,    55,   105,   106,    39,    38,    50,    96,
808       50,    38,    38,    49,     1,    79,    83,    84,    37,   113,
809       39,    50,    79,    86,   111,    79,    69,     1,   104,   108,
810      105,   106,    96,    98,   108,    39,    90,   113,     1,    50,
811       56,    79,   108
812 };
813
814   /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
815 static const yytype_uint8 yyr1[] =
816 {
817        0,    59,    60,    60,    61,    61,    61,    62,    62,    62,
818       62,    62,    63,    63,    63,    63,    64,    64,    64,    64,
819       65,    65,    66,    67,    68,    69,    68,    70,    70,    71,
820       71,    71,    71,    71,    71,    71,    71,    71,    72,    71,
821       73,    71,    71,    71,    71,    71,    74,    71,    71,    75,
822       71,    76,    71,    77,    71,    71,    71,    71,    71,    71,
823       71,    71,    71,    78,    71,    71,    79,    80,    80,    81,
824       81,    82,    82,    82,    82,    83,    83,    83,    84,    85,
825       85,    85,    86,    87,    87,    87,    87,    87,    88,    89,
826       88,    88,    90,    88,    88,    91,    91,    92,    92,    93,
827       93,    94,    94,    95,    95,    96,    96,    96,    97,    97,
828       97,    97,    98,    98,    99,    99,    99,   100,   100,   100,
829      100,   100,   100,   100,   100,   100,   101,   102,   102,   102,
830      103,   103,   103,   103,   104,   104,   104,   105,   105,   106,
831      106,   107,   107,   107,   108,   108,   108,   109,   109,   110,
832      110,   111,   111,   112,   112,   112,   113
833 };
834
835   /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.  */
836 static const yytype_uint8 yyr2[] =
837 {
838        0,     2,     0,     2,     1,     2,     2,     1,     1,     1,
839        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
840        1,     1,     0,     4,     0,     0,     4,     3,     3,     2,
841        1,     1,     1,     2,     2,     2,     3,     2,     0,     3,
842        0,     3,     2,     2,     2,     2,     0,     5,     2,     0,
843        3,     0,     3,     0,     4,     2,     2,     2,     2,     2,
844        1,     1,     2,     0,     4,     1,     1,     1,     1,     0,
845        1,     1,     2,     3,     1,     0,     1,     1,     1,     0,
846        1,     3,     1,     0,     1,     1,     3,     3,     0,     0,
847        3,     1,     0,     5,     3,     0,     1,     0,     1,     0,
848        1,     0,     1,     1,     2,     1,     2,     3,     1,     2,
849        3,     1,     1,     1,     1,     3,     1,     0,     1,     1,
850        1,     1,     1,     3,     3,     3,     3,     0,     1,     1,
851        1,     1,     2,     2,     1,     3,     1,     3,     3,     1,
852        2,     1,     2,     2,     1,     2,     2,     0,     1,     0,
853        1,     1,     2,     1,     2,     2,     1
854 };
855
856
857 #define yyerrok         (yyerrstatus = 0)
858 #define yyclearin       (yychar = YYEMPTY)
859 #define YYEMPTY         (-2)
860 #define YYEOF           0
861
862 #define YYACCEPT        goto yyacceptlab
863 #define YYABORT         goto yyabortlab
864 #define YYERROR         goto yyerrorlab
865
866
867 #define YYRECOVERING()  (!!yyerrstatus)
868
869 #define YYBACKUP(Token, Value)                                  \
870 do                                                              \
871   if (yychar == YYEMPTY)                                        \
872     {                                                           \
873       yychar = (Token);                                         \
874       yylval = (Value);                                         \
875       YYPOPSTACK (yylen);                                       \
876       yystate = *yyssp;                                         \
877       goto yybackup;                                            \
878     }                                                           \
879   else                                                          \
880     {                                                           \
881       yyerror (YY_("syntax error: cannot back up")); \
882       YYERROR;                                                  \
883     }                                                           \
884 while (0)
885
886 /* Error token number */
887 #define YYTERROR        1
888 #define YYERRCODE       256
889
890
891
892 /* Enable debugging if requested.  */
893 #if YYDEBUG
894
895 # ifndef YYFPRINTF
896 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
897 #  define YYFPRINTF fprintf
898 # endif
899
900 # define YYDPRINTF(Args)                        \
901 do {                                            \
902   if (yydebug)                                  \
903     YYFPRINTF Args;                             \
904 } while (0)
905
906 /* This macro is provided for backward compatibility. */
907 #ifndef YY_LOCATION_PRINT
908 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
909 #endif
910
911
912 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
913 do {                                                                      \
914   if (yydebug)                                                            \
915     {                                                                     \
916       YYFPRINTF (stderr, "%s ", Title);                                   \
917       yy_symbol_print (stderr,                                            \
918                   Type, Value); \
919       YYFPRINTF (stderr, "\n");                                           \
920     }                                                                     \
921 } while (0)
922
923
924 /*----------------------------------------.
925 | Print this symbol's value on YYOUTPUT.  |
926 `----------------------------------------*/
927
928 static void
929 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
930 {
931   FILE *yyo = yyoutput;
932   YYUSE (yyo);
933   if (!yyvaluep)
934     return;
935 # ifdef YYPRINT
936   if (yytype < YYNTOKENS)
937     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
938 # endif
939   YYUSE (yytype);
940 }
941
942
943 /*--------------------------------.
944 | Print this symbol on YYOUTPUT.  |
945 `--------------------------------*/
946
947 static void
948 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
949 {
950   YYFPRINTF (yyoutput, "%s %s (",
951              yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
952
953   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
954   YYFPRINTF (yyoutput, ")");
955 }
956
957 /*------------------------------------------------------------------.
958 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
959 | TOP (included).                                                   |
960 `------------------------------------------------------------------*/
961
962 static void
963 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
964 {
965   YYFPRINTF (stderr, "Stack now");
966   for (; yybottom <= yytop; yybottom++)
967     {
968       int yybot = *yybottom;
969       YYFPRINTF (stderr, " %d", yybot);
970     }
971   YYFPRINTF (stderr, "\n");
972 }
973
974 # define YY_STACK_PRINT(Bottom, Top)                            \
975 do {                                                            \
976   if (yydebug)                                                  \
977     yy_stack_print ((Bottom), (Top));                           \
978 } while (0)
979
980
981 /*------------------------------------------------.
982 | Report that the YYRULE is going to be reduced.  |
983 `------------------------------------------------*/
984
985 static void
986 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
987 {
988   unsigned long int yylno = yyrline[yyrule];
989   int yynrhs = yyr2[yyrule];
990   int yyi;
991   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
992              yyrule - 1, yylno);
993   /* The symbols being reduced.  */
994   for (yyi = 0; yyi < yynrhs; yyi++)
995     {
996       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
997       yy_symbol_print (stderr,
998                        yystos[yyssp[yyi + 1 - yynrhs]],
999                        &(yyvsp[(yyi + 1) - (yynrhs)])
1000                                               );
1001       YYFPRINTF (stderr, "\n");
1002     }
1003 }
1004
1005 # define YY_REDUCE_PRINT(Rule)          \
1006 do {                                    \
1007   if (yydebug)                          \
1008     yy_reduce_print (yyssp, yyvsp, Rule); \
1009 } while (0)
1010
1011 /* Nonzero means print parse trace.  It is left uninitialized so that
1012    multiple parsers can coexist.  */
1013 int yydebug;
1014 #else /* !YYDEBUG */
1015 # define YYDPRINTF(Args)
1016 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1017 # define YY_STACK_PRINT(Bottom, Top)
1018 # define YY_REDUCE_PRINT(Rule)
1019 #endif /* !YYDEBUG */
1020
1021
1022 /* YYINITDEPTH -- initial size of the parser's stacks.  */
1023 #ifndef YYINITDEPTH
1024 # define YYINITDEPTH 200
1025 #endif
1026
1027 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1028    if the built-in stack extension method is used).
1029
1030    Do not make this value too large; the results are undefined if
1031    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1032    evaluated with infinite-precision integer arithmetic.  */
1033
1034 #ifndef YYMAXDEPTH
1035 # define YYMAXDEPTH 10000
1036 #endif
1037
1038
1039 #if YYERROR_VERBOSE
1040
1041 # ifndef yystrlen
1042 #  if defined __GLIBC__ && defined _STRING_H
1043 #   define yystrlen strlen
1044 #  else
1045 /* Return the length of YYSTR.  */
1046 static YYSIZE_T
1047 yystrlen (const char *yystr)
1048 {
1049   YYSIZE_T yylen;
1050   for (yylen = 0; yystr[yylen]; yylen++)
1051     continue;
1052   return yylen;
1053 }
1054 #  endif
1055 # endif
1056
1057 # ifndef yystpcpy
1058 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1059 #   define yystpcpy stpcpy
1060 #  else
1061 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1062    YYDEST.  */
1063 static char *
1064 yystpcpy (char *yydest, const char *yysrc)
1065 {
1066   char *yyd = yydest;
1067   const char *yys = yysrc;
1068
1069   while ((*yyd++ = *yys++) != '\0')
1070     continue;
1071
1072   return yyd - 1;
1073 }
1074 #  endif
1075 # endif
1076
1077 # ifndef yytnamerr
1078 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1079    quotes and backslashes, so that it's suitable for yyerror.  The
1080    heuristic is that double-quoting is unnecessary unless the string
1081    contains an apostrophe, a comma, or backslash (other than
1082    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
1083    null, do not copy; instead, return the length of what the result
1084    would have been.  */
1085 static YYSIZE_T
1086 yytnamerr (char *yyres, const char *yystr)
1087 {
1088   if (*yystr == '"')
1089     {
1090       YYSIZE_T yyn = 0;
1091       char const *yyp = yystr;
1092
1093       for (;;)
1094         switch (*++yyp)
1095           {
1096           case '\'':
1097           case ',':
1098             goto do_not_strip_quotes;
1099
1100           case '\\':
1101             if (*++yyp != '\\')
1102               goto do_not_strip_quotes;
1103             /* Fall through.  */
1104           default:
1105             if (yyres)
1106               yyres[yyn] = *yyp;
1107             yyn++;
1108             break;
1109
1110           case '"':
1111             if (yyres)
1112               yyres[yyn] = '\0';
1113             return yyn;
1114           }
1115     do_not_strip_quotes: ;
1116     }
1117
1118   if (! yyres)
1119     return yystrlen (yystr);
1120
1121   return yystpcpy (yyres, yystr) - yyres;
1122 }
1123 # endif
1124
1125 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1126    about the unexpected token YYTOKEN for the state stack whose top is
1127    YYSSP.
1128
1129    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1130    not large enough to hold the message.  In that case, also set
1131    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1132    required number of bytes is too large to store.  */
1133 static int
1134 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1135                 yytype_int16 *yyssp, int yytoken)
1136 {
1137   YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1138   YYSIZE_T yysize = yysize0;
1139   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1140   /* Internationalized format string. */
1141   const char *yyformat = YY_NULLPTR;
1142   /* Arguments of yyformat. */
1143   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1144   /* Number of reported tokens (one for the "unexpected", one per
1145      "expected"). */
1146   int yycount = 0;
1147
1148   /* There are many possibilities here to consider:
1149      - If this state is a consistent state with a default action, then
1150        the only way this function was invoked is if the default action
1151        is an error action.  In that case, don't check for expected
1152        tokens because there are none.
1153      - The only way there can be no lookahead present (in yychar) is if
1154        this state is a consistent state with a default action.  Thus,
1155        detecting the absence of a lookahead is sufficient to determine
1156        that there is no unexpected or expected token to report.  In that
1157        case, just report a simple "syntax error".
1158      - Don't assume there isn't a lookahead just because this state is a
1159        consistent state with a default action.  There might have been a
1160        previous inconsistent state, consistent state with a non-default
1161        action, or user semantic action that manipulated yychar.
1162      - Of course, the expected token list depends on states to have
1163        correct lookahead information, and it depends on the parser not
1164        to perform extra reductions after fetching a lookahead from the
1165        scanner and before detecting a syntax error.  Thus, state merging
1166        (from LALR or IELR) and default reductions corrupt the expected
1167        token list.  However, the list is correct for canonical LR with
1168        one exception: it will still contain any token that will not be
1169        accepted due to an error action in a later state.
1170   */
1171   if (yytoken != YYEMPTY)
1172     {
1173       int yyn = yypact[*yyssp];
1174       yyarg[yycount++] = yytname[yytoken];
1175       if (!yypact_value_is_default (yyn))
1176         {
1177           /* Start YYX at -YYN if negative to avoid negative indexes in
1178              YYCHECK.  In other words, skip the first -YYN actions for
1179              this state because they are default actions.  */
1180           int yyxbegin = yyn < 0 ? -yyn : 0;
1181           /* Stay within bounds of both yycheck and yytname.  */
1182           int yychecklim = YYLAST - yyn + 1;
1183           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1184           int yyx;
1185
1186           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1187             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1188                 && !yytable_value_is_error (yytable[yyx + yyn]))
1189               {
1190                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1191                   {
1192                     yycount = 1;
1193                     yysize = yysize0;
1194                     break;
1195                   }
1196                 yyarg[yycount++] = yytname[yyx];
1197                 {
1198                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1199                   if (! (yysize <= yysize1
1200                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1201                     return 2;
1202                   yysize = yysize1;
1203                 }
1204               }
1205         }
1206     }
1207
1208   switch (yycount)
1209     {
1210 # define YYCASE_(N, S)                      \
1211       case N:                               \
1212         yyformat = S;                       \
1213       break
1214       YYCASE_(0, YY_("syntax error"));
1215       YYCASE_(1, YY_("syntax error, unexpected %s"));
1216       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1217       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1218       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1219       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1220 # undef YYCASE_
1221     }
1222
1223   {
1224     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1225     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1226       return 2;
1227     yysize = yysize1;
1228   }
1229
1230   if (*yymsg_alloc < yysize)
1231     {
1232       *yymsg_alloc = 2 * yysize;
1233       if (! (yysize <= *yymsg_alloc
1234              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1235         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1236       return 1;
1237     }
1238
1239   /* Avoid sprintf, as that infringes on the user's name space.
1240      Don't have undefined behavior even if the translation
1241      produced a string with the wrong number of "%s"s.  */
1242   {
1243     char *yyp = *yymsg;
1244     int yyi = 0;
1245     while ((*yyp = *yyformat) != '\0')
1246       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1247         {
1248           yyp += yytnamerr (yyp, yyarg[yyi++]);
1249           yyformat += 2;
1250         }
1251       else
1252         {
1253           yyp++;
1254           yyformat++;
1255         }
1256   }
1257   return 0;
1258 }
1259 #endif /* YYERROR_VERBOSE */
1260
1261 /*-----------------------------------------------.
1262 | Release the memory associated to this symbol.  |
1263 `-----------------------------------------------*/
1264
1265 static void
1266 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1267 {
1268   YYUSE (yyvaluep);
1269   if (!yymsg)
1270     yymsg = "Deleting";
1271   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1272
1273   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1274   YYUSE (yytype);
1275   YY_IGNORE_MAYBE_UNINITIALIZED_END
1276 }
1277
1278
1279
1280
1281 /* The lookahead symbol.  */
1282 int yychar;
1283
1284 /* The semantic value of the lookahead symbol.  */
1285 YYSTYPE yylval;
1286 /* Number of syntax errors so far.  */
1287 int yynerrs;
1288
1289
1290 /*----------.
1291 | yyparse.  |
1292 `----------*/
1293
1294 int
1295 yyparse (void)
1296 {
1297     int yystate;
1298     /* Number of tokens to shift before error messages enabled.  */
1299     int yyerrstatus;
1300
1301     /* The stacks and their tools:
1302        'yyss': related to states.
1303        'yyvs': related to semantic values.
1304
1305        Refer to the stacks through separate pointers, to allow yyoverflow
1306        to reallocate them elsewhere.  */
1307
1308     /* The state stack.  */
1309     yytype_int16 yyssa[YYINITDEPTH];
1310     yytype_int16 *yyss;
1311     yytype_int16 *yyssp;
1312
1313     /* The semantic value stack.  */
1314     YYSTYPE yyvsa[YYINITDEPTH];
1315     YYSTYPE *yyvs;
1316     YYSTYPE *yyvsp;
1317
1318     YYSIZE_T yystacksize;
1319
1320   int yyn;
1321   int yyresult;
1322   /* Lookahead token as an internal (translated) token number.  */
1323   int yytoken = 0;
1324   /* The variables used to return semantic value and location from the
1325      action routines.  */
1326   YYSTYPE yyval;
1327
1328 #if YYERROR_VERBOSE
1329   /* Buffer for error messages, and its allocated size.  */
1330   char yymsgbuf[128];
1331   char *yymsg = yymsgbuf;
1332   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1333 #endif
1334
1335 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1336
1337   /* The number of symbols on the RHS of the reduced rule.
1338      Keep to zero when no symbol should be popped.  */
1339   int yylen = 0;
1340
1341   yyssp = yyss = yyssa;
1342   yyvsp = yyvs = yyvsa;
1343   yystacksize = YYINITDEPTH;
1344
1345   YYDPRINTF ((stderr, "Starting parse\n"));
1346
1347   yystate = 0;
1348   yyerrstatus = 0;
1349   yynerrs = 0;
1350   yychar = YYEMPTY; /* Cause a token to be read.  */
1351   goto yysetstate;
1352
1353 /*------------------------------------------------------------.
1354 | yynewstate -- Push a new state, which is found in yystate.  |
1355 `------------------------------------------------------------*/
1356  yynewstate:
1357   /* In all cases, when you get here, the value and location stacks
1358      have just been pushed.  So pushing a state here evens the stacks.  */
1359   yyssp++;
1360
1361  yysetstate:
1362   *yyssp = yystate;
1363
1364   if (yyss + yystacksize - 1 <= yyssp)
1365     {
1366       /* Get the current used size of the three stacks, in elements.  */
1367       YYSIZE_T yysize = yyssp - yyss + 1;
1368
1369 #ifdef yyoverflow
1370       {
1371         /* Give user a chance to reallocate the stack.  Use copies of
1372            these so that the &'s don't force the real ones into
1373            memory.  */
1374         YYSTYPE *yyvs1 = yyvs;
1375         yytype_int16 *yyss1 = yyss;
1376
1377         /* Each stack pointer address is followed by the size of the
1378            data in use in that stack, in bytes.  This used to be a
1379            conditional around just the two extra args, but that might
1380            be undefined if yyoverflow is a macro.  */
1381         yyoverflow (YY_("memory exhausted"),
1382                     &yyss1, yysize * sizeof (*yyssp),
1383                     &yyvs1, yysize * sizeof (*yyvsp),
1384                     &yystacksize);
1385
1386         yyss = yyss1;
1387         yyvs = yyvs1;
1388       }
1389 #else /* no yyoverflow */
1390 # ifndef YYSTACK_RELOCATE
1391       goto yyexhaustedlab;
1392 # else
1393       /* Extend the stack our own way.  */
1394       if (YYMAXDEPTH <= yystacksize)
1395         goto yyexhaustedlab;
1396       yystacksize *= 2;
1397       if (YYMAXDEPTH < yystacksize)
1398         yystacksize = YYMAXDEPTH;
1399
1400       {
1401         yytype_int16 *yyss1 = yyss;
1402         union yyalloc *yyptr =
1403           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1404         if (! yyptr)
1405           goto yyexhaustedlab;
1406         YYSTACK_RELOCATE (yyss_alloc, yyss);
1407         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1408 #  undef YYSTACK_RELOCATE
1409         if (yyss1 != yyssa)
1410           YYSTACK_FREE (yyss1);
1411       }
1412 # endif
1413 #endif /* no yyoverflow */
1414
1415       yyssp = yyss + yysize - 1;
1416       yyvsp = yyvs + yysize - 1;
1417
1418       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1419                   (unsigned long int) yystacksize));
1420
1421       if (yyss + yystacksize - 1 <= yyssp)
1422         YYABORT;
1423     }
1424
1425   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1426
1427   if (yystate == YYFINAL)
1428     YYACCEPT;
1429
1430   goto yybackup;
1431
1432 /*-----------.
1433 | yybackup.  |
1434 `-----------*/
1435 yybackup:
1436
1437   /* Do appropriate processing given the current state.  Read a
1438      lookahead token if we need one and don't already have one.  */
1439
1440   /* First try to decide what to do without reference to lookahead token.  */
1441   yyn = yypact[yystate];
1442   if (yypact_value_is_default (yyn))
1443     goto yydefault;
1444
1445   /* Not known => get a lookahead token if don't already have one.  */
1446
1447   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1448   if (yychar == YYEMPTY)
1449     {
1450       YYDPRINTF ((stderr, "Reading a token: "));
1451       yychar = yylex ();
1452     }
1453
1454   if (yychar <= YYEOF)
1455     {
1456       yychar = yytoken = YYEOF;
1457       YYDPRINTF ((stderr, "Now at end of input.\n"));
1458     }
1459   else
1460     {
1461       yytoken = YYTRANSLATE (yychar);
1462       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1463     }
1464
1465   /* If the proper action on seeing token YYTOKEN is to reduce or to
1466      detect an error, take that action.  */
1467   yyn += yytoken;
1468   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1469     goto yydefault;
1470   yyn = yytable[yyn];
1471   if (yyn <= 0)
1472     {
1473       if (yytable_value_is_error (yyn))
1474         goto yyerrlab;
1475       yyn = -yyn;
1476       goto yyreduce;
1477     }
1478
1479   /* Count tokens shifted since error; after three, turn off error
1480      status.  */
1481   if (yyerrstatus)
1482     yyerrstatus--;
1483
1484   /* Shift the lookahead token.  */
1485   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1486
1487   /* Discard the shifted token.  */
1488   yychar = YYEMPTY;
1489
1490   yystate = yyn;
1491   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1492   *++yyvsp = yylval;
1493   YY_IGNORE_MAYBE_UNINITIALIZED_END
1494
1495   goto yynewstate;
1496
1497
1498 /*-----------------------------------------------------------.
1499 | yydefault -- do the default action for the current state.  |
1500 `-----------------------------------------------------------*/
1501 yydefault:
1502   yyn = yydefact[yystate];
1503   if (yyn == 0)
1504     goto yyerrlab;
1505   goto yyreduce;
1506
1507
1508 /*-----------------------------.
1509 | yyreduce -- Do a reduction.  |
1510 `-----------------------------*/
1511 yyreduce:
1512   /* yyn is the number of a rule to reduce with.  */
1513   yylen = yyr2[yyn];
1514
1515   /* If YYLEN is nonzero, implement the default value of the action:
1516      '$$ = $1'.
1517
1518      Otherwise, the following line sets YYVAL to garbage.
1519      This behavior is undocumented and Bison
1520      users should not rely upon it.  Assigning to YYVAL
1521      unconditionally makes the parser a bit smaller, and it avoids a
1522      GCC warning that YYVAL may be used uninitialized.  */
1523   yyval = yyvsp[1-yylen];
1524
1525
1526   YY_REDUCE_PRINT (yyn);
1527   switch (yyn)
1528     {
1529         case 3:
1530 #line 109 "command.y" /* yacc.c:1646  */
1531     {
1532                 cmd_idx = -1;
1533                 want_nodeval = false;
1534                 if (lexptr_begin != NULL) {
1535                         if (input_from_tty && lexptr_begin[0] != '\0')
1536                                 add_history(lexptr_begin);
1537                         efree(lexptr_begin);
1538                         lexptr_begin = NULL;
1539                 }
1540                 if (arg_list != NULL) {
1541                         free_cmdarg(arg_list);
1542                         arg_list = NULL;
1543                 }
1544           }
1545 #line 1546 "command.c" /* yacc.c:1646  */
1546     break;
1547
1548   case 5:
1549 #line 128 "command.y" /* yacc.c:1646  */
1550     {
1551                 if (errcount == 0 && cmd_idx >= 0) {
1552                         Func_cmd cmdfunc;
1553                         bool terminate = false;
1554                         CMDARG *args;
1555                         int ctype = 0;
1556                         
1557                         ctype = cmdtab[cmd_idx].type;
1558
1559                         /* a blank line repeats previous command
1560                          * (list, next, nexti, step, stepi and continue without arguments).
1561                          * save the index in the command table; used in yylex
1562                          */
1563                         if ((ctype == D_list
1564                                         || ctype == D_next
1565                                         || ctype == D_step
1566                                         || ctype == D_nexti
1567                                         || ctype == D_stepi
1568                                         || ctype == D_continue)
1569                                 && arg_list == NULL
1570                                 && ! in_commands
1571                                 && input_from_tty
1572                         )
1573                                 repeat_idx = cmd_idx;
1574                         else
1575                                 repeat_idx = -1;
1576
1577                         /* call the command handler; reset the globals arg_list, cmd_idx,
1578                          * since this handler could invoke yyparse again.
1579                          * call do_commands for the list of commands in `commands';
1580                          * arg_list isn't freed on return.
1581                          */
1582
1583                         cmdfunc = cmdtab[cmd_idx].cf_ptr;
1584                         if (in_commands)
1585                                 cmdfunc = do_commands;
1586                         cmd_idx = -1;
1587                         want_nodeval = false;
1588
1589                         args = arg_list;
1590                         arg_list = NULL;
1591
1592                         terminate = (*cmdfunc)(args, ctype);
1593                         if (! in_commands || ctype == D_commands)
1594                                 free_cmdarg(args);
1595                         if (terminate)
1596                                 YYACCEPT;
1597                 }
1598           }
1599 #line 1600 "command.c" /* yacc.c:1646  */
1600     break;
1601
1602   case 6:
1603 #line 178 "command.y" /* yacc.c:1646  */
1604     {
1605                 yyerrok;
1606           }
1607 #line 1608 "command.c" /* yacc.c:1646  */
1608     break;
1609
1610   case 22:
1611 #line 212 "command.y" /* yacc.c:1646  */
1612     { want_nodeval = true; }
1613 #line 1614 "command.c" /* yacc.c:1646  */
1614     break;
1615
1616   case 23:
1617 #line 217 "command.y" /* yacc.c:1646  */
1618     {
1619                 if (errcount == 0) {
1620                         /* don't free arg_list; passed on to statement_list
1621                          * non-terminal (empty rule action). See below.
1622                          */
1623                         if (input_from_tty) {
1624                                 dbg_prompt = eval_prompt;
1625                                 fprintf(out_fp,
1626                 _("Type (g)awk statement(s). End with the command \"end\"\n"));
1627                                 rl_inhibit_completion = 1;
1628                         }
1629                         cmd_idx = -1;
1630                         in_eval = true;
1631                 }
1632           }
1633 #line 1634 "command.c" /* yacc.c:1646  */
1634     break;
1635
1636   case 24:
1637 #line 236 "command.y" /* yacc.c:1646  */
1638     {
1639                 (yyval) = append_statement(arg_list, (char *) start_EVAL);
1640                 if (read_a_line == read_commands_string)        /* unserializing 'eval' in 'commands' */
1641                         (yyval)->a_string[0] = '\0';
1642                 free_cmdarg(arg_list);
1643                 arg_list = NULL;
1644           }
1645 #line 1646 "command.c" /* yacc.c:1646  */
1646     break;
1647
1648   case 25:
1649 #line 243 "command.y" /* yacc.c:1646  */
1650     { (yyval) = append_statement((yyvsp[-1]), lexptr_begin); }
1651 #line 1652 "command.c" /* yacc.c:1646  */
1652     break;
1653
1654   case 26:
1655 #line 244 "command.y" /* yacc.c:1646  */
1656     {
1657                 (yyval) = (yyvsp[-1]);
1658           }
1659 #line 1660 "command.c" /* yacc.c:1646  */
1660     break;
1661
1662   case 27:
1663 #line 251 "command.y" /* yacc.c:1646  */
1664     {
1665                 arg_list = append_statement((yyvsp[-1]), (char *) end_EVAL);
1666                 if (read_a_line == read_commands_string) {      /* unserializing 'eval' in 'commands' */
1667                         char *str = arg_list->a_string;
1668                         size_t len = strlen(str);
1669                         assert(len > 2 && str[len - 2] == '}');
1670                         str[len - 2] = '\0';
1671                 }
1672                 if (input_from_tty) {
1673                         dbg_prompt = in_commands ? commands_prompt : dgawk_prompt;
1674                         rl_inhibit_completion = 0;
1675                 }
1676                 cmd_idx = find_command("eval", 4);
1677                 in_eval = false;
1678           }
1679 #line 1680 "command.c" /* yacc.c:1646  */
1680     break;
1681
1682   case 28:
1683 #line 267 "command.y" /* yacc.c:1646  */
1684     {
1685                 NODE *n;
1686                 CMDARG *arg;
1687                 n = (yyvsp[0])->a_node;
1688                 arg = append_statement(NULL, (char *) start_EVAL);
1689                 (void) append_statement(arg, n->stptr);
1690                 (void) append_statement(arg, (char *) end_EVAL);
1691                 free_cmdarg(arg_list);
1692                 arg_list = arg;
1693           }
1694 #line 1695 "command.c" /* yacc.c:1646  */
1695     break;
1696
1697   case 34:
1698 #line 286 "command.y" /* yacc.c:1646  */
1699     {
1700                 if (cmdtab[cmd_idx].class == D_FRAME
1701                                 && (yyvsp[0]) != NULL && (yyvsp[0])->a_int < 0)
1702                         yyerror(_("invalid frame number: %d"), (yyvsp[0])->a_int);
1703           }
1704 #line 1705 "command.c" /* yacc.c:1646  */
1705     break;
1706
1707   case 35:
1708 #line 292 "command.y" /* yacc.c:1646  */
1709     {
1710                 int idx = find_argument((yyvsp[0]));
1711                 if (idx < 0)
1712                         yyerror(_("info: invalid option - \"%s\""), (yyvsp[0])->a_string);
1713                 else {
1714                         efree((yyvsp[0])->a_string);
1715                         (yyvsp[0])->a_string = NULL;
1716                         (yyvsp[0])->type = D_argument;
1717                         (yyvsp[0])->a_argument = argtab[idx].value;
1718                 }
1719           }
1720 #line 1721 "command.c" /* yacc.c:1646  */
1721     break;
1722
1723   case 38:
1724 #line 305 "command.y" /* yacc.c:1646  */
1725     { want_nodeval = true; }
1726 #line 1727 "command.c" /* yacc.c:1646  */
1727     break;
1728
1729   case 40:
1730 #line 306 "command.y" /* yacc.c:1646  */
1731     { want_nodeval = true; }
1732 #line 1733 "command.c" /* yacc.c:1646  */
1733     break;
1734
1735   case 46:
1736 #line 311 "command.y" /* yacc.c:1646  */
1737     { want_nodeval = true; }
1738 #line 1739 "command.c" /* yacc.c:1646  */
1739     break;
1740
1741   case 49:
1742 #line 313 "command.y" /* yacc.c:1646  */
1743     { want_nodeval = true; }
1744 #line 1745 "command.c" /* yacc.c:1646  */
1745     break;
1746
1747   case 51:
1748 #line 314 "command.y" /* yacc.c:1646  */
1749     { want_nodeval = true; }
1750 #line 1751 "command.c" /* yacc.c:1646  */
1751     break;
1752
1753   case 53:
1754 #line 315 "command.y" /* yacc.c:1646  */
1755     { want_nodeval = true; }
1756 #line 1757 "command.c" /* yacc.c:1646  */
1757     break;
1758
1759   case 57:
1760 #line 319 "command.y" /* yacc.c:1646  */
1761     {
1762                 if (in_cmd_src((yyvsp[0])->a_string))
1763                         yyerror(_("source \"%s\": already sourced."), (yyvsp[0])->a_string);
1764           }
1765 #line 1766 "command.c" /* yacc.c:1646  */
1766     break;
1767
1768   case 58:
1769 #line 324 "command.y" /* yacc.c:1646  */
1770     {
1771                 if (! input_from_tty)
1772                         yyerror(_("save \"%s\": command not permitted."), (yyvsp[0])->a_string);
1773           }
1774 #line 1775 "command.c" /* yacc.c:1646  */
1775     break;
1776
1777   case 59:
1778 #line 329 "command.y" /* yacc.c:1646  */
1779     {
1780                 int type = 0;
1781                 int num;
1782
1783                 if ((yyvsp[0]) != NULL)
1784                         num = (yyvsp[0])->a_int;
1785
1786                 if (errcount != 0)
1787                         ;
1788                 else if (in_commands)
1789                         yyerror(_("Can't use command `commands' for breakpoint/watchpoint commands"));
1790                 else if ((yyvsp[0]) == NULL &&  ! (type = has_break_or_watch_point(&num, true)))
1791                         yyerror(_("no breakpoint/watchpoint has been set yet"));
1792                 else if ((yyvsp[0]) != NULL && ! (type = has_break_or_watch_point(&num, false)))
1793                         yyerror(_("invalid breakpoint/watchpoint number"));
1794                 if (type) {
1795                         in_commands = true;
1796                         if (input_from_tty) {
1797                                 dbg_prompt = commands_prompt; 
1798                                 fprintf(out_fp, _("Type commands for when %s %d is hit, one per line.\n"),
1799                                                                 (type == D_break) ? "breakpoint" : "watchpoint", num);
1800                                 fprintf(out_fp, _("End with the command \"end\"\n"));
1801                         }
1802                 }
1803           }
1804 #line 1805 "command.c" /* yacc.c:1646  */
1805     break;
1806
1807   case 60:
1808 #line 355 "command.y" /* yacc.c:1646  */
1809     {
1810                 if (! in_commands)
1811                         yyerror(_("`end' valid only in command `commands' or `eval'"));
1812                 else {
1813                         if (input_from_tty)
1814                                 dbg_prompt = dgawk_prompt;      
1815                         in_commands = false;
1816                 }
1817           }
1818 #line 1819 "command.c" /* yacc.c:1646  */
1819     break;
1820
1821   case 61:
1822 #line 365 "command.y" /* yacc.c:1646  */
1823     {
1824                 if (! in_commands)
1825                         yyerror(_("`silent' valid only in command `commands'"));
1826           }
1827 #line 1828 "command.c" /* yacc.c:1646  */
1828     break;
1829
1830   case 62:
1831 #line 370 "command.y" /* yacc.c:1646  */
1832     {
1833                 int idx = find_argument((yyvsp[0]));
1834                 if (idx < 0)
1835                         yyerror(_("trace: invalid option - \"%s\""), (yyvsp[0])->a_string);
1836                 else {
1837                         efree((yyvsp[0])->a_string);
1838                         (yyvsp[0])->a_string = NULL;
1839                         (yyvsp[0])->type = D_argument;
1840                         (yyvsp[0])->a_argument = argtab[idx].value;
1841                 }
1842           }
1843 #line 1844 "command.c" /* yacc.c:1646  */
1844     break;
1845
1846   case 63:
1847 #line 381 "command.y" /* yacc.c:1646  */
1848     { want_nodeval = true; }
1849 #line 1850 "command.c" /* yacc.c:1646  */
1850     break;
1851
1852   case 64:
1853 #line 382 "command.y" /* yacc.c:1646  */
1854     {
1855                 int type;
1856                 int num = (yyvsp[-2])->a_int;
1857                 type = has_break_or_watch_point(&num, false);
1858                 if (! type)
1859                         yyerror(_("condition: invalid breakpoint/watchpoint number"));
1860           }
1861 #line 1862 "command.c" /* yacc.c:1646  */
1862     break;
1863
1864   case 65:
1865 #line 390 "command.y" /* yacc.c:1646  */
1866     {
1867                 if (in_commands) {
1868                         /* Prepend command 'eval' to argument list */
1869                         CMDARG *arg;
1870                         arg = mk_cmdarg(D_string);
1871                         arg->a_string = estrdup("eval", 4);
1872                         arg->next = arg_list;
1873                         arg_list = arg;
1874                 }
1875           }
1876 #line 1877 "command.c" /* yacc.c:1646  */
1877     break;
1878
1879   case 66:
1880 #line 404 "command.y" /* yacc.c:1646  */
1881     {
1882                 if ((yyvsp[0]) != NULL) {
1883                         NODE *n = (yyvsp[0])->a_node;
1884                         (yyvsp[0])->type = D_string;
1885                         (yyvsp[0])->a_string = n->stptr;
1886                         freenode(n);
1887                 }
1888                 (yyval) = (yyvsp[0]);
1889           }
1890 #line 1891 "command.c" /* yacc.c:1646  */
1891     break;
1892
1893   case 68:
1894 #line 418 "command.y" /* yacc.c:1646  */
1895     {   (yyval) = NULL; }
1896 #line 1897 "command.c" /* yacc.c:1646  */
1897     break;
1898
1899   case 69:
1900 #line 423 "command.y" /* yacc.c:1646  */
1901     { (yyval) = NULL; }
1902 #line 1903 "command.c" /* yacc.c:1646  */
1903     break;
1904
1905   case 74:
1906 #line 432 "command.y" /* yacc.c:1646  */
1907     { (yyval) = NULL; }
1908 #line 1909 "command.c" /* yacc.c:1646  */
1909     break;
1910
1911   case 75:
1912 #line 437 "command.y" /* yacc.c:1646  */
1913     { (yyval) = NULL; }
1914 #line 1915 "command.c" /* yacc.c:1646  */
1915     break;
1916
1917   case 77:
1918 #line 440 "command.y" /* yacc.c:1646  */
1919     { (yyval) = NULL; }
1920 #line 1921 "command.c" /* yacc.c:1646  */
1921     break;
1922
1923   case 78:
1924 #line 445 "command.y" /* yacc.c:1646  */
1925     {
1926                 NODE *n;
1927                 n = (yyvsp[0])->a_node;
1928                 if ((n->flags & STRING) == 0)
1929                         yyerror(_("argument not a string"));
1930           }
1931 #line 1932 "command.c" /* yacc.c:1646  */
1932     break;
1933
1934   case 79:
1935 #line 455 "command.y" /* yacc.c:1646  */
1936     { (yyval) = NULL; }
1937 #line 1938 "command.c" /* yacc.c:1646  */
1938     break;
1939
1940   case 80:
1941 #line 457 "command.y" /* yacc.c:1646  */
1942     {
1943                 if (find_option((yyvsp[0])->a_string) < 0)
1944                         yyerror(_("option: invalid parameter - \"%s\""), (yyvsp[0])->a_string);
1945           }
1946 #line 1947 "command.c" /* yacc.c:1646  */
1947     break;
1948
1949   case 81:
1950 #line 462 "command.y" /* yacc.c:1646  */
1951     {
1952                 if (find_option((yyvsp[-2])->a_string) < 0)
1953                         yyerror(_("option: invalid parameter - \"%s\""), (yyvsp[-2])->a_string);
1954           }
1955 #line 1956 "command.c" /* yacc.c:1646  */
1956     break;
1957
1958   case 82:
1959 #line 470 "command.y" /* yacc.c:1646  */
1960     {
1961                 NODE *n;
1962                 n = lookup((yyvsp[0])->a_string);
1963                 if (n == NULL || n->type != Node_func)
1964                         yyerror(_("no such function - \"%s\""), (yyvsp[0])->a_string);
1965                 else {
1966                         (yyvsp[0])->type = D_func;
1967                         efree((yyvsp[0])->a_string);
1968                         (yyvsp[0])->a_string = NULL;
1969                         (yyvsp[0])->a_node = n;
1970                 }
1971           }
1972 #line 1973 "command.c" /* yacc.c:1646  */
1973     break;
1974
1975   case 83:
1976 #line 486 "command.y" /* yacc.c:1646  */
1977     { (yyval) = NULL; }
1978 #line 1979 "command.c" /* yacc.c:1646  */
1979     break;
1980
1981   case 88:
1982 #line 495 "command.y" /* yacc.c:1646  */
1983     { (yyval) = NULL; }
1984 #line 1985 "command.c" /* yacc.c:1646  */
1985     break;
1986
1987   case 89:
1988 #line 496 "command.y" /* yacc.c:1646  */
1989     { want_nodeval = true; }
1990 #line 1991 "command.c" /* yacc.c:1646  */
1991     break;
1992
1993   case 92:
1994 #line 498 "command.y" /* yacc.c:1646  */
1995     { want_nodeval = true; }
1996 #line 1997 "command.c" /* yacc.c:1646  */
1997     break;
1998
1999   case 95:
2000 #line 504 "command.y" /* yacc.c:1646  */
2001     { (yyval) = NULL; }
2002 #line 2003 "command.c" /* yacc.c:1646  */
2003     break;
2004
2005   case 97:
2006 #line 510 "command.y" /* yacc.c:1646  */
2007     { (yyval) = NULL; }
2008 #line 2009 "command.c" /* yacc.c:1646  */
2009     break;
2010
2011   case 99:
2012 #line 516 "command.y" /* yacc.c:1646  */
2013     { (yyval) = NULL; }
2014 #line 2015 "command.c" /* yacc.c:1646  */
2015     break;
2016
2017   case 104:
2018 #line 528 "command.y" /* yacc.c:1646  */
2019     {
2020                 int idx = find_argument((yyvsp[-1]));
2021                 if (idx < 0)
2022                         yyerror(_("enable: invalid option - \"%s\""), (yyvsp[-1])->a_string);
2023                 else {
2024                         efree((yyvsp[-1])->a_string);
2025                         (yyvsp[-1])->a_string = NULL;
2026                         (yyvsp[-1])->type = D_argument;
2027                         (yyvsp[-1])->a_argument = argtab[idx].value;
2028                 }
2029           }
2030 #line 2031 "command.c" /* yacc.c:1646  */
2031     break;
2032
2033   case 106:
2034 #line 544 "command.y" /* yacc.c:1646  */
2035     {
2036                 (yyvsp[0])->type = D_array;     /* dump all items */
2037                 (yyvsp[0])->a_count = 0;
2038           }
2039 #line 2040 "command.c" /* yacc.c:1646  */
2040     break;
2041
2042   case 107:
2043 #line 549 "command.y" /* yacc.c:1646  */
2044     {
2045                 (yyvsp[-1])->type = D_array;
2046                 (yyvsp[-1])->a_count = num_dim;
2047           }
2048 #line 2049 "command.c" /* yacc.c:1646  */
2049     break;
2050
2051   case 117:
2052 #line 575 "command.y" /* yacc.c:1646  */
2053     { (yyval) = NULL; }
2054 #line 2055 "command.c" /* yacc.c:1646  */
2055     break;
2056
2057   case 118:
2058 #line 577 "command.y" /* yacc.c:1646  */
2059     { (yyval) = NULL; }
2060 #line 2061 "command.c" /* yacc.c:1646  */
2061     break;
2062
2063   case 119:
2064 #line 579 "command.y" /* yacc.c:1646  */
2065     {
2066                 CMDARG *a;
2067                 a = mk_cmdarg(D_int);
2068                 a->a_int = -1;
2069                 append_cmdarg(a);
2070           }
2071 #line 2072 "command.c" /* yacc.c:1646  */
2072     break;
2073
2074   case 126:
2075 #line 595 "command.y" /* yacc.c:1646  */
2076     {
2077                 if ((yyvsp[-2])->a_int > (yyvsp[0])->a_int)
2078                         yyerror(_("invalid range specification: %d - %d"),
2079                                 (yyvsp[-2])->a_int, (yyvsp[0])->a_int);
2080                 else
2081                         (yyvsp[-2])->type = D_range;
2082                 (yyval) = (yyvsp[-2]);
2083           }
2084 #line 2085 "command.c" /* yacc.c:1646  */
2085     break;
2086
2087   case 127:
2088 #line 607 "command.y" /* yacc.c:1646  */
2089     { (yyval) = NULL; }
2090 #line 2091 "command.c" /* yacc.c:1646  */
2091     break;
2092
2093   case 134:
2094 #line 621 "command.y" /* yacc.c:1646  */
2095     { (yyval) = (yyvsp[0]); }
2096 #line 2097 "command.c" /* yacc.c:1646  */
2097     break;
2098
2099   case 135:
2100 #line 623 "command.y" /* yacc.c:1646  */
2101     { (yyval) = (yyvsp[-2]); }
2102 #line 2103 "command.c" /* yacc.c:1646  */
2103     break;
2104
2105   case 137:
2106 #line 629 "command.y" /* yacc.c:1646  */
2107     {
2108                 CMDARG *a;
2109                 NODE *subs;
2110                 int count = 0;
2111                 
2112                 for (a = (yyvsp[-1]); a != NULL; a = a->next)
2113                         count++;
2114                 subs = concat_args((yyvsp[-1]), count);
2115                 free_cmdarg((yyvsp[-1])->next);
2116                 (yyvsp[-1])->next = NULL;
2117                 (yyvsp[-1])->type = D_node;
2118                 (yyvsp[-1])->a_node = subs;
2119                 (yyval) = (yyvsp[-1]);
2120           }
2121 #line 2122 "command.c" /* yacc.c:1646  */
2122     break;
2123
2124   case 139:
2125 #line 648 "command.y" /* yacc.c:1646  */
2126     { (yyval) = (yyvsp[0]); num_dim = 1; }
2127 #line 2128 "command.c" /* yacc.c:1646  */
2128     break;
2129
2130   case 140:
2131 #line 650 "command.y" /* yacc.c:1646  */
2132     {   (yyval) = (yyvsp[-1]); num_dim++; }
2133 #line 2134 "command.c" /* yacc.c:1646  */
2134     break;
2135
2136   case 142:
2137 #line 656 "command.y" /* yacc.c:1646  */
2138     {
2139                 NODE *n = (yyvsp[0])->a_node;
2140                 if ((n->flags & NUMBER) == 0)
2141                         yyerror(_("non-numeric value for field number"));
2142                 else
2143                         (yyvsp[0])->type = D_field;
2144                 (yyval) = (yyvsp[0]);
2145           }
2146 #line 2147 "command.c" /* yacc.c:1646  */
2147     break;
2148
2149   case 143:
2150 #line 665 "command.y" /* yacc.c:1646  */
2151     {
2152                 /* a_string is array name, a_count is dimension count */
2153                 (yyvsp[-1])->type = D_subscript;
2154                 (yyvsp[-1])->a_count = num_dim;
2155                 (yyval) = (yyvsp[-1]);
2156           }
2157 #line 2158 "command.c" /* yacc.c:1646  */
2158     break;
2159
2160   case 144:
2161 #line 675 "command.y" /* yacc.c:1646  */
2162     { (yyval) = (yyvsp[0]); }
2163 #line 2164 "command.c" /* yacc.c:1646  */
2164     break;
2165
2166   case 145:
2167 #line 677 "command.y" /* yacc.c:1646  */
2168     { 
2169                 NODE *n = (yyvsp[0])->a_node;
2170                 if ((n->flags & NUMBER) == 0)
2171                         yyerror(_("non-numeric value found, numeric expected"));
2172                 (yyval) = (yyvsp[0]);
2173           }
2174 #line 2175 "command.c" /* yacc.c:1646  */
2175     break;
2176
2177   case 146:
2178 #line 684 "command.y" /* yacc.c:1646  */
2179     { 
2180                 NODE *n = (yyvsp[0])->a_node;
2181                 if ((n->flags & NUMBER) == 0)
2182                         yyerror(_("non-numeric value found, numeric expected"));
2183                 else
2184                         negate_num(n);
2185                 (yyval) = (yyvsp[0]);
2186           }
2187 #line 2188 "command.c" /* yacc.c:1646  */
2188     break;
2189
2190   case 147:
2191 #line 696 "command.y" /* yacc.c:1646  */
2192     { (yyval) = NULL; }
2193 #line 2194 "command.c" /* yacc.c:1646  */
2194     break;
2195
2196   case 148:
2197 #line 698 "command.y" /* yacc.c:1646  */
2198     { (yyval) = (yyvsp[0]); }
2199 #line 2200 "command.c" /* yacc.c:1646  */
2200     break;
2201
2202   case 149:
2203 #line 703 "command.y" /* yacc.c:1646  */
2204     { (yyval) = NULL; }
2205 #line 2206 "command.c" /* yacc.c:1646  */
2206     break;
2207
2208   case 150:
2209 #line 705 "command.y" /* yacc.c:1646  */
2210     { (yyval) = (yyvsp[0]); }
2211 #line 2212 "command.c" /* yacc.c:1646  */
2212     break;
2213
2214   case 151:
2215 #line 710 "command.y" /* yacc.c:1646  */
2216     {
2217                 if ((yyvsp[0])->a_int == 0)
2218                         yyerror(_("non-zero integer value"));
2219                 (yyval) = (yyvsp[0]);
2220           }
2221 #line 2222 "command.c" /* yacc.c:1646  */
2222     break;
2223
2224   case 152:
2225 #line 716 "command.y" /* yacc.c:1646  */
2226     {
2227                 if ((yyvsp[0])->a_int == 0)
2228                         yyerror(_("non-zero integer value"));
2229                 (yyval) = (yyvsp[0]);
2230           }
2231 #line 2232 "command.c" /* yacc.c:1646  */
2232     break;
2233
2234   case 153:
2235 #line 725 "command.y" /* yacc.c:1646  */
2236     { (yyval) = (yyvsp[0]); }
2237 #line 2238 "command.c" /* yacc.c:1646  */
2238     break;
2239
2240   case 154:
2241 #line 727 "command.y" /* yacc.c:1646  */
2242     { (yyval) = (yyvsp[0]); }
2243 #line 2244 "command.c" /* yacc.c:1646  */
2244     break;
2245
2246   case 155:
2247 #line 729 "command.y" /* yacc.c:1646  */
2248     {
2249                 (yyvsp[0])->a_int = - (yyvsp[0])->a_int;
2250                 (yyval) = (yyvsp[0]);
2251           }
2252 #line 2253 "command.c" /* yacc.c:1646  */
2253     break;
2254
2255   case 156:
2256 #line 737 "command.y" /* yacc.c:1646  */
2257     {
2258                 if (lexptr_begin != NULL) {
2259                         if (input_from_tty && lexptr_begin[0] != '\0')
2260                                 add_history(lexptr_begin);
2261                         efree(lexptr_begin);
2262                         lexptr_begin = NULL;
2263                 }
2264           }
2265 #line 2266 "command.c" /* yacc.c:1646  */
2266     break;
2267
2268
2269 #line 2270 "command.c" /* yacc.c:1646  */
2270       default: break;
2271     }
2272   /* User semantic actions sometimes alter yychar, and that requires
2273      that yytoken be updated with the new translation.  We take the
2274      approach of translating immediately before every use of yytoken.
2275      One alternative is translating here after every semantic action,
2276      but that translation would be missed if the semantic action invokes
2277      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
2278      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
2279      incorrect destructor might then be invoked immediately.  In the
2280      case of YYERROR or YYBACKUP, subsequent parser actions might lead
2281      to an incorrect destructor call or verbose syntax error message
2282      before the lookahead is translated.  */
2283   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2284
2285   YYPOPSTACK (yylen);
2286   yylen = 0;
2287   YY_STACK_PRINT (yyss, yyssp);
2288
2289   *++yyvsp = yyval;
2290
2291   /* Now 'shift' the result of the reduction.  Determine what state
2292      that goes to, based on the state we popped back to and the rule
2293      number reduced by.  */
2294
2295   yyn = yyr1[yyn];
2296
2297   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
2298   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
2299     yystate = yytable[yystate];
2300   else
2301     yystate = yydefgoto[yyn - YYNTOKENS];
2302
2303   goto yynewstate;
2304
2305
2306 /*--------------------------------------.
2307 | yyerrlab -- here on detecting error.  |
2308 `--------------------------------------*/
2309 yyerrlab:
2310   /* Make sure we have latest lookahead translation.  See comments at
2311      user semantic actions for why this is necessary.  */
2312   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2313
2314   /* If not already recovering from an error, report this error.  */
2315   if (!yyerrstatus)
2316     {
2317       ++yynerrs;
2318 #if ! YYERROR_VERBOSE
2319       yyerror (YY_("syntax error"));
2320 #else
2321 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
2322                                         yyssp, yytoken)
2323       {
2324         char const *yymsgp = YY_("syntax error");
2325         int yysyntax_error_status;
2326         yysyntax_error_status = YYSYNTAX_ERROR;
2327         if (yysyntax_error_status == 0)
2328           yymsgp = yymsg;
2329         else if (yysyntax_error_status == 1)
2330           {
2331             if (yymsg != yymsgbuf)
2332               YYSTACK_FREE (yymsg);
2333             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
2334             if (!yymsg)
2335               {
2336                 yymsg = yymsgbuf;
2337                 yymsg_alloc = sizeof yymsgbuf;
2338                 yysyntax_error_status = 2;
2339               }
2340             else
2341               {
2342                 yysyntax_error_status = YYSYNTAX_ERROR;
2343                 yymsgp = yymsg;
2344               }
2345           }
2346         yyerror (yymsgp);
2347         if (yysyntax_error_status == 2)
2348           goto yyexhaustedlab;
2349       }
2350 # undef YYSYNTAX_ERROR
2351 #endif
2352     }
2353
2354
2355
2356   if (yyerrstatus == 3)
2357     {
2358       /* If just tried and failed to reuse lookahead token after an
2359          error, discard it.  */
2360
2361       if (yychar <= YYEOF)
2362         {
2363           /* Return failure if at end of input.  */
2364           if (yychar == YYEOF)
2365             YYABORT;
2366         }
2367       else
2368         {
2369           yydestruct ("Error: discarding",
2370                       yytoken, &yylval);
2371           yychar = YYEMPTY;
2372         }
2373     }
2374
2375   /* Else will try to reuse lookahead token after shifting the error
2376      token.  */
2377   goto yyerrlab1;
2378
2379
2380 /*---------------------------------------------------.
2381 | yyerrorlab -- error raised explicitly by YYERROR.  |
2382 `---------------------------------------------------*/
2383 yyerrorlab:
2384
2385   /* Pacify compilers like GCC when the user code never invokes
2386      YYERROR and the label yyerrorlab therefore never appears in user
2387      code.  */
2388   if (/*CONSTCOND*/ 0)
2389      goto yyerrorlab;
2390
2391   /* Do not reclaim the symbols of the rule whose action triggered
2392      this YYERROR.  */
2393   YYPOPSTACK (yylen);
2394   yylen = 0;
2395   YY_STACK_PRINT (yyss, yyssp);
2396   yystate = *yyssp;
2397   goto yyerrlab1;
2398
2399
2400 /*-------------------------------------------------------------.
2401 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
2402 `-------------------------------------------------------------*/
2403 yyerrlab1:
2404   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2405
2406   for (;;)
2407     {
2408       yyn = yypact[yystate];
2409       if (!yypact_value_is_default (yyn))
2410         {
2411           yyn += YYTERROR;
2412           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
2413             {
2414               yyn = yytable[yyn];
2415               if (0 < yyn)
2416                 break;
2417             }
2418         }
2419
2420       /* Pop the current state because it cannot handle the error token.  */
2421       if (yyssp == yyss)
2422         YYABORT;
2423
2424
2425       yydestruct ("Error: popping",
2426                   yystos[yystate], yyvsp);
2427       YYPOPSTACK (1);
2428       yystate = *yyssp;
2429       YY_STACK_PRINT (yyss, yyssp);
2430     }
2431
2432   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2433   *++yyvsp = yylval;
2434   YY_IGNORE_MAYBE_UNINITIALIZED_END
2435
2436
2437   /* Shift the error token.  */
2438   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
2439
2440   yystate = yyn;
2441   goto yynewstate;
2442
2443
2444 /*-------------------------------------.
2445 | yyacceptlab -- YYACCEPT comes here.  |
2446 `-------------------------------------*/
2447 yyacceptlab:
2448   yyresult = 0;
2449   goto yyreturn;
2450
2451 /*-----------------------------------.
2452 | yyabortlab -- YYABORT comes here.  |
2453 `-----------------------------------*/
2454 yyabortlab:
2455   yyresult = 1;
2456   goto yyreturn;
2457
2458 #if !defined yyoverflow || YYERROR_VERBOSE
2459 /*-------------------------------------------------.
2460 | yyexhaustedlab -- memory exhaustion comes here.  |
2461 `-------------------------------------------------*/
2462 yyexhaustedlab:
2463   yyerror (YY_("memory exhausted"));
2464   yyresult = 2;
2465   /* Fall through.  */
2466 #endif
2467
2468 yyreturn:
2469   if (yychar != YYEMPTY)
2470     {
2471       /* Make sure we have latest lookahead translation.  See comments at
2472          user semantic actions for why this is necessary.  */
2473       yytoken = YYTRANSLATE (yychar);
2474       yydestruct ("Cleanup: discarding lookahead",
2475                   yytoken, &yylval);
2476     }
2477   /* Do not reclaim the symbols of the rule whose action triggered
2478      this YYABORT or YYACCEPT.  */
2479   YYPOPSTACK (yylen);
2480   YY_STACK_PRINT (yyss, yyssp);
2481   while (yyssp != yyss)
2482     {
2483       yydestruct ("Cleanup: popping",
2484                   yystos[*yyssp], yyvsp);
2485       YYPOPSTACK (1);
2486     }
2487 #ifndef yyoverflow
2488   if (yyss != yyssa)
2489     YYSTACK_FREE (yyss);
2490 #endif
2491 #if YYERROR_VERBOSE
2492   if (yymsg != yymsgbuf)
2493     YYSTACK_FREE (yymsg);
2494 #endif
2495   return yyresult;
2496 }
2497 #line 747 "command.y" /* yacc.c:1906  */
2498
2499
2500
2501 /* append_statement --- append 'stmt' to the list of eval awk statements */ 
2502
2503 static CMDARG *
2504 append_statement(CMDARG *stmt_list, char *stmt) 
2505 {
2506         CMDARG *a, *arg; 
2507         char *s;
2508         int len, slen, ssize;
2509
2510 #define EVALSIZE        512
2511
2512         if (stmt == start_EVAL) {
2513                 len = sizeof(start_EVAL);
2514                 for (a = stmt_list; a != NULL; a = a->next)
2515                         len += strlen(a->a_string) + 1; /* 1 for ',' */
2516                 len += EVALSIZE;
2517
2518                 emalloc(s, char *, (len + 2) * sizeof(char), "append_statement");
2519                 arg = mk_cmdarg(D_string);
2520                 arg->a_string = s;
2521                 arg->a_count = len;     /* kludge */
2522
2523                 slen = sizeof("function @eval(") - 1;
2524                 memcpy(s, start_EVAL, slen);
2525
2526                 for (a = stmt_list; a != NULL; a = a->next) {
2527                         len = strlen(a->a_string);
2528                         memcpy(s + slen, a->a_string, len);
2529                         slen += len;
2530                         if (a->next != NULL)
2531                                 s[slen++] = ',';
2532                 }
2533                 s[slen++] = ')';
2534                 s[slen++] = '{';
2535                 s[slen] = '\0';
2536                 return arg;
2537         }
2538                  
2539         len = strlen(stmt) + 1; /* 1 for newline */
2540         s = stmt_list->a_string;
2541         slen = strlen(s);
2542         ssize = stmt_list->a_count;
2543         if (len > ssize - slen) {
2544                 ssize = slen + len + EVALSIZE;
2545                 erealloc(s, char *, (ssize + 2) * sizeof(char), "append_statement");
2546                 stmt_list->a_string = s;
2547                 stmt_list->a_count = ssize;
2548         }
2549         memcpy(s + slen, stmt, len);
2550         slen += len;
2551         if (slen >= 2 && s[slen - 2] != '\n') {
2552                 s[slen - 1] = '\n';
2553                 s[slen] = '\0';
2554         }
2555
2556         if (stmt == end_EVAL)
2557                 erealloc(stmt_list->a_string, char *, slen + 2, "append_statement");
2558         return stmt_list;
2559
2560 #undef EVALSIZE
2561 }
2562
2563
2564 /* command names sorted in ascending order */
2565
2566 struct cmdtoken cmdtab[] = {
2567 { "backtrace", "bt", D_backtrace, D_BACKTRACE, do_backtrace,
2568         gettext_noop("backtrace [N] - print trace of all or N innermost (outermost if N < 0) frames.") },
2569 { "break", "b", D_break, D_BREAK, do_breakpoint,
2570         gettext_noop("break [[filename:]N|function] - set breakpoint at the specified location.") },
2571 { "clear", "", D_clear, D_CLEAR, do_clear,
2572         gettext_noop("clear [[filename:]N|function] - delete breakpoints previously set.") },
2573 { "commands", "", D_commands, D_COMMANDS, do_commands,
2574         gettext_noop("commands [num] - starts a list of commands to be executed at a breakpoint(watchpoint) hit.") },
2575 { "condition", "", D_condition, D_CONDITION, do_condition,
2576         gettext_noop("condition num [expr] - set or clear breakpoint or watchpoint condition.") },
2577 { "continue", "c", D_continue, D_CONTINUE, do_continue,
2578         gettext_noop("continue [COUNT] - continue program being debugged.") },
2579 { "delete", "d", D_delete, D_DELETE, do_delete_breakpoint,
2580         gettext_noop("delete [breakpoints] [range] - delete specified breakpoints.") },
2581 { "disable", "", D_disable, D_DISABLE, do_disable_breakpoint,
2582         gettext_noop("disable [breakpoints] [range] - disable specified breakpoints.") },
2583 { "display", "", D_display, D_DISPLAY, do_display,
2584         gettext_noop("display [var] - print value of variable each time the program stops.") },
2585 { "down", "", D_down, D_DOWN, do_down,
2586         gettext_noop("down [N] - move N frames down the stack.") },
2587 { "dump", "", D_dump, D_DUMP, do_dump_instructions,
2588         gettext_noop("dump [filename] - dump instructions to file or stdout.") },
2589 { "enable", "e", D_enable, D_ENABLE, do_enable_breakpoint,
2590         gettext_noop("enable [once|del] [breakpoints] [range] - enable specified breakpoints.") },
2591 { "end", "", D_end, D_END, do_commands,
2592         gettext_noop("end - end a list of commands or awk statements.") },
2593 { "eval", "", D_eval, D_EVAL, do_eval,
2594         gettext_noop("eval stmt|[p1, p2, ...] - evaluate awk statement(s).") },
2595 { "finish", "", D_finish, D_FINISH, do_finish,
2596         gettext_noop("finish - execute until selected stack frame returns.") },
2597 { "frame", "f", D_frame, D_FRAME, do_frame,
2598         gettext_noop("frame [N] - select and print stack frame number N.") },
2599 { "help", "h", D_help, D_HELP, do_help,
2600         gettext_noop("help [command] - print list of commands or explanation of command.") },
2601 { "ignore", "", D_ignore, D_IGNORE, do_ignore_breakpoint,
2602         gettext_noop("ignore N COUNT - set ignore-count of breakpoint number N to COUNT.") },
2603 { "info", "i", D_info, D_INFO, do_info,
2604         gettext_noop("info topic - source|sources|variables|functions|break|frame|args|locals|display|watch.") },
2605 { "list", "l", D_list, D_LIST, do_list,
2606         gettext_noop("list [-|+|[filename:]lineno|function|range] - list specified line(s).") },
2607 { "next", "n", D_next, D_NEXT, do_next,
2608         gettext_noop("next [COUNT] - step program, proceeding through subroutine calls.") },
2609 { "nexti", "ni", D_nexti, D_NEXTI, do_nexti,
2610         gettext_noop("nexti [COUNT] - step one instruction, but proceed through subroutine calls.") },
2611 { "option", "o", D_option, D_OPTION, do_option,
2612         gettext_noop("option [name[=value]] - set or display debugger option(s).") },
2613 { "print", "p", D_print, D_PRINT, do_print_var,
2614         gettext_noop("print var [var] - print value of a variable or array.") },
2615 { "printf", "", D_printf, D_PRINTF, do_print_f,
2616         gettext_noop("printf format, [arg], ... - formatted output.") },
2617 { "quit", "q", D_quit, D_QUIT, do_quit,
2618         gettext_noop("quit - exit debugger.") },
2619 { "return", "", D_return, D_RETURN, do_return,
2620         gettext_noop("return [value] - make selected stack frame return to its caller.") },
2621 { "run", "r", D_run, D_RUN, do_run,
2622         gettext_noop("run - start or restart executing program.") },
2623 #ifdef HAVE_LIBREADLINE
2624 { "save", "", D_save, D_SAVE, do_save,
2625         gettext_noop("save filename - save commands from the session to file.") },
2626 #endif
2627 { "set", "", D_set, D_SET, do_set_var,
2628         gettext_noop("set var = value - assign value to a scalar variable.") },
2629 { "silent", "", D_silent, D_SILENT, do_commands,
2630         gettext_noop("silent - suspends usual message when stopped at a breakpoint/watchpoint.") },
2631 { "source", "", D_source, D_SOURCE, do_source,
2632         gettext_noop("source file - execute commands from file.") },
2633 { "step", "s", D_step, D_STEP, do_step,
2634         gettext_noop("step [COUNT] - step program until it reaches a different source line.") },
2635 { "stepi", "si", D_stepi, D_STEPI, do_stepi,
2636         gettext_noop("stepi [COUNT] - step one instruction exactly.") },
2637 { "tbreak", "t", D_tbreak, D_TBREAK, do_tmp_breakpoint,
2638         gettext_noop("tbreak [[filename:]N|function] - set a temporary breakpoint.") },
2639 { "trace", "", D_trace, D_TRACE, do_trace_instruction,
2640         gettext_noop("trace on|off - print instruction before executing.") },
2641 { "undisplay",  "", D_undisplay, D_UNDISPLAY, do_undisplay,
2642         gettext_noop("undisplay [N] - remove variable(s) from automatic display list.") },
2643 { "until", "u", D_until, D_UNTIL, do_until,
2644         gettext_noop("until [[filename:]N|function] - execute until program reaches a different line or line N within current frame.") },
2645 { "unwatch", "", D_unwatch, D_UNWATCH, do_unwatch,
2646         gettext_noop("unwatch [N] - remove variable(s) from watch list.") },
2647 { "up", "", D_up, D_UP, do_up,
2648         gettext_noop("up [N] - move N frames up the stack.") },
2649 { "watch", "w", D_watch, D_WATCH, do_watch,
2650         gettext_noop("watch var - set a watchpoint for a variable.") },
2651 { NULL, NULL, D_illegal, 0, (Func_cmd) 0,
2652          NULL },
2653 };
2654
2655 struct argtoken argtab[] = {
2656         { "args", D_info, A_ARGS },
2657         { "break", D_info, A_BREAK },
2658         { "del", D_enable, A_DEL },
2659         { "display", D_info, A_DISPLAY },
2660         { "frame", D_info, A_FRAME },
2661         { "functions", D_info, A_FUNCTIONS },
2662         { "locals", D_info, A_LOCALS },
2663         { "off", D_trace, A_TRACE_OFF },
2664         { "on", D_trace, A_TRACE_ON },
2665         { "once", D_enable, A_ONCE },
2666         { "source", D_info, A_SOURCE },
2667         { "sources", D_info, A_SOURCES },
2668         { "variables", D_info, A_VARIABLES },
2669         { "watch", D_info, A_WATCH },
2670         { NULL, D_illegal, A_NONE },
2671 };
2672
2673
2674 /* get_command --- return command handler function */
2675
2676 Func_cmd
2677 get_command(int ctype)
2678 {
2679         int i;
2680         for (i = 0; cmdtab[i].name != NULL; i++) {
2681                 if (cmdtab[i].type == ctype)
2682                         return cmdtab[i].cf_ptr;
2683         }
2684         return (Func_cmd) 0;
2685 }
2686
2687 /* get_command_name --- return command name given it's type */
2688
2689 const char *
2690 get_command_name(int ctype)
2691 {
2692         int i;
2693         for (i = 0; cmdtab[i].name != NULL; i++) {
2694                 if (cmdtab[i].type == ctype)
2695                         return cmdtab[i].name;
2696         }
2697         return NULL;
2698
2699
2700 /* mk_cmdarg --- make an argument for command */
2701
2702 static CMDARG *
2703 mk_cmdarg(enum argtype type)
2704 {
2705         CMDARG *arg;
2706         emalloc(arg, CMDARG *, sizeof(CMDARG), "mk_cmdarg");
2707         memset(arg, 0, sizeof(CMDARG));
2708         arg->type = type;
2709         return arg;
2710 }
2711
2712 /* append_cmdarg --- append ARG to the list of arguments for the current command */
2713  
2714 static void
2715 append_cmdarg(CMDARG *arg)
2716 {
2717         static CMDARG *savetail;
2718
2719         if (arg_list == NULL)
2720                 arg_list = arg;
2721         else
2722                 savetail->next = arg;
2723         savetail = arg;
2724 }
2725
2726 /* free_cmdarg --- free all arguments in LIST */
2727
2728 void
2729 free_cmdarg(CMDARG *list)
2730 {
2731         CMDARG *arg, *nexta;
2732
2733         for (arg = list; arg != NULL; arg = nexta) {
2734                 nexta = arg->next;
2735
2736                 switch (arg->type) {
2737                 case D_variable:
2738                 case D_subscript:
2739                 case D_array:
2740                 case D_string:
2741                         if (arg->a_string != NULL)
2742                                 efree(arg->a_string);
2743                         break;
2744                 case D_node:
2745                 case D_field:
2746                         unref(arg->a_node);
2747                         break;
2748                 default:
2749                         break;
2750                 }
2751                 efree(arg);
2752         }
2753 }
2754
2755 /* yyerror --- print a syntax error message */
2756
2757 static void
2758 yyerror(const char *mesg, ...)
2759 {
2760         va_list args;
2761         va_start(args, mesg);
2762         fprintf(out_fp, _("error: "));
2763         vfprintf(out_fp, mesg, args);
2764         fprintf(out_fp, "\n");
2765         va_end(args);
2766         errcount++;
2767         repeat_idx = -1;
2768 }
2769
2770
2771 /* yylex --- read a command and turn it into tokens */
2772
2773 static int
2774 yylex(void)
2775 {
2776         static char *lexptr = NULL;
2777         static char *lexend;
2778         int c;
2779         char *tokstart;
2780         size_t toklen; 
2781
2782         yylval = (CMDARG *) NULL;
2783
2784         if (errcount > 0 && lexptr_begin == NULL) {
2785                 /* fake a new line */
2786                 errcount = 0;
2787                 return '\n';
2788         }
2789
2790         if (lexptr_begin == NULL) {
2791 again:
2792                 lexptr_begin = read_a_line(dbg_prompt);
2793                 if (lexptr_begin == NULL) {     /* EOF or error */
2794                         if (get_eof_status() == EXIT_FATAL) 
2795                                 exit(EXIT_FATAL);
2796                         if (get_eof_status() == EXIT_FAILURE) {
2797                                 static int seen_eof = 0;
2798
2799                                 /* force a quit, and let do_quit (in debug.c) exit */
2800                                 if (! seen_eof) {
2801                                         if (errno != 0) {
2802                                                 fprintf(stderr, _("can't read command (%s)\n"), strerror(errno));
2803                                                 exit_val = EXIT_FAILURE;
2804                                         } /* else
2805                                                 exit_val = EXIT_SUCCESS; */
2806
2807                                         seen_eof = 1;
2808                                         return '\n';    /* end current command if any */
2809                                 } else if (seen_eof++ == 1) {
2810                                         cmd_idx = find_command("quit", 4);
2811                                         return D_QUIT;  /* 'quit' token */
2812                                 } else
2813                                         return '\n';    /* end command 'quit' */
2814                         }
2815                         if (errno != 0)
2816                                 d_error(_("can't read command (%s)"), strerror(errno));
2817                         if (pop_cmd_src() == 0)
2818                                 goto again;
2819                         exit(EXIT_FATAL);       /* shouldn't happen */
2820                 }
2821
2822                 if (! in_commands && ! in_eval  /* history expansion off in 'commands' and 'eval' */
2823                                 && input_from_tty
2824                 )
2825                         history_expand_line(&lexptr_begin);
2826         
2827                 lexptr = lexptr_begin;
2828                 lexend = lexptr + strlen(lexptr);
2829                 if (*lexptr == '\0'             /* blank line */
2830                                 && repeat_idx >= 0
2831                                 && input_from_tty
2832                                 && ! in_eval
2833                 ) {
2834 #ifdef HAVE_LIBREADLINE
2835                         HIST_ENTRY *h;
2836                         h = previous_history();
2837                         if (h != NULL)
2838                                 add_history(h->line);
2839 #endif
2840                         cmd_idx = repeat_idx;
2841                         return cmdtab[cmd_idx].class;   /* repeat last command */
2842                 }
2843                 repeat_idx = -1;
2844         }
2845         
2846         c = *lexptr;
2847
2848         while (c == ' ' || c == '\t')
2849                 c = *++lexptr;
2850
2851         if (! input_from_tty && c == '#')
2852                 return '\n'; 
2853
2854         tokstart = lexptr;
2855         if (lexptr >= lexend)
2856                 return '\n';
2857
2858         if (cmd_idx < 0) {      /* need a command */
2859                 if (c == '?' && tokstart[1] == '\0'     && ! in_eval) {
2860                         lexptr++;
2861                         cmd_idx = find_command("help", 4);
2862                         return D_HELP;
2863                 }
2864
2865                 while (c != '\0' && c != ' ' && c != '\t') {
2866                         if (! isalpha(c) && ! in_eval) {
2867                                 yyerror(_("invalid character in command"));
2868                                 return '\n';
2869                         }
2870                         c = *++lexptr;
2871                 }
2872
2873                 toklen = lexptr - tokstart;
2874
2875                 if (in_eval) {
2876                         if (toklen == 3
2877                                         && tokstart[3] == '\0'
2878                                         && tokstart[0] == 'e'
2879                                         && tokstart[1] == 'n'
2880                                         && tokstart[2] == 'd'
2881                         ) {
2882                                 cmd_idx = find_command(tokstart, toklen);
2883                                 return D_END;
2884                         }
2885                         lexptr = lexend;
2886                         return D_STATEMENT;
2887                 }
2888
2889                 cmd_idx = find_command(tokstart, toklen);
2890                 if (cmd_idx >= 0) {
2891                         if (in_commands && cmdtab[cmd_idx].type != D_eval) {
2892                                 /* add the actual command string (lexptr_begin) to
2893                                  * arg_list; command string for 'eval' prepended to the arg_list
2894                                  * in the grammer above (see eval_cmd non-terminal).
2895                                  */
2896                                 CMDARG *arg;
2897                                 arg = mk_cmdarg(D_string);
2898                                 arg->a_string = estrdup(lexptr_begin, lexend - lexptr_begin);
2899                                 append_cmdarg(arg);
2900                         }
2901                         return cmdtab[cmd_idx].class;
2902                 } else {
2903                         yyerror(_("unknown command - \"%.*s\", try help"), toklen, tokstart);
2904                         return '\n';
2905                 }
2906         }
2907
2908         c = *lexptr;
2909         
2910         if (cmdtab[cmd_idx].type == D_option) {
2911                 if (c == '=')
2912                         return *lexptr++;
2913         } else if (c == '-' || c == '+' || c == ':' || c == '|')
2914                 return *lexptr++;
2915
2916         if (c == '"') {
2917                 char *str, *p;
2918                 int flags = ALREADY_MALLOCED;
2919                 bool esc_seen = false;
2920
2921                 toklen = lexend - lexptr;
2922                 emalloc(str, char *, toklen + 2, "yylex");
2923                 p = str;
2924
2925                 while ((c = *++lexptr) != '"') {
2926                         if (lexptr == lexend) {
2927 err:
2928                                 efree(str);
2929                                 yyerror(_("unterminated string"));
2930                                 return '\n';
2931                         }
2932                         if (c == '\\') {
2933                                 c = *++lexptr;
2934                                 esc_seen = true;
2935                                 if (want_nodeval || c != '"')
2936                                         *p++ = '\\';
2937                         }
2938                         if (lexptr == lexend)
2939                                 goto err;
2940                         *p++ = c;
2941                 }
2942                 lexptr++;
2943                 *p = '\0';
2944
2945                 if (! want_nodeval) {
2946                         yylval = mk_cmdarg(D_string);
2947                         yylval->a_string = str;
2948                         append_cmdarg(yylval);
2949                         return D_STRING;
2950                 } else {        /* awk string */
2951                         if (esc_seen)
2952                                 flags |= SCAN;
2953                         yylval = mk_cmdarg(D_node);
2954                         yylval->a_node = make_str_node(str, p - str, flags);
2955                         append_cmdarg(yylval);
2956                         return D_NODE;
2957                 }
2958         }
2959
2960         if (! want_nodeval) {
2961                 while ((c = *++lexptr) != '\0' && c != ':' && c != '-'
2962                                         && c != ' ' && c != '\t' && c != '=')
2963                         ;
2964
2965                 /* Is it an integer? */
2966                 if (isdigit((unsigned char) tokstart[0]) && cmdtab[cmd_idx].type != D_option) {
2967                         char *end;
2968                         long l;
2969
2970                         errno = 0;
2971                         l = strtol(tokstart, &end, 0);
2972                         if (errno != 0) {
2973                                 yyerror(_("%s"), strerror(errno));
2974                                 errno = 0;
2975                                 return '\n';
2976                         }
2977
2978                         if (lexptr == end) {
2979                                 yylval = mk_cmdarg(D_int);
2980                                 yylval->a_int = l;
2981                                 append_cmdarg(yylval);
2982                                 return D_INT;
2983                         }
2984                 }
2985
2986                 /* Must be string */
2987                 yylval = mk_cmdarg(D_string);
2988                 yylval->a_string = estrdup(tokstart, lexptr - tokstart);
2989                 append_cmdarg(yylval);
2990                 return D_STRING;
2991         }
2992
2993         /* look for awk number */
2994
2995         if (isdigit((unsigned char) tokstart[0])) {
2996                 NODE *r = NULL;
2997
2998                 errno = 0;
2999 #ifdef HAVE_MPFR
3000                 if (do_mpfr) {
3001                         int tval;
3002                         r = mpg_float();
3003                         tval = mpfr_strtofr(r->mpg_numbr, tokstart, & lexptr, 0, ROUND_MODE);
3004                         IEEE_FMT(r->mpg_numbr, tval);
3005                         if (mpfr_integer_p(r->mpg_numbr)) {
3006                                 /* integral value, convert to a GMP type. */
3007                                 NODE *tmp = r;
3008                                 r = mpg_integer();
3009                                 mpfr_get_z(r->mpg_i, tmp->mpg_numbr, MPFR_RNDZ);
3010                                 unref(tmp);
3011                         }                       
3012                 } else 
3013 #endif
3014                         r = make_number(strtod(tokstart, & lexptr));
3015
3016                 if (errno != 0) {
3017                         yyerror(strerror(errno));
3018                         unref(r);
3019                         errno = 0;
3020                         return '\n';
3021                 }
3022                 yylval = mk_cmdarg(D_node);
3023                 yylval->a_node = r;
3024                 append_cmdarg(yylval);
3025                 return D_NODE;
3026         }
3027
3028         c = *lexptr;
3029         if (c == '$' || c == '@'
3030                         || c == '[' || c == ']'
3031                         || c == ',' || c == '=')
3032                 return *lexptr++;
3033
3034         if (c != '_' && ! isalpha(c)) {
3035                 yyerror(_("invalid character"));
3036                 return '\n';
3037         }
3038
3039         while (isalnum(c) || c == '_')
3040                 c = *++lexptr;
3041         toklen = lexptr - tokstart;
3042
3043         /* awk variable */
3044         yylval = mk_cmdarg(D_variable);
3045         yylval->a_string = estrdup(tokstart, toklen);
3046         append_cmdarg(yylval);
3047         return D_VARIABLE;
3048 }
3049
3050 /* find_argument --- find index in 'argtab' for a command option */
3051
3052 static int
3053 find_argument(CMDARG *arg)
3054 {
3055         /* non-number argument */
3056         int idx;
3057         char *name, *p;
3058         size_t len;
3059         assert(cmd_idx >= 0);
3060         name = arg->a_string;
3061         len = strlen(name);
3062         for (idx = 0; (p = (char *) argtab[idx].name) != NULL; idx++) {
3063                 if (cmdtab[cmd_idx].type == argtab[idx].cmd
3064                                 && *p == *name
3065                                 && strlen(p) == len
3066                                 && strncmp(p, name, len) == 0
3067                 )
3068                         return idx;
3069         }
3070         return -1;      /* invalid option */
3071 }
3072
3073 /* concat_args --- concatenate argument strings into a single string NODE */
3074
3075 static NODE *
3076 concat_args(CMDARG *arg, int count)
3077 {
3078         NODE *n;
3079         NODE **tmp;
3080         char *str, *subsep, *p;
3081         long len, subseplen;
3082         int i;
3083
3084         if (count == 1) {
3085                 n = force_string(arg->a_node);
3086                 return dupnode(n);
3087         }
3088         
3089         emalloc(tmp, NODE **, count * sizeof(NODE *), "concat_args");
3090         subseplen = SUBSEP_node->var_value->stlen;
3091         subsep = SUBSEP_node->var_value->stptr;
3092         len = -subseplen;
3093
3094         for (i = 0; i < count; i++) {
3095                 n = force_string(arg->a_node);
3096                 len += n->stlen + subseplen;
3097                 tmp[i] = n;
3098                 arg = arg->next;
3099         }
3100
3101         emalloc(str, char *, len + 2, "concat_args");
3102         n = tmp[0];
3103         memcpy(str, n->stptr, n->stlen);
3104         p = str + n->stlen;
3105         for (i = 1; i < count; i++) {
3106                 if (subseplen == 1)
3107                         *p++ = *subsep;
3108                 else if (subseplen > 0) {
3109                         memcpy(p, subsep, subseplen);
3110                         p += subseplen;
3111                 }
3112
3113                 n = tmp[i];
3114                 memcpy(p, n->stptr, n->stlen);
3115                 p += n->stlen;
3116         }
3117         str[len] = '\0';
3118         efree(tmp);
3119         return make_str_node(str, len, ALREADY_MALLOCED);
3120 }
3121
3122 /* find_command --- find the index in 'cmdtab' using exact,
3123  *                  abbreviation or unique partial match 
3124  */
3125
3126 static int
3127 find_command(const char *token, size_t toklen)
3128 {
3129         char *name, *abrv;
3130         int i, k;
3131         bool try_exact = true;
3132         int abrv_match = -1;
3133         int partial_match = -1;
3134
3135 #if 'a' == 0x81 /* it's EBCDIC */
3136         /* make sure all lower case characters in token (sorting
3137          * isn't the solution in this case)
3138          */
3139         for (i = 0; i < toklen; i++) {
3140                 if (token[i] != tolower(token[i]))
3141                         return -1;
3142         }
3143 #endif
3144
3145         k = sizeof(cmdtab)/sizeof(cmdtab[0]) - 1;
3146         for (i = 0; i < k; i++) {
3147                 name = (char *) cmdtab[i].name;
3148                 if (try_exact && *token == *name
3149                                 && toklen == strlen(name)
3150                                 && strncmp(name, token, toklen) == 0
3151                 )
3152                         return i;
3153
3154                 if (*name > *token || i == (k - 1))
3155                         try_exact = false;
3156
3157                 if (abrv_match < 0) {
3158                         abrv = cmdtab[i].abbrvn;
3159                         if (abrv[0] == token[0]) {
3160                                 if (toklen == 1 && ! abrv[1])
3161                                         abrv_match = i;
3162                                 else if (toklen == 2 && abrv[1] == token[1])
3163                                         abrv_match = i;
3164                         }
3165                 }
3166                 if (! try_exact && abrv_match >= 0)
3167                         return abrv_match;
3168                 if (partial_match < 0) {
3169                         if (*token == *name
3170                                         && toklen < strlen(name)
3171                                         && strncmp(name, token, toklen) == 0
3172                         ) {
3173                                 if ((i == k - 1 || strncmp(cmdtab[i + 1].name, token, toklen) != 0)
3174                                         && (i == 0 || strncmp(cmdtab[i - 1].name, token, toklen) != 0)
3175                                 )
3176                                         partial_match = i;
3177                         }
3178                 }
3179         }
3180         return partial_match;
3181 }
3182
3183 /* do_help -- help command */
3184
3185 int
3186 do_help(CMDARG *arg, int cmd)
3187 {
3188         int i;
3189         if (arg == NULL) {
3190                 initialize_pager(out_fp);
3191                 if (setjmp(pager_quit_tag) == 0) {
3192                         for (i = 0; cmdtab[i].name != NULL; i++) {
3193                                 gprintf(out_fp, "%s:\n", cmdtab[i].name);
3194                                 gprintf(out_fp, "\t%s\n", _(cmdtab[i].help_txt));
3195                         }
3196                 }
3197         } else if (arg->type == D_string) {
3198                 char *name;
3199                 name = arg->a_string;
3200                 i = find_command(name, strlen(name));
3201                 if (i >= 0) {
3202                         fprintf(out_fp, "%s\n", cmdtab[i].help_txt);
3203                         if (strcmp(cmdtab[i].name, "option") == 0)
3204                                 option_help();
3205                 } else
3206                         fprintf(out_fp, _("undefined command: %s\n"), name);
3207         }
3208
3209         return false;
3210 }
3211
3212
3213 #ifdef HAVE_LIBREADLINE
3214
3215 /* next_word --- find the next word in a line to complete 
3216  *               (word seperation characters are space and tab).
3217  */
3218    
3219 static char *
3220 next_word(char *p, int len, char **endp)
3221 {
3222         char *q;
3223         int i;
3224
3225         if (p == NULL || len <= 0)
3226                 return NULL;
3227         for (i = 0; i < len; i++, p++)
3228                 if (*p != ' ' && *p != '\t')
3229                         break;
3230         if (i == len)
3231                 return NULL;
3232         if (endp != NULL) {
3233                 for (i++, q = p + 1; i < len; i++, q++)
3234                         if (*q == ' ' || *q == '\t')
3235                                 break;
3236                 *endp = q;
3237         }
3238         return p;
3239 }
3240
3241 /* command_completion --- attempt to complete based on the word number in line;
3242  *    try to complete on command names if this is the first word; for the next
3243  *    word(s), the type of completion depends on the command name (first word).
3244  */
3245
3246 #ifndef RL_READLINE_VERSION             /* < 4.2a */
3247 #define rl_completion_matches(x, y) completion_matches((char *) (x), (y))
3248 #endif
3249
3250
3251 char **
3252 command_completion(const char *text, int start, int end)
3253 {
3254         char *cmdtok, *e;
3255         int idx;
3256         int len;
3257
3258         rl_attempted_completion_over = true;    /* no default filename completion please */
3259
3260         this_cmd = D_illegal;
3261         len = start;
3262         if ((cmdtok = next_word(rl_line_buffer, len, &e)) == NULL)      /* no first word yet */
3263                 return  rl_completion_matches(text, command_generator);
3264         len -= (e - rl_line_buffer);
3265
3266         idx = find_command(cmdtok, e - cmdtok);
3267         if (idx < 0)
3268                 return NULL;
3269         this_cmd = cmdtab[idx].type;
3270
3271         if (! next_word(e, len, NULL)) {
3272                 switch (this_cmd) {
3273                 case D_break:
3274                 case D_list:
3275                 case D_until:
3276                 case D_tbreak:
3277                 case D_clear:
3278                         return rl_completion_matches(text, srcfile_generator);
3279                 case D_info:
3280                 case D_enable:
3281                 case D_trace:
3282                 case D_help:
3283                         return rl_completion_matches(text, argument_generator);
3284                 case D_option:
3285                         return rl_completion_matches(text, option_generator);
3286                 case D_print:
3287                 case D_printf:
3288                 case D_set:
3289                 case D_display:
3290                 case D_watch:
3291                         return rl_completion_matches(text, variable_generator);
3292                 default:
3293                         return NULL;
3294                 }
3295         }
3296
3297         if (this_cmd == D_print || this_cmd == D_printf)
3298                 return rl_completion_matches(text, variable_generator);
3299         return NULL;
3300 }       
3301
3302 /* command_generator --- generator function for command completion */
3303  
3304 static char *
3305 command_generator(const char *text, int state)
3306 {
3307         static size_t textlen;
3308         static int idx = 0;
3309         char *name;
3310
3311         if (! state) {  /* first time */
3312                 textlen = strlen(text);
3313                 idx = 0;
3314         }
3315         while ((name = (char *) cmdtab[idx].name) != NULL) {
3316                 idx++;
3317                 if (strncmp(name, text, textlen) == 0)
3318                         return estrdup(name, strlen(name));
3319         }
3320         return NULL;
3321 }
3322
3323 /* srcfile_generator --- generator function for source file completion */
3324
3325 static char *
3326 srcfile_generator(const char *text, int state)
3327 {
3328         static size_t textlen;
3329         static SRCFILE *s;
3330         char *name;
3331         extern SRCFILE *srcfiles;
3332
3333         if (! state) {  /* first time */
3334                 textlen = strlen(text);
3335                 s = srcfiles->next;
3336         }
3337         while (s != srcfiles) {
3338                 if (s->stype != SRC_FILE && s->stype != SRC_INC) {
3339                         s = s->next;
3340                         continue;
3341                 }
3342                 name = s->src;
3343                 s = s->next;
3344                 if (strncmp(name, text, textlen) == 0)
3345                         return estrdup(name, strlen(name));
3346         }
3347         return NULL;
3348 }
3349
3350 /* argument_generator --- generator function for non-number argument completion */
3351
3352 static char *
3353 argument_generator(const char *text, int state)
3354 {
3355         static size_t textlen;
3356         static int idx;
3357         const char *name;
3358
3359         if (! state) {  /* first time */
3360                 textlen = strlen(text);
3361                 idx = 0;
3362         }
3363
3364         if (this_cmd == D_help) {
3365                 while ((name = cmdtab[idx++].name) != NULL) {
3366                         if (strncmp(name, text, textlen) == 0)
3367                                 return estrdup(name, strlen(name));
3368                 }
3369         } else {
3370                 while ((name = argtab[idx].name) != NULL) {
3371                         if (this_cmd != argtab[idx++].cmd)
3372                                 continue;
3373                         if (strncmp(name, text, textlen) == 0)
3374                                 return estrdup(name, strlen(name));
3375                 }
3376         }               
3377         return NULL;
3378 }
3379
3380 /* variable_generator --- generator function for variable name completion */
3381
3382 static char *
3383 variable_generator(const char *text, int state)
3384 {
3385         static size_t textlen;
3386         static int idx = 0;
3387         static NODE *func = NULL;
3388         static NODE **vars = NULL;
3389         const char *name;
3390         NODE *r;
3391
3392         if (! state) {  /* first time */
3393                 textlen = strlen(text);
3394                 if (vars != NULL)
3395                         efree(vars);
3396                 vars = variable_list();
3397                 idx = 0;
3398                 func = get_function();  /* function in current context */
3399         }
3400
3401         /* function params */
3402         while (func != NULL) {
3403                 if (idx >= func->param_cnt) {
3404                         func = NULL;    /* don't try to match params again */
3405                         idx = 0;
3406                         break;
3407                 }
3408                 name = func->fparms[idx++].param;
3409                 if (strncmp(name, text, textlen) == 0)
3410                         return estrdup(name, strlen(name));
3411         }
3412
3413         /* globals */
3414         while ((r = vars[idx++]) != NULL) {
3415                 name = r->vname;
3416                 if (strncmp(name, text, textlen) == 0)
3417                         return estrdup(name, strlen(name));
3418         }
3419
3420         return NULL;
3421 }
3422
3423 /* history_expand_line ---  history expand the LINE */
3424
3425 static void
3426 history_expand_line(char **line)
3427 {
3428         int ret;
3429         char *expansion;
3430
3431         if (! *line || input_fd != 0 || ! input_from_tty)
3432                 return;
3433         using_history();
3434         ret = history_expand(*line, &expansion);
3435         if (ret < 0 || ret == 2)
3436                 efree(expansion);
3437         else {
3438                 efree(*line);
3439                 *line = expansion;
3440         }
3441 }
3442
3443 #endif