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