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