zdefs.c
changeset 11 68ea18fe402c
child 14 a961bb8806b9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/zdefs.c	Tue Aug 28 01:03:24 2007 +0200
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include "dictre.h"
+
+static void new_word(const char *str)
+{
+    printf("%s\n", str);
+}
+
+static int skip_newline(const char *str, int *index)
+{
+    while(str[*index] != 0 && str[*index] != '\n')
+    {
+        ++*index;
+    }
+
+    if (str[*index] == '\n')
+        return *index;
+
+    return -1;
+}
+
+static int until_noword(const char *str, int *index)
+{
+    while(str[*index] != 0 &&
+            str[*index] != ' ' &&
+            str[*index] != '\n' &&
+            str[*index] != '\r' &&
+            str[*index] != ',')
+    {
+        ++*index;
+    }
+
+    if (str[*index] != 0)
+        return *index;
+
+    return -1;
+}
+
+static int until_newword(const unsigned char *str, int *index)
+{
+    while(str[*index] != 0 && str[*index] < 128)
+    {
+        ++*index;
+    }
+
+    if (str[*index] != 0);
+        return *index;
+
+    return -1;
+}
+
+void zprocess_def(const char *root, char *def)
+{
+    int index = 0;
+    int res;
+    /* Jump the first line (index word) Wait for \n */
+    skip_newline(def, &index);
+    ++index;
+
+    res = until_newword(def, &index);
+    if (res == -1)
+        return;
+
+    /* Mark words */
+    do {
+        int end;
+        end = index;
+        res = until_noword(def, &end);
+        if (res == -1)
+            break;
+        def[end] = 0;
+        insert_word(&def[index], root);
+        index = end+1;
+        res = until_newword(def,&index);
+        if (res == -1)
+            break;
+    } while (1);
+    free(def);
+    free(root);
+}