zdefs.c
author viric@llimona
Tue, 28 Aug 2007 08:29:36 +0200
changeset 12 c755c945a96a
parent 11 68ea18fe402c
child 14 a961bb8806b9
permissions -rw-r--r--
Fixed bug zmixing accents.

#include <stdio.h>
#include "dictre.h"

static void new_word(const char *str)
{
    printf("%s\n", str);
}

static int skip_newline(const char *str, int *index)
{
    while(str[*index] != 0 && str[*index] != '\n')
    {
        ++*index;
    }

    if (str[*index] == '\n')
        return *index;

    return -1;
}

static int until_noword(const char *str, int *index)
{
    while(str[*index] != 0 &&
            str[*index] != ' ' &&
            str[*index] != '\n' &&
            str[*index] != '\r' &&
            str[*index] != ',')
    {
        ++*index;
    }

    if (str[*index] != 0)
        return *index;

    return -1;
}

static int until_newword(const unsigned char *str, int *index)
{
    while(str[*index] != 0 && str[*index] < 128)
    {
        ++*index;
    }

    if (str[*index] != 0);
        return *index;

    return -1;
}

void zprocess_def(const char *root, char *def)
{
    int index = 0;
    int res;
    /* Jump the first line (index word) Wait for \n */
    skip_newline(def, &index);
    ++index;

    res = until_newword(def, &index);
    if (res == -1)
        return;

    /* Mark words */
    do {
        int end;
        end = index;
        res = until_noword(def, &end);
        if (res == -1)
            break;
        def[end] = 0;
        insert_word(&def[index], root);
        index = end+1;
        res = until_newword(def,&index);
        if (res == -1)
            break;
    } while (1);
    free(def);
    free(root);
}