Code

Include config.h in source files.
[sysdb.git] / src / tools / sysdb / scanner.l
index 3ec4b04f32f2ce302064866f63b0cd7e15910594..4d9fea5bc6c1f501371739a40f09a4ebd017b40a 100644 (file)
  */
 
 %{
+
+/*
+ * This is a simplified version of frontend/scanner.l. The only purpose is to
+ * find queries (terminated by semicolon).
+ */
+
+#if HAVE_CONFIG_H
+#      include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include "tools/sysdb/input.h"
 
+#include <string.h>
+
 #ifdef YY_INPUT
 #      undef YY_INPUT
 #endif
 #define YY_INPUT(buf, result, max_size) \
+       sdb_input_readline((buf), &(result), (max_size))
+
+#define APPEND() \
        do { \
-               sdb_input_readline(sdb_input, (buf), &(result), (max_size)); \
+               sysdb_input->query_len += strlen(yytext); \
        } while (0)
 
-static sdb_input_t *sdb_input;
 %}
 
 %option interactive
@@ -47,17 +61,41 @@ static sdb_input_t *sdb_input;
 %option verbose
 %option warn
 
-%%
+%x CSC
 
-. { /* do nothing */ }
+whitespace             ([ \t\n\r\f]+)
+simple_comment ("--"[^\n\r]*)
+
+/*
+ * C style comments
+ */
+csc_start      \/\*
+csc_inside     ([^*/]+|[^*]\/|\*[^/])
+csc_end                \*\/
+
+identifier     ([A-Za-z_][A-Za-z_0-9$]*)
 
 %%
 
-void
-sdb_input_set(sdb_input_t *new_input)
-{
-       sdb_input = new_input;
-} /* sdb_input_set */
+{whitespace}           { APPEND(); }
+{simple_comment}       { APPEND(); }
+
+{csc_start}                    { APPEND(); BEGIN(CSC); }
+<CSC>{csc_inside}      { APPEND(); }
+<CSC>{csc_end}         { APPEND(); BEGIN(INITIAL); }
+<CSC><<EOF>>           { return -1; }
+
+{identifier}           { APPEND(); }
+
+       /*
+        * The following rules are specific to the command line tool.
+        */
+
+";"    { APPEND(); sdb_input_exec_query(); }
+
+.      { APPEND(); }
+
+%%
 
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */