0
|
1 |
#include <stdio.h>
|
|
2 |
#include "dictre.h"
|
|
3 |
|
|
4 |
extern struct Word words[];
|
|
5 |
extern int nwords;
|
|
6 |
extern struct Def defs[];
|
|
7 |
extern int ndefs;
|
|
8 |
|
|
9 |
static int write_dictionary_data(FILE *fdefs)
|
|
10 |
{
|
|
11 |
int i;
|
|
12 |
|
|
13 |
int offset = 0;
|
|
14 |
|
|
15 |
for (i=0; i < ndefs; ++i)
|
|
16 |
{
|
|
17 |
fwrite(defs[i].d, defs[i].length, 1, fdefs);
|
|
18 |
defs[i].offset = offset;
|
|
19 |
offset += defs[i].length;
|
|
20 |
}
|
|
21 |
}
|
|
22 |
|
|
23 |
static void write_dictionary_index(FILE *index)
|
|
24 |
{
|
|
25 |
int i;
|
|
26 |
|
|
27 |
for (i=0; i < nwords; ++i)
|
|
28 |
{
|
|
29 |
char offset_str[50];
|
|
30 |
char length_str[50];
|
|
31 |
|
|
32 |
num_to_ia5(offset_str, defs[words[i].def].offset);
|
|
33 |
num_to_ia5(length_str, defs[words[i].def].length);
|
|
34 |
fprintf(index, "%s\t%s\t%s\n",
|
|
35 |
words[i].w, offset_str, length_str);
|
|
36 |
}
|
|
37 |
}
|
|
38 |
|
|
39 |
void write_dictionary(const char *name)
|
|
40 |
{
|
|
41 |
FILE *i, *d;
|
|
42 |
char tmpname[500];
|
|
43 |
|
|
44 |
strcpy(tmpname, name);
|
|
45 |
strcat(tmpname, ".dict");
|
|
46 |
d = fopen(tmpname, "wb");
|
|
47 |
write_dictionary_data(d);
|
|
48 |
fclose(d);
|
|
49 |
|
|
50 |
strcpy(tmpname, name);
|
|
51 |
strcat(tmpname, ".index");
|
|
52 |
i = fopen(tmpname, "wb");
|
|
53 |
write_dictionary_index(i);
|
|
54 |
fclose(i);
|
|
55 |
}
|