parse_text.c
changeset 15 17a66ceb774a
parent 14 a961bb8806b9
child 17 d95d9e7a2b81
equal deleted inserted replaced
14:a961bb8806b9 15:17a66ceb774a
     1 #include <stdio.h>
     1 #include <stdio.h>
     2 #include "dictre.h"
     2 #include "dictre.h"
     3 
     3 
     4 static void give_accent_to_word(const char *tmp)
     4 static void give_accent_to_word(const char *word)
     5 {
     5 {
     6     char def[MAXDEF];
     6     char def[MAXDEF];
       
     7     char low[MAXWORD];
       
     8     char recased[MAXWORD];
       
     9     enum Case vcase[MAXWORD];
     7 
    10 
     8     find_def(tmp, def);
    11     /* Get case */
       
    12     get_case(vcase, word);
       
    13 
       
    14     /* Get lowercase version */
       
    15     get_lowcase_str(low, word);
       
    16 
       
    17     /* Find the lowercase version */
       
    18     find_def(low, def);
     9     if (def[0] != 0) /* found */
    19     if (def[0] != 0) /* found */
    10     {
    20     {
    11         /* Print the word UNTIL a space.
    21         /* Print the word UNTIL a space.
    12          * the definition will have the form:
    22          * the definition will have the form:
    13          *    ACCENTED_WORD NOMINATIVE1 NOMINATIVE2 ... \n */
    23          *    ACCENTED_WORD NOMINATIVE1 NOMINATIVE2 ... \n */
    14         char *first_space;
    24         char *first_space;
    15         char *pos;
    25         char spacepos;
    16         first_space = strchr(def, ' ');
    26         first_space = strchr(def, ' ');
    17         if (first_space != 0) /* Space found */
    27         if (first_space != 0) /* Space found */
    18             for(pos = def; pos < first_space; ++pos)
    28         {
    19                 putchar(*pos);
    29             spacepos = first_space - def;
       
    30             def[spacepos] = 0; /* Mark an end of string */
       
    31             reapply_case(recased, def, vcase);
       
    32             printf("%s", recased);
       
    33         }
    20         return;
    34         return;
    21     }
    35     }
    22 
    36 
    23     /* if first_space == 0 or word not found */
    37     /* if first_space == 0 or word not found */
    24     printf("%s", tmp);
    38     printf("%s", word);
    25 }
    39 }
    26 
    40 
    27 static void process_text(FILE *in, int pos, int length)
    41 static void process_text(FILE *in, int pos, int length)
    28 {
    42 {
    29     unsigned char tmp[MAXWORD];
    43     unsigned char tmp[MAXWORD];