Coverage Report

Created: 2026-10-17 06:18

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