14
|
1 |
#include <stdio.h>
|
|
2 |
#include "dictre.h"
|
|
3 |
|
15
|
4 |
static void give_accent_to_word(const char *word)
|
14
|
5 |
{
|
|
6 |
char def[MAXDEF];
|
15
|
7 |
char low[MAXWORD];
|
|
8 |
char recased[MAXWORD];
|
|
9 |
enum Case vcase[MAXWORD];
|
14
|
10 |
|
15
|
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);
|
14
|
19 |
if (def[0] != 0) /* found */
|
|
20 |
{
|
|
21 |
/* Print the word UNTIL a space.
|
|
22 |
* the definition will have the form:
|
|
23 |
* ACCENTED_WORD NOMINATIVE1 NOMINATIVE2 ... \n */
|
|
24 |
char *first_space;
|
15
|
25 |
char spacepos;
|
14
|
26 |
first_space = strchr(def, ' ');
|
|
27 |
if (first_space != 0) /* Space found */
|
15
|
28 |
{
|
|
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 |
}
|
14
|
34 |
return;
|
|
35 |
}
|
|
36 |
|
|
37 |
/* if first_space == 0 or word not found */
|
15
|
38 |
printf("%s", word);
|
14
|
39 |
}
|
|
40 |
|
|
41 |
static void process_text(FILE *in, int pos, int length)
|
|
42 |
{
|
|
43 |
unsigned char tmp[MAXWORD];
|
|
44 |
int wordpos = 0;
|
|
45 |
do
|
|
46 |
{
|
|
47 |
int c;
|
|
48 |
/* Check pos only if length >= 0 */
|
|
49 |
if (length >= 0 && pos >= length)
|
|
50 |
break;
|
|
51 |
c = fgetc(in);
|
|
52 |
if (c == EOF)
|
|
53 |
break;
|
|
54 |
if (is_ASCII(c))
|
|
55 |
{
|
|
56 |
if (wordpos != 0)
|
|
57 |
{
|
|
58 |
tmp[wordpos] = 0;
|
|
59 |
give_accent_to_word(tmp);
|
|
60 |
wordpos = 0;
|
|
61 |
}
|
|
62 |
putchar(c);
|
|
63 |
}
|
|
64 |
else /* non-ASCII - we consider it russian */
|
|
65 |
{
|
|
66 |
tmp[wordpos++] = c;
|
|
67 |
}
|
|
68 |
|
|
69 |
pos += 1;
|
|
70 |
} while(1);
|
|
71 |
}
|
|
72 |
|
|
73 |
int main()
|
|
74 |
{
|
|
75 |
init_dictionary();
|
|
76 |
process_text(stdin, 0, -1);
|
|
77 |
end_dictionary();
|
|
78 |
}
|