~ubuntu-branches/debian/experimental/cuneiform/experimental

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rling/sources/c/rling_ma.c

  • Committer: Bazaar Package Importer
  • Author(s): Jakub Wilk, libm.diff, swapbytes.diff
  • Date: 2010-09-14 15:53:54 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100914155354-hhxaa13xmhb82e3e
Tags: 1.0.0+dfsg-1
* New upstream release (closes: #575419).
* New maintainer (closes: #543893).
* Document in README.source how to repackage upstream tarball.
* Update debian/copyright.
  + Document that the package is auto-buildable.
  + Document which files were stripped from the upstream tarball.
  + Convert to the DEP-5 format.
* Drop README.Debian, no longer needed.
* Rewrite debian/rules from scratch using dh.
  + Bump debhelper minimum version to 7.4.4 (for cmake support).
  + Turn on MAKE_VERBOSE_MAKEFILE.
  + Disable call to dh_makeshlibs to avoid creation of spurious
    calls to ldconfig in postrm/postinst.
  + Add get-orig-source target.
* Remove unused overrides.
* Link to GraphicsMagick rather than ImageMagick:
  + Build-depend on graphicsmagick-libmagick-dev-compat.
  + Add patch to properly initialize the library. [graphicsmagick.diff]    
* Bump standards version to 3.9.1 (no changes needed).
* Force upgrade of ocrodjvu to at least 0.4.2; earlier versions of ocrodjvu
  don't support this version of Cuneiform.
* List all the supported languages in the package description.
* Update the manual page.
  + Document --dotmatrix, --fax and --singlecolumn options.
  + Document all output formats.
  + Don't use hyphen as minus sign.
  + Fix a few formatting issues.
* Drop Vcs-* fields.
* Add watch file.
* Add patch from Dmitrijs Ledkovs to link the lao library with libm.
  [libm.diff]
* Add patch for a for a more portable function to swap byte order.
  [swapbytes.diff]
* Set Architecture to any; there's no good reason to limit it.
* Run rudimentary tests at build time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
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
 
*/
 
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
56
 
57
57
#include <assert.h>
58
58
#include <stdio.h>
63
63
#include "compat_defs.h"
64
64
/*************************************************************************/
65
65
/* tg_spell.c -  general spelling loop. It scans ED-file,
66
 
   reads objects, i.e. info between reliable spaces (don't confuse
67
 
   with suspected ones), and estimates words generated from the objects
68
 
   to choose the only best word for each object. The best word is being
69
 
   outputed as the first alternatives for object positions
70
 
                                                                         */
 
66
 reads objects, i.e. info between reliable spaces (don't confuse
 
67
 with suspected ones), and estimates words generated from the objects
 
68
 to choose the only best word for each object. The best word is being
 
69
 outputed as the first alternatives for object positions
 
70
 */
71
71
/*************************************************************************/
72
72
 
73
73
//
81
81
// Process indicator:
82
82
//  1. Preliminary updation. 08-13-93 06:40pm, Mike
83
83
//
84
 
  #include "tuner.h"
85
 
  #include "spelmode.h"
86
 
  #include "nt_types.h"
87
 
  #include "tigeremulate.h"
88
 
  #include "crldefines.h"
89
 
  #include <ctype.h>
90
 
  #include <time.h>
91
 
//  #include <malloc.h>
92
 
  #include "crlmemory.h"
93
 
 
94
 
  #include "recdefs.h"
95
 
  #include "lang_def.h"
96
 
 
97
 
  #include "speldefs.h"
98
 
  #include "spelfunc.h"
99
 
//  #include "iolib.h"        // IO stream library
100
 
/*
101
 
  #if defined(TURBO_C)
102
 
    #include "tc_types.h"
103
 
    #include <dir.h>
104
 
  #elif defined(WATCOM)
105
 
    #include "spelwatc.h"
106
 
  #elif defined(THINK_C)
107
 
    #include "spelthin.h"
108
 
  #else
109
 
    #error   NO TOOOL SPECIFIED
110
 
  #endif
111
 
*/
 
84
#include "tuner.h"
 
85
#include "spelmode.h"
 
86
#include "cttypes.h"
 
87
#include "tigeremulate.h"
 
88
#include "crldefines.h"
 
89
#include <ctype.h>
 
90
#include <time.h>
 
91
#include "crlmemory.h"
 
92
 
 
93
#include "recdefs.h"
 
94
#include "lang_def.h"
 
95
 
 
96
#include "speldefs.h"
 
97
#include "spelfunc.h"
112
98
#include "compat_defs.h"
113
99
//      NEED
114
100
//      1)      proceeding ED-file
117
103
//      4)      call function spelling
118
104
 
119
105
 
120
 
void * (*my_alloc)(Word32 )= RLINGAlloc;                  //rling_alloc;
121
 
void   (*my_free)(void * )= RLINGFree;             //rling_free;
122
 
void   user_voc_init(void);
123
 
void GetRecFileName(Int16 tab,Int16 lang, PInt8 wname);
124
 
void   append_by_lang (Int16 lang, PInt8 src, PInt8 dst);
125
 
//Word32 LoadUserDict(PChar8 DictName, PChar8 pool, Word32 pool_size, voc_state *user_dict);
 
106
void * (*my_alloc)(uint32_t) = RLINGAlloc; //rling_alloc;
 
107
void (*my_free)(void *) = RLINGFree; //rling_free;
 
108
void user_voc_init(void);
 
109
void GetRecFileName(int16_t tab, int16_t lang, pchar wname);
 
110
void append_by_lang(int16_t lang, pchar src, pchar dst);
126
111
///////////////////////////////////////////////////////////
127
 
Int16 to_voc();
 
112
int16_t to_voc();
128
113
///////////////////////////////////////////////////////////
129
114
void trees_load_rling(void);
130
 
static void read_rec_file(Int16 fileno, PWord8 pool, PWord8 * end);
131
 
static PWord8 preload_font_BOX( PWord8 free );
132
 
static PWord8 load_BOX(PWord8 free);
133
 
static PWord8 preload_font_BOX( PWord8 free );
 
115
static void read_rec_file(int16_t fileno, puchar pool, puchar * end);
 
116
static puchar preload_font_BOX(puchar free);
 
117
static puchar load_BOX(puchar free);
 
118
static puchar preload_font_BOX(puchar free);
134
119
static void reload_lang_vocs();
135
 
static void correct_let_tables(void); // ��뢠���� � 䠩�� EMBBOX.C: load_BOX()
 
120
static void correct_let_tables(void); // ўл§лў Ґвбп ў д ©«Ґ EMBBOX.C: load_BOX()
136
121
static void correct_letters_pidx_table(void);
137
 
static PWord8 list_BOX(PWord8 free, Int16 typl);
138
 
static void straight_BOX(PWord8 free);
 
122
static puchar list_BOX(puchar free, int16_t typl);
 
123
static void straight_BOX(puchar free);
139
124
 
140
 
Word8            language;
141
 
Word8            multy_language;
142
 
Int16            vocs_NOK;
143
 
Word8            fax1x2;
144
 
Bool16           FlagMixedText;
145
 
PWord8           ED_file_start   = NULL;
146
 
PWord8           ED_file_end     = NULL;
147
 
PWord8           ED_out_end      = NULL;
148
 
PWord8           svbox_pool      = NULL;
149
 
Int16            CheckOpenBinType = (Int16)(O_RDONLY | O_BINARY);
150
 
Int16            CheckOpenTxtType = (Int16)(O_RDONLY | O_TEXT);
151
 
Int16            CheckOpenSubType = (Int16)(S_IREAD);
152
 
static PWord8    memory_pool     = NULL;       /* start of memory pool */
153
 
static PWord8    memory_pool_end = NULL;           /* end of memory pool */
154
 
static PWord8    auto_pool       = NULL;       /* boxes pool for auto & font tables */
155
 
static PWord8    box_pool        = NULL;       /* boxes pool for extr_comp */
156
 
static PWord8    events_tree     = NULL;
157
 
static PWord8    events_tree_rt  = NULL;       /* events tree memory start */
158
 
static Word8     sv_lang         = 255;
159
 
static PWord8    tableBOX        = NULL;       /* BOX table memory start */
160
 
static Word8     all_loaded      = 0;
161
 
static PWord8    fontBOX         = NULL;        /* BOX table for font  */
162
 
static PWord8    omniBOX         = NULL;        /* BOX save table for omni  */
163
 
static Int32     box_n           = BOX_NUM0;
164
 
static PROOT     root_file       = NULL;                /* start of the root file */
165
 
static PWord8    full_list[512];
166
 
static PWord8    font_full_list[512];
167
 
static PWord8    omni_full_list[512];
168
 
static Int8      seq_name[]            = "rec0";
169
 
Int8      own_dir[256]          = {"./"};
170
 
static Int8      txt_ext[16]           = {"txt"};
171
 
static Int16     file_handle[16]       = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
172
 
static Int16     file_stream[16]       = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
173
 
static Int16     stream_op[10]         = {0,0,0,0,0,0,0,0,0,0};
174
 
static Int8 *lang_suff[LANG_TOTAL] =
175
 
{
176
 
"","grm","frn","rus","swe","spa","ita","r&e","ukr","ser","cro","pol","dan","por","dut","dig",
177
 
"uzb","kaz","kaz",                      // 04.09.2000 E.P.
178
 
"cze","rom","hun","bul",        // 04.09.2000 E.P. LANG_CZECH � �.�.
179
 
"slo",  // LANG_SLOVENIAN 25.05.2001 E.P.
180
 
"lat","lit","est",      // LANG_LATVIAN � �.�.
181
 
"tur"   // 03.06.2002 E.P.
182
 
};
 
125
uchar language;
 
126
uchar multy_language;
 
127
int16_t vocs_NOK;
 
128
uchar fax1x2;
 
129
Bool16 FlagMixedText;
 
130
puchar ED_file_start = NULL;
 
131
puchar ED_file_end = NULL;
 
132
puchar ED_out_end = NULL;
 
133
puchar svbox_pool = NULL;
 
134
int16_t CheckOpenBinType = (int16_t) (O_RDONLY | O_BINARY);
 
135
int16_t CheckOpenTxtType = (int16_t) (O_RDONLY | O_TEXT);
 
136
int16_t CheckOpenSubType = (int16_t) (S_IREAD);
 
137
static puchar memory_pool = NULL; /* start of memory pool */
 
138
static puchar memory_pool_end = NULL; /* end of memory pool */
 
139
static puchar auto_pool = NULL; /* boxes pool for auto & font tables */
 
140
static puchar box_pool = NULL; /* boxes pool for extr_comp */
 
141
static puchar events_tree = NULL;
 
142
static puchar events_tree_rt = NULL; /* events tree memory start */
 
143
static uchar sv_lang = 255;
 
144
static puchar tableBOX = NULL; /* BOX table memory start */
 
145
static uchar all_loaded = 0;
 
146
static puchar fontBOX = NULL; /* BOX table for font  */
 
147
static puchar omniBOX = NULL; /* BOX save table for omni  */
 
148
static int32_t box_n = BOX_NUM0;
 
149
static PROOT root_file = NULL; /* start of the root file */
 
150
static puchar full_list[512];
 
151
static puchar font_full_list[512];
 
152
static puchar omni_full_list[512];
 
153
static char seq_name[] = "rec0";
 
154
char own_dir[256] = { "./" };
 
155
static char txt_ext[16] = { "txt" };
 
156
static int16_t file_handle[16] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
 
157
                -1, -1, -1, -1, -1 };
 
158
static int16_t file_stream[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 
159
                0 };
 
160
static int16_t stream_op[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
161
static char *lang_suff[] = { "", "grm", "frn", "rus", "swe", "spa", "ita",
 
162
                "r&e", "ukr", "ser", "cro", "pol", "dan", "por", "dut", "dig", "uzb",
 
163
                "kaz", "kaz", // 04.09.2000 E.P.
 
164
                "cze", "rom", "hun", "bul", // 04.09.2000 E.P. LANG_CZECH и т.д.
 
165
                "slo", // LANG_SLOVENIAN 25.05.2001 E.P.
 
166
                "lat", "lit", "est", // LANG_LATVIAN и т.д.
 
167
                "tur" // 03.06.2002 E.P.
 
168
                };
183
169
/////////////////////////////////////////////////////////////////////////////////////
184
170
//  exit generation functions
185
 
typedef void(*pExitByCatchFunc)(Int32);
186
 
pExitByCatchFunc    pExitFunc = NULL;
187
 
 
188
 
void SetErrorExit( pExitByCatchFunc  pExternalExitFunc )
189
 
{
190
 
        pExitFunc = pExternalExitFunc;
191
 
}
192
 
 
193
 
void ErrorExit(int Code)
194
 
{
195
 
        if (pExitFunc != NULL )
196
 
                pExitFunc( Code );
197
 
}
198
 
////////////////////////////////////////////////////////////////////////////////////
199
 
//
200
 
void TE_make_name (Int16 stream, PInt8 name, PInt8 wname)
201
 
{
202
 
  PInt8 pn;
203
 
  Int16 l;
204
 
 
205
 
        switch (stream)
206
 
        {
207
 
        case TG_STREAM:
208
 
        case TB_STREAM:
209
 
                /* FIXME: own_dir gets changed somewhere so it points to "/" rather than "./".
210
 
                an = own_dir;
211
 
                strcpy (wname, an);
212
 
                */ strcpy(wname, "./");
213
 
                strcat (wname, name);
214
 
                break;
215
 
 
216
 
        case ED_STREAM:
217
 
        case TX_STREAM:
218
 
 
219
 
                l = strlen (name);
220
 
                pn = name + l;
221
 
 
222
 
                while (l--)
223
 
                {
224
 
                        if (*(--pn) == '.')
225
 
                        {
226
 
                                strcpy (wname, name);
227
 
                                return;
228
 
                        }
229
 
 
230
 
                        if (*pn     == DIRSEP)
231
 
                                break;
232
 
                }
233
 
                strcpy (wname,name);
234
 
                switch (stream)
235
 
                {
236
 
                case ED_STREAM:
237
 
 
238
 
                        strcat (wname,".ed");
239
 
                        break;
240
 
 
241
 
                case TX_STREAM:
242
 
 
243
 
                        strcat (wname,txt_ext);
244
 
                        break;
245
 
                }
246
 
                break;
247
 
 
248
 
        default:
249
 
 
250
 
                strcpy (wname, name);
251
 
                break;
252
 
        }
253
 
}
254
 
////////////////////////////////////////////////////////////////////////////////////
255
 
//
256
 
void GetRecFileName(Int16 tab,Int16 lang, PInt8 wname)
257
 
{
258
 
        seq_name[3] = tab + '0';
259
 
        append_by_lang (lang, seq_name, wname);
260
 
        strcat(wname,".dat");
 
171
typedef void(*pExitByCatchFunc)(int32_t);
 
172
pExitByCatchFunc pExitFunc = NULL;
 
173
 
 
174
void SetErrorExit(pExitByCatchFunc pExternalExitFunc) {
 
175
        pExitFunc = pExternalExitFunc;
 
176
}
 
177
 
 
178
void ErrorExit(int Code) {
 
179
        if (pExitFunc != NULL)
 
180
                pExitFunc(Code);
 
181
}
 
182
////////////////////////////////////////////////////////////////////////////////////
 
183
//
 
184
void TE_make_name(int16_t stream, pchar name, pchar wname) {
 
185
        pchar pn;
 
186
        int16_t l;
 
187
 
 
188
        switch (stream) {
 
189
        case TG_STREAM:
 
190
        case TB_STREAM:
 
191
                /* FIXME: own_dir gets changed somewhere so it points to "/" rather than "./".
 
192
                 an = own_dir;
 
193
                 strcpy (wname, an);
 
194
                 */
 
195
                strcpy(wname, "./");
 
196
                strcat(wname, name);
 
197
                break;
 
198
 
 
199
        case ED_STREAM:
 
200
        case TX_STREAM:
 
201
 
 
202
                l = strlen(name);
 
203
                pn = name + l;
 
204
 
 
205
                while (l--) {
 
206
                        if (*(--pn) == '.') {
 
207
                                strcpy(wname, name);
 
208
                                return;
 
209
                        }
 
210
 
 
211
                        if (*pn == DIRSEP)
 
212
                                break;
 
213
                }
 
214
                strcpy(wname, name);
 
215
                switch (stream) {
 
216
                case ED_STREAM:
 
217
 
 
218
                        strcat(wname, ".ed");
 
219
                        break;
 
220
 
 
221
                case TX_STREAM:
 
222
 
 
223
                        strcat(wname, txt_ext);
 
224
                        break;
 
225
                }
 
226
                break;
 
227
 
 
228
        default:
 
229
 
 
230
                strcpy(wname, name);
 
231
                break;
 
232
        }
 
233
}
 
234
////////////////////////////////////////////////////////////////////////////////////
 
235
//
 
236
void GetRecFileName(int16_t tab, int16_t lang, pchar wname) {
 
237
        seq_name[3] = tab + '0';
 
238
        append_by_lang(lang, seq_name, wname);
 
239
        strcat(wname, ".dat");
261
240
}
262
241
////////////////////////////////////////////////////////////////////////////////////
263
242
//
264
243
/*
265
 
Int16 to_voc()
266
 
{
267
 
        if (vocs_NOK == 0)
268
 
        {
269
 
                ed_load();
270
 
                if (!spelling(comp_file, comp_lth))
271
 
                        ed_flip();
272
 
 
273
 
                return 0;
274
 
        }
275
 
        return 1;
276
 
}
277
 
*/
278
 
////////////////////////////////////////////////////////////////////////////////////
279
 
//
280
 
void append_by_lang (Int16 lang, PInt8 src, PInt8 dst)
281
 
{
282
 
        strcpy(dst,src);
283
 
 
284
 
        if ((lang >= 0) && (lang < LANG_TOTAL))
285
 
        {
286
 
                strcat(dst,lang_suff[lang]);
287
 
        }
288
 
/* ������������� 09.07.2001 E.P.
289
 
        else
290
 
        {
291
 
                if( is_cen_language(language) && // 08.09.2000 E.P.
292
 
                        n>0 && n<4 )
293
 
                        strcat(dst,"CEN"); // rec1,rec2,rec3 for croatian
294
 
 
295
 
                strcat(dst,"R&E"); // rec1,rec2,rec3 for Rus/Eng mode
296
 
    }
297
 
*/
298
 
}
299
 
////////////////////////////////////////////////////////////////////////////////////
300
 
//
301
 
Int16 TE_open(Int16 Stream, PInt8 Name, Int16 Type, Int16 SubType)
302
 
{
303
 
        Int8 Wname[160];
304
 
        Int16 i;
305
 
        Int16 fn;
306
 
 
307
 
        TE_make_name (Stream, Name, Wname);
308
 
 
309
 
        for (fn = 1; fn < 16; fn++)
310
 
        {
311
 
                if (file_handle[fn]==-1)
312
 
                {
313
 
                        i = open_data_file(Name, Type); /*, SubType); */
314
 
 
315
 
                        if (i < 0)
316
 
                                return -1;
317
 
 
318
 
                        file_handle[fn] = i;
319
 
                        file_stream[fn] = Stream;
320
 
                        stream_op [Stream] ++;
321
 
 
322
 
                        return fn;
323
 
                }
324
 
        }
325
 
        return -1;
326
 
}
327
 
////////////////////////////////////////////////////////////////////////////////////
328
 
//
329
 
Int16 TE_write(Int16 File, PWord8 Data, Word32 Size)
330
 
{
331
 
        Int16 i;
332
 
 
333
 
        if ((i=file_handle[File]) < 0)
334
 
                return -1;
335
 
 
336
 
        return write(i, Data, Size);
337
 
}
338
 
////////////////////////////////////////////////////////////////////////////////////
339
 
//
340
 
Int16 TE_table_op(Int16 Stream, Int16 Language, Int16 Type, Int16 SubType)
341
 
{
342
 
        Int8 Wname[20];
343
 
 
344
 
        GetRecFileName(Stream,Language,Wname);
345
 
        return TE_open (TB_STREAM, Wname, Type, SubType);
346
 
}
347
 
 
348
 
Int32 TE_read(Int16 File, PInt8 Buffer, Int32 Size)
349
 
{
350
 
        Int16 i;
351
 
 
352
 
        if ((i=file_handle[File]) < 0)
353
 
                return -1;
354
 
 
355
 
        return read (i, Buffer, Size);
356
 
}
357
 
 
358
 
Int16 TE_close(Int16 File)
359
 
{
360
 
        Int16 i, s;
361
 
 
362
 
        if ((File < 0) || (File > 9))
363
 
                return -1;
364
 
 
365
 
        if ((i=file_handle[File]) < 0)
366
 
                return -1;
367
 
 
368
 
        close (i);
369
 
        s = file_stream [File];
370
 
        stream_op [s] --;
371
 
        file_handle [File] = -1;
372
 
        file_stream [File] = 0;
373
 
        return 0;
374
 
}
375
 
 
376
 
PInt8 TE_handle_fgets  ( Int16 Handle, PInt8 Buff, Int16 Lenght )
377
 
{
378
 
        Int8 ch;
379
 
        PInt8 ptr = Buff;
380
 
        Int16  ret;
381
 
 
382
 
        if ( Handle <= 0 || Buff == NULL || Lenght < 1 )
383
 
        {
384
 
                return NULL;
385
 
        }
386
 
 
387
 
        while ( Lenght > 1 )
388
 
        {
389
 
                ret =(Int16)TE_read( Handle, &ch, 1L );
390
 
 
391
 
                if ( ret < 0  )
392
 
                {
393
 
                        return NULL;
394
 
                }      /* ERROR */
395
 
 
396
 
                if ( ret == 0 )
397
 
                {
398
 
                        break;
399
 
                }            /* EOF   */
 
244
 int16_t to_voc()
 
245
 {
 
246
 if (vocs_NOK == 0)
 
247
 {
 
248
 ed_load();
 
249
 if (!spelling(comp_file, comp_lth))
 
250
 ed_flip();
 
251
 
 
252
 return 0;
 
253
 }
 
254
 return 1;
 
255
 }
 
256
 */
 
257
////////////////////////////////////////////////////////////////////////////////////
 
258
//
 
259
void append_by_lang(int16_t lang, pchar src, pchar dst) {
 
260
        strcpy(dst, src);
 
261
 
 
262
        if ((lang >= 0) && (lang < LANG_TOTAL)) {
 
263
                strcat(dst, lang_suff[lang]);
 
264
        }
 
265
        /* Закомментарил 09.07.2001 E.P.
 
266
         else
 
267
         {
 
268
         if( is_cen_language(language) && // 08.09.2000 E.P.
 
269
         n>0 && n<4 )
 
270
         strcat(dst,"CEN"); // rec1,rec2,rec3 for croatian
 
271
 
 
272
         strcat(dst,"R&E"); // rec1,rec2,rec3 for Rus/Eng mode
 
273
         }
 
274
         */
 
275
}
 
276
////////////////////////////////////////////////////////////////////////////////////
 
277
//
 
278
int16_t TE_open(int16_t Stream, pchar Name, int16_t Type, int16_t SubType) {
 
279
        char Wname[160];
 
280
        int16_t i;
 
281
        int16_t fn;
 
282
 
 
283
        TE_make_name(Stream, Name, Wname);
 
284
 
 
285
        for (fn = 1; fn < 16; fn++) {
 
286
                if (file_handle[fn] == -1) {
 
287
                        i = open_data_file(Name, Type); /*, SubType); */
 
288
 
 
289
                        if (i < 0)
 
290
                                return -1;
 
291
 
 
292
                        file_handle[fn] = i;
 
293
                        file_stream[fn] = Stream;
 
294
                        stream_op[Stream]++;
 
295
 
 
296
                        return fn;
 
297
                }
 
298
        }
 
299
        return -1;
 
300
}
 
301
////////////////////////////////////////////////////////////////////////////////////
 
302
//
 
303
int16_t TE_write(int16_t File, puchar Data, uint32_t Size) {
 
304
        int16_t i;
 
305
 
 
306
        if ((i = file_handle[File]) < 0)
 
307
                return -1;
 
308
 
 
309
        return write(i, Data, Size);
 
310
}
 
311
////////////////////////////////////////////////////////////////////////////////////
 
312
//
 
313
int16_t TE_table_op(int16_t Stream, int16_t Language, int16_t Type,
 
314
                int16_t SubType) {
 
315
        char Wname[20];
 
316
 
 
317
        GetRecFileName(Stream, Language, Wname);
 
318
        return TE_open(TB_STREAM, Wname, Type, SubType);
 
319
}
 
320
 
 
321
int32_t TE_read(int16_t File, pchar Buffer, int32_t Size) {
 
322
        int16_t i;
 
323
 
 
324
        if ((i = file_handle[File]) < 0)
 
325
                return -1;
 
326
 
 
327
        return read(i, Buffer, Size);
 
328
}
 
329
 
 
330
int16_t TE_close(int16_t File) {
 
331
        int16_t i, s;
 
332
 
 
333
        if ((File < 0) || (File > 9))
 
334
                return -1;
 
335
 
 
336
        if ((i = file_handle[File]) < 0)
 
337
                return -1;
 
338
 
 
339
        close(i);
 
340
        s = file_stream[File];
 
341
        stream_op[s]--;
 
342
        file_handle[File] = -1;
 
343
        file_stream[File] = 0;
 
344
        return 0;
 
345
}
 
346
 
 
347
pchar TE_handle_fgets(int16_t Handle, pchar Buff, int16_t Lenght) {
 
348
        char ch;
 
349
        pchar ptr = Buff;
 
350
        int16_t ret;
 
351
 
 
352
        if (Handle <= 0 || Buff == NULL || Lenght < 1) {
 
353
                return NULL;
 
354
        }
 
355
 
 
356
        while (Lenght > 1) {
 
357
                ret = (int16_t) TE_read(Handle, &ch, 1L);
 
358
 
 
359
                if (ret < 0) {
 
360
                        return NULL;
 
361
                } /* ERROR */
 
362
 
 
363
                if (ret == 0) {
 
364
                        break;
 
365
                } /* EOF   */
400
366
 
401
367
                /* MinGW file io seems to turn windows file endings into \n
402
 
                  so break -- no skip as when the \r is passed through */
403
 
#ifdef WIN32
404
 
                if ( ch == '\n' ) {
405
 
                       break;
 
368
                 so break -- no skip as when the \r is passed through */
 
369
#if defined(WIN32) || defined(__CYGWIN__)
 
370
                if ( ch == '\n' ) {
 
371
                        break;
406
372
                }
407
373
#endif
408
 
                if ( ch == '\r' ) /* JussiP: The data files have Windows line endings. */
409
 
                {
410
 
                        TE_read(Handle, &ch, 1L); /* Skip the following \n. */
411
 
                        break;
412
 
                }            /* EOL   */
413
 
 
414
 
                *(ptr++) = ch;
415
 
                Lenght--;
416
 
        }
417
 
 
418
 
        *ptr = 0;
419
 
 
420
 
        if (ptr != Buff)
421
 
                return Buff;
422
 
 
423
 
        return NULL;
 
374
                if (ch == '\r') /* JussiP: The data files have Windows line endings. */
 
375
                {
 
376
                        TE_read(Handle, &ch, 1L); /* Skip the following \n. */
 
377
                        break;
 
378
                } /* EOL   */
 
379
 
 
380
                *(ptr++) = ch;
 
381
                Lenght--;
 
382
        }
 
383
 
 
384
        *ptr = 0;
 
385
 
 
386
        if (ptr != Buff)
 
387
                return Buff;
 
388
 
 
389
        return NULL;
424
390
}
425
391
///////////////////////////////////////////////////////////////////////////////////////////////////////
426
392
//
427
 
Int32 TE_file_length(Int16 fn)
428
 
{
429
 
        Int16 i;
430
 
 
431
 
        if ((i=file_handle[fn]) < 0)
432
 
                return -1;
433
 
 
434
 
        return filelength (i);
 
393
int32_t TE_file_length(int16_t fn) {
 
394
        int16_t i;
 
395
 
 
396
        if ((i = file_handle[fn]) < 0)
 
397
                return -1;
 
398
 
 
399
        return filelength(i);
435
400
}
436
401
 
437
 
void ed_out_write(PWord8 p, Word16 size)
438
 
{
439
 
        if ( ED_out_end )
440
 
        {
441
 
                memcpy (ED_out_end, p, size);
442
 
        }
 
402
void ed_out_write(puchar p, uint16_t size) {
 
403
        if (ED_out_end) {
 
404
                memcpy(ED_out_end, p, size);
 
405
        }
443
406
 
444
 
        ED_out_end += size;
 
407
        ED_out_end += size;
445
408
}
446
409
///////////////////////////////////////////////////////////////////////////////////
447
 
// ���������
448
 
void trees_load_rling()
449
 
{
450
 
        // exeption
451
 
        //////////////////////////////////////////////////////////////////////
452
 
        // ������ ������ �������, ������ ������ ��� ���
453
 
        memory_pool = svbox_pool;
454
 
        memory_pool_end = memory_pool + SizeTables;
455
 
 
456
 
        reload_lang_vocs();
457
 
 
458
 
//      all_loaded = 1;
 
410
// протащено
 
411
void trees_load_rling() {
 
412
        // exeption
 
413
        //////////////////////////////////////////////////////////////////////
 
414
        // грузим только словари, память только под них
 
415
        memory_pool = svbox_pool;
 
416
        memory_pool_end = memory_pool + SizeTables;
 
417
 
 
418
        reload_lang_vocs();
 
419
 
 
420
        //      all_loaded = 1;
459
421
 
460
422
}
461
423
////////////////////////////////////////////////////////
462
424
//
463
 
void read_rec_file(Int16 fileno, PWord8 pool, PWord8 * end)
464
 
{
465
 
        Word32 l;
466
 
        Int16 h;
467
 
 
468
 
        h = TBOPEN(fileno,-1,(Int16)(O_RDONLY|O_BINARY), 0);
469
 
 
470
 
        if (h==-1)
471
 
                ErrorExit(RLING_ERROR_CANT_OPEN_TABLE);
472
 
 
473
 
        l=TGREAD(h,pool,0x100000);
474
 
        TGCLOSE(h);
475
 
        l=(l+15) & -16;
476
 
        *end=pool+l;
 
425
void read_rec_file(int16_t fileno, puchar pool, puchar * end) {
 
426
        uint32_t l;
 
427
        int16_t h;
 
428
 
 
429
        h = TBOPEN(fileno, -1, (int16_t) (O_RDONLY | O_BINARY), 0);
 
430
 
 
431
        if (h == -1)
 
432
                ErrorExit(RLING_ERROR_CANT_OPEN_TABLE);
 
433
 
 
434
        l = TGREAD(h, pool, 0x100000);
 
435
        TGCLOSE(h);
 
436
        l = (l + 15) & -16;
 
437
        *end = pool + l;
477
438
}
478
439
//////////////////////////////////////////////////////////////////////////////////////
479
 
// ��������� �� filesys.c
480
 
void reload_lang_vocs()
481
 
{
482
 
        //Int32 roots_lth;
483
 
 
484
 
        correct_letters_pidx_table();
485
 
        correct_let_tables();
486
 
        vocs_NOK = 0;
487
 
        sv_lang = language;
488
 
 
489
 
        box_pool = svbox_pool;
490
 
        box_pool = load_stat_dict(box_pool);
491
 
        box_pool += (memory_pool - box_pool) & 0xf;
492
 
        user_voc_init();
493
 
 
494
 
        if (vocs_NOK)
495
 
                box_pool = svbox_pool;
496
 
 
497
 
        if ((memory_pool+SizeTables)<box_pool)
498
 
                ErrorExit(RLING_ERROR_MEMORY_FAULT);
499
 
        // Max size for recog tables storing
500
 
        box_pool = memory_pool + SizeTables;
501
 
        //#undef SizeTables
502
 
 
503
 
//      roots_lth = box_n;
504
 
//      roots_lth *= BOXSIZE;
505
 
//      root_file = (PROOT)((PWord8)box_pool + roots_lth);
506
 
 
507
 
//      if (memory_pool_end <= (PWord8)root_file)
508
 
//              ErrorExit(9);
509
 
}
510
 
////////////////////////////////////////////////////////////////////////////////////////
511
 
// ��������� �� acc_tabs.c
512
 
void    correct_let_tables(void) // ��뢠���� � 䠩�� EMBBOX.C: load_BOX()
513
 
{
514
 
        //
515
 
        //  ���� ������ ���
516
 
        //
517
 
}
518
 
////////////////////////////////////////////////////////////////////////////////////////
519
 
// ��������� �� proptab.c
520
 
void correct_letters_pidx_table(void)
521
 
{
522
 
        //
523
 
        //  ���� ������ ���
524
 
        //
 
440
// протащено из filesys.c
 
441
void reload_lang_vocs() {
 
442
        //int32_t roots_lth;
 
443
 
 
444
        correct_letters_pidx_table();
 
445
        correct_let_tables();
 
446
        vocs_NOK = 0;
 
447
        sv_lang = language;
 
448
 
 
449
        box_pool = svbox_pool;
 
450
        box_pool = load_stat_dict(box_pool);
 
451
        box_pool += (memory_pool - box_pool) & 0xf;
 
452
        user_voc_init();
 
453
 
 
454
        if (vocs_NOK)
 
455
                box_pool = svbox_pool;
 
456
 
 
457
        if ((memory_pool + SizeTables) < box_pool)
 
458
                ErrorExit(RLING_ERROR_MEMORY_FAULT);
 
459
        // Max size for recog tables storing
 
460
        box_pool = memory_pool + SizeTables;
 
461
        //#undef SizeTables
 
462
 
 
463
        //      roots_lth = box_n;
 
464
        //      roots_lth *= BOXSIZE;
 
465
        //      root_file = (PROOT)((puchar)box_pool + roots_lth);
 
466
 
 
467
        //      if (memory_pool_end <= (puchar)root_file)
 
468
        //              ErrorExit(9);
 
469
}
 
470
////////////////////////////////////////////////////////////////////////////////////////
 
471
// протащено из acc_tabs.c
 
472
void correct_let_tables(void) // ўл§лў Ґвбп ў д ©«Ґ EMBBOX.C: load_BOX()
 
473
{
 
474
        //
 
475
        //  пока ничего нет
 
476
        //
 
477
}
 
478
////////////////////////////////////////////////////////////////////////////////////////
 
479
// протащено из proptab.c
 
480
void correct_letters_pidx_table(void) {
 
481
        //
 
482
        //  пока ничего нет
 
483
        //
525
484
}