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