]> arthur.barton.de Git - netatalk.git/commitdiff
Various fixes
authorFrank Lahm <franklahm@googlemail.com>
Thu, 1 Nov 2012 11:32:38 +0000 (12:32 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Thu, 1 Nov 2012 11:32:38 +0000 (12:32 +0100)
etc/afpd/spotlight_SPARQL_map.c
etc/afpd/spotlight_module.c
etc/afpd/spotlight_rawquery_lexer.c
etc/afpd/spotlight_rawquery_lexer.l
etc/afpd/spotlight_rawquery_parser.c
etc/afpd/spotlight_rawquery_parser.h
etc/afpd/spotlight_rawquery_parser.y

index faf3bca1b6bd9b567c0eaf9e9050531a09c9d621..553e7639c7a840a6bc47ae34399910d1171c846e 100644 (file)
 #include "spotlight_SPARQL_map.h"
 
 struct spotlight_sparql_map spotlight_sparql_map[] = {
+/*   ssm_spotlight_attr                    ssm_sparql_attr              ssm_sparql_query_fmtstr */
     {"*",                                  "fts:match",                 "?x fts:match '%s'"},
     {"kMDItemTextContent",                 "fts:match",                 "?x fts:match '%s'"},
-    {"kMDItemDisplayName",                 "nfo:fileName",              "?x nfo:fileName ?name FILTER(regex(?name, '%s'))"},
+    {"kMDItemDisplayName",                 "nfo:fileName",              "?x nfo:fileName ?y FILTER(regex(?y, '%s'))"},
     {"kMDItemContentCreationDate",         "nfo:fileCreated",           "?x nfo:fileCreated '%s'"},
     {"kMDItemFSContentChangeDate",         "nfo:fileLastModified",      "?x nfo:fileLastModified '%s'"},
     {"kMDItemContentModificationDate",     "nfo:fileLastModified",      "?x nfo:fileLastModified '%s'"},
index 90225721b4213a2813abdfba2f4106d22f6c16c6..5369319ce185eb5048dce8bd3ffa79164b41a1c1 100644 (file)
@@ -118,12 +118,13 @@ static int sl_mod_start_search(void *p)
 {
     EC_INIT;
     slq_t *slq = p; 
-    const gchar *sparql_query;
+    gchar *sparql_query;
     GError *error = NULL;
 
     LOG(log_debug, logtype_sl, "sl_mod_start_search: Spotlight query string: \"%s\"", slq->slq_qstring);
 
-    EC_NULL_LOG( sparql_query = map_spotlight_to_sparql_query(slq) );
+    EC_ZERO_LOGSTR( map_spotlight_to_sparql_query(slq, &sparql_query),
+                    "Mapping Spotlight query failed: \"%s\"", slq->slq_qstring );
     LOG(log_debug, logtype_sl, "sl_mod_start_search: SPARQL query: \"%s\"", sparql_query);
 
 #if 0
index 8cb944bbd6f504779e542a01d13b2800e96281b9..59c123b535b7425094655592bbeb7b96df30b42f 100644 (file)
@@ -359,8 +359,8 @@ static void yy_fatal_error (yyconst char msg[]  );
        *yy_cp = '\0'; \
        (yy_c_buf_p) = yy_cp;
 
-#define YY_NUM_RULES 14
-#define YY_END_OF_BUFFER 15
+#define YY_NUM_RULES 20
+#define YY_END_OF_BUFFER 21
 /* This struct is not used in this scanner,
    but its presence is necessary. */
 struct yy_trans_info
@@ -368,14 +368,16 @@ struct yy_trans_info
        flex_int32_t yy_verify;
        flex_int32_t yy_nxt;
        };
-static yyconst flex_int16_t yy_accept[61] =
+static yyconst flex_int16_t yy_accept[75] =
     {   0,
-        0,    0,   15,   14,   13,   13,    6,   14,   14,    7,
-        8,    5,   12,   14,    5,    5,   14,    0,    0,    9,
-        5,   11,    5,    5,   10,    0,    0,    5,    5,    4,
-        0,    0,    5,    5,    0,    0,    5,    5,    0,    0,
-        5,    0,    0,    1,    0,    0,    0,    2,    0,    0,
-        0,    0,    0,    0,    0,    0,    0,    0,    3,    0
+        0,    0,   21,   20,   17,   17,   20,    7,   20,   20,
+        8,    9,    6,   16,   14,   20,   15,    6,    6,    6,
+        6,   20,    0,   13,    0,   10,    6,   12,    6,    6,
+        6,    6,    6,   11,    0,    0,    6,    6,    6,    6,
+        6,    0,    0,    6,    6,    6,    5,    0,    0,    6,
+        6,    4,    0,    0,    6,    0,    0,    1,    0,    0,
+        0,    2,    0,    0,    0,    0,    0,    0,    0,    0,
+        0,    0,    3,    0
     } ;
 
 static yyconst flex_int32_t yy_ec[256] =
@@ -383,17 +385,17 @@ static yyconst flex_int32_t yy_ec[256] =
         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,    2,    1,    4,    1,    5,    1,    6,    1,    7,
-        8,    9,    1,   10,   11,   12,    1,    1,    1,    1,
-        1,    1,    1,    1,    1,    1,    1,   13,    1,    1,
-       14,    1,    1,    1,    9,    9,    9,    9,    9,    9,
-        9,    9,   15,    9,    9,    9,    9,    9,    9,    9,
-        9,   16,    9,   17,    9,    9,    9,    9,    9,   18,
-        1,    1,    1,    1,    1,    1,   19,    9,   20,   21,
-
-       22,    9,   23,    9,   24,    9,    9,    9,   25,   26,
-       27,    9,    9,    9,   28,   29,    9,    9,   30,    9,
-        9,    9,    1,   31,    1,    1,    1,    1,    1,    1,
+        1,    2,    4,    5,    1,    6,    1,    7,    1,    8,
+        9,   10,    1,   11,   12,   13,    1,    1,    1,    1,
+        1,    1,    1,    1,    1,    1,    1,   14,    1,   15,
+       16,   17,    1,    1,   10,   10,   10,   10,   10,   10,
+       10,   10,   18,   10,   10,   10,   10,   10,   10,   10,
+       10,   19,   10,   20,   10,   10,   10,   10,   10,   21,
+        1,    1,    1,    1,    1,    1,   22,   10,   23,   24,
+
+       25,   26,   27,   10,   28,   10,   10,   29,   30,   31,
+       32,   10,   10,   33,   34,   35,   36,   10,   37,   10,
+       10,   10,    1,   38,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
@@ -410,92 +412,104 @@ static yyconst flex_int32_t yy_ec[256] =
         1,    1,    1,    1,    1
     } ;
 
-static yyconst flex_int32_t yy_meta[32] =
+static yyconst flex_int32_t yy_meta[39] =
     {   0,
-        1,    1,    2,    1,    1,    1,    1,    1,    3,    1,
-        3,    1,    1,    1,    3,    3,    3,    3,    3,    3,
+        1,    1,    2,    1,    1,    1,    1,    1,    1,    3,
+        1,    3,    1,    1,    1,    1,    1,    3,    3,    3,
         3,    3,    3,    3,    3,    3,    3,    3,    3,    3,
-        1
+        3,    3,    3,    3,    3,    3,    3,    1
     } ;
 
-static yyconst flex_int16_t yy_base[75] =
+static yyconst flex_int16_t yy_base[89] =
     {   0,
-        0,    0,  181,    0,    0,  182,    0,  150,  170,    0,
-        0,   31,    0,  159,  144,  137,  133,    0,  137,    0,
-       62,    0,  142,  134,    0,    0,  127,   93,  130,    0,
-      135,  114,  132,  115,    0,  126,  126,  116,    0,  111,
-      118,  123,  105,  121,    0,  104,    0,  182,  113,    0,
-        0,  115,    0,    0,   83,    0,    0,   47,  182,  182,
-      141,  144,  147,   31,  150,  153,  156,  159,  162,  165,
-      168,  171,  174,  177
+        0,    0,  212,    0,    0,  226,  193,    0,  171,  196,
+        0,    0,   38,    0,    0,  184,    0,  166,   53,  172,
+      158,  150,    0,    0,  157,    0,   90,    0,  163,    0,
+      156,  150,  142,    0,    0,  147,  128,  154,    0,  141,
+      149,  161,   68,  160,  155,  156,  159,    0,  118,   77,
+      157,   76,    0,   59,  158,   74,   51,   72,    0,   51,
+        0,  226,   62,    0,    0,   67,    0,    0,   65,    0,
+        0,   57,  226,  226,  186,  189,  192,   38,  195,  198,
+      201,  204,  207,  210,  213,  216,  219,  222
     } ;
 
-static yyconst flex_int16_t yy_def[75] =
+static yyconst flex_int16_t yy_def[89] =
     {   0,
-       60,    1,   60,   61,   61,   60,   61,   61,   61,   61,
-       61,   60,   61,   61,   12,   12,   61,   62,   62,   62,
-       60,   62,   21,   21,   62,   63,   63,   60,   28,   28,
-       60,   60,   64,   64,   65,   60,   64,   64,   66,   60,
-       64,   60,   60,   64,   67,   60,   68,   60,   60,   69,
-       70,   60,   71,   72,   60,   73,   74,   60,   60,    0,
-       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
-       60,   60,   60,   60
+       74,    1,   74,   75,   75,   74,   75,   75,   75,   75,
+       75,   75,   74,   75,   75,   75,   75,   13,   13,   13,
+       13,   75,   76,   76,   76,   76,   74,   76,   27,   27,
+       27,   27,   27,   76,   77,   77,   74,   37,   37,   37,
+       37,   74,   74,   78,   78,   78,   78,   79,   74,   78,
+       78,   78,   80,   74,   78,   74,   74,   78,   81,   74,
+       82,   74,   74,   83,   84,   74,   85,   86,   74,   87,
+       88,   74,   74,    0,   74,   74,   74,   74,   74,   74,
+       74,   74,   74,   74,   74,   74,   74,   74
     } ;
 
-static yyconst flex_int16_t yy_nxt[214] =
+static yyconst flex_int16_t yy_nxt[265] =
     {   0,
         4,    5,    6,    7,    8,    9,   10,   11,   12,   13,
-        4,    4,    4,   14,   15,   12,   12,   12,   12,   16,
-       12,   12,   12,   12,   12,   12,   12,   12,   12,   12,
-       17,   18,   18,   37,   18,   18,   18,   18,   18,   21,
-       18,   18,   18,   18,   18,   21,   21,   21,   21,   21,
-       21,   21,   21,   21,   21,   21,   21,   21,   21,   21,
-       21,   18,   26,   26,   59,   26,   26,   26,   26,   26,
-       28,   26,   26,   26,   26,   26,   28,   28,   28,   28,
-       28,   28,   28,   28,   28,   28,   28,   28,   28,   28,
-       28,   28,   26,   31,   31,   56,   31,   31,   31,   31,
-
-       31,   33,   31,   31,   31,   31,   31,   33,   33,   33,
-       33,   33,   33,   33,   33,   33,   33,   33,   33,   33,
-       33,   33,   33,   31,   35,   35,   60,   53,   60,   50,
-       48,   60,   46,   45,   43,   36,   60,   40,   41,   44,
-       38,   18,   35,   18,   26,   35,   26,   31,   34,   31,
-       39,   32,   39,   42,   30,   42,   47,   29,   47,   49,
-       27,   49,   51,   25,   51,   52,   24,   52,   54,   23,
-       54,   55,   22,   55,   57,   20,   57,   58,   19,   58,
-       60,    3,   60,   60,   60,   60,   60,   60,   60,   60,
-       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
-
-       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
-       60,   60,   60
+       14,    4,    4,    4,   15,   16,   17,   18,   13,   13,
+       13,   13,   19,   13,   13,   20,   13,   13,   13,   13,
+       13,   13,   13,   13,   21,   13,   13,   22,   23,   23,
+       50,   23,   23,   23,   23,   23,   23,   27,   23,   23,
+       23,   23,   23,   23,   23,   27,   27,   27,   27,   27,
+       27,   27,   27,   27,   27,   27,   27,   27,   27,   27,
+       27,   27,   27,   27,   27,   23,   30,   73,   70,   48,
+       67,   64,   62,   74,   60,   59,   57,   74,   74,   31,
+       35,   35,   49,   35,   35,   35,   35,   35,   35,   37,
+
+       35,   35,   35,   35,   35,   35,   35,   37,   37,   37,
+       37,   37,   37,   37,   37,   37,   37,   37,   37,   37,
+       37,   37,   37,   37,   37,   37,   37,   35,   42,   42,
+       54,   42,   42,   42,   42,   42,   42,   44,   42,   42,
+       42,   42,   42,   42,   42,   44,   44,   44,   44,   44,
+       44,   44,   44,   44,   44,   44,   44,   44,   44,   44,
+       44,   44,   44,   44,   44,   42,   48,   48,   74,   74,
+       48,   48,   48,   47,   46,   45,   43,   41,   40,   39,
+       52,   38,   58,   55,   36,   51,   23,   34,   23,   35,
+       33,   35,   42,   32,   42,   53,   29,   53,   56,   28,
+
+       56,   61,   26,   61,   63,   25,   63,   65,   24,   65,
+       66,   74,   66,   68,   74,   68,   69,   74,   69,   71,
+       74,   71,   72,   74,   72,    3,   74,   74,   74,   74,
+       74,   74,   74,   74,   74,   74,   74,   74,   74,   74,
+       74,   74,   74,   74,   74,   74,   74,   74,   74,   74,
+       74,   74,   74,   74,   74,   74,   74,   74,   74,   74,
+       74,   74,   74,   74
     } ;
 
-static yyconst flex_int16_t yy_chk[214] =
+static yyconst flex_int16_t yy_chk[265] =
     {   0,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
-        1,   12,   12,   64,   12,   12,   12,   12,   12,   12,
-       12,   12,   12,   12,   12,   12,   12,   12,   12,   12,
-       12,   12,   12,   12,   12,   12,   12,   12,   12,   12,
-       12,   12,   21,   21,   58,   21,   21,   21,   21,   21,
-       21,   21,   21,   21,   21,   21,   21,   21,   21,   21,
-       21,   21,   21,   21,   21,   21,   21,   21,   21,   21,
-       21,   21,   21,   28,   28,   55,   28,   28,   28,   28,
-
-       28,   28,   28,   28,   28,   28,   28,   28,   28,   28,
-       28,   28,   28,   28,   28,   28,   28,   28,   28,   28,
-       28,   28,   28,   28,   32,   34,   38,   52,   41,   49,
-       46,   44,   43,   42,   40,   32,   37,   36,   38,   41,
-       34,   61,   33,   61,   62,   31,   62,   63,   29,   63,
-       65,   27,   65,   66,   24,   66,   67,   23,   67,   68,
-       19,   68,   69,   17,   69,   70,   16,   70,   71,   15,
-       71,   72,   14,   72,   73,    9,   73,   74,    8,   74,
-        3,   60,   60,   60,   60,   60,   60,   60,   60,   60,
-       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
-
-       60,   60,   60,   60,   60,   60,   60,   60,   60,   60,
-       60,   60,   60
+        1,    1,    1,    1,    1,    1,    1,    1,   13,   13,
+       78,   13,   13,   13,   13,   13,   13,   13,   13,   13,
+       13,   13,   13,   13,   13,   13,   13,   13,   13,   13,
+       13,   13,   13,   13,   13,   13,   13,   13,   13,   13,
+       13,   13,   13,   13,   13,   13,   19,   72,   69,   43,
+       66,   63,   60,   58,   57,   56,   54,   52,   50,   19,
+       27,   27,   43,   27,   27,   27,   27,   27,   27,   27,
+
+       27,   27,   27,   27,   27,   27,   27,   27,   27,   27,
+       27,   27,   27,   27,   27,   27,   27,   27,   27,   27,
+       27,   27,   27,   27,   27,   27,   27,   27,   37,   37,
+       49,   37,   37,   37,   37,   37,   37,   37,   37,   37,
+       37,   37,   37,   37,   37,   37,   37,   37,   37,   37,
+       37,   37,   37,   37,   37,   37,   37,   37,   37,   37,
+       37,   37,   37,   37,   37,   37,   45,   46,   51,   55,
+       47,   44,   42,   41,   40,   38,   36,   33,   32,   31,
+       46,   29,   55,   51,   25,   45,   75,   22,   75,   76,
+       21,   76,   77,   20,   77,   79,   18,   79,   80,   16,
+
+       80,   81,   10,   81,   82,    9,   82,   83,    7,   83,
+       84,    3,   84,   85,    0,   85,   86,    0,   86,   87,
+        0,   87,   88,    0,   88,   74,   74,   74,   74,   74,
+       74,   74,   74,   74,   74,   74,   74,   74,   74,   74,
+       74,   74,   74,   74,   74,   74,   74,   74,   74,   74,
+       74,   74,   74,   74,   74,   74,   74,   74,   74,   74,
+       74,   74,   74,   74
     } ;
 
 static yy_state_type yy_last_accepting_state;
@@ -515,11 +529,12 @@ char *yytext;
 #line 1 "spotlight_rawquery_lexer.l"
 #line 2 "spotlight_rawquery_lexer.l"
 #include <string.h>
+#include <stdbool.h>
 #include <gio/gio.h>
 #include <atalk/talloc.h>
 #include "spotlight.h"
 #include "spotlight_rawquery_parser.h"
-#line 523 "spotlight_rawquery_lexer.c"
+#line 538 "spotlight_rawquery_lexer.c"
 
 #define INITIAL 0
 
@@ -701,9 +716,9 @@ YY_DECL
        register char *yy_cp, *yy_bp;
        register int yy_act;
     
-#line 9 "spotlight_rawquery_lexer.l"
+#line 10 "spotlight_rawquery_lexer.l"
 
-#line 707 "spotlight_rawquery_lexer.c"
+#line 722 "spotlight_rawquery_lexer.c"
 
        if ( !(yy_init) )
                {
@@ -756,13 +771,13 @@ yy_match:
                        while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                                {
                                yy_current_state = (int) yy_def[yy_current_state];
-                               if ( yy_current_state >= 61 )
+                               if ( yy_current_state >= 75 )
                                        yy_c = yy_meta[(unsigned int) yy_c];
                                }
                        yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
                        ++yy_cp;
                        }
-               while ( yy_base[yy_current_state] != 182 );
+               while ( yy_base[yy_current_state] != 226 );
 
 yy_find_action:
                yy_act = yy_accept[yy_current_state];
@@ -788,76 +803,106 @@ do_action:       /* This label is used only to access EOF actions. */
 
 case 1:
 YY_RULE_SETUP
-#line 10 "spotlight_rawquery_lexer.l"
+#line 11 "spotlight_rawquery_lexer.l"
 return FUNC_INRANGE;
        YY_BREAK
 case 2:
 YY_RULE_SETUP
-#line 11 "spotlight_rawquery_lexer.l"
+#line 12 "spotlight_rawquery_lexer.l"
 return DATE_SPEC;
        YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 12 "spotlight_rawquery_lexer.l"
+#line 13 "spotlight_rawquery_lexer.l"
 {yylval.sval = talloc_strdup(ssp_slq, yytext); return DATE;}
        YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 13 "spotlight_rawquery_lexer.l"
-/* ignore case specifier */
+#line 14 "spotlight_rawquery_lexer.l"
+{yylval.bval = false; return BOOL;}
        YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 14 "spotlight_rawquery_lexer.l"
-{yylval.sval = talloc_strdup(ssp_slq, yytext); return WORD;}
+#line 15 "spotlight_rawquery_lexer.l"
+{yylval.bval = true; return BOOL;}
        YY_BREAK
 case 6:
 YY_RULE_SETUP
-#line 15 "spotlight_rawquery_lexer.l"
-return QUOTE;
+#line 16 "spotlight_rawquery_lexer.l"
+{yylval.sval = talloc_strdup(ssp_slq, yytext); return WORD;}
        YY_BREAK
 case 7:
 YY_RULE_SETUP
-#line 16 "spotlight_rawquery_lexer.l"
-return OBRACE;
+#line 17 "spotlight_rawquery_lexer.l"
+return QUOTE;
        YY_BREAK
 case 8:
 YY_RULE_SETUP
-#line 17 "spotlight_rawquery_lexer.l"
-return CBRACE;
+#line 18 "spotlight_rawquery_lexer.l"
+return OBRACE;
        YY_BREAK
 case 9:
 YY_RULE_SETUP
-#line 18 "spotlight_rawquery_lexer.l"
-return AND;
+#line 19 "spotlight_rawquery_lexer.l"
+return CBRACE;
        YY_BREAK
 case 10:
 YY_RULE_SETUP
-#line 19 "spotlight_rawquery_lexer.l"
-return OR;
+#line 20 "spotlight_rawquery_lexer.l"
+return AND;
        YY_BREAK
 case 11:
 YY_RULE_SETUP
-#line 20 "spotlight_rawquery_lexer.l"
-return EQUAL;
+#line 21 "spotlight_rawquery_lexer.l"
+return OR;
        YY_BREAK
 case 12:
 YY_RULE_SETUP
-#line 21 "spotlight_rawquery_lexer.l"
-return COMMA;
+#line 22 "spotlight_rawquery_lexer.l"
+return EQUAL;
        YY_BREAK
 case 13:
-/* rule 13 can match eol */
 YY_RULE_SETUP
-#line 22 "spotlight_rawquery_lexer.l"
-/* ignore */
+#line 23 "spotlight_rawquery_lexer.l"
+return UNEQUAL;
        YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 23 "spotlight_rawquery_lexer.l"
+#line 24 "spotlight_rawquery_lexer.l"
+return LT;
+       YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 25 "spotlight_rawquery_lexer.l"
+return GT;
+       YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 26 "spotlight_rawquery_lexer.l"
+return COMMA;
+       YY_BREAK
+case 17:
+/* rule 17 can match eol */
+YY_RULE_SETUP
+#line 27 "spotlight_rawquery_lexer.l"
+/* ignore */
+       YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 28 "spotlight_rawquery_lexer.l"
+/* ignore case specifier */
+       YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 29 "spotlight_rawquery_lexer.l"
+/* ignore */
+       YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 30 "spotlight_rawquery_lexer.l"
 ECHO;
        YY_BREAK
-#line 861 "spotlight_rawquery_lexer.c"
+#line 906 "spotlight_rawquery_lexer.c"
 case YY_STATE_EOF(INITIAL):
        yyterminate();
 
@@ -1149,7 +1194,7 @@ static int yy_get_next_buffer (void)
                while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                        {
                        yy_current_state = (int) yy_def[yy_current_state];
-                       if ( yy_current_state >= 61 )
+                       if ( yy_current_state >= 75 )
                                yy_c = yy_meta[(unsigned int) yy_c];
                        }
                yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@@ -1177,11 +1222,11 @@ static int yy_get_next_buffer (void)
        while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
                {
                yy_current_state = (int) yy_def[yy_current_state];
-               if ( yy_current_state >= 61 )
+               if ( yy_current_state >= 75 )
                        yy_c = yy_meta[(unsigned int) yy_c];
                }
        yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
-       yy_is_jam = (yy_current_state == 60);
+       yy_is_jam = (yy_current_state == 74);
 
        return yy_is_jam ? 0 : yy_current_state;
 }
@@ -1855,7 +1900,7 @@ void yyfree (void * ptr )
 
 #define YYTABLES_NAME "yytables"
 
-#line 23 "spotlight_rawquery_lexer.l"
+#line 30 "spotlight_rawquery_lexer.l"
 
 
 
index 66f27d4c92c21233c7ae311e303303d3127999f6..6bc87e2c143d1c7d5b56f2787014dd7e174ebd9f 100644 (file)
@@ -1,5 +1,6 @@
 %{
 #include <string.h>
+#include <stdbool.h>
 #include <gio/gio.h>
 #include <atalk/talloc.h>
 #include "spotlight.h"
@@ -10,7 +11,8 @@
 InRange                               return FUNC_INRANGE;
 \$time\.iso                           return DATE_SPEC;
 ....-..-..T..:..:..Z                  {yylval.sval = talloc_strdup(ssp_slq, yytext); return DATE;}
-cwd                                   /* ignore case specifier */
+false                                 {yylval.bval = false; return BOOL;}
+true                                  {yylval.bval = true; return BOOL;}
 [a-zA-Z\*]+                           {yylval.sval = talloc_strdup(ssp_slq, yytext); return WORD;}
 \"                                    return QUOTE;
 \(                                    return OBRACE;
@@ -18,6 +20,11 @@ cwd                                   /* ignore case specifier */
 \&\&                                  return AND;
 \|\|                                  return OR;
 \=\=                                  return EQUAL;
+!\=                                   return UNEQUAL;
+\<                                    return LT;
+\>                                    return GT;
 \,                                    return COMMA;
 [ \t\n]                               /* ignore */
+cwd                                   /* ignore case specifier */
+cd                                    /* ignore */
 %%
index 0cb2b6a4dfee44a9e09fdb21a2e22dc440c5c9f6..1dbe989ec5ab69efa101ce5d93f7ce6e27cb8003 100644 (file)
   extern YY_BUFFER_STATE yy_scan_string( const char *str);
   extern void yy_delete_buffer ( YY_BUFFER_STATE buffer );
 
-  static const char *map_expr(const char *attr, const char *val);
+  /* 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 */
   slq_t *ssp_slq;
-  gchar *ssp_result;
+
+  /* local vars */
+  static gchar *ssp_result;
 
 
 
 /* Line 268 of yacc.c  */
-#line 99 "spotlight_rawquery_parser.c"
+#line 103 "spotlight_rawquery_parser.c"
 
 /* Enabling traces.  */
 #ifndef YYDEBUG
    enum yytokentype {
      DATE = 258,
      WORD = 259,
-     FUNC_INRANGE = 260,
-     DATE_SPEC = 261,
-     OBRACE = 262,
-     CBRACE = 263,
-     EQUAL = 264,
-     COMMA = 265,
-     QUOTE = 266,
-     AND = 267,
-     OR = 268
+     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
    };
 #endif
 /* Tokens.  */
 #define DATE 258
 #define WORD 259
-#define FUNC_INRANGE 260
-#define DATE_SPEC 261
-#define OBRACE 262
-#define CBRACE 263
-#define EQUAL 264
-#define COMMA 265
-#define QUOTE 266
-#define AND 267
-#define OR 268
+#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
 
 
 
@@ -156,15 +168,16 @@ typedef union YYSTYPE
 {
 
 /* Line 293 of yacc.c  */
-#line 34 "spotlight_rawquery_parser.y"
+#line 37 "spotlight_rawquery_parser.y"
 
     int ival;
     const char *sval;
+    bool bval;
 
 
 
 /* Line 293 of yacc.c  */
-#line 168 "spotlight_rawquery_parser.c"
+#line 181 "spotlight_rawquery_parser.c"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -174,22 +187,21 @@ typedef union YYSTYPE
 /* "%code provides" blocks.  */
 
 /* Line 340 of yacc.c  */
-#line 28 "spotlight_rawquery_parser.y"
+#line 32 "spotlight_rawquery_parser.y"
 
-  extern const gchar *map_spotlight_to_sparql_query(slq_t *slq);
+  extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result);
   extern slq_t *ssp_slq;
-  extern gchar *ssp_result;
 
 
 
 /* Line 340 of yacc.c  */
-#line 187 "spotlight_rawquery_parser.c"
+#line 199 "spotlight_rawquery_parser.c"
 
 /* Copy the second part of user declarations.  */
 
 
 /* Line 343 of yacc.c  */
-#line 193 "spotlight_rawquery_parser.c"
+#line 205 "spotlight_rawquery_parser.c"
 
 #ifdef short
 # undef short
@@ -408,20 +420,20 @@ union yyalloc
 /* YYFINAL -- State number of the termination state.  */
 #define YYFINAL  2
 /* YYLAST -- Last index in YYTABLE.  */
-#define YYLAST   37
+#define YYLAST   51
 
 /* YYNTOKENS -- Number of terminals.  */
-#define YYNTOKENS  14
+#define YYNTOKENS  18
 /* YYNNTS -- Number of nonterminals.  */
 #define YYNNTS  6
 /* YYNRULES -- Number of rules.  */
-#define YYNRULES  12
+#define YYNRULES  16
 /* YYNRULES -- Number of states.  */
-#define YYNSTATES  35
+#define YYNSTATES  48
 
 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
 #define YYUNDEFTOK  2
-#define YYMAXUTOK   268
+#define YYMAXUTOK   272
 
 #define YYTRANSLATE(YYX)                                               \
   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@@ -455,7 +467,8 @@ static const yytype_uint8 yytranslate[] =
        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
        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
+       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
+      15,    16,    17
 };
 
 #if YYDEBUG
@@ -463,25 +476,27 @@ static const yytype_uint8 yytranslate[] =
    YYRHS.  */
 static const yytype_uint8 yyprhs[] =
 {
-       0,     0,     3,     4,     7,     9,    13,    15,    17,    21,
-      25,    29,    35
+       0,     0,     3,     4,     7,     9,    11,    15,    17,    19,
+      23,    27,    31,    37,    43,    49,    55
 };
 
 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
 static const yytype_int8 yyrhs[] =
 {
-      15,     0,    -1,    -1,    15,    16,    -1,    17,    -1,    18,
-      13,    18,    -1,    18,    -1,    19,    -1,     7,    17,     8,
-      -1,    17,    12,    17,    -1,    17,    13,    17,    -1,     4,
-       9,    11,     4,    11,    -1,     5,     7,     4,    10,     6,
-       7,     3,     8,    10,     6,     7,     3,     8,     8,    -1
+      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
 };
 
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint8 yyrline[] =
 {
-       0,    52,    52,    54,    58,    68,    74,    75,    76,    77,
-      78,    87,    91
+       0,    57,    57,    59,    63,    73,    79,    85,    86,    87,
+      88,    89,    98,    99,   100,   101,   105
 };
 #endif
 
@@ -490,9 +505,10 @@ static const yytype_uint8 yyrline[] =
    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
 static const char *const yytname[] =
 {
-  "$end", "error", "$undefined", "DATE", "WORD", "FUNC_INRANGE",
-  "DATE_SPEC", "OBRACE", "CBRACE", "EQUAL", "COMMA", "QUOTE", "AND", "OR",
-  "$accept", "input", "line", "expr", "match", "function", 0
+  "$end", "error", "$undefined", "DATE", "WORD", "BOOL", "FUNC_INRANGE",
+  "DATE_SPEC", "OBRACE", "CBRACE", "EQUAL", "UNEQUAL", "GT", "LT", "COMMA",
+  "QUOTE", "AND", "OR", "$accept", "input", "line", "expr", "match",
+  "function", 0
 };
 #endif
 
@@ -502,22 +518,22 @@ static const char *const yytname[] =
 static const yytype_uint16 yytoknum[] =
 {
        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
-     265,   266,   267,   268
+     265,   266,   267,   268,   269,   270,   271,   272
 };
 # endif
 
 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
 static const yytype_uint8 yyr1[] =
 {
-       0,    14,    15,    15,    16,    17,    17,    17,    17,    17,
-      17,    18,    19
+       0,    18,    19,    19,    20,    21,    21,    21,    21,    21,
+      21,    21,    22,    22,    22,    22,    23
 };
 
 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
 static const yytype_uint8 yyr2[] =
 {
-       0,     2,     0,     2,     1,     3,     1,     1,     3,     3,
-       3,     5,    14
+       0,     2,     0,     2,     1,     1,     3,     1,     1,     3,
+       3,     3,     5,     5,     5,     5,    14
 };
 
 /* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
@@ -525,33 +541,35 @@ static const yytype_uint8 yyr2[] =
    means the default is an error.  */
 static const yytype_uint8 yydefact[] =
 {
-       2,     0,     1,     0,     0,     0,     3,     4,     6,     7,
-       0,     0,     0,     0,     0,     0,     0,     0,     8,     9,
-      10,     5,     0,     0,    11,     0,     0,     0,     0,     0,
-       0,     0,     0,     0,    12
+       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
 };
 
 /* YYDEFGOTO[NTERM-NUM].  */
 static const yytype_int8 yydefgoto[] =
 {
-      -1,     1,     6,     7,     8,     9
+      -1,     1,     7,     8,     9,    10
 };
 
 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
    STATE-NUM.  */
-#define YYPACT_NINF -7
+#define YYPACT_NINF -15
 static const yytype_int8 yypact[] =
 {
-      -7,     6,    -7,    -6,    -2,    -3,    -7,     2,     5,    -7,
-      -4,    15,     4,    -3,    -3,    16,    17,    12,    -7,    10,
-      -7,    -7,    13,    19,    -7,    20,    23,    21,    18,    24,
-      25,    28,    26,    27,    -7
+     -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
 };
 
 /* YYPGOTO[NTERM-NUM].  */
 static const yytype_int8 yypgoto[] =
 {
-      -7,    -7,    -7,    -5,    22,    -7
+     -15,   -15,   -15,    -6,    32,   -15
 };
 
 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
@@ -560,34 +578,39 @@ static const yytype_int8 yypgoto[] =
 #define YYTABLE_NINF -1
 static const yytype_uint8 yytable[] =
 {
-      12,     3,     4,    10,     5,    11,     2,    16,    19,    20,
-       3,     4,    18,     5,    13,    14,    13,    14,    15,    17,
-       3,    22,    23,    14,    24,    25,    27,    26,    29,    28,
-      30,    32,    31,     0,    33,    34,     0,    21
+      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
 };
 
 #define yypact_value_is_default(yystate) \
-  ((yystate) == (-7))
+  ((yystate) == (-15))
 
 #define yytable_value_is_error(yytable_value) \
   YYID (0)
 
 static const yytype_int8 yycheck[] =
 {
-       5,     4,     5,     9,     7,     7,     0,    11,    13,    14,
-       4,     5,     8,     7,    12,    13,    12,    13,    13,     4,
-       4,     4,    10,    13,    11,     6,     3,     7,    10,     8,
-       6,     3,     7,    -1,     8,     8,    -1,    15
+       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
 };
 
 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
    symbol of state STATE-NUM.  */
 static const yytype_uint8 yystos[] =
 {
-       0,    15,     0,     4,     5,     7,    16,    17,    18,    19,
-       9,     7,    17,    12,    13,    13,    11,     4,     8,    17,
-      17,    18,     4,    10,    11,     6,     7,     3,     8,    10,
-       6,     7,     3,     8,     8
+       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
 };
 
 #define yyerrok                (yyerrstatus = 0)
@@ -1424,7 +1447,7 @@ yyreduce:
         case 4:
 
 /* Line 1806 of yacc.c  */
-#line 58 "spotlight_rawquery_parser.y"
+#line 63 "spotlight_rawquery_parser.y"
     {
     ssp_result = talloc_asprintf(ssp_slq,
                                  "SELECT DISTINCT ?url WHERE "
@@ -1437,7 +1460,19 @@ yyreduce:
   case 5:
 
 /* Line 1806 of yacc.c  */
-#line 68 "spotlight_rawquery_parser.y"
+#line 73 "spotlight_rawquery_parser.y"
+    {
+    if ((yyvsp[(1) - (1)].bval) == false)
+        YYACCEPT;
+    else
+        YYABORT;
+}
+    break;
+
+  case 6:
+
+/* Line 1806 of yacc.c  */
+#line 79 "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));
@@ -1446,38 +1481,38 @@ yyreduce:
 }
     break;
 
-  case 6:
+  case 7:
 
 /* Line 1806 of yacc.c  */
-#line 74 "spotlight_rawquery_parser.y"
+#line 85 "spotlight_rawquery_parser.y"
     {(yyval.sval) = (yyvsp[(1) - (1)].sval);}
     break;
 
-  case 7:
+  case 8:
 
 /* Line 1806 of yacc.c  */
-#line 75 "spotlight_rawquery_parser.y"
+#line 86 "spotlight_rawquery_parser.y"
     {(yyval.sval) = (yyvsp[(1) - (1)].sval);}
     break;
 
-  case 8:
+  case 9:
 
 /* Line 1806 of yacc.c  */
-#line 76 "spotlight_rawquery_parser.y"
+#line 87 "spotlight_rawquery_parser.y"
     {(yyval.sval) = talloc_asprintf(ssp_slq, "%s", (yyvsp[(2) - (3)].sval));}
     break;
 
-  case 9:
+  case 10:
 
 /* Line 1806 of yacc.c  */
-#line 77 "spotlight_rawquery_parser.y"
+#line 88 "spotlight_rawquery_parser.y"
     {(yyval.sval) = talloc_asprintf(ssp_slq, "%s . %s", (yyvsp[(1) - (3)].sval), (yyvsp[(3) - (3)].sval));}
     break;
 
-  case 10:
+  case 11:
 
 /* Line 1806 of yacc.c  */
-#line 78 "spotlight_rawquery_parser.y"
+#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));
@@ -1486,24 +1521,45 @@ yyreduce:
 }
     break;
 
-  case 11:
+  case 12:
 
 /* Line 1806 of yacc.c  */
-#line 87 "spotlight_rawquery_parser.y"
-    {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), (yyvsp[(4) - (5)].sval));}
+#line 98 "spotlight_rawquery_parser.y"
+    {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '=', (yyvsp[(4) - (5)].sval));}
     break;
 
-  case 12:
+  case 13:
 
 /* Line 1806 of yacc.c  */
-#line 91 "spotlight_rawquery_parser.y"
+#line 99 "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"
+    {(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"
+    {(yyval.sval) = map_expr((yyvsp[(1) - (5)].sval), '>', (yyvsp[(4) - (5)].sval));}
+    break;
+
+  case 16:
+
+/* 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));}
     break;
 
 
 
 /* Line 1806 of yacc.c  */
-#line 1507 "spotlight_rawquery_parser.c"
+#line 1563 "spotlight_rawquery_parser.c"
       default: break;
     }
   /* User semantic actions sometimes alter yychar, and that requires
@@ -1734,7 +1790,7 @@ yyreturn:
 
 
 /* Line 2067 of yacc.c  */
-#line 94 "spotlight_rawquery_parser.y"
+#line 108 "spotlight_rawquery_parser.y"
 
 
 const char *map_daterange(const char *dateattr, const char *date1, const char *date2)
@@ -1756,7 +1812,7 @@ const char *map_daterange(const char *dateattr, const char *date1, const char *d
     return result;
 }
 
-const char *map_expr(const char *attr, const char *val)
+const char *map_expr(const char *attr, char op, const char *val)
 {
     char *result = NULL;
     struct spotlight_sparql_map *p;
@@ -1785,7 +1841,15 @@ int yywrap()
     return 1;
 } 
 
-const gchar *map_spotlight_to_sparql_query(slq_t *slq)
+/**
+ * Map a Spotlight RAW query string to a SPARQL query string
+ *
+ * @param[in]     slq            Spotlight query handle
+ * @param[out]    sparql_result  Mapped SPARQL query, string is allocated in
+ *                               talloc context of slq
+ * @return        0 on success, -1 on error
+ **/
+int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result)
 {
     EC_INIT;
     YY_BUFFER_STATE s = NULL;
@@ -1798,13 +1862,17 @@ const gchar *map_spotlight_to_sparql_query(slq_t *slq)
 EC_CLEANUP:
     if (s)
         yy_delete_buffer(s);
-
-    return ssp_result;
+    if (ret == 0)
+        *sparql_result = NULL;
+    else
+        *sparql_result = ssp_result;
+    EC_EXIT;
 }
 
 #ifdef MAIN
 int main(int argc, char **argv)
 {
+    int ret;
     YY_BUFFER_STATE s;
 
     if (argc != 2) {
@@ -1819,11 +1887,12 @@ int main(int argc, char **argv)
 
     s = yy_scan_string(argv[1]);
 
-    yyparse();
+    ret = yyparse();
 
     yy_delete_buffer(s);
 
-    printf("SPARQL: %s\n", ssp_result);
+    if (ret == 0)
+        printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)");
 
     return 0;
 } 
index 14e27ad684a39aef31035e22a765f31194680c70..09294aed814f7ef8c9b3142c8624831bd8c90062 100644 (file)
    enum yytokentype {
      DATE = 258,
      WORD = 259,
-     FUNC_INRANGE = 260,
-     DATE_SPEC = 261,
-     OBRACE = 262,
-     CBRACE = 263,
-     EQUAL = 264,
-     COMMA = 265,
-     QUOTE = 266,
-     AND = 267,
-     OR = 268
+     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
    };
 #endif
 /* Tokens.  */
 #define DATE 258
 #define WORD 259
-#define FUNC_INRANGE 260
-#define DATE_SPEC 261
-#define OBRACE 262
-#define CBRACE 263
-#define EQUAL 264
-#define COMMA 265
-#define QUOTE 266
-#define AND 267
-#define OR 268
+#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
 
 
 
@@ -71,15 +79,16 @@ typedef union YYSTYPE
 {
 
 /* Line 2068 of yacc.c  */
-#line 34 "spotlight_rawquery_parser.y"
+#line 37 "spotlight_rawquery_parser.y"
 
     int ival;
     const char *sval;
+    bool bval;
 
 
 
 /* Line 2068 of yacc.c  */
-#line 83 "spotlight_rawquery_parser.h"
+#line 92 "spotlight_rawquery_parser.h"
 } YYSTYPE;
 # define YYSTYPE_IS_TRIVIAL 1
 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
@@ -92,13 +101,12 @@ extern YYSTYPE yylval;
 /* "%code provides" blocks.  */
 
 /* Line 2068 of yacc.c  */
-#line 28 "spotlight_rawquery_parser.y"
+#line 32 "spotlight_rawquery_parser.y"
 
-  extern const gchar *map_spotlight_to_sparql_query(slq_t *slq);
+  extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result);
   extern slq_t *ssp_slq;
-  extern gchar *ssp_result;
 
 
 
 /* Line 2068 of yacc.c  */
-#line 105 "spotlight_rawquery_parser.h"
+#line 113 "spotlight_rawquery_parser.h"
index c64f37601ad5edc6205e584eaeb1b1674b7fa0c6..daf5bc2ff7381fcb24792a5f73c3f61b8a23d924 100644 (file)
   extern YY_BUFFER_STATE yy_scan_string( const char *str);
   extern void yy_delete_buffer ( YY_BUFFER_STATE buffer );
 
-  static const char *map_expr(const char *attr, const char *val);
+  /* 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 */
   slq_t *ssp_slq;
-  gchar *ssp_result;
+
+  /* local vars */
+  static gchar *ssp_result;
 
 %}
 
 %code provides {
-  extern const gchar *map_spotlight_to_sparql_query(slq_t *slq);
+  extern int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result);
   extern slq_t *ssp_slq;
-  extern gchar *ssp_result;
 }
 
 %union {
     int ival;
     const char *sval;
+    bool bval;
 }
 
 %expect 1
 %type <sval> match expr line function
 %token <sval> DATE
 %token <sval> WORD
+%token <bval> BOOL
 %token FUNC_INRANGE
 %token DATE_SPEC
-%token OBRACE CBRACE EQUAL COMMA QUOTE
+%token OBRACE CBRACE EQUAL UNEQUAL GT LT COMMA QUOTE
 %left AND
 %left OR
 %%
@@ -65,7 +70,13 @@ expr                           {
 ;
 
 expr:
-match OR match                 {
+BOOL                             {
+    if ($1 == false)
+        YYACCEPT;
+    else
+        YYABORT;
+}
+| match OR match                 {
     if (strcmp($1, $3) != 0)
         $$ = talloc_asprintf(ssp_slq, "{ %s } UNION { %s }", $1, $3);
     else
@@ -84,7 +95,10 @@ match OR match                 {
 ;
 
 match:
-WORD EQUAL QUOTE WORD QUOTE    {$$ = map_expr($1, $4);}
+WORD EQUAL QUOTE WORD QUOTE     {$$ = map_expr($1, '=', $4);}
+| WORD UNEQUAL QUOTE WORD QUOTE {$$ = map_expr($1, '!', $4);}
+| WORD LT QUOTE WORD QUOTE      {$$ = map_expr($1, '<', $4);}
+| WORD GT QUOTE WORD QUOTE      {$$ = map_expr($1, '>', $4);}
 ;
 
 function:
@@ -112,16 +126,18 @@ const char *map_daterange(const char *dateattr, const char *date1, const char *d
     return result;
 }
 
-const char *map_expr(const char *attr, const char *val)
+const char *map_expr(const char *attr, char op, const char *val)
 {
     char *result = NULL;
     struct spotlight_sparql_map *p;
 
     for (p = spotlight_sparql_map; p->ssm_spotlight_attr; p++) {
+#if 0
         if (strcmp(p->ssm_spotlight_attr, attr) == 0) {
             result = talloc_asprintf(ssp_slq, p->ssm_sparql_query_fmtstr, val);
             break;
         }
+#endif
     }
 
     return result;
@@ -141,7 +157,15 @@ int yywrap()
     return 1;
 } 
 
-const gchar *map_spotlight_to_sparql_query(slq_t *slq)
+/**
+ * Map a Spotlight RAW query string to a SPARQL query string
+ *
+ * @param[in]     slq            Spotlight query handle
+ * @param[out]    sparql_result  Mapped SPARQL query, string is allocated in
+ *                               talloc context of slq
+ * @return        0 on success, -1 on error
+ **/
+int map_spotlight_to_sparql_query(slq_t *slq, gchar **sparql_result)
 {
     EC_INIT;
     YY_BUFFER_STATE s = NULL;
@@ -154,13 +178,17 @@ const gchar *map_spotlight_to_sparql_query(slq_t *slq)
 EC_CLEANUP:
     if (s)
         yy_delete_buffer(s);
-
-    return ssp_result;
+    if (ret == 0)
+        *sparql_result = NULL;
+    else
+        *sparql_result = ssp_result;
+    EC_EXIT;
 }
 
 #ifdef MAIN
 int main(int argc, char **argv)
 {
+    int ret;
     YY_BUFFER_STATE s;
 
     if (argc != 2) {
@@ -175,11 +203,12 @@ int main(int argc, char **argv)
 
     s = yy_scan_string(argv[1]);
 
-    yyparse();
+    ret = yyparse();
 
     yy_delete_buffer(s);
 
-    printf("SPARQL: %s\n", ssp_result);
+    if (ret == 0)
+        printf("SPARQL: %s\n", ssp_result ? ssp_result : "(empty)");
 
     return 0;
 }