Coverage Report

Created: 2026-09-01 06:30

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
2.56k
#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
171k
#   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
44
#define ERROR 258
211
394
#define HIDDEN 259
212
1.84k
#define IF 260
213
648
#define ELSE 261
214
2.03k
#define ELIF 262
215
1.23k
#define ENDIF 263
216
271
#define FORMAT 264
217
29.6k
#define TOKEN 265
218
2.58k
#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
496
#  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
324
#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
121
#  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
8.20k
# 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
170k
#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
54
#  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
54
#   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
108
# 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
108
    do                                                                  \
522
108
      {                                                                 \
523
108
        YYPTRDIFF_T yynewbytes;                                         \
524
108
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
525
108
        Stack = &yyptr->Stack_alloc;                                    \
526
108
        yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
527
108
        yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
528
108
      }                                                                 \
529
108
    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
108
      __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
170k
#define YYFINAL  20
555
/* YYLAST -- Last index in YYTABLE.  */
556
301k
#define YYLAST   104
557
558
/* YYNTOKENS -- Number of terminals.  */
559
110k
#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
93.1k
#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
93.3k
  (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
174k
#define YYPACT_NINF (-32)
647
648
#define yypact_value_is_default(Yyn) \
649
174k
  ((Yyn) == YYPACT_NINF)
650
651
#define YYTABLE_NINF (-15)
652
653
#define yytable_value_is_error(Yyn) \
654
9.46k
  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
153k
#define YYEMPTY         (-2)
772
93.8k
#define YYEOF           0
773
774
203
#define YYACCEPT        goto yyacceptlab
775
131
#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
7.37k
#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
334
# 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
108
# 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
4.10k
{
1192
4.10k
  YYUSE (yyvaluep);
1193
4.10k
  if (!yymsg)
1194
0
    yymsg = "Deleting";
1195
4.10k
  YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1196
1197
4.10k
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1198
4.10k
  YYUSE (yytype);
1199
4.10k
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1200
4.10k
}
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
334
{
1221
334
    yy_state_fast_t yystate;
1222
    /* Number of tokens to shift before error messages enabled.  */
1223
334
    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
334
    yy_state_t yyssa[YYINITDEPTH];
1234
334
    yy_state_t *yyss;
1235
334
    yy_state_t *yyssp;
1236
1237
    /* The semantic value stack.  */
1238
334
    YYSTYPE yyvsa[YYINITDEPTH];
1239
334
    YYSTYPE *yyvs;
1240
334
    YYSTYPE *yyvsp;
1241
1242
334
    YYPTRDIFF_T yystacksize;
1243
1244
334
  int yyn;
1245
334
  int yyresult;
1246
  /* Lookahead token as an internal (translated) token number.  */
1247
334
  int yytoken = 0;
1248
  /* The variables used to return semantic value and location from the
1249
     action routines.  */
1250
334
  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
115k
#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
334
  int yylen = 0;
1264
1265
334
  yyssp = yyss = yyssa;
1266
334
  yyvsp = yyvs = yyvsa;
1267
334
  yystacksize = YYINITDEPTH;
1268
1269
334
  YYDPRINTF ((stderr, "Starting parse\n"));
1270
1271
334
  yystate = 0;
1272
334
  yyerrstatus = 0;
1273
334
  yynerrs = 0;
1274
334
  yychar = YYEMPTY; /* Cause a token to be read.  */
1275
334
  goto yysetstate;
1276
1277
1278
/*------------------------------------------------------------.
1279
| yynewstate -- push a new state, which is found in yystate.  |
1280
`------------------------------------------------------------*/
1281
170k
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
170k
  yyssp++;
1285
1286
1287
/*--------------------------------------------------------------------.
1288
| yysetstate -- set current state (the top of the stack) to yystate.  |
1289
`--------------------------------------------------------------------*/
1290
170k
yysetstate:
1291
170k
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1292
170k
  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
1293
170k
  YY_IGNORE_USELESS_CAST_BEGIN
1294
170k
  *yyssp = YY_CAST (yy_state_t, yystate);
1295
170k
  YY_IGNORE_USELESS_CAST_END
1296
1297
170k
  if (yyss + yystacksize - 1 <= yyssp)
1298
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
1299
    goto yyexhaustedlab;
1300
#else
1301
54
    {
1302
      /* Get the current used size of the three stacks, in elements.  */
1303
54
      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
54
      if (YYMAXDEPTH <= yystacksize)
1327
0
        goto yyexhaustedlab;
1328
54
      yystacksize *= 2;
1329
54
      if (YYMAXDEPTH < yystacksize)
1330
0
        yystacksize = YYMAXDEPTH;
1331
1332
54
      {
1333
54
        yy_state_t *yyss1 = yyss;
1334
54
        union yyalloc *yyptr =
1335
54
          YY_CAST (union yyalloc *,
1336
54
                   YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
1337
54
        if (! yyptr)
1338
0
          goto yyexhaustedlab;
1339
54
        YYSTACK_RELOCATE (yyss_alloc, yyss);
1340
54
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1341
54
# undef YYSTACK_RELOCATE
1342
54
        if (yyss1 != yyssa)
1343
27
          YYSTACK_FREE (yyss1);
1344
54
      }
1345
0
# endif
1346
1347
0
      yyssp = yyss + yysize - 1;
1348
54
      yyvsp = yyvs + yysize - 1;
1349
1350
54
      YY_IGNORE_USELESS_CAST_BEGIN
1351
54
      YYDPRINTF ((stderr, "Stack size increased to %ld\n",
1352
54
                  YY_CAST (long, yystacksize)));
1353
54
      YY_IGNORE_USELESS_CAST_END
1354
1355
54
      if (yyss + yystacksize - 1 <= yyssp)
1356
0
        YYABORT;
1357
54
    }
1358
170k
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1359
1360
170k
  if (yystate == YYFINAL)
1361
203
    YYACCEPT;
1362
1363
170k
  goto yybackup;
1364
1365
1366
/*-----------.
1367
| yybackup.  |
1368
`-----------*/
1369
170k
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
170k
  yyn = yypact[yystate];
1375
170k
  if (yypact_value_is_default (yyn))
1376
76.9k
    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
93.4k
  if (yychar == YYEMPTY)
1382
59.4k
    {
1383
59.4k
      YYDPRINTF ((stderr, "Reading a token: "));
1384
59.4k
      yychar = yylex ();
1385
59.4k
    }
1386
1387
93.4k
  if (yychar <= YYEOF)
1388
477
    {
1389
477
      yychar = yytoken = YYEOF;
1390
477
      YYDPRINTF ((stderr, "Now at end of input.\n"));
1391
477
    }
1392
92.9k
  else
1393
92.9k
    {
1394
92.9k
      yytoken = YYTRANSLATE (yychar);
1395
92.9k
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1396
92.9k
    }
1397
1398
  /* If the proper action on seeing token YYTOKEN is to reduce or to
1399
     detect an error, take that action.  */
1400
93.4k
  yyn += yytoken;
1401
93.4k
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1402
24.6k
    goto yydefault;
1403
68.7k
  yyn = yytable[yyn];
1404
68.7k
  if (yyn <= 0)
1405
9.46k
    {
1406
9.46k
      if (yytable_value_is_error (yyn))
1407
0
        goto yyerrlab;
1408
9.46k
      yyn = -yyn;
1409
9.46k
      goto yyreduce;
1410
9.46k
    }
1411
1412
  /* Count tokens shifted since error; after three, turn off error
1413
     status.  */
1414
59.2k
  if (yyerrstatus)
1415
0
    yyerrstatus--;
1416
1417
  /* Shift the lookahead token.  */
1418
59.2k
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1419
59.2k
  yystate = yyn;
1420
59.2k
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1421
59.2k
  *++yyvsp = yylval;
1422
59.2k
  YY_IGNORE_MAYBE_UNINITIALIZED_END
1423
1424
  /* Discard the shifted token.  */
1425
59.2k
  yychar = YYEMPTY;
1426
59.2k
  goto yynewstate;
1427
1428
1429
/*-----------------------------------------------------------.
1430
| yydefault -- do the default action for the current state.  |
1431
`-----------------------------------------------------------*/
1432
101k
yydefault:
1433
101k
  yyn = yydefact[yystate];
1434
101k
  if (yyn == 0)
1435
121
    goto yyerrlab;
1436
101k
  goto yyreduce;
1437
1438
1439
/*-----------------------------.
1440
| yyreduce -- do a reduction.  |
1441
`-----------------------------*/
1442
110k
yyreduce:
1443
  /* yyn is the number of a rule to reduce with.  */
1444
110k
  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
110k
  yyval = yyvsp[1-yylen];
1455
1456
1457
110k
  YY_REDUCE_PRINT (yyn);
1458
110k
  switch (yyn)
1459
110k
    {
1460
203
  case 3:
1461
203
#line 138 "cmd-parse.y"
1462
203
                {
1463
203
      struct cmd_parse_state  *ps = &parse_state;
1464
1465
203
      ps->commands = (yyvsp[0].commands);
1466
203
    }
1467
203
#line 1468 "cmd-parse.c"
1468
203
    break;
1469
1470
2.78k
  case 4:
1471
2.78k
#line 145 "cmd-parse.y"
1472
2.78k
                {
1473
2.78k
      (yyval.commands) = (yyvsp[-1].commands);
1474
2.78k
    }
1475
2.78k
#line 1476 "cmd-parse.c"
1476
2.78k
    break;
1477
1478
8.59k
  case 5:
1479
8.59k
#line 149 "cmd-parse.y"
1480
8.59k
                {
1481
8.59k
      (yyval.commands) = (yyvsp[-2].commands);
1482
8.59k
      TAILQ_CONCAT((yyval.commands), (yyvsp[-1].commands), entry);
1483
8.59k
      free((yyvsp[-1].commands));
1484
8.59k
    }
1485
8.59k
#line 1486 "cmd-parse.c"
1486
8.59k
    break;
1487
1488
5.75k
  case 6:
1489
5.75k
#line 156 "cmd-parse.y"
1490
5.75k
                {
1491
5.75k
      (yyval.commands) = xmalloc (sizeof *(yyval.commands));
1492
5.75k
      TAILQ_INIT((yyval.commands));
1493
5.75k
    }
1494
5.75k
#line 1495 "cmd-parse.c"
1495
5.75k
    break;
1496
1497
386
  case 7:
1498
386
#line 161 "cmd-parse.y"
1499
386
                {
1500
386
      (yyval.commands) = xmalloc (sizeof *(yyval.commands));
1501
386
      TAILQ_INIT((yyval.commands));
1502
386
    }
1503
386
#line 1504 "cmd-parse.c"
1504
386
    break;
1505
1506
433
  case 8:
1507
433
#line 166 "cmd-parse.y"
1508
433
                {
1509
433
      struct cmd_parse_state  *ps = &parse_state;
1510
1511
433
      if (ps->scope == NULL || ps->scope->flag)
1512
244
        (yyval.commands) = (yyvsp[0].commands);
1513
189
      else {
1514
189
        (yyval.commands) = cmd_parse_new_commands();
1515
189
        cmd_parse_free_commands((yyvsp[0].commands));
1516
189
      }
1517
433
    }
1518
433
#line 1519 "cmd-parse.c"
1519
433
    break;
1520
1521
5.16k
  case 9:
1522
5.16k
#line 177 "cmd-parse.y"
1523
5.16k
                {
1524
5.16k
      struct cmd_parse_state  *ps = &parse_state;
1525
1526
5.16k
      if (ps->scope == NULL || ps->scope->flag)
1527
4.07k
        (yyval.commands) = (yyvsp[0].commands);
1528
1.09k
      else {
1529
1.09k
        (yyval.commands) = cmd_parse_new_commands();
1530
1.09k
        cmd_parse_free_commands((yyvsp[0].commands));
1531
1.09k
      }
1532
5.16k
    }
1533
5.16k
#line 1534 "cmd-parse.c"
1534
5.16k
    break;
1535
1536
271
  case 10:
1537
271
#line 189 "cmd-parse.y"
1538
271
                {
1539
271
      (yyval.token) = (yyvsp[0].token);
1540
271
    }
1541
271
#line 1542 "cmd-parse.c"
1542
271
    break;
1543
1544
3.59k
  case 11:
1545
3.59k
#line 193 "cmd-parse.y"
1546
3.59k
                {
1547
3.59k
      (yyval.token) = (yyvsp[0].token);
1548
3.59k
    }
1549
3.59k
#line 1550 "cmd-parse.c"
1550
3.59k
    break;
1551
1552
3.86k
  case 12:
1553
3.86k
#line 198 "cmd-parse.y"
1554
3.86k
                {
1555
3.86k
      struct cmd_parse_state  *ps = &parse_state;
1556
3.86k
      struct cmd_parse_input  *pi = ps->input;
1557
3.86k
      struct format_tree  *ft;
1558
3.86k
      struct client   *c = pi->c;
1559
3.86k
      struct cmd_find_state *fsp;
1560
3.86k
      struct cmd_find_state  fs;
1561
3.86k
      int      flags = FORMAT_NOJOBS;
1562
1563
3.86k
      if (cmd_find_valid_state(&pi->fs))
1564
0
        fsp = &pi->fs;
1565
3.86k
      else {
1566
3.86k
        cmd_find_from_client(&fs, c, 0);
1567
3.86k
        fsp = &fs;
1568
3.86k
      }
1569
3.86k
      ft = format_create(NULL, pi->item, FORMAT_NONE, flags);
1570
3.86k
      format_defaults(ft, c, fsp->s, fsp->wl, fsp->wp);
1571
1572
3.86k
      (yyval.token) = format_expand(ft, (yyvsp[0].token));
1573
3.86k
      format_free(ft);
1574
3.86k
      free((yyvsp[0].token));
1575
3.86k
    }
1576
3.86k
#line 1577 "cmd-parse.c"
1577
3.86k
    break;
1578
1579
2.17k
  case 15:
1580
2.17k
#line 225 "cmd-parse.y"
1581
2.17k
                {
1582
2.17k
      struct cmd_parse_state  *ps = &parse_state;
1583
2.17k
      int      flags = ps->input->flags;
1584
2.17k
      int      flag = 1;
1585
2.17k
      struct cmd_parse_scope  *scope;
1586
1587
2.17k
      if (ps->scope != NULL) {
1588
232
        flag = ps->scope->flag;
1589
232
        TAILQ_FOREACH(scope, &ps->stack, entry)
1590
5.03k
          flag = flag && scope->flag;
1591
232
      }
1592
1593
2.17k
      if (strlen((yyvsp[0].token)) > CMD_PARSE_MAX_ENVIRON_LEN) {
1594
5
        yyerror("environment variable is too long");
1595
5
        YYABORT;
1596
5
      }
1597
2.17k
      if ((~flags & CMD_PARSE_PARSEONLY) && flag)
1598
2.03k
        environ_put(global_environ, (yyvsp[0].token), 0);
1599
2.17k
      free((yyvsp[0].token));
1600
2.17k
    }
1601
0
#line 1602 "cmd-parse.c"
1602
0
    break;
1603
1604
391
  case 16:
1605
391
#line 247 "cmd-parse.y"
1606
391
                {
1607
391
      struct cmd_parse_state  *ps = &parse_state;
1608
391
      int      flags = ps->input->flags;
1609
391
      int      flag = 1;
1610
391
      struct cmd_parse_scope  *scope;
1611
1612
391
      if (ps->scope != NULL) {
1613
258
        flag = ps->scope->flag;
1614
258
        TAILQ_FOREACH(scope, &ps->stack, entry)
1615
128
          flag = flag && scope->flag;
1616
258
      }
1617
1618
391
      if (strlen((yyvsp[0].token)) > CMD_PARSE_MAX_ENVIRON_LEN) {
1619
5
        yyerror("environment variable is too long");
1620
5
        YYABORT;
1621
5
      }
1622
386
      if ((~flags & CMD_PARSE_PARSEONLY) && flag)
1623
130
        environ_put(global_environ, (yyvsp[0].token), ENVIRON_HIDDEN);
1624
386
      free((yyvsp[0].token));
1625
386
    }
1626
0
#line 1627 "cmd-parse.c"
1627
0
    break;
1628
1629
1.84k
  case 17:
1630
1.84k
#line 269 "cmd-parse.y"
1631
1.84k
                {
1632
1.84k
      struct cmd_parse_state  *ps = &parse_state;
1633
1.84k
      struct cmd_parse_scope  *scope;
1634
1635
1.84k
      scope = xmalloc(sizeof *scope);
1636
1.84k
      (yyval.flag) = scope->flag = format_true((yyvsp[0].token));
1637
1.84k
      free((yyvsp[0].token));
1638
1639
1.84k
      if (ps->scope != NULL)
1640
1.18k
        TAILQ_INSERT_HEAD(&ps->stack, ps->scope, entry);
1641
1.84k
      ps->scope = scope;
1642
1.84k
    }
1643
1.84k
#line 1644 "cmd-parse.c"
1644
1.84k
    break;
1645
1646
646
  case 18:
1647
646
#line 283 "cmd-parse.y"
1648
646
                {
1649
646
      struct cmd_parse_state  *ps = &parse_state;
1650
646
      struct cmd_parse_scope  *scope;
1651
1652
646
      scope = xmalloc(sizeof *scope);
1653
646
      scope->flag = !ps->scope->flag;
1654
1655
646
      free(ps->scope);
1656
646
      ps->scope = scope;
1657
646
    }
1658
646
#line 1659 "cmd-parse.c"
1659
646
    break;
1660
1661
2.02k
  case 19:
1662
2.02k
#line 295 "cmd-parse.y"
1663
2.02k
                {
1664
2.02k
      struct cmd_parse_state  *ps = &parse_state;
1665
2.02k
      struct cmd_parse_scope  *scope;
1666
1667
2.02k
      scope = xmalloc(sizeof *scope);
1668
2.02k
      (yyval.flag) = scope->flag = format_true((yyvsp[0].token));
1669
2.02k
      free((yyvsp[0].token));
1670
1671
2.02k
      free(ps->scope);
1672
2.02k
      ps->scope = scope;
1673
2.02k
    }
1674
2.02k
#line 1675 "cmd-parse.c"
1675
2.02k
    break;
1676
1677
1.23k
  case 20:
1678
1.23k
#line 308 "cmd-parse.y"
1679
1.23k
                {
1680
1.23k
      struct cmd_parse_state  *ps = &parse_state;
1681
1682
1.23k
      free(ps->scope);
1683
1.23k
      ps->scope = TAILQ_FIRST(&ps->stack);
1684
1.23k
      if (ps->scope != NULL)
1685
670
        TAILQ_REMOVE(&ps->stack, ps->scope, entry);
1686
1.23k
    }
1687
1.23k
#line 1688 "cmd-parse.c"
1688
1.23k
    break;
1689
1690
53
  case 21:
1691
53
#line 318 "cmd-parse.y"
1692
53
                {
1693
53
      if ((yyvsp[-3].flag))
1694
50
        (yyval.commands) = (yyvsp[-1].commands);
1695
3
      else {
1696
3
        (yyval.commands) = cmd_parse_new_commands();
1697
3
        cmd_parse_free_commands((yyvsp[-1].commands));
1698
3
      }
1699
53
    }
1700
53
#line 1701 "cmd-parse.c"
1701
53
    break;
1702
1703
95
  case 22:
1704
95
#line 327 "cmd-parse.y"
1705
95
                {
1706
95
      if ((yyvsp[-6].flag)) {
1707
60
        (yyval.commands) = (yyvsp[-4].commands);
1708
60
        cmd_parse_free_commands((yyvsp[-1].commands));
1709
60
      } else {
1710
35
        (yyval.commands) = (yyvsp[-1].commands);
1711
35
        cmd_parse_free_commands((yyvsp[-4].commands));
1712
35
      }
1713
95
    }
1714
95
#line 1715 "cmd-parse.c"
1715
95
    break;
1716
1717
112
  case 23:
1718
112
#line 337 "cmd-parse.y"
1719
112
                {
1720
112
      if ((yyvsp[-4].flag)) {
1721
48
        (yyval.commands) = (yyvsp[-2].commands);
1722
48
        cmd_parse_free_commands((yyvsp[-1].elif).commands);
1723
64
      } 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
32
        (yyval.commands) = cmd_parse_new_commands();
1728
32
        cmd_parse_free_commands((yyvsp[-2].commands));
1729
32
        cmd_parse_free_commands((yyvsp[-1].elif).commands);
1730
32
      }
1731
112
    }
1732
112
#line 1733 "cmd-parse.c"
1733
112
    break;
1734
1735
173
  case 24:
1736
173
#line 351 "cmd-parse.y"
1737
173
                {
1738
173
      if ((yyvsp[-7].flag)) {
1739
50
        (yyval.commands) = (yyvsp[-5].commands);
1740
50
        cmd_parse_free_commands((yyvsp[-4].elif).commands);
1741
50
        cmd_parse_free_commands((yyvsp[-1].commands));
1742
123
      } else if ((yyvsp[-4].elif).flag) {
1743
57
        (yyval.commands) = (yyvsp[-4].elif).commands;
1744
57
        cmd_parse_free_commands((yyvsp[-5].commands));
1745
57
        cmd_parse_free_commands((yyvsp[-1].commands));
1746
66
      } else {
1747
66
        (yyval.commands) = (yyvsp[-1].commands);
1748
66
        cmd_parse_free_commands((yyvsp[-5].commands));
1749
66
        cmd_parse_free_commands((yyvsp[-4].elif).commands);
1750
66
      }
1751
173
    }
1752
173
#line 1753 "cmd-parse.c"
1753
173
    break;
1754
1755
297
  case 25:
1756
297
#line 368 "cmd-parse.y"
1757
297
                {
1758
297
      if ((yyvsp[-2].flag)) {
1759
134
        (yyval.elif).flag = 1;
1760
134
        (yyval.elif).commands = (yyvsp[0].commands);
1761
163
      } else {
1762
163
        (yyval.elif).flag = 0;
1763
163
        (yyval.elif).commands = cmd_parse_new_commands();
1764
163
        cmd_parse_free_commands((yyvsp[0].commands));
1765
163
      }
1766
297
    }
1767
297
#line 1768 "cmd-parse.c"
1768
297
    break;
1769
1770
477
  case 26:
1771
477
#line 379 "cmd-parse.y"
1772
477
                {
1773
477
      if ((yyvsp[-3].flag)) {
1774
208
        (yyval.elif).flag = 1;
1775
208
        (yyval.elif).commands = (yyvsp[-1].commands);
1776
208
        cmd_parse_free_commands((yyvsp[0].elif).commands);
1777
269
      } else if ((yyvsp[0].elif).flag) {
1778
131
        (yyval.elif).flag = 1;
1779
131
        (yyval.elif).commands = (yyvsp[0].elif).commands;
1780
131
        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
477
    }
1788
477
#line 1789 "cmd-parse.c"
1789
477
    break;
1790
1791
7.25k
  case 27:
1792
7.25k
#line 397 "cmd-parse.y"
1793
7.25k
                {
1794
7.25k
      struct cmd_parse_state  *ps = &parse_state;
1795
1796
7.25k
      (yyval.commands) = cmd_parse_new_commands();
1797
7.25k
      if (!TAILQ_EMPTY(&(yyvsp[0].command)->arguments) &&
1798
6.83k
          (ps->scope == NULL || ps->scope->flag))
1799
4.63k
        TAILQ_INSERT_TAIL((yyval.commands), (yyvsp[0].command), entry);
1800
2.61k
      else
1801
2.61k
        cmd_parse_free_command((yyvsp[0].command));
1802
7.25k
    }
1803
7.25k
#line 1804 "cmd-parse.c"
1804
7.25k
    break;
1805
1806
1.70k
  case 28:
1807
1.70k
#line 408 "cmd-parse.y"
1808
1.70k
                {
1809
1.70k
      (yyval.commands) = (yyvsp[-1].commands);
1810
1.70k
    }
1811
1.70k
#line 1812 "cmd-parse.c"
1812
1.70k
    break;
1813
1814
433
  case 29:
1815
433
#line 412 "cmd-parse.y"
1816
433
                {
1817
433
      (yyval.commands) = (yyvsp[-2].commands);
1818
433
      TAILQ_CONCAT((yyval.commands), (yyvsp[0].commands), entry);
1819
433
      free((yyvsp[0].commands));
1820
433
    }
1821
433
#line 1822 "cmd-parse.c"
1822
433
    break;
1823
1824
3.81k
  case 30:
1825
3.81k
#line 418 "cmd-parse.y"
1826
3.81k
                {
1827
3.81k
      struct cmd_parse_state  *ps = &parse_state;
1828
1829
3.81k
      if (!TAILQ_EMPTY(&(yyvsp[0].command)->arguments) &&
1830
2.07k
          (ps->scope == NULL || ps->scope->flag)) {
1831
1.86k
        (yyval.commands) = (yyvsp[-2].commands);
1832
1.86k
        TAILQ_INSERT_TAIL((yyval.commands), (yyvsp[0].command), entry);
1833
1.94k
      } else {
1834
1.94k
        (yyval.commands) = cmd_parse_new_commands();
1835
1.94k
        cmd_parse_free_commands((yyvsp[-2].commands));
1836
1.94k
        cmd_parse_free_command((yyvsp[0].command));
1837
1.94k
      }
1838
3.81k
    }
1839
3.81k
#line 1840 "cmd-parse.c"
1840
3.81k
    break;
1841
1842
368
  case 31:
1843
368
#line 432 "cmd-parse.y"
1844
368
                {
1845
368
      (yyval.commands) = (yyvsp[0].commands);
1846
368
    }
1847
368
#line 1848 "cmd-parse.c"
1848
368
    break;
1849
1850
2.15k
  case 32:
1851
2.15k
#line 437 "cmd-parse.y"
1852
2.15k
                {
1853
2.15k
      struct cmd_parse_state  *ps = &parse_state;
1854
1855
2.15k
      (yyval.command) = xcalloc(1, sizeof *(yyval.command));
1856
2.15k
      (yyval.command)->line = ps->input->line;
1857
2.15k
      TAILQ_INIT(&(yyval.command)->arguments);
1858
2.15k
    }
1859
2.15k
#line 1860 "cmd-parse.c"
1860
2.15k
    break;
1861
1862
5.90k
  case 33:
1863
5.90k
#line 445 "cmd-parse.y"
1864
5.90k
                {
1865
5.90k
      struct cmd_parse_state    *ps = &parse_state;
1866
5.90k
      struct cmd_parse_argument *arg;
1867
1868
5.90k
      (yyval.command) = xcalloc(1, sizeof *(yyval.command));
1869
5.90k
      (yyval.command)->line = ps->input->line;
1870
5.90k
      TAILQ_INIT(&(yyval.command)->arguments);
1871
1872
5.90k
      arg = xcalloc(1, sizeof *arg);
1873
5.90k
      arg->type = CMD_PARSE_STRING;
1874
5.90k
      arg->string = (yyvsp[0].token);
1875
5.90k
      TAILQ_INSERT_HEAD(&(yyval.command)->arguments, arg, entry);
1876
5.90k
    }
1877
5.90k
#line 1878 "cmd-parse.c"
1878
5.90k
    break;
1879
1880
2.99k
  case 34:
1881
2.99k
#line 459 "cmd-parse.y"
1882
2.99k
                {
1883
2.99k
      struct cmd_parse_state    *ps = &parse_state;
1884
2.99k
      struct cmd_parse_argument *arg;
1885
1886
2.99k
      (yyval.command) = xcalloc(1, sizeof *(yyval.command));
1887
2.99k
      (yyval.command)->line = ps->input->line;
1888
2.99k
      TAILQ_INIT(&(yyval.command)->arguments);
1889
1890
2.99k
      TAILQ_CONCAT(&(yyval.command)->arguments, (yyvsp[0].arguments), entry);
1891
2.99k
      free((yyvsp[0].arguments));
1892
1893
2.99k
      arg = xcalloc(1, sizeof *arg);
1894
2.99k
      arg->type = CMD_PARSE_STRING;
1895
2.99k
      arg->string = (yyvsp[-1].token);
1896
2.99k
      TAILQ_INSERT_HEAD(&(yyval.command)->arguments, arg, entry);
1897
2.99k
    }
1898
2.99k
#line 1899 "cmd-parse.c"
1899
2.99k
    break;
1900
1901
151
  case 35:
1902
151
#line 477 "cmd-parse.y"
1903
151
                {
1904
151
      if ((yyvsp[-2].flag))
1905
101
        (yyval.commands) = (yyvsp[-1].commands);
1906
50
      else {
1907
50
        (yyval.commands) = cmd_parse_new_commands();
1908
50
        cmd_parse_free_commands((yyvsp[-1].commands));
1909
50
      }
1910
151
    }
1911
151
#line 1912 "cmd-parse.c"
1912
151
    break;
1913
1914
178
  case 36:
1915
178
#line 486 "cmd-parse.y"
1916
178
                {
1917
178
      if ((yyvsp[-4].flag)) {
1918
65
        (yyval.commands) = (yyvsp[-3].commands);
1919
65
        cmd_parse_free_commands((yyvsp[-1].commands));
1920
113
      } else {
1921
113
        (yyval.commands) = (yyvsp[-1].commands);
1922
113
        cmd_parse_free_commands((yyvsp[-3].commands));
1923
113
      }
1924
178
    }
1925
178
#line 1926 "cmd-parse.c"
1926
178
    break;
1927
1928
289
  case 37:
1929
289
#line 496 "cmd-parse.y"
1930
289
                {
1931
289
      if ((yyvsp[-3].flag)) {
1932
134
        (yyval.commands) = (yyvsp[-2].commands);
1933
134
        cmd_parse_free_commands((yyvsp[-1].elif).commands);
1934
155
      } else if ((yyvsp[-1].elif).flag) {
1935
83
        (yyval.commands) = (yyvsp[-1].elif).commands;
1936
83
        cmd_parse_free_commands((yyvsp[-2].commands));
1937
83
      } else {
1938
72
        (yyval.commands) = cmd_parse_new_commands();
1939
72
        cmd_parse_free_commands((yyvsp[-2].commands));
1940
72
        cmd_parse_free_commands((yyvsp[-1].elif).commands);
1941
72
      }
1942
289
    }
1943
289
#line 1944 "cmd-parse.c"
1944
289
    break;
1945
1946
183
  case 38:
1947
183
#line 510 "cmd-parse.y"
1948
183
                {
1949
183
      if ((yyvsp[-5].flag)) {
1950
56
        (yyval.commands) = (yyvsp[-4].commands);
1951
56
        cmd_parse_free_commands((yyvsp[-3].elif).commands);
1952
56
        cmd_parse_free_commands((yyvsp[-1].commands));
1953
127
      } else if ((yyvsp[-3].elif).flag) {
1954
68
        (yyval.commands) = (yyvsp[-3].elif).commands;
1955
68
        cmd_parse_free_commands((yyvsp[-4].commands));
1956
68
        cmd_parse_free_commands((yyvsp[-1].commands));
1957
68
      } else {
1958
59
        (yyval.commands) = (yyvsp[-1].commands);
1959
59
        cmd_parse_free_commands((yyvsp[-4].commands));
1960
59
        cmd_parse_free_commands((yyvsp[-3].elif).commands);
1961
59
      }
1962
183
    }
1963
183
#line 1964 "cmd-parse.c"
1964
183
    break;
1965
1966
490
  case 39:
1967
490
#line 527 "cmd-parse.y"
1968
490
                {
1969
490
      if ((yyvsp[-1].flag)) {
1970
202
        (yyval.elif).flag = 1;
1971
202
        (yyval.elif).commands = (yyvsp[0].commands);
1972
288
      } else {
1973
288
        (yyval.elif).flag = 0;
1974
288
        (yyval.elif).commands = cmd_parse_new_commands();
1975
288
        cmd_parse_free_commands((yyvsp[0].commands));
1976
288
      }
1977
490
    }
1978
490
#line 1979 "cmd-parse.c"
1979
490
    break;
1980
1981
706
  case 40:
1982
706
#line 538 "cmd-parse.y"
1983
706
                {
1984
706
      if ((yyvsp[-2].flag)) {
1985
333
        (yyval.elif).flag = 1;
1986
333
        (yyval.elif).commands = (yyvsp[-1].commands);
1987
333
        cmd_parse_free_commands((yyvsp[0].elif).commands);
1988
373
      } else if ((yyvsp[0].elif).flag) {
1989
206
        (yyval.elif).flag = 1;
1990
206
        (yyval.elif).commands = (yyvsp[0].elif).commands;
1991
206
        cmd_parse_free_commands((yyvsp[-1].commands));
1992
206
      } else {
1993
167
        (yyval.elif).flag = 0;
1994
167
        (yyval.elif).commands = cmd_parse_new_commands();
1995
167
        cmd_parse_free_commands((yyvsp[-1].commands));
1996
167
        cmd_parse_free_commands((yyvsp[0].elif).commands);
1997
167
      }
1998
706
    }
1999
706
#line 2000 "cmd-parse.c"
2000
706
    break;
2001
2002
2.99k
  case 41:
2003
2.99k
#line 556 "cmd-parse.y"
2004
2.99k
                {
2005
2.99k
      (yyval.arguments) = xcalloc(1, sizeof *(yyval.arguments));
2006
2.99k
      TAILQ_INIT((yyval.arguments));
2007
2008
2.99k
      TAILQ_INSERT_HEAD((yyval.arguments), (yyvsp[0].argument), entry);
2009
2.99k
    }
2010
2.99k
#line 2011 "cmd-parse.c"
2011
2.99k
    break;
2012
2013
14.0k
  case 42:
2014
14.0k
#line 563 "cmd-parse.y"
2015
14.0k
                {
2016
14.0k
      TAILQ_INSERT_HEAD((yyvsp[0].arguments), (yyvsp[-1].argument), entry);
2017
14.0k
      (yyval.arguments) = (yyvsp[0].arguments);
2018
14.0k
    }
2019
14.0k
#line 2020 "cmd-parse.c"
2020
14.0k
    break;
2021
2022
16.7k
  case 43:
2023
16.7k
#line 569 "cmd-parse.y"
2024
16.7k
                {
2025
16.7k
      (yyval.argument) = xcalloc(1, sizeof *(yyval.argument));
2026
16.7k
      (yyval.argument)->type = CMD_PARSE_STRING;
2027
16.7k
      (yyval.argument)->string = (yyvsp[0].token);
2028
16.7k
    }
2029
16.7k
#line 2030 "cmd-parse.c"
2030
16.7k
    break;
2031
2032
17
  case 44:
2033
17
#line 575 "cmd-parse.y"
2034
17
                {
2035
17
      (yyval.argument) = xcalloc(1, sizeof *(yyval.argument));
2036
17
      (yyval.argument)->type = CMD_PARSE_STRING;
2037
17
      (yyval.argument)->string = (yyvsp[0].token);
2038
17
    }
2039
17
#line 2040 "cmd-parse.c"
2040
17
    break;
2041
2042
308
  case 45:
2043
308
#line 581 "cmd-parse.y"
2044
308
                {
2045
308
      (yyval.argument) = xcalloc(1, sizeof *(yyval.argument));
2046
308
      (yyval.argument)->type = CMD_PARSE_COMMANDS;
2047
308
      (yyval.argument)->commands = (yyvsp[0].commands);
2048
308
    }
2049
308
#line 2050 "cmd-parse.c"
2050
308
    break;
2051
2052
41
  case 46:
2053
41
#line 588 "cmd-parse.y"
2054
41
                        {
2055
41
        (yyval.commands) = (yyvsp[-1].commands);
2056
41
      }
2057
41
#line 2058 "cmd-parse.c"
2058
41
    break;
2059
2060
267
  case 47:
2061
267
#line 592 "cmd-parse.y"
2062
267
                        {
2063
267
        (yyval.commands) = (yyvsp[-2].commands);
2064
267
        TAILQ_CONCAT((yyval.commands), (yyvsp[-1].commands), entry);
2065
267
        free((yyvsp[-1].commands));
2066
267
      }
2067
267
#line 2068 "cmd-parse.c"
2068
267
    break;
2069
2070
2071
0
#line 2072 "cmd-parse.c"
2072
2073
9.33k
      default: break;
2074
110k
    }
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
110k
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
2087
2088
110k
  YYPOPSTACK (yylen);
2089
110k
  yylen = 0;
2090
110k
  YY_STACK_PRINT (yyss, yyssp);
2091
2092
110k
  *++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
110k
  {
2098
110k
    const int yylhs = yyr1[yyn] - YYNTOKENS;
2099
110k
    const int yyi = yypgoto[yylhs] + *yyssp;
2100
110k
    yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
2101
110k
               ? yytable[yyi]
2102
110k
               : yydefgoto[yylhs]);
2103
110k
  }
2104
2105
110k
  goto yynewstate;
2106
2107
2108
/*--------------------------------------.
2109
| yyerrlab -- here on detecting error.  |
2110
`--------------------------------------*/
2111
121
yyerrlab:
2112
  /* Make sure we have latest lookahead translation.  See comments at
2113
     user semantic actions for why this is necessary.  */
2114
121
  yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
2115
2116
  /* If not already recovering from an error, report this error.  */
2117
121
  if (!yyerrstatus)
2118
121
    {
2119
121
      ++yynerrs;
2120
121
#if ! YYERROR_VERBOSE
2121
121
      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
121
    }
2155
2156
2157
2158
121
  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
121
  goto yyerrlab1;
2180
2181
2182
/*---------------------------------------------------.
2183
| yyerrorlab -- error raised explicitly by YYERROR.  |
2184
`---------------------------------------------------*/
2185
121
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
121
yyerrlab1:
2204
121
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */
2205
2206
121
  for (;;)
2207
3.68k
    {
2208
3.68k
      yyn = yypact[yystate];
2209
3.68k
      if (!yypact_value_is_default (yyn))
2210
3.68k
        {
2211
3.68k
          yyn += YYTERROR;
2212
3.68k
          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.68k
        }
2219
2220
      /* Pop the current state because it cannot handle the error token.  */
2221
3.68k
      if (yyssp == yyss)
2222
121
        YYABORT;
2223
2224
2225
3.56k
      yydestruct ("Error: popping",
2226
3.56k
                  yystos[yystate], yyvsp);
2227
3.56k
      YYPOPSTACK (1);
2228
3.56k
      yystate = *yyssp;
2229
3.56k
      YY_STACK_PRINT (yyss, yyssp);
2230
3.56k
    }
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
203
yyacceptlab:
2248
203
  yyresult = 0;
2249
203
  goto yyreturn;
2250
2251
2252
/*-----------------------------------.
2253
| yyabortlab -- YYABORT comes here.  |
2254
`-----------------------------------*/
2255
131
yyabortlab:
2256
131
  yyresult = 1;
2257
131
  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
334
yyreturn:
2275
334
  if (yychar != YYEMPTY)
2276
121
    {
2277
      /* Make sure we have latest lookahead translation.  See comments at
2278
         user semantic actions for why this is necessary.  */
2279
121
      yytoken = YYTRANSLATE (yychar);
2280
121
      yydestruct ("Cleanup: discarding lookahead",
2281
121
                  yytoken, &yylval);
2282
121
    }
2283
  /* Do not reclaim the symbols of the rule whose action triggered
2284
     this YYABORT or YYACCEPT.  */
2285
334
  YYPOPSTACK (yylen);
2286
334
  YY_STACK_PRINT (yyss, yyssp);
2287
750
  while (yyssp != yyss)
2288
416
    {
2289
416
      yydestruct ("Cleanup: popping",
2290
416
                  yystos[+*yyssp], yyvsp);
2291
416
      YYPOPSTACK (1);
2292
416
    }
2293
334
#ifndef yyoverflow
2294
334
  if (yyss != yyssa)
2295
27
    YYSTACK_FREE (yyss);
2296
334
#endif
2297
#if YYERROR_VERBOSE
2298
  if (yymsg != yymsgbuf)
2299
    YYSTACK_FREE (yymsg);
2300
#endif
2301
334
  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
174
{
2309
174
  char  *s;
2310
2311
174
  if (file == NULL)
2312
174
    s = xstrdup(error);
2313
0
  else
2314
0
    xasprintf(&s, "%s:%u: %s", file, line, error);
2315
174
  return (s);
2316
174
}
2317
2318
static void
2319
cmd_parse_print_commands(struct cmd_parse_input *pi, struct cmd_list *cmdlist)
2320
1.52k
{
2321
1.52k
  char  *s;
2322
2323
1.52k
  if (pi->item == NULL || (~pi->flags & CMD_PARSE_VERBOSE))
2324
1.52k
    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
23.7k
{
2336
23.7k
  switch (arg->type) {
2337
23.5k
  case CMD_PARSE_STRING:
2338
23.5k
    free(arg->string);
2339
23.5k
    break;
2340
158
  case CMD_PARSE_COMMANDS:
2341
158
    cmd_parse_free_commands(arg->commands);
2342
158
    break;
2343
0
  case CMD_PARSE_PARSED_COMMANDS:
2344
0
    cmd_list_free(arg->cmdlist);
2345
0
    break;
2346
23.7k
  }
2347
23.7k
  free(arg);
2348
23.7k
}
2349
2350
static void
2351
cmd_parse_free_arguments(struct cmd_parse_arguments *args)
2352
9.52k
{
2353
9.52k
  struct cmd_parse_argument *arg, *arg1;
2354
2355
23.6k
  TAILQ_FOREACH_SAFE(arg, args, entry, arg1) {
2356
23.6k
    TAILQ_REMOVE(args, arg, entry);
2357
23.6k
    cmd_parse_free_argument(arg);
2358
23.6k
  }
2359
9.52k
}
2360
2361
static void
2362
cmd_parse_free_command(struct cmd_parse_command *cmd)
2363
9.52k
{
2364
9.52k
  cmd_parse_free_arguments(&cmd->arguments);
2365
9.52k
  free(cmd);
2366
9.52k
}
2367
2368
static struct cmd_parse_commands *
2369
cmd_parse_new_commands(void)
2370
11.3k
{
2371
11.3k
  struct cmd_parse_commands *cmds;
2372
2373
11.3k
  cmds = xmalloc(sizeof *cmds);
2374
11.3k
  TAILQ_INIT(cmds);
2375
11.3k
  return (cmds);
2376
11.3k
}
2377
2378
static void
2379
cmd_parse_free_commands(struct cmd_parse_commands *cmds)
2380
7.06k
{
2381
7.06k
  struct cmd_parse_command  *cmd, *cmd1;
2382
2383
7.06k
  TAILQ_FOREACH_SAFE(cmd, cmds, entry, cmd1) {
2384
4.96k
    TAILQ_REMOVE(cmds, cmd, entry);
2385
4.96k
    cmd_parse_free_command(cmd);
2386
4.96k
  }
2387
7.06k
  free(cmds);
2388
7.06k
}
2389
2390
static struct cmd_parse_commands *
2391
cmd_parse_run_parser(char **cause)
2392
334
{
2393
334
  struct cmd_parse_state  *ps = &parse_state;
2394
334
  struct cmd_parse_scope  *scope, *scope1;
2395
334
  int      retval;
2396
2397
334
  ps->commands = NULL;
2398
334
  TAILQ_INIT(&ps->stack);
2399
2400
334
  retval = yyparse();
2401
518
  TAILQ_FOREACH_SAFE(scope, &ps->stack, entry, scope1) {
2402
518
    TAILQ_REMOVE(&ps->stack, scope, entry);
2403
518
    free(scope);
2404
518
  }
2405
334
  if (retval != 0) {
2406
131
    *cause = ps->error;
2407
131
    return (NULL);
2408
131
  }
2409
2410
203
  if (ps->commands == NULL)
2411
0
    return (cmd_parse_new_commands());
2412
203
  return (ps->commands);
2413
203
}
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
334
{
2430
334
  struct cmd_parse_state  *ps = &parse_state;
2431
2432
334
  memset(ps, 0, sizeof *ps);
2433
334
  ps->input = pi;
2434
334
  ps->buf = buf;
2435
334
  ps->len = len;
2436
334
  return (cmd_parse_run_parser(cause));
2437
334
}
2438
2439
static void
2440
cmd_parse_log_commands(struct cmd_parse_commands *cmds, const char *prefix)
2441
678
{
2442
678
  struct cmd_parse_command  *cmd;
2443
678
  struct cmd_parse_argument *arg;
2444
678
  u_int        i, j;
2445
678
  char        *s;
2446
2447
678
  i = 0;
2448
2.19k
  TAILQ_FOREACH(cmd, cmds, entry) {
2449
2.19k
    j = 0;
2450
18.2k
    TAILQ_FOREACH(arg, &cmd->arguments, entry) {
2451
18.2k
      switch (arg->type) {
2452
17.8k
      case CMD_PARSE_STRING:
2453
17.8k
        log_debug("%s %u:%u: %s", prefix, i, j,
2454
17.8k
            arg->string);
2455
17.8k
        break;
2456
342
      case CMD_PARSE_COMMANDS:
2457
342
        xasprintf(&s, "%s %u:%u", prefix, i, j);
2458
342
        cmd_parse_log_commands(arg->commands, s);
2459
342
        free(s);
2460
342
        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
18.2k
      }
2467
18.2k
      j++;
2468
18.2k
    }
2469
2.19k
    i++;
2470
2.19k
  }
2471
678
}
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.75k
{
2477
1.75k
  struct cmd_parse_argument *first;
2478
1.75k
  struct cmd_parse_commands *cmds;
2479
1.75k
  struct cmd_parse_command  *last;
2480
1.75k
  char        *alias, *name, *cause;
2481
2482
1.75k
  if (pi->flags & CMD_PARSE_NOALIAS)
2483
128
    return (0);
2484
1.62k
  memset(pr, 0, sizeof *pr);
2485
2486
1.62k
  first = TAILQ_FIRST(&cmd->arguments);
2487
1.62k
  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.62k
  name = first->string;
2493
2494
1.62k
  alias = cmd_get_alias(name);
2495
1.62k
  if (alias == NULL)
2496
1.49k
    return (0);
2497
128
  log_debug("%s: %u alias %s = %s", __func__, pi->line, name, alias);
2498
2499
128
  cmds = cmd_parse_do_buffer(alias, strlen(alias), pi, &cause);
2500
128
  free(alias);
2501
128
  if (cmds == NULL) {
2502
0
    pr->status = CMD_PARSE_ERROR;
2503
0
    pr->error = cause;
2504
0
    return (1);
2505
0
  }
2506
2507
128
  last = TAILQ_LAST(cmds, cmd_parse_commands);
2508
128
  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
128
  TAILQ_REMOVE(&cmd->arguments, first, entry);
2516
128
  cmd_parse_free_argument(first);
2517
2518
128
  TAILQ_CONCAT(&last->arguments, &cmd->arguments, entry);
2519
128
  cmd_parse_log_commands(cmds, __func__);
2520
2521
128
  pi->flags |= CMD_PARSE_NOALIAS;
2522
128
  cmd_parse_build_commands(cmds, pi, pr);
2523
128
  pi->flags &= ~CMD_PARSE_NOALIAS;
2524
128
  cmd_parse_free_commands(cmds);
2525
128
  return (1);
2526
128
}
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.75k
{
2532
1.75k
  struct cmd_parse_argument *arg;
2533
1.75k
  struct cmd      *add;
2534
1.75k
  char        *cause;
2535
1.75k
  struct args_value   *values = NULL;
2536
1.75k
  u_int        count = 0, idx;
2537
2538
1.75k
  memset(pr, 0, sizeof *pr);
2539
2540
1.75k
  if (cmd_parse_expand_alias(cmd, pi, pr))
2541
128
    return;
2542
2543
16.6k
  TAILQ_FOREACH(arg, &cmd->arguments, entry) {
2544
16.6k
    values = xrecallocarray(values, count, count + 1,
2545
16.6k
        sizeof *values);
2546
16.6k
    switch (arg->type) {
2547
16.5k
    case CMD_PARSE_STRING:
2548
16.5k
      values[count].type = ARGS_STRING;
2549
16.5k
      values[count].string = xstrdup(arg->string);
2550
16.5k
      break;
2551
147
    case CMD_PARSE_COMMANDS:
2552
147
      cmd_parse_build_commands(arg->commands, pi, pr);
2553
147
      if (pr->status != CMD_PARSE_SUCCESS)
2554
2
        goto out;
2555
145
      values[count].type = ARGS_COMMANDS;
2556
145
      values[count].cmdlist = pr->cmdlist;
2557
145
      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
16.6k
    }
2564
16.6k
    count++;
2565
16.6k
  }
2566
2567
1.62k
  add = cmd_parse(values, count, pi->file, pi->line, pi->flags, &cause);
2568
1.62k
  if (add == NULL) {
2569
43
    pr->status = CMD_PARSE_ERROR;
2570
43
    pr->error = cmd_parse_get_error(pi->file, pi->line, cause);
2571
43
    free(cause);
2572
43
    goto out;
2573
43
  }
2574
1.57k
  pr->status = CMD_PARSE_SUCCESS;
2575
1.57k
  pr->cmdlist = cmd_list_new();
2576
1.57k
  cmd_list_append(pr->cmdlist, add);
2577
2578
1.62k
out:
2579
18.2k
  for (idx = 0; idx < count; idx++)
2580
16.6k
    args_free_value(&values[idx]);
2581
1.62k
  free(values);
2582
1.62k
}
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
350
{
2588
350
  struct cmd_parse_command  *cmd;
2589
350
  u_int        line = UINT_MAX;
2590
350
  struct cmd_list     *current = NULL, *result;
2591
350
  char        *s;
2592
2593
350
  memset(pr, 0, sizeof *pr);
2594
2595
  /* Check for an empty list. */
2596
350
  if (TAILQ_EMPTY(cmds)) {
2597
142
    pr->status = CMD_PARSE_SUCCESS;
2598
142
    pr->cmdlist = cmd_list_new();
2599
142
    return;
2600
142
  }
2601
208
  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
208
  result = cmd_list_new();
2610
1.75k
  TAILQ_FOREACH(cmd, cmds, entry) {
2611
1.75k
    if (((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) {
2612
1.56k
      if (current != NULL) {
2613
1.36k
        cmd_parse_print_commands(pi, current);
2614
1.36k
        cmd_list_move(result, current);
2615
1.36k
        cmd_list_free(current);
2616
1.36k
      }
2617
1.56k
      current = cmd_list_new();
2618
1.56k
    }
2619
1.75k
    if (current == NULL)
2620
8
      current = cmd_list_new();
2621
1.75k
    line = pi->line = cmd->line;
2622
2623
1.75k
    cmd_parse_build_command(cmd, pi, pr);
2624
1.75k
    if (pr->status != CMD_PARSE_SUCCESS) {
2625
45
      cmd_list_free(result);
2626
45
      cmd_list_free(current);
2627
45
      return;
2628
45
    }
2629
1.70k
    cmd_list_append_all(current, pr->cmdlist);
2630
1.70k
    cmd_list_free(pr->cmdlist);
2631
1.70k
  }
2632
163
  if (current != NULL) {
2633
163
    cmd_parse_print_commands(pi, current);
2634
163
    cmd_list_move(result, current);
2635
163
    cmd_list_free(current);
2636
163
  }
2637
2638
163
  s = cmd_list_print(result, 0);
2639
163
  log_debug("%s: %s", __func__, s);
2640
163
  free(s);
2641
2642
163
  pr->status = CMD_PARSE_SUCCESS;
2643
163
  pr->cmdlist = result;
2644
163
}
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
8
{
2675
8
  struct cmd_parse_input  input;
2676
2677
8
  if (pi == NULL) {
2678
8
    memset(&input, 0, sizeof input);
2679
8
    pi = &input;
2680
8
  }
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
8
  pi->flags |= CMD_PARSE_ONEGROUP;
2688
8
  return (cmd_parse_from_buffer(s, strlen(s), pi));
2689
8
}
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
206
{
2742
206
  static struct cmd_parse_result   pr;
2743
206
  struct cmd_parse_input     input;
2744
206
  struct cmd_parse_commands *cmds;
2745
206
  char        *cause;
2746
2747
206
  if (pi == NULL) {
2748
0
    memset(&input, 0, sizeof input);
2749
0
    pi = &input;
2750
0
  }
2751
206
  memset(&pr, 0, sizeof pr);
2752
2753
206
  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
206
  cmds = cmd_parse_do_buffer(buf, len, pi, &cause);
2760
206
  if (cmds == NULL) {
2761
131
    pr.status = CMD_PARSE_ERROR;
2762
131
    pr.error = cause;
2763
131
    return (&pr);
2764
131
  }
2765
75
  cmd_parse_build_commands(cmds, pi, &pr);
2766
75
  cmd_parse_free_commands(cmds);
2767
75
  return (&pr);
2768
206
}
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
134
{
2848
134
  struct cmd_parse_state  *ps = &parse_state;
2849
134
  struct cmd_parse_input  *pi = ps->input;
2850
134
  va_list      ap;
2851
134
  char      *error;
2852
2853
134
  if (ps->error != NULL)
2854
3
    return;
2855
2856
134
  va_start(ap, fmt);
2857
131
  xvasprintf(&error, fmt, ap);
2858
131
  va_end(ap);
2859
2860
131
  ps->error = cmd_parse_get_error(pi->file, pi->line, error);
2861
131
  free(error);
2862
131
}
2863
2864
static int
2865
yylex_is_var(char ch, int first)
2866
268k
{
2867
268k
  if (ch == '=')
2868
2.28k
    return (0);
2869
266k
  if (first && isdigit((u_char)ch))
2870
303
    return (0);
2871
266k
  return (isalnum((u_char)ch) || ch == '_');
2872
266k
}
2873
2874
static void
2875
yylex_append(char **buf, size_t *len, const char *add, size_t addlen)
2876
208k
{
2877
208k
  if (addlen > SIZE_MAX - 1 || *len > SIZE_MAX - 1 - addlen)
2878
0
    fatalx("buffer is too big");
2879
208k
  *buf = xrealloc(*buf, (*len) + 1 + addlen);
2880
208k
  memcpy((*buf) + *len, add, addlen);
2881
208k
  (*len) += addlen;
2882
208k
}
2883
2884
static void
2885
yylex_append1(char **buf, size_t *len, char add)
2886
200k
{
2887
200k
  yylex_append(buf, len, &add, 1);
2888
200k
}
2889
2890
static int
2891
yylex_getc1(void)
2892
324k
{
2893
324k
  struct cmd_parse_state  *ps = &parse_state;
2894
324k
  int      ch;
2895
2896
324k
  if (ps->f != NULL)
2897
0
    ch = getc(ps->f);
2898
324k
  else {
2899
324k
    if (ps->off == ps->len)
2900
740
      ch = EOF;
2901
323k
    else
2902
323k
      ch = ps->buf[ps->off++];
2903
324k
  }
2904
324k
  return (ch);
2905
324k
}
2906
2907
static void
2908
yylex_ungetc(int ch)
2909
51.7k
{
2910
51.7k
  struct cmd_parse_state  *ps = &parse_state;
2911
2912
51.7k
  if (ps->f != NULL)
2913
0
    ungetc(ch, ps->f);
2914
51.7k
  else if (ps->off > 0 && ch != EOF)
2915
42.7k
    ps->off--;
2916
51.7k
}
2917
2918
static int
2919
yylex_getc(void)
2920
322k
{
2921
322k
  struct cmd_parse_state  *ps = &parse_state;
2922
322k
  int      ch;
2923
2924
322k
  if (ps->escapes != 0) {
2925
5.84k
    ps->escapes--;
2926
5.84k
    return ('\\');
2927
5.84k
  }
2928
324k
  for (;;) {
2929
324k
    ch = yylex_getc1();
2930
324k
    if (ch == '\\') {
2931
8.07k
      ps->escapes++;
2932
8.07k
      continue;
2933
8.07k
    }
2934
316k
    if (ch == '\n' && (ps->escapes % 2) == 1) {
2935
26
      ps->input->line++;
2936
26
      ps->escapes--;
2937
26
      continue;
2938
26
    }
2939
2940
316k
    if (ps->escapes != 0) {
2941
2.20k
      yylex_ungetc(ch);
2942
2.20k
      ps->escapes--;
2943
2.20k
      return ('\\');
2944
2.20k
    }
2945
313k
    return (ch);
2946
316k
  }
2947
316k
}
2948
2949
static char *
2950
yylex_get_word(int ch)
2951
10.3k
{
2952
10.3k
  char  *buf;
2953
10.3k
  size_t   len;
2954
2955
10.3k
  len = 0;
2956
10.3k
  buf = xmalloc(1);
2957
2958
10.3k
  do
2959
36.6k
    yylex_append1(&buf, &len, ch);
2960
36.6k
  while ((ch = yylex_getc()) != EOF && strchr(" \t\n", ch) == NULL);
2961
10.3k
  yylex_ungetc(ch);
2962
2963
10.3k
  buf[len] = '\0';
2964
10.3k
  log_debug("%s: %s", __func__, buf);
2965
10.3k
  return (buf);
2966
10.3k
}
2967
2968
static int
2969
yylex(void)
2970
59.4k
{
2971
59.4k
  struct cmd_parse_state  *ps = &parse_state;
2972
59.4k
  char      *token, *cp;
2973
59.4k
  int      ch, next, condition;
2974
2975
59.4k
  if (ps->eol)
2976
13.1k
    ps->input->line++;
2977
59.4k
  ps->eol = 0;
2978
2979
59.4k
  condition = ps->condition;
2980
59.4k
  ps->condition = 0;
2981
2982
77.0k
  for (;;) {
2983
77.0k
    ch = yylex_getc();
2984
2985
77.0k
    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
497
      if (ps->eof)
2992
237
        break;
2993
260
      ps->eof = 1;
2994
260
      return ('\n');
2995
497
    }
2996
2997
76.5k
    if (ch == ' ' || ch == '\t') {
2998
      /*
2999
       * Ignore whitespace.
3000
       */
3001
17.2k
      continue;
3002
17.2k
    }
3003
3004
59.2k
    if (ch == '\r') {
3005
      /*
3006
       * Treat \r\n as \n.
3007
       */
3008
30
      ch = yylex_getc();
3009
30
      if (ch != '\n') {
3010
30
        yylex_ungetc(ch);
3011
30
        ch = '\r';
3012
30
      }
3013
30
    }
3014
59.2k
    if (ch == '\n') {
3015
      /*
3016
       * End of line. Update the line number.
3017
       */
3018
13.1k
      ps->eol = 1;
3019
13.1k
      return ('\n');
3020
13.1k
    }
3021
3022
46.1k
    if (ch == ';' || ch == '{' || ch == '}') {
3023
      /*
3024
       * A semicolon or { or } is itself.
3025
       */
3026
7.01k
      return (ch);
3027
7.01k
    }
3028
3029
39.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
668
      next = yylex_getc();
3035
668
      if (condition && next == '{') {
3036
273
        yylval.token = yylex_format();
3037
273
        if (yylval.token == NULL)
3038
2
          return (ERROR);
3039
271
        return (FORMAT);
3040
273
      }
3041
4.35k
      while (next != '\n' && next != EOF)
3042
3.96k
        next = yylex_getc();
3043
395
      if (next == '\n') {
3044
35
        ps->input->line++;
3045
35
        return ('\n');
3046
35
      }
3047
360
      continue;
3048
395
    }
3049
3050
38.4k
    if (ch == '%') {
3051
      /*
3052
       * % is a condition unless it is all % or all numbers,
3053
       * then it is a token.
3054
       */
3055
10.3k
      yylval.token = yylex_get_word('%');
3056
20.8k
      for (cp = yylval.token; *cp != '\0'; cp++) {
3057
16.6k
        if (*cp != '%' && !isdigit((u_char)*cp))
3058
6.18k
          break;
3059
16.6k
      }
3060
10.3k
      if (*cp == '\0')
3061
4.19k
        return (TOKEN);
3062
6.18k
      ps->condition = 1;
3063
6.18k
      if (strcmp(yylval.token, "%hidden") == 0) {
3064
394
        free(yylval.token);
3065
394
        return (HIDDEN);
3066
394
      }
3067
5.79k
      if (strcmp(yylval.token, "%if") == 0) {
3068
1.84k
        free(yylval.token);
3069
1.84k
        return (IF);
3070
1.84k
      }
3071
3.94k
      if (strcmp(yylval.token, "%else") == 0) {
3072
648
        free(yylval.token);
3073
648
        return (ELSE);
3074
648
      }
3075
3.29k
      if (strcmp(yylval.token, "%elif") == 0) {
3076
2.03k
        free(yylval.token);
3077
2.03k
        return (ELIF);
3078
2.03k
      }
3079
1.26k
      if (strcmp(yylval.token, "%endif") == 0) {
3080
1.23k
        free(yylval.token);
3081
1.23k
        return (ENDIF);
3082
1.23k
      }
3083
28
      free(yylval.token);
3084
28
      return (ERROR);
3085
1.26k
    }
3086
3087
    /*
3088
     * Otherwise this is a token.
3089
     */
3090
28.0k
    token = yylex_token(ch);
3091
28.0k
    if (token == NULL)
3092
14
      return (ERROR);
3093
28.0k
    yylval.token = token;
3094
3095
28.0k
    if (strchr(token, '=') != NULL && yylex_is_var(*token, 1)) {
3096
247k
      for (cp = token + 1; *cp != '='; cp++) {
3097
245k
        if (!yylex_is_var(*cp, 0))
3098
117
          break;
3099
245k
      }
3100
2.70k
      if (*cp == '=')
3101
2.58k
        return (EQUALS);
3102
2.70k
    }
3103
25.4k
    return (TOKEN);
3104
28.0k
  }
3105
237
  return (0);
3106
59.4k
}
3107
3108
static char *
3109
yylex_format(void)
3110
273
{
3111
273
  char  *buf;
3112
273
  size_t   len;
3113
273
  int  ch, brackets = 1;
3114
3115
273
  len = 0;
3116
273
  buf = xmalloc(1);
3117
3118
273
  yylex_append(&buf, &len, "#{", 2);
3119
32.6k
  for (;;) {
3120
32.6k
    if ((ch = yylex_getc()) == EOF || ch == '\n')
3121
2
      goto error;
3122
32.6k
    if (ch == '#') {
3123
3.18k
      if ((ch = yylex_getc()) == EOF || ch == '\n')
3124
0
        goto error;
3125
3.18k
      if (ch == '{')
3126
794
        brackets++;
3127
3.18k
      yylex_append1(&buf, &len, '#');
3128
29.4k
    } else if (ch == '}') {
3129
561
      if (brackets != 0 && --brackets == 0) {
3130
271
        yylex_append1(&buf, &len, ch);
3131
271
        break;
3132
271
      }
3133
561
    }
3134
32.4k
    yylex_append1(&buf, &len, ch);
3135
32.4k
  }
3136
271
  if (brackets != 0)
3137
0
    goto error;
3138
3139
271
  buf[len] = '\0';
3140
271
  log_debug("%s: %s", __func__, buf);
3141
271
  return (buf);
3142
3143
2
error:
3144
2
  free(buf);
3145
2
  return (NULL);
3146
271
}
3147
3148
static int
3149
yylex_token_escape(char **buf, size_t *len)
3150
3.89k
{
3151
3.89k
  int  ch, type, o2, o3, mlen;
3152
3.89k
  u_int  size, i, tmp;
3153
3.89k
  char   s[9], m[MB_LEN_MAX];
3154
3155
3.89k
  ch = yylex_getc();
3156
3157
3.89k
  if (ch >= '4' && ch <= '7') {
3158
0
    yyerror("invalid octal escape");
3159
0
    return (0);
3160
0
  }
3161
3.89k
  if (ch >= '0' && ch <= '3') {
3162
1
    o2 = yylex_getc();
3163
1
    if (o2 >= '0' && o2 <= '7') {
3164
1
      o3 = yylex_getc();
3165
1
      if (o3 >= '0' && o3 <= '7') {
3166
1
        ch = 64 * (ch - '0') +
3167
1
              8 * (o2 - '0') +
3168
1
            (o3 - '0');
3169
1
        yylex_append1(buf, len, ch);
3170
1
        return (1);
3171
1
      }
3172
1
    }
3173
0
    yyerror("invalid octal escape");
3174
0
    return (0);
3175
1
  }
3176
3177
3.89k
  switch (ch) {
3178
3
  case EOF:
3179
3
    return (0);
3180
0
  case 'a':
3181
0
    ch = '\a';
3182
0
    break;
3183
1
  case 'b':
3184
1
    ch = '\b';
3185
1
    break;
3186
442
  case 'e':
3187
442
    ch = '\033';
3188
442
    break;
3189
14
  case 'f':
3190
14
    ch = '\f';
3191
14
    break;
3192
2
  case 's':
3193
2
    ch = ' ';
3194
2
    break;
3195
0
  case 'v':
3196
0
    ch = '\v';
3197
0
    break;
3198
384
  case 'r':
3199
384
    ch = '\r';
3200
384
    break;
3201
1
  case 'n':
3202
1
    ch = '\n';
3203
1
    break;
3204
69
  case 't':
3205
69
    ch = '\t';
3206
69
    break;
3207
145
  case 'u':
3208
145
    type = 'u';
3209
145
    size = 4;
3210
145
    goto unicode;
3211
129
  case 'U':
3212
129
    type = 'U';
3213
129
    size = 8;
3214
129
    goto unicode;
3215
3.89k
  }
3216
3217
3.62k
  yylex_append1(buf, len, ch);
3218
3.62k
  return (1);
3219
3220
274
unicode:
3221
1.87k
  for (i = 0; i < size; i++) {
3222
1.60k
    ch = yylex_getc();
3223
1.60k
    if (ch == EOF || ch == '\n')
3224
0
      return (0);
3225
1.60k
    if (!isxdigit((u_char)ch)) {
3226
1
      yyerror("invalid \\%c argument", type);
3227
1
      return (0);
3228
1
    }
3229
1.60k
    s[i] = ch;
3230
1.60k
  }
3231
273
  s[i] = '\0';
3232
3233
273
  if ((size == 4 && sscanf(s, "%4x", &tmp) != 1) ||
3234
273
      (size == 8 && sscanf(s, "%8x", &tmp) != 1)) {
3235
0
    yyerror("invalid \\%c argument", type);
3236
0
    return (0);
3237
0
  }
3238
273
  mlen = wctomb(m, tmp);
3239
273
  if (mlen <= 0 || mlen > (int)sizeof m) {
3240
0
    yyerror("invalid \\%c argument", type);
3241
0
    return (0);
3242
0
  }
3243
273
  yylex_append(buf, len, m, mlen);
3244
273
  return (1);
3245
273
}
3246
3247
static int
3248
yylex_token_variable(char **buf, size_t *len)
3249
9.91k
{
3250
9.91k
  struct environ_entry  *envent;
3251
9.91k
  int      ch, brackets = 0;
3252
9.91k
  char       name[1024];
3253
9.91k
  size_t       namelen = 0;
3254
9.91k
  const char    *value;
3255
3256
9.91k
  ch = yylex_getc();
3257
9.91k
  if (ch == EOF)
3258
5
    return (0);
3259
9.90k
  if (ch == '{')
3260
6
    brackets = 1;
3261
9.89k
  else {
3262
9.89k
    if (!yylex_is_var(ch, 1)) {
3263
2.12k
      yylex_append1(buf, len, '$');
3264
2.12k
      yylex_ungetc(ch);
3265
2.12k
      return (1);
3266
2.12k
    }
3267
7.77k
    name[namelen++] = ch;
3268
7.77k
  }
3269
3270
10.2k
  for (;;) {
3271
10.2k
    ch = yylex_getc();
3272
10.2k
    if (brackets && ch == '}')
3273
5
      break;
3274
10.2k
    if (ch == EOF || !yylex_is_var(ch, 0)) {
3275
7.77k
      if (!brackets) {
3276
7.77k
        yylex_ungetc(ch);
3277
7.77k
        break;
3278
7.77k
      }
3279
0
      yyerror("invalid environment variable");
3280
0
      return (0);
3281
7.77k
    }
3282
2.48k
    if (namelen == (sizeof name) - 2) {
3283
1
      yyerror("environment variable is too long");
3284
1
      return (0);
3285
1
    }
3286
2.48k
    name[namelen++] = ch;
3287
2.48k
  }
3288
7.77k
  name[namelen] = '\0';
3289
3290
7.77k
  envent = environ_find(global_environ, name);
3291
7.77k
  if (envent != NULL && envent->value != NULL) {
3292
7.21k
    value = envent->value;
3293
7.21k
    log_debug("%s: %s -> %s", __func__, name, value);
3294
7.21k
    yylex_append(buf, len, value, strlen(value));
3295
7.21k
  }
3296
7.77k
  return (1);
3297
7.77k
}
3298
3299
static int
3300
yylex_token_tilde(char **buf, size_t *len)
3301
904
{
3302
904
  struct environ_entry  *envent;
3303
904
  int      ch;
3304
904
  char       name[1024];
3305
904
  size_t       namelen = 0;
3306
904
  struct passwd   *pw;
3307
904
  const char    *home = NULL;
3308
3309
3.48k
  for (;;) {
3310
3.48k
    ch = yylex_getc();
3311
3.48k
    if (ch == EOF || strchr("/ \t\n\"'", ch) != NULL) {
3312
903
      yylex_ungetc(ch);
3313
903
      break;
3314
903
    }
3315
2.58k
    if (namelen == (sizeof name) - 2) {
3316
1
      yyerror("user name is too long");
3317
1
      return (0);
3318
1
    }
3319
2.58k
    name[namelen++] = ch;
3320
2.58k
  }
3321
903
  name[namelen] = '\0';
3322
3323
903
  if (*name == '\0') {
3324
772
    envent = environ_find(global_environ, "HOME");
3325
772
    if (envent != NULL &&
3326
557
        envent->value != NULL &&
3327
557
        *envent->value != '\0')
3328
0
      home = envent->value;
3329
772
    else if ((pw = getpwuid(getuid())) != NULL)
3330
772
      home = pw->pw_dir;
3331
772
  } else {
3332
131
    if ((pw = getpwnam(name)) != NULL)
3333
128
      home = pw->pw_dir;
3334
131
  }
3335
903
  if (home == NULL)
3336
3
    return (0);
3337
3338
900
  log_debug("%s: ~%s -> %s", __func__, name, home);
3339
900
  yylex_append(buf, len, home, strlen(home));
3340
900
  return (1);
3341
903
}
3342
3343
static char *
3344
yylex_token(int ch)
3345
28.0k
{
3346
28.0k
  struct cmd_parse_state  *ps = &parse_state;
3347
28.0k
  char      *buf;
3348
28.0k
  size_t       len;
3349
28.0k
  enum { START,
3350
28.0k
         NONE,
3351
28.0k
         DOUBLE_QUOTES,
3352
28.0k
         SINGLE_QUOTES }   state = NONE, last = START;
3353
3354
28.0k
  len = 0;
3355
28.0k
  buf = xmalloc(1);
3356
3357
166k
  for (;;) {
3358
    /* EOF or \n are always the end of the token. */
3359
166k
    if (ch == EOF) {
3360
6.57k
      log_debug("%s: end at EOF", __func__);
3361
6.57k
      break;
3362
6.57k
    }
3363
159k
    if (state == NONE && ch == '\r') {
3364
311
      ch = yylex_getc();
3365
311
      if (ch != '\n') {
3366
307
        yylex_ungetc(ch);
3367
307
        ch = '\r';
3368
307
      }
3369
311
    }
3370
159k
    if (ch == '\n') {
3371
7.88k
      if (state == NONE) {
3372
6.46k
        log_debug("%s: end at EOL", __func__);
3373
6.46k
        break;
3374
6.46k
      }
3375
1.41k
      ps->input->line++;
3376
1.41k
    }
3377
3378
    /* Whitespace or ; or } ends a token unless inside quotes. */
3379
153k
    if (state == NONE && (ch == ' ' || ch == '\t')) {
3380
10.9k
      log_debug("%s: end at WS", __func__);
3381
10.9k
      break;
3382
10.9k
    }
3383
142k
    if (state == NONE && (ch == ';' || ch == '}')) {
3384
4.06k
      log_debug("%s: end at %c", __func__, ch);
3385
4.06k
      break;
3386
4.06k
    }
3387
3388
    /*
3389
     * Spaces and comments inside quotes after \n are removed but
3390
     * the \n is left.
3391
     */
3392
138k
    if (ch == '\n' && state != NONE) {
3393
1.41k
      yylex_append1(&buf, &len, '\n');
3394
1.41k
      while ((ch = yylex_getc()) == ' ' || ch == '\t')
3395
0
        /* nothing */;
3396
1.41k
      if (ch != '#')
3397
1.41k
        continue;
3398
1
      ch = yylex_getc();
3399
1
      if (strchr(",#{}:", ch) != NULL) {
3400
0
        yylex_ungetc(ch);
3401
0
        ch = '#';
3402
1
      } else {
3403
1
        while ((ch = yylex_getc()) != '\n' && ch != EOF)
3404
0
          /* nothing */;
3405
1
      }
3406
1
      continue;
3407
1.41k
    }
3408
3409
    /* \ ~ and $ are expanded except in single quotes. */
3410
136k
    if (ch == '\\' && state != SINGLE_QUOTES) {
3411
3.89k
      if (!yylex_token_escape(&buf, &len))
3412
4
        goto error;
3413
3.89k
      goto skip;
3414
3.89k
    }
3415
133k
    if (ch == '~' && last != state && state != SINGLE_QUOTES) {
3416
904
      if (!yylex_token_tilde(&buf, &len))
3417
4
        goto error;
3418
900
      goto skip;
3419
904
    }
3420
132k
    if (ch == '$' && state != SINGLE_QUOTES) {
3421
9.91k
      if (!yylex_token_variable(&buf, &len))
3422
6
        goto error;
3423
9.90k
      goto skip;
3424
9.91k
    }
3425
122k
    if (ch == '}' && state == NONE)
3426
0
      goto error;  /* unmatched (matched ones were handled) */
3427
3428
    /* ' and " starts or end quotes (and is consumed). */
3429
122k
    if (ch == '\'') {
3430
82
      if (state == NONE) {
3431
32
        state = SINGLE_QUOTES;
3432
32
        goto next;
3433
32
      }
3434
50
      if (state == SINGLE_QUOTES) {
3435
3
        state = NONE;
3436
3
        goto next;
3437
3
      }
3438
50
    }
3439
122k
    if (ch == '"') {
3440
1.75k
      if (state == NONE) {
3441
958
        state = DOUBLE_QUOTES;
3442
958
        goto next;
3443
958
      }
3444
793
      if (state == DOUBLE_QUOTES) {
3445
793
        state = NONE;
3446
793
        goto next;
3447
793
      }
3448
793
    }
3449
3450
    /* Otherwise add the character to the buffer. */
3451
120k
    yylex_append1(&buf, &len, ch);
3452
3453
135k
  skip:
3454
135k
    last = state;
3455
3456
136k
  next:
3457
136k
    ch = yylex_getc();
3458
136k
  }
3459
28.0k
  yylex_ungetc(ch);
3460
3461
28.0k
  buf[len] = '\0';
3462
28.0k
  log_debug("%s: %s", __func__, buf);
3463
28.0k
  return (buf);
3464
3465
14
error:
3466
14
  free(buf);
3467
  return (NULL);
3468
28.0k
}