Coverage Report

Created: 2026-08-13 06:06

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