Coverage Report

Created: 2026-10-05 06:04

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
1.72k
#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
151k
#   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
29
#define ERROR 258
211
262
#define HIDDEN 259
212
2.12k
#define IF 260
213
560
#define ELSE 261
214
1.61k
#define ELIF 262
215
1.58k
#define ENDIF 263
216
367
#define FORMAT 264
217
26.6k
#define TOKEN 265
218
1.72k
#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
509
#  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
276
#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
185
#  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
7.35k
# 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
150k
#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
46
#  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
46
#   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
92
# 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
92
    do                                                                  \
522
92
      {                                                                 \
523
92
        YYPTRDIFF_T yynewbytes;                                         \
524
92
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
525
92
        Stack = &yyptr->Stack_alloc;                                    \
526
92
        yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
527
92
        yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
528
92
      }                                                                 \
529
92
    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
92
      __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
150k
#define YYFINAL  20
555
/* YYLAST -- Last index in YYTABLE.  */
556
264k
#define YYLAST   104
557
558
/* YYNTOKENS -- Number of terminals.  */
559
97.9k
#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
79.5k
#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
79.7k
  (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
153k
#define YYPACT_NINF (-32)
647
648
#define yypact_value_is_default(Yyn) \
649
153k
  ((Yyn) == YYPACT_NINF)
650
651
#define YYTABLE_NINF (-15)
652
653
#define yytable_value_is_error(Yyn) \
654
6.50k
  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
132k
#define YYEMPTY         (-2)
772
80.2k
#define YYEOF           0
773
774
181
#define YYACCEPT        goto yyacceptlab
775
190
#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
6.59k
#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
371
# 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
92
# 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
3.67k
{
1192
3.67k
  YYUSE (yyvaluep);
1193
3.67k
  if (!yymsg)
1194
0
    yymsg = "Deleting";
1195
3.67k
  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1196
1197
3.67k
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1198
3.67k
  YYUSE (yytype);
1199
3.67k
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1200
3.67k
}
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
371
{
1221
371
    yy_state_fast_t yystate;
1222
    /* Number of tokens to shift before error messages enabled.  */
1223
371
    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
371
    yy_state_t yyssa[YYINITDEPTH];
1234
371
    yy_state_t *yyss;
1235
371
    yy_state_t *yyssp;
1236
1237
    /* The semantic value stack.  */
1238
371
    YYSTYPE yyvsa[YYINITDEPTH];
1239
371
    YYSTYPE *yyvs;
1240
371
    YYSTYPE *yyvsp;
1241
1242
371
    YYPTRDIFF_T yystacksize;
1243
1244
371
  int yyn;
1245
371
  int yyresult;
1246
  /* Lookahead token as an internal (translated) token number.  */
1247
371
  int yytoken = 0;
1248
  /* The variables used to return semantic value and location from the
1249
     action routines.  */
1250
371
  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
101k
#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
371
  int yylen = 0;
1264
1265
371
  yyssp = yyss = yyssa;
1266
371
  yyvsp = yyvs = yyvsa;
1267
371
  yystacksize = YYINITDEPTH;
1268
1269
371
  YYDPRINTF ((stderr, "Starting parse\n"));
1270
1271
371
  yystate = 0;
1272
371
  yyerrstatus = 0;
1273
371
  yynerrs = 0;
1274
371
  yychar = YYEMPTY; /* Cause a token to be read.  */
1275
371
  goto yysetstate;
1276
1277
1278
/*------------------------------------------------------------.
1279
| yynewstate -- push a new state, which is found in yystate.  |
1280
`------------------------------------------------------------*/
1281
150k
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
150k
  yyssp++;
1285
1286
1287
/*--------------------------------------------------------------------.
1288
| yysetstate -- set current state (the top of the stack) to yystate.  |
1289
`--------------------------------------------------------------------*/
1290
150k
yysetstate:
1291
150k
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1292
150k
  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1293
150k
  YY_IGNORE_USELESS_CAST_BEGIN
1294
150k
  *yyssp = YY_CAST (yy_state_t, yystate);
1295
150k
  YY_IGNORE_USELESS_CAST_END
1296
1297
150k
  if (yyss + yystacksize - 1 <= yyssp)
1298
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
1299
    goto yyexhaustedlab;
1300
#else
1301
46
    {
1302
      /* Get the current used size of the three stacks, in elements.  */
1303
46
      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
46
      if (YYMAXDEPTH <= yystacksize)
1327
0
        goto yyexhaustedlab;
1328
46
      yystacksize *= 2;
1329
46
      if (YYMAXDEPTH < yystacksize)
1330
0
        yystacksize = YYMAXDEPTH;
1331
1332
46
      {
1333
46
        yy_state_t *yyss1 = yyss;
1334
46
        union yyalloc *yyptr =
1335
46
          YY_CAST (union yyalloc *,
1336
46
                   YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1337
46
        if (! yyptr)
1338
0
          goto yyexhaustedlab;
1339
46
        YYSTACK_RELOCATE (yyss_alloc, yyss);
1340
46
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1341
46
# undef YYSTACK_RELOCATE
1342
46
        if (yyss1 != yyssa)
1343
25
          YYSTACK_FREE (yyss1);
1344
46
      }
1345
0
# endif
1346
1347
0
      yyssp = yyss + yysize - 1;
1348
46
      yyvsp = yyvs + yysize - 1;
1349
1350
46
      YY_IGNORE_USELESS_CAST_BEGIN
1351
46
      YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1352
46
                  YY_CAST (long, yystacksize)));
1353
46
      YY_IGNORE_USELESS_CAST_END
1354
1355
46
      if (yyss + yystacksize - 1 <= yyssp)
1356
0
        YYABORT;
1357
46
    }
1358
150k
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1359
1360
150k
  if (yystate == YYFINAL)
1361
181
    YYACCEPT;
1362
1363
150k
  goto yybackup;
1364
1365
1366
/*-----------.
1367
| yybackup.  |
1368
`-----------*/
1369
150k
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
150k
  yyn = yypact[yystate];
1375
150k
  if (yypact_value_is_default (yyn))
1376
70.7k
    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
79.6k
  if (yychar == YYEMPTY)
1382
52.4k
    {
1383
52.4k
      YYDPRINTF ((stderr, "Reading a token: "));
1384
52.4k
      yychar = yylex ();
1385
52.4k
    }
1386
1387
79.6k
  if (yychar <= YYEOF)
1388
527
    {
1389
527
      yychar = yytoken = YYEOF;
1390
527
      YYDPRINTF ((stderr, "Now at end of input.\n"));
1391
527
    }
1392
79.1k
  else
1393
79.1k
    {
1394
79.1k
      yytoken = YYTRANSLATE (yychar);
1395
79.1k
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1396
79.1k
    }
1397
1398
  /* If the proper action on seeing token YYTOKEN is to reduce or to
1399
     detect an error, take that action.  */
1400
79.6k
  yyn += yytoken;
1401
79.6k
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1402
20.9k
    goto yydefault;
1403
58.7k
  yyn = yytable[yyn];
1404
58.7k
  if (yyn <= 0)
1405
6.50k
    {
1406
6.50k
      if (yytable_value_is_error (yyn))
1407
0
        goto yyerrlab;
1408
6.50k
      yyn = -yyn;
1409
6.50k
      goto yyreduce;
1410
6.50k
    }
1411
1412
  /* Count tokens shifted since error; after three, turn off error
1413
     status.  */
1414
52.2k
  if (yyerrstatus)
1415
0
    yyerrstatus--;
1416
1417
  /* Shift the lookahead token.  */
1418
52.2k
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1419
52.2k
  yystate = yyn;
1420
52.2k
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1421
52.2k
  *++yyvsp = yylval;
1422
52.2k
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1423
1424
  /* Discard the shifted token.  */
1425
52.2k
  yychar = YYEMPTY;
1426
52.2k
  goto yynewstate;
1427
1428
1429
/*-----------------------------------------------------------.
1430
| yydefault -- do the default action for the current state.  |
1431
`-----------------------------------------------------------*/
1432
91.6k
yydefault:
1433
91.6k
  yyn = yydefact[yystate];
1434
91.6k
  if (yyn == 0)
1435
185
    goto yyerrlab;
1436
91.4k
  goto yyreduce;
1437
1438
1439
/*-----------------------------.
1440
| yyreduce -- do a reduction.  |
1441
`-----------------------------*/
1442
97.9k
yyreduce:
1443
  /* yyn is the number of a rule to reduce with.  */
1444
97.9k
  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
97.9k
  yyval = yyvsp[1-yylen];
1455
1456
1457
97.9k
  YY_REDUCE_PRINT (yyn);
1458
97.9k
  switch (yyn)
1459
97.9k
    {
1460
181
  case 3:
1461
181
#line 138 "cmd-parse.y"
1462
181
                {
1463
181
      struct cmd_parse_state  *ps = &parse_state;
1464
1465
181
      ps->commands = (yyvsp[0].commands);
1466
181
    }
1467
181
#line 1468 "cmd-parse.c"
1468
181
    break;
1469
1470
3.23k
  case 4:
1471
3.23k
#line 145 "cmd-parse.y"
1472
3.23k
                {
1473
3.23k
      (yyval.commands) = (yyvsp[-1].commands);
1474
3.23k
    }
1475
3.23k
#line 1476 "cmd-parse.c"
1476
3.23k
    break;
1477
1478
6.90k
  case 5:
1479
6.90k
#line 149 "cmd-parse.y"
1480
6.90k
                {
1481
6.90k
      (yyval.commands) = (yyvsp[-2].commands);
1482
6.90k
      TAILQ_CONCAT((yyval.commands), (yyvsp[-1].commands), entry);
1483
6.90k
      free((yyvsp[-1].commands));
1484
6.90k
    }
1485
6.90k
#line 1486 "cmd-parse.c"
1486
6.90k
    break;
1487
1488
4.64k
  case 6:
1489
4.64k
#line 156 "cmd-parse.y"
1490
4.64k
                {
1491
4.64k
      (yyval.commands) = xmalloc (sizeof *(yyval.commands));
1492
4.64k
      TAILQ_INIT((yyval.commands));
1493
4.64k
    }
1494
4.64k
#line 1495 "cmd-parse.c"
1495
4.64k
    break;
1496
1497
258
  case 7:
1498
258
#line 161 "cmd-parse.y"
1499
258
                {
1500
258
      (yyval.commands) = xmalloc (sizeof *(yyval.commands));
1501
258
      TAILQ_INIT((yyval.commands));
1502
258
    }
1503
258
#line 1504 "cmd-parse.c"
1504
258
    break;
1505
1506
1.01k
  case 8:
1507
1.01k
#line 166 "cmd-parse.y"
1508
1.01k
                {
1509
1.01k
      struct cmd_parse_state  *ps = &parse_state;
1510
1511
1.01k
      if (ps->scope == NULL || ps->scope->flag)
1512
494
        (yyval.commands) = (yyvsp[0].commands);
1513
516
      else {
1514
516
        (yyval.commands) = cmd_parse_new_commands();
1515
516
        cmd_parse_free_commands((yyvsp[0].commands));
1516
516
      }
1517
1.01k
    }
1518
1.01k
#line 1519 "cmd-parse.c"
1519
1.01k
    break;
1520
1521
4.72k
  case 9:
1522
4.72k
#line 177 "cmd-parse.y"
1523
4.72k
                {
1524
4.72k
      struct cmd_parse_state  *ps = &parse_state;
1525
1526
4.72k
      if (ps->scope == NULL || ps->scope->flag)
1527
3.74k
        (yyval.commands) = (yyvsp[0].commands);
1528
976
      else {
1529
976
        (yyval.commands) = cmd_parse_new_commands();
1530
976
        cmd_parse_free_commands((yyvsp[0].commands));
1531
976
      }
1532
4.72k
    }
1533
4.72k
#line 1534 "cmd-parse.c"
1534
4.72k
    break;
1535
1536
367
  case 10:
1537
367
#line 189 "cmd-parse.y"
1538
367
                {
1539
367
      (yyval.token) = (yyvsp[0].token);
1540
367
    }
1541
367
#line 1542 "cmd-parse.c"
1542
367
    break;
1543
1544
3.36k
  case 11:
1545
3.36k
#line 193 "cmd-parse.y"
1546
3.36k
                {
1547
3.36k
      (yyval.token) = (yyvsp[0].token);
1548
3.36k
    }
1549
3.36k
#line 1550 "cmd-parse.c"
1550
3.36k
    break;
1551
1552
3.72k
  case 12:
1553
3.72k
#line 198 "cmd-parse.y"
1554
3.72k
                {
1555
3.72k
      struct cmd_parse_state  *ps = &parse_state;
1556
3.72k
      struct cmd_parse_input  *pi = ps->input;
1557
3.72k
      struct format_tree  *ft;
1558
3.72k
      struct client   *c = pi->c;
1559
3.72k
      struct cmd_find_state *fsp;
1560
3.72k
      struct cmd_find_state  fs;
1561
3.72k
      int      flags = FORMAT_NOJOBS;
1562
1563
3.72k
      if (cmd_find_valid_state(&pi->fs))
1564
0
        fsp = &pi->fs;
1565
3.72k
      else {
1566
3.72k
        cmd_find_from_client(&fs, c, 0);
1567
3.72k
        fsp = &fs;
1568
3.72k
      }
1569
3.72k
      ft = format_create(c, pi->item, FORMAT_NONE, flags);
1570
3.72k
      format_defaults(ft, c, fsp->s, fsp->wl, fsp->wp);
1571
1572
3.72k
      (yyval.token) = format_expand(ft, (yyvsp[0].token));
1573
3.72k
      format_free(ft);
1574
3.72k
      free((yyvsp[0].token));
1575
3.72k
    }
1576
3.72k
#line 1577 "cmd-parse.c"
1577
3.72k
    break;
1578
1579
1.46k
  case 15:
1580
1.46k
#line 225 "cmd-parse.y"
1581
1.46k
                {
1582
1.46k
      struct cmd_parse_state  *ps = &parse_state;
1583
1.46k
      int      flags = ps->input->flags;
1584
1.46k
      int      flag = 1;
1585
1.46k
      struct cmd_parse_scope  *scope;
1586
1587
1.46k
      if (ps->scope != NULL) {
1588
134
        flag = ps->scope->flag;
1589
134
        TAILQ_FOREACH(scope, &ps->stack, entry)
1590
5.67k
          flag = flag && scope->flag;
1591
134
      }
1592
1593
1.46k
      if (strlen((yyvsp[0].token)) > CMD_PARSE_MAX_ENVIRON_LEN) {
1594
3
        yyerror("environment variable is too long");
1595
3
        YYABORT;
1596
3
      }
1597
1.45k
      if ((~flags & CMD_PARSE_PARSEONLY) && flag)
1598
1.32k
        environ_put(global_environ, (yyvsp[0].token), 0);
1599
1.45k
      free((yyvsp[0].token));
1600
1.45k
    }
1601
0
#line 1602 "cmd-parse.c"
1602
0
    break;
1603
1604
260
  case 16:
1605
260
#line 247 "cmd-parse.y"
1606
260
                {
1607
260
      struct cmd_parse_state  *ps = &parse_state;
1608
260
      int      flags = ps->input->flags;
1609
260
      int      flag = 1;
1610
260
      struct cmd_parse_scope  *scope;
1611
1612
260
      if (ps->scope != NULL) {
1613
128
        flag = ps->scope->flag;
1614
128
        TAILQ_FOREACH(scope, &ps->stack, entry)
1615
0
          flag = flag && scope->flag;
1616
128
      }
1617
1618
260
      if (strlen((yyvsp[0].token)) > CMD_PARSE_MAX_ENVIRON_LEN) {
1619
2
        yyerror("environment variable is too long");
1620
2
        YYABORT;
1621
2
      }
1622
258
      if ((~flags & CMD_PARSE_PARSEONLY) && flag)
1623
130
        environ_put(global_environ, (yyvsp[0].token), ENVIRON_HIDDEN);
1624
258
      free((yyvsp[0].token));
1625
258
    }
1626
0
#line 1627 "cmd-parse.c"
1627
0
    break;
1628
1629
2.11k
  case 17:
1630
2.11k
#line 269 "cmd-parse.y"
1631
2.11k
                {
1632
2.11k
      struct cmd_parse_state  *ps = &parse_state;
1633
2.11k
      struct cmd_parse_scope  *scope;
1634
1635
2.11k
      scope = xmalloc(sizeof *scope);
1636
2.11k
      (yyval.flag) = scope->flag = format_true((yyvsp[0].token));
1637
2.11k
      free((yyvsp[0].token));
1638
1639
2.11k
      if (ps->scope != NULL)
1640
1.41k
        TAILQ_INSERT_HEAD(&ps->stack, ps->scope, entry);
1641
2.11k
      ps->scope = scope;
1642
2.11k
    }
1643
2.11k
#line 1644 "cmd-parse.c"
1644
2.11k
    break;
1645
1646
560
  case 18:
1647
560
#line 283 "cmd-parse.y"
1648
560
                {
1649
560
      struct cmd_parse_state  *ps = &parse_state;
1650
560
      struct cmd_parse_scope  *scope;
1651
1652
560
      scope = xmalloc(sizeof *scope);
1653
560
      scope->flag = !ps->scope->flag;
1654
1655
560
      free(ps->scope);
1656
560
      ps->scope = scope;
1657
560
    }
1658
560
#line 1659 "cmd-parse.c"
1659
560
    break;
1660
1661
1.61k
  case 19:
1662
1.61k
#line 295 "cmd-parse.y"
1663
1.61k
                {
1664
1.61k
      struct cmd_parse_state  *ps = &parse_state;
1665
1.61k
      struct cmd_parse_scope  *scope;
1666
1667
1.61k
      scope = xmalloc(sizeof *scope);
1668
1.61k
      (yyval.flag) = scope->flag = format_true((yyvsp[0].token));
1669
1.61k
      free((yyvsp[0].token));
1670
1671
1.61k
      free(ps->scope);
1672
1.61k
      ps->scope = scope;
1673
1.61k
    }
1674
1.61k
#line 1675 "cmd-parse.c"
1675
1.61k
    break;
1676
1677
1.58k
  case 20:
1678
1.58k
#line 308 "cmd-parse.y"
1679
1.58k
                {
1680
1.58k
      struct cmd_parse_state  *ps = &parse_state;
1681
1682
1.58k
      free(ps->scope);
1683
1.58k
      ps->scope = TAILQ_FIRST(&ps->stack);
1684
1.58k
      if (ps->scope != NULL)
1685
1.05k
        TAILQ_REMOVE(&ps->stack, ps->scope, entry);
1686
1.58k
    }
1687
1.58k
#line 1688 "cmd-parse.c"
1688
1.58k
    break;
1689
1690
652
  case 21:
1691
652
#line 318 "cmd-parse.y"
1692
652
                {
1693
652
      if ((yyvsp[-3].flag))
1694
138
        (yyval.commands) = (yyvsp[-1].commands);
1695
514
      else {
1696
514
        (yyval.commands) = cmd_parse_new_commands();
1697
514
        cmd_parse_free_commands((yyvsp[-1].commands));
1698
514
      }
1699
652
    }
1700
652
#line 1701 "cmd-parse.c"
1701
652
    break;
1702
1703
108
  case 22:
1704
108
#line 327 "cmd-parse.y"
1705
108
                {
1706
108
      if ((yyvsp[-6].flag)) {
1707
72
        (yyval.commands) = (yyvsp[-4].commands);
1708
72
        cmd_parse_free_commands((yyvsp[-1].commands));
1709
72
      } else {
1710
36
        (yyval.commands) = (yyvsp[-1].commands);
1711
36
        cmd_parse_free_commands((yyvsp[-4].commands));
1712
36
      }
1713
108
    }
1714
108
#line 1715 "cmd-parse.c"
1715
108
    break;
1716
1717
82
  case 23:
1718
82
#line 337 "cmd-parse.y"
1719
82
                {
1720
82
      if ((yyvsp[-4].flag)) {
1721
49
        (yyval.commands) = (yyvsp[-2].commands);
1722
49
        cmd_parse_free_commands((yyvsp[-1].elif).commands);
1723
49
      } else if ((yyvsp[-1].elif).flag) {
1724
32
        (yyval.commands) = (yyvsp[-1].elif).commands;
1725
32
        cmd_parse_free_commands((yyvsp[-2].commands));
1726
32
      } else {
1727
1
        (yyval.commands) = cmd_parse_new_commands();
1728
1
        cmd_parse_free_commands((yyvsp[-2].commands));
1729
1
        cmd_parse_free_commands((yyvsp[-1].elif).commands);
1730
1
      }
1731
82
    }
1732
82
#line 1733 "cmd-parse.c"
1733
82
    break;
1734
1735
168
  case 24:
1736
168
#line 351 "cmd-parse.y"
1737
168
                {
1738
168
      if ((yyvsp[-7].flag)) {
1739
85
        (yyval.commands) = (yyvsp[-5].commands);
1740
85
        cmd_parse_free_commands((yyvsp[-4].elif).commands);
1741
85
        cmd_parse_free_commands((yyvsp[-1].commands));
1742
85
      } else if ((yyvsp[-4].elif).flag) {
1743
49
        (yyval.commands) = (yyvsp[-4].elif).commands;
1744
49
        cmd_parse_free_commands((yyvsp[-5].commands));
1745
49
        cmd_parse_free_commands((yyvsp[-1].commands));
1746
49
      } else {
1747
34
        (yyval.commands) = (yyvsp[-1].commands);
1748
34
        cmd_parse_free_commands((yyvsp[-5].commands));
1749
34
        cmd_parse_free_commands((yyvsp[-4].elif).commands);
1750
34
      }
1751
168
    }
1752
168
#line 1753 "cmd-parse.c"
1753
168
    break;
1754
1755
259
  case 25:
1756
259
#line 368 "cmd-parse.y"
1757
259
                {
1758
259
      if ((yyvsp[-2].flag)) {
1759
133
        (yyval.elif).flag = 1;
1760
133
        (yyval.elif).commands = (yyvsp[0].commands);
1761
133
      } else {
1762
126
        (yyval.elif).flag = 0;
1763
126
        (yyval.elif).commands = cmd_parse_new_commands();
1764
126
        cmd_parse_free_commands((yyvsp[0].commands));
1765
126
      }
1766
259
    }
1767
259
#line 1768 "cmd-parse.c"
1768
259
    break;
1769
1770
418
  case 26:
1771
418
#line 379 "cmd-parse.y"
1772
418
                {
1773
418
      if ((yyvsp[-3].flag)) {
1774
151
        (yyval.elif).flag = 1;
1775
151
        (yyval.elif).commands = (yyvsp[-1].commands);
1776
151
        cmd_parse_free_commands((yyvsp[0].elif).commands);
1777
267
      } else if ((yyvsp[0].elif).flag) {
1778
129
        (yyval.elif).flag = 1;
1779
129
        (yyval.elif).commands = (yyvsp[0].elif).commands;
1780
129
        cmd_parse_free_commands((yyvsp[-1].commands));
1781
138
      } else {
1782
138
        (yyval.elif).flag = 0;
1783
138
        (yyval.elif).commands = cmd_parse_new_commands();
1784
138
        cmd_parse_free_commands((yyvsp[-1].commands));
1785
138
        cmd_parse_free_commands((yyvsp[0].elif).commands);
1786
138
      }
1787
418
    }
1788
418
#line 1789 "cmd-parse.c"
1789
418
    break;
1790
1791
6.29k
  case 27:
1792
6.29k
#line 397 "cmd-parse.y"
1793
6.29k
                {
1794
6.29k
      struct cmd_parse_state  *ps = &parse_state;
1795
1796
6.29k
      (yyval.commands) = cmd_parse_new_commands();
1797
6.29k
      if (!TAILQ_EMPTY(&(yyvsp[0].command)->arguments) &&
1798
6.04k
          (ps->scope == NULL || ps->scope->flag))
1799
4.21k
        TAILQ_INSERT_TAIL((yyval.commands), (yyvsp[0].command), entry);
1800
2.07k
      else
1801
2.07k
        cmd_parse_free_command((yyvsp[0].command));
1802
6.29k
    }
1803
6.29k
#line 1804 "cmd-parse.c"
1804
6.29k
    break;
1805
1806
914
  case 28:
1807
914
#line 408 "cmd-parse.y"
1808
914
                {
1809
914
      (yyval.commands) = (yyvsp[-1].commands);
1810
914
    }
1811
914
#line 1812 "cmd-parse.c"
1812
914
    break;
1813
1814
334
  case 29:
1815
334
#line 412 "cmd-parse.y"
1816
334
                {
1817
334
      (yyval.commands) = (yyvsp[-2].commands);
1818
334
      TAILQ_CONCAT((yyval.commands), (yyvsp[0].commands), entry);
1819
334
      free((yyvsp[0].commands));
1820
334
    }
1821
334
#line 1822 "cmd-parse.c"
1822
334
    break;
1823
1824
2.29k
  case 30:
1825
2.29k
#line 418 "cmd-parse.y"
1826
2.29k
                {
1827
2.29k
      struct cmd_parse_state  *ps = &parse_state;
1828
1829
2.29k
      if (!TAILQ_EMPTY(&(yyvsp[0].command)->arguments) &&
1830
1.11k
          (ps->scope == NULL || ps->scope->flag)) {
1831
985
        (yyval.commands) = (yyvsp[-2].commands);
1832
985
        TAILQ_INSERT_TAIL((yyval.commands), (yyvsp[0].command), entry);
1833
1.30k
      } else {
1834
1.30k
        (yyval.commands) = cmd_parse_new_commands();
1835
1.30k
        cmd_parse_free_commands((yyvsp[-2].commands));
1836
1.30k
        cmd_parse_free_command((yyvsp[0].command));
1837
1.30k
      }
1838
2.29k
    }
1839
2.29k
#line 1840 "cmd-parse.c"
1840
2.29k
    break;
1841
1842
241
  case 31:
1843
241
#line 432 "cmd-parse.y"
1844
241
                {
1845
241
      (yyval.commands) = (yyvsp[0].commands);
1846
241
    }
1847
241
#line 1848 "cmd-parse.c"
1848
241
    break;
1849
1850
1.43k
  case 32:
1851
1.43k
#line 437 "cmd-parse.y"
1852
1.43k
                {
1853
1.43k
      struct cmd_parse_state  *ps = &parse_state;
1854
1855
1.43k
      (yyval.command) = xcalloc(1, sizeof *(yyval.command));
1856
1.43k
      (yyval.command)->line = ps->input->line;
1857
1.43k
      TAILQ_INIT(&(yyval.command)->arguments);
1858
1.43k
    }
1859
1.43k
#line 1860 "cmd-parse.c"
1860
1.43k
    break;
1861
1862
4.14k
  case 33:
1863
4.14k
#line 445 "cmd-parse.y"
1864
4.14k
                {
1865
4.14k
      struct cmd_parse_state    *ps = &parse_state;
1866
4.14k
      struct cmd_parse_argument *arg;
1867
1868
4.14k
      (yyval.command) = xcalloc(1, sizeof *(yyval.command));
1869
4.14k
      (yyval.command)->line = ps->input->line;
1870
4.14k
      TAILQ_INIT(&(yyval.command)->arguments);
1871
1872
4.14k
      arg = xcalloc(1, sizeof *arg);
1873
4.14k
      arg->type = CMD_PARSE_STRING;
1874
4.14k
      arg->string = (yyvsp[0].token);
1875
4.14k
      TAILQ_INSERT_HEAD(&(yyval.command)->arguments, arg, entry);
1876
4.14k
    }
1877
4.14k
#line 1878 "cmd-parse.c"
1878
4.14k
    break;
1879
1880
3.01k
  case 34:
1881
3.01k
#line 459 "cmd-parse.y"
1882
3.01k
                {
1883
3.01k
      struct cmd_parse_state    *ps = &parse_state;
1884
3.01k
      struct cmd_parse_argument *arg;
1885
1886
3.01k
      (yyval.command) = xcalloc(1, sizeof *(yyval.command));
1887
3.01k
      (yyval.command)->line = ps->input->line;
1888
3.01k
      TAILQ_INIT(&(yyval.command)->arguments);
1889
1890
3.01k
      TAILQ_CONCAT(&(yyval.command)->arguments, (yyvsp[0].arguments), entry);
1891
3.01k
      free((yyvsp[0].arguments));
1892
1893
3.01k
      arg = xcalloc(1, sizeof *arg);
1894
3.01k
      arg->type = CMD_PARSE_STRING;
1895
3.01k
      arg->string = (yyvsp[-1].token);
1896
3.01k
      TAILQ_INSERT_HEAD(&(yyval.command)->arguments, arg, entry);
1897
3.01k
    }
1898
3.01k
#line 1899 "cmd-parse.c"
1899
3.01k
    break;
1900
1901
116
  case 35:
1902
116
#line 477 "cmd-parse.y"
1903
116
                {
1904
116
      if ((yyvsp[-2].flag))
1905
73
        (yyval.commands) = (yyvsp[-1].commands);
1906
43
      else {
1907
43
        (yyval.commands) = cmd_parse_new_commands();
1908
43
        cmd_parse_free_commands((yyvsp[-1].commands));
1909
43
      }
1910
116
    }
1911
116
#line 1912 "cmd-parse.c"
1912
116
    break;
1913
1914
110
  case 36:
1915
110
#line 486 "cmd-parse.y"
1916
110
                {
1917
110
      if ((yyvsp[-4].flag)) {
1918
58
        (yyval.commands) = (yyvsp[-3].commands);
1919
58
        cmd_parse_free_commands((yyvsp[-1].commands));
1920
58
      } else {
1921
52
        (yyval.commands) = (yyvsp[-1].commands);
1922
52
        cmd_parse_free_commands((yyvsp[-3].commands));
1923
52
      }
1924
110
    }
1925
110
#line 1926 "cmd-parse.c"
1926
110
    break;
1927
1928
195
  case 37:
1929
195
#line 496 "cmd-parse.y"
1930
195
                {
1931
195
      if ((yyvsp[-3].flag)) {
1932
92
        (yyval.commands) = (yyvsp[-2].commands);
1933
92
        cmd_parse_free_commands((yyvsp[-1].elif).commands);
1934
103
      } else if ((yyvsp[-1].elif).flag) {
1935
52
        (yyval.commands) = (yyvsp[-1].elif).commands;
1936
52
        cmd_parse_free_commands((yyvsp[-2].commands));
1937
52
      } else {
1938
51
        (yyval.commands) = cmd_parse_new_commands();
1939
51
        cmd_parse_free_commands((yyvsp[-2].commands));
1940
51
        cmd_parse_free_commands((yyvsp[-1].elif).commands);
1941
51
      }
1942
195
    }
1943
195
#line 1944 "cmd-parse.c"
1944
195
    break;
1945
1946
154
  case 38:
1947
154
#line 510 "cmd-parse.y"
1948
154
                {
1949
154
      if ((yyvsp[-5].flag)) {
1950
52
        (yyval.commands) = (yyvsp[-4].commands);
1951
52
        cmd_parse_free_commands((yyvsp[-3].elif).commands);
1952
52
        cmd_parse_free_commands((yyvsp[-1].commands));
1953
102
      } else if ((yyvsp[-3].elif).flag) {
1954
58
        (yyval.commands) = (yyvsp[-3].elif).commands;
1955
58
        cmd_parse_free_commands((yyvsp[-4].commands));
1956
58
        cmd_parse_free_commands((yyvsp[-1].commands));
1957
58
      } else {
1958
44
        (yyval.commands) = (yyvsp[-1].commands);
1959
44
        cmd_parse_free_commands((yyvsp[-4].commands));
1960
44
        cmd_parse_free_commands((yyvsp[-3].elif).commands);
1961
44
      }
1962
154
    }
1963
154
#line 1964 "cmd-parse.c"
1964
154
    break;
1965
1966
363
  case 39:
1967
363
#line 527 "cmd-parse.y"
1968
363
                {
1969
363
      if ((yyvsp[-1].flag)) {
1970
152
        (yyval.elif).flag = 1;
1971
152
        (yyval.elif).commands = (yyvsp[0].commands);
1972
211
      } else {
1973
211
        (yyval.elif).flag = 0;
1974
211
        (yyval.elif).commands = cmd_parse_new_commands();
1975
211
        cmd_parse_free_commands((yyvsp[0].commands));
1976
211
      }
1977
363
    }
1978
363
#line 1979 "cmd-parse.c"
1979
363
    break;
1980
1981
530
  case 40:
1982
530
#line 538 "cmd-parse.y"
1983
530
                {
1984
530
      if ((yyvsp[-2].flag)) {
1985
179
        (yyval.elif).flag = 1;
1986
179
        (yyval.elif).commands = (yyvsp[-1].commands);
1987
179
        cmd_parse_free_commands((yyvsp[0].elif).commands);
1988
351
      } else if ((yyvsp[0].elif).flag) {
1989
194
        (yyval.elif).flag = 1;
1990
194
        (yyval.elif).commands = (yyvsp[0].elif).commands;
1991
194
        cmd_parse_free_commands((yyvsp[-1].commands));
1992
194
      } else {
1993
157
        (yyval.elif).flag = 0;
1994
157
        (yyval.elif).commands = cmd_parse_new_commands();
1995
157
        cmd_parse_free_commands((yyvsp[-1].commands));
1996
157
        cmd_parse_free_commands((yyvsp[0].elif).commands);
1997
157
      }
1998
530
    }
1999
530
#line 2000 "cmd-parse.c"
2000
530
    break;
2001
2002
3.01k
  case 41:
2003
3.01k
#line 556 "cmd-parse.y"
2004
3.01k
                {
2005
3.01k
      (yyval.arguments) = xcalloc(1, sizeof *(yyval.arguments));
2006
3.01k
      TAILQ_INIT((yyval.arguments));
2007
2008
3.01k
      TAILQ_INSERT_HEAD((yyval.arguments), (yyvsp[0].argument), entry);
2009
3.01k
    }
2010
3.01k
#line 2011 "cmd-parse.c"
2011
3.01k
    break;
2012
2013
13.0k
  case 42:
2014
13.0k
#line 563 "cmd-parse.y"
2015
13.0k
                {
2016
13.0k
      TAILQ_INSERT_HEAD((yyvsp[0].arguments), (yyvsp[-1].argument), entry);
2017
13.0k
      (yyval.arguments) = (yyvsp[0].arguments);
2018
13.0k
    }
2019
13.0k
#line 2020 "cmd-parse.c"
2020
13.0k
    break;
2021
2022
15.6k
  case 43:
2023
15.6k
#line 569 "cmd-parse.y"
2024
15.6k
                {
2025
15.6k
      (yyval.argument) = xcalloc(1, sizeof *(yyval.argument));
2026
15.6k
      (yyval.argument)->type = CMD_PARSE_STRING;
2027
15.6k
      (yyval.argument)->string = (yyvsp[0].token);
2028
15.6k
    }
2029
15.6k
#line 2030 "cmd-parse.c"
2030
15.6k
    break;
2031
2032
6
  case 44:
2033
6
#line 575 "cmd-parse.y"
2034
6
                {
2035
6
      (yyval.argument) = xcalloc(1, sizeof *(yyval.argument));
2036
6
      (yyval.argument)->type = CMD_PARSE_STRING;
2037
6
      (yyval.argument)->string = (yyvsp[0].token);
2038
6
    }
2039
6
#line 2040 "cmd-parse.c"
2040
6
    break;
2041
2042
407
  case 45:
2043
407
#line 581 "cmd-parse.y"
2044
407
                {
2045
407
      (yyval.argument) = xcalloc(1, sizeof *(yyval.argument));
2046
407
      (yyval.argument)->type = CMD_PARSE_COMMANDS;
2047
407
      (yyval.argument)->commands = (yyvsp[0].commands);
2048
407
    }
2049
407
#line 2050 "cmd-parse.c"
2050
407
    break;
2051
2052
23
  case 46:
2053
23
#line 588 "cmd-parse.y"
2054
23
                        {
2055
23
        (yyval.commands) = (yyvsp[-1].commands);
2056
23
      }
2057
23
#line 2058 "cmd-parse.c"
2058
23
    break;
2059
2060
384
  case 47:
2061
384
#line 592 "cmd-parse.y"
2062
384
                        {
2063
384
        (yyval.commands) = (yyvsp[-2].commands);
2064
384
        TAILQ_CONCAT((yyval.commands), (yyvsp[-1].commands), entry);
2065
384
        free((yyvsp[-1].commands));
2066
384
      }
2067
384
#line 2068 "cmd-parse.c"
2068
384
    break;
2069
2070
2071
0
#line 2072 "cmd-parse.c"
2072
2073
7.59k
      default: break;
2074
97.9k
    }
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
97.9k
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2087
2088
97.9k
  YYPOPSTACK (yylen);
2089
97.9k
  yylen = 0;
2090
97.9k
  YY_STACK_PRINT (yyss, yyssp);
2091
2092
97.9k
  *++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
97.9k
  {
2098
97.9k
    const int yylhs = yyr1[yyn] - YYNTOKENS;
2099
97.9k
    const int yyi = yypgoto[yylhs] + *yyssp;
2100
97.9k
    yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
2101
97.9k
               ? yytable[yyi]
2102
97.9k
               : yydefgoto[yylhs]);
2103
97.9k
  }
2104
2105
97.9k
  goto yynewstate;
2106
2107
2108
/*--------------------------------------.
2109
| yyerrlab -- here on detecting error.  |
2110
`--------------------------------------*/
2111
185
yyerrlab:
2112
  /* Make sure we have latest lookahead translation.  See comments at
2113
     user semantic actions for why this is necessary.  */
2114
185
  yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2115
2116
  /* If not already recovering from an error, report this error.  */
2117
185
  if (!yyerrstatus)
2118
185
    {
2119
185
      ++yynerrs;
2120
185
#if ! YYERROR_VERBOSE
2121
185
      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
185
    }
2155
2156
2157
2158
185
  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
185
  goto yyerrlab1;
2180
2181
2182
/*---------------------------------------------------.
2183
| yyerrorlab -- error raised explicitly by YYERROR.  |
2184
`---------------------------------------------------*/
2185
185
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
185
yyerrlab1:
2204
185
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2205
2206
185
  for (;;)
2207
3.29k
    {
2208
3.29k
      yyn = yypact[yystate];
2209
3.29k
      if (!yypact_value_is_default (yyn))
2210
3.29k
        {
2211
3.29k
          yyn += YYTERROR;
2212
3.29k
          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
3.29k
        }
2219
2220
      /* Pop the current state because it cannot handle the error token.  */
2221
3.29k
      if (yyssp == yyss)
2222
185
        YYABORT;
2223
2224
2225
3.11k
      yydestruct ("Error: popping",
2226
3.11k
                  yystos[yystate], yyvsp);
2227
3.11k
      YYPOPSTACK (1);
2228
3.11k
      yystate = *yyssp;
2229
3.11k
      YY_STACK_PRINT (yyss, yyssp);
2230
3.11k
    }
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
181
yyacceptlab:
2248
181
  yyresult = 0;
2249
181
  goto yyreturn;
2250
2251
2252
/*-----------------------------------.
2253
| yyabortlab -- YYABORT comes here.  |
2254
`-----------------------------------*/
2255
190
yyabortlab:
2256
190
  yyresult = 1;
2257
190
  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
371
yyreturn:
2275
371
  if (yychar != YYEMPTY)
2276
185
    {
2277
      /* Make sure we have latest lookahead translation.  See comments at
2278
         user semantic actions for why this is necessary.  */
2279
185
      yytoken = YYTRANSLATE (yychar);
2280
185
      yydestruct ("Cleanup: discarding lookahead",
2281
185
                  yytoken, &yylval);
2282
185
    }
2283
  /* Do not reclaim the symbols of the rule whose action triggered
2284
     this YYABORT or YYACCEPT.  */
2285
371
  YYPOPSTACK (yylen);
2286
371
  YY_STACK_PRINT (yyss, yyssp);
2287
750
  while (yyssp != yyss)
2288
379
    {
2289
379
      yydestruct ("Cleanup: popping",
2290
379
                  yystos[+*yyssp], yyvsp);
2291
379
      YYPOPSTACK (1);
2292
379
    }
2293
371
#ifndef yyoverflow
2294
371
  if (yyss != yyssa)
2295
21
    YYSTACK_FREE (yyss);
2296
371
#endif
2297
#if YYERROR_VERBOSE
2298
  if (yymsg != yymsgbuf)
2299
    YYSTACK_FREE (yymsg);
2300
#endif
2301
371
  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
219
{
2309
219
  char  *s;
2310
2311
219
  if (file == NULL)
2312
219
    s = xstrdup(error);
2313
0
  else
2314
0
    xasprintf(&s, "%s:%u: %s", file, line, error);
2315
219
  return (s);
2316
219
}
2317
2318
static void
2319
cmd_parse_print_commands(struct cmd_parse_input *pi, struct cmd_list *cmdlist)
2320
1.43k
{
2321
1.43k
  char  *s;
2322
2323
1.43k
  if (pi->item == NULL || (~pi->flags & CMD_PARSE_VERBOSE))
2324
1.43k
    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
21.7k
{
2336
21.7k
  switch (arg->type) {
2337
21.3k
  case CMD_PARSE_STRING:
2338
21.3k
    free(arg->string);
2339
21.3k
    break;
2340
396
  case CMD_PARSE_COMMANDS:
2341
396
    cmd_parse_free_commands(arg->commands);
2342
396
    break;
2343
0
  case CMD_PARSE_PARSED_COMMANDS:
2344
0
    cmd_list_free(arg->cmdlist);
2345
0
    break;
2346
21.7k
  }
2347
21.7k
  free(arg);
2348
21.7k
}
2349
2350
static void
2351
cmd_parse_free_arguments(struct cmd_parse_arguments *args)
2352
7.47k
{
2353
7.47k
  struct cmd_parse_argument *arg, *arg1;
2354
2355
21.5k
  TAILQ_FOREACH_SAFE(arg, args, entry, arg1) {
2356
21.5k
    TAILQ_REMOVE(args, arg, entry);
2357
21.5k
    cmd_parse_free_argument(arg);
2358
21.5k
  }
2359
7.47k
}
2360
2361
static void
2362
cmd_parse_free_command(struct cmd_parse_command *cmd)
2363
7.47k
{
2364
7.47k
  cmd_parse_free_arguments(&cmd->arguments);
2365
7.47k
  free(cmd);
2366
7.47k
}
2367
2368
static struct cmd_parse_commands *
2369
cmd_parse_new_commands(void)
2370
10.3k
{
2371
10.3k
  struct cmd_parse_commands *cmds;
2372
2373
10.3k
  cmds = xmalloc(sizeof *cmds);
2374
10.3k
  TAILQ_INIT(cmds);
2375
10.3k
  return (cmds);
2376
10.3k
}
2377
2378
static void
2379
cmd_parse_free_commands(struct cmd_parse_commands *cmds)
2380
6.70k
{
2381
6.70k
  struct cmd_parse_command  *cmd, *cmd1;
2382
2383
6.70k
  TAILQ_FOREACH_SAFE(cmd, cmds, entry, cmd1) {
2384
4.09k
    TAILQ_REMOVE(cmds, cmd, entry);
2385
4.09k
    cmd_parse_free_command(cmd);
2386
4.09k
  }
2387
6.70k
  free(cmds);
2388
6.70k
}
2389
2390
static struct cmd_parse_commands *
2391
cmd_parse_run_parser(char **cause)
2392
371
{
2393
371
  struct cmd_parse_state  *ps = &parse_state;
2394
371
  struct cmd_parse_scope  *scope, *scope1;
2395
371
  int      retval;
2396
2397
371
  ps->commands = NULL;
2398
371
  TAILQ_INIT(&ps->stack);
2399
2400
371
  retval = yyparse();
2401
371
  TAILQ_FOREACH_SAFE(scope, &ps->stack, entry, scope1) {
2402
366
    TAILQ_REMOVE(&ps->stack, scope, entry);
2403
366
    free(scope);
2404
366
  }
2405
371
  if (retval != 0) {
2406
190
    *cause = ps->error;
2407
190
    return (NULL);
2408
190
  }
2409
2410
181
  if (ps->commands == NULL)
2411
0
    return (cmd_parse_new_commands());
2412
181
  return (ps->commands);
2413
181
}
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
371
{
2430
371
  struct cmd_parse_state  *ps = &parse_state;
2431
2432
371
  memset(ps, 0, sizeof *ps);
2433
371
  ps->input = pi;
2434
371
  ps->buf = buf;
2435
371
  ps->len = len;
2436
371
  return (cmd_parse_run_parser(cause));
2437
371
}
2438
2439
static void
2440
cmd_parse_log_commands(struct cmd_parse_commands *cmds, const char *prefix)
2441
14.6k
{
2442
14.6k
  struct cmd_parse_command  *cmd;
2443
14.6k
  struct cmd_parse_argument *arg;
2444
14.6k
  u_int        i, j;
2445
14.6k
  char        *s;
2446
2447
14.6k
  i = 0;
2448
16.4k
  TAILQ_FOREACH(cmd, cmds, entry) {
2449
16.4k
    j = 0;
2450
46.7k
    TAILQ_FOREACH(arg, &cmd->arguments, entry) {
2451
46.7k
      switch (arg->type) {
2452
32.5k
      case CMD_PARSE_STRING:
2453
32.5k
        log_debug("%s %u:%u: %s", prefix, i, j,
2454
32.5k
            arg->string);
2455
32.5k
        break;
2456
14.1k
      case CMD_PARSE_COMMANDS:
2457
14.1k
        xasprintf(&s, "%s %u:%u", prefix, i, j);
2458
14.1k
        cmd_parse_log_commands(arg->commands, s);
2459
14.1k
        free(s);
2460
14.1k
        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
46.7k
      }
2467
46.7k
      j++;
2468
46.7k
    }
2469
16.4k
    i++;
2470
16.4k
  }
2471
14.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
1.79k
{
2477
1.79k
  struct cmd_parse_argument *first;
2478
1.79k
  struct cmd_parse_commands *cmds;
2479
1.79k
  struct cmd_parse_command  *last;
2480
1.79k
  char        *alias, *name, *cause;
2481
2482
1.79k
  if (pi->flags & CMD_PARSE_NOALIAS)
2483
132
    return (0);
2484
1.66k
  memset(pr, 0, sizeof *pr);
2485
2486
1.66k
  first = TAILQ_FIRST(&cmd->arguments);
2487
1.66k
  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
1.66k
  name = first->string;
2493
2494
1.66k
  alias = cmd_get_alias(name);
2495
1.66k
  if (alias == NULL)
2496
1.53k
    return (0);
2497
132
  log_debug("%s: %u alias %s = %s", __func__, pi->line, name, alias);
2498
2499
132
  cmds = cmd_parse_do_buffer(alias, strlen(alias), pi, &cause);
2500
132
  free(alias);
2501
132
  if (cmds == NULL) {
2502
0
    pr->status = CMD_PARSE_ERROR;
2503
0
    pr->error = cause;
2504
0
    return (1);
2505
0
  }
2506
2507
132
  last = TAILQ_LAST(cmds, cmd_parse_commands);
2508
132
  if (last == NULL) {
2509
0
    pr->status = CMD_PARSE_SUCCESS;
2510
0
    pr->cmdlist = cmd_list_new();
2511
0
    cmd_parse_free_commands(cmds);
2512
0
    return (1);
2513
0
  }
2514
2515
132
  TAILQ_REMOVE(&cmd->arguments, first, entry);
2516
132
  cmd_parse_free_argument(first);
2517
2518
132
  TAILQ_CONCAT(&last->arguments, &cmd->arguments, entry);
2519
132
  cmd_parse_log_commands(cmds, __func__);
2520
2521
132
  pi->flags |= CMD_PARSE_NOALIAS;
2522
132
  cmd_parse_build_commands(cmds, pi, pr);
2523
132
  pi->flags &= ~CMD_PARSE_NOALIAS;
2524
132
  cmd_parse_free_commands(cmds);
2525
132
  return (1);
2526
132
}
2527
2528
static void
2529
cmd_parse_build_command(struct cmd_parse_command *cmd,
2530
    struct cmd_parse_input *pi, struct cmd_parse_result *pr)
2531
1.79k
{
2532
1.79k
  struct cmd_parse_argument *arg;
2533
1.79k
  struct cmd      *add;
2534
1.79k
  char        *cause;
2535
1.79k
  struct args_value   *values = NULL;
2536
1.79k
  u_int        count = 0, idx;
2537
2538
1.79k
  memset(pr, 0, sizeof *pr);
2539
2540
1.79k
  if (cmd_parse_expand_alias(cmd, pi, pr))
2541
132
    return;
2542
2543
15.7k
  TAILQ_FOREACH(arg, &cmd->arguments, entry) {
2544
15.7k
    values = xrecallocarray(values, count, count + 1,
2545
15.7k
        sizeof *values);
2546
15.7k
    switch (arg->type) {
2547
15.4k
    case CMD_PARSE_STRING:
2548
15.4k
      values[count].type = ARGS_STRING;
2549
15.4k
      values[count].string = xstrdup(arg->string);
2550
15.4k
      break;
2551
289
    case CMD_PARSE_COMMANDS:
2552
289
      cmd_parse_build_commands(arg->commands, pi, pr);
2553
289
      if (pr->status != CMD_PARSE_SUCCESS)
2554
154
        goto out;
2555
135
      values[count].type = ARGS_COMMANDS;
2556
135
      values[count].cmdlist = pr->cmdlist;
2557
135
      break;
2558
0
    case CMD_PARSE_PARSED_COMMANDS:
2559
0
      values[count].type = ARGS_COMMANDS;
2560
0
      values[count].cmdlist = arg->cmdlist;
2561
0
      values[count].cmdlist->references++;
2562
0
      break;
2563
15.7k
    }
2564
15.6k
    count++;
2565
15.6k
  }
2566
2567
1.51k
  add = cmd_parse(values, count, pi->file, pi->line, pi->flags, &cause);
2568
1.51k
  if (add == NULL) {
2569
29
    pr->status = CMD_PARSE_ERROR;
2570
29
    pr->error = cmd_parse_get_error(pi->file, pi->line, cause);
2571
29
    free(cause);
2572
29
    goto out;
2573
29
  }
2574
1.48k
  pr->status = CMD_PARSE_SUCCESS;
2575
1.48k
  pr->cmdlist = cmd_list_new();
2576
1.48k
  cmd_list_append(pr->cmdlist, add);
2577
2578
1.66k
out:
2579
17.2k
  for (idx = 0; idx < count; idx++)
2580
15.6k
    args_free_value(&values[idx]);
2581
1.66k
  free(values);
2582
1.66k
}
2583
2584
static void
2585
cmd_parse_build_commands(struct cmd_parse_commands *cmds,
2586
    struct cmd_parse_input *pi, struct cmd_parse_result *pr)
2587
470
{
2588
470
  struct cmd_parse_command  *cmd;
2589
470
  u_int        line = UINT_MAX;
2590
470
  struct cmd_list     *current = NULL, *result;
2591
470
  char        *s;
2592
2593
470
  memset(pr, 0, sizeof *pr);
2594
2595
  /* Check for an empty list. */
2596
470
  if (TAILQ_EMPTY(cmds)) {
2597
135
    pr->status = CMD_PARSE_SUCCESS;
2598
135
    pr->cmdlist = cmd_list_new();
2599
135
    return;
2600
135
  }
2601
335
  cmd_parse_log_commands(cmds, __func__);
2602
2603
  /*
2604
   * Parse each command into a command list. Create a new command list
2605
   * for each line (unless the flag is set) so they get a new group (so
2606
   * the queue knows which ones to remove if a command fails when
2607
   * executed).
2608
   */
2609
335
  result = cmd_list_new();
2610
1.79k
  TAILQ_FOREACH(cmd, cmds, entry) {
2611
1.79k
    if (((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) {
2612
1.61k
      if (current != NULL) {
2613
1.28k
        cmd_parse_print_commands(pi, current);
2614
1.28k
        cmd_list_move(result, current);
2615
1.28k
        cmd_list_free(current);
2616
1.28k
      }
2617
1.61k
      current = cmd_list_new();
2618
1.61k
    }
2619
1.79k
    if (current == NULL)
2620
2
      current = cmd_list_new();
2621
1.79k
    line = pi->line = cmd->line;
2622
2623
1.79k
    cmd_parse_build_command(cmd, pi, pr);
2624
1.79k
    if (pr->status != CMD_PARSE_SUCCESS) {
2625
183
      cmd_list_free(result);
2626
183
      cmd_list_free(current);
2627
183
      return;
2628
183
    }
2629
1.61k
    cmd_list_append_all(current, pr->cmdlist);
2630
1.61k
    cmd_list_free(pr->cmdlist);
2631
1.61k
  }
2632
152
  if (current != NULL) {
2633
152
    cmd_parse_print_commands(pi, current);
2634
152
    cmd_list_move(result, current);
2635
152
    cmd_list_free(current);
2636
152
  }
2637
2638
152
  s = cmd_list_print(result, 0);
2639
152
  log_debug("%s: %s", __func__, s);
2640
152
  free(s);
2641
2642
152
  pr->status = CMD_PARSE_SUCCESS;
2643
152
  pr->cmdlist = result;
2644
152
}
2645
2646
struct cmd_parse_result *
2647
cmd_parse_from_file(FILE *f, struct cmd_parse_input *pi)
2648
0
{
2649
0
  static struct cmd_parse_result   pr;
2650
0
  struct cmd_parse_input     input;
2651
0
  struct cmd_parse_commands *cmds;
2652
0
  char        *cause;
2653
2654
0
  if (pi == NULL) {
2655
0
    memset(&input, 0, sizeof input);
2656
0
    pi = &input;
2657
0
  }
2658
0
  memset(&pr, 0, sizeof pr);
2659
2660
0
  cmds = cmd_parse_do_file(f, pi, &cause);
2661
0
  if (cmds == NULL) {
2662
0
    pr.status = CMD_PARSE_ERROR;
2663
0
    pr.error = cause;
2664
0
    return (&pr);
2665
0
  }
2666
0
  cmd_parse_build_commands(cmds, pi, &pr);
2667
0
  cmd_parse_free_commands(cmds);
2668
0
  return (&pr);
2669
2670
0
}
2671
2672
struct cmd_parse_result *
2673
cmd_parse_from_string(const char *s, struct cmd_parse_input *pi)
2674
2
{
2675
2
  struct cmd_parse_input  input;
2676
2677
2
  if (pi == NULL) {
2678
2
    memset(&input, 0, sizeof input);
2679
2
    pi = &input;
2680
2
  }
2681
2682
  /*
2683
   * When parsing a string, put commands in one group even if there are
2684
   * multiple lines. This means { a \n b } is identical to "a ; b" when
2685
   * given as an argument to another command.
2686
   */
2687
2
  pi->flags |= CMD_PARSE_ONEGROUP;
2688
2
  return (cmd_parse_from_buffer(s, strlen(s), pi));
2689
2
}
2690
2691
enum cmd_parse_status
2692
cmd_parse_and_insert(const char *s, struct cmd_parse_input *pi,
2693
    struct cmdq_item *after, struct cmdq_state *state, char **error)
2694
0
{
2695
0
  struct cmd_parse_result *pr;
2696
0
  struct cmdq_item  *item;
2697
2698
0
  pr = cmd_parse_from_string(s, pi);
2699
0
  switch (pr->status) {
2700
0
  case CMD_PARSE_ERROR:
2701
0
    if (error != NULL)
2702
0
      *error = pr->error;
2703
0
    else
2704
0
      free(pr->error);
2705
0
    break;
2706
0
  case CMD_PARSE_SUCCESS:
2707
0
    item = cmdq_get_command(pr->cmdlist, state);
2708
0
    cmdq_insert_after(after, item);
2709
0
    cmd_list_free(pr->cmdlist);
2710
0
    break;
2711
0
  }
2712
0
  return (pr->status);
2713
0
}
2714
2715
enum cmd_parse_status
2716
cmd_parse_and_append(const char *s, struct cmd_parse_input *pi,
2717
    struct client *c, struct cmdq_state *state, char **error)
2718
0
{
2719
0
  struct cmd_parse_result *pr;
2720
0
  struct cmdq_item  *item;
2721
2722
0
  pr = cmd_parse_from_string(s, pi);
2723
0
  switch (pr->status) {
2724
0
  case CMD_PARSE_ERROR:
2725
0
    if (error != NULL)
2726
0
      *error = pr->error;
2727
0
    else
2728
0
      free(pr->error);
2729
0
    break;
2730
0
  case CMD_PARSE_SUCCESS:
2731
0
    item = cmdq_get_command(pr->cmdlist, state);
2732
0
    cmdq_append(c, item);
2733
0
    cmd_list_free(pr->cmdlist);
2734
0
    break;
2735
0
  }
2736
0
  return (pr->status);
2737
0
}
2738
2739
struct cmd_parse_result *
2740
cmd_parse_from_buffer(const void *buf, size_t len, struct cmd_parse_input *pi)
2741
239
{
2742
239
  static struct cmd_parse_result   pr;
2743
239
  struct cmd_parse_input     input;
2744
239
  struct cmd_parse_commands *cmds;
2745
239
  char        *cause;
2746
2747
239
  if (pi == NULL) {
2748
0
    memset(&input, 0, sizeof input);
2749
0
    pi = &input;
2750
0
  }
2751
239
  memset(&pr, 0, sizeof pr);
2752
2753
239
  if (len == 0) {
2754
0
    pr.status = CMD_PARSE_SUCCESS;
2755
0
    pr.cmdlist = cmd_list_new();
2756
0
    return (&pr);
2757
0
  }
2758
2759
239
  cmds = cmd_parse_do_buffer(buf, len, pi, &cause);
2760
239
  if (cmds == NULL) {
2761
190
    pr.status = CMD_PARSE_ERROR;
2762
190
    pr.error = cause;
2763
190
    return (&pr);
2764
190
  }
2765
49
  cmd_parse_build_commands(cmds, pi, &pr);
2766
49
  cmd_parse_free_commands(cmds);
2767
49
  return (&pr);
2768
239
}
2769
2770
struct cmd_parse_result *
2771
cmd_parse_from_arguments(struct args_value *values, u_int count,
2772
    struct cmd_parse_input *pi)
2773
0
{
2774
0
  static struct cmd_parse_result   pr;
2775
0
  struct cmd_parse_input     input;
2776
0
  struct cmd_parse_commands *cmds;
2777
0
  struct cmd_parse_command  *cmd;
2778
0
  struct cmd_parse_argument *arg;
2779
0
  u_int        i;
2780
0
  char        *copy;
2781
0
  size_t         size;
2782
0
  int        end;
2783
2784
  /*
2785
   * The commands are already split up into arguments, so just separate
2786
   * into a set of commands by ';'.
2787
   */
2788
2789
0
  if (pi == NULL) {
2790
0
    memset(&input, 0, sizeof input);
2791
0
    pi = &input;
2792
0
  }
2793
0
  memset(&pr, 0, sizeof pr);
2794
2795
0
  cmds = cmd_parse_new_commands();
2796
2797
0
  cmd = xcalloc(1, sizeof *cmd);
2798
0
  cmd->line = pi->line;
2799
0
  TAILQ_INIT(&cmd->arguments);
2800
2801
0
  for (i = 0; i < count; i++) {
2802
0
    end = 0;
2803
0
    if (values[i].type == ARGS_STRING) {
2804
0
      copy = xstrdup(values[i].string);
2805
0
      size = strlen(copy);
2806
0
      if (size != 0 && copy[size - 1] == ';') {
2807
0
        copy[--size] = '\0';
2808
0
        if (size > 0 && copy[size - 1] == '\\')
2809
0
          copy[size - 1] = ';';
2810
0
        else
2811
0
          end = 1;
2812
0
      }
2813
0
      if (!end || size != 0) {
2814
0
        arg = xcalloc(1, sizeof *arg);
2815
0
        arg->type = CMD_PARSE_STRING;
2816
0
        arg->string = copy;
2817
0
        TAILQ_INSERT_TAIL(&cmd->arguments, arg, entry);
2818
0
      } else
2819
0
        free(copy);
2820
0
    } else if (values[i].type == ARGS_COMMANDS) {
2821
0
      arg = xcalloc(1, sizeof *arg);
2822
0
      arg->type = CMD_PARSE_PARSED_COMMANDS;
2823
0
      arg->cmdlist = values[i].cmdlist;
2824
0
      arg->cmdlist->references++;
2825
0
      TAILQ_INSERT_TAIL(&cmd->arguments, arg, entry);
2826
0
    } else
2827
0
      fatalx("unknown argument type");
2828
0
    if (end) {
2829
0
      TAILQ_INSERT_TAIL(cmds, cmd, entry);
2830
0
      cmd = xcalloc(1, sizeof *cmd);
2831
0
      cmd->line = pi->line;
2832
0
      TAILQ_INIT(&cmd->arguments);
2833
0
    }
2834
0
  }
2835
0
  if (!TAILQ_EMPTY(&cmd->arguments))
2836
0
    TAILQ_INSERT_TAIL(cmds, cmd, entry);
2837
0
  else
2838
0
    free(cmd);
2839
2840
0
  cmd_parse_build_commands(cmds, pi, &pr);
2841
0
  cmd_parse_free_commands(cmds);
2842
0
  return (&pr);
2843
0
}
2844
2845
static void printflike(1, 2)
2846
yyerror(const char *fmt, ...)
2847
190
{
2848
190
  struct cmd_parse_state  *ps = &parse_state;
2849
190
  struct cmd_parse_input  *pi = ps->input;
2850
190
  va_list      ap;
2851
190
  char      *error;
2852
2853
190
  if (ps->error != NULL)
2854
0
    return;
2855
2856
190
  va_start(ap, fmt);
2857
190
  xvasprintf(&error, fmt, ap);
2858
190
  va_end(ap);
2859
2860
190
  ps->error = cmd_parse_get_error(pi->file, pi->line, error);
2861
190
  free(error);
2862
190
}
2863
2864
static int
2865
yylex_is_var(char ch, int first)
2866
251k
{
2867
251k
  if (ch == '=')
2868
1.74k
    return (0);
2869
249k
  if (first && isdigit((u_char)ch))
2870
242
    return (0);
2871
249k
  return (isalnum((u_char)ch) || ch == '_');
2872
249k
}
2873
2874
static void
2875
yylex_append(char **buf, size_t *len, const char *add, size_t addlen)
2876
311k
{
2877
311k
  if (addlen > SIZE_MAX - 1 || *len > SIZE_MAX - 1 - addlen)
2878
0
    fatalx("buffer is too big");
2879
311k
  *buf = xrealloc(*buf, (*len) + 1 + addlen);
2880
311k
  memcpy((*buf) + *len, add, addlen);
2881
311k
  (*len) += addlen;
2882
311k
}
2883
2884
static void
2885
yylex_append1(char **buf, size_t *len, char add)
2886
305k
{
2887
305k
  yylex_append(buf, len, &add, 1);
2888
305k
}
2889
2890
static int
2891
yylex_getc1(void)
2892
404k
{
2893
404k
  struct cmd_parse_state  *ps = &parse_state;
2894
404k
  int      ch;
2895
2896
404k
  if (ps->f != NULL)
2897
0
    ch = getc(ps->f);
2898
404k
  else {
2899
404k
    if (ps->off == ps->len)
2900
784
      ch = EOF;
2901
403k
    else
2902
403k
      ch = ps->buf[ps->off++];
2903
404k
  }
2904
404k
  return (ch);
2905
404k
}
2906
2907
static void
2908
yylex_ungetc(int ch)
2909
43.0k
{
2910
43.0k
  struct cmd_parse_state  *ps = &parse_state;
2911
2912
43.0k
  if (ps->f != NULL)
2913
0
    ungetc(ch, ps->f);
2914
43.0k
  else if (ps->off > 0 && ch != EOF)
2915
34.7k
    ps->off--;
2916
43.0k
}
2917
2918
static int
2919
yylex_getc(void)
2920
403k
{
2921
403k
  struct cmd_parse_state  *ps = &parse_state;
2922
403k
  int      ch;
2923
2924
403k
  if (ps->escapes != 0) {
2925
8.21k
    ps->escapes--;
2926
8.21k
    return ('\\');
2927
8.21k
  }
2928
404k
  for (;;) {
2929
404k
    ch = yylex_getc1();
2930
404k
    if (ch == '\\') {
2931
9.18k
      ps->escapes++;
2932
9.18k
      continue;
2933
9.18k
    }
2934
395k
    if (ch == '\n' && (ps->escapes % 2) == 1) {
2935
22
      ps->input->line++;
2936
22
      ps->escapes--;
2937
22
      continue;
2938
22
    }
2939
2940
395k
    if (ps->escapes != 0) {
2941
953
      yylex_ungetc(ch);
2942
953
      ps->escapes--;
2943
953
      return ('\\');
2944
953
    }
2945
394k
    return (ch);
2946
395k
  }
2947
395k
}
2948
2949
static char *
2950
yylex_get_word(int ch)
2951
9.48k
{
2952
9.48k
  char  *buf;
2953
9.48k
  size_t   len;
2954
2955
9.48k
  len = 0;
2956
9.48k
  buf = xmalloc(1);
2957
2958
9.48k
  do
2959
34.1k
    yylex_append1(&buf, &len, ch);
2960
34.1k
  while ((ch = yylex_getc()) != EOF && strchr(" \t\n", ch) == NULL);
2961
9.48k
  yylex_ungetc(ch);
2962
2963
9.48k
  buf[len] = '\0';
2964
9.48k
  log_debug("%s: %s", __func__, buf);
2965
9.48k
  return (buf);
2966
9.48k
}
2967
2968
static int
2969
yylex(void)
2970
52.4k
{
2971
52.4k
  struct cmd_parse_state  *ps = &parse_state;
2972
52.4k
  char      *token, *cp;
2973
52.4k
  int      ch, next, condition;
2974
2975
52.4k
  if (ps->eol)
2976
12.1k
    ps->input->line++;
2977
52.4k
  ps->eol = 0;
2978
2979
52.4k
  condition = ps->condition;
2980
52.4k
  ps->condition = 0;
2981
2982
67.4k
  for (;;) {
2983
67.4k
    ch = yylex_getc();
2984
2985
67.4k
    if (ch == EOF) {
2986
      /*
2987
       * Ensure every file or string is terminated by a
2988
       * newline. This keeps the parser simpler and avoids
2989
       * having to add a newline to each string.
2990
       */
2991
540
      if (ps->eof)
2992
261
        break;
2993
279
      ps->eof = 1;
2994
279
      return ('\n');
2995
540
    }
2996
2997
66.9k
    if (ch == ' ' || ch == '\t') {
2998
      /*
2999
       * Ignore whitespace.
3000
       */
3001
14.7k
      continue;
3002
14.7k
    }
3003
3004
52.1k
    if (ch == '\r') {
3005
      /*
3006
       * Treat \r\n as \n.
3007
       */
3008
46
      ch = yylex_getc();
3009
46
      if (ch != '\n') {
3010
46
        yylex_ungetc(ch);
3011
46
        ch = '\r';
3012
46
      }
3013
46
    }
3014
52.1k
    if (ch == '\n') {
3015
      /*
3016
       * End of line. Update the line number.
3017
       */
3018
12.1k
      ps->eol = 1;
3019
12.1k
      return ('\n');
3020
12.1k
    }
3021
3022
39.9k
    if (ch == ';' || ch == '{' || ch == '}') {
3023
      /*
3024
       * A semicolon or { or } is itself.
3025
       */
3026
4.83k
      return (ch);
3027
4.83k
    }
3028
3029
35.1k
    if (ch == '#') {
3030
      /*
3031
       * #{ after a condition opens a format; anything else
3032
       * is a comment, ignore up to the end of the line.
3033
       */
3034
642
      next = yylex_getc();
3035
642
      if (condition && next == '{') {
3036
368
        yylval.token = yylex_format();
3037
368
        if (yylval.token == NULL)
3038
1
          return (ERROR);
3039
367
        return (FORMAT);
3040
368
      }
3041
3.97k
      while (next != '\n' && next != EOF)
3042
3.70k
        next = yylex_getc();
3043
274
      if (next == '\n') {
3044
28
        ps->input->line++;
3045
28
        return ('\n');
3046
28
      }
3047
246
      continue;
3048
274
    }
3049
3050
34.5k
    if (ch == '%') {
3051
      /*
3052
       * % is a condition unless it is all % or all numbers,
3053
       * then it is a token.
3054
       */
3055
9.48k
      yylval.token = yylex_get_word('%');
3056
18.9k
      for (cp = yylval.token; *cp != '\0'; cp++) {
3057
15.6k
        if (*cp != '%' && !isdigit((u_char)*cp))
3058
6.16k
          break;
3059
15.6k
      }
3060
9.48k
      if (*cp == '\0')
3061
3.31k
        return (TOKEN);
3062
6.16k
      ps->condition = 1;
3063
6.16k
      if (strcmp(yylval.token, "%hidden") == 0) {
3064
262
        free(yylval.token);
3065
262
        return (HIDDEN);
3066
262
      }
3067
5.90k
      if (strcmp(yylval.token, "%if") == 0) {
3068
2.12k
        free(yylval.token);
3069
2.12k
        return (IF);
3070
2.12k
      }
3071
3.78k
      if (strcmp(yylval.token, "%else") == 0) {
3072
560
        free(yylval.token);
3073
560
        return (ELSE);
3074
560
      }
3075
3.22k
      if (strcmp(yylval.token, "%elif") == 0) {
3076
1.61k
        free(yylval.token);
3077
1.61k
        return (ELIF);
3078
1.61k
      }
3079
1.60k
      if (strcmp(yylval.token, "%endif") == 0) {
3080
1.58k
        free(yylval.token);
3081
1.58k
        return (ENDIF);
3082
1.58k
      }
3083
23
      free(yylval.token);
3084
23
      return (ERROR);
3085
1.60k
    }
3086
3087
    /*
3088
     * Otherwise this is a token.
3089
     */
3090
25.0k
    token = yylex_token(ch);
3091
25.0k
    if (token == NULL)
3092
5
      return (ERROR);
3093
25.0k
    yylval.token = token;
3094
3095
25.0k
    if (strchr(token, '=') != NULL && yylex_is_var(*token, 1)) {
3096
239k
      for (cp = token + 1; *cp != '='; cp++) {
3097
238k
        if (!yylex_is_var(*cp, 0))
3098
101
          break;
3099
238k
      }
3100
1.82k
      if (*cp == '=')
3101
1.72k
        return (EQUALS);
3102
1.82k
    }
3103
23.2k
    return (TOKEN);
3104
25.0k
  }
3105
261
  return (0);
3106
52.4k
}
3107
3108
static char *
3109
yylex_format(void)
3110
368
{
3111
368
  char  *buf;
3112
368
  size_t   len;
3113
368
  int  ch, brackets = 1;
3114
3115
368
  len = 0;
3116
368
  buf = xmalloc(1);
3117
3118
368
  yylex_append(&buf, &len, "#{", 2);
3119
96.7k
  for (;;) {
3120
96.7k
    if ((ch = yylex_getc()) == EOF || ch == '\n')
3121
1
      goto error;
3122
96.7k
    if (ch == '#') {
3123
6.19k
      if ((ch = yylex_getc()) == EOF || ch == '\n')
3124
0
        goto error;
3125
6.19k
      if (ch == '{')
3126
1.39k
        brackets++;
3127
6.19k
      yylex_append1(&buf, &len, '#');
3128
90.5k
    } else if (ch == '}') {
3129
1.25k
      if (brackets != 0 && --brackets == 0) {
3130
367
        yylex_append1(&buf, &len, ch);
3131
367
        break;
3132
367
      }
3133
1.25k
    }
3134
96.4k
    yylex_append1(&buf, &len, ch);
3135
96.4k
  }
3136
367
  if (brackets != 0)
3137
0
    goto error;
3138
3139
367
  buf[len] = '\0';
3140
367
  log_debug("%s: %s", __func__, buf);
3141
367
  return (buf);
3142
3143
1
error:
3144
1
  free(buf);
3145
1
  return (NULL);
3146
367
}
3147
3148
static int
3149
yylex_token_escape(char **buf, size_t *len)
3150
4.47k
{
3151
4.47k
  int  ch, type, o2, o3, mlen;
3152
4.47k
  u_int  size, i, tmp;
3153
4.47k
  char   s[9], m[MB_LEN_MAX];
3154
3155
4.47k
  ch = yylex_getc();
3156
3157
4.47k
  if (ch >= '4' && ch <= '7') {
3158
0
    yyerror("invalid octal escape");
3159
0
    return (0);
3160
0
  }
3161
4.47k
  if (ch >= '0' && ch <= '3') {
3162
0
    o2 = yylex_getc();
3163
0
    if (o2 >= '0' && o2 <= '7') {
3164
0
      o3 = yylex_getc();
3165
0
      if (o3 >= '0' && o3 <= '7') {
3166
0
        ch = 64 * (ch - '0') +
3167
0
              8 * (o2 - '0') +
3168
0
            (o3 - '0');
3169
0
        yylex_append1(buf, len, ch);
3170
0
        return (1);
3171
0
      }
3172
0
    }
3173
0
    yyerror("invalid octal escape");
3174
0
    return (0);
3175
0
  }
3176
3177
4.47k
  switch (ch) {
3178
2
  case EOF:
3179
2
    return (0);
3180
48
  case 'a':
3181
48
    ch = '\a';
3182
48
    break;
3183
0
  case 'b':
3184
0
    ch = '\b';
3185
0
    break;
3186
3
  case 'e':
3187
3
    ch = '\033';
3188
3
    break;
3189
78
  case 'f':
3190
78
    ch = '\f';
3191
78
    break;
3192
4
  case 's':
3193
4
    ch = ' ';
3194
4
    break;
3195
19
  case 'v':
3196
19
    ch = '\v';
3197
19
    break;
3198
38
  case 'r':
3199
38
    ch = '\r';
3200
38
    break;
3201
0
  case 'n':
3202
0
    ch = '\n';
3203
0
    break;
3204
56
  case 't':
3205
56
    ch = '\t';
3206
56
    break;
3207
11
  case 'u':
3208
11
    type = 'u';
3209
11
    size = 4;
3210
11
    goto unicode;
3211
0
  case 'U':
3212
0
    type = 'U';
3213
0
    size = 8;
3214
0
    goto unicode;
3215
4.47k
  }
3216
3217
4.46k
  yylex_append1(buf, len, ch);
3218
4.46k
  return (1);
3219
3220
11
unicode:
3221
55
  for (i = 0; i < size; i++) {
3222
44
    ch = yylex_getc();
3223
44
    if (ch == EOF || ch == '\n')
3224
0
      return (0);
3225
44
    if (!isxdigit((u_char)ch)) {
3226
0
      yyerror("invalid \\%c argument", type);
3227
0
      return (0);
3228
0
    }
3229
44
    s[i] = ch;
3230
44
  }
3231
11
  s[i] = '\0';
3232
3233
11
  if ((size == 4 && sscanf(s, "%4x", &tmp) != 1) ||
3234
11
      (size == 8 && sscanf(s, "%8x", &tmp) != 1)) {
3235
0
    yyerror("invalid \\%c argument", type);
3236
0
    return (0);
3237
0
  }
3238
11
  mlen = wctomb(m, tmp);
3239
11
  if (mlen <= 0 || mlen > (int)sizeof m) {
3240
0
    yyerror("invalid \\%c argument", type);
3241
0
    return (0);
3242
0
  }
3243
11
  yylex_append(buf, len, m, mlen);
3244
11
  return (1);
3245
11
}
3246
3247
static int
3248
yylex_token_variable(char **buf, size_t *len)
3249
5.74k
{
3250
5.74k
  struct environ_entry  *envent;
3251
5.74k
  int      ch, brackets = 0;
3252
5.74k
  char       name[1024];
3253
5.74k
  size_t       namelen = 0;
3254
5.74k
  const char    *value;
3255
3256
5.74k
  ch = yylex_getc();
3257
5.74k
  if (ch == EOF)
3258
2
    return (0);
3259
5.73k
  if (ch == '{')
3260
0
    brackets = 1;
3261
5.73k
  else {
3262
5.73k
    if (!yylex_is_var(ch, 1)) {
3263
1.60k
      yylex_append1(buf, len, '$');
3264
1.60k
      yylex_ungetc(ch);
3265
1.60k
      return (1);
3266
1.60k
    }
3267
4.13k
    name[namelen++] = ch;
3268
4.13k
  }
3269
3270
5.16k
  for (;;) {
3271
5.16k
    ch = yylex_getc();
3272
5.16k
    if (brackets && ch == '}')
3273
0
      break;
3274
5.16k
    if (ch == EOF || !yylex_is_var(ch, 0)) {
3275
4.13k
      if (!brackets) {
3276
4.13k
        yylex_ungetc(ch);
3277
4.13k
        break;
3278
4.13k
      }
3279
0
      yyerror("invalid environment variable");
3280
0
      return (0);
3281
4.13k
    }
3282
1.02k
    if (namelen == (sizeof name) - 2) {
3283
0
      yyerror("environment variable is too long");
3284
0
      return (0);
3285
0
    }
3286
1.02k
    name[namelen++] = ch;
3287
1.02k
  }
3288
4.13k
  name[namelen] = '\0';
3289
3290
4.13k
  envent = environ_find(global_environ, name);
3291
4.13k
  if (envent != NULL && envent->value != NULL) {
3292
3.71k
    value = envent->value;
3293
3.71k
    log_debug("%s: %s -> %s", __func__, name, value);
3294
3.71k
    yylex_append(buf, len, value, strlen(value));
3295
3.71k
  }
3296
4.13k
  return (1);
3297
4.13k
}
3298
3299
static int
3300
yylex_token_tilde(char **buf, size_t *len)
3301
1.13k
{
3302
1.13k
  struct environ_entry  *envent;
3303
1.13k
  int      ch;
3304
1.13k
  char       name[1024];
3305
1.13k
  size_t       namelen = 0;
3306
1.13k
  struct passwd   *pw;
3307
1.13k
  const char    *home = NULL;
3308
3309
1.85k
  for (;;) {
3310
1.85k
    ch = yylex_getc();
3311
1.85k
    if (ch == EOF || strchr("/ \t\n\"'", ch) != NULL) {
3312
1.13k
      yylex_ungetc(ch);
3313
1.13k
      break;
3314
1.13k
    }
3315
722
    if (namelen == (sizeof name) - 2) {
3316
0
      yyerror("user name is too long");
3317
0
      return (0);
3318
0
    }
3319
722
    name[namelen++] = ch;
3320
722
  }
3321
1.13k
  name[namelen] = '\0';
3322
3323
1.13k
  if (*name == '\0') {
3324
1.00k
    envent = environ_find(global_environ, "HOME");
3325
1.00k
    if (envent != NULL &&
3326
0
        envent->value != NULL &&
3327
0
        *envent->value != '\0')
3328
0
      home = envent->value;
3329
1.00k
    else if ((pw = getpwuid(getuid())) != NULL)
3330
1.00k
      home = pw->pw_dir;
3331
1.00k
  } else {
3332
130
    if ((pw = getpwnam(name)) != NULL)
3333
129
      home = pw->pw_dir;
3334
130
  }
3335
1.13k
  if (home == NULL)
3336
1
    return (0);
3337
3338
1.13k
  log_debug("%s: ~%s -> %s", __func__, name, home);
3339
1.13k
  yylex_append(buf, len, home, strlen(home));
3340
1.13k
  return (1);
3341
1.13k
}
3342
3343
static char *
3344
yylex_token(int ch)
3345
25.0k
{
3346
25.0k
  struct cmd_parse_state  *ps = &parse_state;
3347
25.0k
  char      *buf;
3348
25.0k
  size_t       len;
3349
25.0k
  enum { START,
3350
25.0k
         NONE,
3351
25.0k
         DOUBLE_QUOTES,
3352
25.0k
         SINGLE_QUOTES }   state = NONE, last = START;
3353
3354
25.0k
  len = 0;
3355
25.0k
  buf = xmalloc(1);
3356
3357
201k
  for (;;) {
3358
    /* EOF or \n are always the end of the token. */
3359
201k
    if (ch == EOF) {
3360
6.20k
      log_debug("%s: end at EOF", __func__);
3361
6.20k
      break;
3362
6.20k
    }
3363
194k
    if (state == NONE && ch == '\r') {
3364
363
      ch = yylex_getc();
3365
363
      if (ch != '\n') {
3366
335
        yylex_ungetc(ch);
3367
335
        ch = '\r';
3368
335
      }
3369
363
    }
3370
194k
    if (ch == '\n') {
3371
6.79k
      if (state == NONE) {
3372
6.14k
        log_debug("%s: end at EOL", __func__);
3373
6.14k
        break;
3374
6.14k
      }
3375
652
      ps->input->line++;
3376
652
    }
3377
3378
    /* Whitespace or ; or } ends a token unless inside quotes. */
3379
188k
    if (state == NONE && (ch == ' ' || ch == '\t')) {
3380
10.1k
      log_debug("%s: end at WS", __func__);
3381
10.1k
      break;
3382
10.1k
    }
3383
178k
    if (state == NONE && (ch == ';' || ch == '}')) {
3384
2.55k
      log_debug("%s: end at %c", __func__, ch);
3385
2.55k
      break;
3386
2.55k
    }
3387
3388
    /*
3389
     * Spaces and comments inside quotes after \n are removed but
3390
     * the \n is left.
3391
     */
3392
176k
    if (ch == '\n' && state != NONE) {
3393
652
      yylex_append1(&buf, &len, '\n');
3394
652
      while ((ch = yylex_getc()) == ' ' || ch == '\t')
3395
0
        /* nothing */;
3396
652
      if (ch != '#')
3397
226
        continue;
3398
426
      ch = yylex_getc();
3399
426
      if (strchr(",#{}:", ch) != NULL) {
3400
386
        yylex_ungetc(ch);
3401
386
        ch = '#';
3402
386
      } else {
3403
224
        while ((ch = yylex_getc()) != '\n' && ch != EOF)
3404
184
          /* nothing */;
3405
40
      }
3406
426
      continue;
3407
652
    }
3408
3409
    /* \ ~ and $ are expanded except in single quotes. */
3410
175k
    if (ch == '\\' && state != SINGLE_QUOTES) {
3411
4.47k
      if (!yylex_token_escape(&buf, &len))
3412
2
        goto error;
3413
4.47k
      goto skip;
3414
4.47k
    }
3415
170k
    if (ch == '~' && last != state && state != SINGLE_QUOTES) {
3416
1.13k
      if (!yylex_token_tilde(&buf, &len))
3417
1
        goto error;
3418
1.13k
      goto skip;
3419
1.13k
    }
3420
169k
    if (ch == '$' && state != SINGLE_QUOTES) {
3421
5.74k
      if (!yylex_token_variable(&buf, &len))
3422
2
        goto error;
3423
5.73k
      goto skip;
3424
5.74k
    }
3425
164k
    if (ch == '}' && state == NONE)
3426
0
      goto error;  /* unmatched (matched ones were handled) */
3427
3428
    /* ' and " starts or end quotes (and is consumed). */
3429
164k
    if (ch == '\'') {
3430
429
      if (state == NONE) {
3431
75
        state = SINGLE_QUOTES;
3432
75
        goto next;
3433
75
      }
3434
354
      if (state == SINGLE_QUOTES) {
3435
45
        state = NONE;
3436
45
        goto next;
3437
45
      }
3438
354
    }
3439
163k
    if (ch == '"') {
3440
2.14k
      if (state == NONE) {
3441
1.02k
        state = DOUBLE_QUOTES;
3442
1.02k
        goto next;
3443
1.02k
      }
3444
1.12k
      if (state == DOUBLE_QUOTES) {
3445
882
        state = NONE;
3446
882
        goto next;
3447
882
      }
3448
1.12k
    }
3449
3450
    /* Otherwise add the character to the buffer. */
3451
162k
    yylex_append1(&buf, &len, ch);
3452
3453
173k
  skip:
3454
173k
    last = state;
3455
3456
175k
  next:
3457
175k
    ch = yylex_getc();
3458
175k
  }
3459
25.0k
  yylex_ungetc(ch);
3460
3461
25.0k
  buf[len] = '\0';
3462
25.0k
  log_debug("%s: %s", __func__, buf);
3463
25.0k
  return (buf);
3464
3465
5
error:
3466
5
  free(buf);
3467
  return (NULL);
3468
25.0k
}