Initial commit
[platform/upstream/ccid.git] / src / tokenparser.c
1
2 #line 3 "tokenparser.c"
3
4 #define  YY_INT_ALIGNED short int
5
6 /* A lexical scanner generated by flex */
7
8 #define FLEX_SCANNER
9 #define YY_FLEX_MAJOR_VERSION 2
10 #define YY_FLEX_MINOR_VERSION 6
11 #define YY_FLEX_SUBMINOR_VERSION 4
12 #if YY_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
57 /* Limits of integral types. */
58 #ifndef INT8_MIN
59 #define INT8_MIN               (-128)
60 #endif
61 #ifndef INT16_MIN
62 #define INT16_MIN              (-32767-1)
63 #endif
64 #ifndef INT32_MIN
65 #define INT32_MIN              (-2147483647-1)
66 #endif
67 #ifndef INT8_MAX
68 #define INT8_MAX               (127)
69 #endif
70 #ifndef INT16_MAX
71 #define INT16_MAX              (32767)
72 #endif
73 #ifndef INT32_MAX
74 #define INT32_MAX              (2147483647)
75 #endif
76 #ifndef UINT8_MAX
77 #define UINT8_MAX              (255U)
78 #endif
79 #ifndef UINT16_MAX
80 #define UINT16_MAX             (65535U)
81 #endif
82 #ifndef UINT32_MAX
83 #define UINT32_MAX             (4294967295U)
84 #endif
85
86 #ifndef SIZE_MAX
87 #define SIZE_MAX               (~(size_t)0)
88 #endif
89
90 #endif /* ! C99 */
91
92 #endif /* ! FLEXINT_H */
93
94 /* begin standard C++ headers. */
95
96 /* TODO: this is always defined, so inline it */
97 #define yyconst const
98
99 #if defined(__GNUC__) && __GNUC__ >= 3
100 #define yynoreturn __attribute__((__noreturn__))
101 #else
102 #define yynoreturn
103 #endif
104
105 /* Returned upon end-of-file. */
106 #define YY_NULL 0
107
108 /* Promotes a possibly negative, possibly signed char to an
109  *   integer in range [0..255] for use as an array index.
110  */
111 #define YY_SC_TO_UI(c) ((YY_CHAR) (c))
112
113 /* Enter a start condition.  This macro really ought to take a parameter,
114  * but we do it the disgusting crufty way forced on us by the ()-less
115  * definition of BEGIN.
116  */
117 #define BEGIN (yy_start) = 1 + 2 *
118 /* Translate the current start state into a value that can be later handed
119  * to BEGIN to return to the state.  The YYSTATE alias is for lex
120  * compatibility.
121  */
122 #define YY_START (((yy_start) - 1) / 2)
123 #define YYSTATE YY_START
124 /* Action number for EOF rule of a given start state. */
125 #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
126 /* Special action meaning "start processing a new file". */
127 #define YY_NEW_FILE yyrestart( yyin  )
128 #define YY_END_OF_BUFFER_CHAR 0
129
130 /* Size of default input buffer. */
131 #ifndef YY_BUF_SIZE
132 #ifdef __ia64__
133 /* On IA-64, the buffer size is 16k, not 8k.
134  * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
135  * Ditto for the __ia64__ case accordingly.
136  */
137 #define YY_BUF_SIZE 32768
138 #else
139 #define YY_BUF_SIZE 16384
140 #endif /* __ia64__ */
141 #endif
142
143 /* The state buf must be large enough to hold one state per character in the main buffer.
144  */
145 #define YY_STATE_BUF_SIZE   ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
146
147 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
148 #define YY_TYPEDEF_YY_BUFFER_STATE
149 typedef struct yy_buffer_state *YY_BUFFER_STATE;
150 #endif
151
152 #ifndef YY_TYPEDEF_YY_SIZE_T
153 #define YY_TYPEDEF_YY_SIZE_T
154 typedef size_t yy_size_t;
155 #endif
156
157 extern int yyleng;
158
159 extern FILE *yyin, *yyout;
160
161 #define EOB_ACT_CONTINUE_SCAN 0
162 #define EOB_ACT_END_OF_FILE 1
163 #define EOB_ACT_LAST_MATCH 2
164     
165     #define YY_LESS_LINENO(n)
166     #define YY_LINENO_REWIND_TO(ptr)
167     
168 /* Return all but the first "n" matched characters back to the input stream. */
169 #define yyless(n) \
170         do \
171                 { \
172                 /* Undo effects of setting up yytext. */ \
173         int yyless_macro_arg = (n); \
174         YY_LESS_LINENO(yyless_macro_arg);\
175                 *yy_cp = (yy_hold_char); \
176                 YY_RESTORE_YY_MORE_OFFSET \
177                 (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
178                 YY_DO_BEFORE_ACTION; /* set up yytext again */ \
179                 } \
180         while ( 0 )
181 #define unput(c) yyunput( c, (yytext_ptr)  )
182
183 #ifndef YY_STRUCT_YY_BUFFER_STATE
184 #define YY_STRUCT_YY_BUFFER_STATE
185 struct yy_buffer_state
186         {
187         FILE *yy_input_file;
188
189         char *yy_ch_buf;                /* input buffer */
190         char *yy_buf_pos;               /* current position in input buffer */
191
192         /* Size of input buffer in bytes, not including room for EOB
193          * characters.
194          */
195         int yy_buf_size;
196
197         /* Number of characters read into yy_ch_buf, not including EOB
198          * characters.
199          */
200         int yy_n_chars;
201
202         /* Whether we "own" the buffer - i.e., we know we created it,
203          * and can realloc() it to grow it, and should free() it to
204          * delete it.
205          */
206         int yy_is_our_buffer;
207
208         /* Whether this is an "interactive" input source; if so, and
209          * if we're using stdio for input, then we want to use getc()
210          * instead of fread(), to make sure we stop fetching input after
211          * each newline.
212          */
213         int yy_is_interactive;
214
215         /* Whether we're considered to be at the beginning of a line.
216          * If so, '^' rules will be active on the next match, otherwise
217          * not.
218          */
219         int yy_at_bol;
220
221     int yy_bs_lineno; /**< The line count. */
222     int yy_bs_column; /**< The column count. */
223
224         /* Whether to try to fill the input buffer when we reach the
225          * end of it.
226          */
227         int yy_fill_buffer;
228
229         int yy_buffer_status;
230
231 #define YY_BUFFER_NEW 0
232 #define YY_BUFFER_NORMAL 1
233         /* When an EOF's been seen but there's still some text to process
234          * then we mark the buffer as YY_EOF_PENDING, to indicate that we
235          * shouldn't try reading from the input source any more.  We might
236          * still have a bunch of tokens to match, though, because of
237          * possible backing-up.
238          *
239          * When we actually see the EOF, we change the status to "new"
240          * (via yyrestart()), so that the user can continue scanning by
241          * just pointing yyin at a new input file.
242          */
243 #define YY_BUFFER_EOF_PENDING 2
244
245         };
246 #endif /* !YY_STRUCT_YY_BUFFER_STATE */
247
248 /* Stack of input buffers. */
249 static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
250 static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
251 static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
252
253 /* We provide macros for accessing buffer states in case in the
254  * future we want to put the buffer states in a more general
255  * "scanner state".
256  *
257  * Returns the top of the stack, or NULL.
258  */
259 #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
260                           ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
261                           : NULL)
262 /* Same as previous macro, but useful when we know that the buffer stack is not
263  * NULL or when we need an lvalue. For internal use only.
264  */
265 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
266
267 /* yy_hold_char holds the character lost when yytext is formed. */
268 static char yy_hold_char;
269 static int yy_n_chars;          /* number of characters read into yy_ch_buf */
270 int yyleng;
271
272 /* Points to current character in buffer. */
273 static char *yy_c_buf_p = NULL;
274 static int yy_init = 0;         /* whether we need to initialize */
275 static int yy_start = 0;        /* start state number */
276
277 /* Flag which is used to allow yywrap()'s to do buffer switches
278  * instead of setting up a fresh yyin.  A bit of a hack ...
279  */
280 static int yy_did_buffer_switch_on_eof;
281
282 void yyrestart ( FILE *input_file  );
283 void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer  );
284 YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size  );
285 void yy_delete_buffer ( YY_BUFFER_STATE b  );
286 void yy_flush_buffer ( YY_BUFFER_STATE b  );
287 void yypush_buffer_state ( YY_BUFFER_STATE new_buffer  );
288 void yypop_buffer_state ( void );
289
290 static void yyensure_buffer_stack ( void );
291 static void yy_load_buffer_state ( void );
292 static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file  );
293 #define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER )
294
295 YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size  );
296 YY_BUFFER_STATE yy_scan_string ( const char *yy_str  );
297 YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len  );
298
299 void *yyalloc ( yy_size_t  );
300 void *yyrealloc ( void *, yy_size_t  );
301 void yyfree ( void *  );
302
303 #define yy_new_buffer yy_create_buffer
304 #define yy_set_interactive(is_interactive) \
305         { \
306         if ( ! YY_CURRENT_BUFFER ){ \
307         yyensure_buffer_stack (); \
308                 YY_CURRENT_BUFFER_LVALUE =    \
309             yy_create_buffer( yyin, YY_BUF_SIZE ); \
310         } \
311         YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
312         }
313 #define yy_set_bol(at_bol) \
314         { \
315         if ( ! YY_CURRENT_BUFFER ){\
316         yyensure_buffer_stack (); \
317                 YY_CURRENT_BUFFER_LVALUE =    \
318             yy_create_buffer( yyin, YY_BUF_SIZE ); \
319         } \
320         YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
321         }
322 #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
323
324 /* Begin user sect3 */
325
326 #define yywrap() (/*CONSTCOND*/1)
327 #define YY_SKIP_YYWRAP
328 typedef flex_uint8_t YY_CHAR;
329
330 FILE *yyin = NULL, *yyout = NULL;
331
332 typedef int yy_state_type;
333
334 extern int yylineno;
335 int yylineno = 1;
336
337 extern char *yytext;
338 #ifdef yytext_ptr
339 #undef yytext_ptr
340 #endif
341 #define yytext_ptr yytext
342
343 static yy_state_type yy_get_previous_state ( void );
344 static yy_state_type yy_try_NUL_trans ( yy_state_type current_state  );
345 static int yy_get_next_buffer ( void );
346 static void yynoreturn yy_fatal_error ( const char* msg  );
347
348 /* Done after the current pattern has been matched and before the
349  * corresponding action - sets up yytext.
350  */
351 #define YY_DO_BEFORE_ACTION \
352         (yytext_ptr) = yy_bp; \
353         yyleng = (int) (yy_cp - yy_bp); \
354         (yy_hold_char) = *yy_cp; \
355         *yy_cp = '\0'; \
356         (yy_c_buf_p) = yy_cp;
357 #define YY_NUM_RULES 7
358 #define YY_END_OF_BUFFER 8
359 /* This struct is not used in this scanner,
360    but its presence is necessary. */
361 struct yy_trans_info
362         {
363         flex_int32_t yy_verify;
364         flex_int32_t yy_nxt;
365         };
366 static const flex_int16_t yy_accept[39] =
367     {   0,
368         0,    0,    8,    6,    4,    2,    1,    6,    1,    0,
369         0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
370         0,    0,    0,    0,    0,    0,    0,    0,    0,    3,
371         0,    0,    0,    0,    0,    0,    5,    0
372     } ;
373
374 static const YY_CHAR yy_ec[256] =
375     {   0,
376         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
377         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
378         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
379         1,    2,    4,    4,    5,    4,    4,    4,    4,    4,
380         4,    4,    4,    4,    4,    4,    6,    7,    7,    7,
381         7,    7,    7,    7,    7,    7,    7,    4,    4,    8,
382         4,    9,    4,    4,   10,   10,   10,   10,   10,   10,
383        10,   10,   10,   10,   10,   10,   10,   10,   10,   10,
384        10,   10,   10,   10,   10,   10,   10,   10,   10,   10,
385         4,    1,    4,    4,    4,    1,   11,   11,   11,   11,
386
387        12,   11,   13,   11,   14,   11,   15,   11,   11,   16,
388        11,   11,   11,   17,   18,   19,   11,   11,   11,   11,
389        20,   11,    1,    1,    1,    4,    1,    1,    1,    1,
390         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
391         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
392         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
393         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
394         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
395         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
396         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
397
398         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
399         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
400         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
401         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
402         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
403         1,    1,    1,    1,    1
404     } ;
405
406 static const YY_CHAR yy_meta[21] =
407     {   0,
408         1,    2,    3,    4,    4,    4,    2,    1,    1,    2,
409         2,    2,    2,    2,    2,    2,    2,    2,    2,    2
410     } ;
411
412 static const flex_int16_t yy_base[43] =
413     {   0,
414         0,    7,   49,   50,   50,   50,    0,    1,    0,   36,
415        28,   26,   28,   35,   29,    0,   26,   33,   27,   33,
416        29,   22,    0,   24,   27,   14,   27,   23,   13,   50,
417        10,    9,    4,    1,    0,    2,   50,   50,   19,   23,
418         2,   26
419     } ;
420
421 static const flex_int16_t yy_def[43] =
422     {   0,
423        39,   39,   38,   38,   38,   38,   40,   38,   40,   38,
424        38,   38,   38,   38,   38,   41,   38,   41,   38,   38,
425        38,   38,   42,   38,   42,   38,   38,   38,   38,   38,
426        38,   38,   38,   38,   38,   38,   38,    0,   38,   38,
427        38,   38
428     } ;
429
430 static const flex_int16_t yy_nxt[71] =
431     {   0,
432        38,    5,    6,   18,    7,   38,   38,    8,    5,    6,
433        37,    7,   36,   38,    8,   10,   35,   34,   11,    4,
434         4,    4,    4,    9,    9,   33,    9,   25,   32,   25,
435        31,   30,   29,   28,   27,   26,   24,   23,   22,   21,
436        20,   19,   17,   16,   15,   14,   13,   12,   38,    3,
437        38,   38,   38,   38,   38,   38,   38,   38,   38,   38,
438        38,   38,   38,   38,   38,   38,   38,   38,   38,   38
439     } ;
440
441 static const flex_int16_t yy_chk[71] =
442     {   0,
443         0,    1,    1,   41,    1,    0,    0,    1,    2,    2,
444        36,    2,   35,    0,    2,    8,   34,   33,    8,   39,
445        39,   39,   39,   40,   40,   32,   40,   42,   31,   42,
446        29,   28,   27,   26,   25,   24,   22,   21,   20,   19,
447        18,   17,   15,   14,   13,   12,   11,   10,    3,   38,
448        38,   38,   38,   38,   38,   38,   38,   38,   38,   38,
449        38,   38,   38,   38,   38,   38,   38,   38,   38,   38
450     } ;
451
452 static yy_state_type yy_last_accepting_state;
453 static char *yy_last_accepting_cpos;
454
455 extern int yy_flex_debug;
456 int yy_flex_debug = 0;
457
458 /* The intent behind this definition is that it'll catch
459  * any uses of REJECT which flex missed.
460  */
461 #define REJECT reject_used_but_not_detected
462 #define yymore() yymore_used_but_not_detected
463 #define YY_MORE_ADJ 0
464 #define YY_RESTORE_YY_MORE_OFFSET
465 char *yytext;
466 #line 1 "tokenparser.l"
467 /*
468  * Reads lexical config files and updates database.
469  *
470  * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
471  *
472  * Copyright (C) 2001-2003
473  *  David Corcoran <corcoran@musclecard.com>
474  * Copyright (C) 2003-2010
475  *  Ludovic Rousseau <ludovic.rousseau@free.fr>
476  *
477 Redistribution and use in source and binary forms, with or without
478 modification, are permitted provided that the following conditions
479 are met:
480
481 1. Redistributions of source code must retain the above copyright
482    notice, this list of conditions and the following disclaimer.
483 2. Redistributions in binary form must reproduce the above copyright
484    notice, this list of conditions and the following disclaimer in the
485    documentation and/or other materials provided with the distribution.
486 3. The name of the author may not be used to endorse or promote products
487    derived from this software without specific prior written permission.
488
489 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
490 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
491 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
492 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
493 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
494 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
495 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
496 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
497 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
498 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
499  */
500 /**
501  * @file
502  * @brief provides parsing functions for Info.plist files
503  * platforms
504  */
505 #line 42 "tokenparser.l"
506
507 #include "config.h"
508 #include <stdio.h>
509 #include <string.h>
510 #include <errno.h>
511 #define NDEBUG
512 #include <assert.h>
513
514 #include "simclist.h"
515 #include "debuglog.h"
516 #include "parser.h"
517
518 static void eval_key(char *pcToken, list_t *list_key);
519 static void eval_value(char *pcToken, list_t *list_values);
520 void tperrorCheck (char *pcToken_error);
521
522 static list_t *ListKeys;
523 static list_t *ListValues;
524
525 #line 526 "tokenparser.c"
526 #define YY_NO_INPUT 1
527 #line 528 "tokenparser.c"
528
529 #define INITIAL 0
530
531 #ifndef YY_NO_UNISTD_H
532 /* Special case for "unistd.h", since it is non-ANSI. We include it way
533  * down here because we want the user's section 1 to have been scanned first.
534  * The user has a chance to override it with an option.
535  */
536 #include <unistd.h>
537 #endif
538
539 #ifndef YY_EXTRA_TYPE
540 #define YY_EXTRA_TYPE void *
541 #endif
542
543 static int yy_init_globals ( void );
544
545 /* Accessor methods to globals.
546    These are made visible to non-reentrant scanners for convenience. */
547
548 int yylex_destroy ( void );
549
550 int yyget_debug ( void );
551
552 void yyset_debug ( int debug_flag  );
553
554 YY_EXTRA_TYPE yyget_extra ( void );
555
556 void yyset_extra ( YY_EXTRA_TYPE user_defined  );
557
558 FILE *yyget_in ( void );
559
560 void yyset_in  ( FILE * _in_str  );
561
562 FILE *yyget_out ( void );
563
564 void yyset_out  ( FILE * _out_str  );
565
566                         int yyget_leng ( void );
567
568 char *yyget_text ( void );
569
570 int yyget_lineno ( void );
571
572 void yyset_lineno ( int _line_number  );
573
574 /* Macros after this point can all be overridden by user definitions in
575  * section 1.
576  */
577
578 #ifndef YY_SKIP_YYWRAP
579 #ifdef __cplusplus
580 extern "C" int yywrap ( void );
581 #else
582 extern int yywrap ( void );
583 #endif
584 #endif
585
586 #ifndef YY_NO_UNPUT
587     
588 #endif
589
590 #ifndef yytext_ptr
591 static void yy_flex_strncpy ( char *, const char *, int );
592 #endif
593
594 #ifdef YY_NEED_STRLEN
595 static int yy_flex_strlen ( const char * );
596 #endif
597
598 #ifndef YY_NO_INPUT
599 #ifdef __cplusplus
600 static int yyinput ( void );
601 #else
602 static int input ( void );
603 #endif
604
605 #endif
606
607 /* Amount of stuff to slurp up with each read. */
608 #ifndef YY_READ_BUF_SIZE
609 #ifdef __ia64__
610 /* On IA-64, the buffer size is 16k, not 8k */
611 #define YY_READ_BUF_SIZE 16384
612 #else
613 #define YY_READ_BUF_SIZE 8192
614 #endif /* __ia64__ */
615 #endif
616
617 /* Copy whatever the last rule matched to the standard output. */
618 #ifndef ECHO
619 /* This used to be an fputs(), but since the string might contain NUL's,
620  * we now use fwrite().
621  */
622 #define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
623 #endif
624
625 /* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
626  * is returned in "result".
627  */
628 #ifndef YY_INPUT
629 #define YY_INPUT(buf,result,max_size) \
630         if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
631                 { \
632                 int c = '*'; \
633                 int n; \
634                 for ( n = 0; n < max_size && \
635                              (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
636                         buf[n] = (char) c; \
637                 if ( c == '\n' ) \
638                         buf[n++] = (char) c; \
639                 if ( c == EOF && ferror( yyin ) ) \
640                         YY_FATAL_ERROR( "input in flex scanner failed" ); \
641                 result = n; \
642                 } \
643         else \
644                 { \
645                 errno=0; \
646                 while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
647                         { \
648                         if( errno != EINTR) \
649                                 { \
650                                 YY_FATAL_ERROR( "input in flex scanner failed" ); \
651                                 break; \
652                                 } \
653                         errno=0; \
654                         clearerr(yyin); \
655                         } \
656                 }\
657 \
658
659 #endif
660
661 /* No semi-colon after return; correct usage is to write "yyterminate();" -
662  * we don't want an extra ';' after the "return" because that will cause
663  * some compilers to complain about unreachable statements.
664  */
665 #ifndef yyterminate
666 #define yyterminate() return YY_NULL
667 #endif
668
669 /* Number of entries by which start-condition stack grows. */
670 #ifndef YY_START_STACK_INCR
671 #define YY_START_STACK_INCR 25
672 #endif
673
674 /* Report a fatal error. */
675 #ifndef YY_FATAL_ERROR
676 #define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
677 #endif
678
679 /* end tables serialization structures and prototypes */
680
681 /* Default declaration of generated scanner - a define so the user can
682  * easily add parameters.
683  */
684 #ifndef YY_DECL
685 #define YY_DECL_IS_OURS 1
686
687 extern int yylex (void);
688
689 #define YY_DECL int yylex (void)
690 #endif /* !YY_DECL */
691
692 /* Code executed at the beginning of each rule, after yytext and yyleng
693  * have been set up.
694  */
695 #ifndef YY_USER_ACTION
696 #define YY_USER_ACTION
697 #endif
698
699 /* Code executed at the end of each rule. */
700 #ifndef YY_BREAK
701 #define YY_BREAK /*LINTED*/break;
702 #endif
703
704 #define YY_RULE_SETUP \
705         YY_USER_ACTION
706
707 /** The main scanner function which does all the work.
708  */
709 YY_DECL
710 {
711         yy_state_type yy_current_state;
712         char *yy_cp, *yy_bp;
713         int yy_act;
714     
715         if ( !(yy_init) )
716                 {
717                 (yy_init) = 1;
718
719 #ifdef YY_USER_INIT
720                 YY_USER_INIT;
721 #endif
722
723                 if ( ! (yy_start) )
724                         (yy_start) = 1; /* first start state */
725
726                 if ( ! yyin )
727                         yyin = stdin;
728
729                 if ( ! yyout )
730                         yyout = stdout;
731
732                 if ( ! YY_CURRENT_BUFFER ) {
733                         yyensure_buffer_stack ();
734                         YY_CURRENT_BUFFER_LVALUE =
735                                 yy_create_buffer( yyin, YY_BUF_SIZE );
736                 }
737
738                 yy_load_buffer_state(  );
739                 }
740
741         {
742 #line 67 "tokenparser.l"
743
744
745 #line 746 "tokenparser.c"
746
747         while ( /*CONSTCOND*/1 )                /* loops until end-of-file is reached */
748                 {
749                 yy_cp = (yy_c_buf_p);
750
751                 /* Support of yytext. */
752                 *yy_cp = (yy_hold_char);
753
754                 /* yy_bp points to the position in yy_ch_buf of the start of
755                  * the current run.
756                  */
757                 yy_bp = yy_cp;
758
759                 yy_current_state = (yy_start);
760 yy_match:
761                 do
762                         {
763                         YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
764                         if ( yy_accept[yy_current_state] )
765                                 {
766                                 (yy_last_accepting_state) = yy_current_state;
767                                 (yy_last_accepting_cpos) = yy_cp;
768                                 }
769                         while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
770                                 {
771                                 yy_current_state = (int) yy_def[yy_current_state];
772                                 if ( yy_current_state >= 39 )
773                                         yy_c = yy_meta[yy_c];
774                                 }
775                         yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
776                         ++yy_cp;
777                         }
778                 while ( yy_base[yy_current_state] != 50 );
779
780 yy_find_action:
781                 yy_act = yy_accept[yy_current_state];
782                 if ( yy_act == 0 )
783                         { /* have to back up */
784                         yy_cp = (yy_last_accepting_cpos);
785                         yy_current_state = (yy_last_accepting_state);
786                         yy_act = yy_accept[yy_current_state];
787                         }
788
789                 YY_DO_BEFORE_ACTION;
790
791 do_action:      /* This label is used only to access EOF actions. */
792
793                 switch ( yy_act )
794         { /* beginning of action switch */
795                         case 0: /* must back up */
796                         /* undo the effects of YY_DO_BEFORE_ACTION */
797                         *yy_cp = (yy_hold_char);
798                         yy_cp = (yy_last_accepting_cpos);
799                         yy_current_state = (yy_last_accepting_state);
800                         goto yy_find_action;
801
802 case 1:
803 YY_RULE_SETUP
804 #line 69 "tokenparser.l"
805 {}
806         YY_BREAK
807 case 2:
808 /* rule 2 can match eol */
809 YY_RULE_SETUP
810 #line 70 "tokenparser.l"
811 {}
812         YY_BREAK
813 case 3:
814 YY_RULE_SETUP
815 #line 71 "tokenparser.l"
816 { eval_key(yytext, ListKeys); }
817         YY_BREAK
818 case 4:
819 YY_RULE_SETUP
820 #line 72 "tokenparser.l"
821 {}
822         YY_BREAK
823 case 5:
824 YY_RULE_SETUP
825 #line 73 "tokenparser.l"
826 { eval_value(yytext, ListValues); }
827         YY_BREAK
828 case 6:
829 YY_RULE_SETUP
830 #line 74 "tokenparser.l"
831 { tperrorCheck(yytext); }
832         YY_BREAK
833 case 7:
834 YY_RULE_SETUP
835 #line 75 "tokenparser.l"
836 ECHO;
837         YY_BREAK
838 #line 839 "tokenparser.c"
839 case YY_STATE_EOF(INITIAL):
840         yyterminate();
841
842         case YY_END_OF_BUFFER:
843                 {
844                 /* Amount of text matched not including the EOB char. */
845                 int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
846
847                 /* Undo the effects of YY_DO_BEFORE_ACTION. */
848                 *yy_cp = (yy_hold_char);
849                 YY_RESTORE_YY_MORE_OFFSET
850
851                 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
852                         {
853                         /* We're scanning a new file or input source.  It's
854                          * possible that this happened because the user
855                          * just pointed yyin at a new source and called
856                          * yylex().  If so, then we have to assure
857                          * consistency between YY_CURRENT_BUFFER and our
858                          * globals.  Here is the right place to do so, because
859                          * this is the first action (other than possibly a
860                          * back-up) that will match for the new input source.
861                          */
862                         (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
863                         YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
864                         YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
865                         }
866
867                 /* Note that here we test for yy_c_buf_p "<=" to the position
868                  * of the first EOB in the buffer, since yy_c_buf_p will
869                  * already have been incremented past the NUL character
870                  * (since all states make transitions on EOB to the
871                  * end-of-buffer state).  Contrast this with the test
872                  * in input().
873                  */
874                 if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
875                         { /* This was really a NUL. */
876                         yy_state_type yy_next_state;
877
878                         (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
879
880                         yy_current_state = yy_get_previous_state(  );
881
882                         /* Okay, we're now positioned to make the NUL
883                          * transition.  We couldn't have
884                          * yy_get_previous_state() go ahead and do it
885                          * for us because it doesn't know how to deal
886                          * with the possibility of jamming (and we don't
887                          * want to build jamming into it because then it
888                          * will run more slowly).
889                          */
890
891                         yy_next_state = yy_try_NUL_trans( yy_current_state );
892
893                         yy_bp = (yytext_ptr) + YY_MORE_ADJ;
894
895                         if ( yy_next_state )
896                                 {
897                                 /* Consume the NUL. */
898                                 yy_cp = ++(yy_c_buf_p);
899                                 yy_current_state = yy_next_state;
900                                 goto yy_match;
901                                 }
902
903                         else
904                                 {
905                                 yy_cp = (yy_c_buf_p);
906                                 goto yy_find_action;
907                                 }
908                         }
909
910                 else switch ( yy_get_next_buffer(  ) )
911                         {
912                         case EOB_ACT_END_OF_FILE:
913                                 {
914                                 (yy_did_buffer_switch_on_eof) = 0;
915
916                                 if ( yywrap(  ) )
917                                         {
918                                         /* Note: because we've taken care in
919                                          * yy_get_next_buffer() to have set up
920                                          * yytext, we can now set up
921                                          * yy_c_buf_p so that if some total
922                                          * hoser (like flex itself) wants to
923                                          * call the scanner after we return the
924                                          * YY_NULL, it'll still work - another
925                                          * YY_NULL will get returned.
926                                          */
927                                         (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
928
929                                         yy_act = YY_STATE_EOF(YY_START);
930                                         goto do_action;
931                                         }
932
933                                 else
934                                         {
935                                         if ( ! (yy_did_buffer_switch_on_eof) )
936                                                 YY_NEW_FILE;
937                                         }
938                                 break;
939                                 }
940
941                         case EOB_ACT_CONTINUE_SCAN:
942                                 (yy_c_buf_p) =
943                                         (yytext_ptr) + yy_amount_of_matched_text;
944
945                                 yy_current_state = yy_get_previous_state(  );
946
947                                 yy_cp = (yy_c_buf_p);
948                                 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
949                                 goto yy_match;
950
951                         case EOB_ACT_LAST_MATCH:
952                                 (yy_c_buf_p) =
953                                 &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
954
955                                 yy_current_state = yy_get_previous_state(  );
956
957                                 yy_cp = (yy_c_buf_p);
958                                 yy_bp = (yytext_ptr) + YY_MORE_ADJ;
959                                 goto yy_find_action;
960                         }
961                 break;
962                 }
963
964         default:
965                 YY_FATAL_ERROR(
966                         "fatal flex scanner internal error--no action found" );
967         } /* end of action switch */
968                 } /* end of scanning one token */
969         } /* end of user's declarations */
970 } /* end of yylex */
971
972 /* yy_get_next_buffer - try to read in a new buffer
973  *
974  * Returns a code representing an action:
975  *      EOB_ACT_LAST_MATCH -
976  *      EOB_ACT_CONTINUE_SCAN - continue scanning from current position
977  *      EOB_ACT_END_OF_FILE - end of file
978  */
979 static int yy_get_next_buffer (void)
980 {
981         char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
982         char *source = (yytext_ptr);
983         int number_to_move, i;
984         int ret_val;
985
986         if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
987                 YY_FATAL_ERROR(
988                 "fatal flex scanner internal error--end of buffer missed" );
989
990         if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
991                 { /* Don't try to fill the buffer, so this is an EOF. */
992                 if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
993                         {
994                         /* We matched a single character, the EOB, so
995                          * treat this as a final EOF.
996                          */
997                         return EOB_ACT_END_OF_FILE;
998                         }
999
1000                 else
1001                         {
1002                         /* We matched some text prior to the EOB, first
1003                          * process it.
1004                          */
1005                         return EOB_ACT_LAST_MATCH;
1006                         }
1007                 }
1008
1009         /* Try to read more data. */
1010
1011         /* First move last chars to start of buffer. */
1012         number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
1013
1014         for ( i = 0; i < number_to_move; ++i )
1015                 *(dest++) = *(source++);
1016
1017         if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1018                 /* don't do the read, it's not guaranteed to return an EOF,
1019                  * just force an EOF
1020                  */
1021                 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
1022
1023         else
1024                 {
1025                         int num_to_read =
1026                         YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1027
1028                 while ( num_to_read <= 0 )
1029                         { /* Not enough room in the buffer - grow it. */
1030
1031                         /* just a shorter name for the current buffer */
1032                         YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1033
1034                         int yy_c_buf_p_offset =
1035                                 (int) ((yy_c_buf_p) - b->yy_ch_buf);
1036
1037                         if ( b->yy_is_our_buffer )
1038                                 {
1039                                 int new_size = b->yy_buf_size * 2;
1040
1041                                 if ( new_size <= 0 )
1042                                         b->yy_buf_size += b->yy_buf_size / 8;
1043                                 else
1044                                         b->yy_buf_size *= 2;
1045
1046                                 b->yy_ch_buf = (char *)
1047                                         /* Include room in for 2 EOB chars. */
1048                                         yyrealloc( (void *) b->yy_ch_buf,
1049                                                          (yy_size_t) (b->yy_buf_size + 2)  );
1050                                 }
1051                         else
1052                                 /* Can't grow it, we don't own it. */
1053                                 b->yy_ch_buf = NULL;
1054
1055                         if ( ! b->yy_ch_buf )
1056                                 YY_FATAL_ERROR(
1057                                 "fatal error - scanner input buffer overflow" );
1058
1059                         (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
1060
1061                         num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1062                                                 number_to_move - 1;
1063
1064                         }
1065
1066                 if ( num_to_read > YY_READ_BUF_SIZE )
1067                         num_to_read = YY_READ_BUF_SIZE;
1068
1069                 /* Read in more data. */
1070                 YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1071                         (yy_n_chars), num_to_read );
1072
1073                 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1074                 }
1075
1076         if ( (yy_n_chars) == 0 )
1077                 {
1078                 if ( number_to_move == YY_MORE_ADJ )
1079                         {
1080                         ret_val = EOB_ACT_END_OF_FILE;
1081                         yyrestart( yyin  );
1082                         }
1083
1084                 else
1085                         {
1086                         ret_val = EOB_ACT_LAST_MATCH;
1087                         YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1088                                 YY_BUFFER_EOF_PENDING;
1089                         }
1090                 }
1091
1092         else
1093                 ret_val = EOB_ACT_CONTINUE_SCAN;
1094
1095         if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1096                 /* Extend the array by 50%, plus the number we really need. */
1097                 int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
1098                 YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
1099                         (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size  );
1100                 if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1101                         YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1102                 /* "- 2" to take care of EOB's */
1103                 YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
1104         }
1105
1106         (yy_n_chars) += number_to_move;
1107         YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
1108         YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
1109
1110         (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1111
1112         return ret_val;
1113 }
1114
1115 /* yy_get_previous_state - get the state just before the EOB char was reached */
1116
1117     static yy_state_type yy_get_previous_state (void)
1118 {
1119         yy_state_type yy_current_state;
1120         char *yy_cp;
1121     
1122         yy_current_state = (yy_start);
1123
1124         for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
1125                 {
1126                 YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1127                 if ( yy_accept[yy_current_state] )
1128                         {
1129                         (yy_last_accepting_state) = yy_current_state;
1130                         (yy_last_accepting_cpos) = yy_cp;
1131                         }
1132                 while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1133                         {
1134                         yy_current_state = (int) yy_def[yy_current_state];
1135                         if ( yy_current_state >= 39 )
1136                                 yy_c = yy_meta[yy_c];
1137                         }
1138                 yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1139                 }
1140
1141         return yy_current_state;
1142 }
1143
1144 /* yy_try_NUL_trans - try to make a transition on the NUL character
1145  *
1146  * synopsis
1147  *      next_state = yy_try_NUL_trans( current_state );
1148  */
1149     static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state )
1150 {
1151         int yy_is_jam;
1152         char *yy_cp = (yy_c_buf_p);
1153
1154         YY_CHAR yy_c = 1;
1155         if ( yy_accept[yy_current_state] )
1156                 {
1157                 (yy_last_accepting_state) = yy_current_state;
1158                 (yy_last_accepting_cpos) = yy_cp;
1159                 }
1160         while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1161                 {
1162                 yy_current_state = (int) yy_def[yy_current_state];
1163                 if ( yy_current_state >= 39 )
1164                         yy_c = yy_meta[yy_c];
1165                 }
1166         yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1167         yy_is_jam = (yy_current_state == 38);
1168
1169                 return yy_is_jam ? 0 : yy_current_state;
1170 }
1171
1172 #ifndef YY_NO_UNPUT
1173
1174 #endif
1175
1176 #ifndef YY_NO_INPUT
1177 #ifdef __cplusplus
1178     static int yyinput (void)
1179 #else
1180     static int input  (void)
1181 #endif
1182
1183 {
1184         int c;
1185     
1186         *(yy_c_buf_p) = (yy_hold_char);
1187
1188         if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
1189                 {
1190                 /* yy_c_buf_p now points to the character we want to return.
1191                  * If this occurs *before* the EOB characters, then it's a
1192                  * valid NUL; if not, then we've hit the end of the buffer.
1193                  */
1194                 if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
1195                         /* This was really a NUL. */
1196                         *(yy_c_buf_p) = '\0';
1197
1198                 else
1199                         { /* need more input */
1200                         int offset = (int) ((yy_c_buf_p) - (yytext_ptr));
1201                         ++(yy_c_buf_p);
1202
1203                         switch ( yy_get_next_buffer(  ) )
1204                                 {
1205                                 case EOB_ACT_LAST_MATCH:
1206                                         /* This happens because yy_g_n_b()
1207                                          * sees that we've accumulated a
1208                                          * token and flags that we need to
1209                                          * try matching the token before
1210                                          * proceeding.  But for input(),
1211                                          * there's no matching to consider.
1212                                          * So convert the EOB_ACT_LAST_MATCH
1213                                          * to EOB_ACT_END_OF_FILE.
1214                                          */
1215
1216                                         /* Reset buffer status. */
1217                                         yyrestart( yyin );
1218
1219                                         /*FALLTHROUGH*/
1220
1221                                 case EOB_ACT_END_OF_FILE:
1222                                         {
1223                                         if ( yywrap(  ) )
1224                                                 return 0;
1225
1226                                         if ( ! (yy_did_buffer_switch_on_eof) )
1227                                                 YY_NEW_FILE;
1228 #ifdef __cplusplus
1229                                         return yyinput();
1230 #else
1231                                         return input();
1232 #endif
1233                                         }
1234
1235                                 case EOB_ACT_CONTINUE_SCAN:
1236                                         (yy_c_buf_p) = (yytext_ptr) + offset;
1237                                         break;
1238                                 }
1239                         }
1240                 }
1241
1242         c = *(unsigned char *) (yy_c_buf_p);    /* cast for 8-bit char's */
1243         *(yy_c_buf_p) = '\0';   /* preserve yytext */
1244         (yy_hold_char) = *++(yy_c_buf_p);
1245
1246         return c;
1247 }
1248 #endif  /* ifndef YY_NO_INPUT */
1249
1250 /** Immediately switch to a different input stream.
1251  * @param input_file A readable stream.
1252  * 
1253  * @note This function does not reset the start condition to @c INITIAL .
1254  */
1255     void yyrestart  (FILE * input_file )
1256 {
1257     
1258         if ( ! YY_CURRENT_BUFFER ){
1259         yyensure_buffer_stack ();
1260                 YY_CURRENT_BUFFER_LVALUE =
1261             yy_create_buffer( yyin, YY_BUF_SIZE );
1262         }
1263
1264         yy_init_buffer( YY_CURRENT_BUFFER, input_file );
1265         yy_load_buffer_state(  );
1266 }
1267
1268 /** Switch to a different input buffer.
1269  * @param new_buffer The new input buffer.
1270  * 
1271  */
1272     void yy_switch_to_buffer  (YY_BUFFER_STATE  new_buffer )
1273 {
1274     
1275         /* TODO. We should be able to replace this entire function body
1276          * with
1277          *              yypop_buffer_state();
1278          *              yypush_buffer_state(new_buffer);
1279      */
1280         yyensure_buffer_stack ();
1281         if ( YY_CURRENT_BUFFER == new_buffer )
1282                 return;
1283
1284         if ( YY_CURRENT_BUFFER )
1285                 {
1286                 /* Flush out information for old buffer. */
1287                 *(yy_c_buf_p) = (yy_hold_char);
1288                 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1289                 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1290                 }
1291
1292         YY_CURRENT_BUFFER_LVALUE = new_buffer;
1293         yy_load_buffer_state(  );
1294
1295         /* We don't actually know whether we did this switch during
1296          * EOF (yywrap()) processing, but the only time this flag
1297          * is looked at is after yywrap() is called, so it's safe
1298          * to go ahead and always set it.
1299          */
1300         (yy_did_buffer_switch_on_eof) = 1;
1301 }
1302
1303 static void yy_load_buffer_state  (void)
1304 {
1305         (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1306         (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1307         yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1308         (yy_hold_char) = *(yy_c_buf_p);
1309 }
1310
1311 /** Allocate and initialize an input buffer state.
1312  * @param file A readable stream.
1313  * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1314  * 
1315  * @return the allocated buffer state.
1316  */
1317     YY_BUFFER_STATE yy_create_buffer  (FILE * file, int  size )
1318 {
1319         YY_BUFFER_STATE b;
1320     
1321         b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state )  );
1322         if ( ! b )
1323                 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1324
1325         b->yy_buf_size = size;
1326
1327         /* yy_ch_buf has to be 2 characters longer than the size given because
1328          * we need to put in 2 end-of-buffer characters.
1329          */
1330         b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2)  );
1331         if ( ! b->yy_ch_buf )
1332                 YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1333
1334         b->yy_is_our_buffer = 1;
1335
1336         yy_init_buffer( b, file );
1337
1338         return b;
1339 }
1340
1341 /** Destroy the buffer.
1342  * @param b a buffer created with yy_create_buffer()
1343  * 
1344  */
1345     void yy_delete_buffer (YY_BUFFER_STATE  b )
1346 {
1347     
1348         if ( ! b )
1349                 return;
1350
1351         if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1352                 YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1353
1354         if ( b->yy_is_our_buffer )
1355                 yyfree( (void *) b->yy_ch_buf  );
1356
1357         yyfree( (void *) b  );
1358 }
1359
1360 /* Initializes or reinitializes a buffer.
1361  * This function is sometimes called more than once on the same buffer,
1362  * such as during a yyrestart() or at EOF.
1363  */
1364     static void yy_init_buffer  (YY_BUFFER_STATE  b, FILE * file )
1365
1366 {
1367         int oerrno = errno;
1368     
1369         yy_flush_buffer( b );
1370
1371         b->yy_input_file = file;
1372         b->yy_fill_buffer = 1;
1373
1374     /* If b is the current buffer, then yy_init_buffer was _probably_
1375      * called from yyrestart() or through yy_get_next_buffer.
1376      * In that case, we don't want to reset the lineno or column.
1377      */
1378     if (b != YY_CURRENT_BUFFER){
1379         b->yy_bs_lineno = 1;
1380         b->yy_bs_column = 0;
1381     }
1382
1383         b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
1384     
1385         errno = oerrno;
1386 }
1387
1388 /** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1389  * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1390  * 
1391  */
1392     void yy_flush_buffer (YY_BUFFER_STATE  b )
1393 {
1394         if ( ! b )
1395                 return;
1396
1397         b->yy_n_chars = 0;
1398
1399         /* We always need two end-of-buffer characters.  The first causes
1400          * a transition to the end-of-buffer state.  The second causes
1401          * a jam in that state.
1402          */
1403         b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1404         b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1405
1406         b->yy_buf_pos = &b->yy_ch_buf[0];
1407
1408         b->yy_at_bol = 1;
1409         b->yy_buffer_status = YY_BUFFER_NEW;
1410
1411         if ( b == YY_CURRENT_BUFFER )
1412                 yy_load_buffer_state(  );
1413 }
1414
1415 /** Pushes the new state onto the stack. The new state becomes
1416  *  the current state. This function will allocate the stack
1417  *  if necessary.
1418  *  @param new_buffer The new state.
1419  *  
1420  */
1421 void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
1422 {
1423         if (new_buffer == NULL)
1424                 return;
1425
1426         yyensure_buffer_stack();
1427
1428         /* This block is copied from yy_switch_to_buffer. */
1429         if ( YY_CURRENT_BUFFER )
1430                 {
1431                 /* Flush out information for old buffer. */
1432                 *(yy_c_buf_p) = (yy_hold_char);
1433                 YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
1434                 YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
1435                 }
1436
1437         /* Only push if top exists. Otherwise, replace top. */
1438         if (YY_CURRENT_BUFFER)
1439                 (yy_buffer_stack_top)++;
1440         YY_CURRENT_BUFFER_LVALUE = new_buffer;
1441
1442         /* copied from yy_switch_to_buffer. */
1443         yy_load_buffer_state(  );
1444         (yy_did_buffer_switch_on_eof) = 1;
1445 }
1446
1447 /** Removes and deletes the top of the stack, if present.
1448  *  The next element becomes the new top.
1449  *  
1450  */
1451 void yypop_buffer_state (void)
1452 {
1453         if (!YY_CURRENT_BUFFER)
1454                 return;
1455
1456         yy_delete_buffer(YY_CURRENT_BUFFER );
1457         YY_CURRENT_BUFFER_LVALUE = NULL;
1458         if ((yy_buffer_stack_top) > 0)
1459                 --(yy_buffer_stack_top);
1460
1461         if (YY_CURRENT_BUFFER) {
1462                 yy_load_buffer_state(  );
1463                 (yy_did_buffer_switch_on_eof) = 1;
1464         }
1465 }
1466
1467 /* Allocates the stack if it does not exist.
1468  *  Guarantees space for at least one push.
1469  */
1470 static void yyensure_buffer_stack (void)
1471 {
1472         yy_size_t num_to_alloc;
1473     
1474         if (!(yy_buffer_stack)) {
1475
1476                 /* First allocation is just for 2 elements, since we don't know if this
1477                  * scanner will even need a stack. We use 2 instead of 1 to avoid an
1478                  * immediate realloc on the next call.
1479          */
1480       num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1481                 (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
1482                                                                 (num_to_alloc * sizeof(struct yy_buffer_state*)
1483                                                                 );
1484                 if ( ! (yy_buffer_stack) )
1485                         YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1486
1487                 memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1488
1489                 (yy_buffer_stack_max) = num_to_alloc;
1490                 (yy_buffer_stack_top) = 0;
1491                 return;
1492         }
1493
1494         if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
1495
1496                 /* Increase the buffer to prepare for a possible push. */
1497                 yy_size_t grow_size = 8 /* arbitrary grow size */;
1498
1499                 num_to_alloc = (yy_buffer_stack_max) + grow_size;
1500                 (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
1501                                                                 ((yy_buffer_stack),
1502                                                                 num_to_alloc * sizeof(struct yy_buffer_state*)
1503                                                                 );
1504                 if ( ! (yy_buffer_stack) )
1505                         YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1506
1507                 /* zero only the new slots.*/
1508                 memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
1509                 (yy_buffer_stack_max) = num_to_alloc;
1510         }
1511 }
1512
1513 /** Setup the input buffer state to scan directly from a user-specified character buffer.
1514  * @param base the character buffer
1515  * @param size the size in bytes of the character buffer
1516  * 
1517  * @return the newly allocated buffer state object.
1518  */
1519 YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
1520 {
1521         YY_BUFFER_STATE b;
1522     
1523         if ( size < 2 ||
1524              base[size-2] != YY_END_OF_BUFFER_CHAR ||
1525              base[size-1] != YY_END_OF_BUFFER_CHAR )
1526                 /* They forgot to leave room for the EOB's. */
1527                 return NULL;
1528
1529         b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state )  );
1530         if ( ! b )
1531                 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
1532
1533         b->yy_buf_size = (int) (size - 2);      /* "- 2" to take care of EOB's */
1534         b->yy_buf_pos = b->yy_ch_buf = base;
1535         b->yy_is_our_buffer = 0;
1536         b->yy_input_file = NULL;
1537         b->yy_n_chars = b->yy_buf_size;
1538         b->yy_is_interactive = 0;
1539         b->yy_at_bol = 1;
1540         b->yy_fill_buffer = 0;
1541         b->yy_buffer_status = YY_BUFFER_NEW;
1542
1543         yy_switch_to_buffer( b  );
1544
1545         return b;
1546 }
1547
1548 /** Setup the input buffer state to scan a string. The next call to yylex() will
1549  * scan from a @e copy of @a str.
1550  * @param yystr a NUL-terminated string to scan
1551  * 
1552  * @return the newly allocated buffer state object.
1553  * @note If you want to scan bytes that may contain NUL values, then use
1554  *       yy_scan_bytes() instead.
1555  */
1556 YY_BUFFER_STATE yy_scan_string (const char * yystr )
1557 {
1558     
1559         return yy_scan_bytes( yystr, (int) strlen(yystr) );
1560 }
1561
1562 /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
1563  * scan from a @e copy of @a bytes.
1564  * @param yybytes the byte buffer to scan
1565  * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
1566  * 
1567  * @return the newly allocated buffer state object.
1568  */
1569 YY_BUFFER_STATE yy_scan_bytes  (const char * yybytes, int  _yybytes_len )
1570 {
1571         YY_BUFFER_STATE b;
1572         char *buf;
1573         yy_size_t n;
1574         int i;
1575     
1576         /* Get memory for full buffer, including space for trailing EOB's. */
1577         n = (yy_size_t) (_yybytes_len + 2);
1578         buf = (char *) yyalloc( n  );
1579         if ( ! buf )
1580                 YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
1581
1582         for ( i = 0; i < _yybytes_len; ++i )
1583                 buf[i] = yybytes[i];
1584
1585         buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
1586
1587         b = yy_scan_buffer( buf, n );
1588         if ( ! b )
1589                 YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
1590
1591         /* It's okay to grow etc. this buffer, and we should throw it
1592          * away when we're done.
1593          */
1594         b->yy_is_our_buffer = 1;
1595
1596         return b;
1597 }
1598
1599 #ifndef YY_EXIT_FAILURE
1600 #define YY_EXIT_FAILURE 2
1601 #endif
1602
1603 static void yynoreturn yy_fatal_error (const char* msg )
1604 {
1605                         fprintf( stderr, "%s\n", msg );
1606         exit( YY_EXIT_FAILURE );
1607 }
1608
1609 /* Redefine yyless() so it works in section 3 code. */
1610
1611 #undef yyless
1612 #define yyless(n) \
1613         do \
1614                 { \
1615                 /* Undo effects of setting up yytext. */ \
1616         int yyless_macro_arg = (n); \
1617         YY_LESS_LINENO(yyless_macro_arg);\
1618                 yytext[yyleng] = (yy_hold_char); \
1619                 (yy_c_buf_p) = yytext + yyless_macro_arg; \
1620                 (yy_hold_char) = *(yy_c_buf_p); \
1621                 *(yy_c_buf_p) = '\0'; \
1622                 yyleng = yyless_macro_arg; \
1623                 } \
1624         while ( 0 )
1625
1626 /* Accessor  methods (get/set functions) to struct members. */
1627
1628 /** Get the current line number.
1629  * 
1630  */
1631 int yyget_lineno  (void)
1632 {
1633     
1634     return yylineno;
1635 }
1636
1637 /** Get the input stream.
1638  * 
1639  */
1640 FILE *yyget_in  (void)
1641 {
1642         return yyin;
1643 }
1644
1645 /** Get the output stream.
1646  * 
1647  */
1648 FILE *yyget_out  (void)
1649 {
1650         return yyout;
1651 }
1652
1653 /** Get the length of the current token.
1654  * 
1655  */
1656 int yyget_leng  (void)
1657 {
1658         return yyleng;
1659 }
1660
1661 /** Get the current token.
1662  * 
1663  */
1664
1665 char *yyget_text  (void)
1666 {
1667         return yytext;
1668 }
1669
1670 /** Set the current line number.
1671  * @param _line_number line number
1672  * 
1673  */
1674 void yyset_lineno (int  _line_number )
1675 {
1676     
1677     yylineno = _line_number;
1678 }
1679
1680 /** Set the input stream. This does not discard the current
1681  * input buffer.
1682  * @param _in_str A readable stream.
1683  * 
1684  * @see yy_switch_to_buffer
1685  */
1686 void yyset_in (FILE *  _in_str )
1687 {
1688         yyin = _in_str ;
1689 }
1690
1691 void yyset_out (FILE *  _out_str )
1692 {
1693         yyout = _out_str ;
1694 }
1695
1696 int yyget_debug  (void)
1697 {
1698         return yy_flex_debug;
1699 }
1700
1701 void yyset_debug (int  _bdebug )
1702 {
1703         yy_flex_debug = _bdebug ;
1704 }
1705
1706 static int yy_init_globals (void)
1707 {
1708         /* Initialization is the same as for the non-reentrant scanner.
1709      * This function is called from yylex_destroy(), so don't allocate here.
1710      */
1711
1712     (yy_buffer_stack) = NULL;
1713     (yy_buffer_stack_top) = 0;
1714     (yy_buffer_stack_max) = 0;
1715     (yy_c_buf_p) = NULL;
1716     (yy_init) = 0;
1717     (yy_start) = 0;
1718
1719 /* Defined in main.c */
1720 #ifdef YY_STDINIT
1721     yyin = stdin;
1722     yyout = stdout;
1723 #else
1724     yyin = NULL;
1725     yyout = NULL;
1726 #endif
1727
1728     /* For future reference: Set errno on error, since we are called by
1729      * yylex_init()
1730      */
1731     return 0;
1732 }
1733
1734 /* yylex_destroy is for both reentrant and non-reentrant scanners. */
1735 int yylex_destroy  (void)
1736 {
1737     
1738     /* Pop the buffer stack, destroying each element. */
1739         while(YY_CURRENT_BUFFER){
1740                 yy_delete_buffer( YY_CURRENT_BUFFER  );
1741                 YY_CURRENT_BUFFER_LVALUE = NULL;
1742                 yypop_buffer_state();
1743         }
1744
1745         /* Destroy the stack itself. */
1746         yyfree((yy_buffer_stack) );
1747         (yy_buffer_stack) = NULL;
1748
1749     /* Reset the globals. This is important in a non-reentrant scanner so the next time
1750      * yylex() is called, initialization will occur. */
1751     yy_init_globals( );
1752
1753     return 0;
1754 }
1755
1756 /*
1757  * Internal utility routines.
1758  */
1759
1760 #ifndef yytext_ptr
1761 static void yy_flex_strncpy (char* s1, const char * s2, int n )
1762 {
1763                 
1764         int i;
1765         for ( i = 0; i < n; ++i )
1766                 s1[i] = s2[i];
1767 }
1768 #endif
1769
1770 #ifdef YY_NEED_STRLEN
1771 static int yy_flex_strlen (const char * s )
1772 {
1773         int n;
1774         for ( n = 0; s[n]; ++n )
1775                 ;
1776
1777         return n;
1778 }
1779 #endif
1780
1781 void *yyalloc (yy_size_t  size )
1782 {
1783                         return malloc(size);
1784 }
1785
1786 void *yyrealloc  (void * ptr, yy_size_t  size )
1787 {
1788                 
1789         /* The cast to (char *) in the following accommodates both
1790          * implementations that use char* generic pointers, and those
1791          * that use void* generic pointers.  It works with the latter
1792          * because both ANSI C and C++ allow castless assignment from
1793          * any pointer type to void*, and deal with argument conversions
1794          * as though doing an assignment.
1795          */
1796         return realloc(ptr, size);
1797 }
1798
1799 void yyfree (void * ptr )
1800 {
1801                         free( (char *) ptr );   /* see yyrealloc() for (char *) cast */
1802 }
1803
1804 #define YYTABLES_NAME "yytables"
1805
1806 #line 75 "tokenparser.l"
1807
1808
1809
1810 static void eval_key(char *pcToken, list_t *list_key)
1811 {
1812         struct bundleElt *elt;
1813         int r;
1814         size_t len;
1815
1816         /* create a new list element */
1817         elt = malloc(sizeof(*elt));
1818         assert(elt);
1819
1820         /* <key>foobar</key>
1821          * 012345 : 5 is the first key character index */
1822
1823         /* calculate the argument length */
1824         for (len=0; pcToken[len+5] != '<'; len++)
1825                 ;
1826         len++;  /* final NULL byte */
1827
1828         elt->key = malloc(len);
1829         memcpy(elt->key, &pcToken[5], len-1);
1830         elt->key[len-1] = '\0';
1831
1832         r = list_init(&elt->values);
1833         assert(r >= 0);
1834         (void)r;
1835
1836         /* add the key/values */
1837         list_append(list_key, elt);
1838
1839         /* set the list to store the values */
1840         ListValues = &elt->values;
1841 }
1842
1843 static void eval_value(char *pcToken, list_t *list_values)
1844 {
1845         int r;
1846         size_t len;
1847         char *value;
1848         char *amp;
1849
1850         /* <string>foobar</string>
1851          * 012345678 : 8 is the first string character index */
1852
1853         /* calculate the argument length */
1854         for (len=0; pcToken[len+8] != '<'; len++)
1855                 ;
1856         len++;  /* final NULL byte */
1857
1858         value = malloc(len);
1859         assert(value);
1860
1861         memcpy(value, &pcToken[8], len-1);
1862         value[len-1] = '\0';
1863
1864         /* for all &amp; in the string */
1865         amp = value;
1866         while ((amp = strstr(amp, "&amp;")) != NULL)
1867         {
1868                 char *p;
1869
1870                 /* just skip "amp;" substring (4 letters) */
1871                 for (p = amp+1; *(p+4); p++)
1872                 {
1873                         *p = *(p+4);
1874                 }
1875                 /* terminate the now shorter string */
1876                 *p = '\0';
1877
1878                 /* skip the & and continue */
1879                 amp++;
1880         }
1881
1882         r = list_append(list_values, value);
1883         assert(r >= 0);
1884         (void)r;
1885 }
1886
1887 void tperrorCheck (char *token_error)
1888 {
1889     (void)token_error;
1890 }
1891
1892 /**
1893  * Find an optional key in a configuration file
1894  * No error is logged if the key is not found
1895  *
1896  * @param l list generated by bundleParse()
1897  * @param key searched key
1898  * @param[out] values list of token value (if key found)
1899  * @retval 0 OK
1900  * @retval 1 key not found
1901  */
1902 int LTPBundleFindValueWithKey(list_t *l, const char *key, list_t **values)
1903 {
1904         unsigned int i;
1905         int ret = 1;
1906
1907         for (i=0; i < list_size(l); i++)
1908         {
1909                 struct bundleElt *elt;
1910
1911                 elt = list_get_at(l, i);
1912                 assert(elt);
1913
1914                 if (0 == strcmp(elt->key, key))
1915                 {
1916                         *values = &elt->values;
1917                         ret = 0;
1918                 }
1919         }
1920
1921         return ret;
1922 }
1923
1924
1925 /**
1926  * Parse a Info.plist file and file a list
1927  *
1928  * @param fileName file name
1929  * @param l list containing the results
1930  * @retval -1 configuration file not found
1931  * @retval 0 OK
1932  */
1933 int bundleParse(const char *fileName, list_t *l)
1934 {
1935         FILE *file = NULL;
1936         int r;
1937 #ifndef NDEBUG
1938         int i;
1939 #endif
1940
1941         file = fopen(fileName, "r");
1942         if (!file)
1943         {
1944                 Log3(PCSC_LOG_CRITICAL, "Could not open bundle file %s: %s",
1945                         fileName, strerror(errno));
1946                 return 1;
1947         }
1948
1949         r = list_init(l);
1950         assert(r >= 0);
1951         (void)r;
1952
1953         ListKeys = l;
1954         yyin = file;
1955
1956         do
1957         {
1958                 (void)yylex();
1959         } while (!feof(file));
1960         yylex_destroy();
1961
1962         (void)fclose(file);
1963
1964 #ifndef NDEBUG
1965         printf("size: %d\n", list_size(l));
1966         for (i=0; i < list_size(l); i++)
1967         {
1968                 struct bundleElt *elt;
1969                 unsigned int j;
1970
1971                 elt = list_get_at(l, i);
1972                 assert(elt);
1973                 printf("Key: %s\n", elt->key);
1974
1975                 for (j=0; j<list_size(&elt->values); j++)
1976                 {
1977                         char *v = list_get_at(&elt->values, j);
1978                         printf(" value: %s\n", v);
1979                 }
1980         }
1981 #endif
1982
1983         return 0;
1984 }
1985
1986 /**
1987  * Free the list created by bundleParse()
1988  *
1989  * @param l list containing the results
1990  */
1991 void bundleRelease(list_t *l)
1992 {
1993         unsigned int i;
1994
1995         for (i=0; i < list_size(l); i++)
1996         {
1997                 struct bundleElt *elt;
1998                 unsigned int j;
1999
2000                 elt = list_get_at(l, i);
2001                 assert(elt);
2002
2003                 /* free all the values */
2004                 for (j=0; j<list_size(&elt->values); j++)
2005                         free(list_get_at(&elt->values, j));
2006                 list_destroy(&elt->values);
2007
2008                 /* free the key */
2009                 free(elt->key);
2010                 free(elt);
2011         }
2012
2013         list_destroy(l);
2014 }
2015