]> arthur.barton.de Git - netatalk.git/blob - etc/spotlight/sparql_parser.c
Spotlight: use async Tracker SPARQL API
[netatalk.git] / etc / spotlight / sparql_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 "sparql_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 "sparql_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 *ssp_slq;
99
100   /* local vars */
101   static gchar *ssp_result;
102   static char sparqlvar;
103   static char *result_limit;
104
105 /* Line 371 of yacc.c  */
106 #line 107 "sparql_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_SPARQL_PARSER_H_INCLUDED
127 # define YY_YY_SPARQL_PARSER_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 "sparql_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 "sparql_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 "sparql_parser.y"
214
215   #define SPRAW_TIME_OFFSET 978307200
216   extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result);
217   extern slq_t *ssp_slq;
218
219
220 /* Line 387 of yacc.c  */
221 #line 222 "sparql_parser.c"
222
223 #endif /* !YY_YY_SPARQL_PARSER_H_INCLUDED  */
224
225 /* Copy the second part of user declarations.  */
226
227 /* Line 390 of yacc.c  */
228 #line 229 "sparql_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   52
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  22
456 /* YYNRULES -- Number of states.  */
457 #define YYNSTATES  51
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,    15,    17,    19,
505       23,    27,    31,    37,    43,    49,    55,    62,    69,    76,
506       83,    92,    97
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,    16,    21,    -1,    21,    -1,    22,    -1,     7,
514       20,     8,    -1,    20,    15,    20,    -1,    20,    16,    20,
515       -1,     3,     9,    14,     3,    14,    -1,     3,    10,    14,
516        3,    14,    -1,     3,    12,    14,     3,    14,    -1,     3,
517       11,    14,     3,    14,    -1,     3,     9,    14,     3,    14,
518        3,    -1,     3,    10,    14,     3,    14,     3,    -1,     3,
519       12,    14,     3,    14,     3,    -1,     3,    11,    14,     3,
520       14,     3,    -1,     5,     7,     3,    13,    23,    13,    23,
521        8,    -1,     6,     7,     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,    88,    99,   107,   108,   109,
528      110,   117,   130,   131,   132,   133,   134,   135,   136,   137,
529      141,   145,   146
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,    20,    21,    21,    21,    21,    21,    21,    21,    21,
560       22,    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,     3,     1,     1,     3,
567        3,     3,     5,     5,     5,     5,     6,     6,     6,     6,
568        8,     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,     7,
577        8,     0,     0,     0,     0,     0,     0,     0,     0,     0,
578        0,     0,     0,     0,     0,     9,    10,    11,     6,     0,
579        0,     0,     0,     0,    12,    13,    15,    14,    22,     0,
580        0,    16,    17,    19,    18,     0,     0,     0,     0,    21,
581       20
582 };
583
584 /* YYDEFGOTO[NTERM-NUM].  */
585 static const yytype_int8 yydefgoto[] =
586 {
587       -1,     1,     7,     8,     9,    10,    40
588 };
589
590 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
591    STATE-NUM.  */
592 #define YYPACT_NINF -10
593 static const yytype_int8 yypact[] =
594 {
595      -10,    10,   -10,     9,   -10,    -2,    -1,   -10,     8,    -9,
596      -10,     2,    12,    13,    14,    26,    -7,    -1,    -1,    27,
597       28,    29,    30,    31,    22,   -10,    20,   -10,   -10,    23,
598       24,    25,    32,    19,    37,    38,    39,    40,   -10,    41,
599       34,   -10,   -10,   -10,   -10,    42,    19,    36,    43,   -10,
600      -10
601 };
602
603 /* YYPGOTO[NTERM-NUM].  */
604 static const yytype_int8 yypgoto[] =
605 {
606      -10,   -10,   -10,    -6,    33,   -10,     3
607 };
608
609 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
610    positive, shift that token.  If negative, reduce the rule which
611    number is the opposite.  If YYTABLE_NINF, syntax error.  */
612 #define YYTABLE_NINF -1
613 static const yytype_uint8 yytable[] =
614 {
615       16,    25,     3,     4,     5,    15,     6,    19,    17,    18,
616        2,    26,    27,     3,     4,     5,    20,     6,    11,    12,
617       13,    14,    38,    17,    18,    39,    21,    22,    23,    24,
618        3,    29,    30,    31,    32,    33,    18,    34,    35,    36,
619       41,    42,    43,    44,    49,    47,    37,    46,    45,    48,
620        0,    50,    28
621 };
622
623 #define yypact_value_is_default(Yystate) \
624   (!!((Yystate) == (-10)))
625
626 #define yytable_value_is_error(Yytable_value) \
627   YYID (0)
628
629 static const yytype_int8 yycheck[] =
630 {
631        6,     8,     3,     4,     5,     7,     7,    16,    15,    16,
632        0,    17,    18,     3,     4,     5,    14,     7,     9,    10,
633       11,    12,     3,    15,    16,     6,    14,    14,    14,     3,
634        3,     3,     3,     3,     3,    13,    16,    14,    14,    14,
635        3,     3,     3,     3,     8,     3,    14,    13,     7,    46,
636       -1,     8,    19
637 };
638
639 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
640    symbol of state STATE-NUM.  */
641 static const yytype_uint8 yystos[] =
642 {
643        0,    18,     0,     3,     4,     5,     7,    19,    20,    21,
644       22,     9,    10,    11,    12,     7,    20,    15,    16,    16,
645       14,    14,    14,    14,     3,     8,    20,    20,    21,     3,
646        3,     3,     3,    13,    14,    14,    14,    14,     3,     6,
647       23,     3,     3,     3,     3,     7,    13,     3,    23,     8,
648        8
649 };
650
651 #define yyerrok         (yyerrstatus = 0)
652 #define yyclearin       (yychar = YYEMPTY)
653 #define YYEMPTY         (-2)
654 #define YYEOF           0
655
656 #define YYACCEPT        goto yyacceptlab
657 #define YYABORT         goto yyabortlab
658 #define YYERROR         goto yyerrorlab
659
660
661 /* Like YYERROR except do call yyerror.  This remains here temporarily
662    to ease the transition to the new meaning of YYERROR, for GCC.
663    Once GCC version 2 has supplanted version 1, this can go.  However,
664    YYFAIL appears to be in use.  Nevertheless, it is formally deprecated
665    in Bison 2.4.2's NEWS entry, where a plan to phase it out is
666    discussed.  */
667
668 #define YYFAIL          goto yyerrlab
669 #if defined YYFAIL
670   /* This is here to suppress warnings from the GCC cpp's
671      -Wunused-macros.  Normally we don't worry about that warning, but
672      some users do, and we want to make it easy for users to remove
673      YYFAIL uses, which will produce warnings from Bison 2.5.  */
674 #endif
675
676 #define YYRECOVERING()  (!!yyerrstatus)
677
678 #define YYBACKUP(Token, Value)                                  \
679 do                                                              \
680   if (yychar == YYEMPTY)                                        \
681     {                                                           \
682       yychar = (Token);                                         \
683       yylval = (Value);                                         \
684       YYPOPSTACK (yylen);                                       \
685       yystate = *yyssp;                                         \
686       goto yybackup;                                            \
687     }                                                           \
688   else                                                          \
689     {                                                           \
690       yyerror (YY_("syntax error: cannot back up")); \
691       YYERROR;                                                  \
692     }                                                           \
693 while (YYID (0))
694
695 /* Error token number */
696 #define YYTERROR        1
697 #define YYERRCODE       256
698
699
700 /* This macro is provided for backward compatibility. */
701 #ifndef YY_LOCATION_PRINT
702 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
703 #endif
704
705
706 /* YYLEX -- calling `yylex' with the right arguments.  */
707 #ifdef YYLEX_PARAM
708 # define YYLEX yylex (YYLEX_PARAM)
709 #else
710 # define YYLEX yylex ()
711 #endif
712
713 /* Enable debugging if requested.  */
714 #if YYDEBUG
715
716 # ifndef YYFPRINTF
717 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
718 #  define YYFPRINTF fprintf
719 # endif
720
721 # define YYDPRINTF(Args)                        \
722 do {                                            \
723   if (yydebug)                                  \
724     YYFPRINTF Args;                             \
725 } while (YYID (0))
726
727 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)                    \
728 do {                                                                      \
729   if (yydebug)                                                            \
730     {                                                                     \
731       YYFPRINTF (stderr, "%s ", Title);                                   \
732       yy_symbol_print (stderr,                                            \
733                   Type, Value); \
734       YYFPRINTF (stderr, "\n");                                           \
735     }                                                                     \
736 } while (YYID (0))
737
738
739 /*--------------------------------.
740 | Print this symbol on YYOUTPUT.  |
741 `--------------------------------*/
742
743 /*ARGSUSED*/
744 #if (defined __STDC__ || defined __C99__FUNC__ \
745      || defined __cplusplus || defined _MSC_VER)
746 static void
747 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
748 #else
749 static void
750 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
751     FILE *yyoutput;
752     int yytype;
753     YYSTYPE const * const yyvaluep;
754 #endif
755 {
756   FILE *yyo = yyoutput;
757   YYUSE (yyo);
758   if (!yyvaluep)
759     return;
760 # ifdef YYPRINT
761   if (yytype < YYNTOKENS)
762     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
763 # else
764   YYUSE (yyoutput);
765 # endif
766   switch (yytype)
767     {
768       default:
769         break;
770     }
771 }
772
773
774 /*--------------------------------.
775 | Print this symbol on YYOUTPUT.  |
776 `--------------------------------*/
777
778 #if (defined __STDC__ || defined __C99__FUNC__ \
779      || defined __cplusplus || defined _MSC_VER)
780 static void
781 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
782 #else
783 static void
784 yy_symbol_print (yyoutput, yytype, yyvaluep)
785     FILE *yyoutput;
786     int yytype;
787     YYSTYPE const * const yyvaluep;
788 #endif
789 {
790   if (yytype < YYNTOKENS)
791     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
792   else
793     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
794
795   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
796   YYFPRINTF (yyoutput, ")");
797 }
798
799 /*------------------------------------------------------------------.
800 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
801 | TOP (included).                                                   |
802 `------------------------------------------------------------------*/
803
804 #if (defined __STDC__ || defined __C99__FUNC__ \
805      || defined __cplusplus || defined _MSC_VER)
806 static void
807 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
808 #else
809 static void
810 yy_stack_print (yybottom, yytop)
811     yytype_int16 *yybottom;
812     yytype_int16 *yytop;
813 #endif
814 {
815   YYFPRINTF (stderr, "Stack now");
816   for (; yybottom <= yytop; yybottom++)
817     {
818       int yybot = *yybottom;
819       YYFPRINTF (stderr, " %d", yybot);
820     }
821   YYFPRINTF (stderr, "\n");
822 }
823
824 # define YY_STACK_PRINT(Bottom, Top)                            \
825 do {                                                            \
826   if (yydebug)                                                  \
827     yy_stack_print ((Bottom), (Top));                           \
828 } while (YYID (0))
829
830
831 /*------------------------------------------------.
832 | Report that the YYRULE is going to be reduced.  |
833 `------------------------------------------------*/
834
835 #if (defined __STDC__ || defined __C99__FUNC__ \
836      || defined __cplusplus || defined _MSC_VER)
837 static void
838 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
839 #else
840 static void
841 yy_reduce_print (yyvsp, yyrule)
842     YYSTYPE *yyvsp;
843     int yyrule;
844 #endif
845 {
846   int yynrhs = yyr2[yyrule];
847   int yyi;
848   unsigned long int yylno = yyrline[yyrule];
849   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
850              yyrule - 1, yylno);
851   /* The symbols being reduced.  */
852   for (yyi = 0; yyi < yynrhs; yyi++)
853     {
854       YYFPRINTF (stderr, "   $%d = ", yyi + 1);
855       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
856                        &(yyvsp[(yyi + 1) - (yynrhs)])
857                                        );
858       YYFPRINTF (stderr, "\n");
859     }
860 }
861
862 # define YY_REDUCE_PRINT(Rule)          \
863 do {                                    \
864   if (yydebug)                          \
865     yy_reduce_print (yyvsp, Rule); \
866 } while (YYID (0))
867
868 /* Nonzero means print parse trace.  It is left uninitialized so that
869    multiple parsers can coexist.  */
870 int yydebug;
871 #else /* !YYDEBUG */
872 # define YYDPRINTF(Args)
873 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
874 # define YY_STACK_PRINT(Bottom, Top)
875 # define YY_REDUCE_PRINT(Rule)
876 #endif /* !YYDEBUG */
877
878
879 /* YYINITDEPTH -- initial size of the parser's stacks.  */
880 #ifndef YYINITDEPTH
881 # define YYINITDEPTH 200
882 #endif
883
884 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
885    if the built-in stack extension method is used).
886
887    Do not make this value too large; the results are undefined if
888    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
889    evaluated with infinite-precision integer arithmetic.  */
890
891 #ifndef YYMAXDEPTH
892 # define YYMAXDEPTH 10000
893 #endif
894
895
896 #if YYERROR_VERBOSE
897
898 # ifndef yystrlen
899 #  if defined __GLIBC__ && defined _STRING_H
900 #   define yystrlen strlen
901 #  else
902 /* Return the length of YYSTR.  */
903 #if (defined __STDC__ || defined __C99__FUNC__ \
904      || defined __cplusplus || defined _MSC_VER)
905 static YYSIZE_T
906 yystrlen (const char *yystr)
907 #else
908 static YYSIZE_T
909 yystrlen (yystr)
910     const char *yystr;
911 #endif
912 {
913   YYSIZE_T yylen;
914   for (yylen = 0; yystr[yylen]; yylen++)
915     continue;
916   return yylen;
917 }
918 #  endif
919 # endif
920
921 # ifndef yystpcpy
922 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
923 #   define yystpcpy stpcpy
924 #  else
925 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
926    YYDEST.  */
927 #if (defined __STDC__ || defined __C99__FUNC__ \
928      || defined __cplusplus || defined _MSC_VER)
929 static char *
930 yystpcpy (char *yydest, const char *yysrc)
931 #else
932 static char *
933 yystpcpy (yydest, yysrc)
934     char *yydest;
935     const char *yysrc;
936 #endif
937 {
938   char *yyd = yydest;
939   const char *yys = yysrc;
940
941   while ((*yyd++ = *yys++) != '\0')
942     continue;
943
944   return yyd - 1;
945 }
946 #  endif
947 # endif
948
949 # ifndef yytnamerr
950 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
951    quotes and backslashes, so that it's suitable for yyerror.  The
952    heuristic is that double-quoting is unnecessary unless the string
953    contains an apostrophe, a comma, or backslash (other than
954    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
955    null, do not copy; instead, return the length of what the result
956    would have been.  */
957 static YYSIZE_T
958 yytnamerr (char *yyres, const char *yystr)
959 {
960   if (*yystr == '"')
961     {
962       YYSIZE_T yyn = 0;
963       char const *yyp = yystr;
964
965       for (;;)
966         switch (*++yyp)
967           {
968           case '\'':
969           case ',':
970             goto do_not_strip_quotes;
971
972           case '\\':
973             if (*++yyp != '\\')
974               goto do_not_strip_quotes;
975             /* Fall through.  */
976           default:
977             if (yyres)
978               yyres[yyn] = *yyp;
979             yyn++;
980             break;
981
982           case '"':
983             if (yyres)
984               yyres[yyn] = '\0';
985             return yyn;
986           }
987     do_not_strip_quotes: ;
988     }
989
990   if (! yyres)
991     return yystrlen (yystr);
992
993   return yystpcpy (yyres, yystr) - yyres;
994 }
995 # endif
996
997 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
998    about the unexpected token YYTOKEN for the state stack whose top is
999    YYSSP.
1000
1001    Return 0 if *YYMSG was successfully written.  Return 1 if *YYMSG is
1002    not large enough to hold the message.  In that case, also set
1003    *YYMSG_ALLOC to the required number of bytes.  Return 2 if the
1004    required number of bytes is too large to store.  */
1005 static int
1006 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1007                 yytype_int16 *yyssp, int yytoken)
1008 {
1009   YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
1010   YYSIZE_T yysize = yysize0;
1011   enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1012   /* Internationalized format string. */
1013   const char *yyformat = YY_NULL;
1014   /* Arguments of yyformat. */
1015   char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1016   /* Number of reported tokens (one for the "unexpected", one per
1017      "expected"). */
1018   int yycount = 0;
1019
1020   /* There are many possibilities here to consider:
1021      - Assume YYFAIL is not used.  It's too flawed to consider.  See
1022        <http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html>
1023        for details.  YYERROR is fine as it does not invoke this
1024        function.
1025      - If this state is a consistent state with a default action, then
1026        the only way this function was invoked is if the default action
1027        is an error action.  In that case, don't check for expected
1028        tokens because there are none.
1029      - The only way there can be no lookahead present (in yychar) is if
1030        this state is a consistent state with a default action.  Thus,
1031        detecting the absence of a lookahead is sufficient to determine
1032        that there is no unexpected or expected token to report.  In that
1033        case, just report a simple "syntax error".
1034      - Don't assume there isn't a lookahead just because this state is a
1035        consistent state with a default action.  There might have been a
1036        previous inconsistent state, consistent state with a non-default
1037        action, or user semantic action that manipulated yychar.
1038      - Of course, the expected token list depends on states to have
1039        correct lookahead information, and it depends on the parser not
1040        to perform extra reductions after fetching a lookahead from the
1041        scanner and before detecting a syntax error.  Thus, state merging
1042        (from LALR or IELR) and default reductions corrupt the expected
1043        token list.  However, the list is correct for canonical LR with
1044        one exception: it will still contain any token that will not be
1045        accepted due to an error action in a later state.
1046   */
1047   if (yytoken != YYEMPTY)
1048     {
1049       int yyn = yypact[*yyssp];
1050       yyarg[yycount++] = yytname[yytoken];
1051       if (!yypact_value_is_default (yyn))
1052         {
1053           /* Start YYX at -YYN if negative to avoid negative indexes in
1054              YYCHECK.  In other words, skip the first -YYN actions for
1055              this state because they are default actions.  */
1056           int yyxbegin = yyn < 0 ? -yyn : 0;
1057           /* Stay within bounds of both yycheck and yytname.  */
1058           int yychecklim = YYLAST - yyn + 1;
1059           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1060           int yyx;
1061
1062           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1063             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1064                 && !yytable_value_is_error (yytable[yyx + yyn]))
1065               {
1066                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1067                   {
1068                     yycount = 1;
1069                     yysize = yysize0;
1070                     break;
1071                   }
1072                 yyarg[yycount++] = yytname[yyx];
1073                 {
1074                   YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
1075                   if (! (yysize <= yysize1
1076                          && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1077                     return 2;
1078                   yysize = yysize1;
1079                 }
1080               }
1081         }
1082     }
1083
1084   switch (yycount)
1085     {
1086 # define YYCASE_(N, S)                      \
1087       case N:                               \
1088         yyformat = S;                       \
1089       break
1090       YYCASE_(0, YY_("syntax error"));
1091       YYCASE_(1, YY_("syntax error, unexpected %s"));
1092       YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1093       YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1094       YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1095       YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1096 # undef YYCASE_
1097     }
1098
1099   {
1100     YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1101     if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
1102       return 2;
1103     yysize = yysize1;
1104   }
1105
1106   if (*yymsg_alloc < yysize)
1107     {
1108       *yymsg_alloc = 2 * yysize;
1109       if (! (yysize <= *yymsg_alloc
1110              && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1111         *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1112       return 1;
1113     }
1114
1115   /* Avoid sprintf, as that infringes on the user's name space.
1116      Don't have undefined behavior even if the translation
1117      produced a string with the wrong number of "%s"s.  */
1118   {
1119     char *yyp = *yymsg;
1120     int yyi = 0;
1121     while ((*yyp = *yyformat) != '\0')
1122       if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1123         {
1124           yyp += yytnamerr (yyp, yyarg[yyi++]);
1125           yyformat += 2;
1126         }
1127       else
1128         {
1129           yyp++;
1130           yyformat++;
1131         }
1132   }
1133   return 0;
1134 }
1135 #endif /* YYERROR_VERBOSE */
1136
1137 /*-----------------------------------------------.
1138 | Release the memory associated to this symbol.  |
1139 `-----------------------------------------------*/
1140
1141 /*ARGSUSED*/
1142 #if (defined __STDC__ || defined __C99__FUNC__ \
1143      || defined __cplusplus || defined _MSC_VER)
1144 static void
1145 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1146 #else
1147 static void
1148 yydestruct (yymsg, yytype, yyvaluep)
1149     const char *yymsg;
1150     int yytype;
1151     YYSTYPE *yyvaluep;
1152 #endif
1153 {
1154   YYUSE (yyvaluep);
1155
1156   if (!yymsg)
1157     yymsg = "Deleting";
1158   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1159
1160   switch (yytype)
1161     {
1162
1163       default:
1164         break;
1165     }
1166 }
1167
1168
1169
1170
1171 /* The lookahead symbol.  */
1172 int yychar;
1173
1174
1175 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1176 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1177 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
1178 #endif
1179 #ifndef YY_INITIAL_VALUE
1180 # define YY_INITIAL_VALUE(Value) /* Nothing. */
1181 #endif
1182
1183 /* The semantic value of the lookahead symbol.  */
1184 YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
1185
1186 /* Number of syntax errors so far.  */
1187 int yynerrs;
1188
1189
1190 /*----------.
1191 | yyparse.  |
1192 `----------*/
1193
1194 #ifdef YYPARSE_PARAM
1195 #if (defined __STDC__ || defined __C99__FUNC__ \
1196      || defined __cplusplus || defined _MSC_VER)
1197 int
1198 yyparse (void *YYPARSE_PARAM)
1199 #else
1200 int
1201 yyparse (YYPARSE_PARAM)
1202     void *YYPARSE_PARAM;
1203 #endif
1204 #else /* ! YYPARSE_PARAM */
1205 #if (defined __STDC__ || defined __C99__FUNC__ \
1206      || defined __cplusplus || defined _MSC_VER)
1207 int
1208 yyparse (void)
1209 #else
1210 int
1211 yyparse ()
1212
1213 #endif
1214 #endif
1215 {
1216     int yystate;
1217     /* Number of tokens to shift before error messages enabled.  */
1218     int yyerrstatus;
1219
1220     /* The stacks and their tools:
1221        `yyss': related to states.
1222        `yyvs': related to semantic values.
1223
1224        Refer to the stacks through separate pointers, to allow yyoverflow
1225        to reallocate them elsewhere.  */
1226
1227     /* The state stack.  */
1228     yytype_int16 yyssa[YYINITDEPTH];
1229     yytype_int16 *yyss;
1230     yytype_int16 *yyssp;
1231
1232     /* The semantic value stack.  */
1233     YYSTYPE yyvsa[YYINITDEPTH];
1234     YYSTYPE *yyvs;
1235     YYSTYPE *yyvsp;
1236
1237     YYSIZE_T yystacksize;
1238
1239   int yyn;
1240   int yyresult;
1241   /* Lookahead token as an internal (translated) token number.  */
1242   int yytoken = 0;
1243   /* The variables used to return semantic value and location from the
1244      action routines.  */
1245   YYSTYPE yyval;
1246
1247 #if YYERROR_VERBOSE
1248   /* Buffer for error messages, and its allocated size.  */
1249   char yymsgbuf[128];
1250   char *yymsg = yymsgbuf;
1251   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1252 #endif
1253
1254 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1255
1256   /* The number of symbols on the RHS of the reduced rule.
1257      Keep to zero when no symbol should be popped.  */
1258   int yylen = 0;
1259
1260   yyssp = yyss = yyssa;
1261   yyvsp = yyvs = yyvsa;
1262   yystacksize = YYINITDEPTH;
1263
1264   YYDPRINTF ((stderr, "Starting parse\n"));
1265
1266   yystate = 0;
1267   yyerrstatus = 0;
1268   yynerrs = 0;
1269   yychar = YYEMPTY; /* Cause a token to be read.  */
1270   goto yysetstate;
1271
1272 /*------------------------------------------------------------.
1273 | yynewstate -- Push a new state, which is found in yystate.  |
1274 `------------------------------------------------------------*/
1275  yynewstate:
1276   /* In all cases, when you get here, the value and location stacks
1277      have just been pushed.  So pushing a state here evens the stacks.  */
1278   yyssp++;
1279
1280  yysetstate:
1281   *yyssp = yystate;
1282
1283   if (yyss + yystacksize - 1 <= yyssp)
1284     {
1285       /* Get the current used size of the three stacks, in elements.  */
1286       YYSIZE_T yysize = yyssp - yyss + 1;
1287
1288 #ifdef yyoverflow
1289       {
1290         /* Give user a chance to reallocate the stack.  Use copies of
1291            these so that the &'s don't force the real ones into
1292            memory.  */
1293         YYSTYPE *yyvs1 = yyvs;
1294         yytype_int16 *yyss1 = yyss;
1295
1296         /* Each stack pointer address is followed by the size of the
1297            data in use in that stack, in bytes.  This used to be a
1298            conditional around just the two extra args, but that might
1299            be undefined if yyoverflow is a macro.  */
1300         yyoverflow (YY_("memory exhausted"),
1301                     &yyss1, yysize * sizeof (*yyssp),
1302                     &yyvs1, yysize * sizeof (*yyvsp),
1303                     &yystacksize);
1304
1305         yyss = yyss1;
1306         yyvs = yyvs1;
1307       }
1308 #else /* no yyoverflow */
1309 # ifndef YYSTACK_RELOCATE
1310       goto yyexhaustedlab;
1311 # else
1312       /* Extend the stack our own way.  */
1313       if (YYMAXDEPTH <= yystacksize)
1314         goto yyexhaustedlab;
1315       yystacksize *= 2;
1316       if (YYMAXDEPTH < yystacksize)
1317         yystacksize = YYMAXDEPTH;
1318
1319       {
1320         yytype_int16 *yyss1 = yyss;
1321         union yyalloc *yyptr =
1322           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1323         if (! yyptr)
1324           goto yyexhaustedlab;
1325         YYSTACK_RELOCATE (yyss_alloc, yyss);
1326         YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1327 #  undef YYSTACK_RELOCATE
1328         if (yyss1 != yyssa)
1329           YYSTACK_FREE (yyss1);
1330       }
1331 # endif
1332 #endif /* no yyoverflow */
1333
1334       yyssp = yyss + yysize - 1;
1335       yyvsp = yyvs + yysize - 1;
1336
1337       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1338                   (unsigned long int) yystacksize));
1339
1340       if (yyss + yystacksize - 1 <= yyssp)
1341         YYABORT;
1342     }
1343
1344   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1345
1346   if (yystate == YYFINAL)
1347     YYACCEPT;
1348
1349   goto yybackup;
1350
1351 /*-----------.
1352 | yybackup.  |
1353 `-----------*/
1354 yybackup:
1355
1356   /* Do appropriate processing given the current state.  Read a
1357      lookahead token if we need one and don't already have one.  */
1358
1359   /* First try to decide what to do without reference to lookahead token.  */
1360   yyn = yypact[yystate];
1361   if (yypact_value_is_default (yyn))
1362     goto yydefault;
1363
1364   /* Not known => get a lookahead token if don't already have one.  */
1365
1366   /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
1367   if (yychar == YYEMPTY)
1368     {
1369       YYDPRINTF ((stderr, "Reading a token: "));
1370       yychar = YYLEX;
1371     }
1372
1373   if (yychar <= YYEOF)
1374     {
1375       yychar = yytoken = YYEOF;
1376       YYDPRINTF ((stderr, "Now at end of input.\n"));
1377     }
1378   else
1379     {
1380       yytoken = YYTRANSLATE (yychar);
1381       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1382     }
1383
1384   /* If the proper action on seeing token YYTOKEN is to reduce or to
1385      detect an error, take that action.  */
1386   yyn += yytoken;
1387   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1388     goto yydefault;
1389   yyn = yytable[yyn];
1390   if (yyn <= 0)
1391     {
1392       if (yytable_value_is_error (yyn))
1393         goto yyerrlab;
1394       yyn = -yyn;
1395       goto yyreduce;
1396     }
1397
1398   /* Count tokens shifted since error; after three, turn off error
1399      status.  */
1400   if (yyerrstatus)
1401     yyerrstatus--;
1402
1403   /* Shift the lookahead token.  */
1404   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1405
1406   /* Discard the shifted token.  */
1407   yychar = YYEMPTY;
1408
1409   yystate = yyn;
1410   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1411   *++yyvsp = yylval;
1412   YY_IGNORE_MAYBE_UNINITIALIZED_END
1413
1414   goto yynewstate;
1415
1416
1417 /*-----------------------------------------------------------.
1418 | yydefault -- do the default action for the current state.  |
1419 `-----------------------------------------------------------*/
1420 yydefault:
1421   yyn = yydefact[yystate];
1422   if (yyn == 0)
1423     goto yyerrlab;
1424   goto yyreduce;
1425
1426
1427 /*-----------------------------.
1428 | yyreduce -- Do a reduction.  |
1429 `-----------------------------*/
1430 yyreduce:
1431   /* yyn is the number of a rule to reduce with.  */
1432   yylen = yyr2[yyn];
1433
1434   /* If YYLEN is nonzero, implement the default value of the action:
1435      `$$ = $1'.
1436
1437      Otherwise, the following line sets YYVAL to garbage.
1438      This behavior is undocumented and Bison
1439      users should not rely upon it.  Assigning to YYVAL
1440      unconditionally makes the parser a bit smaller, and it avoids a
1441      GCC warning that YYVAL may be used uninitialized.  */
1442   yyval = yyvsp[1-yylen];
1443
1444
1445   YY_REDUCE_PRINT (yyn);
1446   switch (yyn)
1447     {
1448         case 4:
1449 /* Line 1792 of yacc.c  */
1450 #line 74 "sparql_parser.y"
1451     {
1452     if (ssp_slq->slq_result_limit)
1453         result_limit = talloc_asprintf(ssp_slq, "LIMIT %ld", ssp_slq->slq_result_limit);
1454     else
1455         result_limit = "";
1456     ssp_result = talloc_asprintf(ssp_slq,
1457                                  "SELECT ?url WHERE "
1458                                  "{ %s . ?obj nie:url ?url . FILTER(tracker:uri-is-descendant('file://%s/', ?url)) } %s",
1459                                  (yyvsp[(1) - (1)].sval), ssp_slq->slq_vol->v_path, result_limit);
1460     (yyval.sval) = ssp_result;
1461 }
1462     break;
1463
1464   case 5:
1465 /* Line 1792 of yacc.c  */
1466 #line 88 "sparql_parser.y"
1467     {
1468         /*
1469          * We can't properly handle these in expressions, fortunately this
1470          * is probably only ever used by OS X as sole element in an
1471          * expression ie "False" (when Finder window selected our share
1472          * but no search string entered yet). Packet traces showed that OS
1473          * X Spotlight server then returns a failure (ie -1) which is what
1474          * we do here too by calling YYABORT.
1475          */
1476         YYABORT;
1477 }
1478     break;
1479
1480   case 6:
1481 /* Line 1792 of yacc.c  */
1482 #line 99 "sparql_parser.y"
1483     {
1484     if ((yyvsp[(1) - (3)].sval) == NULL || (yyvsp[(3) - (3)].sval) == NULL)
1485         YYABORT;
1486     if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0)
1487         (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1488     else
1489         (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval));
1490 }
1491     break;
1492
1493   case 7:
1494 /* Line 1792 of yacc.c  */
1495 #line 107 "sparql_parser.y"
1496     {(yyval.sval) = (yyvsp[(1) - (1)].sval); if ((yyval.sval) == NULL) YYABORT;}
1497     break;
1498
1499   case 8:
1500 /* Line 1792 of yacc.c  */
1501 #line 108 "sparql_parser.y"
1502     {(yyval.sval) = (yyvsp[(1) - (1)].sval);}
1503     break;
1504
1505   case 9:
1506 /* Line 1792 of yacc.c  */
1507 #line 109 "sparql_parser.y"
1508     {(yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(2) - (3)].sval));}
1509     break;
1510
1511   case 10:
1512 /* Line 1792 of yacc.c  */
1513 #line 110 "sparql_parser.y"
1514     {
1515     if (!ssp_slq->slq_allow_expr) {
1516         yyerror("Spotlight queries with logic expressions are disabled");
1517         YYABORT;
1518     }
1519     (yyval.sval) = talloc_asprintf(ssp_slq, "%s . %s", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1520 }
1521     break;
1522
1523   case 11:
1524 /* Line 1792 of yacc.c  */
1525 #line 117 "sparql_parser.y"
1526     {
1527     if (!ssp_slq->slq_allow_expr) {
1528         yyerror("Spotlight queries with logic expressions are disabled");
1529         YYABORT;
1530     }
1531     if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0)
1532         (yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
1533     else
1534         (yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(1) - (3)].sval));
1535 }
1536     break;
1537
1538   case 12:
1539 /* Line 1792 of yacc.c  */
1540 #line 130 "sparql_parser.y"
1541     {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '=', (yyvsp[(4) - (5)].sval));}
1542     break;
1543
1544   case 13:
1545 /* Line 1792 of yacc.c  */
1546 #line 131 "sparql_parser.y"
1547     {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '!', (yyvsp[(4) - (5)].sval));}
1548     break;
1549
1550   case 14:
1551 /* Line 1792 of yacc.c  */
1552 #line 132 "sparql_parser.y"
1553     {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '<', (yyvsp[(4) - (5)].sval));}
1554     break;
1555
1556   case 15:
1557 /* Line 1792 of yacc.c  */
1558 #line 133 "sparql_parser.y"
1559     {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '>', (yyvsp[(4) - (5)].sval));}
1560     break;
1561
1562   case 16:
1563 /* Line 1792 of yacc.c  */
1564 #line 134 "sparql_parser.y"
1565     {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '=', (yyvsp[(4) - (6)].sval));}
1566     break;
1567
1568   case 17:
1569 /* Line 1792 of yacc.c  */
1570 #line 135 "sparql_parser.y"
1571     {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '!', (yyvsp[(4) - (6)].sval));}
1572     break;
1573
1574   case 18:
1575 /* Line 1792 of yacc.c  */
1576 #line 136 "sparql_parser.y"
1577     {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '<', (yyvsp[(4) - (6)].sval));}
1578     break;
1579
1580   case 19:
1581 /* Line 1792 of yacc.c  */
1582 #line 137 "sparql_parser.y"
1583     {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '>', (yyvsp[(4) - (6)].sval));}
1584     break;
1585
1586   case 20:
1587 /* Line 1792 of yacc.c  */
1588 #line 141 "sparql_parser.y"
1589     {(yyval.sval) = map_daterange((yyvsp[(3) - (8)].sval), (yyvsp[(5) - (8)].tval), (yyvsp[(7) - (8)].tval));}
1590     break;
1591
1592   case 21:
1593 /* Line 1792 of yacc.c  */
1594 #line 145 "sparql_parser.y"
1595     {(yyval.tval) = isodate2unix((yyvsp[(3) - (4)].sval));}
1596     break;
1597
1598   case 22:
1599 /* Line 1792 of yacc.c  */
1600 #line 146 "sparql_parser.y"
1601     {(yyval.tval) = atoi((yyvsp[(1) - (1)].sval)) + SPRAW_TIME_OFFSET;}
1602     break;
1603
1604
1605 /* Line 1792 of yacc.c  */
1606 #line 1607 "sparql_parser.c"
1607       default: break;
1608     }
1609   /* User semantic actions sometimes alter yychar, and that requires
1610      that yytoken be updated with the new translation.  We take the
1611      approach of translating immediately before every use of yytoken.
1612      One alternative is translating here after every semantic action,
1613      but that translation would be missed if the semantic action invokes
1614      YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
1615      if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
1616      incorrect destructor might then be invoked immediately.  In the
1617      case of YYERROR or YYBACKUP, subsequent parser actions might lead
1618      to an incorrect destructor call or verbose syntax error message
1619      before the lookahead is translated.  */
1620   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1621
1622   YYPOPSTACK (yylen);
1623   yylen = 0;
1624   YY_STACK_PRINT (yyss, yyssp);
1625
1626   *++yyvsp = yyval;
1627
1628   /* Now `shift' the result of the reduction.  Determine what state
1629      that goes to, based on the state we popped back to and the rule
1630      number reduced by.  */
1631
1632   yyn = yyr1[yyn];
1633
1634   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1635   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1636     yystate = yytable[yystate];
1637   else
1638     yystate = yydefgoto[yyn - YYNTOKENS];
1639
1640   goto yynewstate;
1641
1642
1643 /*------------------------------------.
1644 | yyerrlab -- here on detecting error |
1645 `------------------------------------*/
1646 yyerrlab:
1647   /* Make sure we have latest lookahead translation.  See comments at
1648      user semantic actions for why this is necessary.  */
1649   yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
1650
1651   /* If not already recovering from an error, report this error.  */
1652   if (!yyerrstatus)
1653     {
1654       ++yynerrs;
1655 #if ! YYERROR_VERBOSE
1656       yyerror (YY_("syntax error"));
1657 #else
1658 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
1659                                         yyssp, yytoken)
1660       {
1661         char const *yymsgp = YY_("syntax error");
1662         int yysyntax_error_status;
1663         yysyntax_error_status = YYSYNTAX_ERROR;
1664         if (yysyntax_error_status == 0)
1665           yymsgp = yymsg;
1666         else if (yysyntax_error_status == 1)
1667           {
1668             if (yymsg != yymsgbuf)
1669               YYSTACK_FREE (yymsg);
1670             yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
1671             if (!yymsg)
1672               {
1673                 yymsg = yymsgbuf;
1674                 yymsg_alloc = sizeof yymsgbuf;
1675                 yysyntax_error_status = 2;
1676               }
1677             else
1678               {
1679                 yysyntax_error_status = YYSYNTAX_ERROR;
1680                 yymsgp = yymsg;
1681               }
1682           }
1683         yyerror (yymsgp);
1684         if (yysyntax_error_status == 2)
1685           goto yyexhaustedlab;
1686       }
1687 # undef YYSYNTAX_ERROR
1688 #endif
1689     }
1690
1691
1692
1693   if (yyerrstatus == 3)
1694     {
1695       /* If just tried and failed to reuse lookahead token after an
1696          error, discard it.  */
1697
1698       if (yychar <= YYEOF)
1699         {
1700           /* Return failure if at end of input.  */
1701           if (yychar == YYEOF)
1702             YYABORT;
1703         }
1704       else
1705         {
1706           yydestruct ("Error: discarding",
1707                       yytoken, &yylval);
1708           yychar = YYEMPTY;
1709         }
1710     }
1711
1712   /* Else will try to reuse lookahead token after shifting the error
1713      token.  */
1714   goto yyerrlab1;
1715
1716
1717 /*---------------------------------------------------.
1718 | yyerrorlab -- error raised explicitly by YYERROR.  |
1719 `---------------------------------------------------*/
1720 yyerrorlab:
1721
1722   /* Pacify compilers like GCC when the user code never invokes
1723      YYERROR and the label yyerrorlab therefore never appears in user
1724      code.  */
1725   if (/*CONSTCOND*/ 0)
1726      goto yyerrorlab;
1727
1728   /* Do not reclaim the symbols of the rule which action triggered
1729      this YYERROR.  */
1730   YYPOPSTACK (yylen);
1731   yylen = 0;
1732   YY_STACK_PRINT (yyss, yyssp);
1733   yystate = *yyssp;
1734   goto yyerrlab1;
1735
1736
1737 /*-------------------------------------------------------------.
1738 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1739 `-------------------------------------------------------------*/
1740 yyerrlab1:
1741   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
1742
1743   for (;;)
1744     {
1745       yyn = yypact[yystate];
1746       if (!yypact_value_is_default (yyn))
1747         {
1748           yyn += YYTERROR;
1749           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1750             {
1751               yyn = yytable[yyn];
1752               if (0 < yyn)
1753                 break;
1754             }
1755         }
1756
1757       /* Pop the current state because it cannot handle the error token.  */
1758       if (yyssp == yyss)
1759         YYABORT;
1760
1761
1762       yydestruct ("Error: popping",
1763                   yystos[yystate], yyvsp);
1764       YYPOPSTACK (1);
1765       yystate = *yyssp;
1766       YY_STACK_PRINT (yyss, yyssp);
1767     }
1768
1769   YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1770   *++yyvsp = yylval;
1771   YY_IGNORE_MAYBE_UNINITIALIZED_END
1772
1773
1774   /* Shift the error token.  */
1775   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1776
1777   yystate = yyn;
1778   goto yynewstate;
1779
1780
1781 /*-------------------------------------.
1782 | yyacceptlab -- YYACCEPT comes here.  |
1783 `-------------------------------------*/
1784 yyacceptlab:
1785   yyresult = 0;
1786   goto yyreturn;
1787
1788 /*-----------------------------------.
1789 | yyabortlab -- YYABORT comes here.  |
1790 `-----------------------------------*/
1791 yyabortlab:
1792   yyresult = 1;
1793   goto yyreturn;
1794
1795 #if !defined yyoverflow || YYERROR_VERBOSE
1796 /*-------------------------------------------------.
1797 | yyexhaustedlab -- memory exhaustion comes here.  |
1798 `-------------------------------------------------*/
1799 yyexhaustedlab:
1800   yyerror (YY_("memory exhausted"));
1801   yyresult = 2;
1802   /* Fall through.  */
1803 #endif
1804
1805 yyreturn:
1806   if (yychar != YYEMPTY)
1807     {
1808       /* Make sure we have latest lookahead translation.  See comments at
1809          user semantic actions for why this is necessary.  */
1810       yytoken = YYTRANSLATE (yychar);
1811       yydestruct ("Cleanup: discarding lookahead",
1812                   yytoken, &yylval);
1813     }
1814   /* Do not reclaim the symbols of the rule which action triggered
1815      this YYABORT or YYACCEPT.  */
1816   YYPOPSTACK (yylen);
1817   YY_STACK_PRINT (yyss, yyssp);
1818   while (yyssp != yyss)
1819     {
1820       yydestruct ("Cleanup: popping",
1821                   yystos[*yyssp], yyvsp);
1822       YYPOPSTACK (1);
1823     }
1824 #ifndef yyoverflow
1825   if (yyss != yyssa)
1826     YYSTACK_FREE (yyss);
1827 #endif
1828 #if YYERROR_VERBOSE
1829   if (yymsg != yymsgbuf)
1830     YYSTACK_FREE (yymsg);
1831 #endif
1832   /* Make sure YYID is used.  */
1833   return YYID (yyresult);
1834 }
1835
1836
1837 /* Line 2055 of yacc.c  */
1838 #line 149 "sparql_parser.y"
1839
1840
1841 static time_t isodate2unix(const char *s)
1842 {
1843     struct tm tm;
1844
1845     if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL)
1846         return (time_t)-1;
1847     return mktime(&tm);
1848 }
1849
1850 static const char *map_daterange(const char *dateattr, time_t date1, time_t date2)
1851 {
1852     EC_INIT;
1853     char *result = NULL;
1854     struct spotlight_sparql_map *p;
1855     struct tm *tmp;
1856     char buf1[64], buf2[64];
1857
1858     EC_NULL_LOG( tmp = localtime(&date1) );
1859     strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1860     EC_NULL_LOG( tmp = localtime(&date2) );
1861     strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp);
1862
1863     for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
1864         if (strcmp(dateattr, p->ssm_spotlight_attr) == 0) {
1865             result = talloc_asprintf(ssp_slq,
1866                                      "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')",
1867                                      p->ssm_sparql_attr,
1868                                      sparqlvar,
1869                                      sparqlvar,
1870                                      buf1,
1871                                      sparqlvar,
1872                                      buf2);
1873             sparqlvar++;
1874             break;
1875         }
1876     }
1877
1878 EC_CLEANUP:
1879     if (ret != 0)
1880         return NULL;
1881     return result;
1882 }
1883
1884 static char *map_type_search(const char *attr, char op, const char *val)
1885 {
1886     char *result = NULL;
1887     const char *sparqlAttr;
1888
1889     for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) {
1890         if (strcmp(p->mdtm_value, val) == 0) {
1891             switch (p->mdtm_type) {
1892             case kMDTypeMapRDF:
1893                 sparqlAttr = "rdf:type";
1894                 break;
1895             case kMDTypeMapMime:
1896                 sparqlAttr = "nie:mimeType";
1897                 break;
1898             default:
1899                 return NULL;
1900             }
1901             result = talloc_asprintf(ssp_slq, "?obj %s '%s'",
1902                                      sparqlAttr,
1903                                      p->mdtm_sparql);
1904             break;
1905         }
1906     }
1907     return result;
1908 }
1909
1910 static const char *map_expr(const char *attr, char op, const char *val)
1911 {
1912     EC_INIT;
1913     char *result = NULL;
1914     struct spotlight_sparql_map *p;
1915     time_t t;
1916     struct tm *tmp;
1917     char buf1[64];
1918     bstring q = NULL, search = NULL, replace = NULL;
1919
1920     for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
1921         if (p->ssm_enabled && (strcmp(p->ssm_spotlight_attr, attr) == 0)) {
1922             if (p->ssm_type != ssmt_type && p->ssm_sparql_attr == NULL) {
1923                 yyerror("unsupported Spotlight attribute");
1924                 EC_FAIL;
1925             }
1926             switch (p->ssm_type) {
1927             case ssmt_bool:
1928                 result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val);
1929                 break;
1930             case ssmt_num:
1931                 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c%c '%s')",
1932                                          p->ssm_sparql_attr,
1933                                          sparqlvar,
1934                                          sparqlvar,
1935                                          op,
1936                                          op == '!' ? '=' : ' ', /* append '=' to '!' */
1937                                          val);
1938                 sparqlvar++;
1939                 break;
1940             case ssmt_str:
1941                 q = bformat("^%s$", val);
1942                 search = bfromcstr("*");
1943                 replace = bfromcstr(".*");
1944                 bfindreplace(q, search, replace, 0);
1945                 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(regex(?%c, '%s'))",
1946                                          p->ssm_sparql_attr,
1947                                          sparqlvar,
1948                                          sparqlvar,
1949                                          bdata(q));
1950                 sparqlvar++;
1951                 break;
1952             case ssmt_fts:
1953                 result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val);
1954                 break;
1955             case ssmt_date:
1956                 t = atoi(val) + SPRAW_TIME_OFFSET;
1957                 EC_NULL( tmp = localtime(&t) );
1958                 strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
1959                 result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c '%s')",
1960                                          p->ssm_sparql_attr,
1961                                          sparqlvar,
1962                                          sparqlvar,
1963                                          op,
1964                                          buf1);
1965                 sparqlvar++;
1966                 break;
1967             case ssmt_type:
1968                 result = map_type_search(attr, op, val);
1969                 break;
1970             default:
1971                 EC_FAIL;
1972             }
1973             break;
1974         }
1975     }
1976
1977 EC_CLEANUP:
1978     if (ret != 0)
1979         result = NULL;
1980     if (q)
1981         bdestroy(q);
1982     if (search)
1983         bdestroy(search);
1984     if (replace)
1985         bdestroy(replace);
1986     return result;
1987 }
1988
1989 void yyerror(const char *str)
1990 {
1991 #ifdef MAIN
1992     printf("yyerror: %s\n", str);
1993 #else
1994     LOG(log_error, logtype_sl, "yyerror: %s", str);
1995 #endif
1996 }
1997  
1998 int yywrap()
1999 {
2000     return 1;
2001
2002
2003 /**
2004  * Map a Spotlight RAW query string to a SPARQL query string
2005  *
2006  * @param[in]     slq            Spotlight query handle
2007  * @param[out]    sparql_result  Mapped SPARQL query, string is allocated in
2008  *                               talloc context of slq
2009  * @return        0 on success, -1 on error
2010  **/
2011 int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result)
2012 {
2013     EC_INIT;
2014     YY_BUFFER_STATE s = NULL;
2015     ssp_result = NULL;
2016
2017     ssp_slq = slq;
2018     s = yy_scan_string(slq->slq_qstring);
2019     sparqlvar = 'a';
2020
2021     EC_ZERO( yyparse() );
2022
2023 EC_CLEANUP:
2024     if (s)
2025         yy_delete_buffer(s);
2026     if (ret == 0)
2027         *sparql_result = ssp_result;
2028     else
2029         *sparql_result = NULL;
2030     EC_EXIT;
2031 }
2032
2033 #ifdef MAIN
2034 int main(int argc, char **argv)
2035 {
2036     int ret;
2037     YY_BUFFER_STATE s;
2038
2039     if (argc != 2) {
2040         printf("usage: %s QUERY\n", argv[0]);
2041         return 1;
2042     }
2043
2044     ssp_slq = talloc_zero(NULL, slq_t);
2045     struct vol *vol = talloc_zero(ssp_slq, struct vol);
2046     vol->v_path = "/Volumes/test";
2047     ssp_slq->slq_vol = vol;
2048     ssp_slq->slq_allow_expr = true;
2049     sparqlvar = 'a';
2050
2051     s = yy_scan_string(argv[1]);
2052
2053     ret = yyparse();
2054
2055     yy_delete_buffer(s);
2056
2057     if (ret == 0)
2058         printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)");
2059
2060     return 0;
2061
2062 #endif