Debian Codegraph @

cuneiform_src/Kern/rling/sources/c/speldici.c

raw symbols SCIP
1 /*
2 Copyright (c) 1993-2008, Cognitive Technologies
3 All rights reserved.
4
5 Разрешается повторное распространение и использование как в виде исходного кода,
6 так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
7
8 * При повторном распространении исходного кода должны оставаться указанное
9 выше уведомление об авторском праве, этот список условий и последующий
10 отказ от гарантий.
11 * При повторном распространении двоичного кода в документации и/или в
12 других материалах, поставляемых при распространении, должны сохраняться
13 указанная выше информация об авторском праве, этот список условий и
14 последующий отказ от гарантий.
15 * Ни название Cognitive Technologies, ни имена ее сотрудников не могут
16 быть использованы в качестве средства поддержки и/или продвижения
17 продуктов, основанных на этом ПО, без предварительного письменного
18 разрешения.
19
20 ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
21 ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
22 ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
23 ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
24 МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
25 НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
26 ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
27 НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
28 СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
29 ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
30 НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
31 ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
32
33 Redistribution and use in source and binary forms, with or without modification,
34 are permitted provided that the following conditions are met:
35
36 * Redistributions of source code must retain the above copyright notice,
37 this list of conditions and the following disclaimer.
38 * Redistributions in binary form must reproduce the above copyright notice,
39 this list of conditions and the following disclaimer in the documentation
40 and/or other materials provided with the distribution.
41 * Neither the name of the Cognitive Technologies nor the names of its
42 contributors may be used to endorse or promote products derived from this
43 software without specific prior written permission.
44
45 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */
56
57 /**************************************************************************/
58 /* -- Updation history. -- */
59 /**************************************************************************/
60 /* 17-02-93 03:36pm, Mike - File has been commented once more. */
61 /* 04-01-93 09:49pm, Mike - New dictionary file format. */
62 /**************************************************************************/
63 //
64 // 08-13-93 06:33pm, Mike.
65 // Comments: Updating for multi-lingual version of CuneiForm ( release
66 // 28-June-93 ). Release has been received from Joe by FEDERAL
67 // mail.
68 //
69 // 1. Function < uchar * load_stat_dict ( char *point ) > has
70 // been rewritten to use new strems technology.
71 // Parameter CountryCode in the load_stat_dict has been removed.
72 // The global variable uchar language is used now to check current
73 // language settings. All IO operations have been changed to use
74 // data streams from IOLIB.H.
75 // 2. Functions < void user_voc_init (void) > and < static void
76 // unload_user_dicts(void) > have been added after Joe.
77 // 3. Function < void load_user_dicts ( char * list_name, char *
78 // point) > has been rewritten after Joe.
79 // 4. Function < int32_t read_all_voc( int16_t seqn, char *name, char *p ) >
80 // has been removed with new streams technology.
81 //
82 // 08-14-93 06:01pm, Mike
83 //
84 // 5. Function < uchar * load_stat_dict ( char *point ) > has
85 // been changed to load ALL tables at once. Speller's standalone module
86 // MAIN.C need to be changed !!!
87 //
88 // Process indicator:
89 // 1. Preliminary updation. 08-13-93 06:40pm, Mike
90 //
91 /**************************************************************************/
92
93 /**************************************************************************/
94 /*********** Definitions section. ***********************************/
95 /**************************************************************************/
96 #include <string.h>
97 #include <stdio.h>
98
99 #include "spelmode.h"
100
101 #include "recdefs.h"
102 #include "lang.h"
103
104 #include "speldefs.h"
105 #include "spelfunc.h"
106 #include "udicfunc.h"
107 #include "tigeremulate.h"
108
109 #ifndef MAXPATH
110 #define MAXPATH 128
111 #endif
112
113 /**************************************************************************/
114 /*********** Export section. ***********************************/
115 /**************************************************************************/
116 /* -- Code -- */
117
118 // 08-13-93 08:13pm, Mike
119 // Parameter CountryCode has been removed.
120 // 12-09-93 ATAL
121 // This function have tu return proper pointer, never NULL !
122 void * (*my_alloc)(uint32_t len);
123 void (*my_free)(void *);
124 void ErrorExit(int Code);
125 //uint32_t LoadUserDict( char*, char*, uint32_t, voc_state*);
126
127 uchar * load_stat_dict(char *point);
128 /*---------- Updated : 04-01-93 09:46pm, Mike ------
129 Function loads static dictionary file into far memory location
130 <point> The side effect is initialization of decoder table
131 by call of function dectable_init(). New static dictionary
132 format is used : all tables in the one file.
133 Returns far pointer to the next available memory block.
134 --------------------------------------------------*/
135
136 void init_stat_dict(struct dict_state * dict);
137 /*-----------------17-02-93 03:21pm-----------------
138 Function copies static dictionary control structure from far memory
139 <load_dict> into NEAR control structure <dict>.
140 --------------------------------------------------*/
141
142 // 08-13-93 08:55pm, Mike
143 // Return type has been changed from <uchar *> to <void>
144 void load_user_dicts(char * list_name, char * point);
145 /*-----------------17-02-93 03:30pm-----------------
146 Function loads user's dictionaries into memory by
147 list of vocs.
148 --------------------------------------------------*/
149 void unload_user_dicts(void);
150
151 // 08-13-93 06:35pm, Mike after Joe...
152 extern int32_t read_all_vtab(int16_t seqn, char *p);
153
154 /* -- Data -- */
155
156 struct dict_state * load_dict = NULL; //Allex 09.07.98
157 /*-----------------17-02-93 02:49pm-----------------
158 Global work pointer to static dictionary control structure.
159 --------------------------------------------------*/
160
161 user_voc voc_array[MAX_VOC_NUMBER];
162 int16_t real_voc_no = 0;
163
164 // 08-13-93 06:35pm, Mike after Joe...
165 extern int16_t vocs_NOK;
166
167 /**************************************************************************/
168 /*********** Import section. ***********************************/
169 /**************************************************************************/
170 /* -- Code -- */
171
172 int16_t cond_open(int16_t seqn, puchar name, uint16_t b1, uint16_t b2);
173 puchar seq_nam(int16_t seqn);
174 pchar full_name(puchar w, puchar n);
175
176 /* -- Data -- */
177
178 extern uchar alphabet[][ABCSIZE];
179
180 extern char tiger_dir[40];
181
182 /**************************************************************************/
183 /*********** Locals section. *************************************/
184 /**************************************************************************/
185 /* -- Code -- */
186
187 // 08-13-93 06:32pm, Mike
188 // int32_t read_all_voc(int16_t seqn, char *name, char *p);
189 // /*-----------------17-02-93 02:27pm-----------------
190 // Function reads an dictionary file with name <name>
191 // or with number <seqn> into far memory location <p>.
192 // --------------------------------------------------*/
193
194 static int16_t parce_voc_list_record(char * w, char * nm, int16_t *type);
195
196 /**************************************************************************/
197 /*********** Code section. **************************************/
198 /**************************************************************************/
199
200 uchar * load_stat_dict(char *point)
201 /*---------- Updated : 04-01-93 09:46pm, Mike ------
202 Function loads static dictionary file into far memory location
203 <point> The side effect is initialization of decoder table
204 by call of function dectable_init(). New static dictionary
205 format is used : all tables in the one file.
206 Returns far pointer to the next available memory block.
207 --------------------------------------------------*/
208 {
209 int32_t size;
210 PTDictState dict;
211 PTDictHeaderMask dictHdr;
212 char nearBuf[65];
213 uint32_t treeLength, tailsLength;
214 uint32_t rulesLength, hushLength;
215
216 if (!InitializeAlphabet(language)) {
217 ErrorExit(RLING_ERROR_CANT_OPEN_TABLE);
218 }
219
220 /* -- Initialize control pointers. -- */
221 load_dict = dict = (PTDictState) point;
222 point += sizeof(TDictState);
223
224 /* -- Read whole static dictionary file. -- */
225 size = read_all_vtab(7, point);
226 if (size == -1) {
227 #ifdef SYSPR_ERROR
228 PRINTF("Unable to open TREE.VOC \n");
229 #endif
230 ErrorExit(RLING_ERROR_CANT_OPEN_TABLE);
231 //return (uchar *)dict;
232 } else {
233 dict->size = size;
234 dictHdr = (PTDictHeaderMask) point;
235 }
236
237 /* -- Check correctness of file header. -- */
238 memcpy(nearBuf, dictHdr->sign, sizeof(dictHdr->sign));
239 if (memcmp(nearBuf, STAT_DICT_SIGN, sizeof(STAT_DICT_SIGN))) {
240 return (uchar *) dict;
241 }
242
243 /* -- Check CPU type for current data. -- */
244 #ifdef PC_TYPE
245 if ( dictHdr->cpuType[0] != 'I' ) {
246 return (uchar *)dict;
247 }
248 #endif
249 #ifdef __MAC__
250 if ( dictHdr->cpuType[0] != 'M' ) {
251 return (uchar *)dict;
252 }
253 #endif
254
255 /* -- Get data section sizes. -- */
256 treeLength = strtoul(dictHdr->treeLength, NULL, 10);
257 tailsLength = strtoul(dictHdr->tailsLength, NULL, 10);
258 rulesLength = strtoul(dictHdr->rulesLength, NULL, 10);
259 hushLength = strtoul(dictHdr->hushLength, NULL, 10);
260
261 /* -- Get alphabet size. -- */
262 size = strtoul(dictHdr->abcSize, NULL, 10);
263 if (size > 64) {
264 return (uchar *) dict;
265 } else {
266 dict->abcSize = (uint16_t) size;
267 }
268
269 /* -- Load decode tables. -- NEED TO THINK ABOUT !!!
270 --
271 -- memcpy( nearBuf, dictHdr->abcUpper, sizeof(dictHdr->abcUpper));
272 -- memcpy( alphabet[0], nearBuf, sizeof(dictHdr->abcUpper) );
273 -- memcpy( nearBuf, dictHdr->abcLower, sizeof(dictHdr->abcLower));
274 -- memcpy( alphabet[1], nearBuf, sizeof(dictHdr->abcLower) );
275 --
276 */
277
278 /* -- Initialize decoder tables. */
279 dectable_init();
280
281 /* -- Set pointers for access procedure. -- */
282 dict->root = (uchar *) dictHdr + sizeof(TDictHeaderMask);
283 dict->tailset_root = (uchar *) dict->root + treeLength;
284 dict->vartable = (PTTailVar)((uchar *) dict->tailset_root + tailsLength);
285 dict->table = (PTShiftType)((uchar *) dict->vartable + rulesLength);
286
287 /* -- Check size corectness. -- */
288 size = treeLength + tailsLength + rulesLength + hushLength
289 + sizeof(TDictHeaderMask);
290
291 if ((int32_t) dict->size != size) {
292 return (uchar *) dict;
293 }
294
295 // 08-14-93 05:50pm, Mike
296 // Bolvano ( after Lepik )!!!!
297 // If you want to use .ART and so on you need to load these files!!!!!
298
299 // else {
300 // return dict->root + dict->size;
301 // }
302
303 // Here is the new version of dictionary loading.
304
305 point = dict->root + dict->size; // temp: for return value counting.
306
307 if ((point = load_specABC(point, language)) == NULL) {
308 #ifdef SYSPR
309 PRINTF( "\n SPELLER: Unable to open Special voc...\n");
310 #endif
311 return (uchar *) dict;
312 }
313
314 if (!loadArtBase(language)) {
315 #ifdef SYSPR
316 PRINTF( "\n SPELLER: Problems to load special"
317 " replacement table...\n"
318 );
319 #endif
320 return (uchar *) dict;
321 }
322
323 return point;
324 }
325
326 /* ------------------------------------------------------------------ */
327 // 08-13-93 05:37pm, Mike
328 // Not needed with IOLIB.H
329 //
330 //int32_t read_all_voc( int16_t seqn, char *name, char *p )
331 // /*-----------------17-02-93 02:27pm-----------------
332 // Function reads an dictionary file with name <name>
333 // or with number <seqn> into far memory location <p>.
334 // --------------------------------------------------*/
335 //{
336 // int32_t l;
337 // uchar w[MAXPATH];
338 //
339 // full_name( w, (puchar)name );
340 // l = read_all_file( (char *)w, p );
341 // if ( l <= 0 ) {
342 // full_name( w, (puchar)seq_nam( seqn ));
343 // l = read_all_file( (char *)w, p );
344 // }
345 //
346 // return l;
347 //}
348 //
349 /* ------------------------------------------------------------------ */
350
351 void init_stat_dict(struct dict_state * dict)
352 /*-----------------17-02-93 03:21pm-----------------
353 Function copies static dictionary control structure from far memory
354 <load_dict> into NEAR control structure <dict>.
355 --------------------------------------------------*/
356 {
357 memcpy(dict, load_dict, sizeof(struct dict_state));
358 }
359
360 /* ------------------------------------------------------------------ */
361 // 08-13-93 05:54pm, Mike
362 // From Joe...
363
364 void user_voc_init(void) {
365 real_voc_no = 0;
366 }
367
368 /* ------------------------------------------------------------------ */
369 // 08-13-93 05:54pm, Mike
370 // From Joe...
371
372 void unload_user_dicts(void) {
373 int i;
374 for (i = 0; i < real_voc_no; i++) {
375 my_free(voc_array[i].voc.vocseg/*,0*/);
376 }
377 real_voc_no = 0;
378 }
379
380 /* ------------------------------------------------------------------ */
381
382 #define VOCMEMSIZE 0x10000L /* 64K */
383 // old version : read list of vocs from disk file USER.LST
384
385 void load_user_dicts_kzl(char * list_name, char * point)
386 /*-----------------17-02-93 03:30pm-----------------
387 Function loads user's dictionaries into memory by
388 list of vocs.
389 --------------------------------------------------*/
390 {
391 char w[MAXPATH], nm[MAXPATH];
392 FILE * lst;
393 int16_t type;
394 int16_t errorNo = 0;
395
396 unload_user_dicts();
397
398 lst = fopen(list_name, "rt");
399 if (lst < 0) {
400 return;
401 }
402
403 while (fgets(w, MAXPATH, lst) != NULL) {
404
405 if (real_voc_no == MAX_VOC_NUMBER) {
406 errorNo = VOC_TOOLARGELIST;
407 break;
408 }
409
410 if (!parce_voc_list_record(w, nm, &type)) {
411 continue;
412 }
413
414 if ((point = my_alloc(VOCMEMSIZE)) == NULL) {
415 errorNo = VOC_NOTLOADED;
416 break;
417 }
418
419 if (LoadUserDict(nm, point, VOCMEMSIZE, &(voc_array[real_voc_no].voc))
420 == 0L) {
421 my_free(point/*, 0*/);
422 errorNo = VOC_NOTLOADED;
423 break;
424 }
425
426 real_voc_no++;
427 }
428
429 fclose(lst);
430 if (errorNo != 0) {
431 ErrorExit( /*ERR_voc,*/errorNo);
432 }
433
434 return;
435 }
436 //////////////////////////////////////////////////////////////////////////////
437 // list_of_name if concat many vocs name, cutting '\0', last limit is "\0\0"
438 /*-----------------17-02-93 03:30pm-----------------
439 Function loads user's dictionaries into memory using
440 list of names of vocabularies(in list_of_names).
441 --------------------------------------------------*/
442 void load_user_dicts(char * list_of_names, char * point) {
443 int16_t type;
444 int16_t errorNo = 0;
445 char nm[MAXPATH];
446
447 unload_user_dicts();
448
449 while ((*list_of_names) != 0) {
450 if (real_voc_no == MAX_VOC_NUMBER) {
451 errorNo = RLING_ERROR_TOO_MANY_USER_DICTONARY;
452 break;
453 }
454
455 if (!parce_voc_list_record(list_of_names, nm, &type)) {
456 continue;
457 }
458
459 if ((point = my_alloc(VOCMEMSIZE)) == NULL) {
460 errorNo = RLING_ERROR_CANT_OPEN_USER_DICTONARY;
461 break;
462 }
463
464 if (LoadUserDict(nm, point, VOCMEMSIZE, &(voc_array[real_voc_no].voc))
465 == 0L) {
466 my_free(point /*,0*/);
467 errorNo = RLING_ERROR_CANT_OPEN_USER_DICTONARY;
468 break;
469 }
470
471 list_of_names += (strlen(list_of_names) + 1);
472 real_voc_no++;
473 }
474
475 if (errorNo != 0) {
476 unload_user_dicts();
477 ErrorExit(errorNo);
478 }
479
480 return;
481 }
482 /* ------------------------------------------------------------------ */
483
484 int16_t parce_voc_list_record(char * w, char * nm, int16_t *type) {
485 *type = 0;
486 while ((*w) && (*w == ' '))
487 w++;
488 if ((!*w) || (*w == '\n'))
489 return 0;
490 while ((*w != ' ') && (*w != 0) && (*w != '\n'))
491 *(nm++) = *(w++);
492 *nm = 0;
493 return 1;
494 }
495
496 /* ------------------------------------------------------------------ */