prepare_meanings.c
changeset 22 0b923f95df16
child 23 97feccfc5215
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/prepare_meanings.c	Sat Sep 01 23:52:38 2007 +0200
@@ -0,0 +1,92 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "dictre.h"
+
+#define NELEM(x) (sizeof(x)/sizeof(x[0]))
+
+
+const char *dictionarynames[] = { "bokarjovrueo", "slovnyk_ru-en" };
+static struct Dict dictionaries[5/*MAX DICT*/];
+static int ndictionaries;
+
+static void init_dictionaries()
+{
+    ndictionaries = 0;
+
+    init_dictionary(&dictionaries[0], "bokarjovrueo");
+    dictionaries[0].trim_last_newlines = 1;
+    ndictionaries++;
+
+    init_dictionary(&dictionaries[1], "slovnyk_ru-en");
+    dictionaries[1].trim_first_line = 1;
+    dictionaries[1].trim_last_newlines = 1;
+    ndictionaries++;
+}
+
+static void close_dictionaries()
+{
+    int i;
+    for(i=0; i<ndictionaries; ++i)
+        end_dictionary(&dictionaries[i]);
+
+    ndictionaries=0;
+}
+
+void dump_word(const char *word)
+{
+    int i;
+    char def[MAXDEF];
+    int word_header_dumped = 0;
+
+    if (strncmp(word, "00database", sizeof("00database"-1)) == 0)
+        return;
+
+    for (i=0; i < ndictionaries; ++i)
+    {
+        char *found;
+        find_def(&dictionaries[i], word, def);
+        if (def[0])
+        {
+            if(!word_header_dumped)
+            {
+                printf(":%s:", word);
+                word_header_dumped = 1;
+            }
+            printf("[%s]\n%s\n\n", dictionarynames[i], def);
+        }
+    }
+}
+
+void dump_words()
+{
+    FILE *fwords;
+    char word[MAXWORD];
+
+    fwords = fopen("words.txt", "r");
+    if (fwords == 0)
+    {
+        printf("Cannot open words.txt\n");
+        exit(-1);
+    }
+
+    do
+    {
+        char *res;
+        res = fgets(word, MAXWORD, fwords);
+        if (res == 0)
+            break;
+        word[strlen(word) - 1] = 0; /* Remove \n in the line */
+        dump_word(word);
+    } while(1);
+}
+
+int main()
+{
+    init_dictionaries();
+
+    dump_words();
+
+    close_dictionaries();
+
+    return 0;
+}