9
DictMgr::DictMgr(const char * dictpath, const char * etype) : numdict(0)
11
// load list of etype entries
12
pdentry = (dictentry *)malloc(MAXDICTIONARIES*sizeof(struct dictentry));
14
if (parse_file(dictpath, etype)) {
16
// no dictionary.lst found is okay
24
dictentry * pdict = NULL;
27
for (int i=0;i<numdict;i++) {
36
if (pdict->filename) {
37
free(pdict->filename);
38
pdict->filename = NULL;
50
// read in list of etype entries and build up structure to describe them
51
int DictMgr::parse_file(const char * dictpath, const char * etype)
55
char line[MAXDICTENTRYLEN+1];
56
dictentry * pdict = pdentry;
58
// open the dictionary list file
60
dictlst = fopen(dictpath,"r");
65
// step one is to parse the dictionary list building up the
66
// descriptive structures
68
// read in each line ignoring any that dont start with etype
69
while (fgets(line,MAXDICTENTRYLEN,dictlst)) {
72
/* parse in a dictionary entry */
73
if (strncmp(line,etype,4) == 0) {
74
if (numdict < MAXDICTIONARIES) {
78
while ((piece=mystrsep(&tp,' '))) {
82
case 1: pdict->lang = mystrdup(piece); break;
83
case 2: if (strcmp (piece, "ANY") == 0)
84
pdict->region = mystrdup("");
86
pdict->region = mystrdup(piece);
88
case 3: pdict->filename = mystrdup(piece); break;
103
case 2: //deliberate fallthrough
109
fprintf(stderr,"dictionary list corruption in line \"%s\"\n",line);
119
// return text encoding of dictionary
120
int DictMgr::get_list(dictentry ** ppentry)
128
// strip strings into token based on single char delimiter
129
// acts like strsep() but only uses a delim char and not
132
char * DictMgr::mystrsep(char ** stringp, const char delim)
135
char * mp = *stringp;
136
size_t n = strlen(mp);
138
char * dp = (char *)memchr(mp,(int)((unsigned char)delim),n);
142
rv = (char *) malloc(nc+1);
148
rv = (char *) malloc(n+1);
160
// replaces strdup with ansi version
161
char * DictMgr::mystrdup(const char * s)
165
int sl = strlen(s)+1;
166
d = (char *) malloc(sl);
167
if (d) memcpy(d,s,sl);
173
// remove cross-platform text line end characters
174
void DictMgr:: mychomp(char * s)
177
if ((k > 0) && ((*(s+k-1)=='\r') || (*(s+k-1)=='\n'))) *(s+k-1) = '\0';
178
if ((k > 1) && (*(s+k-2) == '\r')) *(s+k-2) = '\0';