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