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