10 DictMgr::DictMgr(const char * dictpath, const char * etype) : numdict(0)
12 // load list of etype entries
13 pdentry = (dictentry *)malloc(MAXDICTIONARIES*sizeof(struct dictentry));
15 if (parse_file(dictpath, etype)) {
17 // no dictionary.lst found is okay
25 dictentry * pdict = NULL;
28 for (int i=0;i<numdict;i++) {
37 if (pdict->filename) {
38 free(pdict->filename);
39 pdict->filename = NULL;
51 // read in list of etype entries and build up structure to describe them
52 int DictMgr::parse_file(const char * dictpath, const char * etype)
56 char line[MAXDICTENTRYLEN+1];
57 dictentry * pdict = pdentry;
59 // open the dictionary list file
61 dictlst = myfopen(dictpath,"r");
66 // step one is to parse the dictionary list building up the
67 // descriptive structures
69 // read in each line ignoring any that dont start with etype
70 while (fgets(line,MAXDICTENTRYLEN,dictlst)) {
73 /* parse in a dictionary entry */
74 if (strncmp(line,etype,4) == 0) {
75 if (numdict < MAXDICTIONARIES) {
79 while ((piece=mystrsep(&tp,' '))) {
83 case 1: pdict->lang = mystrdup(piece); break;
84 case 2: if (strcmp (piece, "ANY") == 0)
85 pdict->region = mystrdup("");
87 pdict->region = mystrdup(piece);
89 case 3: pdict->filename = mystrdup(piece); break;
111 fprintf(stderr,"dictionary list corruption in line \"%s\"\n",line);
121 // return text encoding of dictionary
122 int DictMgr::get_list(dictentry ** ppentry)
130 // strip strings into token based on single char delimiter
131 // acts like strsep() but only uses a delim char and not
134 char * DictMgr::mystrsep(char ** stringp, const char delim)
137 char * mp = *stringp;
138 size_t n = strlen(mp);
140 char * dp = (char *)memchr(mp,(int)((unsigned char)delim),n);
144 rv = (char *) malloc(nc+1);
150 rv = (char *) malloc(n+1);
162 // replaces strdup with ansi version
163 char * DictMgr::mystrdup(const char * s)
167 int sl = strlen(s)+1;
168 d = (char *) malloc(sl);
169 if (d) memcpy(d,s,sl);
175 // remove cross-platform text line end characters
176 void DictMgr:: mychomp(char * s)
179 if ((k > 0) && ((*(s+k-1)=='\r') || (*(s+k-1)=='\n'))) *(s+k-1) = '\0';
180 if ((k > 1) && (*(s+k-2) == '\r')) *(s+k-2) = '\0';