# HG changeset patch # User viric@llimona # Date 1188735850 -7200 # Node ID 026a2ba0ce160a24de8458b3ae2ddf5ab4eb9c01 # Parent 97feccfc5215927bb5694a9113f2942e929b1b2c Now the HTML result shows word meanings. diff -r 97feccfc5215 -r 026a2ba0ce16 dictre.h --- 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 }; diff -r 97feccfc5215 -r 026a2ba0ce16 errors.txt --- 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. diff -r 97feccfc5215 -r 026a2ba0ce16 find.c --- 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; } diff -r 97feccfc5215 -r 026a2ba0ce16 make-signifoj.sh --- 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 diff -r 97feccfc5215 -r 026a2ba0ce16 parse_text.c --- 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( +"\n" +"\n" +" \n" +" Akcentigita teksto\n" +"\n" +"\n" +"\n" +"" +); + +} + +static void print_html_footer() +{ + printf("\n"); +} + +static void dump_signifo_with_p(const char *word, const char *signifo) +{ + int i; + char last; + + printf("

## Se moto %s:

\n

", word); + + last = 0; + i=0; + do + { + char nun; + nun = *signifo; + if (nun == '\0') + break; + if (nun == '\n' && last == '\n') + printf("

"); + putchar(nun); + last = nun; + ++signifo; + } while(1); + printf("

"); +} + +static void print_start_signifoj(int id) +{ + printf("

\n", id, id); +} + +static void print_end_signifoj() +{ + printf("

"); +} + +/* 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("" + "%s",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("
"); 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("
\n
"); + 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("
"); } 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; diff -r 97feccfc5215 -r 026a2ba0ce16 prepare_meanings.c --- 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); } } }