Updated from branch dev
[cascardo/grammar.git] / scanner.c
diff --git a/scanner.c b/scanner.c
new file mode 100644 (file)
index 0000000..1307bca
--- /dev/null
+++ b/scanner.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <scanner.h>
+
+static void string_free (gpointer data)
+{
+  g_string_free ((GString*) data, TRUE);
+}
+
+scanner_t* scanner_new (readcb cb, gpointer data)
+{
+
+  scanner_t* scanner;
+
+  scanner = g_malloc (sizeof (scanner_t));
+  scanner->cb = cb;
+  scanner->data = data;
+  scanner->buffer = g_string_sized_new (256);
+  scanner->reserved = g_hash_table_new_full (g_string_hash, g_string_equal,
+                                            string_free, NULL);
+
+  return scanner;
+
+}
+
+void scanner_delete (scanner_t* scanner)
+{
+  g_hash_table_destroy (scanner->reserved);
+  g_string_free (scanner->buffer, TRUE);
+  g_free (scanner);
+}