11 DictMgr::DictMgr(const char * dictpath
, const char * etype
)
13 // load list of etype entries
15 pdentry
= (dictentry
*)malloc(MAXDICTIONARIES
*sizeof(struct dictentry
));
17 if (parse_file(dictpath
, etype
)) {
19 // no dictionary.lst found is okay
29 dictentry
* pdict
= NULL
;
32 for (int i
=0;i
<numdict
;i
++) {
41 if (pdict
->filename
) {
42 free(pdict
->filename
);
43 pdict
->filename
= NULL
;
55 // read in list of etype entries and build up structure to describe them
56 int DictMgr::parse_file(const char * dictpath
, const char * etype
)
60 char line
[MAXDICTENTRYLEN
+1];
61 dictentry
* pdict
= pdentry
;
63 // open the dictionary list file
65 dictlst
= fopen(dictpath
,"r");
70 // step one is to parse the dictionary list building up the
71 // descriptive structures
73 // read in each line ignoring any that dont start with etype
74 while (fgets(line
,MAXDICTENTRYLEN
,dictlst
)) {
77 /* parse in a dictionary entry */
78 if (strncmp(line
,etype
,4) == 0) {
79 if (numdict
< MAXDICTIONARIES
) {
83 while ((piece
=mystrsep(&tp
,' '))) {
87 case 1: pdict
->lang
= mystrdup(piece
); break;
88 case 2: if (strcmp (piece
, "ANY") == 0)
89 pdict
->region
= mystrdup("");
91 pdict
->region
= mystrdup(piece
);
93 case 3: pdict
->filename
= mystrdup(piece
); break;
104 fprintf(stderr
,"dictionary list corruption in line \"%s\"\n",line
);
114 // return text encoding of dictionary
115 int DictMgr::get_list(dictentry
** ppentry
)
123 // strip strings into token based on single char delimiter
124 // acts like strsep() but only uses a delim char and not
127 char * DictMgr::mystrsep(char ** stringp
, const char delim
)
130 char * mp
= *stringp
;
133 char * dp
= (char *)memchr(mp
,(int)((unsigned char)delim
),n
);
136 int nc
= (int)((unsigned long)dp
- (unsigned long)mp
);
137 rv
= (char *) malloc(nc
+1);
142 rv
= (char *) malloc(n
+1);
153 // replaces strdup with ansi version
154 char * DictMgr::mystrdup(const char * s
)
159 d
= (char *) malloc(((sl
+1) * sizeof(char)));
160 if (d
) memcpy(d
,s
,((sl
+1)*sizeof(char)));
166 // remove cross-platform text line end characters
167 void DictMgr:: mychomp(char * s
)
170 if ((k
> 0) && ((*(s
+k
-1)=='\r') || (*(s
+k
-1)=='\n'))) *(s
+k
-1) = '\0';
171 if ((k
> 1) && (*(s
+k
-2) == '\r')) *(s
+k
-2) = '\0';