-/* A Bison parser, made by GNU Bison 2.5. */
+/* A Bison parser, made by GNU Bison 2.7. */
/* Bison implementation for Yacc-like parsers in C
- Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
+ Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#define YYBISON 1
/* Bison version. */
-#define YYBISON_VERSION "2.5"
+#define YYBISON_VERSION "2.7"
/* Skeleton name. */
#define YYSKELETON_NAME "yacc.c"
/* Pull parsers. */
#define YYPULL 1
-/* Using locations. */
-#define YYLSP_NEEDED 0
/* Copy the first part of user declarations. */
-
-/* Line 268 of yacc.c */
+/* Line 371 of yacc.c */
#line 1 "spotlight_rawquery_parser.y"
+ #include <atalk/standards.h>
+
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+ #include <time.h>
+
#include <gio/gio.h>
+
#include <atalk/talloc.h>
#include <atalk/logger.h>
#include <atalk/errchk.h>
+
#include "spotlight_SPARQL_map.h"
#include "spotlight.h"
/* forward declarations */
static const char *map_expr(const char *attr, char op, const char *val);
- static const char *map_daterange(const char *dateattr, const char *date1, const char *date2);
-
- /* global vars, eg needed by the lexer */
+ static const char *map_daterange(const char *dateattr, time_t date1, time_t date2);
+ static time_t isodate2unix(const char *s);
+
+ /* global vars, eg needed by the lexer */
slq_t *ssp_slq;
/* local vars */
static gchar *ssp_result;
+ static char sparqlvar;
+/* Line 371 of yacc.c */
+#line 106 "spotlight_rawquery_parser.c"
-
-/* Line 268 of yacc.c */
-#line 103 "spotlight_rawquery_parser.c"
-
-/* Enabling traces. */
-#ifndef YYDEBUG
-# define YYDEBUG 0
-#endif
+# ifndef YY_NULL
+# if defined __cplusplus && 201103L <= __cplusplus
+# define YY_NULL nullptr
+# else
+# define YY_NULL 0
+# endif
+# endif
/* Enabling verbose error messages. */
#ifdef YYERROR_VERBOSE
# define YYERROR_VERBOSE 1
#endif
-/* Enabling the token table. */
-#ifndef YYTOKEN_TABLE
-# define YYTOKEN_TABLE 0
+/* In a future release of Bison, this section will be replaced
+ by #include "y.tab.h". */
+#ifndef YY_YY_Y_TAB_H_INCLUDED
+# define YY_YY_Y_TAB_H_INCLUDED
+/* Enabling traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+#if YYDEBUG
+extern int yydebug;
#endif
-
/* Tokens. */
#ifndef YYTOKENTYPE
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
- DATE = 258,
- WORD = 259,
- BOOL = 260,
- FUNC_INRANGE = 261,
- DATE_SPEC = 262,
- OBRACE = 263,
- CBRACE = 264,
- EQUAL = 265,
- UNEQUAL = 266,
- GT = 267,
- LT = 268,
- COMMA = 269,
- QUOTE = 270,
- AND = 271,
- OR = 272
+ WORD = 258,
+ BOOL = 259,
+ FUNC_INRANGE = 260,
+ DATE_ISO = 261,
+ OBRACE = 262,
+ CBRACE = 263,
+ EQUAL = 264,
+ UNEQUAL = 265,
+ GT = 266,
+ LT = 267,
+ COMMA = 268,
+ QUOTE = 269,
+ AND = 270,
+ OR = 271
};
#endif
/* Tokens. */
-#define DATE 258
-#define WORD 259
-#define BOOL 260
-#define FUNC_INRANGE 261
-#define DATE_SPEC 262
-#define OBRACE 263
-#define CBRACE 264
-#define EQUAL 265
-#define UNEQUAL 266
-#define GT 267
-#define LT 268
-#define COMMA 269
-#define QUOTE 270
-#define AND 271
-#define OR 272
-
+#define WORD 258
+#define BOOL 259
+#define FUNC_INRANGE 260
+#define DATE_ISO 261
+#define OBRACE 262
+#define CBRACE 263
+#define EQUAL 264
+#define UNEQUAL 265
+#define GT 266
+#define LT 267
+#define COMMA 268
+#define QUOTE 269
+#define AND 270
+#define OR 271
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
{
-
-/* Line 293 of yacc.c */
-#line 37 "spotlight_rawquery_parser.y"
+/* Line 387 of yacc.c */
+#line 45 "spotlight_rawquery_parser.y"
int ival;
const char *sval;
bool bval;
+ time_t tval;
-
-/* Line 293 of yacc.c */
-#line 181 "spotlight_rawquery_parser.c"
+/* Line 387 of yacc.c */
+#line 189 "spotlight_rawquery_parser.c"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
-/* "%code provides" blocks. */
+extern YYSTYPE yylval;
-/* Line 340 of yacc.c */
-#line 32 "spotlight_rawquery_parser.y"
+#ifdef YYPARSE_PARAM
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void *YYPARSE_PARAM);
+#else
+int yyparse ();
+#endif
+#else /* ! YYPARSE_PARAM */
+#if defined __STDC__ || defined __cplusplus
+int yyparse (void);
+#else
+int yyparse ();
+#endif
+#endif /* ! YYPARSE_PARAM */
+/* "%code provides" blocks. */
+/* Line 387 of yacc.c */
+#line 39 "spotlight_rawquery_parser.y"
+ #define SPRAW_TIME_OFFSET 978307200
extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result);
extern slq_t *ssp_slq;
+/* Line 387 of yacc.c */
+#line 221 "spotlight_rawquery_parser.c"
-/* Line 340 of yacc.c */
-#line 199 "spotlight_rawquery_parser.c"
+#endif /* !YY_YY_Y_TAB_H_INCLUDED */
/* Copy the second part of user declarations. */
-
-/* Line 343 of yacc.c */
-#line 205 "spotlight_rawquery_parser.c"
+/* Line 390 of yacc.c */
+#line 228 "spotlight_rawquery_parser.c"
#ifdef short
# undef short
# if defined YYENABLE_NLS && YYENABLE_NLS
# if ENABLE_NLS
# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
-# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
# endif
# endif
# ifndef YY_
-# define YY_(msgid) msgid
+# define YY_(Msgid) Msgid
# endif
#endif
/* Suppress unused-variable warnings by "using" E. */
#if ! defined lint || defined __GNUC__
-# define YYUSE(e) ((void) (e))
+# define YYUSE(E) ((void) (E))
#else
-# define YYUSE(e) /* empty */
+# define YYUSE(E) /* empty */
#endif
/* Identity function, used to suppress warnings about constant conditions. */
#ifndef lint
-# define YYID(n) (n)
+# define YYID(N) (N)
#else
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+ /* Use EXIT_SUCCESS as a witness for stdlib.h. */
# ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
# endif
#endif
#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
-/* Copy COUNT objects from FROM to TO. The source and destination do
+/* Copy COUNT objects from SRC to DST. The source and destination do
not overlap. */
# ifndef YYCOPY
# if defined __GNUC__ && 1 < __GNUC__
-# define YYCOPY(To, From, Count) \
- __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
+# define YYCOPY(Dst, Src, Count) \
+ __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
# else
-# define YYCOPY(To, From, Count) \
- do \
- { \
- YYSIZE_T yyi; \
- for (yyi = 0; yyi < (Count); yyi++) \
- (To)[yyi] = (From)[yyi]; \
- } \
+# define YYCOPY(Dst, Src, Count) \
+ do \
+ { \
+ YYSIZE_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (Dst)[yyi] = (Src)[yyi]; \
+ } \
while (YYID (0))
# endif
# endif
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 2
/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 51
+#define YYLAST 52
/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS 18
+#define YYNTOKENS 17
/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS 6
+#define YYNNTS 7
/* YYNRULES -- Number of rules. */
-#define YYNRULES 16
+#define YYNRULES 22
/* YYNRULES -- Number of states. */
-#define YYNSTATES 48
+#define YYNSTATES 51
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2
-#define YYMAXUTOK 272
+#define YYMAXUTOK 271
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17
+ 15, 16
};
#if YYDEBUG
static const yytype_uint8 yyprhs[] =
{
0, 0, 3, 4, 7, 9, 11, 15, 17, 19,
- 23, 27, 31, 37, 43, 49, 55
+ 23, 27, 31, 37, 43, 49, 55, 62, 69, 76,
+ 83, 92, 97
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] =
{
- 19, 0, -1, -1, 19, 20, -1, 21, -1, 5,
- -1, 22, 17, 22, -1, 22, -1, 23, -1, 8,
- 21, 9, -1, 21, 16, 21, -1, 21, 17, 21,
- -1, 4, 10, 15, 4, 15, -1, 4, 11, 15,
- 4, 15, -1, 4, 13, 15, 4, 15, -1, 4,
- 12, 15, 4, 15, -1, 6, 8, 4, 14, 7,
- 8, 3, 9, 14, 7, 8, 3, 9, 9, -1
+ 18, 0, -1, -1, 18, 19, -1, 20, -1, 4,
+ -1, 21, 16, 21, -1, 21, -1, 22, -1, 7,
+ 20, 8, -1, 20, 15, 20, -1, 20, 16, 20,
+ -1, 3, 9, 14, 3, 14, -1, 3, 10, 14,
+ 3, 14, -1, 3, 12, 14, 3, 14, -1, 3,
+ 11, 14, 3, 14, -1, 3, 9, 14, 3, 14,
+ 3, -1, 3, 10, 14, 3, 14, 3, -1, 3,
+ 12, 14, 3, 14, 3, -1, 3, 11, 14, 3,
+ 14, 3, -1, 5, 7, 3, 13, 23, 13, 23,
+ 8, -1, 6, 7, 3, 8, -1, 3, -1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 57, 57, 59, 63, 73, 79, 85, 86, 87,
- 88, 89, 98, 99, 100, 101, 105
+ 0, 67, 67, 69, 73, 83, 89, 95, 96, 97,
+ 98, 99, 108, 109, 110, 111, 112, 113, 114, 115,
+ 119, 123, 124
};
#endif
-#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
+#if YYDEBUG || YYERROR_VERBOSE || 1
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
{
- "$end", "error", "$undefined", "DATE", "WORD", "BOOL", "FUNC_INRANGE",
- "DATE_SPEC", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA",
+ "$end", "error", "$undefined", "WORD", "BOOL", "FUNC_INRANGE",
+ "DATE_ISO", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA",
"QUOTE", "AND", "OR", "$accept", "input", "line", "expr", "match",
- "function", 0
+ "function", "date", YY_NULL
};
#endif
static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
- 265, 266, 267, 268, 269, 270, 271, 272
+ 265, 266, 267, 268, 269, 270, 271
};
# endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
- 0, 18, 19, 19, 20, 21, 21, 21, 21, 21,
- 21, 21, 22, 22, 22, 22, 23
+ 0, 17, 18, 18, 19, 20, 20, 20, 20, 20,
+ 20, 20, 21, 21, 21, 21, 21, 21, 21, 21,
+ 22, 23, 23
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
0, 2, 0, 2, 1, 1, 3, 1, 1, 3,
- 3, 3, 5, 5, 5, 5, 14
+ 3, 3, 5, 5, 5, 5, 6, 6, 6, 6,
+ 8, 4, 1
};
/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
2, 0, 1, 0, 5, 0, 0, 3, 4, 7,
8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 9, 10, 11, 6, 0,
- 0, 0, 0, 0, 12, 13, 15, 14, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 16
+ 0, 0, 0, 0, 12, 13, 15, 14, 22, 0,
+ 0, 16, 17, 19, 18, 0, 0, 0, 0, 21,
+ 20
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
- -1, 1, 7, 8, 9, 10
+ -1, 1, 7, 8, 9, 10, 40
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
-#define YYPACT_NINF -15
+#define YYPACT_NINF -10
static const yytype_int8 yypact[] =
{
- -15, 1, -15, 12, -15, -4, 13, -15, -14, -7,
- -15, -2, 5, 11, 14, 10, -1, 13, 13, 23,
- 24, 26, 27, 28, 19, -15, 17, -15, -15, 20,
- 21, 22, 25, 31, -15, -15, -15, -15, 33, 36,
- 34, 30, 35, 37, 43, 38, 39, -15
+ -10, 10, -10, 9, -10, -2, -1, -10, 8, -9,
+ -10, 2, 12, 13, 14, 26, -7, -1, -1, 27,
+ 28, 29, 30, 31, 22, -10, 20, -10, -10, 23,
+ 24, 25, 32, 19, 37, 38, 39, 40, -10, 41,
+ 34, -10, -10, -10, -10, 42, 19, 36, 43, -10,
+ -10
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
- -15, -15, -15, -6, 32, -15
+ -10, -10, -10, -6, 33, -10, 3
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
#define YYTABLE_NINF -1
static const yytype_uint8 yytable[] =
{
- 16, 2, 17, 18, 15, 3, 4, 5, 25, 6,
- 19, 26, 27, 20, 24, 17, 18, 3, 4, 5,
- 21, 6, 11, 12, 13, 14, 22, 3, 29, 23,
- 30, 31, 32, 33, 18, 34, 35, 36, 38, 40,
- 37, 39, 43, 41, 42, 44, 45, 46, 47, 0,
- 0, 28
+ 16, 25, 3, 4, 5, 15, 6, 19, 17, 18,
+ 2, 26, 27, 3, 4, 5, 20, 6, 11, 12,
+ 13, 14, 38, 17, 18, 39, 21, 22, 23, 24,
+ 3, 29, 30, 31, 32, 33, 18, 34, 35, 36,
+ 41, 42, 43, 44, 49, 47, 37, 46, 45, 48,
+ 0, 50, 28
};
-#define yypact_value_is_default(yystate) \
- ((yystate) == (-15))
+#define yypact_value_is_default(Yystate) \
+ (!!((Yystate) == (-10)))
-#define yytable_value_is_error(yytable_value) \
+#define yytable_value_is_error(Yytable_value) \
YYID (0)
static const yytype_int8 yycheck[] =
{
- 6, 0, 16, 17, 8, 4, 5, 6, 9, 8,
- 17, 17, 18, 15, 4, 16, 17, 4, 5, 6,
- 15, 8, 10, 11, 12, 13, 15, 4, 4, 15,
- 4, 4, 4, 14, 17, 15, 15, 15, 7, 3,
- 15, 8, 7, 9, 14, 8, 3, 9, 9, -1,
- -1, 19
+ 6, 8, 3, 4, 5, 7, 7, 16, 15, 16,
+ 0, 17, 18, 3, 4, 5, 14, 7, 9, 10,
+ 11, 12, 3, 15, 16, 6, 14, 14, 14, 3,
+ 3, 3, 3, 3, 3, 13, 16, 14, 14, 14,
+ 3, 3, 3, 3, 8, 3, 14, 13, 7, 46,
+ -1, 8, 19
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
- 0, 19, 0, 4, 5, 6, 8, 20, 21, 22,
- 23, 10, 11, 12, 13, 8, 21, 16, 17, 17,
- 15, 15, 15, 15, 4, 9, 21, 21, 22, 4,
- 4, 4, 4, 14, 15, 15, 15, 15, 7, 8,
- 3, 9, 14, 7, 8, 3, 9, 9
+ 0, 18, 0, 3, 4, 5, 7, 19, 20, 21,
+ 22, 9, 10, 11, 12, 7, 20, 15, 16, 16,
+ 14, 14, 14, 14, 3, 8, 20, 20, 21, 3,
+ 3, 3, 3, 13, 14, 14, 14, 14, 3, 6,
+ 23, 3, 3, 3, 3, 7, 13, 3, 23, 8,
+ 8
};
#define yyerrok (yyerrstatus = 0)
#define YYRECOVERING() (!!yyerrstatus)
-#define YYBACKUP(Token, Value) \
-do \
- if (yychar == YYEMPTY && yylen == 1) \
- { \
- yychar = (Token); \
- yylval = (Value); \
- YYPOPSTACK (1); \
- goto yybackup; \
- } \
- else \
- { \
+#define YYBACKUP(Token, Value) \
+do \
+ if (yychar == YYEMPTY) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ YYPOPSTACK (yylen); \
+ yystate = *yyssp; \
+ goto yybackup; \
+ } \
+ else \
+ { \
yyerror (YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (YYID (0))
-
+/* Error token number */
#define YYTERROR 1
#define YYERRCODE 256
-/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
- If N is 0, then set CURRENT to the empty location which ends
- the previous symbol: RHS[0] (always defined). */
-
-#define YYRHSLOC(Rhs, K) ((Rhs)[K])
-#ifndef YYLLOC_DEFAULT
-# define YYLLOC_DEFAULT(Current, Rhs, N) \
- do \
- if (YYID (N)) \
- { \
- (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
- (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
- (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
- (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
- } \
- else \
- { \
- (Current).first_line = (Current).last_line = \
- YYRHSLOC (Rhs, 0).last_line; \
- (Current).first_column = (Current).last_column = \
- YYRHSLOC (Rhs, 0).last_column; \
- } \
- while (YYID (0))
-#endif
-
-
/* This macro is provided for backward compatibility. */
-
#ifndef YY_LOCATION_PRINT
# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
#endif
/* YYLEX -- calling `yylex' with the right arguments. */
-
#ifdef YYLEX_PARAM
# define YYLEX yylex (YYLEX_PARAM)
#else
YYSTYPE const * const yyvaluep;
#endif
{
+ FILE *yyo = yyoutput;
+ YYUSE (yyo);
if (!yyvaluep)
return;
# ifdef YYPRINT
switch (yytype)
{
default:
- break;
+ break;
}
}
yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
yytype_int16 *yyssp, int yytoken)
{
- YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]);
+ YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]);
YYSIZE_T yysize = yysize0;
- YYSIZE_T yysize1;
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
/* Internationalized format string. */
- const char *yyformat = 0;
+ const char *yyformat = YY_NULL;
/* Arguments of yyformat. */
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
/* Number of reported tokens (one for the "unexpected", one per
break;
}
yyarg[yycount++] = yytname[yyx];
- yysize1 = yysize + yytnamerr (0, yytname[yyx]);
- if (! (yysize <= yysize1
- && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
- return 2;
- yysize = yysize1;
+ {
+ YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]);
+ if (! (yysize <= yysize1
+ && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
}
}
}
# undef YYCASE_
}
- yysize1 = yysize + yystrlen (yyformat);
- if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
- return 2;
- yysize = yysize1;
+ {
+ YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
+ if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM))
+ return 2;
+ yysize = yysize1;
+ }
if (*yymsg_alloc < yysize)
{
{
default:
- break;
+ break;
}
}
-/* Prevent warnings from -Wmissing-prototypes. */
-#ifdef YYPARSE_PARAM
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void *YYPARSE_PARAM);
-#else
-int yyparse ();
-#endif
-#else /* ! YYPARSE_PARAM */
-#if defined __STDC__ || defined __cplusplus
-int yyparse (void);
-#else
-int yyparse ();
-#endif
-#endif /* ! YYPARSE_PARAM */
/* The lookahead symbol. */
int yychar;
+
+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END
+#endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
+
/* The semantic value of the lookahead symbol. */
-YYSTYPE yylval;
+YYSTYPE yylval YY_INITIAL_VALUE(yyval_default);
/* Number of syntax errors so far. */
int yynerrs;
`yyss': related to states.
`yyvs': related to semantic values.
- Refer to the stacks thru separate pointers, to allow yyoverflow
+ Refer to the stacks through separate pointers, to allow yyoverflow
to reallocate them elsewhere. */
/* The state stack. */
int yyn;
int yyresult;
/* Lookahead token as an internal (translated) token number. */
- int yytoken;
+ int yytoken = 0;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
Keep to zero when no symbol should be popped. */
int yylen = 0;
- yytoken = 0;
- yyss = yyssa;
- yyvs = yyvsa;
+ yyssp = yyss = yyssa;
+ yyvsp = yyvs = yyvsa;
yystacksize = YYINITDEPTH;
YYDPRINTF ((stderr, "Starting parse\n"));
yyerrstatus = 0;
yynerrs = 0;
yychar = YYEMPTY; /* Cause a token to be read. */
-
- /* Initialize stack pointers.
- Waste one element of value and location stack
- so that they stay on the same level as the state stack.
- The wasted elements are never initialized. */
- yyssp = yyss;
- yyvsp = yyvs;
-
goto yysetstate;
/*------------------------------------------------------------.
yychar = YYEMPTY;
yystate = yyn;
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
goto yynewstate;
switch (yyn)
{
case 4:
-
-/* Line 1806 of yacc.c */
-#line 63 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 73 "spotlight_rawquery_parser.y"
{
ssp_result = talloc_asprintf(ssp_slq,
"SELECT DISTINCT ?url WHERE "
- "{ ?x nie:url ?url FILTER(fn:starts-with(?url, 'file://%s/')) . %s}",
+ "{ ?obj nie:url ?url FILTER(regex(?url, '^file://%s/')) . %s}",
ssp_slq->slq_vol->v_path, (yyvsp[(1) - (1)].sval));
(yyval.sval) = ssp_result;
}
break;
case 5:
-
-/* Line 1806 of yacc.c */
-#line 73 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 83 "spotlight_rawquery_parser.y"
{
if ((yyvsp[(1) - (1)].bval) == false)
YYACCEPT;
break;
case 6:
-
-/* Line 1806 of yacc.c */
-#line 79 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 89 "spotlight_rawquery_parser.y"
{
if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0)
(yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
break;
case 7:
-
-/* Line 1806 of yacc.c */
-#line 85 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 95 "spotlight_rawquery_parser.y"
{(yyval.sval) = (yyvsp[(1) - (1)].sval); if ((yyval.sval) == NULL) YYABORT;}
break;
case 8:
-
-/* Line 1806 of yacc.c */
-#line 86 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 96 "spotlight_rawquery_parser.y"
{(yyval.sval) = (yyvsp[(1) - (1)].sval);}
break;
case 9:
-
-/* Line 1806 of yacc.c */
-#line 87 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 97 "spotlight_rawquery_parser.y"
{(yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(2) - (3)].sval));}
break;
case 10:
-
-/* Line 1806 of yacc.c */
-#line 88 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 98 "spotlight_rawquery_parser.y"
{(yyval.sval) = talloc_asprintf(ssp_slq, "%s . %s", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));}
break;
case 11:
-
-/* Line 1806 of yacc.c */
-#line 89 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 99 "spotlight_rawquery_parser.y"
{
if (strcmp((yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval)) != 0)
(yyval.sval) = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));
break;
case 12:
-
-/* Line 1806 of yacc.c */
-#line 98 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 108 "spotlight_rawquery_parser.y"
{(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '=', (yyvsp[(4) - (5)].sval));}
break;
case 13:
-
-/* Line 1806 of yacc.c */
-#line 99 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 109 "spotlight_rawquery_parser.y"
{(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '!', (yyvsp[(4) - (5)].sval));}
break;
case 14:
-
-/* Line 1806 of yacc.c */
-#line 100 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 110 "spotlight_rawquery_parser.y"
{(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '<', (yyvsp[(4) - (5)].sval));}
break;
case 15:
-
-/* Line 1806 of yacc.c */
-#line 101 "spotlight_rawquery_parser.y"
+/* Line 1792 of yacc.c */
+#line 111 "spotlight_rawquery_parser.y"
{(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '>', (yyvsp[(4) - (5)].sval));}
break;
case 16:
+/* Line 1792 of yacc.c */
+#line 112 "spotlight_rawquery_parser.y"
+ {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '=', (yyvsp[(4) - (6)].sval));}
+ break;
-/* Line 1806 of yacc.c */
-#line 105 "spotlight_rawquery_parser.y"
- {(yyval.sval) = map_daterange((yyvsp[(3) - (14)].sval), (yyvsp[(7) - (14)].sval), (yyvsp[(12) - (14)].sval));}
+ case 17:
+/* Line 1792 of yacc.c */
+#line 113 "spotlight_rawquery_parser.y"
+ {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '!', (yyvsp[(4) - (6)].sval));}
break;
+ case 18:
+/* Line 1792 of yacc.c */
+#line 114 "spotlight_rawquery_parser.y"
+ {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '<', (yyvsp[(4) - (6)].sval));}
+ break;
+ case 19:
+/* Line 1792 of yacc.c */
+#line 115 "spotlight_rawquery_parser.y"
+ {(yyval.sval) = map_expr((yyvsp[(1) - (6)].sval), '>', (yyvsp[(4) - (6)].sval));}
+ break;
-/* Line 1806 of yacc.c */
-#line 1563 "spotlight_rawquery_parser.c"
+ case 20:
+/* Line 1792 of yacc.c */
+#line 119 "spotlight_rawquery_parser.y"
+ {(yyval.sval) = map_daterange((yyvsp[(3) - (8)].sval), (yyvsp[(5) - (8)].tval), (yyvsp[(7) - (8)].tval));}
+ break;
+
+ case 21:
+/* Line 1792 of yacc.c */
+#line 123 "spotlight_rawquery_parser.y"
+ {(yyval.tval) = isodate2unix((yyvsp[(3) - (4)].sval));}
+ break;
+
+ case 22:
+/* Line 1792 of yacc.c */
+#line 124 "spotlight_rawquery_parser.y"
+ {(yyval.tval) = atoi((yyvsp[(1) - (1)].sval)) + SPRAW_TIME_OFFSET;}
+ break;
+
+
+/* Line 1792 of yacc.c */
+#line 1585 "spotlight_rawquery_parser.c"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
YY_STACK_PRINT (yyss, yyssp);
}
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
*++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
/* Shift the error token. */
yyresult = 1;
goto yyreturn;
-#if !defined(yyoverflow) || YYERROR_VERBOSE
+#if !defined yyoverflow || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
}
+/* Line 2055 of yacc.c */
+#line 127 "spotlight_rawquery_parser.y"
-/* Line 2067 of yacc.c */
-#line 108 "spotlight_rawquery_parser.y"
+static time_t isodate2unix(const char *s)
+{
+ struct tm tm;
+
+ if (strptime(s, "%Y-%m-%dT%H:%M:%SZ", &tm) == NULL)
+ return (time_t)-1;
+ return mktime(&tm);
+}
-const char *map_daterange(const char *dateattr, const char *date1, const char *date2)
+const char *map_daterange(const char *dateattr, time_t date1, time_t date2)
{
+ EC_INIT;
char *result = NULL;
struct spotlight_sparql_map *p;
+ struct tm *tmp;
+ char buf1[64], buf2[64];
+
+ EC_NULL_LOG( tmp = localtime(&date1) );
+ strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
+ EC_NULL_LOG( tmp = localtime(&date2) );
+ strftime(buf2, sizeof(buf2), "%Y-%m-%dT%H:%M:%SZ", tmp);
for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
if (strcmp(dateattr, p->ssm_spotlight_attr) == 0) {
result = talloc_asprintf(ssp_slq,
- "?x %s ?d FILTER (?d > '%s' && ?d < '%s')",
+ "?obj %s ?%c FILTER (?%c > '%s' && ?%c < '%s')",
p->ssm_sparql_attr,
- date1,
- date2);
+ sparqlvar,
+ sparqlvar,
+ buf1,
+ sparqlvar,
+ buf2);
+ sparqlvar++;
+ break;
}
}
+EC_CLEANUP:
+ if (ret != 0)
+ return NULL;
+ return result;
+}
+
+static char *map_type_search(const char *attr, char op, const char *val)
+{
+ char *result = NULL;
+ const char *sparqlAttr;
+ for (struct MDTypeMap *p = MDTypeMap; p->mdtm_value; p++) {
+ if (strcmp(p->mdtm_value, val) == 0) {
+ switch (p->mdtm_type) {
+ case kMDTypeMapRDF:
+ sparqlAttr = "rdf:type";
+ break;
+ case kMDTypeMapMime:
+ sparqlAttr = "nie:mimeType";
+ break;
+ default:
+ return NULL;
+ }
+ result = talloc_asprintf(ssp_slq, "?obj %s '%s'",
+ sparqlAttr,
+ p->mdtm_sparql);
+ break;
+ }
+ }
return result;
}
EC_INIT;
char *result = NULL;
struct spotlight_sparql_map *p;
+ time_t t;
+ struct tm *tmp;
+ char buf1[64];
+ bstring q = NULL, search = NULL, replace = NULL;
for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
- if (strcmp(p->ssm_spotlight_attr, attr) == 0) {
+ if (p->ssm_sparql_attr && strcmp(p->ssm_spotlight_attr, attr) == 0) {
switch (p->ssm_type) {
case ssmt_bool:
- result = talloc_asprintf(ssp_slq, "?x %s '%s'", p->ssm_sparql_attr, val);
+ result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val);
break;
case ssmt_num:
- result = talloc_asprintf(ssp_slq, "?x %s ?y FILTER(?y %c '%s')", p->ssm_sparql_attr, op, val);
+ result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c%c '%s')",
+ p->ssm_sparql_attr,
+ sparqlvar,
+ sparqlvar,
+ op,
+ op == '!' ? '=' : ' ', /* append '=' to '!' */
+ val);
+ sparqlvar++;
break;
case ssmt_str:
- result = talloc_asprintf(ssp_slq, "?x %s ?y FILTER(regex(?y, '%s'))", p->ssm_sparql_attr, val);
+ q = bformat("^%s$", val);
+ search = bfromcstr("*");
+ replace = bfromcstr(".*");
+ bfindreplace(q, search, replace, 0);
+ result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(regex(?%c, '%s'))",
+ p->ssm_sparql_attr,
+ sparqlvar,
+ sparqlvar,
+ bdata(q));
+ sparqlvar++;
break;
case ssmt_fts:
- result = talloc_asprintf(ssp_slq, "?x %s '%s'", p->ssm_sparql_attr, val);
+ result = talloc_asprintf(ssp_slq, "?obj %s '%s'", p->ssm_sparql_attr, val);
break;
case ssmt_date:
- yyerror("enexpected ssmt_date");
- EC_FAIL;
+ t = atoi(val) + SPRAW_TIME_OFFSET;
+ EC_NULL( tmp = localtime(&t) );
+ strftime(buf1, sizeof(buf1), "%Y-%m-%dT%H:%M:%SZ", tmp);
+ result = talloc_asprintf(ssp_slq, "?obj %s ?%c FILTER(?%c %c '%s')",
+ p->ssm_sparql_attr,
+ sparqlvar,
+ sparqlvar,
+ op,
+ buf1);
+ sparqlvar++;
+ break;
+ case ssmt_type:
+ result = map_type_search(attr, op, val);
+ break;
default:
yyerror("unknown Spotlight attribute type");
EC_FAIL;
}
EC_CLEANUP:
+ if (q)
+ bdestroy(q);
+ if (search)
+ bdestroy(search);
+ if (replace)
+ bdestroy(replace);
return result;
}
ssp_slq = slq;
s = yy_scan_string(slq->slq_qstring);
+ sparqlvar = 'a';
EC_ZERO( yyparse() );
struct vol *vol = talloc_zero(ssp_slq, struct vol);
vol->v_path = "/Volumes/test";
ssp_slq->slq_vol = vol;
+ sparqlvar = 'a';
s = yy_scan_string(argv[1]);
return 0;
}
#endif
-