parse_text.c
author viric <viriketo@gmail.com>
Fri, 30 Mar 2012 18:56:20 +0200
changeset 33 ebbedaa090be
parent 28 75b6d5659a19
permissions -rw-r--r--
Adding what I had in the web for zparsetext (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"
28
75b6d5659a19 Better browser support.
viric@llimona
parents: 25
diff changeset
    39
#if 0
75b6d5659a19 Better browser support.
viric@llimona
parents: 25
diff changeset
    40
"    x = ev.x + window.pageXOffset;\n"
75b6d5659a19 Better browser support.
viric@llimona
parents: 25
diff changeset
    41
#endif
75b6d5659a19 Better browser support.
viric@llimona
parents: 25
diff changeset
    42
"    y = ev.pageY;\n"
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    43
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    44
"    if (blocked != \"\")\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    45
"        return;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    46
#if 0
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    47
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    48
"    if (x + 320 > window.innerWidth)\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    49
"        x = window.innerWidth - 320;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    50
"\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
"    if (y < window.innerHeight / 2)\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    53
"    {\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    54
"        y += 5;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    55
"        document.getElementById(element).style.top = y;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    56
"    } else {\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    57
"        y -= 5;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    58
"        document.getElementById(element).style.top = 0;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    59
"        document.getElementById(element).style.bottom = y;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    60
"    }\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    61
"    */\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    62
#endif
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    63
"    y += 5;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    64
"    document.getElementById(element).style.top = y + 'px';\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    65
"    \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.left = 0;\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    68
*/
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    69
"    document.getElementById(element).style.display = 'block';\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    70
"}\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
"function undisplay(element)\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
"    document.getElementById(element).style.display = 'none';\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    75
"}\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    76
"\n"
28
75b6d5659a19 Better browser support.
viric@llimona
parents: 25
diff changeset
    77
"function klako(element, ev)\n"
24
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
"    if (blocked == \"\")\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    80
"    {\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    81
"        display(element, ev);\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    82
"        blocked = element;\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
"    else\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    85
"    {\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    86
"        undisplay(blocked);\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    87
"        blocked = \"\";\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
"}\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    90
"\n"
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    91
"</script>"
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
}
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
static void print_html_footer()
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
    printf("</body></html>\n");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
    99
}
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   100
25
8d524bb8dcea Changed the name for zprocess to prepare_akcentiga
viric@llimona
parents: 24
diff changeset
   101
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
   102
        const unsigned char *signifo)
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   103
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   104
    int i;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   105
    char last;
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
    printf("<p>## Se moto %s:</p>\n<p>", word);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   108
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   109
    last = 0;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   110
    i=0;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   111
    do
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   112
    {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   113
        char nun;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   114
        nun = *signifo;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   115
        if (nun == '\0')
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   116
            break;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   117
        if (nun == '\n' && last == '\n')
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   118
            printf("</p><p>");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   119
        putchar(nun);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   120
        last = nun;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   121
        ++signifo;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   122
    } while(1);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   123
    printf("</p>");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   124
}
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
static void print_start_signifoj(int id)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   127
{
28
75b6d5659a19 Better browser support.
viric@llimona
parents: 25
diff changeset
   128
    printf("<div id=\"vorto%i\" onclick=\"klako('vorto%i', event);\" "
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   129
            "class=\"difino\"><p>\n", id, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   130
}
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
static void print_end_signifoj()
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
    printf("</p></div>");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   135
}
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   136
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   137
/* This expects the word to start exactly at *wordlist */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   138
static void print_signifoj(char *wordlist, int id)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   139
{
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   140
    char * next_space;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   141
    char def[MAXDEF];
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   142
    int start_shown = 0;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   143
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   144
    do {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   145
        next_space = strchr(wordlist, ' ');
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, '\n');
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   148
        if (next_space == 0)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   149
            next_space = strchr(wordlist, '\0');
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   150
        if (next_space != 0 && next_space != wordlist)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   151
        {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   152
            int spacepos;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   153
            spacepos = next_space - wordlist;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   154
            wordlist[spacepos] = 0;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   155
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   156
            /* wordlist has the word to search */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   157
            find_def(&dsignifoj, wordlist, def);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   158
            if (def[0])
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
                if (!start_shown)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   161
                {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   162
                    print_start_signifoj(id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   163
                    start_shown = 1;
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
                dump_signifo_with_p(wordlist, def);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   166
            }
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   167
        } else
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   168
            break;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   169
        wordlist = next_space + 1;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   170
    } while(1);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   171
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   172
    if (start_shown)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   173
        print_end_signifoj();
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   174
}
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
static print_accented(const char *word, int id)
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
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   179
    {
28
75b6d5659a19 Better browser support.
viric@llimona
parents: 25
diff changeset
   180
        printf("<span class=\"vorto\" onclick=\"klako('vorto%i', event);\">"
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   181
                "%s</span>",id,word);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   182
    } else
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   183
        printf("%s", word);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   184
}
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   185
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   186
static void give_accent_to_word(const char *word)
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   187
{
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   188
    char def[MAXDEF];
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   189
    char low[MAXWORD];
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   190
    char recased[MAXWORD];
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   191
    enum Case vcase[MAXWORD];
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   192
    static int id = 1;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   193
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   194
    /* Get case */
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   195
    get_case(vcase, word);
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   196
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   197
    /* Get lowercase version */
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   198
    get_lowcase_str(low, word);
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   199
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   200
    /* Find the lowercase version */
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   201
    find_def(&dakcentiga, low, def);
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   202
    if (def[0] != 0) /* found */
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   203
    {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   204
        /* Print the word UNTIL a space.
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   205
         * the definition will have the form:
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   206
         *    ACCENTED_WORD NOMINATIVE1 NOMINATIVE2 ... \n */
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   207
        char *first_space;
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   208
        char spacepos;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   209
        first_space = strchr(def, ' ');
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   210
        if (first_space != 0) /* Space found */
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   211
        {
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   212
            spacepos = first_space - def;
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   213
            def[spacepos] = 0; /* Mark an end of string */
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   214
            reapply_case(recased, def, vcase);
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   215
            print_accented(recased, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   216
            if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   217
                print_signifoj(first_space + 1 /*' '*/, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   218
            ++id;
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   219
        }
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   220
        return;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   221
    }
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   222
    else if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   223
    {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   224
        char def[MAXDEF];
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   225
        /* 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
   226
         * print_signifoj() */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   227
        find_def(&dsignifoj, low, def);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   228
        if (def[0])
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   229
        {
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   230
            print_accented(word, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   231
            print_signifoj(low, id);
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   232
            ++id;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   233
            return;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   234
        }
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   235
    }
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   236
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   237
    /* else ... */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   238
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   239
    /* 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
   240
     * when give_html...*/
15
17a66ceb774a Pritraktado de majuskloj per ICU.
viric@llimona
parents: 14
diff changeset
   241
    printf("%s", word);
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   242
}
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   243
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   244
static int my_fgetc(FILE *f)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   245
{
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   246
    if (is_http)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   247
        return http_getc(f);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   248
    else
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   249
        return fgetc(f);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   250
}
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   251
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   252
static void process_text(FILE *in, int pos, int length)
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   253
{
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   254
    unsigned char tmp[MAXWORD];
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   255
    int wordpos = 0;
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   256
    int skip_non_ascii = 0;
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   257
    int last = 0;
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   258
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   259
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   260
        printf("<div class=\"alineo\">");
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   261
    do
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   262
    {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   263
        int c;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   264
        /* Check pos only if length >= 0 */
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   265
        if (length >= 0 && pos >= length)
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   266
            break;
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   267
        c = my_fgetc(in);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   268
        if (c == EOF || c == END_OF_URL)
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   269
            break;
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   270
        if (c == '\r')
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   271
            continue;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   272
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   273
        /* Process 'last' for eventual line break */
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   274
        if (give_html && c == '\n' && last == '\n')
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   275
            printf("</div>\n<div class=\"alineo\">");
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   276
        last = c;
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   277
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   278
        if (skip_non_ascii || is_ASCII(c))
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   279
        {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   280
            if (wordpos != 0)
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   281
            {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   282
                tmp[wordpos] = 0;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   283
                give_accent_to_word(tmp);
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   284
                wordpos = 0;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   285
            }
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   286
            putchar(c);
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   287
            /* End of skip_non_ascii when we find an
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   288
             * ascii string */
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   289
            if (skip_non_ascii && is_ASCII(c))
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   290
                skip_non_ascii = 0;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   291
        }
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   292
        else /* non-ASCII - we consider it russian */
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   293
        {
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   294
            tmp[wordpos++] = c;
18
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   295
            if (wordpos >= MAXWORD)
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   296
            {
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   297
                /* Dump the word and the rest of non-ASCII, because
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   298
                 * we cannot fit it in 'tmp' */
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   299
                int i;
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   300
                for(i=0; i < wordpos; ++i)
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   301
                    putchar(tmp[i]);
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   302
                wordpos=0;
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   303
                skip_non_ascii = 1;
64ed4238657f Fixed possible buffer overflow.
viric@llimona
parents: 17
diff changeset
   304
            }
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   305
        }
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   306
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   307
        pos += 1;
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   308
    } while(1);
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   309
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   310
    /* End word */
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   311
    if (wordpos != 0)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   312
    {
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   313
        tmp[wordpos] = 0;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   314
        give_accent_to_word(tmp);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   315
        wordpos = 0;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   316
    }
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   317
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   318
        printf("</div>");
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   319
}
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
static print_http_header()
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
    printf("Content-Type:text/html;charset=utf-8\r\n\r\n");
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   324
}
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
int eat_form_ok()
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   327
{
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   328
    const char mask[] = "teksto=";
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   329
    char tmp[sizeof(mask)];
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   330
    fread(tmp, 1, sizeof(mask)-1, stdin);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   331
    tmp[sizeof(mask)-1] = 0;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   332
    if (strcmp(mask, tmp) == 0)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   333
        return 1;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   334
    return 0;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   335
}
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   336
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   337
int main()
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   338
{
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   339
    char *c;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   340
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   341
    init_dictionary(&dakcentiga, "akcentiga");
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   342
    init_dictionary(&dsignifoj, "signifoj");
17
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
    if (c = getenv("CONTENT_LENGTH"))
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   345
    {
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   346
        content_length = atoi(c);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   347
        is_http = 1;
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
    if (is_http)
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   350
    {
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   351
        print_http_header();
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   352
        if (!eat_form_ok())
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   353
            return -1;
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   354
    }
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   355
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   356
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   357
        print_html_header();
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   358
    /* We pass -1 so we don't check content length */
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   359
    process_text(stdin, 0, -1);
24
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   360
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   361
    if (give_html)
026a2ba0ce16 Now the HTML result shows word meanings.
viric@llimona
parents: 18
diff changeset
   362
        print_html_footer();
17
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   363
    end_dictionary(&dakcentiga);
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   364
d95d9e7a2b81 General interface to dictionary search.
viric@llimona
parents: 15
diff changeset
   365
    return 0;
14
a961bb8806b9 first 'zparsetext'.
viric@llimona
parents:
diff changeset
   366
}