parse_text.c
author viric@llimona
Sat, 01 Sep 2007 00:50:11 +0200
changeset 15 17a66ceb774a
parent 14 a961bb8806b9
child 17 d95d9e7a2b81
permissions -rw-r--r--
Pritraktado de majuskloj per ICU.
viric@14
     1
#include <stdio.h>
viric@14
     2
#include "dictre.h"
viric@14
     3
viric@15
     4
static void give_accent_to_word(const char *word)
viric@14
     5
{
viric@14
     6
    char def[MAXDEF];
viric@15
     7
    char low[MAXWORD];
viric@15
     8
    char recased[MAXWORD];
viric@15
     9
    enum Case vcase[MAXWORD];
viric@14
    10
viric@15
    11
    /* Get case */
viric@15
    12
    get_case(vcase, word);
viric@15
    13
viric@15
    14
    /* Get lowercase version */
viric@15
    15
    get_lowcase_str(low, word);
viric@15
    16
viric@15
    17
    /* Find the lowercase version */
viric@15
    18
    find_def(low, def);
viric@14
    19
    if (def[0] != 0) /* found */
viric@14
    20
    {
viric@14
    21
        /* Print the word UNTIL a space.
viric@14
    22
         * the definition will have the form:
viric@14
    23
         *    ACCENTED_WORD NOMINATIVE1 NOMINATIVE2 ... \n */
viric@14
    24
        char *first_space;
viric@15
    25
        char spacepos;
viric@14
    26
        first_space = strchr(def, ' ');
viric@14
    27
        if (first_space != 0) /* Space found */
viric@15
    28
        {
viric@15
    29
            spacepos = first_space - def;
viric@15
    30
            def[spacepos] = 0; /* Mark an end of string */
viric@15
    31
            reapply_case(recased, def, vcase);
viric@15
    32
            printf("%s", recased);
viric@15
    33
        }
viric@14
    34
        return;
viric@14
    35
    }
viric@14
    36
viric@14
    37
    /* if first_space == 0 or word not found */
viric@15
    38
    printf("%s", word);
viric@14
    39
}
viric@14
    40
viric@14
    41
static void process_text(FILE *in, int pos, int length)
viric@14
    42
{
viric@14
    43
    unsigned char tmp[MAXWORD];
viric@14
    44
    int wordpos = 0;
viric@14
    45
    do
viric@14
    46
    {
viric@14
    47
        int c;
viric@14
    48
        /* Check pos only if length >= 0 */
viric@14
    49
        if (length >= 0 && pos >= length)
viric@14
    50
            break;
viric@14
    51
        c = fgetc(in);
viric@14
    52
        if (c == EOF)
viric@14
    53
            break;
viric@14
    54
        if (is_ASCII(c))
viric@14
    55
        {
viric@14
    56
            if (wordpos != 0)
viric@14
    57
            {
viric@14
    58
                tmp[wordpos] = 0;
viric@14
    59
                give_accent_to_word(tmp);
viric@14
    60
                wordpos = 0;
viric@14
    61
            }
viric@14
    62
            putchar(c);
viric@14
    63
        }
viric@14
    64
        else /* non-ASCII - we consider it russian */
viric@14
    65
        {
viric@14
    66
            tmp[wordpos++] = c;
viric@14
    67
        }
viric@14
    68
viric@14
    69
        pos += 1;
viric@14
    70
    } while(1);
viric@14
    71
}
viric@14
    72
viric@14
    73
int main()
viric@14
    74
{
viric@14
    75
    init_dictionary();
viric@14
    76
    process_text(stdin, 0, -1);
viric@14
    77
    end_dictionary();
viric@14
    78
}