Making the makefile not depend on /usr.
#include <stdio.h>
#include "dictre.h"
extern struct Word words[];
extern int nwords;
extern struct Def defs[];
extern int ndefs;
static int write_dictionary_data(FILE *fdefs)
{
int i;
int offset = 0;
for (i=0; i < ndefs; ++i)
{
fwrite(defs[i].d, defs[i].length, 1, fdefs);
defs[i].offset = offset;
offset += defs[i].length;
}
}
static void write_dictionary_index(FILE *index)
{
int i;
for (i=0; i < nwords; ++i)
{
char offset_str[50];
char length_str[50];
num_to_ia5(offset_str, defs[words[i].def].offset);
num_to_ia5(length_str, defs[words[i].def].length);
fprintf(index, "%s\t%s\t%s\n",
words[i].w, offset_str, length_str);
}
}
void write_dictionary(const char *name)
{
FILE *i, *d;
char tmpname[500];
strcpy(tmpname, name);
strcat(tmpname, ".dict");
d = fopen(tmpname, "wb");
write_dictionary_data(d);
fclose(d);
strcpy(tmpname, name);
strcat(tmpname, ".index");
i = fopen(tmpname, "wb");
write_dictionary_index(i);
fclose(i);
}