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;