]> arthur.barton.de Git - netatalk.git/blob - etc/spotlight/slmod_rdf_parser.c
0256f2873efc8868b5e528fa9fe8f349317b7981
[netatalk.git] / etc / spotlight / slmod_rdf_parser.c
1 /* A Bison parser, made by GNU Bison 2.7.  */
2
3 /* Bison implementation for Yacc-like parsers in C
4    
5       Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
6    
7    This program is free software: you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19
20 /* As a special exception, you may create a larger work that contains
21    part or all of the Bison parser skeleton and distribute that work
22    under terms of your choice, so long as that work isn't itself a
23    parser generator using the skeleton or a modified version thereof
24    as a parser skeleton.  Alternatively, if you modify or redistribute
25    the parser skeleton itself, you may (at your option) remove this
26    special exception, which will cause the skeleton and the resulting
27    Bison output files to be licensed under the GNU General Public
28    License without this special exception.
29    
30    This special exception was added by the Free Software Foundation in
31    version 2.2 of Bison.  */
32
33 /* C LALR(1) parser skeleton written by Richard Stallman, by
34    simplifying the original so-called "semantic" parser.  */
35
36 /* All symbols defined below should begin with yy or YY, to avoid
37    infringing on user name space.  This should be done even for local
38    variables, as they might otherwise be expanded by user macros.
39    There are some unavoidable exceptions within include files to
40    define necessary library symbols; they are noted "INFRINGES ON
41    USER NAME SPACE" below.  */
42
43 /* Identify Bison output.  */
44 #define YYBISON 1
45
46 /* Bison version.  */
47 #define YYBISON_VERSION "2.7"
48
49 /* Skeleton name.  */
50 #define YYSKELETON_NAME "yacc.c"
51
52 /* Pure parsers.  */
53 #define YYPURE 0
54
55 /* Push parsers.  */
56 #define YYPUSH 0
57
58 /* Pull parsers.  */
59 #define YYPULL 1
60
61
62
63
64 /* Copy the first part of user declarations.  */
65 /* Line 371 of yacc.c  */
66 #line 1 "slmod_rdf_parser.y"
67
68   #include <atalk/standards.h>
69
70   #include <stdbool.h>
71   #include <stdio.h>
72   #include <string.h>
73   #include <time.h>
74
75   #include <gio/gio.h>
76   #include <tracker.h>
77
78   #include <atalk/talloc.h>
79   #include <atalk/logger.h>
80   #include <atalk/errchk.h>
81   #include <atalk/spotlight.h>
82
83   #include "slmod_rdf_map.h"
84
85   struct yy_buffer_state;
86   typedef struct yy_buffer_state *YY_BUFFER_STATE;
87   extern int yylex (void);
88   extern void yyerror (char const *);
89   extern void *yyterminate(void);
90   extern YY_BUFFER_STATE yy_scan_string( const char *str);
91   extern void yy_delete_buffer ( YY_BUFFER_STATE buffer );
92
93   /* forward declarations */
94   static const char *map_expr(const char *attr, char op, const char *val);
95   static const char *map_daterange(const char *dateattr, time_t date1, time_t date2);
96   static time_t isodate2unix(const char *s);
97  
98  /* global vars, eg needed by the lexer */
99   slq_t *srp_slq;
100
101   /* local vars */
102   static gchar *srp_result;
103   static gchar *srp_fts;
104
105 /* Line 371 of yacc.c  */
106 #line 107 "slmod_rdf_parser.c"
107
108 # ifndef YY_NULL
109 #  if defined __cplusplus && 201103L <= __cplusplus
110 #   define YY_NULL nullptr
111 #  else
112 #   define YY_NULL 0
113 #  endif
114 # endif
115
116 /* Enabling verbose error messages.  */
117 #ifdef YYERROR_VERBOSE
118 # undef YYERROR_VERBOSE
119 # define YYERROR_VERBOSE 1
120 #else
121 # define YYERROR_VERBOSE 1
122 #endif
123
124 /* In a future release of Bison, this section will be replaced
125    by #include "y.tab.h".  */
126 #ifndef YY_YY_Y_TAB_H_INCLUDED
127 # define YY_YY_Y_TAB_H_INCLUDED
128 /* Enabling traces.  */
129 #ifndef YYDEBUG
130 # define YYDEBUG 0
131 #endif
132 #if YYDEBUG
133 extern int yydebug;
134 #endif
135
136 /* Tokens.  */
137 #ifndef YYTOKENTYPE
138 # define YYTOKENTYPE
139    /* Put the tokens into the symbol table, so that GDB and other debuggers
140       know about them.  */
141    enum yytokentype {
142      WORD = 258,
143      BOOL = 259,
144      FUNC_INRANGE = 260,
145      DATE_ISO = 261,
146      OBRACE = 262,
147      CBRACE = 263,
148      EQUAL = 264,
149      UNEQUAL = 265,
150      GT = 266,
151      LT = 267,
152      COMMA = 268,
153      QUOTE = 269,
154      AND = 270,
155      OR = 271
156    };
157 #endif
158 /* Tokens.  */
159 #define WORD 258
160 #define BOOL 259
161 #define FUNC_INRANGE 260
162 #define DATE_ISO 261
163 #define OBRACE 262
164 #define CBRACE 263
165 #define EQUAL 264
166 #define UNEQUAL 265
167 #define GT 266
168 #define LT 267
169 #define COMMA 268
170 #define QUOTE 269
171 #define AND 270
172 #define OR 271
173
174
175
176 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
177 typedef union YYSTYPE
178 {
179 /* Line 387 of yacc.c  */
180 #line 46 "slmod_rdf_parser.y"
181
182     int ival;
183     const char *sval;
184     bool bval;
185     time_t tval;
186
187
188 /* Line 387 of yacc.c  */
189 #line 190 "slmod_rdf_parser.c"
190 } YYSTYPE;
191 # define YYSTYPE_IS_TRIVIAL 1
192 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
193 # define YYSTYPE_IS_DECLARED 1
194 #endif
195
196 extern YYSTYPE yylval;
197
198 #ifdef YYPARSE_PARAM
199 #if defined __STDC__ || defined __cplusplus
200 int yyparse (void *YYPARSE_PARAM);
201 #else
202 int yyparse ();
203 #endif
204 #else /* ! YYPARSE_PARAM */
205 #if defined __STDC__ || defined __cplusplus
206 int yyparse (void);
207 #else
208 int yyparse ();
209 #endif
210 #endif /* ! YYPARSE_PARAM */
211 /* "%code provides" blocks.  */
212 /* Line 387 of yacc.c  */
213 #line 40 "slmod_rdf_parser.y"
214
215   #define SPRAW_TIME_OFFSET 978307200
216   extern int map_spotlight_to_rdf_query(slq_t *slq);
217   extern slq_t *srp_slq;
218
219
220 /* Line 387 of yacc.c  */
221 #line 222 "slmod_rdf_parser.c"
222
223 #endif /* !YY_YY_Y_TAB_H_INCLUDED  */
224
225 /* Copy the second part of user declarations.  */
226
227 /* Line 390 of yacc.c  */
228 #line 229 "slmod_rdf_parser.c"
229
230 #ifdef short
231 # undef short
232 #endif
233
234 #ifdef YYTYPE_UINT8
235 typedef YYTYPE_UINT8 yytype_uint8;
236 #else
237 typedef unsigned char yytype_uint8;
238 #endif
239
240 #ifdef YYTYPE_INT8
241 typedef YYTYPE_INT8 yytype_int8;
242 #elif (defined __STDC__ || defined __C99__FUNC__ \
243      || defined __cplusplus || defined _MSC_VER)
244 typedef signed char yytype_int8;
245 #else
246 typedef short int yytype_int8;
247 #endif
248
249 #ifdef YYTYPE_UINT16
250 typedef YYTYPE_UINT16 yytype_uint16;
251 #else
252 typedef unsigned short int yytype_uint16;
253 #endif
254
255 #ifdef YYTYPE_INT16
256 typedef YYTYPE_INT16 yytype_int16;
257 #else
258 typedef short int yytype_int16;
259 #endif
260
261 #ifndef YYSIZE_T
262 # ifdef __SIZE_TYPE__
263 #  define YYSIZE_T __SIZE_TYPE__
264 # elif defined size_t
265 #  define YYSIZE_T size_t
266 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
267      || defined __cplusplus || defined _MSC_VER)
268 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
269 #  define YYSIZE_T size_t
270 # else
271 #  define YYSIZE_T unsigned int
272 # endif
273 #endif
274
275 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
276
277 #ifndef YY_
278 # if defined YYENABLE_NLS && YYENABLE_NLS
279 #  if ENABLE_NLS
280 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
281 #   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
282 #  endif
283 # endif
284 # ifndef YY_
285 #  define YY_(Msgid) Msgid
286 # endif
287 #endif
288
289 /* Suppress unused-variable warnings by "using" E.  */
290 #if ! defined lint || defined __GNUC__
291 # define YYUSE(E) ((void) (E))
292 #else
293 # define YYUSE(E) /* empty */
294 #endif
295
296 /* Identity function, used to suppress warnings about constant conditions.  */
297 #ifndef lint
298 # define YYID(N) (N)
299 #else
300 #if (defined __STDC__ || defined __C99__FUNC__ \
301      || defined __cplusplus || defined _MSC_VER)
302 static int
303 YYID (int yyi)
304 #else
305 static int
306 YYID (yyi)
307     int yyi;
308 #endif
309 {
310   return yyi;
311 }
312 #endif
313
314 #if ! defined yyoverflow || YYERROR_VERBOSE
315
316 /* The parser invokes alloca or malloc; define the necessary symbols.  */
317
318 # ifdef YYSTACK_USE_ALLOCA
319 #  if YYSTACK_USE_ALLOCA
320 #   ifdef __GNUC__
321 #    define YYSTACK_ALLOC __builtin_alloca
322 #   elif defined __BUILTIN_VA_ARG_INCR
323 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
324 #   elif defined _AIX
325 #    define YYSTACK_ALLOC __alloca
326 #   elif defined _MSC_VER
327 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
328 #    define alloca _alloca
329 #   else
330 #    define YYSTACK_ALLOC alloca
331 #    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
332      || defined __cplusplus || defined _MSC_VER)
333 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
334       /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
335 #     ifndef EXIT_SUCCESS
336 #      define EXIT_SUCCESS 0
337 #     endif
338 #    endif
339 #   endif
340 #  endif
341 # endif
342
343 # ifdef YYSTACK_ALLOC
344    /* Pacify GCC's `empty if-body' warning.  */
345 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
346 #  ifndef YYSTACK_ALLOC_MAXIMUM
347     /* The OS might guarantee only one guard page at the bottom of the stack,
348        and a page size can be as small as 4096 bytes.  So we cannot safely
349        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
350        to allow for a few compiler-allocated temporary stack slots.  */
351 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
352 #  endif
353 # else
354 #  define YYSTACK_ALLOC YYMALLOC
355 #  define YYSTACK_FREE YYFREE
356 #  ifndef YYSTACK_ALLOC_MAXIMUM
357 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
358 #  endif
359 #  if (defined __cplusplus && ! defined EXIT_SUCCESS \
360        && ! ((defined YYMALLOC || defined malloc) \
361              && (defined YYFREE || defined free)))
362 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
363 #   ifndef EXIT_SUCCESS
364 #    define EXIT_SUCCESS 0
365 #   endif
366 #  endif
367 #  ifndef YYMALLOC
368 #   define YYMALLOC malloc
369 #   if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
370      || defined __cplusplus || defined _MSC_VER)
371 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
372 #   endif
373 #  endif
374 #  ifndef YYFREE
375 #   define YYFREE free
376 #   if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
377      || defined __cplusplus || defined _MSC_VER)
378 void free (void *); /* INFRINGES ON USER NAME SPACE */
379 #   endif
380 #  endif
381 # endif
382 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
383
384
385 #if (! defined yyoverflow \
386      && (! defined __cplusplus \
387          || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
388
389 /* A type that is properly aligned for any stack member.  */
390 union yyalloc
391 {
392   yytype_int16 yyss_alloc;
393   YYSTYPE yyvs_alloc;
394 };
395
396 /* The size of the maximum gap between one aligned stack and the next.  */
397 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
398
399 /* The size of an array large to enough to hold all stacks, each with
400    N elements.  */
401 # define YYSTACK_BYTES(N) \
402      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
403       + YYSTACK_GAP_MAXIMUM)
404
405 # define YYCOPY_NEEDED 1
406
407 /* Relocate STACK from its old location to the new one.  The
408    local variables YYSIZE and YYSTACKSIZE give the old and new number of
409    elements in the stack, and YYPTR gives the new location of the
410    stack.  Advance YYPTR to a properly aligned location for the next
411    stack.  */
412 # define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
413     do                                                                  \
414       {                                                                 \
415         YYSIZE_T yynewbytes;                                            \
416         YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
417         Stack = &yyptr->Stack_alloc;                                    \
418         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
419         yyptr += yynewbytes / sizeof (*yyptr);                          \
420       }                                                                 \
421     while (YYID (0))
422
423 #endif
424
425 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
426 /* Copy COUNT objects from SRC to DST.  The source and destination do
427    not overlap.  */
428 # ifndef YYCOPY
429 #  if defined __GNUC__ && 1 < __GNUC__
430 #   define YYCOPY(Dst, Src, Count) \
431       __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
432 #  else
433 #   define YYCOPY(Dst, Src, Count)              \
434       do                                        \
435         {                                       \
436           YYSIZE_T yyi;                         \
437           for (yyi = 0; yyi < (Count); yyi++)   \
438             (Dst)[yyi] = (Src)[yyi];            \
439         }                                       \
440       while (YYID (0))
441 #  endif
442 # endif
443 #endif /* !YYCOPY_NEEDED */
444
445 /* YYFINAL -- State number of the termination state.  */
446 #define YYFINAL  2
447 /* YYLAST -- Last index in YYTABLE.  */
448 #define YYLAST   51
449
450 /* YYNTOKENS -- Number of terminals.  */
451 #define YYNTOKENS  17
452 /* YYNNTS -- Number of nonterminals.  */
453 #define YYNNTS  7
454 /* YYNRULES -- Number of rules.  */
455 #define YYNRULES  21
456 /* YYNRULES -- Number of states.  */
457 #define YYNSTATES  49
458
459 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
460 #define YYUNDEFTOK  2
461 #define YYMAXUTOK   271
462
463 #define YYTRANSLATE(YYX)                                                \
464   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
465
466 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
467 static const yytype_uint8 yytranslate[] =
468 {
469        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
470        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
471        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
472        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
473        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
474        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
475        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
476        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
477        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
478        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
479        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
480        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
481        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
482        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
483        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
484        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
485        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
486        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
487        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
488        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
489        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
490        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
491        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
492        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
493        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
494        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
495        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
496       15,    16
497 };
498
499 #if YYDEBUG
500 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
501    YYRHS.  */
502 static const yytype_uint8 yyprhs[] =
503 {
504        0,     0,     3,     4,     7,     9,    11,    13,    15,    19,
505       23,    27,    33,    39,    45,    51,    58,    65,    72,    79,
506       88,    93
507 };
508
509 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
510 static const yytype_int8 yyrhs[] =
511 {
512       18,     0,    -1,    -1,    18,    19,    -1,    20,    -1,     4,
513       -1,    21,    -1,    22,    -1,     7,    20,     8,    -1,    20,
514       15,    20,    -1,    20,    16,    20,    -1,     3,     9,    14,
515        3,    14,    -1,     3,    10,    14,     3,    14,    -1,     3,
516       12,    14,     3,    14,    -1,     3,    11,    14,     3,    14,
517       -1,     3,     9,    14,     3,    14,     3,    -1,     3,    10,
518       14,     3,    14,     3,    -1,     3,    12,    14,     3,    14,
519        3,    -1,     3,    11,    14,     3,    14,     3,    -1,     5,
520        7,     3,    13,    23,    13,    23,     8,    -1,     6,     7,
521        3,     8,    -1,     3,    -1
522 };
523
524 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
525 static const yytype_uint8 yyrline[] =
526 {
527        0,    68,    68,    70,    74,    91,    97,    98,    99,   100,
528      101,   126,   127,   128,   129,   130,   131,   132,   133,   137,
529      141,   142
530 };
531 #endif
532
533 #if YYDEBUG || YYERROR_VERBOSE || 1
534 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
535    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
536 static const char *const yytname[] =
537 {
538   "$end", "error", "$undefined", "WORD", "BOOL", "FUNC_INRANGE",
539   "DATE_ISO", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA",
540   "QUOTE", "AND", "OR", "$accept", "input", "line", "expr", "match",
541   "function", "date", YY_NULL
542 };
543 #endif
544
545 # ifdef YYPRINT
546 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
547    token YYLEX-NUM.  */
548 static const yytype_uint16 yytoknum[] =
549 {
550        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
551      265,   266,   267,   268,   269,   270,   271
552 };
553 # endif
554
555 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
556 static const yytype_uint8 yyr1[] =
557 {
558        0,    17,    18,    18,    19,    20,    20,    20,    20,    20,
559       20,    21,    21,    21,    21,    21,    21,    21,    21,    22,
560       23,    23
561 };
562
563 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
564 static const yytype_uint8 yyr2[] =
565 {
566        0,     2,     0,     2,     1,     1,     1,     1,     3,     3,
567        3,     5,     5,     5,     5,     6,     6,     6,     6,     8,
568        4,     1
569 };
570
571 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
572    Performed when YYTABLE doesn't specify something else to do.  Zero
573    means the default is an error.  */
574 static const yytype_uint8 yydefact[] =
575 {
576        2,     0,     1,     0,     5,     0,     0,     3,     4,     6,
577        7,     0,     0,     0,     0,     0,     0,     0,     0,     0,
578        0,     0,     0,     0,     8,     9,    10,     0,     0,     0,
579        0,     0,    11,    12,    14,    13,    21,     0,     0,    15,
580       16,    18,    17,     0,     0,     0,     0,    20,    19
581 };
582
583 /* YYDEFGOTO[NTERM-NUM].  */
584 static const yytype_int8 yydefgoto[] =
585 {
586       -1,     1,     7,     8,     9,    10,    38
587 };
588
589 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
590    STATE-NUM.  */
591 #define YYPACT_NINF -8
592 static const yytype_int8 yypact[] =
593 {
594       -8,    10,    -8,     9,    -8,    -2,    -1,    -8,     8,    -8,
595       -8,     2,    12,    13,    14,     4,    -7,    -1,    -1,    26,
596       27,    28,    29,    20,    -8,    18,    -8,    21,    22,    23,
597       24,    19,    36,    37,    38,    39,    -8,    40,    30,    -8,
598       -8,    -8,    -8,    41,    19,    42,    43,    -8,    -8
599 };
600
601 /* YYPGOTO[NTERM-NUM].  */
602 static const yytype_int8 yypgoto[] =
603 {
604       -8,    -8,    -8,    -6,    -8,    -8,     1
605 };
606
607 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
608    positive, shift that token.  If negative, reduce the rule which
609    number is the opposite.  If YYTABLE_NINF, syntax error.  */
610 #define YYTABLE_NINF -1
611 static const yytype_uint8 yytable[] =
612 {
613       16,    24,     3,     4,     5,    15,     6,    23,    17,    18,
614        2,    25,    26,     3,     4,     5,    19,     6,    11,    12,
615       13,    14,    36,    17,    18,    37,    20,    21,    22,    27,
616       28,    29,    30,    31,    18,    32,    33,    34,    35,    39,
617       40,    41,    42,    44,    45,    46,     0,    43,     0,     0,
618       47,    48
619 };
620
621 #define yypact_value_is_default(Yystate) \
622   (!!((Yystate) == (-8)))
623
624 #define yytable_value_is_error(Yytable_value) \
625   YYID (0)
626
627 static const yytype_int8 yycheck[] =
628 {
629        6,     8,     3,     4,     5,     7,     7,     3,    15,    16,
630        0,    17,    18,     3,     4,     5,    14,     7,     9,    10,
631       11,    12,     3,    15,    16,     6,    14,    14,    14,     3,
632        3,     3,     3,    13,    16,    14,    14,    14,    14,     3,
633        3,     3,     3,    13,     3,    44,    -1,     7,    -1,    -1,
634        8,     8
635 };
636
637 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
638    symbol of state STATE-NUM.  */
639 static const yytype_uint8 yystos[] =
640 {
641        0,    18,     0,     3,     4,     5,     7,    19,    20,    21,
642       22,     9,    10,    11,    12,     7,    20,    15,    16,    14,
643       14,    14,    14,     3,     8,    20,    20,     3,     3,     3,
644        3,    13,    14,    14,    14,    14,     3,     6,    23,     3,
645        3,     3,     3,     7,    13,     3,    23,     8,     8
646 };
647
648 #define yyerrok         (yyerrstatus = 0)
649 #define yyclearin       (yychar = YYEMPTY)
650 #define YYEMPTY         (-2)
651 #define YYEOF           0
652
653 #define YYACCEPT        goto yyacceptlab
654 #define YYABORT         goto yyabortlab
655 #define YYERROR         goto yyerrorlab
656
657
658 /* Like YYERROR except do call yyerror.  This remains here temporarily
659    to ease the transition to the new meaning of YYERROR, for GCC.
660    Once GCC version 2 has supplanted version 1, this can go.  However,
661    YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
662    in Bison 2.4.2's NEWS entry, where a plan to phase it out is
663    discussed.  */
664
665 #define YYFAIL          goto yyerrlab
666 #if defined YYFAIL
667   /* This is here to suppress warnings from the GCC cpp's
668      -Wunused-macros.  Normally we don't worry about that warning, but
669      some users do, and we want to make it easy for users to remove
670      YYFAIL uses, which will produce warnings from Bison 2.5.  */
671 #endif
672
673 #define YYRECOVERING()  (!!yyerrstatus)
674
675 #define YYBACKUP(Token, Value)                                  \
676 do                                                              \
677   if (yychar == YYEMPTY)                                        \
678     {                                                           \
679       yychar = (Token);                                         \
680       yylval = (Value);                                         \
681       YYPOPSTACK (yylen);                                       \
682       yystate = *yyssp;                                         \
683       goto yybackup;                                            \
684     }                                                           \
685   else                                                          \
686     {                                                           \
687       yyerror (YY_("syntax error: cannot back up")); \
688       YYERROR;                                                  \
689     }                                                           \
690 while (YYID (0))
691
692 /* Error token number */
693 #define YYTERROR        1
694 #define YYERRCODE       256
695
696
697 /* This macro is provided for backward compatibility. */
698 #ifndef YY_LOCATION_PRINT
699 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
700 #endif
701
702
703 /* YYLEX -- calling `yylex' with the right arguments.  */
704 #ifdef YYLEX_PARAM
705 # define YYLEX yylex (YYLEX_PARAM)
706 #else
707 # define YYLEX yylex ()
708 #endif
709
710 /* Enable debugging if requested.  */
711 #if YYDEBUG
712
713 # ifndef YYFPRINTF
714 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
715 #  define YYFPRINTF fprintf
716 # endif
717
718 # define YYDPRINTF(Args)                        \
719 do {                                            \
720   if (yydebug)                                  \
721     YYFPRINTF Args;                             \
722 } while (YYID (0))
723
724 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
725 do {                                                                      \
726   if (yydebug)                                                            \
727     {                                                                     \
728       YYFPRINTF (stderr, "%s ", Title);                                   \
729       yy_symbol_print (stderr,                                            \
730                   Type, Value); \
731       YYFPRINTF (stderr, "\n");                                           \
732     }                                                                     \
733 } while (YYID (0))
734
735
736 /*--------------------------------.
737 | Print this symbol on YYOUTPUT.  |
738 `--------------------------------*/
739
740 /*ARGSUSED*/
741 #if (defined __STDC__ || defined __C99__FUNC__ \
742      || defined __cplusplus || defined _MSC_VER)
743 static void
744 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
745 #else
746 static void
747 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
748     FILE *yyoutput;
749     int yytype;
750     YYSTYPE const * const yyvaluep;
751 #endif
752 {
753   FILE *yyo = yyoutput;
754   YYUSE (yyo);
755   if (!yyvaluep)
756     return;
757 # ifdef YYPRINT
758   if (yytype < YYNTOKENS)
759     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
760 # else
761   YYUSE (yyoutput);
762 # endif
763   switch (yytype)
764     {
765       default:
766         break;
767     }
768 }
769
770
771 /*--------------------------------.
772 | Print this symbol on YYOUTPUT.  |
773 `--------------------------------*/
774
775 #if (defined __STDC__ || defined __C99__FUNC__ \
776      || defined __cplusplus || defined _MSC_VER)
777 static void
778 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
779 #else
780 static void
781 yy_symbol_print (yyoutput, yytype, yyvaluep)
782     FILE *yyoutput;
783     int yytype;
784     YYSTYPE const * const yyvaluep;
785 #endif
786 {
787   if (yytype < YYNTOKENS)
788     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
789   else
790     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
791
792   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
793   YYFPRINTF (yyoutput, ")");
794 }
795
796 /*------------------------------------------------------------------.
797 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
798 | TOP (included).                                                   |
799 `------------------------------------------------------------------*/
800
801 #if (defined __STDC__ || defined __C99__FUNC__ \
802      || defined __cplusplus || defined _MSC_VER)
803 static void
804 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
805 #else
806 static void
807 yy_stack_print (yybottom, yytop)
808     yytype_int16 *yybottom;
809     yytype_int16 *yytop;
810 #endif
811 {
812   YYFPRINTF (stderr, "Stack now");
813   for (; yybottom <= yytop; yybottom++)
814     {
815       int yybot = *yybottom;
816       YYFPRINTF (stderr, " %d", yybot);
817     }
818   YYFPRINTF (stderr, "\n");
819 }
820
821 # define YY_STACK_PRINT(Bottom, Top)                            \
822 do {                                                            \
823   if (yydebug)                                                  \
824     yy_stack_print ((Bottom), (Top));                           \
825 } while (YYID (0))
826
827
828 /*------------------------------------------------.
829 | Report that the YYRULE is going to be reduced.  |
830 `------------------------------------------------*/
831
832 #if (defined __STDC__ || defined __C99__FUNC__ \
833      || defined __cplusplus || defined _MSC_VER)
834 static void
835 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
836 #else
837 static void
838 yy_reduce_print (yyvsp, yyrule)
839     YYSTYPE *yyvsp;
840     int yyrule;
841 #endif
842 {
843   int yynrhs = yyr2[yyrule];
844   int yyi;
845   unsigned long int yylno = yyrline[yyrule];
846   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
847              yyrule - 1, yylno);
848   /* The symbols being reduced.  */
849   for (yyi = 0; yyi < yynrhs; yyi++)
850     {
851       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
852       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
853                        &(yyvsp[(yyi + 1) - (yynrhs)])
854                                        );
855       YYFPRINTF (stderr, "\n");
856     }
857 }
858
859 # define YY_REDUCE_PRINT(Rule)          \
860 do {                                    \
861   if (yydebug)                          \
862     yy_reduce_print (yyvsp, Rule); \
863 } while (YYID (0))
864
865 /* Nonzero means print parse trace.  It is left uninitialized so that
866    multiple parsers can coexist.  */
867 int yydebug;
868 #else /* !YYDEBUG */
869 # define YYDPRINTF(Args)
870 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
871 # define YY_STACK_PRINT(Bottom, Top)
872 # define YY_REDUCE_PRINT(Rule)
873 #endif /* !YYDEBUG */
874
875
876 /* YYINITDEPTH -- initial size of the parser's stacks.  */
877 #ifndef YYINITDEPTH
878 # define YYINITDEPTH 200
879 #endif
880
881 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
882    if the built-in stack extension method is used).
883
884    Do not make this value too large; the results are undefined if
885    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
886    evaluated with infinite-precision integer arithmetic.  */
887
888 #ifndef YYMAXDEPTH
889 # define YYMAXDEPTH 10000
890 #endif
891
892
893 #if YYERROR_VERBOSE
894
895 # ifndef yystrlen
896 #  if defined __GLIBC__ && defined _STRING_H
897 #   define yystrlen strlen
898 #  else
899 /* Return the length of YYSTR.  */
900 #if (defined __STDC__ || defined __C99__FUNC__ \
901      || defined __cplusplus || defined _MSC_VER)
902 static YYSIZE_T
903 yystrlen (const char *yystr)
904 #else
905 static YYSIZE_T
906 yystrlen (yystr)
907     const char *yystr;
908 #endif
909 {
910   YYSIZE_T yylen;
911   for (yylen = 0; yystr[yylen]; yylen++)
912     continue;
913   return yylen;
914 }
915 #  endif
916 # endif
917
918 # ifndef yystpcpy
919 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
920 #   define yystpcpy stpcpy
921 #  else
922 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
923    YYDEST.  */
924 #if (defined __STDC__ || defined __C99__FUNC__ \
925      || defined __cplusplus || defined _MSC_VER)
926 static char *
927 yystpcpy (char *yydest, const char *yysrc)
928 #else
929 static char *
930 yystpcpy (yydest, yysrc)
931     char *yydest;
932     const char *yysrc;
933 #endif
934 {
935   char *yyd = yydest;
936   const char *yys = yysrc;
937
938   while ((*yyd++ = *yys++) != '\0')
939     continue;
940
941   return yyd - 1;
942 }
943 #  endif
944 # endif
945
946 # ifndef yytnamerr
947 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
948    quotes and backslashes, so that it's suitable for yyerror.  The
949    heuristic is that double-quoting is unnecessary unless the string
950    contains an apostrophe, a comma, or backslash (other than
951    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
952    null, do not copy; instead, return the length of what the result
953    would have been.  */
954 static YYSIZE_T
955 yytnamerr (char *yyres, const char *yystr)
956 {
957   if (*yystr == '"')
958     {
959       YYSIZE_T yyn = 0;
960       char const *yyp = yystr;
961
962       for (;;)
963         switch (*++yyp)
964           {
965           case '\'':
966           case ',':
967             goto do_not_strip_quotes;
968
969           case '\\':
970             if (*++yyp != '\\')
971               goto do_not_strip_quotes;
972             /* Fall through.  */
973           default:
974             if (yyres)
975               yyres[yyn] = *yyp;
976             yyn++;
977             break;
978
979           case '"':
980             if (yyres)
981               yyres[yyn] = '\0';
982             return yyn;
983           }
984     do_not_strip_quotes: ;
985     }
986
987   if (! yyres)
988     return yystrlen (yystr);
989
990   return yystpcpy (yyres, yystr) - yyres;
991 }
992 # endif
993
994 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
995    about the unexpected token YYTOKEN for the state stack whose top is
996    YYSSP.
997
998    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
999    not large enough to hold the message.  In that case, also set
1000    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1001    required number of bytes is too large to store.  */
1002 static int
1003 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1004                 yytype_int16 *yyssp, int yytoken)
1005 {
1006   YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1007   YYSIZE_T yysize = yysize0;
1008   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1009   /* Internationalized format string. */
1010   const char *yyformat = YY_NULL;
1011   /* Arguments of yyformat. */
1012   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1013   /* Number of reported tokens (one for the "unexpected", one per
1014      "expected"). */
1015   int yycount = 0;
1016
1017   /* There are many possibilities here to consider:
1018      - Assume YYFAIL is not used.  It's too flawed to consider.  See
1019        <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1020        for details.  YYERROR is fine as it does not invoke this
1021        function.
1022      - If this state is a consistent state with a default action, then
1023        the only way this function was invoked is if the default action
1024        is an error action.  In that case, don't check for expected
1025        tokens because there are none.
1026      - The only way there can be no lookahead present (in yychar) is if
1027        this state is a consistent state with a default action.  Thus,
1028        detecting the absence of a lookahead is sufficient to determine
1029        that there is no unexpected or expected token to report.  In that
1030        case, just report a simple "syntax error".
1031      - Don't assume there isn't a lookahead just because this state is a
1032        consistent state with a default action.  There might have been a
1033        previous inconsistent state, consistent state with a non-default
1034        action, or user semantic action that manipulated yychar.
1035      - Of course, the expected token list depends on states to have
1036        correct lookahead information, and it depends on the parser not
1037        to perform extra reductions after fetching a lookahead from the
1038        scanner and before detecting a syntax error.  Thus, state merging
1039        (from LALR or IELR) and default reductions corrupt the expected
1040        token list.  However, the list is correct for canonical LR with
1041        one exception: it will still contain any token that will not be
1042        accepted due to an error action in a later state.
1043   */
1044   if (yytoken != YYEMPTY)
1045     {
1046       int yyn = yypact[*yyssp];
1047       yyarg[yycount++] = yytname[yytoken];
1048       if (!yypact_value_is_default (yyn))
1049         {
1050           /* Start YYX at -YYN if negative to avoid negative indexes in
1051              YYCHECK.  In other words, skip the first -YYN actions for
1052              this state because they are default actions.  */
1053           int yyxbegin = yyn < 0 ? -yyn : 0;
1054           /* Stay within bounds of both yycheck and yytname.  */
1055           int yychecklim = YYLAST - yyn + 1;
1056           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1057           int yyx;
1058
1059           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1060             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1061                 && !yytable_value_is_error (yytable[yyx + yyn]))
1062               {
1063                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1064                   {
1065                     yycount = 1;
1066                     yysize = yysize0;
1067                     break;
1068                   }
1069                 yyarg[yycount++] = yytname[yyx];
1070                 {
1071                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1072                   if (! (yysize <= yysize1
1073                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1074                     return 2;
1075                   yysize = yysize1;
1076                 }
1077               }
1078         }
1079     }
1080
1081   switch (yycount)
1082     {
1083 # define YYCASE_(N, S)                      \
1084       case N:                               \
1085         yyformat = S;                       \
1086       break
1087       YYCASE_(0, YY_("syntax error"));
1088       YYCASE_(1, YY_("syntax error, unexpected %s"));
1089       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1090       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1091       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1092       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1093 # undef YYCASE_
1094     }
1095
1096   {
1097     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1098     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1099       return 2;
1100     yysize = yysize1;
1101   }
1102
1103   if (*yymsg_alloc < yysize)
1104     {
1105       *yymsg_alloc = 2 * yysize;
1106       if (! (yysize <= *yymsg_alloc
1107              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1108         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1109       return 1;
1110     }
1111
1112   /* Avoid sprintf, as that infringes on the user's name space.
1113      Don't have undefined behavior even if the translation
1114      produced a string with the wrong number of "%s"s.  */
1115   {
1116     char *yyp = *yymsg;
1117     int yyi = 0;
1118     while ((*yyp = *yyformat) != '\0')
1119       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1120         {
1121           yyp += yytnamerr (yyp, yyarg[yyi++]);
1122           yyformat += 2;
1123         }
1124       else
1125         {
1126           yyp++;
1127           yyformat++;
1128         }
1129   }
1130   return 0;
1131 }
1132 #endif /* YYERROR_VERBOSE */
1133
1134 /*-----------------------------------------------.
1135 | Release the memory associated to this symbol.  |
1136 `-----------------------------------------------*/
1137
1138 /*ARGSUSED*/
1139 #if (defined __STDC__ || defined __C99__FUNC__ \
1140      || defined __cplusplus || defined _MSC_VER)
1141 static void
1142 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1143 #else
1144 static void
1145 yydestruct (yymsg, yytype, yyvaluep)
1146     const char *yymsg;
1147     int yytype;
1148     YYSTYPE *yyvaluep;
1149 #endif
1150 {
1151   YYUSE (yyvaluep);
1152
1153   if (!yymsg)
1154     yymsg = "Deleting";
1155   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1156
1157   switch (yytype)
1158     {
1159
1160       default:
1161         break;
1162     }
1163 }
1164
1165
1166
1167
1168 /* The lookahead symbol.  */
1169 int yychar;
1170
1171
1172 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1173 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1174 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
1175 #endif
1176 #ifndef YY_INITIAL_VALUE
1177 # define YY_INITIAL_VALUE(Value) /* Nothing. */
1178 #endif
1179
1180 /* The semantic value of the lookahead symbol.  */
1181 YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
1182
1183 /* Number of syntax errors so far.  */
1184 int yynerrs;
1185
1186
1187 /*----------.
1188 | yyparse.  |
1189 `----------*/
1190
1191 #ifdef YYPARSE_PARAM
1192 #if (defined __STDC__ || defined __C99__FUNC__ \
1193      || defined __cplusplus || defined _MSC_VER)
1194 int
1195 yyparse (void *YYPARSE_PARAM)
1196 #else
1197 int
1198 yyparse (YYPARSE_PARAM)
1199     void *YYPARSE_PARAM;
1200 #endif
1201 #else /* ! YYPARSE_PARAM */
1202 #if (defined __STDC__ || defined __C99__FUNC__ \
1203      || defined __cplusplus || defined _MSC_VER)
1204 int
1205 yyparse (void)
1206 #else
1207 int
1208 yyparse ()
1209
1210 #endif
1211 #endif
1212 {
1213     int yystate;
1214     /* Number of tokens to shift before error messages enabled.  */
1215     int yyerrstatus;
1216
1217     /* The stacks and their tools:
1218        `yyss': related to states.
1219        `yyvs': related to semantic values.
1220
1221        Refer to the stacks through separate pointers, to allow yyoverflow
1222        to reallocate them elsewhere.  */
1223
1224     /* The state stack.  */
1225     yytype_int16 yyssa[YYINITDEPTH];
1226     yytype_int16 *yyss;
1227     yytype_int16 *yyssp;
1228
1229     /* The semantic value stack.  */
1230     YYSTYPE yyvsa[YYINITDEPTH];
1231     YYSTYPE *yyvs;
1232     YYSTYPE *yyvsp;
1233
1234     YYSIZE_T yystacksize;
1235
1236   int yyn;
1237   int yyresult;
1238   /* Lookahead token as an internal (translated) token number.  */
1239   int yytoken = 0;
1240   /* The variables used to return semantic value and location from the
1241      action routines.  */
1242   YYSTYPE yyval;
1243
1244 #if YYERROR_VERBOSE
1245   /* Buffer for error messages, and its allocated size.  */
1246   char yymsgbuf[128];
1247   char *yymsg = yymsgbuf;
1248   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1249 #endif
1250
1251 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1252
1253   /* The number of symbols on the RHS of the reduced rule.
1254      Keep to zero when no symbol should be popped.  */
1255   int yylen = 0;
1256
1257   yyssp = yyss = yyssa;
1258   yyvsp = yyvs = yyvsa;
1259   yystacksize = YYINITDEPTH;
1260
1261   YYDPRINTF ((stderr, "Starting parse\n"));
1262
1263   yystate = 0;
1264   yyerrstatus = 0;
1265   yynerrs = 0;
1266   yychar = YYEMPTY; /* Cause a token to be read.  */
1267   goto yysetstate;
1268
1269 /*------------------------------------------------------------.
1270 | yynewstate -- Push a new state, which is found in yystate.  |
1271 `------------------------------------------------------------*/
1272  yynewstate:
1273   /* In all cases, when you get here, the value and location stacks
1274      have just been pushed.  So pushing a state here evens the stacks.  */
1275   yyssp++;
1276
1277  yysetstate:
1278   *yyssp = yystate;
1279
1280   if (yyss + yystacksize - 1 <= yyssp)
1281     {
1282       /* Get the current used size of the three stacks, in elements.  */
1283       YYSIZE_T yysize = yyssp - yyss + 1;
1284
1285 #ifdef yyoverflow
1286       {
1287         /* Give user a chance to reallocate the stack.  Use copies of
1288            these so that the &'s don't force the real ones into
1289            memory.  */
1290         YYSTYPE *yyvs1 = yyvs;
1291         yytype_int16 *yyss1 = yyss;
1292
1293         /* Each stack pointer address is followed by the size of the
1294            data in use in that stack, in bytes.  This used to be a
1295            conditional around just the two extra args, but that might
1296            be undefined if yyoverflow is a macro.  */
1297         yyoverflow (YY_("memory exhausted"),
1298                     &yyss1, yysize * sizeof (*yyssp),
1299                     &yyvs1, yysize * sizeof (*yyvsp),
1300                     &yystacksize);
1301
1302         yyss = yyss1;
1303         yyvs = yyvs1;
1304       }
1305 #else /* no yyoverflow */
1306 # ifndef YYSTACK_RELOCATE
1307       goto yyexhaustedlab;
1308 # else
1309       /* Extend the stack our own way.  */
1310       if (YYMAXDEPTH <= yystacksize)
1311         goto yyexhaustedlab;
1312       yystacksize *= 2;
1313       if (YYMAXDEPTH < yystacksize)
1314         yystacksize = YYMAXDEPTH;
1315
1316       {
1317         yytype_int16 *yyss1 = yyss;
1318         union yyalloc *yyptr =
1319           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1320         if (! yyptr)
1321           goto yyexhaustedlab;
1322         YYSTACK_RELOCATE (yyss_alloc, yyss);
1323         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1324 #  undef YYSTACK_RELOCATE
1325         if (yyss1 != yyssa)
1326           YYSTACK_FREE (yyss1);
1327       }
1328 # endif
1329 #endif /* no yyoverflow */
1330
1331       yyssp = yyss + yysize - 1;
1332       yyvsp = yyvs + yysize - 1;
1333
1334       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1335                   (unsigned long int) yystacksize));
1336
1337       if (yyss + yystacksize - 1 <= yyssp)
1338         YYABORT;
1339     }
1340
1341   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1342
1343   if (yystate == YYFINAL)
1344     YYACCEPT;
1345
1346   goto yybackup;
1347
1348 /*-----------.
1349 | yybackup.  |
1350 `-----------*/
1351 yybackup:
1352
1353   /* Do appropriate processing given the current state.  Read a
1354      lookahead token if we need one and don't already have one.  */
1355
1356   /* First try to decide what to do without reference to lookahead token.  */
1357   yyn = yypact[yystate];
1358   if (yypact_value_is_default (yyn))
1359     goto yydefault;
1360
1361   /* Not known => get a lookahead token if don't already have one.  */
1362
1363   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1364   if (yychar == YYEMPTY)
1365     {
1366       YYDPRINTF ((stderr, "Reading a token: "));
1367       yychar = YYLEX;
1368     }
1369
1370   if (yychar <= YYEOF)
1371     {
1372       yychar = yytoken = YYEOF;
1373       YYDPRINTF ((stderr, "Now at end of input.\n"));
1374     }
1375   else
1376     {
1377       yytoken = YYTRANSLATE (yychar);
1378       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1379     }
1380
1381   /* If the proper action on seeing token YYTOKEN is to reduce or to
1382      detect an error, take that action.  */
1383   yyn += yytoken;
1384   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1385     goto yydefault;
1386   yyn = yytable[yyn];
1387   if (yyn <= 0)
1388     {
1389       if (yytable_value_is_error (yyn))
1390         goto yyerrlab;
1391       yyn = -yyn;
1392       goto yyreduce;
1393     }
1394
1395   /* Count tokens shifted since error; after three, turn off error
1396      status.  */
1397   if (yyerrstatus)
1398     yyerrstatus--;
1399
1400   /* Shift the lookahead token.  */
1401   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1402
1403   /* Discard the shifted token.  */
1404   yychar = YYEMPTY;
1405
1406   yystate = yyn;
1407   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1408   *++yyvsp = yylval;
1409   YY_IGNORE_MAYBE_UNINITIALIZED_END
1410
1411   goto yynewstate;
1412
1413
1414 /*-----------------------------------------------------------.
1415 | yydefault -- do the default action for the current state.  |
1416 `-----------------------------------------------------------*/
1417 yydefault:
1418   yyn = yydefact[yystate];
1419   if (yyn == 0)
1420     goto yyerrlab;
1421   goto yyreduce;
1422
1423
1424 /*-----------------------------.
1425 | yyreduce -- Do a reduction.  |
1426 `-----------------------------*/
1427 yyreduce:
1428   /* yyn is the number of a rule to reduce with.  */
1429   yylen = yyr2[yyn];
1430
1431   /* If YYLEN is nonzero, implement the default value of the action:
1432      `$$ = $1'.
1433
1434      Otherwise, the following line sets YYVAL to garbage.
1435      This behavior is undocumented and Bison
1436      users should not rely upon it.  Assigning to YYVAL
1437      unconditionally makes the parser a bit smaller, and it avoids a
1438      GCC warning that YYVAL may be used uninitialized.  */
1439   yyval = yyvsp[1-yylen];
1440
1441
1442   YY_REDUCE_PRINT (yyn);
1443   switch (yyn)
1444     {
1445         case 4:
1446 /* Line 1792 of yacc.c  */
1447 #line 74 "slmod_rdf_parser.y"
1448     {
1449     srp_result = talloc_asprintf(srp_slq,
1450                                  "<rdfq:Condition>\n"
1451                                  "  <rdfq:and>\n"
1452                                  "    <rdfq:startsWith>\n"
1453                                  "      <rdfq:Property name=\"File:Path\" />\n"
1454                                  "      <rdf:String>%s</rdf:String>\n"
1455                                  "    </rdfq:startsWith>\n"
1456                                  "    %s\n"
1457                                  "  </rdfq:and>\n"
1458                                  "</rdfq:Condition>\n",
1459                                  srp_slq->slq_vol->v_path, (yyvsp[(1) - (1)].sval));
1460     (yyval.sval) = srp_result;
1461 }
1462     break;
1463
1464   case 5:
1465 /* Line 1792 of yacc.c  */
1466 #line 91 "slmod_rdf_parser.y"
1467     {
1468     if ((yyvsp[(1) - (1)].bval) == false)
1469         YYACCEPT;
1470     else
1471         YYABORT;
1472 }
1473     break;
1474
1475   case 6:
1476 /* Line 1792 of yacc.c  */
1477 #line 97 "slmod_rdf_parser.y"
1478     {(yyval.sval) = (yyvsp[(1) - (1)].sval); if ((yyval.sval) == NULL) YYABORT;}
1479     break;
1480
1481   case 7:
1482 /* Line 1792 of yacc.c  */
1483 #line 98 "slmod_rdf_parser.y"
1484     {(yyval.sval) = (yyvsp[(1) - (1)].sval);}
1485     break;
1486
1487   case 8:
1488 /* Line 1792 of yacc.c  */
1489 #line 99 "slmod_rdf_parser.y"
1490     {(yyval.sval) = talloc_asprintf(srp_slq, "%s\n", (yyvsp[(2) - (3)].sval));}
1491     break;
1492
1493   case 9:
1494 /* Line 1792 of yacc.c  */
1495 #line 100 "slmod_rdf_parser.y"
1496     {(yyval.sval) = talloc_asprintf(srp_slq, "<rdfq:and>\n%s\n%s\n</rdfq:and>\n", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));}
1497     break;
1498
1499   case 10:
1500 /* Line 1792 of yacc.c  */
1501 #line 101 "slmod_rdf_parser.y"
1502     {
1503     if (strcmp((yyvsp[(1) - (3)].sval), "") == 0 || strcmp((yyvsp[(3) - (3)].sval), "") == 0) {
1504         /*
1505          * The default Spotlight search term issued by the Finder (10.8) is:
1506          * '* == "searchterm" || kMDItemTextContent == "searchterm"'
1507          * As it isn't mappable to a single Tracker RDF query, we silently
1508          * map ANY FTS query expression being part of an OR compound
1509          * expression to a simple filename search.
1510          * FTS queries are thus only possible by explicitly requesting
1511          * file content FTS search in the Finder on the client (resulting
1512          * in a 'kMDItemTextContent == "searchterm"' query).
1513          */
1514         if (strcmp((yyvsp[(1) - (3)].sval), "") == 0)
1515             (yyval.sval) = talloc_asprintf(srp_slq, (yyvsp[(3) - (3)].sval));
1516         else
1517             (yyval.sval) = talloc_asprintf(srp_slq, (yyvsp[(1) - (3)].sval));
1518         talloc_free(srp_fts);
1519         srp_fts = NULL;
1520     } else {
1521         (yyval.sval) = talloc_asprintf(srp_slq, "<rdfq:or>\n%s\n%s\n</rdfq:or>\n", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1522     }
1523 }
1524     break;
1525
1526   case 11:
1527 /* Line 1792 of yacc.c  */
1528 #line 126 "slmod_rdf_parser.y"
1529     {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '=', (yyvsp[(4) - (5)].sval));}
1530     break;
1531
1532   case 12:
1533 /* Line 1792 of yacc.c  */
1534 #line 127 "slmod_rdf_parser.y"
1535     {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '!', (yyvsp[(4) - (5)].sval));}
1536     break;
1537
1538   case 13:
1539 /* Line 1792 of yacc.c  */
1540 #line 128 "slmod_rdf_parser.y"
1541     {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '<', (yyvsp[(4) - (5)].sval));}
1542     break;
1543
1544   case 14:
1545 /* Line 1792 of yacc.c  */
1546 #line 129 "slmod_rdf_parser.y"
1547     {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '>', (yyvsp[(4) - (5)].sval));}
1548     break;
1549
1550   case 15:
1551 /* Line 1792 of yacc.c  */
1552 #line 130 "slmod_rdf_parser.y"
1553     {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '=', (yyvsp[(4) - (6)].sval));}
1554     break;
1555
1556   case 16:
1557 /* Line 1792 of yacc.c  */
1558 #line 131 "slmod_rdf_parser.y"
1559     {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '!', (yyvsp[(4) - (6)].sval));}
1560     break;
1561
1562   case 17:
1563 /* Line 1792 of yacc.c  */
1564 #line 132 "slmod_rdf_parser.y"
1565     {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '<', (yyvsp[(4) - (6)].sval));}
1566     break;
1567
1568   case 18:
1569 /* Line 1792 of yacc.c  */
1570 #line 133 "slmod_rdf_parser.y"
1571     {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '>', (yyvsp[(4) - (6)].sval));}
1572     break;
1573
1574   case 19:
1575 /* Line 1792 of yacc.c  */
1576 #line 137 "slmod_rdf_parser.y"
1577     {(yyval.sval) = map_daterange((yyvsp[(3) - (8)].sval), (yyvsp[(5) - (8)].tval), (yyvsp[(7) - (8)].tval));}
1578     break;
1579
1580   case 20:
1581 /* Line 1792 of yacc.c  */
1582 #line 141 "slmod_rdf_parser.y"
1583     {(yyval.tval) = isodate2unix((yyvsp[(3) - (4)].sval));}
1584     break;
1585
1586   case 21:
1587 /* Line 1792 of yacc.c  */
1588 #line 142 "slmod_rdf_parser.y"
1589     {(yyval.tval) = atoi((yyvsp[(1) - (1)].sval)) + SPRAW_TIME_OFFSET;}
1590     break;
1591
1592
1593 /* Line 1792 of yacc.c  */
1594 #line 1595 "slmod_rdf_parser.c"
1595       default: break;
1596     }
1597   /* User semantic actions sometimes alter yychar, and that requires
1598      that yytoken be updated with the new translation.  We take the
1599      approach of translating immediately before every use of yytoken.
1600      One alternative is translating here after every semantic action,
1601      but that translation would be missed if the semantic action invokes
1602      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1603      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
1604      incorrect destructor might then be invoked immediately.  In the
1605      case of YYERROR or YYBACKUP, subsequent parser actions might lead
1606      to an incorrect destructor call or verbose syntax error message
1607      before the lookahead is translated.  */
1608   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1609
1610   YYPOPSTACK (yylen);
1611   yylen = 0;
1612   YY_STACK_PRINT (yyss, yyssp);
1613
1614   *++yyvsp = yyval;
1615
1616   /* Now `shift' the result of the reduction.  Determine what state
1617      that goes to, based on the state we popped back to and the rule
1618      number reduced by.  */
1619
1620   yyn = yyr1[yyn];
1621
1622   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1623   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1624     yystate = yytable[yystate];
1625   else
1626     yystate = yydefgoto[yyn - YYNTOKENS];
1627
1628   goto yynewstate;
1629
1630
1631 /*------------------------------------.
1632 | yyerrlab -- here on detecting error |
1633 `------------------------------------*/
1634 yyerrlab:
1635   /* Make sure we have latest lookahead translation.  See comments at
1636      user semantic actions for why this is necessary.  */
1637   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1638
1639   /* If not already recovering from an error, report this error.  */
1640   if (!yyerrstatus)
1641     {
1642       ++yynerrs;
1643 #if ! YYERROR_VERBOSE
1644       yyerror (YY_("syntax error"));
1645 #else
1646 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1647                                         yyssp, yytoken)
1648       {
1649         char const *yymsgp = YY_("syntax error");
1650         int yysyntax_error_status;
1651         yysyntax_error_status = YYSYNTAX_ERROR;
1652         if (yysyntax_error_status == 0)
1653           yymsgp = yymsg;
1654         else if (yysyntax_error_status == 1)
1655           {
1656             if (yymsg != yymsgbuf)
1657               YYSTACK_FREE (yymsg);
1658             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1659             if (!yymsg)
1660               {
1661                 yymsg = yymsgbuf;
1662                 yymsg_alloc = sizeof yymsgbuf;
1663                 yysyntax_error_status = 2;
1664               }
1665             else
1666               {
1667                 yysyntax_error_status = YYSYNTAX_ERROR;
1668                 yymsgp = yymsg;
1669               }
1670           }
1671         yyerror (yymsgp);
1672         if (yysyntax_error_status == 2)
1673           goto yyexhaustedlab;
1674       }
1675 # undef YYSYNTAX_ERROR
1676 #endif
1677     }
1678
1679
1680
1681   if (yyerrstatus == 3)
1682     {
1683       /* If just tried and failed to reuse lookahead token after an
1684          error, discard it.  */
1685
1686       if (yychar <= YYEOF)
1687         {
1688           /* Return failure if at end of input.  */
1689           if (yychar == YYEOF)
1690             YYABORT;
1691         }
1692       else
1693         {
1694           yydestruct ("Error: discarding",
1695                       yytoken, &yylval);
1696           yychar = YYEMPTY;
1697         }
1698     }
1699
1700   /* Else will try to reuse lookahead token after shifting the error
1701      token.  */
1702   goto yyerrlab1;
1703
1704
1705 /*---------------------------------------------------.
1706 | yyerrorlab -- error raised explicitly by YYERROR.  |
1707 `---------------------------------------------------*/
1708 yyerrorlab:
1709
1710   /* Pacify compilers like GCC when the user code never invokes
1711      YYERROR and the label yyerrorlab therefore never appears in user
1712      code.  */
1713   if (/*CONSTCOND*/ 0)
1714      goto yyerrorlab;
1715
1716   /* Do not reclaim the symbols of the rule which action triggered
1717      this YYERROR.  */
1718   YYPOPSTACK (yylen);
1719   yylen = 0;
1720   YY_STACK_PRINT (yyss, yyssp);
1721   yystate = *yyssp;
1722   goto yyerrlab1;
1723
1724
1725 /*-------------------------------------------------------------.
1726 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1727 `-------------------------------------------------------------*/
1728 yyerrlab1:
1729   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1730
1731   for (;;)
1732     {
1733       yyn = yypact[yystate];
1734       if (!yypact_value_is_default (yyn))
1735         {
1736           yyn += YYTERROR;
1737           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1738             {
1739               yyn = yytable[yyn];
1740               if (0 < yyn)
1741                 break;
1742             }
1743         }
1744
1745       /* Pop the current state because it cannot handle the error token.  */
1746       if (yyssp == yyss)
1747         YYABORT;
1748
1749
1750       yydestruct ("Error: popping",
1751                   yystos[yystate], yyvsp);
1752       YYPOPSTACK (1);
1753       yystate = *yyssp;
1754       YY_STACK_PRINT (yyss, yyssp);
1755     }
1756
1757   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1758   *++yyvsp = yylval;
1759   YY_IGNORE_MAYBE_UNINITIALIZED_END
1760
1761
1762   /* Shift the error token.  */
1763   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1764
1765   yystate = yyn;
1766   goto yynewstate;
1767
1768
1769 /*-------------------------------------.
1770 | yyacceptlab -- YYACCEPT comes here.  |
1771 `-------------------------------------*/
1772 yyacceptlab:
1773   yyresult = 0;
1774   goto yyreturn;
1775
1776 /*-----------------------------------.
1777 | yyabortlab -- YYABORT comes here.  |
1778 `-----------------------------------*/
1779 yyabortlab:
1780   yyresult = 1;
1781   goto yyreturn;
1782
1783 #if !defined yyoverflow || YYERROR_VERBOSE
1784 /*-------------------------------------------------.
1785 | yyexhaustedlab -- memory exhaustion comes here.  |
1786 `-------------------------------------------------*/
1787 yyexhaustedlab:
1788   yyerror (YY_("memory exhausted"));
1789   yyresult = 2;
1790   /* Fall through.  */
1791 #endif
1792
1793 yyreturn:
1794   if (yychar != YYEMPTY)
1795     {
1796       /* Make sure we have latest lookahead translation.  See comments at
1797          user semantic actions for why this is necessary.  */
1798       yytoken = YYTRANSLATE (yychar);
1799       yydestruct ("Cleanup: discarding lookahead",
1800                   yytoken, &yylval);
1801     }
1802   /* Do not reclaim the symbols of the rule which action triggered
1803      this YYABORT or YYACCEPT.  */
1804   YYPOPSTACK (yylen);
1805   YY_STACK_PRINT (yyss, yyssp);
1806   while (yyssp != yyss)
1807     {
1808       yydestruct ("Cleanup: popping",
1809                   yystos[*yyssp], yyvsp);
1810       YYPOPSTACK (1);
1811     }
1812 #ifndef yyoverflow
1813   if (yyss != yyssa)
1814     YYSTACK_FREE (yyss);
1815 #endif
1816 #if YYERROR_VERBOSE
1817   if (yymsg != yymsgbuf)
1818     YYSTACK_FREE (yymsg);
1819 #endif
1820   /* Make sure YYID is used.  */
1821   return YYID (yyresult);
1822 }
1823
1824
1825 /* Line 2055 of yacc.c  */
1826 #line 145 "slmod_rdf_parser.y"
1827
1828
1829 static time_t isodate2unix(const char *s)
1830 {
1831     struct tm tm;
1832
1833     if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL)
1834         return (time_t)-1;
1835     return mktime(&tm);
1836 }
1837
1838 static const char *map_daterange(const char *dateattr, time_t date1, time_t date2)
1839 {
1840     EC_INIT;
1841     char *result = NULL;
1842     struct spotlight_rdf_map *p;
1843     struct tm *tmp;
1844     char buf1[64], buf2[64];
1845
1846     EC_NULL_LOG( tmp = localtime(&date1) );
1847     strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1848     EC_NULL_LOG( tmp = localtime(&date2) );
1849     strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp);
1850
1851     for (p = spotlight_rdf_map; p->srm_spotlight_attr; p++) {
1852         if (strcmp(dateattr, p->srm_spotlight_attr) == 0) {
1853                 result = talloc_asprintf(srp_slq,
1854                                          "<rdfq:and>\n"
1855                                          "  <rdfq:greaterThan>\n"
1856                                          "    <rdfq:Property name=\"%s\" />\n"
1857                                          "    <rdf:Date>%s</rdf:Date>\n"
1858                                          "  </rdfq:greaterThan>\n"
1859                                          "  <rdfq:lessThan>\n"
1860                                          "    <rdfq:Property name=\"%s\" />\n"
1861                                          "    <rdf:Date>%s</rdf:Date>\n"
1862                                          "  </rdfq:lessThan>\n"
1863                                          "</rdfq:and>\n",
1864                                          p->srm_rdf_attr, buf1,
1865                                          p->srm_rdf_attr, buf2);
1866             break;
1867         }
1868     }
1869
1870 EC_CLEANUP:
1871     if (ret != 0)
1872         return NULL;
1873     return result;
1874 }
1875
1876 static char *map_type_search(const char *attr, char op, const char *val)
1877 {
1878     char *result = NULL;
1879
1880     for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) {
1881         if (strcmp(p->mdtm_value, val) == 0) {
1882             if (!p->mdtm_type)
1883                 return NULL;
1884             if (val[0] == '9') {
1885                 srp_slq->slq_service = SERVICE_FOLDERS;
1886                 return "";
1887             }
1888             result = talloc_asprintf(srp_slq,
1889                                      "<rdfq:%s>\n"
1890                                      "  <rdfq:Property name=\"File:Mime\" />\n"
1891                                      "  <rdf:String>%s</rdf:String>\n"
1892                                      "</rdfq:%s>\n",
1893                                      p->mdtm_rdfop,
1894                                      p->mdtm_type,
1895                                      p->mdtm_rdfop);
1896             break;
1897         }
1898     }
1899     return result;
1900 }
1901
1902 static const char *map_expr(const char *attr, char op, const char *val)
1903 {
1904     EC_INIT;
1905     char *result = NULL;
1906     struct spotlight_rdf_map *p;
1907     time_t t;
1908     struct tm *tmp;
1909     char buf1[64];
1910     bstring q = NULL, search = NULL, replace = NULL;
1911     char *rdfop;
1912
1913     for (p = spotlight_rdf_map; p->srm_spotlight_attr; p++) {
1914         if (p->srm_rdf_attr && strcmp(p->srm_spotlight_attr, attr) == 0) {
1915             switch (p->srm_type) {
1916             case srmt_num:
1917                 q = bformat("^%s$", val);
1918                 search = bfromcstr("*");
1919                 replace = bfromcstr(".*");
1920                 bfindreplace(q, search, replace, 0);
1921                 result = talloc_asprintf(srp_slq,
1922                                          "<rdfq:regex>\n"
1923                                          "  <rdfq:Property name=\"%s\" />\n"
1924                                          "  <rdf:String>%s</rdf:String>\n"
1925                                          "</rdfq:regex>\n",
1926                                          p->srm_rdf_attr,
1927                                          bdata(q));
1928                 bdestroy(q);
1929                 break;
1930
1931             case srmt_str:
1932                 q = bformat("^%s$", val);
1933                 search = bfromcstr("*");
1934                 replace = bfromcstr(".*");
1935                 bfindreplace(q, search, replace, 0);
1936                 result = talloc_asprintf(srp_slq,
1937                                          "<rdfq:regex>\n"
1938                                          "  <rdfq:Property name=\"%s\" />\n"
1939                                          "  <rdf:String>%s</rdf:String>\n"
1940                                          "</rdfq:regex>\n",
1941                                          p->srm_rdf_attr,
1942                                          bdata(q));
1943                 bdestroy(q);
1944                 break;
1945
1946             case srmt_fts:
1947                 if (srp_fts) {
1948                     yyerror("only single fts query allowed");
1949                     EC_FAIL;
1950                 }
1951                 q = bfromcstr(val);
1952                 search = bfromcstr("*");
1953                 replace = bfromcstr("");
1954                 bfindreplace(q, search, replace, 0);
1955                 srp_fts = talloc_strdup(srp_slq, bdata(q));
1956                 result = "";
1957                 break;
1958
1959             case srmt_date:
1960                 t = atoi(val) + SPRAW_TIME_OFFSET;
1961                 EC_NULL( tmp = localtime(&t) );
1962                 strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1963
1964                 switch (op) {
1965                 case '=':
1966                     rdfop = "equals";
1967                 case '<':
1968                     rdfop = "lessThan";
1969                 case '>':
1970                     rdfop = "greaterThan";
1971                 default:
1972                     yyerror("unknown date comparison");
1973                     EC_FAIL;
1974                 }
1975                 result = talloc_asprintf(srp_slq,
1976                                          "<rdfq:%s>\n"
1977                                          "  <rdfq:Property name=\"%s\" />\n"
1978                                          "  <rdf:Date>%s</rdf:Date>\n"
1979                                          "</rdfq:%s>\n",
1980                                          rdfop,
1981                                          p->srm_rdf_attr,
1982                                          buf1,
1983                                          rdfop);
1984
1985                 break;
1986
1987             case srmt_type:
1988                 result = map_type_search(attr, op, val);
1989                 break;
1990
1991             default:
1992                 yyerror("unknown Spotlight attribute type");
1993                 EC_FAIL;
1994             }
1995             break;
1996         }
1997     }
1998
1999 EC_CLEANUP:
2000     if (q)
2001         bdestroy(q);
2002     if (search)
2003         bdestroy(search);
2004     if (replace)
2005         bdestroy(replace);
2006     return result;
2007 }
2008
2009 void yyerror(const char *str)
2010 {
2011 #ifdef MAIN
2012     printf("yyerror: %s\n", str);
2013 #else
2014     LOG(log_error, logtype_sl, "yyerror: %s", str);
2015 #endif
2016 }
2017  
2018 int yywrap()
2019 {
2020     return 1;
2021
2022
2023 /**
2024  * Map a Spotlight RAW query string to a RDF query
2025  *
2026  * @param[in]     slq            Spotlight query handle
2027  * @return        0 on success, -1 on error
2028  **/
2029 int map_spotlight_to_rdf_query(slq_t *slq)
2030 {
2031     EC_INIT;
2032     YY_BUFFER_STATE s = NULL;
2033     srp_result = NULL;
2034     srp_fts = NULL;
2035     slq->slq_service = SERVICE_FILES;
2036     srp_slq = slq;
2037     s = yy_scan_string(slq->slq_qstring);
2038
2039     EC_ZERO( yyparse() );
2040
2041 EC_CLEANUP:
2042     if (s)
2043         yy_delete_buffer(s);
2044     if (ret == 0) {
2045         slq->slq_trackerquery = srp_result;
2046         slq->slq_fts = srp_fts;
2047     }
2048     EC_EXIT;
2049 }
2050
2051 #ifdef MAIN
2052 int main(int argc, char **argv)
2053 {
2054     int ret;
2055     YY_BUFFER_STATE s;
2056
2057     if (argc != 2) {
2058         printf("usage: %s QUERY\n", argv[0]);
2059         return 1;
2060     }
2061
2062     srp_slq = talloc_zero(NULL, slq_t);
2063     struct vol *vol = talloc_zero(srp_slq, struct vol);
2064     vol->v_path = "/Volumes/test";
2065     srp_slq->slq_vol = vol;
2066
2067     s = yy_scan_string(argv[1]);
2068
2069     ret = yyparse();
2070
2071     yy_delete_buffer(s);
2072
2073     if (ret == 0)
2074         printf("RDF:\n%s\nFTS: %s\n",
2075                srp_result ? srp_result : "(empty)",
2076                srp_fts ? srp_fts : "(none)");
2077     return 0;
2078
2079 #endif