Now the HTML result shows word meanings.
authorviric@llimona
Sun, 02 Sep 2007 14:24:10 +0200
changeset 24 026a2ba0ce16
parent 23 97feccfc5215
child 25 8d524bb8dcea
Now the HTML result shows word meanings.
dictre.h
errors.txt
find.c
make-signifoj.sh
parse_text.c
prepare_meanings.c
--- a/dictre.h	Sun Sep 02 00:02:48 2007 +0200
+++ b/dictre.h	Sun Sep 02 14:24:10 2007 +0200
@@ -1,6 +1,6 @@
 enum {
     MAXWORD=200,
-    MAXDEF=10000,
+    MAXDEF=100000,
     END_OF_URL=-2,
     HTTP_DECODE_ERROR=-3
 };
--- a/errors.txt	Sun Sep 02 00:02:48 2007 +0200
+++ b/errors.txt	Sun Sep 02 14:24:10 2007 +0200
@@ -1,4 +1,5 @@
 * Mankas получить en Zaliznjak.
+* En signifoj, post dictfmt, привет aperas dufoje.. (?!?)
 
 Optimigo:
 - Ne cxiam sangxi al minusklaj literoj por sercxi. Nur kaze de netrovo.
--- a/find.c	Sun Sep 02 00:02:48 2007 +0200
+++ b/find.c	Sun Sep 02 14:24:10 2007 +0200
@@ -74,13 +74,17 @@
     int i,j;
     for(i=0; i < len; ++i)
     {
+        /* prepare ltrimming when finding the first newline character */
         if (def[i] == '\n')
         {
+            /* Remove spaces after the first newline */
+            for(i+=1; def[i] == ' '; ++i);
+
             /* Break */
-            memmove(def, def + i + 1 /* \n */,
+            memmove(def, def + i,
                     len - i - 1);
             def[len-i-1] = 0;
-            return len-i-2/*\n*/+1/*\0*/;
+            return len-i-1+1/*\0*/;
         }
     }
     return len;
@@ -169,8 +173,10 @@
 static const char * search_next(struct Dict *d, const char *word, const char *from)
 {
     const char *ret;
-    ret = skip_until_newline(d, from);
-    if (compare(from, word) == 0)
+    ret = skip_until_newline(d, from) + 1;
+    if (ret == (char *) 1) /* pointer at end */
+        return 0;
+    if (compare(word, ret) == 0)
         return ret;
     return 0;
 }
--- a/make-signifoj.sh	Sun Sep 02 00:02:48 2007 +0200
+++ b/make-signifoj.sh	Sun Sep 02 14:24:10 2007 +0200
@@ -5,4 +5,4 @@
 
 ./prepare_meanings > signifoj.txt
 
-dictfmt -s "Diversaj vortaroj" -j --locale ca_ES.UTF-8 --without-headword signifoj < signifoj.txt
+dictfmt -s "Diversaj vortaroj" -j --locale ca_ES.UTF-8 --allchars --without-headword signifoj < signifoj.txt
--- a/parse_text.c	Sun Sep 02 00:02:48 2007 +0200
+++ b/parse_text.c	Sun Sep 02 14:24:10 2007 +0200
@@ -3,8 +3,182 @@
 #include "dictre.h"
 
 static int is_http = 0;
+static int give_html = 1;
 static int content_length = -1;
 static struct Dict dakcentiga;
+static struct Dict dsignifoj;
+
+static void print_html_header()
+{
+    printf(
+"<html>\n"
+"<head>\n"
+"    <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n"
+"    <title>Akcentigita teksto</title>\n"
+"</head>\n"
+"<style type=\"text/css\" media=\"screen\">\n"
+"div.difino { display: none ;\n"
+"    position: absolute;\n"
+"    left: 0;\n"
+"    background: moccasin;\n"
+"    border: thin;\n"
+"    border-color: black;\n"
+"    padding: 10px 10px 10px 10px;\n"
+"    text-indent: 0em;\n"
+"    text-align: left;\n"
+"    }\n"
+"div.alineo { text-indent: 2em ; text-align: justify }\n"
+"</style>\n"
+"<body>\n"
+"<script language=\"javascript\">\n"
+"var blocked = \"\";\n"
+"\n"
+"function display(element, ev)\n"
+"{\n"
+"    var x,y;\n"
+"    x = ev.screenX + window.pageXOffset;\n"
+"    y = ev.screenY + window.pageYOffset;\n"
+"\n"
+"    if (blocked != \"\")\n"
+"        return;\n"
+#if 0
+"\n"
+"    if (x + 320 > window.innerWidth)\n"
+"        x = window.innerWidth - 320;\n"
+"\n"
+"    /*\n"
+"    if (y < window.innerHeight / 2)\n"
+"    {\n"
+"        y += 5;\n"
+"        document.getElementById(element).style.top = y;\n"
+"    } else {\n"
+"        y -= 5;\n"
+"        document.getElementById(element).style.top = 0;\n"
+"        document.getElementById(element).style.bottom = y;\n"
+"    }\n"
+"    */\n"
+#endif
+"    y += 5;\n"
+"    document.getElementById(element).style.top = y + 'px';\n"
+"    \n"
+/*
+"    document.getElementById(element).style.left = 0;\n"
+*/
+"    document.getElementById(element).style.display = 'block';\n"
+"}\n"
+"\n"
+"function undisplay(element)\n"
+"{\n"
+"    document.getElementById(element).style.display = 'none';\n"
+"}\n"
+"\n"
+"function click(element, ev)\n"
+"{\n"
+"    if (blocked == \"\")\n"
+"    {\n"
+"        display(element, ev);\n"
+"        blocked = element;\n"
+"    }\n"
+"    else\n"
+"    {\n"
+"        undisplay(blocked);\n"
+"        blocked = \"\";\n"
+"    }\n"
+"}\n"
+"\n"
+"</script>"
+);
+
+}
+
+static void print_html_footer()
+{
+    printf("</body></html>\n");
+}
+
+static void dump_signifo_with_p(const char *word, const char *signifo)
+{
+    int i;
+    char last;
+
+    printf("<p>## Se moto %s:</p>\n<p>", word);
+
+    last = 0;
+    i=0;
+    do
+    {
+        char nun;
+        nun = *signifo;
+        if (nun == '\0')
+            break;
+        if (nun == '\n' && last == '\n')
+            printf("</p><p>");
+        putchar(nun);
+        last = nun;
+        ++signifo;
+    } while(1);
+    printf("</p>");
+}
+
+static void print_start_signifoj(int id)
+{
+    printf("<div id=\"vorto%i\" onclick=\"click('vorto%i', event);\" "
+            "class=\"difino\"><p>\n", id, id);
+}
+
+static void print_end_signifoj()
+{
+    printf("</p></div>");
+}
+
+/* This expects the word to start exactly at *wordlist */
+static void print_signifoj(char *wordlist, int id)
+{
+    char * next_space;
+    char def[MAXDEF];
+    int start_shown = 0;
+
+    do {
+        next_space = strchr(wordlist, ' ');
+        if (next_space == 0)
+            next_space = strchr(wordlist, '\n');
+        if (next_space == 0)
+            next_space = strchr(wordlist, '\0');
+        if (next_space != 0 && next_space != wordlist)
+        {
+            int spacepos;
+            spacepos = next_space - wordlist;
+            wordlist[spacepos] = 0;
+
+            /* wordlist has the word to search */
+            find_def(&dsignifoj, wordlist, def);
+            if (def[0])
+            {
+                if (!start_shown)
+                {
+                    print_start_signifoj(id);
+                    start_shown = 1;
+                }
+                dump_signifo_with_p(wordlist, def);
+            }
+        } else
+            break;
+        wordlist = next_space + 1;
+    } while(1);
+
+    if (start_shown)
+        print_end_signifoj();
+}
+
+static print_accented(const char *word, int id)
+{
+    if (give_html)
+    {
+        printf("<span class=\"vorto\" onclick=\"click('vorto%i', event);\">"
+                "%s</span>",id,word);
+    } else
+        printf("%s", word);
+}
 
 static void give_accent_to_word(const char *word)
 {
@@ -12,6 +186,7 @@
     char low[MAXWORD];
     char recased[MAXWORD];
     enum Case vcase[MAXWORD];
+    static int id = 1;
 
     /* Get case */
     get_case(vcase, word);
@@ -34,12 +209,32 @@
             spacepos = first_space - def;
             def[spacepos] = 0; /* Mark an end of string */
             reapply_case(recased, def, vcase);
-            printf("%s", recased);
+            print_accented(recased, id);
+            if (give_html)
+                print_signifoj(first_space + 1 /*' '*/, id);
+            ++id;
         }
         return;
     }
+    else if (give_html)
+    {
+        char def[MAXDEF];
+        /* OPTIMIZE: This, if find, will react in a second search at
+         * print_signifoj() */
+        find_def(&dsignifoj, low, def);
+        if (def[0])
+        {
+            print_accented(word, id);
+            print_signifoj(low, id);
+            ++id;
+            return;
+        }
+    }
 
-    /* if first_space == 0 or word not found */
+    /* else ... */
+
+    /* if first_space == 0 or word not found _AND_ word not found in meanings
+     * when give_html...*/
     printf("%s", word);
 }
 
@@ -56,7 +251,10 @@
     unsigned char tmp[MAXWORD];
     int wordpos = 0;
     int skip_non_ascii = 0;
+    int last = 0;
 
+    if (give_html)
+        printf("<div class=\"alineo\">");
     do
     {
         int c;
@@ -66,6 +264,14 @@
         c = my_fgetc(in);
         if (c == EOF || c == END_OF_URL)
             break;
+        if (c == '\r')
+            continue;
+
+        /* Process 'last' for eventual line break */
+        if (give_html && c == '\n' && last == '\n')
+            printf("</div>\n<div class=\"alineo\">");
+        last = c;
+
         if (skip_non_ascii || is_ASCII(c))
         {
             if (wordpos != 0)
@@ -105,6 +311,8 @@
         give_accent_to_word(tmp);
         wordpos = 0;
     }
+    if (give_html)
+        printf("</div>");
 }
 
 static print_http_header()
@@ -128,6 +336,7 @@
     char *c;
 
     init_dictionary(&dakcentiga, "akcentiga");
+    init_dictionary(&dsignifoj, "signifoj");
 
     if (c = getenv("CONTENT_LENGTH"))
     {
@@ -140,7 +349,14 @@
         if (!eat_form_ok())
             return -1;
     }
+
+    if (give_html)
+        print_html_header();
+    /* We pass -1 so we don't check content length */
     process_text(stdin, 0, -1);
+
+    if (give_html)
+        print_html_footer();
     end_dictionary(&dakcentiga);
 
     return 0;
--- a/prepare_meanings.c	Sun Sep 02 00:02:48 2007 +0200
+++ b/prepare_meanings.c	Sun Sep 02 14:24:10 2007 +0200
@@ -58,7 +58,7 @@
                 printf(":%s:", word);
                 word_header_dumped = 1;
             }
-            printf("[%s]\n%s\n\n", dictionarynames[i], def);
+            printf("-- [%s]\n%s\n\n", dictionarynames[i], def);
         }
     }
 }