zdefs.c
changeset 11 68ea18fe402c
child 14 a961bb8806b9
equal deleted inserted replaced
10:188a0e3b3fb4 11:68ea18fe402c
       
     1 #include <stdio.h>
       
     2 #include "dictre.h"
       
     3 
       
     4 static void new_word(const char *str)
       
     5 {
       
     6     printf("%s\n", str);
       
     7 }
       
     8 
       
     9 static int skip_newline(const char *str, int *index)
       
    10 {
       
    11     while(str[*index] != 0 && str[*index] != '\n')
       
    12     {
       
    13         ++*index;
       
    14     }
       
    15 
       
    16     if (str[*index] == '\n')
       
    17         return *index;
       
    18 
       
    19     return -1;
       
    20 }
       
    21 
       
    22 static int until_noword(const char *str, int *index)
       
    23 {
       
    24     while(str[*index] != 0 &&
       
    25             str[*index] != ' ' &&
       
    26             str[*index] != '\n' &&
       
    27             str[*index] != '\r' &&
       
    28             str[*index] != ',')
       
    29     {
       
    30         ++*index;
       
    31     }
       
    32 
       
    33     if (str[*index] != 0)
       
    34         return *index;
       
    35 
       
    36     return -1;
       
    37 }
       
    38 
       
    39 static int until_newword(const unsigned char *str, int *index)
       
    40 {
       
    41     while(str[*index] != 0 && str[*index] < 128)
       
    42     {
       
    43         ++*index;
       
    44     }
       
    45 
       
    46     if (str[*index] != 0);
       
    47         return *index;
       
    48 
       
    49     return -1;
       
    50 }
       
    51 
       
    52 void zprocess_def(const char *root, char *def)
       
    53 {
       
    54     int index = 0;
       
    55     int res;
       
    56     /* Jump the first line (index word) Wait for \n */
       
    57     skip_newline(def, &index);
       
    58     ++index;
       
    59 
       
    60     res = until_newword(def, &index);
       
    61     if (res == -1)
       
    62         return;
       
    63 
       
    64     /* Mark words */
       
    65     do {
       
    66         int end;
       
    67         end = index;
       
    68         res = until_noword(def, &end);
       
    69         if (res == -1)
       
    70             break;
       
    71         def[end] = 0;
       
    72         insert_word(&def[index], root);
       
    73         index = end+1;
       
    74         res = until_newword(def,&index);
       
    75         if (res == -1)
       
    76             break;
       
    77     } while (1);
       
    78     free(def);
       
    79     free(root);
       
    80 }