1 #line 2 "psqlscanslash.c"
2 /*-------------------------------------------------------------------------
3 *
4 * psqlscanslash.l
5 * lexical scanner for psql backslash commands
6 *
7 * XXX Avoid creating backtracking cases --- see the backend lexer for info.
8 *
9 * See fe_utils/psqlscan_int.h for additional commentary.
10 *
11 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
12 * Portions Copyright (c) 1994, Regents of the University of California
13 *
14 * IDENTIFICATION
15 * src/bin/psql/psqlscanslash.l
16 *
17 *-------------------------------------------------------------------------
18 */
19 #include "postgres_fe.h"
20
21 #include "psqlscanslash.h"
22 #include "common/logging.h"
23 #include "fe_utils/conditional.h"
24
25 #include "libpq-fe.h"
26
27 #line 28 "psqlscanslash.c"
28
29 #define YY_INT_ALIGNED short int
30
31 /* A lexical scanner generated by flex */
32
33 #define FLEX_SCANNER
34 #define YY_FLEX_MAJOR_VERSION 2
35 #define YY_FLEX_MINOR_VERSION 6
36 #define YY_FLEX_SUBMINOR_VERSION 4
37 #if YY_FLEX_SUBMINOR_VERSION > 0
38 #define FLEX_BETA
39 #endif
40
41 #ifdef yy_create_buffer
42 #define slash_yy_create_buffer_ALREADY_DEFINED
43 #else
44 #define yy_create_buffer slash_yy_create_buffer
45 #endif
46
47 #ifdef yy_delete_buffer
48 #define slash_yy_delete_buffer_ALREADY_DEFINED
49 #else
50 #define yy_delete_buffer slash_yy_delete_buffer
51 #endif
52
53 #ifdef yy_scan_buffer
54 #define slash_yy_scan_buffer_ALREADY_DEFINED
55 #else
56 #define yy_scan_buffer slash_yy_scan_buffer
57 #endif
58
59 #ifdef yy_scan_string
60 #define slash_yy_scan_string_ALREADY_DEFINED
61 #else
62 #define yy_scan_string slash_yy_scan_string
63 #endif
64
65 #ifdef yy_scan_bytes
66 #define slash_yy_scan_bytes_ALREADY_DEFINED
67 #else
68 #define yy_scan_bytes slash_yy_scan_bytes
69 #endif
70
71 #ifdef yy_init_buffer
72 #define slash_yy_init_buffer_ALREADY_DEFINED
73 #else
74 #define yy_init_buffer slash_yy_init_buffer
75 #endif
76
77 #ifdef yy_flush_buffer
78 #define slash_yy_flush_buffer_ALREADY_DEFINED
79 #else
80 #define yy_flush_buffer slash_yy_flush_buffer
81 #endif
82
83 #ifdef yy_load_buffer_state
84 #define slash_yy_load_buffer_state_ALREADY_DEFINED
85 #else
86 #define yy_load_buffer_state slash_yy_load_buffer_state
87 #endif
88
89 #ifdef yy_switch_to_buffer
90 #define slash_yy_switch_to_buffer_ALREADY_DEFINED
91 #else
92 #define yy_switch_to_buffer slash_yy_switch_to_buffer
93 #endif
94
95 #ifdef yypush_buffer_state
96 #define slash_yypush_buffer_state_ALREADY_DEFINED
97 #else
98 #define yypush_buffer_state slash_yypush_buffer_state
99 #endif
100
101 #ifdef yypop_buffer_state
102 #define slash_yypop_buffer_state_ALREADY_DEFINED
103 #else
104 #define yypop_buffer_state slash_yypop_buffer_state
105 #endif
106
107 #ifdef yyensure_buffer_stack
108 #define slash_yyensure_buffer_stack_ALREADY_DEFINED
109 #else
110 #define yyensure_buffer_stack slash_yyensure_buffer_stack
111 #endif
112
113 #ifdef yylex
114 #define slash_yylex_ALREADY_DEFINED
115 #else
116 #define yylex slash_yylex
117 #endif
118
119 #ifdef yyrestart
120 #define slash_yyrestart_ALREADY_DEFINED
121 #else
122 #define yyrestart slash_yyrestart
123 #endif
124
125 #ifdef yylex_init
126 #define slash_yylex_init_ALREADY_DEFINED
127 #else
128 #define yylex_init slash_yylex_init
129 #endif
130
131 #ifdef yylex_init_extra
132 #define slash_yylex_init_extra_ALREADY_DEFINED
133 #else
134 #define yylex_init_extra slash_yylex_init_extra
135 #endif
136
137 #ifdef yylex_destroy
138 #define slash_yylex_destroy_ALREADY_DEFINED
139 #else
140 #define yylex_destroy slash_yylex_destroy
141 #endif
142
143 #ifdef yyget_debug
144 #define slash_yyget_debug_ALREADY_DEFINED
145 #else
146 #define yyget_debug slash_yyget_debug
147 #endif
148
149 #ifdef yyset_debug
150 #define slash_yyset_debug_ALREADY_DEFINED
151 #else
152 #define yyset_debug slash_yyset_debug
153 #endif
154
155 #ifdef yyget_extra
156 #define slash_yyget_extra_ALREADY_DEFINED
157 #else
158 #define yyget_extra slash_yyget_extra
159 #endif
160
161 #ifdef yyset_extra
162 #define slash_yyset_extra_ALREADY_DEFINED
163 #else
164 #define yyset_extra slash_yyset_extra
165 #endif
166
167 #ifdef yyget_in
168 #define slash_yyget_in_ALREADY_DEFINED
169 #else
170 #define yyget_in slash_yyget_in
171 #endif
172
173 #ifdef yyset_in
174 #define slash_yyset_in_ALREADY_DEFINED
175 #else
176 #define yyset_in slash_yyset_in
177 #endif
178
179 #ifdef yyget_out
180 #define slash_yyget_out_ALREADY_DEFINED
181 #else
182 #define yyget_out slash_yyget_out
183 #endif
184
185 #ifdef yyset_out
186 #define slash_yyset_out_ALREADY_DEFINED
187 #else
188 #define yyset_out slash_yyset_out
189 #endif
190
191 #ifdef yyget_leng
192 #define slash_yyget_leng_ALREADY_DEFINED
193 #else
194 #define yyget_leng slash_yyget_leng
195 #endif
196
197 #ifdef yyget_text
198 #define slash_yyget_text_ALREADY_DEFINED
199 #else
200 #define yyget_text slash_yyget_text
201 #endif
202
203 #ifdef yyget_lineno
204 #define slash_yyget_lineno_ALREADY_DEFINED
205 #else
206 #define yyget_lineno slash_yyget_lineno
207 #endif
208
209 #ifdef yyset_lineno
210 #define slash_yyset_lineno_ALREADY_DEFINED
211 #else
212 #define yyset_lineno slash_yyset_lineno
213 #endif
214
215 #ifdef yyget_column
216 #define slash_yyget_column_ALREADY_DEFINED
217 #else
218 #define yyget_column slash_yyget_column
219 #endif
220
221 #ifdef yyset_column
222 #define slash_yyset_column_ALREADY_DEFINED
223 #else
224 #define yyset_column slash_yyset_column
225 #endif
226
227 #ifdef yywrap
228 #define slash_yywrap_ALREADY_DEFINED
229 #else
230 #define yywrap slash_yywrap
231 #endif
232
233 #ifdef yyget_lval
234 #define slash_yyget_lval_ALREADY_DEFINED
235 #else
236 #define yyget_lval slash_yyget_lval
237 #endif
238
239 #ifdef yyset_lval
240 #define slash_yyset_lval_ALREADY_DEFINED
241 #else
242 #define yyset_lval slash_yyset_lval
243 #endif
244
245 #ifdef yyalloc
246 #define slash_yyalloc_ALREADY_DEFINED
247 #else
248 #define yyalloc slash_yyalloc
249 #endif
250
251 #ifdef yyrealloc
252 #define slash_yyrealloc_ALREADY_DEFINED
253 #else
254 #define yyrealloc slash_yyrealloc
255 #endif
256
257 #ifdef yyfree
258 #define slash_yyfree_ALREADY_DEFINED
259 #else
260 #define yyfree slash_yyfree
261 #endif
262
263 /* First, we deal with platform-specific or compiler-specific issues. */
264
265 /* begin standard C headers. */
266 #include <stdio.h>
267 #include <string.h>
268 #include <errno.h>
269 #include <stdlib.h>
270
271 /* end standard C headers. */
272
273 /* flex integer type definitions */
274
275 #ifndef FLEXINT_H
276 #define FLEXINT_H
277
278 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
279
280 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
281
282 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
283 * if you want the limit (max/min) macros for int types.
284 */
285 #ifndef __STDC_LIMIT_MACROS
286 #define __STDC_LIMIT_MACROS 1
287 #endif
288
289 #include <inttypes.h>
290 typedef int8_t flex_int8_t;
291 typedef uint8_t flex_uint8_t;
292 typedef int16_t flex_int16_t;
293 typedef uint16_t flex_uint16_t;
294 typedef int32_t flex_int32_t;
295 typedef uint32_t flex_uint32_t;
296 #else
297 typedef signed char flex_int8_t;
298 typedef short int flex_int16_t;
299 typedef int flex_int32_t;
300 typedef unsigned char flex_uint8_t;
301 typedef unsigned short int flex_uint16_t;
302 typedef unsigned int flex_uint32_t;
303
304 /* Limits of integral types. */
305 #ifndef INT8_MIN
306 #define INT8_MIN (-128)
307 #endif
308 #ifndef INT16_MIN
309 #define INT16_MIN (-32767-1)
310 #endif
311 #ifndef INT32_MIN
312 #define INT32_MIN (-2147483647-1)
313 #endif
314 #ifndef INT8_MAX
315 #define INT8_MAX (127)
316 #endif
317 #ifndef INT16_MAX
318 #define INT16_MAX (32767)
319 #endif
320 #ifndef INT32_MAX
321 #define INT32_MAX (2147483647)
322 #endif
323 #ifndef UINT8_MAX
324 #define UINT8_MAX (255U)
325 #endif
326 #ifndef UINT16_MAX
327 #define UINT16_MAX (65535U)
328 #endif
329 #ifndef UINT32_MAX
330 #define UINT32_MAX (4294967295U)
331 #endif
332
333 #ifndef SIZE_MAX
334 #define SIZE_MAX (~(size_t)0)
335 #endif
336
337 #endif /* ! C99 */
338
339 #endif /* ! FLEXINT_H */
340
341 /* begin standard C++ headers. */
342
343 /* TODO: this is always defined, so inline it */
344 #define yyconst const
345
346 #if defined(__GNUC__) && __GNUC__ >= 3
347 #define yynoreturn __attribute__((__noreturn__))
348 #else
349 #define yynoreturn
350 #endif
351
352 /* Returned upon end-of-file. */
353 #define YY_NULL 0
354
355 /* Promotes a possibly negative, possibly signed char to an
356 * integer in range [0..255] for use as an array index.
357 */
358 #define YY_SC_TO_UI(c) ((YY_CHAR) (c))
359
360 /* An opaque pointer. */
361 #ifndef YY_TYPEDEF_YY_SCANNER_T
362 #define YY_TYPEDEF_YY_SCANNER_T
363 typedef void* yyscan_t;
364 #endif
365
366 /* For convenience, these vars (plus the bison vars far below)
367 are macros in the reentrant scanner. */
368 #define yyin yyg->yyin_r
369 #define yyout yyg->yyout_r
370 #define yyextra yyg->yyextra_r
371 #define yyleng yyg->yyleng_r
372 #define yytext yyg->yytext_r
373 #define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
374 #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
375 #define yy_flex_debug yyg->yy_flex_debug_r
376
377 /* Enter a start condition. This macro really ought to take a parameter,
378 * but we do it the disgusting crufty way forced on us by the ()-less
379 * definition of BEGIN.
380 */
381 #define BEGIN yyg->yy_start = 1 + 2 *
382 /* Translate the current start state into a value that can be later handed
383 * to BEGIN to return to the state. The YYSTATE alias is for lex
384 * compatibility.
385 */
386 #define YY_START ((yyg->yy_start - 1) / 2)
387 #define YYSTATE YY_START
388 /* Action number for EOF rule of a given start state. */
389 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
390 /* Special action meaning "start processing a new file". */
391 #define YY_NEW_FILE yyrestart( yyin , yyscanner )
392 #define YY_END_OF_BUFFER_CHAR 0
393
394 /* Size of default input buffer. */
395 #ifndef YY_BUF_SIZE
396 #ifdef __ia64__
397 /* On IA-64, the buffer size is 16k, not 8k.
398 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
399 * Ditto for the __ia64__ case accordingly.
400 */
401 #define YY_BUF_SIZE 32768
402 #else
403 #define YY_BUF_SIZE 16384
404 #endif /* __ia64__ */
405 #endif
406
407 /* The state buf must be large enough to hold one state per character in the main buffer.
408 */
409 #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
410
411 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
412 #define YY_TYPEDEF_YY_BUFFER_STATE
413 typedef struct yy_buffer_state *YY_BUFFER_STATE;
414 #endif
415
416 #ifndef YY_TYPEDEF_YY_SIZE_T
417 #define YY_TYPEDEF_YY_SIZE_T
418 typedef size_t yy_size_t;
419 #endif
420
421 #define EOB_ACT_CONTINUE_SCAN 0
422 #define EOB_ACT_END_OF_FILE 1
423 #define EOB_ACT_LAST_MATCH 2
424
425 #define YY_LESS_LINENO(n)
426 #define YY_LINENO_REWIND_TO(ptr)
427
428 /* Return all but the first "n" matched characters back to the input stream. */
429 #define yyless(n) \
430 do \
431 { \
432 /* Undo effects of setting up yytext. */ \
433 int yyless_macro_arg = (n); \
434 YY_LESS_LINENO(yyless_macro_arg);\
435 *yy_cp = yyg->yy_hold_char; \
436 YY_RESTORE_YY_MORE_OFFSET \
437 yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
438 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
439 } \
440 while ( 0 )
441 #define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
442
443 #ifndef YY_STRUCT_YY_BUFFER_STATE
444 #define YY_STRUCT_YY_BUFFER_STATE
445 struct yy_buffer_state
446 {
447 FILE *yy_input_file;
448
449 char *yy_ch_buf; /* input buffer */
450 char *yy_buf_pos; /* current position in input buffer */
451
452 /* Size of input buffer in bytes, not including room for EOB
453 * characters.
454 */
455 int yy_buf_size;
456
457 /* Number of characters read into yy_ch_buf, not including EOB
458 * characters.
459 */
460 int yy_n_chars;
461
462 /* Whether we "own" the buffer - i.e., we know we created it,
463 * and can realloc() it to grow it, and should free() it to
464 * delete it.
465 */
466 int yy_is_our_buffer;
467
468 /* Whether this is an "interactive" input source; if so, and
469 * if we're using stdio for input, then we want to use getc()
470 * instead of fread(), to make sure we stop fetching input after
471 * each newline.
472 */
473 int yy_is_interactive;
474
475 /* Whether we're considered to be at the beginning of a line.
476 * If so, '^' rules will be active on the next match, otherwise
477 * not.
478 */
479 int yy_at_bol;
480
481 int yy_bs_lineno; /**< The line count. */
482 int yy_bs_column; /**< The column count. */
483
484 /* Whether to try to fill the input buffer when we reach the
485 * end of it.
486 */
487 int yy_fill_buffer;
488
489 int yy_buffer_status;
490
491 #define YY_BUFFER_NEW 0
492 #define YY_BUFFER_NORMAL 1
493 /* When an EOF's been seen but there's still some text to process
494 * then we mark the buffer as YY_EOF_PENDING, to indicate that we
495 * shouldn't try reading from the input source any more. We might
496 * still have a bunch of tokens to match, though, because of
497 * possible backing-up.
498 *
499 * When we actually see the EOF, we change the status to "new"
500 * (via yyrestart()), so that the user can continue scanning by
501 * just pointing yyin at a new input file.
502 */
503 #define YY_BUFFER_EOF_PENDING 2
504
505 };
506 #endif /* !YY_STRUCT_YY_BUFFER_STATE */
507
508 /* We provide macros for accessing buffer states in case in the
509 * future we want to put the buffer states in a more general
510 * "scanner state".
511 *
512 * Returns the top of the stack, or NULL.
513 */
514 #define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
515 ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
516 : NULL)
517 /* Same as previous macro, but useful when we know that the buffer stack is not
518 * NULL or when we need an lvalue. For internal use only.
519 */
520 #define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
521
522 void yyrestart ( FILE *input_file , yyscan_t yyscanner );
523 void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
524 YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
525 void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
526 void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
527 void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
528 void yypop_buffer_state ( yyscan_t yyscanner );
529
530 static void yyensure_buffer_stack ( yyscan_t yyscanner );
531 static void yy_load_buffer_state ( yyscan_t yyscanner );
532 static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
533 #define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner)
534
535 YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
536 YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
537 YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
538
539 void *yyalloc ( yy_size_t , yyscan_t yyscanner );
540 void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
541 void yyfree ( void * , yyscan_t yyscanner );
542
543 #define yy_new_buffer yy_create_buffer
544 #define yy_set_interactive(is_interactive) \
545 { \
546 if ( ! YY_CURRENT_BUFFER ){ \
547 yyensure_buffer_stack (yyscanner); \
548 YY_CURRENT_BUFFER_LVALUE = \
549 yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \
550 } \
551 YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
552 }
553 #define yy_set_bol(at_bol) \
554 { \
555 if ( ! YY_CURRENT_BUFFER ){\
556 yyensure_buffer_stack (yyscanner); \
557 YY_CURRENT_BUFFER_LVALUE = \
558 yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \
559 } \
560 YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
561 }
562 #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
563
564 /* Begin user sect3 */
565
566 #define slash_yywrap(yyscanner) (/*CONSTCOND*/1)
567 #define YY_SKIP_YYWRAP
568 typedef flex_uint8_t YY_CHAR;
569
570 typedef int yy_state_type;
571
572 #define yytext_ptr yytext_r
573
574 static const flex_int16_t yy_nxt[][22] =
575 {
576 {
577 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
578 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
579 0, 0
580 },
581
582 {
583 19, 20, 20, 20, 20, 20, 20, 20, 20, 20,
584 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
585 20, 20
586 },
587
588 {
589 19, 20, 20, 20, 20, 20, 20, 20, 20, 20,
590 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
591 20, 20
592 },
593
594 {
595 19, 21, 22, 23, 21, 21, 21, 21, 21, 21,
596
597 21, 22, 21, 21, 21, 21, 21, 21, 21, 21,
598 21, 21
599 },
600
601 {
602 19, 21, 22, 23, 21, 21, 21, 21, 21, 21,
603 21, 22, 21, 21, 21, 21, 21, 21, 21, 21,
604 21, 21
605 },
606
607 {
608 19, 24, 25, 26, 24, 24, 24, 24, 24, 24,
609 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
610 27, 24
611 },
612
613 {
614 19, 24, 25, 26, 24, 24, 24, 24, 24, 24,
615 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
616
617 27, 24
618 },
619
620 {
621 19, 28, 29, 30, 31, 32, 28, 28, 33, 28,
622 28, 29, 34, 28, 28, 28, 28, 28, 28, 28,
623 28, 28
624 },
625
626 {
627 19, 28, 29, 30, 31, 32, 28, 28, 33, 28,
628 28, 29, 34, 28, 28, 28, 28, 28, 28, 28,
629 28, 28
630 },
631
632 {
633 19, 35, 35, 35, 35, 36, 35, 35, 35, 35,
634 35, 37, 35, 35, 35, 35, 35, 35, 35, 35,
635 35, 35
636
637 },
638
639 {
640 19, 35, 35, 35, 35, 36, 35, 35, 35, 35,
641 35, 37, 35, 35, 35, 35, 35, 35, 35, 35,
642 35, 35
643 },
644
645 {
646 19, 38, 38, 38, 38, 38, 38, 38, 39, 38,
647 38, 38, 40, 38, 38, 38, 38, 38, 38, 38,
648 38, 38
649 },
650
651 {
652 19, 38, 38, 38, 38, 38, 38, 38, 39, 38,
653 38, 38, 40, 38, 38, 38, 38, 38, 38, 38,
654 38, 38
655 },
656
657 {
658 19, 41, 41, 41, 42, 41, 41, 41, 41, 41,
659
660 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
661 41, 41
662 },
663
664 {
665 19, 41, 41, 41, 42, 41, 41, 41, 41, 41,
666 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
667 41, 41
668 },
669
670 {
671 19, 43, 44, 45, 43, 43, 43, 43, 43, 43,
672 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
673 43, 43
674 },
675
676 {
677 19, 43, 44, 45, 43, 43, 43, 43, 43, 43,
678 43, 43, 43, 43, 43, 43, 43, 43, 43, 43,
679
680 43, 43
681 },
682
683 {
684 19, 46, 46, 46, 46, 46, 46, 46, 46, 46,
685 46, 47, 46, 46, 46, 46, 46, 46, 46, 46,
686 46, 46
687 },
688
689 {
690 19, 46, 46, 46, 46, 46, 46, 46, 46, 46,
691 46, 47, 46, 46, 46, 46, 46, 46, 46, 46,
692 46, 46
693 },
694
695 {
696 -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
697 -19, -19, -19, -19, -19, -19, -19, -19, -19, -19,
698 -19, -19
699
700 },
701
702 {
703 19, -20, -20, -20, -20, -20, -20, -20, -20, -20,
704 -20, -20, -20, -20, -20, -20, -20, -20, -20, -20,
705 -20, -20
706 },
707
708 {
709 19, -21, -21, -21, -21, -21, -21, -21, -21, -21,
710 -21, -21, -21, -21, -21, -21, -21, -21, -21, -21,
711 -21, -21
712 },
713
714 {
715 19, -22, -22, -22, -22, -22, -22, -22, -22, -22,
716 -22, -22, -22, -22, -22, -22, -22, -22, -22, -22,
717 -22, -22
718 },
719
720 {
721 19, -23, -23, -23, -23, -23, -23, -23, -23, -23,
722
723 -23, -23, -23, -23, -23, -23, -23, -23, -23, -23,
724 -23, -23
725 },
726
727 {
728 19, -24, -24, -24, -24, -24, -24, -24, -24, -24,
729 -24, -24, -24, -24, -24, -24, -24, -24, -24, -24,
730 -24, -24
731 },
732
733 {
734 19, -25, 48, 48, -25, -25, -25, -25, -25, -25,
735 -25, -25, -25, -25, -25, -25, -25, -25, -25, -25,
736 -25, -25
737 },
738
739 {
740 19, -26, 48, 48, -26, -26, -26, -26, -26, -26,
741 -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
742
743 -26, -26
744 },
745
746 {
747 19, -27, -27, -27, -27, -27, -27, -27, -27, -27,
748 -27, -27, -27, -27, -27, -27, -27, -27, -27, -27,
749 -27, -27
750 },
751
752 {
753 19, -28, -28, -28, -28, -28, -28, -28, -28, -28,
754 -28, -28, -28, -28, -28, -28, -28, -28, -28, -28,
755 -28, -28
756 },
757
758 {
759 19, -29, -29, -29, -29, -29, -29, -29, -29, -29,
760 -29, -29, -29, -29, -29, -29, -29, -29, -29, -29,
761 -29, -29
762
763 },
764
765 {
766 19, -30, -30, -30, -30, -30, -30, -30, -30, -30,
767 -30, -30, -30, -30, -30, -30, -30, -30, -30, -30,
768 -30, -30
769 },
770
771 {
772 19, -31, -31, -31, -31, -31, -31, -31, -31, -31,
773 -31, -31, -31, -31, -31, -31, -31, -31, -31, -31,
774 -31, -31
775 },
776
777 {
778 19, -32, -32, -32, -32, -32, -32, -32, -32, -32,
779 -32, -32, -32, -32, -32, -32, -32, -32, -32, -32,
780 -32, -32
781 },
782
783 {
784 19, -33, -33, -33, 49, 50, 51, 51, -33, -33,
785
786 51, -33, -33, 51, 51, 51, 51, 51, 51, 52,
787 -33, -33
788 },
789
790 {
791 19, -34, -34, -34, -34, -34, -34, -34, -34, -34,
792 -34, -34, -34, -34, -34, -34, -34, -34, -34, -34,
793 -34, -34
794 },
795
796 {
797 19, -35, -35, -35, -35, -35, -35, -35, -35, -35,
798 -35, -35, -35, -35, -35, -35, -35, -35, -35, -35,
799 -35, -35
800 },
801
802 {
803 19, -36, -36, -36, -36, 53, -36, -36, -36, -36,
804 -36, -36, -36, -36, -36, -36, -36, -36, -36, -36,
805
806 -36, -36
807 },
808
809 {
810 19, 54, 54, -37, 54, 54, 55, 54, 54, 54,
811 54, 54, 54, 56, 57, 58, 59, 60, 61, 54,
812 54, 54
813 },
814
815 {
816 19, -38, -38, -38, -38, -38, -38, -38, -38, -38,
817 -38, -38, -38, -38, -38, -38, -38, -38, -38, -38,
818 -38, -38
819 },
820
821 {
822 19, -39, -39, -39, -39, 62, 63, 63, -39, -39,
823 63, -39, -39, 63, 63, 63, 63, 63, 63, -39,
824 -39, -39
825
826 },
827
828 {
829 19, -40, -40, -40, -40, -40, -40, -40, -40, -40,
830 -40, -40, -40, -40, -40, -40, -40, -40, -40, -40,
831 -40, -40
832 },
833
834 {
835 19, -41, -41, -41, -41, -41, -41, -41, -41, -41,
836 -41, -41, -41, -41, -41, -41, -41, -41, -41, -41,
837 -41, -41
838 },
839
840 {
841 19, -42, -42, -42, -42, -42, -42, -42, -42, -42,
842 -42, -42, -42, -42, -42, -42, -42, -42, -42, -42,
843 -42, -42
844 },
845
846 {
847 19, -43, -43, -43, -43, -43, -43, -43, -43, -43,
848
849 -43, -43, -43, -43, -43, -43, -43, -43, -43, -43,
850 -43, -43
851 },
852
853 {
854 19, -44, 64, 64, -44, -44, -44, -44, -44, -44,
855 -44, -44, -44, -44, -44, -44, -44, -44, -44, -44,
856 -44, -44
857 },
858
859 {
860 19, -45, 64, 64, -45, -45, -45, -45, -45, -45,
861 -45, -45, -45, -45, -45, -45, -45, -45, -45, -45,
862 -45, -45
863 },
864
865 {
866 19, -46, -46, -46, -46, -46, -46, -46, -46, -46,
867 -46, -46, -46, -46, -46, -46, -46, -46, -46, -46,
868
869 -46, -46
870 },
871
872 {
873 19, -47, -47, -47, -47, -47, -47, -47, -47, -47,
874 -47, 65, -47, -47, -47, -47, -47, -47, -47, -47,
875 -47, -47
876 },
877
878 {
879 19, -48, 48, 48, -48, -48, -48, -48, -48, -48,
880 -48, -48, -48, -48, -48, -48, -48, -48, -48, -48,
881 -48, -48
882 },
883
884 {
885 19, -49, -49, -49, -49, -49, 66, 66, -49, -49,
886 66, -49, -49, 66, 66, 66, 66, 66, 66, -49,
887 -49, -49
888
889 },
890
891 {
892 19, -50, -50, -50, -50, -50, 67, 67, -50, -50,
893 67, -50, -50, 67, 67, 67, 67, 67, 67, -50,
894 -50, -50
895 },
896
897 {
898 19, -51, -51, -51, -51, -51, 51, 51, -51, -51,
899 51, -51, -51, 51, 51, 51, 51, 51, 51, -51,
900 -51, -51
901 },
902
903 {
904 19, -52, -52, -52, -52, -52, -52, -52, -52, 68,
905 -52, -52, -52, -52, -52, -52, -52, -52, -52, -52,
906 -52, -52
907 },
908
909 {
910 19, -53, -53, -53, -53, -53, -53, -53, -53, -53,
911
912 -53, -53, -53, -53, -53, -53, -53, -53, -53, -53,
913 -53, -53
914 },
915
916 {
917 19, -54, -54, -54, -54, -54, -54, -54, -54, -54,
918 -54, -54, -54, -54, -54, -54, -54, -54, -54, -54,
919 -54, -54
920 },
921
922 {
923 19, -55, -55, -55, -55, -55, 69, -55, -55, -55,
924 -55, -55, -55, -55, -55, -55, -55, -55, -55, -55,
925 -55, -55
926 },
927
928 {
929 19, -56, -56, -56, -56, -56, -56, -56, -56, -56,
930 -56, -56, -56, -56, -56, -56, -56, -56, -56, -56,
931
932 -56, -56
933 },
934
935 {
936 19, -57, -57, -57, -57, -57, -57, -57, -57, -57,
937 -57, -57, -57, -57, -57, -57, -57, -57, -57, -57,
938 -57, -57
939 },
940
941 {
942 19, -58, -58, -58, -58, -58, -58, -58, -58, -58,
943 -58, -58, -58, -58, -58, -58, -58, -58, -58, -58,
944 -58, -58
945 },
946
947 {
948 19, -59, -59, -59, -59, -59, -59, -59, -59, -59,
949 -59, -59, -59, -59, -59, -59, -59, -59, -59, -59,
950 -59, -59
951
952 },
953
954 {
955 19, -60, -60, -60, -60, -60, -60, -60, -60, -60,
956 -60, -60, -60, -60, -60, -60, -60, -60, -60, -60,
957 -60, -60
958 },
959
960 {
961 19, -61, -61, -61, -61, -61, 70, 70, -61, -61,
962 -61, -61, -61, 70, 70, -61, -61, -61, -61, -61,
963 -61, -61
964 },
965
966 {
967 19, -62, -62, -62, -62, -62, 71, 71, -62, -62,
968 71, -62, -62, 71, 71, 71, 71, 71, 71, -62,
969 -62, -62
970 },
971
972 {
973 19, -63, -63, -63, -63, -63, 63, 63, -63, -63,
974
975 63, -63, -63, 63, 63, 63, 63, 63, 63, -63,
976 -63, -63
977 },
978
979 {
980 19, -64, 64, 64, -64, -64, -64, -64, -64, -64,
981 -64, -64, -64, -64, -64, -64, -64, -64, -64, -64,
982 -64, -64
983 },
984
985 {
986 19, -65, -65, -65, -65, -65, -65, -65, -65, -65,
987 -65, -65, -65, -65, -65, -65, -65, -65, -65, -65,
988 -65, -65
989 },
990
991 {
992 19, -66, -66, -66, 72, -66, 66, 66, -66, -66,
993 66, -66, -66, 66, 66, 66, 66, 66, 66, -66,
994
995 -66, -66
996 },
997
998 {
999 19, -67, -67, -67, -67, 73, 67, 67, -67, -67,
1000 67, -67, -67, 67, 67, 67, 67, 67, 67, -67,
1001 -67, -67
1002 },
1003
1004 {
1005 19, -68, -68, -68, -68, -68, 74, 74, -68, -68,
1006 74, -68, -68, 74, 74, 74, 74, 74, 74, -68,
1007 -68, -68
1008 },
1009
1010 {
1011 19, -69, -69, -69, -69, -69, 75, -69, -69, -69,
1012 -69, -69, -69, -69, -69, -69, -69, -69, -69, -69,
1013 -69, -69
1014
1015 },
1016
1017 {
1018 19, -70, -70, -70, -70, -70, 76, 76, -70, -70,
1019 -70, -70, -70, 76, 76, -70, -70, -70, -70, -70,
1020 -70, -70
1021 },
1022
1023 {
1024 19, -71, -71, -71, -71, 77, 71, 71, -71, -71,
1025 71, -71, -71, 71, 71, 71, 71, 71, 71, -71,
1026 -71, -71
1027 },
1028
1029 {
1030 19, -72, -72, -72, -72, -72, -72, -72, -72, -72,
1031 -72, -72, -72, -72, -72, -72, -72, -72, -72, -72,
1032 -72, -72
1033 },
1034
1035 {
1036 19, -73, -73, -73, -73, -73, -73, -73, -73, -73,
1037
1038 -73, -73, -73, -73, -73, -73, -73, -73, -73, -73,
1039 -73, -73
1040 },
1041
1042 {
1043 19, -74, -74, -74, -74, -74, 74, 74, -74, -74,
1044 74, -74, -74, 74, 74, 74, 74, 74, 74, -74,
1045 -74, 78
1046 },
1047
1048 {
1049 19, -75, -75, -75, -75, -75, -75, -75, -75, -75,
1050 -75, -75, -75, -75, -75, -75, -75, -75, -75, -75,
1051 -75, -75
1052 },
1053
1054 {
1055 19, -76, -76, -76, -76, -76, -76, -76, -76, -76,
1056 -76, -76, -76, -76, -76, -76, -76, -76, -76, -76,
1057
1058 -76, -76
1059 },
1060
1061 {
1062 19, -77, -77, -77, -77, -77, -77, -77, -77, -77,
1063 -77, -77, -77, -77, -77, -77, -77, -77, -77, -77,
1064 -77, -77
1065 },
1066
1067 {
1068 19, -78, -78, -78, -78, -78, -78, -78, -78, -78,
1069 -78, -78, -78, -78, -78, -78, -78, -78, -78, -78,
1070 -78, -78
1071 },
1072
1073 } ;
1074
1075 static yy_state_type yy_get_previous_state ( yyscan_t yyscanner );
1076 static yy_state_type yy_try_NUL_trans ( yy_state_type current_state , yyscan_t yyscanner);
1077 static int yy_get_next_buffer ( yyscan_t yyscanner );
1078 static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
1079
1080 /* Done after the current pattern has been matched and before the
1081 * corresponding action - sets up yytext.
1082 */
1083 #define YY_DO_BEFORE_ACTION \
1084 yyg->yytext_ptr = yy_bp; \
1085 yyleng = (int) (yy_cp - yy_bp); \
1086 yyg->yy_hold_char = *yy_cp; \
1087 *yy_cp = '\0'; \
1088 yyg->yy_c_buf_p = yy_cp;
1089 #define YY_NUM_RULES 42
1090 #define YY_END_OF_BUFFER 43
1091 /* This struct is not used in this scanner,
1092 but its presence is necessary. */
1093 struct yy_trans_info
1094 {
1095 flex_int32_t yy_verify;
1096 flex_int32_t yy_nxt;
1097 };
1098 static const flex_int16_t yy_accept[79] =
1099 { 0,
1100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1101 0, 0, 0, 0, 0, 0, 0, 0, 43, 1,
1102 3, 2, 2, 6, 4, 4, 5, 19, 7, 7,
1103 10, 8, 19, 9, 30, 20, 30, 35, 35, 31,
1104 37, 36, 39, 38, 38, 41, 41, 4, 16, 15,
1105 11, 18, 21, 29, 27, 24, 26, 22, 25, 23,
1106 29, 34, 32, 38, 40, 16, 15, 17, 27, 28,
1107 34, 13, 12, 17, 27, 28, 33, 14
1108 } ;
1109
1110 static const YY_CHAR yy_ec[256] =
1111 { 0,
1112 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1113 1, 2, 2, 1, 1, 1, 1, 1, 1, 1,
1114 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1115 1, 2, 1, 4, 1, 1, 1, 1, 5, 1,
1116 1, 1, 1, 1, 1, 1, 1, 6, 6, 6,
1117 6, 6, 6, 6, 6, 7, 7, 8, 1, 1,
1118 1, 1, 9, 1, 7, 7, 7, 7, 7, 7,
1119 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1120 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1121 1, 11, 1, 1, 10, 12, 7, 13, 7, 7,
1122
1123 7, 14, 10, 10, 10, 10, 10, 10, 10, 15,
1124 10, 10, 10, 16, 10, 17, 10, 10, 10, 18,
1125 10, 10, 19, 20, 21, 1, 1, 10, 10, 10,
1126 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1127 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1128 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1129 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1130 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1131 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1132 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1133
1134 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1135 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1136 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1137 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1138 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
1139 10, 10, 10, 10, 10
1140 } ;
1141
1142 /* The intent behind this definition is that it'll catch
1143 * any uses of REJECT which flex missed.
1144 */
1145 #define REJECT reject_used_but_not_detected
1146 #define yymore() yymore_used_but_not_detected
1147 #define YY_MORE_ADJ 0
1148 #define YY_RESTORE_YY_MORE_OFFSET
1149 #line 1 "psqlscanslash.l"
1150
1151 #line 29 "psqlscanslash.l"
1152 #include "fe_utils/psqlscan_int.h"
1153
1154 /*
1155 * We must have a typedef YYSTYPE for yylex's first argument, but this lexer
1156 * doesn't presently make use of that argument, so just declare it as int.
1157 */
1158 typedef int YYSTYPE;
1159
1160 /*
1161 * Set the type of yyextra; we use it as a pointer back to the containing
1162 * PsqlScanState.
1163 */
1164 #define YY_EXTRA_TYPE PsqlScanState
1165
1166 /*
1167 * These variables do not need to be saved across calls. Yeah, it's a bit
1168 * of a hack, but putting them into PsqlScanStateData would be klugy too.
1169 */
1170 static enum slash_option_type option_type;
1171 static char *option_quote;
1172 static int unquoted_option_chars;
1173 static int backtick_start_offset;
1174
1175
1176 /* Return values from yylex() */
1177 #define LEXRES_EOL 0 /* end of input */
1178 #define LEXRES_OK 1 /* OK completion of backslash argument */
1179
1180
1181 static void evaluate_backtick(PsqlScanState state);
1182
1183 #define ECHO psqlscan_emit(cur_state, yytext, yyleng)
1184
1185 /*
1186 * Work around a bug in flex 2.5.35: it emits a couple of functions that
1187 * it forgets to emit declarations for. Since we use -Wmissing-prototypes,
1188 * this would cause warnings. Providing our own declarations should be
1189 * harmless even when the bug gets fixed.
1190 */
1191 extern int slash_yyget_column(yyscan_t yyscanner);
1192 extern void slash_yyset_column(int column_no, yyscan_t yyscanner);
1193
1194 /* LCOV_EXCL_START */
1195
1196 #line 1197 "psqlscanslash.c"
1197 /* Except for the prefix, these options should match psqlscan.l */
1198 #define YY_NO_INPUT 1
1199 /*
1200 * OK, here is a short description of lex/flex rules behavior.
1201 * The longest pattern which matches an input string is always chosen.
1202 * For equal-length patterns, the first occurring in the rules list is chosen.
1203 * INITIAL is the starting state, to which all non-conditional rules apply.
1204 * Exclusive states change parsing rules while the state is active. When in
1205 * an exclusive state, only those rules defined for that state apply.
1206 */
1207 /* Exclusive states for lexing backslash commands */
1208
1209 /*
1210 * Assorted character class definitions that should match psqlscan.l.
1211 */
1212 #line 1213 "psqlscanslash.c"
1213
1214 #define INITIAL 0
1215 #define xslashcmd 1
1216 #define xslashargstart 2
1217 #define xslasharg 3
1218 #define xslashquote 4
1219 #define xslashbackquote 5
1220 #define xslashdquote 6
1221 #define xslashwholeline 7
1222 #define xslashend 8
1223
1224 #ifndef YY_NO_UNISTD_H
1225 /* Special case for "unistd.h", since it is non-ANSI. We include it way
1226 * down here because we want the user's section 1 to have been scanned first.
1227 * The user has a chance to override it with an option.
1228 */
1229 #include <unistd.h>
1230 #endif
1231
1232 #ifndef YY_EXTRA_TYPE
1233 #define YY_EXTRA_TYPE void *
1234 #endif
1235
1236 /* Holds the entire state of the reentrant scanner. */
1237 struct yyguts_t
1238 {
1239
1240 /* User-defined. Not touched by flex. */
1241 YY_EXTRA_TYPE yyextra_r;
1242
1243 /* The rest are the same as the globals declared in the non-reentrant scanner. */
1244 FILE *yyin_r, *yyout_r;
1245 size_t yy_buffer_stack_top; /**< index of top of stack. */
1246 size_t yy_buffer_stack_max; /**< capacity of stack. */
1247 YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
1248 char yy_hold_char;
1249 int yy_n_chars;
1250 int yyleng_r;
1251 char *yy_c_buf_p;
1252 int yy_init;
1253 int yy_start;
1254 int yy_did_buffer_switch_on_eof;
1255 int yy_start_stack_ptr;
1256 int yy_start_stack_depth;
1257 int *yy_start_stack;
1258 yy_state_type yy_last_accepting_state;
1259 char* yy_last_accepting_cpos;
1260
1261 int yylineno_r;
1262 int yy_flex_debug_r;
1263
1264 char *yytext_r;
1265 int yy_more_flag;
1266 int yy_more_len;
1267
1268 YYSTYPE * yylval_r;
1269
1270 }; /* end struct yyguts_t */
1271
1272 static int yy_init_globals ( yyscan_t yyscanner );
1273
1274 /* This must go here because YYSTYPE and YYLTYPE are included
1275 * from bison output in section 1.*/
1276 # define yylval yyg->yylval_r
1277
1278 int yylex_init (yyscan_t* scanner);
1279
1280 int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner);
1281
1282 /* Accessor methods to globals.
1283 These are made visible to non-reentrant scanners for convenience. */
1284
1285 int yylex_destroy ( yyscan_t yyscanner );
1286
1287 int yyget_debug ( yyscan_t yyscanner );
1288
1289 void yyset_debug ( int debug_flag , yyscan_t yyscanner );
1290
1291 YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
1292
1293 void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
1294
1295 FILE *yyget_in ( yyscan_t yyscanner );
1296
1297 void yyset_in ( FILE * _in_str , yyscan_t yyscanner );
1298
1299 FILE *yyget_out ( yyscan_t yyscanner );
1300
1301 void yyset_out ( FILE * _out_str , yyscan_t yyscanner );
1302
1303 int yyget_leng ( yyscan_t yyscanner );
1304
1305 char *yyget_text ( yyscan_t yyscanner );
1306
1307 int yyget_lineno ( yyscan_t yyscanner );
1308
1309 void yyset_lineno ( int _line_number , yyscan_t yyscanner );
1310
1311 int yyget_column ( yyscan_t yyscanner );
1312
1313 void yyset_column ( int _column_no , yyscan_t yyscanner );
1314
1315 YYSTYPE * yyget_lval ( yyscan_t yyscanner );
1316
1317 void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner );
1318
1319 /* Macros after this point can all be overridden by user definitions in
1320 * section 1.
1321 */
1322
1323 #ifndef YY_SKIP_YYWRAP
1324 #ifdef __cplusplus
1325 extern "C" int yywrap ( yyscan_t yyscanner );
1326 #else
1327 extern int yywrap ( yyscan_t yyscanner );
1328 #endif
1329 #endif
1330
1331 #ifndef YY_NO_UNPUT
1332
1333 #endif
1334
1335 #ifndef yytext_ptr
1336 static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
1337 #endif
1338
1339 #ifdef YY_NEED_STRLEN
1340 static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
1341 #endif
1342
1343 #ifndef YY_NO_INPUT
1344 #ifdef __cplusplus
1345 static int yyinput ( yyscan_t yyscanner );
1346 #else
1347 static int input ( yyscan_t yyscanner );
1348 #endif
1349
1350 #endif
1351
1352 /* Amount of stuff to slurp up with each read. */
1353 #ifndef YY_READ_BUF_SIZE
1354 #ifdef __ia64__
1355 /* On IA-64, the buffer size is 16k, not 8k */
1356 #define YY_READ_BUF_SIZE 16384
1357 #else
1358 #define YY_READ_BUF_SIZE 8192
1359 #endif /* __ia64__ */
1360 #endif
1361
1362 /* Copy whatever the last rule matched to the standard output. */
1363 #ifndef ECHO
1364 /* This used to be an fputs(), but since the string might contain NUL's,
1365 * we now use fwrite().
1366 */
1367 #define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
1368 #endif
1369
1370 /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
1371 * is returned in "result".
1372 */
1373 #ifndef YY_INPUT
1374 #define YY_INPUT(buf,result,max_size) \
1375 if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
1376 { \
1377 int c = '*'; \
1378 int n; \
1379 for ( n = 0; n < max_size && \
1380 (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
1381 buf[n] = (char) c; \
1382 if ( c == '\n' ) \
1383 buf[n++] = (char) c; \
1384 if ( c == EOF && ferror( yyin ) ) \
1385 YY_FATAL_ERROR( "input in flex scanner failed" ); \
1386 result = n; \
1387 } \
1388 else \
1389 { \
1390 errno=0; \
1391 while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
1392 { \
1393 if( errno != EINTR) \
1394 { \
1395 YY_FATAL_ERROR( "input in flex scanner failed" ); \
1396 break; \
1397 } \
1398 errno=0; \
1399 clearerr(yyin); \
1400 } \
1401 }\
1402 \
1403
1404 #endif
1405
1406 /* No semi-colon after return; correct usage is to write "yyterminate();" -
1407 * we don't want an extra ';' after the "return" because that will cause
1408 * some compilers to complain about unreachable statements.
1409 */
1410 #ifndef yyterminate
1411 #define yyterminate() return YY_NULL
1412 #endif
1413
1414 /* Number of entries by which start-condition stack grows. */
1415 #ifndef YY_START_STACK_INCR
1416 #define YY_START_STACK_INCR 25
1417 #endif
1418
1419 /* Report a fatal error. */
1420 #ifndef YY_FATAL_ERROR
1421 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
1422 #endif
1423
1424 /* end tables serialization structures and prototypes */
1425
1426 /* Default declaration of generated scanner - a define so the user can
1427 * easily add parameters.
1428 */
1429 #ifndef YY_DECL
1430 #define YY_DECL_IS_OURS 1
1431
1432 extern int yylex \
1433 (YYSTYPE * yylval_param , yyscan_t yyscanner);
1434
1435 #define YY_DECL int yylex \
1436 (YYSTYPE * yylval_param , yyscan_t yyscanner)
1437 #endif /* !YY_DECL */
1438
1439 /* Code executed at the beginning of each rule, after yytext and yyleng
1440 * have been set up.
1441 */
1442 #ifndef YY_USER_ACTION
1443 #define YY_USER_ACTION
1444 #endif
1445
1446 /* Code executed at the end of each rule. */
1447 #ifndef YY_BREAK
1448 #define YY_BREAK /*LINTED*/break;
1449 #endif
1450
1451 #define YY_RULE_SETUP \
1452 YY_USER_ACTION
1453
1454 /** The main scanner function which does all the work.
1455 */
1456 YY_DECL
1457 {
1458 yy_state_type yy_current_state;
1459 char *yy_cp, *yy_bp;
1460 int yy_act;
1461 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1462
1463 yylval = yylval_param;
1464
1465 if ( !yyg->yy_init )
1466 {
1467 yyg->yy_init = 1;
1468
1469 #ifdef YY_USER_INIT
1470 YY_USER_INIT;
1471 #endif
1472
1473 if ( ! yyg->yy_start )
1474 yyg->yy_start = 1; /* first start state */
1475
1476 if ( ! yyin )
1477 yyin = stdin;
1478
1479 if ( ! yyout )
1480 yyout = stdout;
1481
1482 if ( ! YY_CURRENT_BUFFER ) {
1483 yyensure_buffer_stack (yyscanner);
1484 YY_CURRENT_BUFFER_LVALUE =
1485 yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
1486 }
1487
1488 yy_load_buffer_state( yyscanner );
1489 }
1490
1491 {
1492 #line 119 "psqlscanslash.l"
1493
1494
1495
1496 #line 123 "psqlscanslash.l"
1497 /* Declare some local variables inside yylex(), for convenience */
1498 PsqlScanState cur_state = yyextra;
1499 PQExpBuffer output_buf = cur_state->output_buf;
1500
1501 /*
1502 * Force flex into the state indicated by start_state. This has a
1503 * couple of purposes: it lets some of the functions below set a new
1504 * starting state without ugly direct access to flex variables, and it
1505 * allows us to transition from one flex lexer to another so that we
1506 * can lex different parts of the source string using separate lexers.
1507 */
1508 BEGIN(cur_state->start_state);
1509
1510
1511 /*
1512 * We don't really expect to be invoked in the INITIAL state in this
1513 * lexer; but if we are, just spit data to the output_buf until EOF.
1514 */
1515
1516 #line 1517 "psqlscanslash.c"
1517
1518 while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
1519 {
1520 yy_cp = yyg->yy_c_buf_p;
1521
1522 /* Support of yytext. */
1523 *yy_cp = yyg->yy_hold_char;
1524
1525 /* yy_bp points to the position in yy_ch_buf of the start of
1526 * the current run.
1527 */
1528 yy_bp = yy_cp;
1529
1530 yy_current_state = yyg->yy_start;
1531 yy_match:
1532 while ( (yy_current_state = yy_nxt[yy_current_state][ yy_ec[YY_SC_TO_UI(*yy_cp)] ]) > 0 )
1533 ++yy_cp;
1534
1535 yy_current_state = -yy_current_state;
1536
1537 yy_find_action:
1538 yy_act = yy_accept[yy_current_state];
1539
1540 YY_DO_BEFORE_ACTION;
1541
1542 do_action: /* This label is used only to access EOF actions. */
1543
1544 switch ( yy_act )
1545 { /* beginning of action switch */
1546 case 1:
1547 /* rule 1 can match eol */
1548 YY_RULE_SETUP
1549 #line 142 "psqlscanslash.l"
1550 { ECHO; }
1551 YY_BREAK
1552 /*
1553 * Exclusive lexer states to handle backslash command lexing
1554 */
1555
1556 /* command name ends at whitespace or backslash; eat all else */
1557 case 2:
1558 /* rule 2 can match eol */
1559 YY_RULE_SETUP
1560 #line 151 "psqlscanslash.l"
1561 {
1562 yyless(0);
1563 cur_state->start_state = YY_START;
1564 return LEXRES_OK;
1565 }
1566 YY_BREAK
1567 case 3:
1568 YY_RULE_SETUP
1569 #line 157 "psqlscanslash.l"
1570 { ECHO; }
1571 YY_BREAK
1572
1573
1574 /*
1575 * Discard any whitespace before argument, then go to xslasharg state.
1576 * An exception is that "|" is only special at start of argument, so we
1577 * check for it here.
1578 */
1579 case 4:
1580 /* rule 4 can match eol */
1581 YY_RULE_SETUP
1582 #line 168 "psqlscanslash.l"
1583 { }
1584 YY_BREAK
1585 case 5:
1586 YY_RULE_SETUP
1587 #line 170 "psqlscanslash.l"
1588 {
1589 if (option_type == OT_FILEPIPE)
1590 {
1591 /* treat like whole-string case */
1592 ECHO;
1593 BEGIN(xslashwholeline);
1594 }
1595 else
1596 {
1597 /* vertical bar is not special otherwise */
1598 yyless(0);
1599 BEGIN(xslasharg);
1600 }
1601 }
1602 YY_BREAK
1603 case 6:
1604 YY_RULE_SETUP
1605 #line 185 "psqlscanslash.l"
1606 {
1607 yyless(0);
1608 BEGIN(xslasharg);
1609 }
1610 YY_BREAK
1611
1612
1613 /*
1614 * Default processing of text in a slash command's argument.
1615 *
1616 * Note: unquoted_option_chars counts the number of characters at the
1617 * end of the argument that were not subject to any form of quoting.
1618 * psql_scan_slash_option needs this to strip trailing semicolons safely.
1619 */
1620 case 7:
1621 /* rule 7 can match eol */
1622 YY_RULE_SETUP
1623 #line 201 "psqlscanslash.l"
1624 {
1625 /*
1626 * Unquoted space is end of arg; do not eat. Likewise
1627 * backslash is end of command or next command, do not eat
1628 *
1629 * XXX this means we can't conveniently accept options
1630 * that include unquoted backslashes; therefore, option
1631 * processing that encourages use of backslashes is rather
1632 * broken.
1633 */
1634 yyless(0);
1635 cur_state->start_state = YY_START;
1636 return LEXRES_OK;
1637 }
1638 YY_BREAK
1639 case 8:
1640 YY_RULE_SETUP
1641 #line 216 "psqlscanslash.l"
1642 {
1643 *option_quote = '\'';
1644 unquoted_option_chars = 0;
1645 BEGIN(xslashquote);
1646 }
1647 YY_BREAK
1648 case 9:
1649 YY_RULE_SETUP
1650 #line 222 "psqlscanslash.l"
1651 {
1652 backtick_start_offset = output_buf->len;
1653 *option_quote = '`';
1654 unquoted_option_chars = 0;
1655 BEGIN(xslashbackquote);
1656 }
1657 YY_BREAK
1658 case 10:
1659 YY_RULE_SETUP
1660 #line 229 "psqlscanslash.l"
1661 {
1662 ECHO;
1663 *option_quote = '"';
1664 unquoted_option_chars = 0;
1665 BEGIN(xslashdquote);
1666 }
1667 YY_BREAK
1668 case 11:
1669 YY_RULE_SETUP
1670 #line 236 "psqlscanslash.l"
1671 {
1672 /* Possible psql variable substitution */
1673 if (cur_state->callbacks->get_variable == NULL)
1674 ECHO;
1675 else
1676 {
1677 char *varname;
1678 char *value;
1679
1680 varname = psqlscan_extract_substring(cur_state,
1681 yytext + 1,
1682 yyleng - 1);
1683 value = cur_state->callbacks->get_variable(varname,
1684 PQUOTE_PLAIN,
1685 cur_state->cb_passthrough);
1686 free(varname);
1687
1688 /*
1689 * The variable value is just emitted without any
1690 * further examination. This is consistent with the
1691 * pre-8.0 code behavior, if not with the way that
1692 * variables are handled outside backslash commands.
1693 * Note that we needn't guard against recursion here.
1694 */
1695 if (value)
1696 {
1697 appendPQExpBufferStr(output_buf, value);
1698 free(value);
1699 }
1700 else
1701 ECHO;
1702
1703 *option_quote = ':';
1704 }
1705 unquoted_option_chars = 0;
1706 }
1707 YY_BREAK
1708 case 12:
1709 YY_RULE_SETUP
1710 #line 273 "psqlscanslash.l"
1711 {
1712 psqlscan_escape_variable(cur_state, yytext, yyleng,
1713 PQUOTE_SQL_LITERAL);
1714 *option_quote = ':';
1715 unquoted_option_chars = 0;
1716 }
1717 YY_BREAK
1718 case 13:
1719 YY_RULE_SETUP
1720 #line 281 "psqlscanslash.l"
1721 {
1722 psqlscan_escape_variable(cur_state, yytext, yyleng,
1723 PQUOTE_SQL_IDENT);
1724 *option_quote = ':';
1725 unquoted_option_chars = 0;
1726 }
1727 YY_BREAK
1728 case 14:
1729 YY_RULE_SETUP
1730 #line 288 "psqlscanslash.l"
1731 {
1732 psqlscan_test_variable(cur_state, yytext, yyleng);
1733 }
1734 YY_BREAK
1735 case 15:
1736 YY_RULE_SETUP
1737 #line 292 "psqlscanslash.l"
1738 {
1739 /* Throw back everything but the colon */
1740 yyless(1);
1741 unquoted_option_chars++;
1742 ECHO;
1743 }
1744 YY_BREAK
1745 case 16:
1746 YY_RULE_SETUP
1747 #line 299 "psqlscanslash.l"
1748 {
1749 /* Throw back everything but the colon */
1750 yyless(1);
1751 unquoted_option_chars++;
1752 ECHO;
1753 }
1754 YY_BREAK
1755 case 17:
1756 YY_RULE_SETUP
1757 #line 306 "psqlscanslash.l"
1758 {
1759 /* Throw back everything but the colon */
1760 yyless(1);
1761 unquoted_option_chars++;
1762 ECHO;
1763 }
1764 YY_BREAK
1765 case 18:
1766 YY_RULE_SETUP
1767 #line 313 "psqlscanslash.l"
1768 {
1769 /* Throw back everything but the colon */
1770 yyless(1);
1771 unquoted_option_chars++;
1772 ECHO;
1773 }
1774 YY_BREAK
1775 case 19:
1776 YY_RULE_SETUP
1777 #line 320 "psqlscanslash.l"
1778 {
1779 unquoted_option_chars++;
1780 ECHO;
1781 }
1782 YY_BREAK
1783
1784
1785 /*
1786 * single-quoted text: copy literally except for '' and backslash
1787 * sequences
1788 */
1789 case 20:
1790 YY_RULE_SETUP
1791 #line 333 "psqlscanslash.l"
1792 { BEGIN(xslasharg); }
1793 YY_BREAK
1794 case 21:
1795 YY_RULE_SETUP
1796 #line 335 "psqlscanslash.l"
1797 { appendPQExpBufferChar(output_buf, '\''); }
1798 YY_BREAK
1799 case 22:
1800 YY_RULE_SETUP
1801 #line 337 "psqlscanslash.l"
1802 { appendPQExpBufferChar(output_buf, '\n'); }
1803 YY_BREAK
1804 case 23:
1805 YY_RULE_SETUP
1806 #line 338 "psqlscanslash.l"
1807 { appendPQExpBufferChar(output_buf, '\t'); }
1808 YY_BREAK
1809 case 24:
1810 YY_RULE_SETUP
1811 #line 339 "psqlscanslash.l"
1812 { appendPQExpBufferChar(output_buf, '\b'); }
1813 YY_BREAK
1814 case 25:
1815 YY_RULE_SETUP
1816 #line 340 "psqlscanslash.l"
1817 { appendPQExpBufferChar(output_buf, '\r'); }
1818 YY_BREAK
1819 case 26:
1820 YY_RULE_SETUP
1821 #line 341 "psqlscanslash.l"
1822 { appendPQExpBufferChar(output_buf, '\f'); }
1823 YY_BREAK
1824 case 27:
1825 YY_RULE_SETUP
1826 #line 343 "psqlscanslash.l"
1827 {
1828 /* octal case */
1829 appendPQExpBufferChar(output_buf,
1830 (char) strtol(yytext + 1, NULL, 8));
1831 }
1832 YY_BREAK
1833 case 28:
1834 YY_RULE_SETUP
1835 #line 349 "psqlscanslash.l"
1836 {
1837 /* hex case */
1838 appendPQExpBufferChar(output_buf,
1839 (char) strtol(yytext + 2, NULL, 16));
1840 }
1841 YY_BREAK
1842 case 29:
1843 YY_RULE_SETUP
1844 #line 355 "psqlscanslash.l"
1845 { psqlscan_emit(cur_state, yytext + 1, 1); }
1846 YY_BREAK
1847 case 30:
1848 /* rule 30 can match eol */
1849 YY_RULE_SETUP
1850 #line 357 "psqlscanslash.l"
1851 { ECHO; }
1852 YY_BREAK
1853
1854
1855 /*
1856 * backticked text: copy everything until next backquote (expanding
1857 * variable references, but doing nought else), then evaluate.
1858 */
1859 case 31:
1860 YY_RULE_SETUP
1861 #line 367 "psqlscanslash.l"
1862 {
1863 /* In an inactive \if branch, don't evaluate the command */
1864 if (cur_state->cb_passthrough == NULL ||
1865 conditional_active((ConditionalStack) cur_state->cb_passthrough))
1866 evaluate_backtick(cur_state);
1867 BEGIN(xslasharg);
1868 }
1869 YY_BREAK
1870 case 32:
1871 YY_RULE_SETUP
1872 #line 375 "psqlscanslash.l"
1873 {
1874 /* Possible psql variable substitution */
1875 if (cur_state->callbacks->get_variable == NULL)
1876 ECHO;
1877 else
1878 {
1879 char *varname;
1880 char *value;
1881
1882 varname = psqlscan_extract_substring(cur_state,
1883 yytext + 1,
1884 yyleng - 1);
1885 value = cur_state->callbacks->get_variable(varname,
1886 PQUOTE_PLAIN,
1887 cur_state->cb_passthrough);
1888 free(varname);
1889
1890 if (value)
1891 {
1892 appendPQExpBufferStr(output_buf, value);
1893 free(value);
1894 }
1895 else
1896 ECHO;
1897 }
1898 }
1899 YY_BREAK
1900 case 33:
1901 YY_RULE_SETUP
1902 #line 402 "psqlscanslash.l"
1903 {
1904 psqlscan_escape_variable(cur_state, yytext, yyleng,
1905 PQUOTE_SHELL_ARG);
1906 }
1907 YY_BREAK
1908 case 34:
1909 YY_RULE_SETUP
1910 #line 407 "psqlscanslash.l"
1911 {
1912 /* Throw back everything but the colon */
1913 yyless(1);
1914 ECHO;
1915 }
1916 YY_BREAK
1917 case 35:
1918 /* rule 35 can match eol */
1919 YY_RULE_SETUP
1920 #line 413 "psqlscanslash.l"
1921 { ECHO; }
1922 YY_BREAK
1923
1924
1925 /* double-quoted text: copy verbatim, including the double quotes */
1926 case 36:
1927 YY_RULE_SETUP
1928 #line 420 "psqlscanslash.l"
1929 {
1930 ECHO;
1931 BEGIN(xslasharg);
1932 }
1933 YY_BREAK
1934 case 37:
1935 /* rule 37 can match eol */
1936 YY_RULE_SETUP
1937 #line 425 "psqlscanslash.l"
1938 { ECHO; }
1939 YY_BREAK
1940
1941
1942 /* copy everything until end of input line */
1943 /* but suppress leading whitespace */
1944 case 38:
1945 /* rule 38 can match eol */
1946 YY_RULE_SETUP
1947 #line 433 "psqlscanslash.l"
1948 {
1949 if (output_buf->len > 0)
1950 ECHO;
1951 }
1952 YY_BREAK
1953 case 39:
1954 YY_RULE_SETUP
1955 #line 438 "psqlscanslash.l"
1956 { ECHO; }
1957 YY_BREAK
1958
1959
1960 /* at end of command, eat a double backslash, but not anything else */
1961 case 40:
1962 YY_RULE_SETUP
1963 #line 445 "psqlscanslash.l"
1964 {
1965 cur_state->start_state = YY_START;
1966 return LEXRES_OK;
1967 }
1968 YY_BREAK
1969 case 41:
1970 /* rule 41 can match eol */
1971 YY_RULE_SETUP
1972 #line 450 "psqlscanslash.l"
1973 {
1974 yyless(0);
1975 cur_state->start_state = YY_START;
1976 return LEXRES_OK;
1977 }
1978 YY_BREAK
1979
1980 case YY_STATE_EOF(INITIAL):
1981 case YY_STATE_EOF(xslashcmd):
1982 case YY_STATE_EOF(xslashargstart):
1983 case YY_STATE_EOF(xslasharg):
1984 case YY_STATE_EOF(xslashquote):
1985 case YY_STATE_EOF(xslashbackquote):
1986 case YY_STATE_EOF(xslashdquote):
1987 case YY_STATE_EOF(xslashwholeline):
1988 case YY_STATE_EOF(xslashend):
1989 #line 458 "psqlscanslash.l"
1990 {
1991 if (cur_state->buffer_stack == NULL)
1992 {
1993 cur_state->start_state = YY_START;
1994 return LEXRES_EOL; /* end of input reached */
1995 }
1996
1997 /*
1998 * We were expanding a variable, so pop the inclusion
1999 * stack and keep lexing
2000 */
2001 psqlscan_pop_buffer_stack(cur_state);
2002 psqlscan_select_top_buffer(cur_state);
2003 }
2004 YY_BREAK
2005 case 42:
2006 YY_RULE_SETUP
2007 #line 473 "psqlscanslash.l"
2008 YY_FATAL_ERROR( "flex scanner jammed" );
2009 YY_BREAK
2010 #line 2011 "psqlscanslash.c"
2011
2012 case YY_END_OF_BUFFER:
2013 {
2014 /* Amount of text matched not including the EOB char. */
2015 int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
2016
2017 /* Undo the effects of YY_DO_BEFORE_ACTION. */
2018 *yy_cp = yyg->yy_hold_char;
2019 YY_RESTORE_YY_MORE_OFFSET
2020
2021 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
2022 {
2023 /* We're scanning a new file or input source. It's
2024 * possible that this happened because the user
2025 * just pointed yyin at a new source and called
2026 * yylex(). If so, then we have to assure
2027 * consistency between YY_CURRENT_BUFFER and our
2028 * globals. Here is the right place to do so, because
2029 * this is the first action (other than possibly a
2030 * back-up) that will match for the new input source.
2031 */
2032 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
2033 YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
2034 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
2035 }
2036
2037 /* Note that here we test for yy_c_buf_p "<=" to the position
2038 * of the first EOB in the buffer, since yy_c_buf_p will
2039 * already have been incremented past the NUL character
2040 * (since all states make transitions on EOB to the
2041 * end-of-buffer state). Contrast this with the test
2042 * in input().
2043 */
2044 if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
2045 { /* This was really a NUL. */
2046 yy_state_type yy_next_state;
2047
2048 yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
2049
2050 yy_current_state = yy_get_previous_state( yyscanner );
2051
2052 /* Okay, we're now positioned to make the NUL
2053 * transition. We couldn't have
2054 * yy_get_previous_state() go ahead and do it
2055 * for us because it doesn't know how to deal
2056 * with the possibility of jamming (and we don't
2057 * want to build jamming into it because then it
2058 * will run more slowly).
2059 */
2060
2061 yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
2062
2063 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
2064
2065 if ( yy_next_state )
2066 {
2067 /* Consume the NUL. */
2068 yy_cp = ++yyg->yy_c_buf_p;
2069 yy_current_state = yy_next_state;
2070 goto yy_match;
2071 }
2072
2073 else
2074 {
2075 yy_cp = yyg->yy_c_buf_p;
2076 goto yy_find_action;
2077 }
2078 }
2079
2080 else switch ( yy_get_next_buffer( yyscanner ) )
2081 {
2082 case EOB_ACT_END_OF_FILE:
2083 {
2084 yyg->yy_did_buffer_switch_on_eof = 0;
2085
2086 if ( yywrap( yyscanner ) )
2087 {
2088 /* Note: because we've taken care in
2089 * yy_get_next_buffer() to have set up
2090 * yytext, we can now set up
2091 * yy_c_buf_p so that if some total
2092 * hoser (like flex itself) wants to
2093 * call the scanner after we return the
2094 * YY_NULL, it'll still work - another
2095 * YY_NULL will get returned.
2096 */
2097 yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
2098
2099 yy_act = YY_STATE_EOF(YY_START);
2100 goto do_action;
2101 }
2102
2103 else
2104 {
2105 if ( ! yyg->yy_did_buffer_switch_on_eof )
2106 YY_NEW_FILE;
2107 }
2108 break;
2109 }
2110
2111 case EOB_ACT_CONTINUE_SCAN:
2112 yyg->yy_c_buf_p =
2113 yyg->yytext_ptr + yy_amount_of_matched_text;
2114
2115 yy_current_state = yy_get_previous_state( yyscanner );
2116
2117 yy_cp = yyg->yy_c_buf_p;
2118 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
2119 goto yy_match;
2120
2121 case EOB_ACT_LAST_MATCH:
2122 yyg->yy_c_buf_p =
2123 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
2124
2125 yy_current_state = yy_get_previous_state( yyscanner );
2126
2127 yy_cp = yyg->yy_c_buf_p;
2128 yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
2129 goto yy_find_action;
2130 }
2131 break;
2132 }
2133
2134 default:
2135 YY_FATAL_ERROR(
2136 "fatal flex scanner internal error--no action found" );
2137 } /* end of action switch */
2138 } /* end of scanning one token */
2139 } /* end of user's declarations */
2140 } /* end of yylex */
2141
2142 /* yy_get_next_buffer - try to read in a new buffer
2143 *
2144 * Returns a code representing an action:
2145 * EOB_ACT_LAST_MATCH -
2146 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
2147 * EOB_ACT_END_OF_FILE - end of file
2148 */
yy_get_next_buffer(yyscan_t yyscanner)2149 static int yy_get_next_buffer (yyscan_t yyscanner)
2150 {
2151 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2152 char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
2153 char *source = yyg->yytext_ptr;
2154 int number_to_move, i;
2155 int ret_val;
2156
2157 if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
2158 YY_FATAL_ERROR(
2159 "fatal flex scanner internal error--end of buffer missed" );
2160
2161 if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
2162 { /* Don't try to fill the buffer, so this is an EOF. */
2163 if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
2164 {
2165 /* We matched a single character, the EOB, so
2166 * treat this as a final EOF.
2167 */
2168 return EOB_ACT_END_OF_FILE;
2169 }
2170
2171 else
2172 {
2173 /* We matched some text prior to the EOB, first
2174 * process it.
2175 */
2176 return EOB_ACT_LAST_MATCH;
2177 }
2178 }
2179
2180 /* Try to read more data. */
2181
2182 /* First move last chars to start of buffer. */
2183 number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
2184
2185 for ( i = 0; i < number_to_move; ++i )
2186 *(dest++) = *(source++);
2187
2188 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
2189 /* don't do the read, it's not guaranteed to return an EOF,
2190 * just force an EOF
2191 */
2192 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
2193
2194 else
2195 {
2196 int num_to_read =
2197 YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
2198
2199 while ( num_to_read <= 0 )
2200 { /* Not enough room in the buffer - grow it. */
2201
2202 /* just a shorter name for the current buffer */
2203 YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
2204
2205 int yy_c_buf_p_offset =
2206 (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
2207
2208 if ( b->yy_is_our_buffer )
2209 {
2210 int new_size = b->yy_buf_size * 2;
2211
2212 if ( new_size <= 0 )
2213 b->yy_buf_size += b->yy_buf_size / 8;
2214 else
2215 b->yy_buf_size *= 2;
2216
2217 b->yy_ch_buf = (char *)
2218 /* Include room in for 2 EOB chars. */
2219 yyrealloc( (void *) b->yy_ch_buf,
2220 (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
2221 }
2222 else
2223 /* Can't grow it, we don't own it. */
2224 b->yy_ch_buf = NULL;
2225
2226 if ( ! b->yy_ch_buf )
2227 YY_FATAL_ERROR(
2228 "fatal error - scanner input buffer overflow" );
2229
2230 yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
2231
2232 num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
2233 number_to_move - 1;
2234
2235 }
2236
2237 if ( num_to_read > YY_READ_BUF_SIZE )
2238 num_to_read = YY_READ_BUF_SIZE;
2239
2240 /* Read in more data. */
2241 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
2242 yyg->yy_n_chars, num_to_read );
2243
2244 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2245 }
2246
2247 if ( yyg->yy_n_chars == 0 )
2248 {
2249 if ( number_to_move == YY_MORE_ADJ )
2250 {
2251 ret_val = EOB_ACT_END_OF_FILE;
2252 yyrestart( yyin , yyscanner);
2253 }
2254
2255 else
2256 {
2257 ret_val = EOB_ACT_LAST_MATCH;
2258 YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
2259 YY_BUFFER_EOF_PENDING;
2260 }
2261 }
2262
2263 else
2264 ret_val = EOB_ACT_CONTINUE_SCAN;
2265
2266 if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
2267 /* Extend the array by 50%, plus the number we really need. */
2268 int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
2269 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
2270 (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
2271 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
2272 YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
2273 /* "- 2" to take care of EOB's */
2274 YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
2275 }
2276
2277 yyg->yy_n_chars += number_to_move;
2278 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
2279 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
2280
2281 yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
2282
2283 return ret_val;
2284 }
2285
2286 /* yy_get_previous_state - get the state just before the EOB char was reached */
2287
yy_get_previous_state(yyscan_t yyscanner)2288 static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
2289 {
2290 yy_state_type yy_current_state;
2291 char *yy_cp;
2292 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2293
2294 yy_current_state = yyg->yy_start;
2295
2296 for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
2297 {
2298 yy_current_state = yy_nxt[yy_current_state][(*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1)];
2299 }
2300
2301 return yy_current_state;
2302 }
2303
2304 /* yy_try_NUL_trans - try to make a transition on the NUL character
2305 *
2306 * synopsis
2307 * next_state = yy_try_NUL_trans( current_state );
2308 */
yy_try_NUL_trans(yy_state_type yy_current_state,yyscan_t yyscanner)2309 static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner)
2310 {
2311 int yy_is_jam;
2312 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
2313
2314 yy_current_state = yy_nxt[yy_current_state][1];
2315 yy_is_jam = (yy_current_state <= 0);
2316
2317 (void)yyg;
2318 return yy_is_jam ? 0 : yy_current_state;
2319 }
2320
2321 #ifndef YY_NO_UNPUT
2322
2323 #endif
2324
2325 #ifndef YY_NO_INPUT
2326 #ifdef __cplusplus
yyinput(yyscan_t yyscanner)2327 static int yyinput (yyscan_t yyscanner)
2328 #else
2329 static int input (yyscan_t yyscanner)
2330 #endif
2331
2332 {
2333 int c;
2334 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2335
2336 *yyg->yy_c_buf_p = yyg->yy_hold_char;
2337
2338 if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
2339 {
2340 /* yy_c_buf_p now points to the character we want to return.
2341 * If this occurs *before* the EOB characters, then it's a
2342 * valid NUL; if not, then we've hit the end of the buffer.
2343 */
2344 if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
2345 /* This was really a NUL. */
2346 *yyg->yy_c_buf_p = '\0';
2347
2348 else
2349 { /* need more input */
2350 int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
2351 ++yyg->yy_c_buf_p;
2352
2353 switch ( yy_get_next_buffer( yyscanner ) )
2354 {
2355 case EOB_ACT_LAST_MATCH:
2356 /* This happens because yy_g_n_b()
2357 * sees that we've accumulated a
2358 * token and flags that we need to
2359 * try matching the token before
2360 * proceeding. But for input(),
2361 * there's no matching to consider.
2362 * So convert the EOB_ACT_LAST_MATCH
2363 * to EOB_ACT_END_OF_FILE.
2364 */
2365
2366 /* Reset buffer status. */
2367 yyrestart( yyin , yyscanner);
2368
2369 /*FALLTHROUGH*/
2370
2371 case EOB_ACT_END_OF_FILE:
2372 {
2373 if ( yywrap( yyscanner ) )
2374 return 0;
2375
2376 if ( ! yyg->yy_did_buffer_switch_on_eof )
2377 YY_NEW_FILE;
2378 #ifdef __cplusplus
2379 return yyinput(yyscanner);
2380 #else
2381 return input(yyscanner);
2382 #endif
2383 }
2384
2385 case EOB_ACT_CONTINUE_SCAN:
2386 yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
2387 break;
2388 }
2389 }
2390 }
2391
2392 c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
2393 *yyg->yy_c_buf_p = '\0'; /* preserve yytext */
2394 yyg->yy_hold_char = *++yyg->yy_c_buf_p;
2395
2396 return c;
2397 }
2398 #endif /* ifndef YY_NO_INPUT */
2399
2400 /** Immediately switch to a different input stream.
2401 * @param input_file A readable stream.
2402 * @param yyscanner The scanner object.
2403 * @note This function does not reset the start condition to @c INITIAL .
2404 */
yyrestart(FILE * input_file,yyscan_t yyscanner)2405 void yyrestart (FILE * input_file , yyscan_t yyscanner)
2406 {
2407 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2408
2409 if ( ! YY_CURRENT_BUFFER ){
2410 yyensure_buffer_stack (yyscanner);
2411 YY_CURRENT_BUFFER_LVALUE =
2412 yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
2413 }
2414
2415 yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
2416 yy_load_buffer_state( yyscanner );
2417 }
2418
2419 /** Switch to a different input buffer.
2420 * @param new_buffer The new input buffer.
2421 * @param yyscanner The scanner object.
2422 */
yy_switch_to_buffer(YY_BUFFER_STATE new_buffer,yyscan_t yyscanner)2423 void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
2424 {
2425 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2426
2427 /* TODO. We should be able to replace this entire function body
2428 * with
2429 * yypop_buffer_state();
2430 * yypush_buffer_state(new_buffer);
2431 */
2432 yyensure_buffer_stack (yyscanner);
2433 if ( YY_CURRENT_BUFFER == new_buffer )
2434 return;
2435
2436 if ( YY_CURRENT_BUFFER )
2437 {
2438 /* Flush out information for old buffer. */
2439 *yyg->yy_c_buf_p = yyg->yy_hold_char;
2440 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
2441 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2442 }
2443
2444 YY_CURRENT_BUFFER_LVALUE = new_buffer;
2445 yy_load_buffer_state( yyscanner );
2446
2447 /* We don't actually know whether we did this switch during
2448 * EOF (yywrap()) processing, but the only time this flag
2449 * is looked at is after yywrap() is called, so it's safe
2450 * to go ahead and always set it.
2451 */
2452 yyg->yy_did_buffer_switch_on_eof = 1;
2453 }
2454
yy_load_buffer_state(yyscan_t yyscanner)2455 static void yy_load_buffer_state (yyscan_t yyscanner)
2456 {
2457 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2458 yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
2459 yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
2460 yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
2461 yyg->yy_hold_char = *yyg->yy_c_buf_p;
2462 }
2463
2464 /** Allocate and initialize an input buffer state.
2465 * @param file A readable stream.
2466 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
2467 * @param yyscanner The scanner object.
2468 * @return the allocated buffer state.
2469 */
yy_create_buffer(FILE * file,int size,yyscan_t yyscanner)2470 YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner)
2471 {
2472 YY_BUFFER_STATE b;
2473
2474 b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
2475 if ( ! b )
2476 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
2477
2478 b->yy_buf_size = size;
2479
2480 /* yy_ch_buf has to be 2 characters longer than the size given because
2481 * we need to put in 2 end-of-buffer characters.
2482 */
2483 b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
2484 if ( ! b->yy_ch_buf )
2485 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
2486
2487 b->yy_is_our_buffer = 1;
2488
2489 yy_init_buffer( b, file , yyscanner);
2490
2491 return b;
2492 }
2493
2494 /** Destroy the buffer.
2495 * @param b a buffer created with yy_create_buffer()
2496 * @param yyscanner The scanner object.
2497 */
yy_delete_buffer(YY_BUFFER_STATE b,yyscan_t yyscanner)2498 void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
2499 {
2500 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2501
2502 if ( ! b )
2503 return;
2504
2505 if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
2506 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
2507
2508 if ( b->yy_is_our_buffer )
2509 yyfree( (void *) b->yy_ch_buf , yyscanner );
2510
2511 yyfree( (void *) b , yyscanner );
2512 }
2513
2514 /* Initializes or reinitializes a buffer.
2515 * This function is sometimes called more than once on the same buffer,
2516 * such as during a yyrestart() or at EOF.
2517 */
yy_init_buffer(YY_BUFFER_STATE b,FILE * file,yyscan_t yyscanner)2518 static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner)
2519
2520 {
2521 int oerrno = errno;
2522 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2523
2524 yy_flush_buffer( b , yyscanner);
2525
2526 b->yy_input_file = file;
2527 b->yy_fill_buffer = 1;
2528
2529 /* If b is the current buffer, then yy_init_buffer was _probably_
2530 * called from yyrestart() or through yy_get_next_buffer.
2531 * In that case, we don't want to reset the lineno or column.
2532 */
2533 if (b != YY_CURRENT_BUFFER){
2534 b->yy_bs_lineno = 1;
2535 b->yy_bs_column = 0;
2536 }
2537
2538 b->yy_is_interactive = 0;
2539
2540 errno = oerrno;
2541 }
2542
2543 /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
2544 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
2545 * @param yyscanner The scanner object.
2546 */
yy_flush_buffer(YY_BUFFER_STATE b,yyscan_t yyscanner)2547 void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner)
2548 {
2549 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2550 if ( ! b )
2551 return;
2552
2553 b->yy_n_chars = 0;
2554
2555 /* We always need two end-of-buffer characters. The first causes
2556 * a transition to the end-of-buffer state. The second causes
2557 * a jam in that state.
2558 */
2559 b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
2560 b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
2561
2562 b->yy_buf_pos = &b->yy_ch_buf[0];
2563
2564 b->yy_at_bol = 1;
2565 b->yy_buffer_status = YY_BUFFER_NEW;
2566
2567 if ( b == YY_CURRENT_BUFFER )
2568 yy_load_buffer_state( yyscanner );
2569 }
2570
2571 /** Pushes the new state onto the stack. The new state becomes
2572 * the current state. This function will allocate the stack
2573 * if necessary.
2574 * @param new_buffer The new state.
2575 * @param yyscanner The scanner object.
2576 */
yypush_buffer_state(YY_BUFFER_STATE new_buffer,yyscan_t yyscanner)2577 void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
2578 {
2579 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2580 if (new_buffer == NULL)
2581 return;
2582
2583 yyensure_buffer_stack(yyscanner);
2584
2585 /* This block is copied from yy_switch_to_buffer. */
2586 if ( YY_CURRENT_BUFFER )
2587 {
2588 /* Flush out information for old buffer. */
2589 *yyg->yy_c_buf_p = yyg->yy_hold_char;
2590 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
2591 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
2592 }
2593
2594 /* Only push if top exists. Otherwise, replace top. */
2595 if (YY_CURRENT_BUFFER)
2596 yyg->yy_buffer_stack_top++;
2597 YY_CURRENT_BUFFER_LVALUE = new_buffer;
2598
2599 /* copied from yy_switch_to_buffer. */
2600 yy_load_buffer_state( yyscanner );
2601 yyg->yy_did_buffer_switch_on_eof = 1;
2602 }
2603
2604 /** Removes and deletes the top of the stack, if present.
2605 * The next element becomes the new top.
2606 * @param yyscanner The scanner object.
2607 */
yypop_buffer_state(yyscan_t yyscanner)2608 void yypop_buffer_state (yyscan_t yyscanner)
2609 {
2610 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2611 if (!YY_CURRENT_BUFFER)
2612 return;
2613
2614 yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner);
2615 YY_CURRENT_BUFFER_LVALUE = NULL;
2616 if (yyg->yy_buffer_stack_top > 0)
2617 --yyg->yy_buffer_stack_top;
2618
2619 if (YY_CURRENT_BUFFER) {
2620 yy_load_buffer_state( yyscanner );
2621 yyg->yy_did_buffer_switch_on_eof = 1;
2622 }
2623 }
2624
2625 /* Allocates the stack if it does not exist.
2626 * Guarantees space for at least one push.
2627 */
yyensure_buffer_stack(yyscan_t yyscanner)2628 static void yyensure_buffer_stack (yyscan_t yyscanner)
2629 {
2630 yy_size_t num_to_alloc;
2631 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2632
2633 if (!yyg->yy_buffer_stack) {
2634
2635 /* First allocation is just for 2 elements, since we don't know if this
2636 * scanner will even need a stack. We use 2 instead of 1 to avoid an
2637 * immediate realloc on the next call.
2638 */
2639 num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
2640 yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
2641 (num_to_alloc * sizeof(struct yy_buffer_state*)
2642 , yyscanner);
2643 if ( ! yyg->yy_buffer_stack )
2644 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2645
2646 memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
2647
2648 yyg->yy_buffer_stack_max = num_to_alloc;
2649 yyg->yy_buffer_stack_top = 0;
2650 return;
2651 }
2652
2653 if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
2654
2655 /* Increase the buffer to prepare for a possible push. */
2656 yy_size_t grow_size = 8 /* arbitrary grow size */;
2657
2658 num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
2659 yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
2660 (yyg->yy_buffer_stack,
2661 num_to_alloc * sizeof(struct yy_buffer_state*)
2662 , yyscanner);
2663 if ( ! yyg->yy_buffer_stack )
2664 YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2665
2666 /* zero only the new slots.*/
2667 memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
2668 yyg->yy_buffer_stack_max = num_to_alloc;
2669 }
2670 }
2671
2672 /** Setup the input buffer state to scan directly from a user-specified character buffer.
2673 * @param base the character buffer
2674 * @param size the size in bytes of the character buffer
2675 * @param yyscanner The scanner object.
2676 * @return the newly allocated buffer state object.
2677 */
yy_scan_buffer(char * base,yy_size_t size,yyscan_t yyscanner)2678 YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner)
2679 {
2680 YY_BUFFER_STATE b;
2681
2682 if ( size < 2 ||
2683 base[size-2] != YY_END_OF_BUFFER_CHAR ||
2684 base[size-1] != YY_END_OF_BUFFER_CHAR )
2685 /* They forgot to leave room for the EOB's. */
2686 return NULL;
2687
2688 b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
2689 if ( ! b )
2690 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
2691
2692 b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
2693 b->yy_buf_pos = b->yy_ch_buf = base;
2694 b->yy_is_our_buffer = 0;
2695 b->yy_input_file = NULL;
2696 b->yy_n_chars = b->yy_buf_size;
2697 b->yy_is_interactive = 0;
2698 b->yy_at_bol = 1;
2699 b->yy_fill_buffer = 0;
2700 b->yy_buffer_status = YY_BUFFER_NEW;
2701
2702 yy_switch_to_buffer( b , yyscanner );
2703
2704 return b;
2705 }
2706
2707 /** Setup the input buffer state to scan a string. The next call to yylex() will
2708 * scan from a @e copy of @a str.
2709 * @param yystr a NUL-terminated string to scan
2710 * @param yyscanner The scanner object.
2711 * @return the newly allocated buffer state object.
2712 * @note If you want to scan bytes that may contain NUL values, then use
2713 * yy_scan_bytes() instead.
2714 */
yy_scan_string(const char * yystr,yyscan_t yyscanner)2715 YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
2716 {
2717
2718 return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
2719 }
2720
2721 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
2722 * scan from a @e copy of @a bytes.
2723 * @param yybytes the byte buffer to scan
2724 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
2725 * @param yyscanner The scanner object.
2726 * @return the newly allocated buffer state object.
2727 */
yy_scan_bytes(const char * yybytes,int _yybytes_len,yyscan_t yyscanner)2728 YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len , yyscan_t yyscanner)
2729 {
2730 YY_BUFFER_STATE b;
2731 char *buf;
2732 yy_size_t n;
2733 int i;
2734
2735 /* Get memory for full buffer, including space for trailing EOB's. */
2736 n = (yy_size_t) (_yybytes_len + 2);
2737 buf = (char *) yyalloc( n , yyscanner );
2738 if ( ! buf )
2739 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
2740
2741 for ( i = 0; i < _yybytes_len; ++i )
2742 buf[i] = yybytes[i];
2743
2744 buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2745
2746 b = yy_scan_buffer( buf, n , yyscanner);
2747 if ( ! b )
2748 YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
2749
2750 /* It's okay to grow etc. this buffer, and we should throw it
2751 * away when we're done.
2752 */
2753 b->yy_is_our_buffer = 1;
2754
2755 return b;
2756 }
2757
2758 #ifndef YY_EXIT_FAILURE
2759 #define YY_EXIT_FAILURE 2
2760 #endif
2761
yy_fatal_error(const char * msg,yyscan_t yyscanner)2762 static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
2763 {
2764 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2765 (void)yyg;
2766 fprintf( stderr, "%s\n", msg );
2767 exit( YY_EXIT_FAILURE );
2768 }
2769
2770 /* Redefine yyless() so it works in section 3 code. */
2771
2772 #undef yyless
2773 #define yyless(n) \
2774 do \
2775 { \
2776 /* Undo effects of setting up yytext. */ \
2777 int yyless_macro_arg = (n); \
2778 YY_LESS_LINENO(yyless_macro_arg);\
2779 yytext[yyleng] = yyg->yy_hold_char; \
2780 yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
2781 yyg->yy_hold_char = *yyg->yy_c_buf_p; \
2782 *yyg->yy_c_buf_p = '\0'; \
2783 yyleng = yyless_macro_arg; \
2784 } \
2785 while ( 0 )
2786
2787 /* Accessor methods (get/set functions) to struct members. */
2788
2789 /** Get the user-defined data for this scanner.
2790 * @param yyscanner The scanner object.
2791 */
yyget_extra(yyscan_t yyscanner)2792 YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner)
2793 {
2794 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2795 return yyextra;
2796 }
2797
2798 /** Get the current line number.
2799 * @param yyscanner The scanner object.
2800 */
yyget_lineno(yyscan_t yyscanner)2801 int yyget_lineno (yyscan_t yyscanner)
2802 {
2803 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2804
2805 if (! YY_CURRENT_BUFFER)
2806 return 0;
2807
2808 return yylineno;
2809 }
2810
2811 /** Get the current column number.
2812 * @param yyscanner The scanner object.
2813 */
yyget_column(yyscan_t yyscanner)2814 int yyget_column (yyscan_t yyscanner)
2815 {
2816 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2817
2818 if (! YY_CURRENT_BUFFER)
2819 return 0;
2820
2821 return yycolumn;
2822 }
2823
2824 /** Get the input stream.
2825 * @param yyscanner The scanner object.
2826 */
yyget_in(yyscan_t yyscanner)2827 FILE *yyget_in (yyscan_t yyscanner)
2828 {
2829 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2830 return yyin;
2831 }
2832
2833 /** Get the output stream.
2834 * @param yyscanner The scanner object.
2835 */
yyget_out(yyscan_t yyscanner)2836 FILE *yyget_out (yyscan_t yyscanner)
2837 {
2838 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2839 return yyout;
2840 }
2841
2842 /** Get the length of the current token.
2843 * @param yyscanner The scanner object.
2844 */
yyget_leng(yyscan_t yyscanner)2845 int yyget_leng (yyscan_t yyscanner)
2846 {
2847 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2848 return yyleng;
2849 }
2850
2851 /** Get the current token.
2852 * @param yyscanner The scanner object.
2853 */
2854
yyget_text(yyscan_t yyscanner)2855 char *yyget_text (yyscan_t yyscanner)
2856 {
2857 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2858 return yytext;
2859 }
2860
2861 /** Set the user-defined data. This data is never touched by the scanner.
2862 * @param user_defined The data to be associated with this scanner.
2863 * @param yyscanner The scanner object.
2864 */
yyset_extra(YY_EXTRA_TYPE user_defined,yyscan_t yyscanner)2865 void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner)
2866 {
2867 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2868 yyextra = user_defined ;
2869 }
2870
2871 /** Set the current line number.
2872 * @param _line_number line number
2873 * @param yyscanner The scanner object.
2874 */
yyset_lineno(int _line_number,yyscan_t yyscanner)2875 void yyset_lineno (int _line_number , yyscan_t yyscanner)
2876 {
2877 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2878
2879 /* lineno is only valid if an input buffer exists. */
2880 if (! YY_CURRENT_BUFFER )
2881 YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
2882
2883 yylineno = _line_number;
2884 }
2885
2886 /** Set the current column.
2887 * @param _column_no column number
2888 * @param yyscanner The scanner object.
2889 */
yyset_column(int _column_no,yyscan_t yyscanner)2890 void yyset_column (int _column_no , yyscan_t yyscanner)
2891 {
2892 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2893
2894 /* column is only valid if an input buffer exists. */
2895 if (! YY_CURRENT_BUFFER )
2896 YY_FATAL_ERROR( "yyset_column called with no buffer" );
2897
2898 yycolumn = _column_no;
2899 }
2900
2901 /** Set the input stream. This does not discard the current
2902 * input buffer.
2903 * @param _in_str A readable stream.
2904 * @param yyscanner The scanner object.
2905 * @see yy_switch_to_buffer
2906 */
yyset_in(FILE * _in_str,yyscan_t yyscanner)2907 void yyset_in (FILE * _in_str , yyscan_t yyscanner)
2908 {
2909 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2910 yyin = _in_str ;
2911 }
2912
yyset_out(FILE * _out_str,yyscan_t yyscanner)2913 void yyset_out (FILE * _out_str , yyscan_t yyscanner)
2914 {
2915 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2916 yyout = _out_str ;
2917 }
2918
yyget_debug(yyscan_t yyscanner)2919 int yyget_debug (yyscan_t yyscanner)
2920 {
2921 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2922 return yy_flex_debug;
2923 }
2924
yyset_debug(int _bdebug,yyscan_t yyscanner)2925 void yyset_debug (int _bdebug , yyscan_t yyscanner)
2926 {
2927 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2928 yy_flex_debug = _bdebug ;
2929 }
2930
2931 /* Accessor methods for yylval and yylloc */
2932
yyget_lval(yyscan_t yyscanner)2933 YYSTYPE * yyget_lval (yyscan_t yyscanner)
2934 {
2935 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2936 return yylval;
2937 }
2938
yyset_lval(YYSTYPE * yylval_param,yyscan_t yyscanner)2939 void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner)
2940 {
2941 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2942 yylval = yylval_param;
2943 }
2944
2945 /* User-visible API */
2946
2947 /* yylex_init is special because it creates the scanner itself, so it is
2948 * the ONLY reentrant function that doesn't take the scanner as the last argument.
2949 * That's why we explicitly handle the declaration, instead of using our macros.
2950 */
yylex_init(yyscan_t * ptr_yy_globals)2951 int yylex_init(yyscan_t* ptr_yy_globals)
2952 {
2953 if (ptr_yy_globals == NULL){
2954 errno = EINVAL;
2955 return 1;
2956 }
2957
2958 *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
2959
2960 if (*ptr_yy_globals == NULL){
2961 errno = ENOMEM;
2962 return 1;
2963 }
2964
2965 /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
2966 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2967
2968 return yy_init_globals ( *ptr_yy_globals );
2969 }
2970
2971 /* yylex_init_extra has the same functionality as yylex_init, but follows the
2972 * convention of taking the scanner as the last argument. Note however, that
2973 * this is a *pointer* to a scanner, as it will be allocated by this call (and
2974 * is the reason, too, why this function also must handle its own declaration).
2975 * The user defined value in the first argument will be available to yyalloc in
2976 * the yyextra field.
2977 */
yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t * ptr_yy_globals)2978 int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
2979 {
2980 struct yyguts_t dummy_yyguts;
2981
2982 yyset_extra (yy_user_defined, &dummy_yyguts);
2983
2984 if (ptr_yy_globals == NULL){
2985 errno = EINVAL;
2986 return 1;
2987 }
2988
2989 *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
2990
2991 if (*ptr_yy_globals == NULL){
2992 errno = ENOMEM;
2993 return 1;
2994 }
2995
2996 /* By setting to 0xAA, we expose bugs in
2997 yy_init_globals. Leave at 0x00 for releases. */
2998 memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2999
3000 yyset_extra (yy_user_defined, *ptr_yy_globals);
3001
3002 return yy_init_globals ( *ptr_yy_globals );
3003 }
3004
yy_init_globals(yyscan_t yyscanner)3005 static int yy_init_globals (yyscan_t yyscanner)
3006 {
3007 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3008 /* Initialization is the same as for the non-reentrant scanner.
3009 * This function is called from yylex_destroy(), so don't allocate here.
3010 */
3011
3012 yyg->yy_buffer_stack = NULL;
3013 yyg->yy_buffer_stack_top = 0;
3014 yyg->yy_buffer_stack_max = 0;
3015 yyg->yy_c_buf_p = NULL;
3016 yyg->yy_init = 0;
3017 yyg->yy_start = 0;
3018
3019 yyg->yy_start_stack_ptr = 0;
3020 yyg->yy_start_stack_depth = 0;
3021 yyg->yy_start_stack = NULL;
3022
3023 /* Defined in main.c */
3024 #ifdef YY_STDINIT
3025 yyin = stdin;
3026 yyout = stdout;
3027 #else
3028 yyin = NULL;
3029 yyout = NULL;
3030 #endif
3031
3032 /* For future reference: Set errno on error, since we are called by
3033 * yylex_init()
3034 */
3035 return 0;
3036 }
3037
3038 /* yylex_destroy is for both reentrant and non-reentrant scanners. */
yylex_destroy(yyscan_t yyscanner)3039 int yylex_destroy (yyscan_t yyscanner)
3040 {
3041 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3042
3043 /* Pop the buffer stack, destroying each element. */
3044 while(YY_CURRENT_BUFFER){
3045 yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
3046 YY_CURRENT_BUFFER_LVALUE = NULL;
3047 yypop_buffer_state(yyscanner);
3048 }
3049
3050 /* Destroy the stack itself. */
3051 yyfree(yyg->yy_buffer_stack , yyscanner);
3052 yyg->yy_buffer_stack = NULL;
3053
3054 /* Destroy the start condition stack. */
3055 yyfree( yyg->yy_start_stack , yyscanner );
3056 yyg->yy_start_stack = NULL;
3057
3058 /* Reset the globals. This is important in a non-reentrant scanner so the next time
3059 * yylex() is called, initialization will occur. */
3060 yy_init_globals( yyscanner);
3061
3062 /* Destroy the main struct (reentrant only). */
3063 yyfree ( yyscanner , yyscanner );
3064 yyscanner = NULL;
3065 return 0;
3066 }
3067
3068 /*
3069 * Internal utility routines.
3070 */
3071
3072 #ifndef yytext_ptr
yy_flex_strncpy(char * s1,const char * s2,int n,yyscan_t yyscanner)3073 static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
3074 {
3075 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3076 (void)yyg;
3077
3078 int i;
3079 for ( i = 0; i < n; ++i )
3080 s1[i] = s2[i];
3081 }
3082 #endif
3083
3084 #ifdef YY_NEED_STRLEN
yy_flex_strlen(const char * s,yyscan_t yyscanner)3085 static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
3086 {
3087 int n;
3088 for ( n = 0; s[n]; ++n )
3089 ;
3090
3091 return n;
3092 }
3093 #endif
3094
yyalloc(yy_size_t size,yyscan_t yyscanner)3095 void *yyalloc (yy_size_t size , yyscan_t yyscanner)
3096 {
3097 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3098 (void)yyg;
3099 return malloc(size);
3100 }
3101
yyrealloc(void * ptr,yy_size_t size,yyscan_t yyscanner)3102 void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner)
3103 {
3104 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3105 (void)yyg;
3106
3107 /* The cast to (char *) in the following accommodates both
3108 * implementations that use char* generic pointers, and those
3109 * that use void* generic pointers. It works with the latter
3110 * because both ANSI C and C++ allow castless assignment from
3111 * any pointer type to void*, and deal with argument conversions
3112 * as though doing an assignment.
3113 */
3114 return realloc(ptr, size);
3115 }
3116
yyfree(void * ptr,yyscan_t yyscanner)3117 void yyfree (void * ptr , yyscan_t yyscanner)
3118 {
3119 struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
3120 (void)yyg;
3121 free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
3122 }
3123
3124 #define YYTABLES_NAME "yytables"
3125
3126 #line 473 "psqlscanslash.l"
3127
3128
3129 /* LCOV_EXCL_STOP */
3130
3131 /*
3132 * Scan the command name of a psql backslash command. This should be called
3133 * after psql_scan() returns PSCAN_BACKSLASH. It is assumed that the input
3134 * has been consumed through the leading backslash.
3135 *
3136 * The return value is a malloc'd copy of the command name, as parsed off
3137 * from the input.
3138 */
3139 char *
psql_scan_slash_command(PsqlScanState state)3140 psql_scan_slash_command(PsqlScanState state)
3141 {
3142 PQExpBufferData mybuf;
3143
3144 /* Must be scanning already */
3145 Assert(state->scanbufhandle != NULL);
3146
3147 /* Build a local buffer that we'll return the data of */
3148 initPQExpBuffer(&mybuf);
3149
3150 /* Set current output target */
3151 state->output_buf = &mybuf;
3152
3153 /* Set input source */
3154 if (state->buffer_stack != NULL)
3155 yy_switch_to_buffer(state->buffer_stack->buf, state->scanner);
3156 else
3157 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
3158
3159 /*
3160 * Set lexer start state. Note that this is sufficient to switch
3161 * state->scanner over to using the tables in this lexer file.
3162 */
3163 state->start_state = xslashcmd;
3164
3165 /* And lex. */
3166 yylex(NULL, state->scanner);
3167
3168 /* There are no possible errors in this lex state... */
3169
3170 /*
3171 * In case the caller returns to using the regular SQL lexer, reselect the
3172 * appropriate initial state.
3173 */
3174 psql_scan_reselect_sql_lexer(state);
3175
3176 return mybuf.data;
3177 }
3178
3179 /*
3180 * Parse off the next argument for a backslash command, and return it as a
3181 * malloc'd string. If there are no more arguments, returns NULL.
3182 *
3183 * type tells what processing, if any, to perform on the option string;
3184 * for example, if it's a SQL identifier, we want to downcase any unquoted
3185 * letters.
3186 *
3187 * if quote is not NULL, *quote is set to 0 if no quoting was found, else
3188 * the last quote symbol used in the argument.
3189 *
3190 * if semicolon is true, unquoted trailing semicolon(s) that would otherwise
3191 * be taken as part of the option string will be stripped.
3192 *
3193 * NOTE: the only possible syntax errors for backslash options are unmatched
3194 * quotes, which are detected when we run out of input. Therefore, on a
3195 * syntax error we just throw away the string and return NULL; there is no
3196 * need to worry about flushing remaining input.
3197 */
3198 char *
psql_scan_slash_option(PsqlScanState state,enum slash_option_type type,char * quote,bool semicolon)3199 psql_scan_slash_option(PsqlScanState state,
3200 enum slash_option_type type,
3201 char *quote,
3202 bool semicolon)
3203 {
3204 PQExpBufferData mybuf;
3205 int lexresult PG_USED_FOR_ASSERTS_ONLY;
3206 int final_state;
3207 char local_quote;
3208
3209 /* Must be scanning already */
3210 Assert(state->scanbufhandle != NULL);
3211
3212 if (quote == NULL)
3213 quote = &local_quote;
3214 *quote = 0;
3215
3216 /* Build a local buffer that we'll return the data of */
3217 initPQExpBuffer(&mybuf);
3218
3219 /* Set up static variables that will be used by yylex */
3220 option_type = type;
3221 option_quote = quote;
3222 unquoted_option_chars = 0;
3223
3224 /* Set current output target */
3225 state->output_buf = &mybuf;
3226
3227 /* Set input source */
3228 if (state->buffer_stack != NULL)
3229 yy_switch_to_buffer(state->buffer_stack->buf, state->scanner);
3230 else
3231 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
3232
3233 /* Set lexer start state */
3234 if (type == OT_WHOLE_LINE)
3235 state->start_state = xslashwholeline;
3236 else
3237 state->start_state = xslashargstart;
3238
3239 /* And lex. */
3240 lexresult = yylex(NULL, state->scanner);
3241
3242 /* Save final state for a moment... */
3243 final_state = state->start_state;
3244
3245 /*
3246 * In case the caller returns to using the regular SQL lexer, reselect the
3247 * appropriate initial state.
3248 */
3249 psql_scan_reselect_sql_lexer(state);
3250
3251 /*
3252 * Check the lex result: we should have gotten back either LEXRES_OK
3253 * or LEXRES_EOL (the latter indicating end of string). If we were inside
3254 * a quoted string, as indicated by final_state, EOL is an error.
3255 */
3256 Assert(lexresult == LEXRES_EOL || lexresult == LEXRES_OK);
3257
3258 switch (final_state)
3259 {
3260 case xslashargstart:
3261 /* empty arg */
3262 break;
3263 case xslasharg:
3264 /* Strip any unquoted trailing semi-colons if requested */
3265 if (semicolon)
3266 {
3267 while (unquoted_option_chars-- > 0 &&
3268 mybuf.len > 0 &&
3269 mybuf.data[mybuf.len - 1] == ';')
3270 {
3271 mybuf.data[--mybuf.len] = '\0';
3272 }
3273 }
3274
3275 /*
3276 * If SQL identifier processing was requested, then we strip out
3277 * excess double quotes and optionally downcase unquoted letters.
3278 */
3279 if (type == OT_SQLID || type == OT_SQLIDHACK)
3280 {
3281 dequote_downcase_identifier(mybuf.data,
3282 (type != OT_SQLIDHACK),
3283 state->encoding);
3284 /* update mybuf.len for possible shortening */
3285 mybuf.len = strlen(mybuf.data);
3286 }
3287 break;
3288 case xslashquote:
3289 case xslashbackquote:
3290 case xslashdquote:
3291 /* must have hit EOL inside quotes */
3292 pg_log_error("unterminated quoted string");
3293 termPQExpBuffer(&mybuf);
3294 return NULL;
3295 case xslashwholeline:
3296 /* always okay */
3297 break;
3298 default:
3299 /* can't get here */
3300 fprintf(stderr, "invalid YY_START\n");
3301 exit(1);
3302 }
3303
3304 /*
3305 * An unquoted empty argument isn't possible unless we are at end of
3306 * command. Return NULL instead.
3307 */
3308 if (mybuf.len == 0 && *quote == 0)
3309 {
3310 termPQExpBuffer(&mybuf);
3311 return NULL;
3312 }
3313
3314 /* Else return the completed string. */
3315 return mybuf.data;
3316 }
3317
3318 /*
3319 * Eat up any unused \\ to complete a backslash command.
3320 */
3321 void
psql_scan_slash_command_end(PsqlScanState state)3322 psql_scan_slash_command_end(PsqlScanState state)
3323 {
3324 /* Must be scanning already */
3325 Assert(state->scanbufhandle != NULL);
3326
3327 /* Set current output target */
3328 state->output_buf = NULL; /* we won't output anything */
3329
3330 /* Set input source */
3331 if (state->buffer_stack != NULL)
3332 yy_switch_to_buffer(state->buffer_stack->buf, state->scanner);
3333 else
3334 yy_switch_to_buffer(state->scanbufhandle, state->scanner);
3335
3336 /* Set lexer start state */
3337 state->start_state = xslashend;
3338
3339 /* And lex. */
3340 yylex(NULL, state->scanner);
3341
3342 /* There are no possible errors in this lex state... */
3343
3344 /*
3345 * We expect the caller to return to using the regular SQL lexer, so
3346 * reselect the appropriate initial state.
3347 */
3348 psql_scan_reselect_sql_lexer(state);
3349 }
3350
3351 /*
3352 * Fetch current paren nesting depth
3353 */
3354 int
psql_scan_get_paren_depth(PsqlScanState state)3355 psql_scan_get_paren_depth(PsqlScanState state)
3356 {
3357 return state->paren_depth;
3358 }
3359
3360 /*
3361 * Set paren nesting depth
3362 */
3363 void
psql_scan_set_paren_depth(PsqlScanState state,int depth)3364 psql_scan_set_paren_depth(PsqlScanState state, int depth)
3365 {
3366 Assert(depth >= 0);
3367 state->paren_depth = depth;
3368 }
3369
3370 /*
3371 * De-quote and optionally downcase a SQL identifier.
3372 *
3373 * The string at *str is modified in-place; it can become shorter,
3374 * but not longer.
3375 *
3376 * If downcase is true then non-quoted letters are folded to lower case.
3377 * Ideally this behavior will match the backend's downcase_identifier();
3378 * but note that it could differ if LC_CTYPE is different in the frontend.
3379 *
3380 * Note that a string like FOO"BAR"BAZ will be converted to fooBARbaz;
3381 * this is somewhat inconsistent with the SQL spec, which would have us
3382 * parse it as several identifiers. But for psql's purposes, we want a
3383 * string like "foo"."bar" to be treated as one option, so there's little
3384 * choice; this routine doesn't get to change the token boundaries.
3385 */
3386 void
dequote_downcase_identifier(char * str,bool downcase,int encoding)3387 dequote_downcase_identifier(char *str, bool downcase, int encoding)
3388 {
3389 bool inquotes = false;
3390 char *cp = str;
3391
3392 while (*cp)
3393 {
3394 if (*cp == '"')
3395 {
3396 if (inquotes && cp[1] == '"')
3397 {
3398 /* Keep the first quote, remove the second */
3399 cp++;
3400 }
3401 else
3402 inquotes = !inquotes;
3403 /* Collapse out quote at *cp */
3404 memmove(cp, cp + 1, strlen(cp));
3405 /* do not advance cp */
3406 }
3407 else
3408 {
3409 if (downcase && !inquotes)
3410 *cp = pg_tolower((unsigned char) *cp);
3411 cp += PQmblenBounded(cp, encoding);
3412 }
3413 }
3414 }
3415
3416 /*
3417 * Evaluate a backticked substring of a slash command's argument.
3418 *
3419 * The portion of output_buf starting at backtick_start_offset is evaluated
3420 * as a shell command and then replaced by the command's output.
3421 */
3422 static void
evaluate_backtick(PsqlScanState state)3423 evaluate_backtick(PsqlScanState state)
3424 {
3425 PQExpBuffer output_buf = state->output_buf;
3426 char *cmd = output_buf->data + backtick_start_offset;
3427 PQExpBufferData cmd_output;
3428 FILE *fd;
3429 bool error = false;
3430 char buf[512];
3431 size_t result;
3432
3433 initPQExpBuffer(&cmd_output);
3434
3435 fd = popen(cmd, "r");
3436 if (!fd)
3437 {
3438 pg_log_error("%s: %m", cmd);
3439 error = true;
3440 }
3441
3442 if (!error)
3443 {
3444 do
3445 {
3446 result = fread(buf, 1, sizeof(buf), fd);
3447 if (ferror(fd))
3448 {
3449 pg_log_error("%s: %m", cmd);
3450 error = true;
3451 break;
3452 }
3453 appendBinaryPQExpBuffer(&cmd_output, buf, result);
3454 } while (!feof(fd));
3455 }
3456
3457 if (fd && pclose(fd) == -1)
3458 {
3459 pg_log_error("%s: %m", cmd);
3460 error = true;
3461 }
3462
3463 if (PQExpBufferDataBroken(cmd_output))
3464 {
3465 pg_log_error("%s: out of memory", cmd);
3466 error = true;
3467 }
3468
3469 /* Now done with cmd, delete it from output_buf */
3470 output_buf->len = backtick_start_offset;
3471 output_buf->data[output_buf->len] = '\0';
3472
3473 /* If no error, transfer result to output_buf */
3474 if (!error)
3475 {
3476 /* strip any trailing newline (but only one) */
3477 if (cmd_output.len > 0 &&
3478 cmd_output.data[cmd_output.len - 1] == '\n')
3479 cmd_output.len--;
3480 appendBinaryPQExpBuffer(output_buf, cmd_output.data, cmd_output.len);
3481 }
3482
3483 termPQExpBuffer(&cmd_output);
3484 }
3485
3486