parse_text.c
author viric@llimona
Sun, 02 Sep 2007 15:57:34 +0200
changeset 25 8d524bb8dcea
parent 24 026a2ba0ce16
child 28 75b6d5659a19
permissions -rw-r--r--
Changed the name for zprocess to prepare_akcentiga
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
     1
#include <stdio.h>
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
     2
#include <stdlib.h>
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
     3
#include "dictre.h"
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
     4
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
     5
static int is_http = 0;
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
     6
static int give_html = 1;
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
     7
static int content_length = -1;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
     8
static struct Dict dakcentiga;
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
     9
static struct Dict dsignifoj;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    10
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    11
static void print_html_header()
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    12
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    13
    printf(
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    14
"<html>\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    15
"<head>\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    16
"    <meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\">\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    17
"    <title>Akcentigita teksto</title>\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    18
"</head>\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    19
"<style type=\"text/css\" media=\"screen\">\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    20
"div.difino { display: none ;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    21
"    position: absolute;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    22
"    left: 0;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    23
"    background: moccasin;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    24
"    border: thin;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    25
"    border-color: black;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    26
"    padding: 10px 10px 10px 10px;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    27
"    text-indent: 0em;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    28
"    text-align: left;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    29
"    }\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    30
"div.alineo { text-indent: 2em ; text-align: justify }\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    31
"</style>\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    32
"<body>\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    33
"<script language=\"javascript\">\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    34
"var blocked = \"\";\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    35
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    36
"function display(element, ev)\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    37
"{\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    38
"    var x,y;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    39
"    x = ev.screenX + window.pageXOffset;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    40
"    y = ev.screenY + window.pageYOffset;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    41
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    42
"    if (blocked != \"\")\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    43
"        return;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    44
#if 0
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    45
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    46
"    if (x + 320 > window.innerWidth)\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    47
"        x = window.innerWidth - 320;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    48
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    49
"    /*\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    50
"    if (y < window.innerHeight / 2)\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    51
"    {\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    52
"        y += 5;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    53
"        document.getElementById(element).style.top = y;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    54
"    } else {\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    55
"        y -= 5;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    56
"        document.getElementById(element).style.top = 0;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    57
"        document.getElementById(element).style.bottom = y;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    58
"    }\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    59
"    */\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    60
#endif
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    61
"    y += 5;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    62
"    document.getElementById(element).style.top = y + 'px';\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    63
"    \n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    64
/*
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    65
"    document.getElementById(element).style.left = 0;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    66
*/
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    67
"    document.getElementById(element).style.display = 'block';\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    68
"}\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    69
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    70
"function undisplay(element)\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    71
"{\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    72
"    document.getElementById(element).style.display = 'none';\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    73
"}\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    74
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    75
"function click(element, ev)\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    76
"{\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    77
"    if (blocked == \"\")\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    78
"    {\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    79
"        display(element, ev);\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    80
"        blocked = element;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    81
"    }\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    82
"    else\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    83
"    {\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    84
"        undisplay(blocked);\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    85
"        blocked = \"\";\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    86
"    }\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    87
"}\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    88
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    89
"</script>"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    90
);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    91
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    92
}
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    93
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    94
static void print_html_footer()
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    95
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    96
    printf("</body></html>\n");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    97
}
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    98
25
8d524bb8dcea Changed the name for zprocess to prepare_akcentiga
viric@llimona
parents: 24
diff changeset
    99
static void dump_signifo_with_p(const unsigned char *word,
8d524bb8dcea Changed the name for zprocess to prepare_akcentiga
viric@llimona
parents: 24
diff changeset
   100
        const unsigned char *signifo)
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   101
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   102
    int i;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   103
    char last;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   104
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   105
    printf("<p>## Se moto %s:</p>\n<p>", word);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   106
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   107
    last = 0;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   108
    i=0;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   109
    do
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   110
    {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   111
        char nun;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   112
        nun = *signifo;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   113
        if (nun == '\0')
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   114
            break;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   115
        if (nun == '\n' && last == '\n')
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   116
            printf("</p><p>");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   117
        putchar(nun);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   118
        last = nun;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   119
        ++signifo;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   120
    } while(1);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   121
    printf("</p>");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   122
}
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   123
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   124
static void print_start_signifoj(int id)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   125
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   126
    printf("<div id=\"vorto%i\" onclick=\"click('vorto%i', event);\" "
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   127
            "class=\"difino\"><p>\n", id, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   128
}
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   129
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   130
static void print_end_signifoj()
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   131
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   132
    printf("</p></div>");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   133
}
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   134
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   135
/* This expects the word to start exactly at *wordlist */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   136
static void print_signifoj(char *wordlist, int id)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   137
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   138
    char * next_space;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   139
    char def[MAXDEF];
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   140
    int start_shown = 0;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   141
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   142
    do {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   143
        next_space = strchr(wordlist, ' ');
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   144
        if (next_space == 0)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   145
            next_space = strchr(wordlist, '\n');
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   146
        if (next_space == 0)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   147
            next_space = strchr(wordlist, '\0');
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   148
        if (next_space != 0 && next_space != wordlist)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   149
        {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   150
            int spacepos;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   151
            spacepos = next_space - wordlist;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   152
            wordlist[spacepos] = 0;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   153
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   154
            /* wordlist has the word to search */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   155
            find_def(&dsignifoj, wordlist, def);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   156
            if (def[0])
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   157
            {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   158
                if (!start_shown)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   159
                {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   160
                    print_start_signifoj(id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   161
                    start_shown = 1;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   162
                }
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   163
                dump_signifo_with_p(wordlist, def);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   164
            }
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   165
        } else
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   166
            break;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   167
        wordlist = next_space + 1;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   168
    } while(1);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   169
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   170
    if (start_shown)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   171
        print_end_signifoj();
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   172
}
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   173
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   174
static print_accented(const char *word, int id)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   175
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   176
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   177
    {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   178
        printf("<span class=\"vorto\" onclick=\"click('vorto%i', event);\">"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   179
                "%s</span>",id,word);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   180
    } else
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   181
        printf("%s", word);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   182
}
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   183
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   184
static void give_accent_to_word(const char *word)
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   185
{
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   186
    char def[MAXDEF];
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   187
    char low[MAXWORD];
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   188
    char recased[MAXWORD];
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   189
    enum Case vcase[MAXWORD];
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   190
    static int id = 1;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   191
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   192
    /* Get case */
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   193
    get_case(vcase, word);
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   194
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   195
    /* Get lowercase version */
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   196
    get_lowcase_str(low, word);
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   197
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   198
    /* Find the lowercase version */
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   199
    find_def(&dakcentiga, low, def);
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   200
    if (def[0] != 0) /* found */
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   201
    {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   202
        /* Print the word UNTIL a space.
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   203
         * the definition will have the form:
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   204
         *    ACCENTED_WORD NOMINATIVE1 NOMINATIVE2 ... \n */
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   205
        char *first_space;
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   206
        char spacepos;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   207
        first_space = strchr(def, ' ');
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   208
        if (first_space != 0) /* Space found */
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   209
        {
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   210
            spacepos = first_space - def;
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   211
            def[spacepos] = 0; /* Mark an end of string */
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   212
            reapply_case(recased, def, vcase);
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   213
            print_accented(recased, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   214
            if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   215
                print_signifoj(first_space + 1 /*' '*/, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   216
            ++id;
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   217
        }
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   218
        return;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   219
    }
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   220
    else if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   221
    {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   222
        char def[MAXDEF];
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   223
        /* OPTIMIZE: This, if find, will react in a second search at
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   224
         * print_signifoj() */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   225
        find_def(&dsignifoj, low, def);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   226
        if (def[0])
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   227
        {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   228
            print_accented(word, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   229
            print_signifoj(low, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   230
            ++id;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   231
            return;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   232
        }
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   233
    }
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   234
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   235
    /* else ... */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   236
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   237
    /* if first_space == 0 or word not found _AND_ word not found in meanings
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   238
     * when give_html...*/
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   239
    printf("%s", word);
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   240
}
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   241
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   242
static int my_fgetc(FILE *f)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   243
{
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   244
    if (is_http)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   245
        return http_getc(f);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   246
    else
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   247
        return fgetc(f);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   248
}
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   249
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   250
static void process_text(FILE *in, int pos, int length)
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   251
{
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   252
    unsigned char tmp[MAXWORD];
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   253
    int wordpos = 0;
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   254
    int skip_non_ascii = 0;
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   255
    int last = 0;
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   256
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   257
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   258
        printf("<div class=\"alineo\">");
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   259
    do
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   260
    {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   261
        int c;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   262
        /* Check pos only if length >= 0 */
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   263
        if (length >= 0 && pos >= length)
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   264
            break;
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   265
        c = my_fgetc(in);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   266
        if (c == EOF || c == END_OF_URL)
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   267
            break;
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   268
        if (c == '\r')
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   269
            continue;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   270
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   271
        /* Process 'last' for eventual line break */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   272
        if (give_html && c == '\n' && last == '\n')
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   273
            printf("</div>\n<div class=\"alineo\">");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   274
        last = c;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   275
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   276
        if (skip_non_ascii || is_ASCII(c))
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   277
        {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   278
            if (wordpos != 0)
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   279
            {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   280
                tmp[wordpos] = 0;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   281
                give_accent_to_word(tmp);
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   282
                wordpos = 0;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   283
            }
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   284
            putchar(c);
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   285
            /* End of skip_non_ascii when we find an
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   286
             * ascii string */
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   287
            if (skip_non_ascii && is_ASCII(c))
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   288
                skip_non_ascii = 0;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   289
        }
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   290
        else /* non-ASCII - we consider it russian */
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   291
        {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   292
            tmp[wordpos++] = c;
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   293
            if (wordpos >= MAXWORD)
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   294
            {
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   295
                /* Dump the word and the rest of non-ASCII, because
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   296
                 * we cannot fit it in 'tmp' */
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   297
                int i;
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   298
                for(i=0; i < wordpos; ++i)
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   299
                    putchar(tmp[i]);
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   300
                wordpos=0;
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   301
                skip_non_ascii = 1;
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   302
            }
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   303
        }
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   304
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   305
        pos += 1;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   306
    } while(1);
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   307
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   308
    /* End word */
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   309
    if (wordpos != 0)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   310
    {
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   311
        tmp[wordpos] = 0;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   312
        give_accent_to_word(tmp);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   313
        wordpos = 0;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   314
    }
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   315
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   316
        printf("</div>");
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   317
}
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   318
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   319
static print_http_header()
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   320
{
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   321
    printf("Content-Type:text/html;charset=utf-8\r\n\r\n");
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   322
}
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   323
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   324
int eat_form_ok()
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   325
{
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   326
    const char mask[] = "teksto=";
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   327
    char tmp[sizeof(mask)];
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   328
    fread(tmp, 1, sizeof(mask)-1, stdin);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   329
    tmp[sizeof(mask)-1] = 0;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   330
    if (strcmp(mask, tmp) == 0)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   331
        return 1;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   332
    return 0;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   333
}
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   334
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   335
int main()
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   336
{
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   337
    char *c;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   338
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   339
    init_dictionary(&dakcentiga, "akcentiga");
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   340
    init_dictionary(&dsignifoj, "signifoj");
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   341
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   342
    if (c = getenv("CONTENT_LENGTH"))
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   343
    {
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   344
        content_length = atoi(c);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   345
        is_http = 1;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   346
    }
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   347
    if (is_http)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   348
    {
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   349
        print_http_header();
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   350
        if (!eat_form_ok())
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   351
            return -1;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   352
    }
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   353
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   354
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   355
        print_html_header();
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   356
    /* We pass -1 so we don't check content length */
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   357
    process_text(stdin, 0, -1);
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   358
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   359
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   360
        print_html_footer();
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   361
    end_dictionary(&dakcentiga);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   362
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   363
    return 0;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   364
}