1
2 #line 3 "<stdout>"
3
4 #define FF_INT_ALIGNED short int
5
6 /* A lexical scanner generated by flex */
7
8 #define FLEX_SCANNER
9 #define FF_FLEX_MAJOR_VERSION 2
10 #define FF_FLEX_MINOR_VERSION 5
11 #define FF_FLEX_SUBMINOR_VERSION 35
12 #if FF_FLEX_SUBMINOR_VERSION > 0
13 #define FLEX_BETA
14 #endif
15
16 /* First, we deal with platform-specific or compiler-specific issues. */
17
18 /* begin standard C headers. */
19 #include <stdio.h>
20 #include <string.h>
21 #include <errno.h>
22 #include <stdlib.h>
23
24 /* end standard C headers. */
25
26 /* flex integer type definitions */
27
28 #ifndef FLEXINT_H
29 #define FLEXINT_H
30
31 /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
32
33 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
34
35 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
36 * if you want the limit (max/min) macros for int types.
37 */
38 #ifndef __STDC_LIMIT_MACROS
39 #define __STDC_LIMIT_MACROS 1
40 #endif
41
42 #include <inttypes.h>
43 typedef int8_t flex_int8_t;
44 typedef uint8_t flex_uint8_t;
45 typedef int16_t flex_int16_t;
46 typedef uint16_t flex_uint16_t;
47 typedef int32_t flex_int32_t;
48 typedef uint32_t flex_uint32_t;
49 typedef uint64_t flex_uint64_t;
50 #else
51 typedef signed char flex_int8_t;
52 typedef short int flex_int16_t;
53 typedef int flex_int32_t;
54 typedef unsigned char flex_uint8_t;
55 typedef unsigned short int flex_uint16_t;
56 typedef unsigned int flex_uint32_t;
57 #endif /* ! C99 */
58
59 /* Limits of integral types. */
60 #ifndef INT8_MIN
61 #define INT8_MIN (-128)
62 #endif
63 #ifndef INT16_MIN
64 #define INT16_MIN (-32767-1)
65 #endif
66 #ifndef INT32_MIN
67 #define INT32_MIN (-2147483647-1)
68 #endif
69 #ifndef INT8_MAX
70 #define INT8_MAX (127)
71 #endif
72 #ifndef INT16_MAX
73 #define INT16_MAX (32767)
74 #endif
75 #ifndef INT32_MAX
76 #define INT32_MAX (2147483647)
77 #endif
78 #ifndef UINT8_MAX
79 #define UINT8_MAX (255U)
80 #endif
81 #ifndef UINT16_MAX
82 #define UINT16_MAX (65535U)
83 #endif
84 #ifndef UINT32_MAX
85 #define UINT32_MAX (4294967295U)
86 #endif
87
88 #endif /* ! FLEXINT_H */
89
90 #ifdef __cplusplus
91
92 /* The "const" storage-class-modifier is valid. */
93 #define FF_USE_CONST
94
95 #else /* ! __cplusplus */
96
97 /* C99 requires __STDC__ to be defined as 1. */
98 #if defined (__STDC__)
99
100 #define FF_USE_CONST
101
102 #endif /* defined (__STDC__) */
103 #endif /* ! __cplusplus */
104
105 #ifdef FF_USE_CONST
106 #define ffconst const
107 #else
108 #define ffconst
109 #endif
110
111 /* Returned upon end-of-file. */
112 #define FF_NULL 0
113
114 /* Promotes a possibly negative, possibly signed char to an unsigned
115 * integer for use as an array index. If the signed char is negative,
116 * we want to instead treat it as an 8-bit unsigned char, hence the
117 * double cast.
118 */
119 #define FF_SC_TO_UI(c) ((unsigned int) (unsigned char) c)
120
121 /* Enter a start condition. This macro really ought to take a parameter,
122 * but we do it the disgusting crufty way forced on us by the ()-less
123 * definition of BEGIN.
124 */
125 #define BEGIN (ff_start) = 1 + 2 *
126
127 /* Translate the current start state into a value that can be later handed
128 * to BEGIN to return to the state. The FFSTATE alias is for lex
129 * compatibility.
130 */
131 #define FF_START (((ff_start) - 1) / 2)
132 #define FFSTATE FF_START
133
134 /* Action number for EOF rule of a given start state. */
135 #define FF_STATE_EOF(state) (FF_END_OF_BUFFER + state + 1)
136
137 /* Special action meaning "start processing a new file". */
138 #define FF_NEW_FILE ffrestart(ffin )
139
140 #define FF_END_OF_BUFFER_CHAR 0
141
142 /* Size of default input buffer. */
143 #ifndef FF_BUF_SIZE
144 #define FF_BUF_SIZE 16384
145 #endif
146
147 /* The state buf must be large enough to hold one state per character in the main buffer.
148 */
149 #define FF_STATE_BUF_SIZE ((FF_BUF_SIZE + 2) * sizeof(ff_state_type))
150
151 #ifndef FF_TYPEDEF_FF_BUFFER_STATE
152 #define FF_TYPEDEF_FF_BUFFER_STATE
153 typedef struct ff_buffer_state *FF_BUFFER_STATE;
154 #endif
155
156 #ifndef FF_TYPEDEF_FF_SIZE_T
157 #define FF_TYPEDEF_FF_SIZE_T
158 typedef size_t ff_size_t;
159 #endif
160
161 extern ff_size_t ffleng;
162
163 extern FILE *ffin, *ffout;
164
165 #define EOB_ACT_CONTINUE_SCAN 0
166 #define EOB_ACT_END_OF_FILE 1
167 #define EOB_ACT_LAST_MATCH 2
168
169 #define FF_LESS_LINENO(n)
170
171 /* Return all but the first "n" matched characters back to the input stream. */
172 #define ffless(n) \
173 do \
174 { \
175 /* Undo effects of setting up fftext. */ \
176 int ffless_macro_arg = (n); \
177 FF_LESS_LINENO(ffless_macro_arg);\
178 *ff_cp = (ff_hold_char); \
179 FF_RESTORE_FF_MORE_OFFSET \
180 (ff_c_buf_p) = ff_cp = ff_bp + ffless_macro_arg - FF_MORE_ADJ; \
181 FF_DO_BEFORE_ACTION; /* set up fftext again */ \
182 } \
183 while ( 0 )
184
185 #define unput(c) ffunput( c, (fftext_ptr) )
186
187 #ifndef FF_STRUCT_FF_BUFFER_STATE
188 #define FF_STRUCT_FF_BUFFER_STATE
189 struct ff_buffer_state
190 {
191 FILE *ff_input_file;
192
193 char *ff_ch_buf; /* input buffer */
194 char *ff_buf_pos; /* current position in input buffer */
195
196 /* Size of input buffer in bytes, not including room for EOB
197 * characters.
198 */
199 ff_size_t ff_buf_size;
200
201 /* Number of characters read into ff_ch_buf, not including EOB
202 * characters.
203 */
204 ff_size_t ff_n_chars;
205
206 /* Whether we "own" the buffer - i.e., we know we created it,
207 * and can realloc() it to grow it, and should free() it to
208 * delete it.
209 */
210 int ff_is_our_buffer;
211
212 /* Whether this is an "interactive" input source; if so, and
213 * if we're using stdio for input, then we want to use getc()
214 * instead of fread(), to make sure we stop fetching input after
215 * each newline.
216 */
217 int ff_is_interactive;
218
219 /* Whether we're considered to be at the beginning of a line.
220 * If so, '^' rules will be active on the next match, otherwise
221 * not.
222 */
223 int ff_at_bol;
224
225 int ff_bs_lineno; /**< The line count. */
226 int ff_bs_column; /**< The column count. */
227
228 /* Whether to try to fill the input buffer when we reach the
229 * end of it.
230 */
231 int ff_fill_buffer;
232
233 int ff_buffer_status;
234
235 #define FF_BUFFER_NEW 0
236 #define FF_BUFFER_NORMAL 1
237 /* When an EOF's been seen but there's still some text to process
238 * then we mark the buffer as FF_EOF_PENDING, to indicate that we
239 * shouldn't try reading from the input source any more. We might
240 * still have a bunch of tokens to match, though, because of
241 * possible backing-up.
242 *
243 * When we actually see the EOF, we change the status to "new"
244 * (via ffrestart()), so that the user can continue scanning by
245 * just pointing ffin at a new input file.
246 */
247 #define FF_BUFFER_EOF_PENDING 2
248
249 };
250 #endif /* !FF_STRUCT_FF_BUFFER_STATE */
251
252 /* Stack of input buffers. */
253 static size_t ff_buffer_stack_top = 0; /**< index of top of stack. */
254 static size_t ff_buffer_stack_max = 0; /**< capacity of stack. */
255 static FF_BUFFER_STATE * ff_buffer_stack = 0; /**< Stack as an array. */
256
257 /* We provide macros for accessing buffer states in case in the
258 * future we want to put the buffer states in a more general
259 * "scanner state".
260 *
261 * Returns the top of the stack, or NULL.
262 */
263 #define FF_CURRENT_BUFFER ( (ff_buffer_stack) \
264 ? (ff_buffer_stack)[(ff_buffer_stack_top)] \
265 : NULL)
266
267 /* Same as previous macro, but useful when we know that the buffer stack is not
268 * NULL or when we need an lvalue. For internal use only.
269 */
270 #define FF_CURRENT_BUFFER_LVALUE (ff_buffer_stack)[(ff_buffer_stack_top)]
271
272 /* ff_hold_char holds the character lost when fftext is formed. */
273 static char ff_hold_char;
274 static ff_size_t ff_n_chars; /* number of characters read into ff_ch_buf */
275 ff_size_t ffleng;
276
277 /* Points to current character in buffer. */
278 static char *ff_c_buf_p = (char *) 0;
279 static int ff_init = 0; /* whether we need to initialize */
280 static int ff_start = 0; /* start state number */
281
282 /* Flag which is used to allow ffwrap()'s to do buffer switches
283 * instead of setting up a fresh ffin. A bit of a hack ...
284 */
285 static int ff_did_buffer_switch_on_eof;
286
287 void ffrestart (FILE *input_file );
288 void ff_switch_to_buffer (FF_BUFFER_STATE new_buffer );
289 FF_BUFFER_STATE ff_create_buffer (FILE *file,int size );
290 void ff_delete_buffer (FF_BUFFER_STATE b );
291 void ff_flush_buffer (FF_BUFFER_STATE b );
292 void ffpush_buffer_state (FF_BUFFER_STATE new_buffer );
293 void ffpop_buffer_state (void );
294
295 static void ffensure_buffer_stack (void );
296 static void ff_load_buffer_state (void );
297 static void ff_init_buffer (FF_BUFFER_STATE b,FILE *file );
298
299 #define FF_FLUSH_BUFFER ff_flush_buffer(FF_CURRENT_BUFFER )
300
301 FF_BUFFER_STATE ff_scan_buffer (char *base,ff_size_t size );
302 FF_BUFFER_STATE ff_scan_string (ffconst char *ff_str );
303 FF_BUFFER_STATE ff_scan_bytes (ffconst char *bytes,ff_size_t len );
304
305 void *ffalloc (ff_size_t );
306 void *ffrealloc (void *,ff_size_t );
307 void yyfffree (void * );
308
309 #define ff_new_buffer ff_create_buffer
310
311 #define ff_set_interactive(is_interactive) \
312 { \
313 if ( ! FF_CURRENT_BUFFER ){ \
314 ffensure_buffer_stack (); \
315 FF_CURRENT_BUFFER_LVALUE = \
316 ff_create_buffer(ffin,FF_BUF_SIZE ); \
317 } \
318 FF_CURRENT_BUFFER_LVALUE->ff_is_interactive = is_interactive; \
319 }
320
321 #define ff_set_bol(at_bol) \
322 { \
323 if ( ! FF_CURRENT_BUFFER ){\
324 ffensure_buffer_stack (); \
325 FF_CURRENT_BUFFER_LVALUE = \
326 ff_create_buffer(ffin,FF_BUF_SIZE ); \
327 } \
328 FF_CURRENT_BUFFER_LVALUE->ff_at_bol = at_bol; \
329 }
330
331 #define FF_AT_BOL() (FF_CURRENT_BUFFER_LVALUE->ff_at_bol)
332
333 /* Begin user sect3 */
334
335 typedef unsigned char FF_CHAR;
336
337 FILE *ffin = (FILE *) 0, *ffout = (FILE *) 0;
338
339 typedef int ff_state_type;
340
341 extern int fflineno;
342
343 int fflineno = 1;
344
345 extern char *fftext;
346 #define fftext_ptr fftext
347
348 static ff_state_type ff_get_previous_state (void );
349 static ff_state_type ff_try_NUL_trans (ff_state_type current_state );
350 static int ff_get_next_buffer (void );
351 static void ff_fatal_error (ffconst char msg[] );
352
353 /* Done after the current pattern has been matched and before the
354 * corresponding action - sets up fftext.
355 */
356 #define FF_DO_BEFORE_ACTION \
357 (fftext_ptr) = ff_bp; \
358 ffleng = (ff_size_t) (ff_cp - ff_bp); \
359 (ff_hold_char) = *ff_cp; \
360 *ff_cp = '\0'; \
361 (ff_c_buf_p) = ff_cp;
362
363 #define FF_NUM_RULES 30
364 #define FF_END_OF_BUFFER 31
365 /* This struct is not used in this scanner,
366 but its presence is necessary. */
367 struct ff_trans_info
368 {
369 flex_int32_t ff_verify;
370 flex_int32_t ff_nxt;
371 };
372 static ffconst flex_int16_t ff_accept[174] =
373 { 0,
374 0, 0, 31, 29, 1, 28, 18, 29, 29, 29,
375 29, 29, 29, 29, 10, 8, 8, 24, 29, 23,
376 13, 13, 13, 13, 9, 13, 13, 13, 13, 13,
377 17, 13, 13, 13, 13, 13, 13, 13, 29, 1,
378 22, 0, 12, 0, 11, 0, 13, 20, 0, 0,
379 0, 0, 0, 0, 0, 17, 0, 10, 0, 0,
380 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
381 0, 0, 10, 8, 0, 0, 0, 0, 26, 21,
382 25, 13, 13, 13, 2, 13, 13, 13, 4, 13,
383 13, 13, 13, 3, 13, 27, 13, 13, 13, 13,
384
385 13, 13, 13, 13, 13, 19, 0, 11, 0, 0,
386 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
387 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
388 0, 0, 0, 0, 0, 0, 10, 5, 6, 7,
389 14, 13, 23, 24, 13, 13, 13, 0, 0, 0,
390 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,
391 0, 0, 15, 0, 0, 0, 0, 0, 0, 0,
392 16, 0, 0
393 } ;
394
395 static ffconst flex_int32_t ff_ec[256] =
396 { 0,
397 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
398 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
399 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
400 1, 2, 4, 5, 6, 7, 1, 8, 9, 10,
401 11, 12, 13, 1, 13, 14, 1, 15, 16, 17,
402 17, 17, 17, 17, 17, 18, 18, 1, 1, 19,
403 20, 21, 1, 1, 22, 23, 24, 25, 26, 27,
404 28, 29, 30, 31, 31, 32, 31, 33, 34, 31,
405 35, 36, 31, 37, 38, 31, 31, 39, 31, 31,
406 1, 1, 40, 41, 42, 1, 43, 44, 24, 45,
407
408 46, 47, 48, 29, 49, 31, 31, 50, 31, 51,
409 52, 31, 53, 54, 31, 55, 56, 31, 31, 57,
410 31, 31, 1, 58, 1, 1, 1, 1, 1, 1,
411 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
412 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
413 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
414 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
415 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
416 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
417 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
418
419 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
420 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
421 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
422 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
423 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
424 1, 1, 1, 1, 1
425 } ;
426
427 static ffconst flex_int32_t ff_meta[59] =
428 { 0,
429 1, 1, 2, 1, 1, 1, 3, 1, 1, 1,
430 1, 1, 1, 1, 4, 4, 4, 4, 1, 1,
431 1, 4, 4, 4, 4, 4, 4, 5, 5, 5,
432 5, 5, 5, 5, 5, 5, 5, 5, 5, 1,
433 1, 5, 4, 4, 4, 4, 4, 5, 5, 5,
434 5, 5, 5, 5, 5, 5, 5, 1
435 } ;
436
437 static ffconst flex_int16_t ff_base[182] =
438 { 0,
439 0, 0, 412, 413, 409, 413, 390, 404, 401, 400,
440 398, 396, 34, 392, 70, 114, 16, 383, 46, 382,
441 29, 84, 359, 28, 358, 52, 157, 64, 91, 128,
442 358, 0, 40, 27, 69, 92, 100, 171, 340, 395,
443 413, 391, 413, 388, 387, 386, 413, 413, 383, 357,
444 358, 356, 336, 337, 335, 413, 139, 190, 352, 349,
445 71, 111, 135, 347, 348, 330, 327, 59, 64, 116,
446 325, 323, 175, 0, 59, 120, 326, 0, 413, 413,
447 413, 153, 184, 0, 202, 209, 210, 219, 351, 220,
448 228, 229, 211, 230, 240, 413, 221, 246, 254, 263,
449
450 264, 265, 266, 239, 275, 413, 346, 342, 310, 313,
451 309, 289, 292, 288, 275, 317, 327, 326, 325, 324,
452 323, 322, 298, 320, 297, 287, 317, 315, 314, 312,
453 311, 310, 249, 289, 243, 294, 298, 134, 246, 0,
454 413, 285, 413, 413, 288, 308, 309, 261, 261, 256,
455 221, 215, 246, 241, 223, 218, 213, 208, 197, 413,
456 166, 160, 413, 128, 122, 150, 154, 105, 101, 96,
457 413, 84, 413, 351, 354, 359, 364, 366, 368, 373,
458 89
459 } ;
460
461 static ffconst flex_int16_t ff_def[182] =
462 { 0,
463 173, 1, 173, 173, 173, 173, 173, 174, 175, 176,
464 173, 177, 173, 173, 173, 173, 16, 173, 173, 173,
465 178, 178, 178, 178, 178, 178, 178, 178, 178, 178,
466 173, 179, 178, 178, 178, 178, 178, 178, 173, 173,
467 173, 174, 173, 180, 175, 176, 173, 173, 177, 173,
468 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
469 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
470 173, 173, 173, 17, 173, 173, 173, 181, 173, 173,
471 173, 178, 178, 179, 178, 178, 178, 178, 27, 178,
472 178, 178, 178, 178, 178, 173, 178, 178, 178, 178,
473
474 178, 178, 178, 178, 178, 173, 180, 180, 173, 173,
475 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
476 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
477 173, 173, 173, 173, 173, 173, 173, 173, 173, 181,
478 173, 178, 173, 173, 178, 178, 178, 173, 173, 173,
479 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
480 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
481 173, 173, 0, 173, 173, 173, 173, 173, 173, 173,
482 173
483 } ;
484
485 static ffconst flex_int16_t ff_nxt[472] =
486 { 0,
487 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
488 4, 14, 4, 15, 16, 17, 17, 17, 18, 19,
489 20, 21, 22, 23, 23, 24, 25, 26, 27, 23,
490 23, 28, 29, 30, 23, 23, 25, 23, 23, 4,
491 31, 32, 33, 22, 23, 34, 25, 35, 23, 36,
492 37, 38, 23, 23, 25, 23, 23, 39, 50, 173,
493 51, 83, 86, 52, 79, 80, 81, 173, 84, 84,
494 84, 136, 173, 137, 137, 137, 137, 87, 53, 98,
495 54, 84, 55, 57, 58, 58, 58, 58, 88, 90,
496 97, 59, 140, 84, 171, 60, 118, 61, 85, 85,
497
498 91, 62, 63, 64, 128, 84, 171, 119, 65, 130,
499 84, 171, 66, 129, 99, 67, 92, 68, 131, 69,
500 70, 71, 85, 100, 93, 84, 72, 73, 74, 74,
501 74, 74, 84, 84, 138, 138, 120, 101, 75, 75,
502 85, 84, 94, 94, 94, 103, 102, 121, 138, 138,
503 172, 104, 57, 115, 115, 115, 115, 76, 75, 75,
504 122, 132, 141, 95, 171, 77, 94, 133, 123, 84,
505 78, 89, 89, 89, 89, 170, 169, 168, 89, 89,
506 89, 89, 89, 89, 94, 94, 94, 94, 57, 58,
507 58, 58, 58, 141, 84, 89, 167, 166, 84, 89,
508
509 89, 89, 89, 89, 58, 58, 58, 58, 142, 94,
510 96, 141, 84, 89, 75, 75, 85, 85, 141, 141,
511 141, 160, 80, 81, 105, 84, 48, 94, 141, 141,
512 141, 96, 143, 79, 75, 75, 160, 141, 141, 141,
513 85, 144, 41, 84, 94, 94, 94, 145, 141, 141,
514 84, 84, 84, 106, 48, 141, 163, 165, 85, 80,
515 84, 84, 84, 141, 164, 146, 163, 81, 94, 84,
516 84, 84, 141, 141, 141, 141, 143, 79, 144, 41,
517 84, 84, 162, 161, 141, 139, 94, 84, 106, 115,
518 115, 115, 115, 147, 141, 84, 159, 141, 48, 75,
519
520 75, 160, 106, 158, 84, 84, 84, 84, 137, 137,
521 137, 137, 137, 137, 137, 137, 84, 141, 141, 75,
522 75, 48, 160, 41, 144, 79, 84, 143, 81, 84,
523 80, 157, 156, 106, 155, 41, 144, 79, 143, 81,
524 80, 154, 153, 152, 151, 150, 149, 148, 108, 84,
525 84, 42, 108, 42, 42, 42, 45, 45, 45, 46,
526 141, 46, 46, 46, 49, 139, 49, 49, 49, 82,
527 82, 84, 84, 107, 135, 107, 107, 107, 134, 127,
528 126, 125, 124, 117, 116, 114, 113, 112, 111, 110,
529 109, 43, 47, 173, 108, 43, 40, 106, 96, 84,
530
531 84, 81, 79, 56, 43, 48, 47, 44, 43, 41,
532 40, 173, 3, 173, 173, 173, 173, 173, 173, 173,
533 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
534 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
535 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
536 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
537 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
538 173
539 } ;
540
541 static ffconst flex_int16_t ff_chk[472] =
542 { 0,
543 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
544 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
545 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
546 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
547 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
548 1, 1, 1, 1, 1, 1, 1, 1, 13, 17,
549 13, 21, 24, 13, 19, 19, 19, 17, 34, 24,
550 21, 75, 17, 75, 75, 75, 75, 26, 13, 34,
551 13, 33, 13, 15, 15, 15, 15, 15, 26, 28,
552 33, 15, 181, 26, 172, 15, 61, 15, 22, 22,
553
554 28, 15, 15, 15, 68, 28, 170, 61, 15, 69,
555 35, 169, 15, 68, 35, 15, 29, 15, 69, 15,
556 15, 15, 22, 35, 29, 22, 15, 16, 16, 16,
557 16, 16, 29, 36, 76, 76, 62, 36, 16, 16,
558 22, 37, 30, 30, 30, 37, 36, 62, 138, 138,
559 168, 37, 57, 57, 57, 57, 57, 16, 16, 16,
560 63, 70, 82, 30, 167, 16, 30, 70, 63, 30,
561 16, 27, 27, 27, 27, 166, 165, 164, 27, 27,
562 27, 27, 27, 27, 30, 38, 38, 38, 73, 73,
563 73, 73, 73, 83, 82, 27, 162, 161, 27, 27,
564
565 27, 27, 27, 27, 58, 58, 58, 58, 83, 38,
566 159, 85, 38, 27, 58, 58, 85, 85, 86, 87,
567 93, 158, 86, 87, 38, 83, 157, 38, 88, 90,
568 97, 156, 88, 90, 58, 58, 155, 91, 92, 94,
569 85, 91, 92, 85, 94, 94, 94, 93, 104, 95,
570 86, 87, 93, 95, 154, 98, 153, 152, 85, 98,
571 88, 90, 97, 99, 151, 97, 150, 99, 94, 91,
572 92, 94, 100, 101, 102, 103, 100, 101, 102, 103,
573 104, 95, 149, 148, 105, 139, 94, 98, 105, 115,
574 115, 115, 115, 104, 142, 99, 135, 145, 142, 115,
575
576 115, 145, 134, 133, 100, 101, 102, 103, 136, 136,
577 136, 136, 137, 137, 137, 137, 105, 146, 147, 115,
578 115, 146, 147, 132, 131, 130, 142, 129, 128, 145,
579 127, 126, 125, 124, 123, 122, 121, 120, 119, 118,
580 117, 116, 114, 113, 112, 111, 110, 109, 108, 146,
581 147, 174, 107, 174, 174, 174, 175, 175, 175, 176,
582 89, 176, 176, 176, 177, 77, 177, 177, 177, 178,
583 178, 179, 179, 180, 72, 180, 180, 180, 71, 67,
584 66, 65, 64, 60, 59, 55, 54, 53, 52, 51,
585 50, 49, 46, 45, 44, 42, 40, 39, 31, 25,
586
587 23, 20, 18, 14, 12, 11, 10, 9, 8, 7,
588 5, 3, 173, 173, 173, 173, 173, 173, 173, 173,
589 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
590 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
591 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
592 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
593 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
594 173
595 } ;
596
597 static ff_state_type ff_last_accepting_state;
598 static char *ff_last_accepting_cpos;
599
600 extern int ff_flex_debug;
601 int ff_flex_debug = 0;
602
603 /* The intent behind this definition is that it'll catch
604 * any uses of REJECT which flex missed.
605 */
606 #define REJECT reject_used_but_not_detected
607 #define ffmore() ffmore_used_but_not_detected
608 #define FF_MORE_ADJ 0
609 #define FF_RESTORE_FF_MORE_OFFSET
610 char *fftext;
611 #line 1 "eval.l"
612 #line 2 "eval.l"
613 /************************************************************************/
614 /* */
615 /* CFITSIO Lexical Parser */
616 /* */
617 /* This file is one of 3 files containing code which parses an */
618 /* arithmetic expression and evaluates it in the context of an input */
619 /* FITS file table extension. The CFITSIO lexical parser is divided */
620 /* into the following 3 parts/files: the CFITSIO "front-end", */
621 /* eval_f.c, contains the interface between the user/CFITSIO and the */
622 /* real core of the parser; the FLEX interpreter, eval_l.c, takes the */
623 /* input string and parses it into tokens and identifies the FITS */
624 /* information required to evaluate the expression (ie, keywords and */
625 /* columns); and, the BISON grammar and evaluation routines, eval_y.c, */
626 /* receives the FLEX output and determines and performs the actual */
627 /* operations. The files eval_l.c and eval_y.c are produced from */
628 /* running flex and bison on the files eval.l and eval.y, respectively. */
629 /* (flex and bison are available from any GNU archive: see www.gnu.org) */
630 /* */
631 /* The grammar rules, rather than evaluating the expression in situ, */
632 /* builds a tree, or Nodal, structure mapping out the order of */
633 /* operations and expression dependencies. This "compilation" process */
634 /* allows for much faster processing of multiple rows. This technique */
635 /* was developed by Uwe Lammers of the XMM Science Analysis System, */
636 /* although the CFITSIO implementation is entirely code original. */
637 /* */
638 /* */
639 /* Modification History: */
640 /* */
641 /* Kent Blackburn c1992 Original parser code developed for the */
642 /* FTOOLS software package, in particular, */
643 /* the fselect task. */
644 /* Kent Blackburn c1995 BIT column support added */
645 /* Peter D Wilson Feb 1998 Vector column support added */
646 /* Peter D Wilson May 1998 Ported to CFITSIO library. User */
647 /* interface routines written, in essence */
648 /* making fselect, fcalc, and maketime */
649 /* capabilities available to all tools */
650 /* via single function calls. */
651 /* Peter D Wilson Jun 1998 Major rewrite of parser core, so as to */
652 /* create a run-time evaluation tree, */
653 /* inspired by the work of Uwe Lammers, */
654 /* resulting in a speed increase of */
655 /* 10-100 times. */
656 /* Peter D Wilson Jul 1998 gtifilter(a,b,c,d) function added */
657 /* Peter D Wilson Aug 1998 regfilter(a,b,c,d) function added */
658 /* Peter D Wilson Jul 1999 Make parser fitsfile-independent, */
659 /* allowing a purely vector-based usage */
660 /* */
661 /************************************************************************/
662
663 #include <math.h>
664 #include <string.h>
665 #include <ctype.h>
666 #ifdef sparc
667 #include <malloc.h>
668 #else
669 #include <stdlib.h>
670 #endif
671 #include "eval_defs.h"
672
673 ParseData gParse; /* Global structure holding all parser information */
674
675 /***** Internal functions *****/
676
677 int ffGetVariable( char *varName, FFSTYPE *varVal );
678
679 static int find_variable( char *varName );
680 static int expr_read( char *buf, int nbytes );
681
682 /***** Definitions *****/
683
684 #define FF_NO_UNPUT /* Don't include FFUNPUT function */
685 #define FF_NEVER_INTERACTIVE 1
686
687 #define MAXCHR 256
688 #define MAXBIT 128
689
690 #define OCT_0 "000"
691 #define OCT_1 "001"
692 #define OCT_2 "010"
693 #define OCT_3 "011"
694 #define OCT_4 "100"
695 #define OCT_5 "101"
696 #define OCT_6 "110"
697 #define OCT_7 "111"
698 #define OCT_X "xxx"
699
700 #define HEX_0 "0000"
701 #define HEX_1 "0001"
702 #define HEX_2 "0010"
703 #define HEX_3 "0011"
704 #define HEX_4 "0100"
705 #define HEX_5 "0101"
706 #define HEX_6 "0110"
707 #define HEX_7 "0111"
708 #define HEX_8 "1000"
709 #define HEX_9 "1001"
710 #define HEX_A "1010"
711 #define HEX_B "1011"
712 #define HEX_C "1100"
713 #define HEX_D "1101"
714 #define HEX_E "1110"
715 #define HEX_F "1111"
716 #define HEX_X "xxxx"
717
718 /*
719 MJT - 13 June 1996
720 read from buffer instead of stdin
721 (as per old ftools.skel)
722 */
723 #undef FF_INPUT
724 #define FF_INPUT(buf,result,max_size) \
725 if ( (result = expr_read( (char *) buf, max_size )) < 0 ) \
726 FF_FATAL_ERROR( "read() in flex scanner failed" );
727
728 #line 729 "<stdout>"
729
730 #define INITIAL 0
731
732 #ifndef FF_NO_UNISTD_H
733 /* Special case for "unistd.h", since it is non-ANSI. We include it way
734 * down here because we want the user's section 1 to have been scanned first.
735 * The user has a chance to override it with an option.
736 */
737 #include <unistd.h>
738 #endif
739
740 #ifndef FF_EXTRA_TYPE
741 #define FF_EXTRA_TYPE void *
742 #endif
743
744 static int ff_init_globals (void );
745
746 /* Accessor methods to globals.
747 These are made visible to non-reentrant scanners for convenience. */
748
749 int fflex_destroy (void );
750
751 int ffget_debug (void );
752
753 void ffset_debug (int debug_flag );
754
755 FF_EXTRA_TYPE ffget_extra (void );
756
757 void ffset_extra (FF_EXTRA_TYPE user_defined );
758
759 FILE *ffget_in (void );
760
761 void ffset_in (FILE * in_str );
762
763 FILE *ffget_out (void );
764
765 void ffset_out (FILE * out_str );
766
767 ff_size_t ffget_leng (void );
768
769 char *ffget_text (void );
770
771 int ffget_lineno (void );
772
773 void ffset_lineno (int line_number );
774
775 /* Macros after this point can all be overridden by user definitions in
776 * section 1.
777 */
778
779 #ifndef FF_SKIP_FFWRAP
780 #ifdef __cplusplus
781 extern "C" int ffwrap (void );
782 #else
783 extern int ffwrap (void );
784 #endif
785 #endif
786
787 static void ffunput (int c,char *buf_ptr );
788
789 #ifndef fftext_ptr
790 static void ff_flex_strncpy (char *,ffconst char *,int );
791 #endif
792
793 #ifdef FF_NEED_STRLEN
794 static int ff_flex_strlen (ffconst char * );
795 #endif
796
797 #ifndef FF_NO_INPUT
798
799 #ifdef __cplusplus
800 static int ffinput (void );
801 #else
802 static int input (void );
803 #endif
804
805 #endif
806
807 /* Amount of stuff to slurp up with each read. */
808 #ifndef FF_READ_BUF_SIZE
809 #define FF_READ_BUF_SIZE 8192
810 #endif
811
812 /* Copy whatever the last rule matched to the standard output. */
813 #ifndef ECHO
814 /* This used to be an fputs(), but since the string might contain NUL's,
815 * we now use fwrite().
816 */
817 #define ECHO fwrite( fftext, ffleng, 1, ffout )
818 #endif
819
820 /* Gets input and stuffs it into "buf". number of characters read, or FF_NULL,
821 * is returned in "result".
822 */
823 #ifndef FF_INPUT
824 #define FF_INPUT(buf,result,max_size) \
825 if ( FF_CURRENT_BUFFER_LVALUE->ff_is_interactive ) \
826 { \
827 int c = '*'; \
828 ff_size_t n; \
829 for ( n = 0; n < max_size && \
830 (c = getc( ffin )) != EOF && c != '\n'; ++n ) \
831 buf[n] = (char) c; \
832 if ( c == '\n' ) \
833 buf[n++] = (char) c; \
834 if ( c == EOF && ferror( ffin ) ) \
835 FF_FATAL_ERROR( "input in flex scanner failed" ); \
836 result = n; \
837 } \
838 else \
839 { \
840 errno=0; \
841 while ( (result = fread(buf, 1, max_size, ffin))==0 && ferror(ffin)) \
842 { \
843 if( errno != EINTR) \
844 { \
845 FF_FATAL_ERROR( "input in flex scanner failed" ); \
846 break; \
847 } \
848 errno=0; \
849 clearerr(ffin); \
850 } \
851 }\
852 \
853
854 #endif
855
856 /* No semi-colon after return; correct usage is to write "ffterminate();" -
857 * we don't want an extra ';' after the "return" because that will cause
858 * some compilers to complain about unreachable statements.
859 */
860 #ifndef ffterminate
861 #define ffterminate() return FF_NULL
862 #endif
863
864 /* Number of entries by which start-condition stack grows. */
865 #ifndef FF_START_STACK_INCR
866 #define FF_START_STACK_INCR 25
867 #endif
868
869 /* Report a fatal error. */
870 #ifndef FF_FATAL_ERROR
871 #define FF_FATAL_ERROR(msg) ff_fatal_error( msg )
872 #endif
873
874 /* end tables serialization structures and prototypes */
875
876 /* Default declaration of generated scanner - a define so the user can
877 * easily add parameters.
878 */
879 #ifndef FF_DECL
880 #define FF_DECL_IS_OURS 1
881
882 extern int fflex (void);
883
884 #define FF_DECL int fflex (void)
885 #endif /* !FF_DECL */
886
887 /* Code executed at the beginning of each rule, after fftext and ffleng
888 * have been set up.
889 */
890 #ifndef FF_USER_ACTION
891 #define FF_USER_ACTION
892 #endif
893
894 /* Code executed at the end of each rule. */
895 #ifndef FF_BREAK
896 #define FF_BREAK break;
897 #endif
898
899 #define FF_RULE_SETUP \
900 FF_USER_ACTION
901
902 /** The main scanner function which does all the work.
903 */
904 FF_DECL
905 {
906 register ff_state_type ff_current_state;
907 register char *ff_cp, *ff_bp;
908 register int ff_act;
909
910 #line 146 "eval.l"
911
912
913 #line 914 "<stdout>"
914
915 if ( !(ff_init) )
916 {
917 (ff_init) = 1;
918
919 #ifdef FF_USER_INIT
920 FF_USER_INIT;
921 #endif
922
923 if ( ! (ff_start) )
924 (ff_start) = 1; /* first start state */
925
926 if ( ! ffin )
927 ffin = stdin;
928
929 if ( ! ffout )
930 ffout = stdout;
931
932 if ( ! FF_CURRENT_BUFFER ) {
933 ffensure_buffer_stack ();
934 FF_CURRENT_BUFFER_LVALUE =
935 ff_create_buffer(ffin,FF_BUF_SIZE );
936 }
937
938 ff_load_buffer_state( );
939 }
940
941 while ( 1 ) /* loops until end-of-file is reached */
942 {
943 ff_cp = (ff_c_buf_p);
944
945 /* Support of fftext. */
946 *ff_cp = (ff_hold_char);
947
948 /* ff_bp points to the position in ff_ch_buf of the start of
949 * the current run.
950 */
951 ff_bp = ff_cp;
952
953 ff_current_state = (ff_start);
954 ff_match:
955 do
956 {
957 register FF_CHAR ff_c = ff_ec[FF_SC_TO_UI(*ff_cp)];
958 if ( ff_accept[ff_current_state] )
959 {
960 (ff_last_accepting_state) = ff_current_state;
961 (ff_last_accepting_cpos) = ff_cp;
962 }
963 while ( ff_chk[ff_base[ff_current_state] + ff_c] != ff_current_state )
964 {
965 ff_current_state = (int) ff_def[ff_current_state];
966 if ( ff_current_state >= 174 )
967 ff_c = ff_meta[(unsigned int) ff_c];
968 }
969 ff_current_state = ff_nxt[ff_base[ff_current_state] + (unsigned int) ff_c];
970 ++ff_cp;
971 }
972 while ( ff_base[ff_current_state] != 413 );
973
974 ff_find_action:
975 ff_act = ff_accept[ff_current_state];
976 if ( ff_act == 0 )
977 { /* have to back up */
978 ff_cp = (ff_last_accepting_cpos);
979 ff_current_state = (ff_last_accepting_state);
980 ff_act = ff_accept[ff_current_state];
981 }
982
983 FF_DO_BEFORE_ACTION;
984
985 do_action: /* This label is used only to access EOF actions. */
986
987 switch ( ff_act )
988 { /* beginning of action switch */
989 case 0: /* must back up */
990 /* undo the effects of FF_DO_BEFORE_ACTION */
991 *ff_cp = (ff_hold_char);
992 ff_cp = (ff_last_accepting_cpos);
993 ff_current_state = (ff_last_accepting_state);
994 goto ff_find_action;
995
996 case 1:
997 FF_RULE_SETUP
998 #line 148 "eval.l"
999 ;
1000 FF_BREAK
1001 case 2:
1002 FF_RULE_SETUP
1003 #line 149 "eval.l"
1004 {
1005 int len;
1006 len = strlen(fftext);
1007 while (fftext[len] == ' ')
1008 len--;
1009 len = len - 1;
1010 strncpy(fflval.str,&fftext[1],len);
1011 fflval.str[len] = '\0';
1012 return( BITSTR );
1013 }
1014 FF_BREAK
1015 case 3:
1016 FF_RULE_SETUP
1017 #line 159 "eval.l"
1018 {
1019 int len;
1020 char tmpstring[256];
1021 char bitstring[256];
1022 len = strlen(fftext);
1023 if (len >= 256) {
1024 char errMsg[100];
1025 gParse.status = PARSE_SYNTAX_ERR;
1026 strcpy (errMsg,"Bit string exceeds maximum length: '");
1027 strncat(errMsg, &(fftext[0]), 20);
1028 strcat (errMsg,"...'");
1029 ffpmsg (errMsg);
1030 len = 0;
1031 } else {
1032 while (fftext[len] == ' ')
1033 len--;
1034 len = len - 1;
1035 strncpy(tmpstring,&fftext[1],len);
1036 }
1037 tmpstring[len] = '\0';
1038 bitstring[0] = '\0';
1039 len = 0;
1040 while ( tmpstring[len] != '\0')
1041 {
1042 switch ( tmpstring[len] )
1043 {
1044 case '0':
1045 strcat(bitstring,OCT_0);
1046 break;
1047 case '1':
1048 strcat(bitstring,OCT_1);
1049 break;
1050 case '2':
1051 strcat(bitstring,OCT_2);
1052 break;
1053 case '3':
1054 strcat(bitstring,OCT_3);
1055 break;
1056 case '4':
1057 strcat(bitstring,OCT_4);
1058 break;
1059 case '5':
1060 strcat(bitstring,OCT_5);
1061 break;
1062 case '6':
1063 strcat(bitstring,OCT_6);
1064 break;
1065 case '7':
1066 strcat(bitstring,OCT_7);
1067 break;
1068 case 'x':
1069 case 'X':
1070 strcat(bitstring,OCT_X);
1071 break;
1072 }
1073 len++;
1074 }
1075 strcpy( fflval.str, bitstring );
1076 return( BITSTR );
1077 }
1078 FF_BREAK
1079 case 4:
1080 FF_RULE_SETUP
1081 #line 219 "eval.l"
1082 {
1083 int len;
1084 char tmpstring[256];
1085 char bitstring[256];
1086 len = strlen(fftext);
1087 if (len >= 256) {
1088 char errMsg[100];
1089 gParse.status = PARSE_SYNTAX_ERR;
1090 strcpy (errMsg,"Hex string exceeds maximum length: '");
1091 strncat(errMsg, &(fftext[0]), 20);
1092 strcat (errMsg,"...'");
1093 ffpmsg (errMsg);
1094 len = 0;
1095 } else {
1096 while (fftext[len] == ' ')
1097 len--;
1098 len = len - 1;
1099 strncpy(tmpstring,&fftext[1],len);
1100 }
1101 tmpstring[len] = '\0';
1102 bitstring[0] = '\0';
1103 len = 0;
1104 while ( tmpstring[len] != '\0')
1105 {
1106 switch ( tmpstring[len] )
1107 {
1108 case '0':
1109 strcat(bitstring,HEX_0);
1110 break;
1111 case '1':
1112 strcat(bitstring,HEX_1);
1113 break;
1114 case '2':
1115 strcat(bitstring,HEX_2);
1116 break;
1117 case '3':
1118 strcat(bitstring,HEX_3);
1119 break;
1120 case '4':
1121 strcat(bitstring,HEX_4);
1122 break;
1123 case '5':
1124 strcat(bitstring,HEX_5);
1125 break;
1126 case '6':
1127 strcat(bitstring,HEX_6);
1128 break;
1129 case '7':
1130 strcat(bitstring,HEX_7);
1131 break;
1132 case '8':
1133 strcat(bitstring,HEX_8);
1134 break;
1135 case '9':
1136 strcat(bitstring,HEX_9);
1137 break;
1138 case 'a':
1139 case 'A':
1140 strcat(bitstring,HEX_A);
1141 break;
1142 case 'b':
1143 case 'B':
1144 strcat(bitstring,HEX_B);
1145 break;
1146 case 'c':
1147 case 'C':
1148 strcat(bitstring,HEX_C);
1149 break;
1150 case 'd':
1151 case 'D':
1152 strcat(bitstring,HEX_D);
1153 break;
1154 case 'e':
1155 case 'E':
1156 strcat(bitstring,HEX_E);
1157 break;
1158 case 'f':
1159 case 'F':
1160 strcat(bitstring,HEX_F);
1161 break;
1162 case 'x':
1163 case 'X':
1164 strcat(bitstring,HEX_X);
1165 break;
1166 }
1167 len++;
1168 }
1169
1170 strcpy( fflval.str, bitstring );
1171 return( BITSTR );
1172 }
1173 FF_BREAK
1174 case 5:
1175 FF_RULE_SETUP
1176 #line 310 "eval.l"
1177 {
1178 long int constval = 0;
1179 char *p;
1180 for (p = &(fftext[2]); *p; p++) {
1181 constval = (constval << 1) | (*p == '1');
1182 }
1183 fflval.lng = constval;
1184 return( LONG );
1185 }
1186 FF_BREAK
1187 case 6:
1188 FF_RULE_SETUP
1189 #line 319 "eval.l"
1190 {
1191 long int constval = 0;
1192 char *p;
1193 for (p = &(fftext[2]); *p; p++) {
1194 constval = (constval << 3) | (*p - '0');
1195 }
1196 fflval.lng = constval;
1197 return( LONG );
1198 }
1199 FF_BREAK
1200 case 7:
1201 FF_RULE_SETUP
1202 #line 328 "eval.l"
1203 {
1204 long int constval = 0;
1205 char *p;
1206 for (p = &(fftext[2]); *p; p++) {
1207 int v = (isdigit(*p) ? (*p - '0') : (*p - 'a' + 10));
1208 constval = (constval << 4) | v;
1209 }
1210 fflval.lng = constval;
1211 return( LONG );
1212 }
1213 FF_BREAK
1214 case 8:
1215 FF_RULE_SETUP
1216 #line 340 "eval.l"
1217 {
1218 fflval.lng = atol(fftext);
1219 return( LONG );
1220 }
1221 FF_BREAK
1222 case 9:
1223 FF_RULE_SETUP
1224 #line 344 "eval.l"
1225 {
1226 if ((fftext[0] == 't') || (fftext[0] == 'T'))
1227 fflval.log = 1;
1228 else
1229 fflval.log = 0;
1230 return( BOOLEAN );
1231 }
1232 FF_BREAK
1233 case 10:
1234 FF_RULE_SETUP
1235 #line 351 "eval.l"
1236 {
1237 fflval.dbl = atof(fftext);
1238 return( DOUBLE );
1239 }
1240 FF_BREAK
1241 case 11:
1242 FF_RULE_SETUP
1243 #line 355 "eval.l"
1244 {
1245 if( !fits_strcasecmp(fftext,"#PI") ) {
1246 fflval.dbl = (double)(4) * atan((double)(1));
1247 return( DOUBLE );
1248 } else if( !fits_strcasecmp(fftext,"#E") ) {
1249 fflval.dbl = exp((double)(1));
1250 return( DOUBLE );
1251 } else if( !fits_strcasecmp(fftext,"#DEG") ) {
1252 fflval.dbl = ((double)4)*atan((double)1)/((double)180);
1253 return( DOUBLE );
1254 } else if( !fits_strcasecmp(fftext,"#ROW") ) {
1255 return( ROWREF );
1256 } else if( !fits_strcasecmp(fftext,"#NULL") ) {
1257 return( NULLREF );
1258 } else if( !fits_strcasecmp(fftext,"#SNULL") ) {
1259 return( SNULLREF );
1260 } else {
1261 int len;
1262 if (fftext[1] == '$') {
1263 len = strlen(fftext) - 3;
1264 fflval.str[0] = '#';
1265 strncpy(fflval.str+1,&fftext[2],len);
1266 fflval.str[len+1] = '\0';
1267 fftext = fflval.str;
1268 }
1269 return( (*gParse.getData)(fftext, &fflval) );
1270 }
1271 }
1272 FF_BREAK
1273 case 12:
1274 FF_RULE_SETUP
1275 #line 383 "eval.l"
1276 {
1277 int len;
1278 len = strlen(fftext) - 2;
1279 if (len >= MAX_STRLEN) {
1280 char errMsg[100];
1281 gParse.status = PARSE_SYNTAX_ERR;
1282 strcpy (errMsg,"String exceeds maximum length: '");
1283 strncat(errMsg, &(fftext[1]), 20);
1284 strcat (errMsg,"...'");
1285 ffpmsg (errMsg);
1286 len = 0;
1287 } else {
1288 strncpy(fflval.str,&fftext[1],len);
1289 }
1290 fflval.str[len] = '\0';
1291 return( STRING );
1292 }
1293 FF_BREAK
1294 case 13:
1295 FF_RULE_SETUP
1296 #line 400 "eval.l"
1297 {
1298 int len,type;
1299
1300 if (fftext[0] == '$') {
1301 len = strlen(fftext) - 2;
1302 strncpy(fflval.str,&fftext[1],len);
1303 fflval.str[len] = '\0';
1304 fftext = fflval.str;
1305 }
1306 type = ffGetVariable(fftext, &fflval);
1307 return( type );
1308 }
1309 FF_BREAK
1310 case 14:
1311 FF_RULE_SETUP
1312 #line 412 "eval.l"
1313 {
1314 char *fname;
1315 int len=0;
1316 fname = &fflval.str[0];
1317 while( (fname[len]=toupper(fftext[len])) ) len++;
1318
1319 if( FSTRCMP(fname,"BOX(")==0
1320 || FSTRCMP(fname,"CIRCLE(")==0
1321 || FSTRCMP(fname,"ELLIPSE(")==0
1322 || FSTRCMP(fname,"NEAR(")==0
1323 || FSTRCMP(fname,"ISNULL(")==0
1324 )
1325 /* Return type is always boolean */
1326 return( BFUNCTION );
1327
1328 else if( FSTRCMP(fname,"GTIFILTER(")==0 )
1329 return( GTIFILTER );
1330
1331 else if( FSTRCMP(fname,"GTIOVERLAP(")==0 )
1332 return( GTIOVERLAP );
1333
1334 else if( FSTRCMP(fname,"REGFILTER(")==0 )
1335 return( REGFILTER );
1336
1337 else if( FSTRCMP(fname,"STRSTR(")==0 )
1338 return( IFUNCTION ); /* Returns integer */
1339
1340 else
1341 return( FUNCTION );
1342 }
1343 FF_BREAK
1344 case 15:
1345 FF_RULE_SETUP
1346 #line 442 "eval.l"
1347 { return( INTCAST ); }
1348 FF_BREAK
1349 case 16:
1350 FF_RULE_SETUP
1351 #line 443 "eval.l"
1352 { return( FLTCAST ); }
1353 FF_BREAK
1354 case 17:
1355 FF_RULE_SETUP
1356 #line 444 "eval.l"
1357 { return( POWER ); }
1358 FF_BREAK
1359 case 18:
1360 FF_RULE_SETUP
1361 #line 445 "eval.l"
1362 { return( NOT ); }
1363 FF_BREAK
1364 case 19:
1365 FF_RULE_SETUP
1366 #line 446 "eval.l"
1367 { return( OR ); }
1368 FF_BREAK
1369 case 20:
1370 FF_RULE_SETUP
1371 #line 447 "eval.l"
1372 { return( AND ); }
1373 FF_BREAK
1374 case 21:
1375 FF_RULE_SETUP
1376 #line 448 "eval.l"
1377 { return( EQ ); }
1378 FF_BREAK
1379 case 22:
1380 FF_RULE_SETUP
1381 #line 449 "eval.l"
1382 { return( NE ); }
1383 FF_BREAK
1384 case 23:
1385 FF_RULE_SETUP
1386 #line 450 "eval.l"
1387 { return( GT ); }
1388 FF_BREAK
1389 case 24:
1390 FF_RULE_SETUP
1391 #line 451 "eval.l"
1392 { return( LT ); }
1393 FF_BREAK
1394 case 25:
1395 FF_RULE_SETUP
1396 #line 452 "eval.l"
1397 { return( GTE ); }
1398 FF_BREAK
1399 case 26:
1400 FF_RULE_SETUP
1401 #line 453 "eval.l"
1402 { return( LTE ); }
1403 FF_BREAK
1404 case 27:
1405 FF_RULE_SETUP
1406 #line 454 "eval.l"
1407 { return( XOR ); }
1408 FF_BREAK
1409 case 28:
1410 /* rule 28 can match eol */
1411 FF_RULE_SETUP
1412 #line 455 "eval.l"
1413 { return( '\n' ); }
1414 FF_BREAK
1415 case 29:
1416 FF_RULE_SETUP
1417 #line 456 "eval.l"
1418 { return( fftext[0] ); }
1419 FF_BREAK
1420 case 30:
1421 FF_RULE_SETUP
1422 #line 457 "eval.l"
1423 ECHO;
1424 FF_BREAK
1425 #line 1426 "<stdout>"
1426 case FF_STATE_EOF(INITIAL):
1427 ffterminate();
1428
1429 case FF_END_OF_BUFFER:
1430 {
1431 /* Amount of text matched not including the EOB char. */
1432 int ff_amount_of_matched_text = (int) (ff_cp - (fftext_ptr)) - 1;
1433
1434 /* Undo the effects of FF_DO_BEFORE_ACTION. */
1435 *ff_cp = (ff_hold_char);
1436 FF_RESTORE_FF_MORE_OFFSET
1437
1438 if ( FF_CURRENT_BUFFER_LVALUE->ff_buffer_status == FF_BUFFER_NEW )
1439 {
1440 /* We're scanning a new file or input source. It's
1441 * possible that this happened because the user
1442 * just pointed ffin at a new source and called
1443 * fflex(). If so, then we have to assure
1444 * consistency between FF_CURRENT_BUFFER and our
1445 * globals. Here is the right place to do so, because
1446 * this is the first action (other than possibly a
1447 * back-up) that will match for the new input source.
1448 */
1449 (ff_n_chars) = FF_CURRENT_BUFFER_LVALUE->ff_n_chars;
1450 FF_CURRENT_BUFFER_LVALUE->ff_input_file = ffin;
1451 FF_CURRENT_BUFFER_LVALUE->ff_buffer_status = FF_BUFFER_NORMAL;
1452 }
1453
1454 /* Note that here we test for ff_c_buf_p "<=" to the position
1455 * of the first EOB in the buffer, since ff_c_buf_p will
1456 * already have been incremented past the NUL character
1457 * (since all states make transitions on EOB to the
1458 * end-of-buffer state). Contrast this with the test
1459 * in input().
1460 */
1461 if ( (ff_c_buf_p) <= &FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[(ff_n_chars)] )
1462 { /* This was really a NUL. */
1463 ff_state_type ff_next_state;
1464
1465 (ff_c_buf_p) = (fftext_ptr) + ff_amount_of_matched_text;
1466
1467 ff_current_state = ff_get_previous_state( );
1468
1469 /* Okay, we're now positioned to make the NUL
1470 * transition. We couldn't have
1471 * ff_get_previous_state() go ahead and do it
1472 * for us because it doesn't know how to deal
1473 * with the possibility of jamming (and we don't
1474 * want to build jamming into it because then it
1475 * will run more slowly).
1476 */
1477
1478 ff_next_state = ff_try_NUL_trans( ff_current_state );
1479
1480 ff_bp = (fftext_ptr) + FF_MORE_ADJ;
1481
1482 if ( ff_next_state )
1483 {
1484 /* Consume the NUL. */
1485 ff_cp = ++(ff_c_buf_p);
1486 ff_current_state = ff_next_state;
1487 goto ff_match;
1488 }
1489
1490 else
1491 {
1492 ff_cp = (ff_c_buf_p);
1493 goto ff_find_action;
1494 }
1495 }
1496
1497 else switch ( ff_get_next_buffer( ) )
1498 {
1499 case EOB_ACT_END_OF_FILE:
1500 {
1501 (ff_did_buffer_switch_on_eof) = 0;
1502
1503 if ( ffwrap( ) )
1504 {
1505 /* Note: because we've taken care in
1506 * ff_get_next_buffer() to have set up
1507 * fftext, we can now set up
1508 * ff_c_buf_p so that if some total
1509 * hoser (like flex itself) wants to
1510 * call the scanner after we return the
1511 * FF_NULL, it'll still work - another
1512 * FF_NULL will get returned.
1513 */
1514 (ff_c_buf_p) = (fftext_ptr) + FF_MORE_ADJ;
1515
1516 ff_act = FF_STATE_EOF(FF_START);
1517 goto do_action;
1518 }
1519
1520 else
1521 {
1522 if ( ! (ff_did_buffer_switch_on_eof) )
1523 FF_NEW_FILE;
1524 }
1525 break;
1526 }
1527
1528 case EOB_ACT_CONTINUE_SCAN:
1529 (ff_c_buf_p) =
1530 (fftext_ptr) + ff_amount_of_matched_text;
1531
1532 ff_current_state = ff_get_previous_state( );
1533
1534 ff_cp = (ff_c_buf_p);
1535 ff_bp = (fftext_ptr) + FF_MORE_ADJ;
1536 goto ff_match;
1537
1538 case EOB_ACT_LAST_MATCH:
1539 (ff_c_buf_p) =
1540 &FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[(ff_n_chars)];
1541
1542 ff_current_state = ff_get_previous_state( );
1543
1544 ff_cp = (ff_c_buf_p);
1545 ff_bp = (fftext_ptr) + FF_MORE_ADJ;
1546 goto ff_find_action;
1547 }
1548 break;
1549 }
1550
1551 default:
1552 FF_FATAL_ERROR(
1553 "fatal flex scanner internal error--no action found" );
1554 } /* end of action switch */
1555 } /* end of scanning one token */
1556 } /* end of fflex */
1557
1558 /* ff_get_next_buffer - try to read in a new buffer
1559 *
1560 * Returns a code representing an action:
1561 * EOB_ACT_LAST_MATCH -
1562 * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1563 * EOB_ACT_END_OF_FILE - end of file
1564 */
ff_get_next_buffer(void)1565 static int ff_get_next_buffer (void)
1566 {
1567 register char *dest = FF_CURRENT_BUFFER_LVALUE->ff_ch_buf;
1568 register char *source = (fftext_ptr);
1569 register int number_to_move, i;
1570 int ret_val;
1571
1572 if ( (ff_c_buf_p) > &FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[(ff_n_chars) + 1] )
1573 FF_FATAL_ERROR(
1574 "fatal flex scanner internal error--end of buffer missed" );
1575
1576 if ( FF_CURRENT_BUFFER_LVALUE->ff_fill_buffer == 0 )
1577 { /* Don't try to fill the buffer, so this is an EOF. */
1578 if ( (ff_c_buf_p) - (fftext_ptr) - FF_MORE_ADJ == 1 )
1579 {
1580 /* We matched a single character, the EOB, so
1581 * treat this as a final EOF.
1582 */
1583 return EOB_ACT_END_OF_FILE;
1584 }
1585
1586 else
1587 {
1588 /* We matched some text prior to the EOB, first
1589 * process it.
1590 */
1591 return EOB_ACT_LAST_MATCH;
1592 }
1593 }
1594
1595 /* Try to read more data. */
1596
1597 /* First move last chars to start of buffer. */
1598 number_to_move = (int) ((ff_c_buf_p) - (fftext_ptr)) - 1;
1599
1600 for ( i = 0; i < number_to_move; ++i )
1601 *(dest++) = *(source++);
1602
1603 if ( FF_CURRENT_BUFFER_LVALUE->ff_buffer_status == FF_BUFFER_EOF_PENDING )
1604 /* don't do the read, it's not guaranteed to return an EOF,
1605 * just force an EOF
1606 */
1607 FF_CURRENT_BUFFER_LVALUE->ff_n_chars = (ff_n_chars) = 0;
1608
1609 else
1610 {
1611 ff_size_t num_to_read =
1612 FF_CURRENT_BUFFER_LVALUE->ff_buf_size - number_to_move - 1;
1613
1614 while ( num_to_read <= 0 )
1615 { /* Not enough room in the buffer - grow it. */
1616
1617 /* just a shorter name for the current buffer */
1618 FF_BUFFER_STATE b = FF_CURRENT_BUFFER;
1619
1620 int ff_c_buf_p_offset =
1621 (int) ((ff_c_buf_p) - b->ff_ch_buf);
1622
1623 if ( b->ff_is_our_buffer )
1624 {
1625 ff_size_t new_size = b->ff_buf_size * 2;
1626
1627 if ( new_size <= 0 )
1628 b->ff_buf_size += b->ff_buf_size / 8;
1629 else
1630 b->ff_buf_size *= 2;
1631
1632 b->ff_ch_buf = (char *)
1633 /* Include room in for 2 EOB chars. */
1634 ffrealloc((void *) b->ff_ch_buf,b->ff_buf_size + 2 );
1635 }
1636 else
1637 /* Can't grow it, we don't own it. */
1638 b->ff_ch_buf = 0;
1639
1640 if ( ! b->ff_ch_buf )
1641 FF_FATAL_ERROR(
1642 "fatal error - scanner input buffer overflow" );
1643
1644 (ff_c_buf_p) = &b->ff_ch_buf[ff_c_buf_p_offset];
1645
1646 num_to_read = FF_CURRENT_BUFFER_LVALUE->ff_buf_size -
1647 number_to_move - 1;
1648
1649 }
1650
1651 if ( num_to_read > FF_READ_BUF_SIZE )
1652 num_to_read = FF_READ_BUF_SIZE;
1653
1654 /* Read in more data. */
1655 FF_INPUT( (&FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[number_to_move]),
1656 (ff_n_chars), num_to_read );
1657
1658 FF_CURRENT_BUFFER_LVALUE->ff_n_chars = (ff_n_chars);
1659 }
1660
1661 if ( (ff_n_chars) == 0 )
1662 {
1663 if ( number_to_move == FF_MORE_ADJ )
1664 {
1665 ret_val = EOB_ACT_END_OF_FILE;
1666 ffrestart(ffin );
1667 }
1668
1669 else
1670 {
1671 ret_val = EOB_ACT_LAST_MATCH;
1672 FF_CURRENT_BUFFER_LVALUE->ff_buffer_status =
1673 FF_BUFFER_EOF_PENDING;
1674 }
1675 }
1676
1677 else
1678 ret_val = EOB_ACT_CONTINUE_SCAN;
1679
1680 if ((ff_size_t) ((ff_n_chars) + number_to_move) > FF_CURRENT_BUFFER_LVALUE->ff_buf_size) {
1681 /* Extend the array by 50%, plus the number we really need. */
1682 ff_size_t new_size = (ff_n_chars) + number_to_move + ((ff_n_chars) >> 1);
1683 FF_CURRENT_BUFFER_LVALUE->ff_ch_buf = (char *) ffrealloc((void *) FF_CURRENT_BUFFER_LVALUE->ff_ch_buf,new_size );
1684 if ( ! FF_CURRENT_BUFFER_LVALUE->ff_ch_buf )
1685 FF_FATAL_ERROR( "out of dynamic memory in ff_get_next_buffer()" );
1686 }
1687
1688 (ff_n_chars) += number_to_move;
1689 FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[(ff_n_chars)] = FF_END_OF_BUFFER_CHAR;
1690 FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[(ff_n_chars) + 1] = FF_END_OF_BUFFER_CHAR;
1691
1692 (fftext_ptr) = &FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[0];
1693
1694 return ret_val;
1695 }
1696
1697 /* ff_get_previous_state - get the state just before the EOB char was reached */
1698
ff_get_previous_state(void)1699 static ff_state_type ff_get_previous_state (void)
1700 {
1701 register ff_state_type ff_current_state;
1702 register char *ff_cp;
1703
1704 ff_current_state = (ff_start);
1705
1706 for ( ff_cp = (fftext_ptr) + FF_MORE_ADJ; ff_cp < (ff_c_buf_p); ++ff_cp )
1707 {
1708 register FF_CHAR ff_c = (*ff_cp ? ff_ec[FF_SC_TO_UI(*ff_cp)] : 1);
1709 if ( ff_accept[ff_current_state] )
1710 {
1711 (ff_last_accepting_state) = ff_current_state;
1712 (ff_last_accepting_cpos) = ff_cp;
1713 }
1714 while ( ff_chk[ff_base[ff_current_state] + ff_c] != ff_current_state )
1715 {
1716 ff_current_state = (int) ff_def[ff_current_state];
1717 if ( ff_current_state >= 174 )
1718 ff_c = ff_meta[(unsigned int) ff_c];
1719 }
1720 ff_current_state = ff_nxt[ff_base[ff_current_state] + (unsigned int) ff_c];
1721 }
1722
1723 return ff_current_state;
1724 }
1725
1726 /* ff_try_NUL_trans - try to make a transition on the NUL character
1727 *
1728 * synopsis
1729 * next_state = ff_try_NUL_trans( current_state );
1730 */
ff_try_NUL_trans(ff_state_type ff_current_state)1731 static ff_state_type ff_try_NUL_trans (ff_state_type ff_current_state )
1732 {
1733 register int ff_is_jam;
1734 register char *ff_cp = (ff_c_buf_p);
1735
1736 register FF_CHAR ff_c = 1;
1737 if ( ff_accept[ff_current_state] )
1738 {
1739 (ff_last_accepting_state) = ff_current_state;
1740 (ff_last_accepting_cpos) = ff_cp;
1741 }
1742 while ( ff_chk[ff_base[ff_current_state] + ff_c] != ff_current_state )
1743 {
1744 ff_current_state = (int) ff_def[ff_current_state];
1745 if ( ff_current_state >= 174 )
1746 ff_c = ff_meta[(unsigned int) ff_c];
1747 }
1748 ff_current_state = ff_nxt[ff_base[ff_current_state] + (unsigned int) ff_c];
1749 ff_is_jam = (ff_current_state == 173);
1750
1751 return ff_is_jam ? 0 : ff_current_state;
1752 }
1753
ffunput(int c,register char * ff_bp)1754 static void ffunput (int c, register char * ff_bp )
1755 {
1756 register char *ff_cp;
1757
1758 ff_cp = (ff_c_buf_p);
1759
1760 /* undo effects of setting up fftext */
1761 *ff_cp = (ff_hold_char);
1762
1763 if ( ff_cp < FF_CURRENT_BUFFER_LVALUE->ff_ch_buf + 2 )
1764 { /* need to shift things up to make room */
1765 /* +2 for EOB chars. */
1766 register ff_size_t number_to_move = (ff_n_chars) + 2;
1767 register char *dest = &FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[
1768 FF_CURRENT_BUFFER_LVALUE->ff_buf_size + 2];
1769 register char *source =
1770 &FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[number_to_move];
1771
1772 while ( source > FF_CURRENT_BUFFER_LVALUE->ff_ch_buf )
1773 *--dest = *--source;
1774
1775 ff_cp += (int) (dest - source);
1776 ff_bp += (int) (dest - source);
1777 FF_CURRENT_BUFFER_LVALUE->ff_n_chars =
1778 (ff_n_chars) = FF_CURRENT_BUFFER_LVALUE->ff_buf_size;
1779
1780 if ( ff_cp < FF_CURRENT_BUFFER_LVALUE->ff_ch_buf + 2 )
1781 FF_FATAL_ERROR( "flex scanner push-back overflow" );
1782 }
1783
1784 *--ff_cp = (char) c;
1785
1786 (fftext_ptr) = ff_bp;
1787 (ff_hold_char) = *ff_cp;
1788 (ff_c_buf_p) = ff_cp;
1789 }
1790
1791 #ifndef FF_NO_INPUT
1792 #ifdef __cplusplus
ffinput(void)1793 static int ffinput (void)
1794 #else
1795 static int input (void)
1796 #endif
1797
1798 {
1799 int c;
1800
1801 *(ff_c_buf_p) = (ff_hold_char);
1802
1803 if ( *(ff_c_buf_p) == FF_END_OF_BUFFER_CHAR )
1804 {
1805 /* ff_c_buf_p now points to the character we want to return.
1806 * If this occurs *before* the EOB characters, then it's a
1807 * valid NUL; if not, then we've hit the end of the buffer.
1808 */
1809 if ( (ff_c_buf_p) < &FF_CURRENT_BUFFER_LVALUE->ff_ch_buf[(ff_n_chars)] )
1810 /* This was really a NUL. */
1811 *(ff_c_buf_p) = '\0';
1812
1813 else
1814 { /* need more input */
1815 ff_size_t offset = (ff_c_buf_p) - (fftext_ptr);
1816 ++(ff_c_buf_p);
1817
1818 switch ( ff_get_next_buffer( ) )
1819 {
1820 case EOB_ACT_LAST_MATCH:
1821 /* This happens because ff_g_n_b()
1822 * sees that we've accumulated a
1823 * token and flags that we need to
1824 * try matching the token before
1825 * proceeding. But for input(),
1826 * there's no matching to consider.
1827 * So convert the EOB_ACT_LAST_MATCH
1828 * to EOB_ACT_END_OF_FILE.
1829 */
1830
1831 /* Reset buffer status. */
1832 ffrestart(ffin );
1833
1834 /*FALLTHROUGH*/
1835
1836 case EOB_ACT_END_OF_FILE:
1837 {
1838 if ( ffwrap( ) )
1839 return 0;
1840
1841 if ( ! (ff_did_buffer_switch_on_eof) )
1842 FF_NEW_FILE;
1843 #ifdef __cplusplus
1844 return ffinput();
1845 #else
1846 return input();
1847 #endif
1848 }
1849
1850 case EOB_ACT_CONTINUE_SCAN:
1851 (ff_c_buf_p) = (fftext_ptr) + offset;
1852 break;
1853 }
1854 }
1855 }
1856
1857 c = *(unsigned char *) (ff_c_buf_p); /* cast for 8-bit char's */
1858 *(ff_c_buf_p) = '\0'; /* preserve fftext */
1859 (ff_hold_char) = *++(ff_c_buf_p);
1860
1861 return c;
1862 }
1863 #endif /* ifndef FF_NO_INPUT */
1864
1865 /** Immediately switch to a different input stream.
1866 * @param input_file A readable stream.
1867 *
1868 * @note This function does not reset the start condition to @c INITIAL .
1869 */
ffrestart(FILE * input_file)1870 void ffrestart (FILE * input_file )
1871 {
1872
1873 if ( ! FF_CURRENT_BUFFER ){
1874 ffensure_buffer_stack ();
1875 FF_CURRENT_BUFFER_LVALUE =
1876 ff_create_buffer(ffin,FF_BUF_SIZE );
1877 }
1878
1879 ff_init_buffer(FF_CURRENT_BUFFER,input_file );
1880 ff_load_buffer_state( );
1881 }
1882
1883 /** Switch to a different input buffer.
1884 * @param new_buffer The new input buffer.
1885 *
1886 */
ff_switch_to_buffer(FF_BUFFER_STATE new_buffer)1887 void ff_switch_to_buffer (FF_BUFFER_STATE new_buffer )
1888 {
1889
1890 /* TODO. We should be able to replace this entire function body
1891 * with
1892 * ffpop_buffer_state();
1893 * ffpush_buffer_state(new_buffer);
1894 */
1895 ffensure_buffer_stack ();
1896 if ( FF_CURRENT_BUFFER == new_buffer )
1897 return;
1898
1899 if ( FF_CURRENT_BUFFER )
1900 {
1901 /* Flush out information for old buffer. */
1902 *(ff_c_buf_p) = (ff_hold_char);
1903 FF_CURRENT_BUFFER_LVALUE->ff_buf_pos = (ff_c_buf_p);
1904 FF_CURRENT_BUFFER_LVALUE->ff_n_chars = (ff_n_chars);
1905 }
1906
1907 FF_CURRENT_BUFFER_LVALUE = new_buffer;
1908 ff_load_buffer_state( );
1909
1910 /* We don't actually know whether we did this switch during
1911 * EOF (ffwrap()) processing, but the only time this flag
1912 * is looked at is after ffwrap() is called, so it's safe
1913 * to go ahead and always set it.
1914 */
1915 (ff_did_buffer_switch_on_eof) = 1;
1916 }
1917
ff_load_buffer_state(void)1918 static void ff_load_buffer_state (void)
1919 {
1920 (ff_n_chars) = FF_CURRENT_BUFFER_LVALUE->ff_n_chars;
1921 (fftext_ptr) = (ff_c_buf_p) = FF_CURRENT_BUFFER_LVALUE->ff_buf_pos;
1922 ffin = FF_CURRENT_BUFFER_LVALUE->ff_input_file;
1923 (ff_hold_char) = *(ff_c_buf_p);
1924 }
1925
1926 /** Allocate and initialize an input buffer state.
1927 * @param file A readable stream.
1928 * @param size The character buffer size in bytes. When in doubt, use @c FF_BUF_SIZE.
1929 *
1930 * @return the allocated buffer state.
1931 */
ff_create_buffer(FILE * file,int size)1932 FF_BUFFER_STATE ff_create_buffer (FILE * file, int size )
1933 {
1934 FF_BUFFER_STATE b;
1935
1936 b = (FF_BUFFER_STATE) ffalloc(sizeof( struct ff_buffer_state ) );
1937 if ( ! b )
1938 FF_FATAL_ERROR( "out of dynamic memory in ff_create_buffer()" );
1939
1940 b->ff_buf_size = size;
1941
1942 /* ff_ch_buf has to be 2 characters longer than the size given because
1943 * we need to put in 2 end-of-buffer characters.
1944 */
1945 b->ff_ch_buf = (char *) ffalloc(b->ff_buf_size + 2 );
1946 if ( ! b->ff_ch_buf )
1947 FF_FATAL_ERROR( "out of dynamic memory in ff_create_buffer()" );
1948
1949 b->ff_is_our_buffer = 1;
1950
1951 ff_init_buffer(b,file );
1952
1953 return b;
1954 }
1955
1956 /** Destroy the buffer.
1957 * @param b a buffer created with ff_create_buffer()
1958 *
1959 */
ff_delete_buffer(FF_BUFFER_STATE b)1960 void ff_delete_buffer (FF_BUFFER_STATE b )
1961 {
1962
1963 if ( ! b )
1964 return;
1965
1966 if ( b == FF_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1967 FF_CURRENT_BUFFER_LVALUE = (FF_BUFFER_STATE) 0;
1968
1969 if ( b->ff_is_our_buffer )
1970 yyfffree((void *) b->ff_ch_buf );
1971
1972 yyfffree((void *) b );
1973 }
1974
1975 #ifndef __cplusplus
1976 extern int isatty (int );
1977 #endif /* __cplusplus */
1978
1979 /* Initializes or reinitializes a buffer.
1980 * This function is sometimes called more than once on the same buffer,
1981 * such as during a ffrestart() or at EOF.
1982 */
ff_init_buffer(FF_BUFFER_STATE b,FILE * file)1983 static void ff_init_buffer (FF_BUFFER_STATE b, FILE * file )
1984
1985 {
1986 int oerrno = errno;
1987
1988 ff_flush_buffer(b );
1989
1990 b->ff_input_file = file;
1991 b->ff_fill_buffer = 1;
1992
1993 /* If b is the current buffer, then ff_init_buffer was _probably_
1994 * called from ffrestart() or through ff_get_next_buffer.
1995 * In that case, we don't want to reset the lineno or column.
1996 */
1997 if (b != FF_CURRENT_BUFFER){
1998 b->ff_bs_lineno = 1;
1999 b->ff_bs_column = 0;
2000 }
2001
2002 b->ff_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
2003
2004 errno = oerrno;
2005 }
2006
2007 /** Discard all buffered characters. On the next scan, FF_INPUT will be called.
2008 * @param b the buffer state to be flushed, usually @c FF_CURRENT_BUFFER.
2009 *
2010 */
ff_flush_buffer(FF_BUFFER_STATE b)2011 void ff_flush_buffer (FF_BUFFER_STATE b )
2012 {
2013 if ( ! b )
2014 return;
2015
2016 b->ff_n_chars = 0;
2017
2018 /* We always need two end-of-buffer characters. The first causes
2019 * a transition to the end-of-buffer state. The second causes
2020 * a jam in that state.
2021 */
2022 b->ff_ch_buf[0] = FF_END_OF_BUFFER_CHAR;
2023 b->ff_ch_buf[1] = FF_END_OF_BUFFER_CHAR;
2024
2025 b->ff_buf_pos = &b->ff_ch_buf[0];
2026
2027 b->ff_at_bol = 1;
2028 b->ff_buffer_status = FF_BUFFER_NEW;
2029
2030 if ( b == FF_CURRENT_BUFFER )
2031 ff_load_buffer_state( );
2032 }
2033
2034 /** Pushes the new state onto the stack. The new state becomes
2035 * the current state. This function will allocate the stack
2036 * if necessary.
2037 * @param new_buffer The new state.
2038 *
2039 */
ffpush_buffer_state(FF_BUFFER_STATE new_buffer)2040 void ffpush_buffer_state (FF_BUFFER_STATE new_buffer )
2041 {
2042 if (new_buffer == NULL)
2043 return;
2044
2045 ffensure_buffer_stack();
2046
2047 /* This block is copied from ff_switch_to_buffer. */
2048 if ( FF_CURRENT_BUFFER )
2049 {
2050 /* Flush out information for old buffer. */
2051 *(ff_c_buf_p) = (ff_hold_char);
2052 FF_CURRENT_BUFFER_LVALUE->ff_buf_pos = (ff_c_buf_p);
2053 FF_CURRENT_BUFFER_LVALUE->ff_n_chars = (ff_n_chars);
2054 }
2055
2056 /* Only push if top exists. Otherwise, replace top. */
2057 if (FF_CURRENT_BUFFER)
2058 (ff_buffer_stack_top)++;
2059 FF_CURRENT_BUFFER_LVALUE = new_buffer;
2060
2061 /* copied from ff_switch_to_buffer. */
2062 ff_load_buffer_state( );
2063 (ff_did_buffer_switch_on_eof) = 1;
2064 }
2065
2066 /** Removes and deletes the top of the stack, if present.
2067 * The next element becomes the new top.
2068 *
2069 */
ffpop_buffer_state(void)2070 void ffpop_buffer_state (void)
2071 {
2072 if (!FF_CURRENT_BUFFER)
2073 return;
2074
2075 ff_delete_buffer(FF_CURRENT_BUFFER );
2076 FF_CURRENT_BUFFER_LVALUE = NULL;
2077 if ((ff_buffer_stack_top) > 0)
2078 --(ff_buffer_stack_top);
2079
2080 if (FF_CURRENT_BUFFER) {
2081 ff_load_buffer_state( );
2082 (ff_did_buffer_switch_on_eof) = 1;
2083 }
2084 }
2085
2086 /* Allocates the stack if it does not exist.
2087 * Guarantees space for at least one push.
2088 */
ffensure_buffer_stack(void)2089 static void ffensure_buffer_stack (void)
2090 {
2091 ff_size_t num_to_alloc;
2092
2093 if (!(ff_buffer_stack)) {
2094
2095 /* First allocation is just for 2 elements, since we don't know if this
2096 * scanner will even need a stack. We use 2 instead of 1 to avoid an
2097 * immediate realloc on the next call.
2098 */
2099 num_to_alloc = 1;
2100 (ff_buffer_stack) = (struct ff_buffer_state**)ffalloc
2101 (num_to_alloc * sizeof(struct ff_buffer_state*)
2102 );
2103 if ( ! (ff_buffer_stack) )
2104 FF_FATAL_ERROR( "out of dynamic memory in ffensure_buffer_stack()" );
2105
2106 memset((ff_buffer_stack), 0, num_to_alloc * sizeof(struct ff_buffer_state*));
2107
2108 (ff_buffer_stack_max) = num_to_alloc;
2109 (ff_buffer_stack_top) = 0;
2110 return;
2111 }
2112
2113 if ((ff_buffer_stack_top) >= ((ff_buffer_stack_max)) - 1){
2114
2115 /* Increase the buffer to prepare for a possible push. */
2116 int grow_size = 8 /* arbitrary grow size */;
2117
2118 num_to_alloc = (ff_buffer_stack_max) + grow_size;
2119 (ff_buffer_stack) = (struct ff_buffer_state**)ffrealloc
2120 ((ff_buffer_stack),
2121 num_to_alloc * sizeof(struct ff_buffer_state*)
2122 );
2123 if ( ! (ff_buffer_stack) )
2124 FF_FATAL_ERROR( "out of dynamic memory in ffensure_buffer_stack()" );
2125
2126 /* zero only the new slots.*/
2127 memset((ff_buffer_stack) + (ff_buffer_stack_max), 0, grow_size * sizeof(struct ff_buffer_state*));
2128 (ff_buffer_stack_max) = num_to_alloc;
2129 }
2130 }
2131
2132 /** Setup the input buffer state to scan directly from a user-specified character buffer.
2133 * @param base the character buffer
2134 * @param size the size in bytes of the character buffer
2135 *
2136 * @return the newly allocated buffer state object.
2137 */
ff_scan_buffer(char * base,ff_size_t size)2138 FF_BUFFER_STATE ff_scan_buffer (char * base, ff_size_t size )
2139 {
2140 FF_BUFFER_STATE b;
2141
2142 if ( size < 2 ||
2143 base[size-2] != FF_END_OF_BUFFER_CHAR ||
2144 base[size-1] != FF_END_OF_BUFFER_CHAR )
2145 /* They forgot to leave room for the EOB's. */
2146 return 0;
2147
2148 b = (FF_BUFFER_STATE) ffalloc(sizeof( struct ff_buffer_state ) );
2149 if ( ! b )
2150 FF_FATAL_ERROR( "out of dynamic memory in ff_scan_buffer()" );
2151
2152 b->ff_buf_size = size - 2; /* "- 2" to take care of EOB's */
2153 b->ff_buf_pos = b->ff_ch_buf = base;
2154 b->ff_is_our_buffer = 0;
2155 b->ff_input_file = 0;
2156 b->ff_n_chars = b->ff_buf_size;
2157 b->ff_is_interactive = 0;
2158 b->ff_at_bol = 1;
2159 b->ff_fill_buffer = 0;
2160 b->ff_buffer_status = FF_BUFFER_NEW;
2161
2162 ff_switch_to_buffer(b );
2163
2164 return b;
2165 }
2166
2167 /** Setup the input buffer state to scan a string. The next call to fflex() will
2168 * scan from a @e copy of @a str.
2169 * @param ffstr a NUL-terminated string to scan
2170 *
2171 * @return the newly allocated buffer state object.
2172 * @note If you want to scan bytes that may contain NUL values, then use
2173 * ff_scan_bytes() instead.
2174 */
ff_scan_string(ffconst char * ffstr)2175 FF_BUFFER_STATE ff_scan_string (ffconst char * ffstr )
2176 {
2177
2178 return ff_scan_bytes(ffstr,strlen(ffstr) );
2179 }
2180
2181 /** Setup the input buffer state to scan the given bytes. The next call to fflex() will
2182 * scan from a @e copy of @a bytes.
2183 * @param bytes the byte buffer to scan
2184 * @param len the number of bytes in the buffer pointed to by @a bytes.
2185 *
2186 * @return the newly allocated buffer state object.
2187 */
ff_scan_bytes(ffconst char * ffbytes,ff_size_t _ffbytes_len)2188 FF_BUFFER_STATE ff_scan_bytes (ffconst char * ffbytes, ff_size_t _ffbytes_len )
2189 {
2190 FF_BUFFER_STATE b;
2191 char *buf;
2192 ff_size_t n, i;
2193
2194 /* Get memory for full buffer, including space for trailing EOB's. */
2195 n = _ffbytes_len + 2;
2196 buf = (char *) ffalloc(n );
2197 if ( ! buf )
2198 FF_FATAL_ERROR( "out of dynamic memory in ff_scan_bytes()" );
2199
2200 for ( i = 0; i < _ffbytes_len; ++i )
2201 buf[i] = ffbytes[i];
2202
2203 buf[_ffbytes_len] = buf[_ffbytes_len+1] = FF_END_OF_BUFFER_CHAR;
2204
2205 b = ff_scan_buffer(buf,n );
2206 if ( ! b )
2207 FF_FATAL_ERROR( "bad buffer in ff_scan_bytes()" );
2208
2209 /* It's okay to grow etc. this buffer, and we should throw it
2210 * away when we're done.
2211 */
2212 b->ff_is_our_buffer = 1;
2213
2214 return b;
2215 }
2216
2217 #ifndef FF_EXIT_FAILURE
2218 #define FF_EXIT_FAILURE 2
2219 #endif
2220
ff_fatal_error(ffconst char * msg)2221 static void ff_fatal_error (ffconst char* msg )
2222 {
2223 (void) fprintf( stderr, "%s\n", msg );
2224 exit( FF_EXIT_FAILURE );
2225 }
2226
2227 /* Redefine ffless() so it works in section 3 code. */
2228
2229 #undef ffless
2230 #define ffless(n) \
2231 do \
2232 { \
2233 /* Undo effects of setting up fftext. */ \
2234 int ffless_macro_arg = (n); \
2235 FF_LESS_LINENO(ffless_macro_arg);\
2236 fftext[ffleng] = (ff_hold_char); \
2237 (ff_c_buf_p) = fftext + ffless_macro_arg; \
2238 (ff_hold_char) = *(ff_c_buf_p); \
2239 *(ff_c_buf_p) = '\0'; \
2240 ffleng = ffless_macro_arg; \
2241 } \
2242 while ( 0 )
2243
2244 /* Accessor methods (get/set functions) to struct members. */
2245
2246 /** Get the current line number.
2247 *
2248 */
ffget_lineno(void)2249 int ffget_lineno (void)
2250 {
2251
2252 return fflineno;
2253 }
2254
2255 /** Get the input stream.
2256 *
2257 */
ffget_in(void)2258 FILE *ffget_in (void)
2259 {
2260 return ffin;
2261 }
2262
2263 /** Get the output stream.
2264 *
2265 */
ffget_out(void)2266 FILE *ffget_out (void)
2267 {
2268 return ffout;
2269 }
2270
2271 /** Get the length of the current token.
2272 *
2273 */
ffget_leng(void)2274 ff_size_t ffget_leng (void)
2275 {
2276 return ffleng;
2277 }
2278
2279 /** Get the current token.
2280 *
2281 */
2282
ffget_text(void)2283 char *ffget_text (void)
2284 {
2285 return fftext;
2286 }
2287
2288 /** Set the current line number.
2289 * @param line_number
2290 *
2291 */
ffset_lineno(int line_number)2292 void ffset_lineno (int line_number )
2293 {
2294
2295 fflineno = line_number;
2296 }
2297
2298 /** Set the input stream. This does not discard the current
2299 * input buffer.
2300 * @param in_str A readable stream.
2301 *
2302 * @see ff_switch_to_buffer
2303 */
ffset_in(FILE * in_str)2304 void ffset_in (FILE * in_str )
2305 {
2306 ffin = in_str ;
2307 }
2308
ffset_out(FILE * out_str)2309 void ffset_out (FILE * out_str )
2310 {
2311 ffout = out_str ;
2312 }
2313
ffget_debug(void)2314 int ffget_debug (void)
2315 {
2316 return ff_flex_debug;
2317 }
2318
ffset_debug(int bdebug)2319 void ffset_debug (int bdebug )
2320 {
2321 ff_flex_debug = bdebug ;
2322 }
2323
ff_init_globals(void)2324 static int ff_init_globals (void)
2325 {
2326 /* Initialization is the same as for the non-reentrant scanner.
2327 * This function is called from fflex_destroy(), so don't allocate here.
2328 */
2329
2330 (ff_buffer_stack) = 0;
2331 (ff_buffer_stack_top) = 0;
2332 (ff_buffer_stack_max) = 0;
2333 (ff_c_buf_p) = (char *) 0;
2334 (ff_init) = 0;
2335 (ff_start) = 0;
2336
2337 /* Defined in main.c */
2338 #ifdef FF_STDINIT
2339 ffin = stdin;
2340 ffout = stdout;
2341 #else
2342 ffin = (FILE *) 0;
2343 ffout = (FILE *) 0;
2344 #endif
2345
2346 /* For future reference: Set errno on error, since we are called by
2347 * fflex_init()
2348 */
2349 return 0;
2350 }
2351
2352 /* fflex_destroy is for both reentrant and non-reentrant scanners. */
fflex_destroy(void)2353 int fflex_destroy (void)
2354 {
2355
2356 /* Pop the buffer stack, destroying each element. */
2357 while(FF_CURRENT_BUFFER){
2358 ff_delete_buffer(FF_CURRENT_BUFFER );
2359 FF_CURRENT_BUFFER_LVALUE = NULL;
2360 ffpop_buffer_state();
2361 }
2362
2363 /* Destroy the stack itself. */
2364 yyfffree((ff_buffer_stack) );
2365 (ff_buffer_stack) = NULL;
2366
2367 /* Reset the globals. This is important in a non-reentrant scanner so the next time
2368 * fflex() is called, initialization will occur. */
2369 ff_init_globals( );
2370
2371 return 0;
2372 }
2373
2374 /*
2375 * Internal utility routines.
2376 */
2377
2378 #ifndef fftext_ptr
ff_flex_strncpy(char * s1,ffconst char * s2,int n)2379 static void ff_flex_strncpy (char* s1, ffconst char * s2, int n )
2380 {
2381 register int i;
2382 for ( i = 0; i < n; ++i )
2383 s1[i] = s2[i];
2384 }
2385 #endif
2386
2387 #ifdef FF_NEED_STRLEN
ff_flex_strlen(ffconst char * s)2388 static int ff_flex_strlen (ffconst char * s )
2389 {
2390 register int n;
2391 for ( n = 0; s[n]; ++n )
2392 ;
2393
2394 return n;
2395 }
2396 #endif
2397
ffalloc(ff_size_t size)2398 void *ffalloc (ff_size_t size )
2399 {
2400 return (void *) malloc( size );
2401 }
2402
ffrealloc(void * ptr,ff_size_t size)2403 void *ffrealloc (void * ptr, ff_size_t size )
2404 {
2405 /* The cast to (char *) in the following accommodates both
2406 * implementations that use char* generic pointers, and those
2407 * that use void* generic pointers. It works with the latter
2408 * because both ANSI C and C++ allow castless assignment from
2409 * any pointer type to void*, and deal with argument conversions
2410 * as though doing an assignment.
2411 */
2412 return (void *) realloc( (char *) ptr, size );
2413 }
2414
yyfffree(void * ptr)2415 void yyfffree (void * ptr )
2416 {
2417 free( (char *) ptr ); /* see ffrealloc() for (char *) cast */
2418 }
2419
2420 #define FFTABLES_NAME "fftables"
2421
2422 #line 457 "eval.l"
2423
2424
2425
ffwrap()2426 int ffwrap()
2427 {
2428 /* MJT -- 13 June 1996
2429 Supplied for compatibility with
2430 pre-2.5.1 versions of flex which
2431 do not recognize %option noffwrap
2432 */
2433 return(1);
2434 }
2435
2436 /*
2437 expr_read is lifted from old ftools.skel.
2438 Now we can use any version of flex with
2439 no .skel file necessary! MJT - 13 June 1996
2440
2441 keep a memory of how many bytes have been
2442 read previously, so that an unlimited-sized
2443 buffer can be supported. PDW - 28 Feb 1998
2444 */
2445
expr_read(char * buf,int nbytes)2446 static int expr_read(char *buf, int nbytes)
2447 {
2448 int n;
2449
2450 n = 0;
2451 if( !gParse.is_eobuf ) {
2452 do {
2453 buf[n++] = gParse.expr[gParse.index++];
2454 } while ((n<nbytes)&&(gParse.expr[gParse.index] != '\0'));
2455 if( gParse.expr[gParse.index] == '\0' ) gParse.is_eobuf = 1;
2456 }
2457 buf[n] = '\0';
2458 return(n);
2459 }
2460
ffGetVariable(char * varName,FFSTYPE * thelval)2461 int ffGetVariable( char *varName, FFSTYPE *thelval )
2462 {
2463 int varNum, type;
2464 char errMsg[MAXVARNAME+25];
2465
2466 varNum = find_variable( varName );
2467 if( varNum<0 ) {
2468 if( gParse.getData ) {
2469 type = (*gParse.getData)( varName, thelval );
2470 } else {
2471 type = pERROR;
2472 gParse.status = PARSE_SYNTAX_ERR;
2473 strcpy (errMsg,"Unable to find data: ");
2474 strncat(errMsg, varName, MAXVARNAME);
2475 ffpmsg (errMsg);
2476 }
2477 } else {
2478 /* Convert variable type into expression type */
2479 switch( gParse.varData[ varNum ].type ) {
2480 case LONG:
2481 case DOUBLE: type = COLUMN; break;
2482 case BOOLEAN: type = BCOLUMN; break;
2483 case STRING: type = SCOLUMN; break;
2484 case BITSTR: type = BITCOL; break;
2485 default:
2486 type = pERROR;
2487 gParse.status = PARSE_SYNTAX_ERR;
2488 strcpy (errMsg,"Bad datatype for data: ");
2489 strncat(errMsg, varName, MAXVARNAME);
2490 ffpmsg (errMsg);
2491 break;
2492 }
2493 thelval->lng = varNum;
2494 }
2495 return( type );
2496 }
2497
find_variable(char * varName)2498 static int find_variable(char *varName)
2499 {
2500 int i;
2501
2502 if( gParse.nCols )
2503 for( i=0; i<gParse.nCols; i++ ) {
2504 if( ! fits_strncasecmp(gParse.varData[i].name,varName,MAXVARNAME) ) {
2505 return( i );
2506 }
2507 }
2508 return( -1 );
2509 }
2510
2511