/src/liblouis/liblouis/internal.h
Line | Count | Source |
1 | | /* liblouis Braille Translation and Back-Translation Library |
2 | | |
3 | | Based on the Linux screenreader BRLTTY, copyright (C) 1999-2006 by The |
4 | | BRLTTY Team |
5 | | |
6 | | Copyright (C) 2004, 2005, 2006 ViewPlus Technologies, Inc. www.viewplus.com |
7 | | Copyright (C) 2004, 2005, 2006 JJB Software, Inc. www.jjb-software.com |
8 | | Copyright (C) 2016 Mike Gray, American Printing House for the Blind |
9 | | Copyright (C) 2016 Davy Kager, Dedicon |
10 | | |
11 | | This file is part of liblouis. |
12 | | |
13 | | liblouis is free software: you can redistribute it and/or modify it |
14 | | under the terms of the GNU Lesser General Public License as published |
15 | | by the Free Software Foundation, either version 2.1 of the License, or |
16 | | (at your option) any later version. |
17 | | |
18 | | liblouis is distributed in the hope that it will be useful, but |
19 | | WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
21 | | Lesser General Public License for more details. |
22 | | |
23 | | You should have received a copy of the GNU Lesser General Public |
24 | | License along with liblouis. If not, see <http://www.gnu.org/licenses/>. |
25 | | */ |
26 | | |
27 | | /** |
28 | | * @file |
29 | | * @brief Internal API of liblouis |
30 | | */ |
31 | | |
32 | | #ifndef __LOUIS_H_ |
33 | | #define __LOUIS_H_ |
34 | | |
35 | | #ifdef __cplusplus |
36 | | extern "C" { |
37 | | #endif /* __cplusplus */ |
38 | | |
39 | | #include <stdio.h> |
40 | | #include "liblouis.h" |
41 | | |
42 | | /* Unlike Windows, Mingw can handle forward slashes as directory |
43 | | separator, see http://mingw.org/wiki/Posix_path_conversion */ |
44 | | #if defined(_WIN32) && !defined(__MINGW32__) && !defined(__MINGW64__) |
45 | | #define PATH_SEP ';' |
46 | | #define DIR_SEP '\\' |
47 | | #else |
48 | | #define PATH_SEP ':' |
49 | 1 | #define DIR_SEP '/' |
50 | | #endif |
51 | | |
52 | | #ifdef _MSC_VER |
53 | | #define strcasecmp _stricmp |
54 | | #endif |
55 | | |
56 | 4.06k | #define NUMVAR 50 |
57 | 528 | #define EMPHMODECHARSSIZE 256 |
58 | 2.50k | #define NOEMPHCHARSSIZE 256 |
59 | 102 | #define LETSIGNSIZE 256 |
60 | | // noletsignbefore and noletsignafter is hardly ever used and usually |
61 | | // only with very few chars, so it only needs a small array |
62 | 47 | #define LETSIGNBEFORESIZE 64 |
63 | 39 | #define LETSIGNAFTERSIZE 64 |
64 | 36 | #define SEQPATTERNSIZE 128 |
65 | 11.3M | #define CHARSIZE sizeof(widechar) |
66 | 11.0k | #define DEFAULTRULESIZE 50 |
67 | | |
68 | | typedef struct intCharTupple { |
69 | | unsigned long long key; |
70 | | char value; |
71 | | } intCharTupple; |
72 | | |
73 | | /* HASHNUM must be prime */ |
74 | 342M | #define HASHNUM 1123 |
75 | | |
76 | | #define MAXPASS 4 |
77 | 4.08M | #define MAXSTRING 2048 |
78 | | #define MAX_MACRO_VAR 100 // maximal number of variable substitutions a macro can contain |
79 | 86.6k | #define MAX_EMPH_CLASSES 10 // maximal number of emphasis classes |
80 | 94.5M | #define MAX_MODES 6 // maximal number of modes that can be handled |
81 | 2.20k | #define MAX_SOURCE_FILES 100 // maximal number of files a table can consist of |
82 | | |
83 | | typedef unsigned int TranslationTableOffset; |
84 | | |
85 | | /* Basic type for translation table data, which carries all alignment |
86 | | * constraints that fields contained in translation table may have. |
87 | | * Notably TranslationTableCharacterAttributes is unsigned long long, so we need |
88 | | * at least this big basic type. */ |
89 | | typedef unsigned long long TranslationTableData; |
90 | 231k | #define OFFSETSIZE sizeof(TranslationTableData) |
91 | | |
92 | | typedef enum { |
93 | | /* The first 8 are the predefined character classes. They need to be listed first and |
94 | | in this order because of how allocateCharacterClasses works. */ |
95 | | CTC_Space = 0x1, |
96 | | CTC_Letter = 0x2, |
97 | | CTC_Digit = 0x4, |
98 | | CTC_Punctuation = 0x8, |
99 | | CTC_UpperCase = 0x10, |
100 | | CTC_LowerCase = 0x20, |
101 | | CTC_Math = 0x40, |
102 | | CTC_Sign = 0x80, |
103 | | CTC_LitDigit = 0x100, |
104 | | CTC_CapsMode = 0x200, |
105 | | // bit 0x400 used to be taken by CTC_EmphMode |
106 | | CTC_NumericMode = 0x800, |
107 | | CTC_NumericNoContract = 0x1000, |
108 | | CTC_SeqDelimiter = 0x2000, |
109 | | CTC_SeqBefore = 0x4000, |
110 | | CTC_SeqAfter = 0x8000, |
111 | | /* The following 8 are reserved for %0 to %7 (in no particular order) */ |
112 | | /* Be careful with changing these values (and also CTC_EndOfInput) because in |
113 | | pattern_compile_expression they are stored in a unsigned int after cutting off the |
114 | | 16 least significant bits. */ |
115 | | CTC_UserDefined1 = 0x10000, |
116 | | CTC_UserDefined2 = 0x20000, |
117 | | CTC_UserDefined3 = 0x40000, |
118 | | CTC_UserDefined4 = 0x80000, |
119 | | CTC_UserDefined5 = 0x100000, |
120 | | CTC_UserDefined6 = 0x200000, |
121 | | CTC_UserDefined7 = 0x400000, |
122 | | CTC_UserDefined8 = 0x800000, |
123 | | CTC_EndOfInput = 0x1000000, // only used by pattern matcher |
124 | | CTC_EmpMatch = 0x2000000, // only used in TranslationTableRule->before and |
125 | | // TranslationTableRule->after |
126 | | CTC_MidEndNumericMode = 0x4000000, |
127 | | /* At least 37 more bits available in an unsigned long long (at least 64 bits). Used |
128 | | for custom attributes 9 to 45. These need to be the last values of the enum. */ |
129 | | CTC_UserDefined9 = 0x8000000, |
130 | | CTC_UserDefined10 = 0x10000000, |
131 | | CTC_UserDefined11 = 0x20000000, |
132 | | CTC_UserDefined12 = 0x40000000, |
133 | | } TranslationTableCharacterAttribute; |
134 | | |
135 | | typedef enum { |
136 | | pass_first = '`', |
137 | | pass_last = '~', |
138 | | pass_lookback = '_', |
139 | | pass_string = '\"', |
140 | | pass_dots = '@', |
141 | | pass_omit = '?', |
142 | | pass_startReplace = '[', |
143 | | pass_endReplace = ']', |
144 | | pass_startGroup = '{', |
145 | | pass_endGroup = '}', |
146 | | pass_variable = '#', |
147 | | pass_not = '!', |
148 | | pass_search = '/', |
149 | | pass_any = 'a', |
150 | | pass_digit = 'd', |
151 | | pass_litDigit = 'D', |
152 | | pass_letter = 'l', |
153 | | pass_math = 'm', |
154 | | pass_punctuation = 'p', |
155 | | pass_sign = 'S', |
156 | | pass_space = 's', |
157 | | pass_uppercase = 'U', |
158 | | pass_lowercase = 'u', |
159 | | pass_class1 = 'w', |
160 | | pass_class2 = 'x', |
161 | | pass_class3 = 'y', |
162 | | pass_class4 = 'z', |
163 | | pass_attributes = '$', |
164 | | pass_groupstart = '{', |
165 | | pass_groupend = '}', |
166 | | pass_groupreplace = ';', |
167 | | pass_swap = '%', |
168 | | pass_hyphen = '-', |
169 | | pass_until = '.', |
170 | | pass_eq = '=', |
171 | | pass_lt = '<', |
172 | | pass_gt = '>', |
173 | | pass_endTest = 32, |
174 | | pass_plus = '+', |
175 | | pass_copy = '*', |
176 | | pass_leftParen = '(', |
177 | | pass_rightParen = ')', |
178 | | pass_comma = ',', |
179 | | pass_lteq = 130, |
180 | | pass_gteq = 131, |
181 | | pass_invalidToken = 132, |
182 | | pass_noteq = 133, |
183 | | pass_and = 134, |
184 | | pass_or = 135, |
185 | | pass_nameFound = 136, |
186 | | pass_numberFound = 137, |
187 | | pass_boolean = 138, |
188 | | pass_class = 139, |
189 | | pass_define = 140, |
190 | | pass_emphasis = 141, |
191 | | pass_group = 142, |
192 | | pass_mark = 143, |
193 | | pass_repGroup = 143, |
194 | | pass_script = 144, |
195 | | pass_noMoreTokens = 145, |
196 | | pass_replace = 146, |
197 | | pass_if = 147, |
198 | | pass_then = 148, |
199 | | pass_all = 255 |
200 | | } pass_Codes; |
201 | | |
202 | | typedef unsigned long long TranslationTableCharacterAttributes; |
203 | | |
204 | | typedef struct { |
205 | | TranslationTableOffset next; |
206 | | widechar lookFor; |
207 | | widechar found; |
208 | | } CharDotsMapping; |
209 | | |
210 | | typedef struct { |
211 | | const char *sourceFile; |
212 | | int sourceLine; |
213 | | TranslationTableOffset next; |
214 | | TranslationTableOffset definitionRule; |
215 | | TranslationTableOffset otherRules; |
216 | | TranslationTableCharacterAttributes attributes; |
217 | | TranslationTableCharacterAttributes mode; |
218 | | TranslationTableOffset compRule; |
219 | | widechar value; |
220 | | TranslationTableOffset basechar; |
221 | | TranslationTableOffset linked; |
222 | | int ruleIndex; /** sequence number of rule within table */ |
223 | | int finalized; |
224 | | } TranslationTableCharacter; |
225 | | |
226 | | typedef enum { /* Op codes */ |
227 | | CTO_IncludeFile, |
228 | | CTO_Locale, /* Deprecated, do not use */ |
229 | | CTO_Undefined, |
230 | | /* Do not change the order of the following opcodes! */ |
231 | | CTO_CapsLetter, |
232 | | CTO_BegCapsWord, |
233 | | CTO_EndCapsWord, |
234 | | CTO_BegCaps, |
235 | | CTO_EndCaps, |
236 | | CTO_BegCapsPhrase, |
237 | | CTO_EndCapsPhrase, |
238 | | CTO_LenCapsPhrase, |
239 | | CTO_ModeLetter, |
240 | | CTO_BegModeWord, |
241 | | CTO_EndModeWord, |
242 | | CTO_BegMode, |
243 | | CTO_EndMode, |
244 | | CTO_BegModePhrase, |
245 | | CTO_EndModePhrase, |
246 | | CTO_LenModePhrase, |
247 | | /* End of ordered opcodes */ |
248 | | CTO_LetterSign, |
249 | | CTO_NoLetsignBefore, |
250 | | CTO_NoLetsign, |
251 | | CTO_NoLetsignAfter, |
252 | | CTO_NumberSign, |
253 | | CTO_NoNumberSign, |
254 | | CTO_NumericModeChars, |
255 | | CTO_MidEndNumericModeChars, |
256 | | CTO_NumericNoContractChars, |
257 | | CTO_SeqDelimiter, |
258 | | CTO_SeqBeforeChars, |
259 | | CTO_SeqAfterChars, |
260 | | CTO_SeqAfterPattern, |
261 | | CTO_SeqAfterExpression, |
262 | | CTO_EmphClass, |
263 | | |
264 | | /* Do not change the order of the following opcodes! */ |
265 | | CTO_EmphLetter, |
266 | | CTO_BegEmphWord, |
267 | | CTO_EndEmphWord, |
268 | | CTO_BegEmph, |
269 | | CTO_EndEmph, |
270 | | CTO_BegEmphPhrase, |
271 | | CTO_EndEmphPhrase, |
272 | | CTO_LenEmphPhrase, |
273 | | /* End of ordered opcodes */ |
274 | | |
275 | | CTO_CapsModeChars, |
276 | | CTO_EmphModeChars, |
277 | | CTO_NoEmphChars, |
278 | | CTO_BegComp, |
279 | | CTO_EndComp, |
280 | | CTO_NoContractSign, |
281 | | CTO_MultInd, |
282 | | CTO_CompDots, |
283 | | CTO_Comp6, |
284 | | CTO_Class, /* define a character class */ |
285 | | CTO_After, /* only match if after character in class */ |
286 | | CTO_Before, /* only match if before character in class 30 */ |
287 | | CTO_NoBack, |
288 | | CTO_NoFor, |
289 | | CTO_EmpMatchBefore, |
290 | | CTO_EmpMatchAfter, |
291 | | CTO_SwapCc, |
292 | | CTO_SwapCd, |
293 | | CTO_SwapDd, |
294 | | CTO_Space, |
295 | | CTO_Digit, |
296 | | CTO_Punctuation, |
297 | | CTO_Math, |
298 | | CTO_Sign, |
299 | | CTO_Letter, |
300 | | CTO_UpperCase, |
301 | | CTO_LowerCase, |
302 | | CTO_Grouping, |
303 | | CTO_UpLow, |
304 | | CTO_LitDigit, |
305 | | CTO_Display, |
306 | | CTO_Replace, |
307 | | CTO_Context, |
308 | | CTO_Correct, |
309 | | CTO_Pass2, |
310 | | CTO_Pass3, |
311 | | CTO_Pass4, |
312 | | CTO_Repeated, |
313 | | CTO_RepWord, |
314 | | CTO_RepEndWord, |
315 | | CTO_CapsNoCont, |
316 | | CTO_Always, |
317 | | CTO_ExactDots, |
318 | | CTO_NoCross, |
319 | | CTO_Syllable, |
320 | | CTO_NoCont, |
321 | | CTO_CompBrl, |
322 | | CTO_Literal, |
323 | | CTO_LargeSign, |
324 | | CTO_WholeWord, |
325 | | CTO_PartWord, |
326 | | CTO_JoinNum, |
327 | | CTO_JoinableWord, |
328 | | CTO_LowWord, |
329 | | CTO_Contraction, |
330 | | CTO_SuffixableWord, /** whole word or beginning of word */ |
331 | | CTO_PrefixableWord, /** whole word or end of word */ |
332 | | CTO_BegWord, /** beginning of word only */ |
333 | | CTO_BegMidWord, /** beginning or middle of word */ |
334 | | CTO_MidWord, /** middle of word only 20 */ |
335 | | CTO_MidEndWord, /** middle or end of word */ |
336 | | CTO_EndWord, /** end of word only */ |
337 | | CTO_PrePunc, /** punctuation in string at beginning of word */ |
338 | | CTO_PostPunc, /** punctuation in string at end of word */ |
339 | | CTO_BegNum, /** beginning of number */ |
340 | | CTO_MidNum, /** middle of number, e.g., decimal point */ |
341 | | CTO_EndNum, /** end of number */ |
342 | | CTO_DecPoint, |
343 | | CTO_Hyphen, |
344 | | // CTO_Apostrophe, |
345 | | // CTO_Initial, |
346 | | CTO_NoBreak, |
347 | | CTO_Match, |
348 | | CTO_BackMatch, |
349 | | CTO_Attribute, |
350 | | CTO_Base, |
351 | | CTO_Macro, |
352 | | CTO_None, |
353 | | |
354 | | /** "internal" opcodes */ |
355 | | CTO_EndCapsPhraseBefore, |
356 | | CTO_EndCapsPhraseAfter, |
357 | | |
358 | | CTO_All |
359 | | } TranslationTableOpcode; |
360 | | |
361 | | typedef struct { |
362 | | const char *sourceFile; |
363 | | int sourceLine; |
364 | | int index; /** sequence number of rule within table */ |
365 | | TranslationTableOffset charsnext; /** next chars entry */ |
366 | | TranslationTableOffset dotsnext; /** next dots entry */ |
367 | | TranslationTableCharacterAttributes after; /** character types which must follow */ |
368 | | TranslationTableCharacterAttributes before; /** character types which must precede */ |
369 | | TranslationTableOffset patterns; /** before and after patterns */ |
370 | | TranslationTableOpcode opcode; /** rule for testing validity of replacement */ |
371 | | char nocross; |
372 | | short charslen; /** length of string to be replaced */ |
373 | | short dotslen; /** length of replacement string */ |
374 | | widechar charsdots[DEFAULTRULESIZE]; /** find and replacement strings */ |
375 | | } TranslationTableRule; |
376 | | |
377 | | typedef struct /* state transition */ |
378 | | { |
379 | | widechar ch; |
380 | | widechar newState; |
381 | | } HyphenationTrans; |
382 | | |
383 | | typedef union { |
384 | | HyphenationTrans *pointer; |
385 | | TranslationTableOffset offset; |
386 | | } PointOff; |
387 | | |
388 | | typedef struct /* one state */ |
389 | | { |
390 | | PointOff trans; |
391 | | TranslationTableOffset hyphenPattern; |
392 | | widechar fallbackState; |
393 | | widechar numTrans; |
394 | | } HyphenationState; |
395 | | |
396 | | typedef struct CharacterClass { |
397 | | struct CharacterClass *next; |
398 | | TranslationTableCharacterAttributes attribute; |
399 | | widechar length; |
400 | | widechar name[1]; |
401 | | } CharacterClass; |
402 | | |
403 | | typedef struct RuleName { |
404 | | struct RuleName *next; |
405 | | TranslationTableOffset ruleOffset; |
406 | | widechar length; |
407 | | widechar name[1]; |
408 | | } RuleName; |
409 | | |
410 | | typedef struct { |
411 | | /* either typeform or mode should be set, not both */ |
412 | | formtype typeform; /* corresponding value in "typeforms" enum */ |
413 | | TranslationTableCharacterAttributes mode; /* corresponding character attribute */ |
414 | | unsigned int value; /* bit field that contains a single "1" */ |
415 | | unsigned short |
416 | | rule; /* emphasis rules (index in emphRules, emphModeChars and noEmphChars) */ |
417 | | } EmphasisClass; |
418 | | |
419 | | typedef struct { |
420 | | TranslationTableOffset tableSize; |
421 | | TranslationTableOffset bytesUsed; |
422 | | TranslationTableOffset charToDots[HASHNUM]; |
423 | | TranslationTableOffset dotsToChar[HASHNUM]; |
424 | | TranslationTableData ruleArea[1]; /** Space for storing all rules and values */ |
425 | | } DisplayTableHeader; |
426 | | |
427 | | /** |
428 | | * Translation table header |
429 | | */ |
430 | | typedef struct { /* translation table */ |
431 | | |
432 | | /* state needed during compilation */ |
433 | | TranslationTableOffset tableSize; |
434 | | TranslationTableOffset bytesUsed; |
435 | | CharacterClass *characterClasses; |
436 | | TranslationTableCharacterAttributes nextCharacterClassAttribute; |
437 | | TranslationTableCharacterAttributes nextNumberedCharacterClassAttribute; |
438 | | RuleName *ruleNames; |
439 | | TranslationTableCharacterAttributes |
440 | | numberedAttributes[8]; /* attributes 0-7 used in match rules (could also be |
441 | | stored in `characterClasses', but this is slightly |
442 | | faster) */ |
443 | | int usesAttributeOrClass; /* 1 = attribute, 2 = class */ |
444 | | char *sourceFiles[MAX_SOURCE_FILES + 1]; |
445 | | int ruleCounter; |
446 | | |
447 | | /* needed for translation or other api functions */ |
448 | | int finalized; |
449 | | int capsNoCont; |
450 | | int numPasses; |
451 | | int corrections; |
452 | | int syllables; |
453 | | int usesSequences; |
454 | | int usesNumericMode; |
455 | | int hasCapsModeChars; |
456 | | TranslationTableOffset undefined; |
457 | | TranslationTableOffset letterSign; |
458 | | TranslationTableOffset numberSign; |
459 | | TranslationTableOffset noContractSign; |
460 | | TranslationTableOffset noNumberSign; |
461 | | widechar seqPatterns[SEQPATTERNSIZE]; |
462 | | char *emphClassNames[MAX_EMPH_CLASSES]; |
463 | | EmphasisClass emphClasses[MAX_EMPH_CLASSES]; |
464 | | EmphasisClass modes[MAX_MODES]; |
465 | | int seqPatternsCount; |
466 | | widechar seqAfterExpression[SEQPATTERNSIZE]; |
467 | | int seqAfterExpressionLength; |
468 | | TranslationTableOffset emphRules[MAX_EMPH_CLASSES + MAX_MODES] |
469 | | [9]; /* 9 is the size of the EmphCodeOffset enum */ |
470 | | TranslationTableOffset begComp; |
471 | | TranslationTableOffset endComp; |
472 | | TranslationTableOffset hyphenStatesArray; |
473 | | widechar noLetsignBefore[LETSIGNBEFORESIZE]; |
474 | | int noLetsignBeforeCount; |
475 | | widechar noLetsign[LETSIGNSIZE]; |
476 | | int noLetsignCount; |
477 | | widechar noLetsignAfter[LETSIGNAFTERSIZE]; |
478 | | int noLetsignAfterCount; |
479 | | widechar emphModeChars[MAX_EMPH_CLASSES] /* does not include caps: capsmodechars are |
480 | | * currently stored as character attributes |
481 | | */ |
482 | | [EMPHMODECHARSSIZE + 1]; |
483 | | widechar noEmphChars[MAX_EMPH_CLASSES] /* does not include caps */ |
484 | | [NOEMPHCHARSSIZE + 1]; |
485 | | TranslationTableOffset characters[HASHNUM]; /** Character definitions */ |
486 | | TranslationTableOffset dots[HASHNUM]; /** Dot definitions */ |
487 | | TranslationTableOffset forPassRules[MAXPASS + 1]; |
488 | | TranslationTableOffset backPassRules[MAXPASS + 1]; |
489 | | TranslationTableOffset forRules[HASHNUM]; /** Chains of forward rules */ |
490 | | TranslationTableOffset backRules[HASHNUM]; /** Chains of backward rules */ |
491 | | TranslationTableData ruleArea[1]; /** Space for storing all rules and values */ |
492 | | } TranslationTableHeader; |
493 | | |
494 | | typedef enum { |
495 | | alloc_typebuf, |
496 | | alloc_wordBuffer, |
497 | | alloc_emphasisBuffer, |
498 | | alloc_destSpacing, |
499 | | alloc_passbuf, |
500 | | alloc_posMapping1, |
501 | | alloc_posMapping2, |
502 | | alloc_posMapping3 |
503 | | } AllocBuf; |
504 | | |
505 | 12.7k | #define MAXPASSBUF 3 |
506 | | |
507 | | typedef enum { |
508 | | begPhraseOffset = 0, |
509 | | endPhraseBeforeOffset = 1, |
510 | | endPhraseAfterOffset = 2, |
511 | | begOffset = 3, |
512 | | endOffset = 4, |
513 | | letterOffset = 5, |
514 | | begWordOffset = 6, |
515 | | endWordOffset = 7, |
516 | | lenPhraseOffset = 8 |
517 | | } EmphCodeOffset; |
518 | | |
519 | | /* Grouping the begin, end, word and symbol bits and using the type of |
520 | | * a single bit group for representing the emphasis classes allows us |
521 | | * to do simple bit operations. */ |
522 | | |
523 | | /* fields contain sums of EmphasisClass.value */ |
524 | | /* MAX_EMPH_CLASSES + MAX_MODES may not exceed 16 */ |
525 | | typedef struct { |
526 | | unsigned int begin : 16; |
527 | | unsigned int end : 16; |
528 | | unsigned int word : 16; |
529 | | unsigned int symbol : 16; |
530 | | } EmphasisInfo; |
531 | | |
532 | | typedef enum { noEncoding, bigEndian, littleEndian, ascii8 } EncodingType; |
533 | | |
534 | | typedef struct { |
535 | | const char *fileName; |
536 | | const char *sourceFile; |
537 | | FILE *in; |
538 | | int lineNumber; |
539 | | EncodingType encoding; |
540 | | int status; |
541 | | int linelen; |
542 | | int linepos; |
543 | | int checkencoding[2]; |
544 | | widechar line[MAXSTRING]; |
545 | | } FileInfo; |
546 | | |
547 | | /* The following function definitions are hooks into |
548 | | * compileTranslationTable.c. Some are used by other library modules. |
549 | | * Others are used by tools like lou_allround.c and lou_debug.c. */ |
550 | | |
551 | | /** |
552 | | * Comma separated list of directories to search for tables. |
553 | | */ |
554 | | char *EXPORT_CALL |
555 | | _lou_getTablePath(void); |
556 | | |
557 | | /** |
558 | | * Resolve tableList against base. |
559 | | */ |
560 | | char **EXPORT_CALL |
561 | | _lou_resolveTable(const char *tableList, const char *base); |
562 | | |
563 | | /** |
564 | | * The default table resolver |
565 | | */ |
566 | | char **EXPORT_CALL |
567 | | _lou_defaultTableResolver(const char *tableList, const char *base); |
568 | | |
569 | | /** |
570 | | * Return single-cell dot pattern corresponding to a character. |
571 | | * TODO: move to commonTranslationFunctions.c |
572 | | */ |
573 | | widechar EXPORT_CALL |
574 | | _lou_getDotsForChar(widechar c, const DisplayTableHeader *table); |
575 | | |
576 | | /** |
577 | | * Return character corresponding to a single-cell dot pattern. |
578 | | * TODO: move to commonTranslationFunctions.c |
579 | | */ |
580 | | widechar EXPORT_CALL |
581 | | _lou_getCharForDots(widechar d, const DisplayTableHeader *table); |
582 | | |
583 | | void EXPORT_CALL |
584 | | _lou_getTable(const char *tableList, const char *displayTableList, |
585 | | const TranslationTableHeader **translationTable, |
586 | | const DisplayTableHeader **displayTable); |
587 | | |
588 | | const TranslationTableHeader *EXPORT_CALL |
589 | | _lou_getTranslationTable(const char *tableList); |
590 | | |
591 | | const DisplayTableHeader *EXPORT_CALL |
592 | | _lou_getDisplayTable(const char *tableList); |
593 | | |
594 | | int EXPORT_CALL |
595 | | _lou_compileTranslationRule(const char *tableList, const char *inString); |
596 | | |
597 | | int EXPORT_CALL |
598 | | _lou_compileDisplayRule(const char *tableList, const char *inString); |
599 | | |
600 | | /** |
601 | | * Allocate memory for internal buffers |
602 | | * |
603 | | * Used by lou_translateString.c and lou_backTranslateString.c ONLY |
604 | | * to allocate memory for internal buffers. |
605 | | * TODO: move to utils.c |
606 | | */ |
607 | | void *EXPORT_CALL |
608 | | _lou_allocMem(AllocBuf buffer, int index, int srcmax, int destmax); |
609 | | |
610 | | /** |
611 | | * Hash function for character strings |
612 | | * |
613 | | * @param lowercase Whether to convert the string to lowercase because |
614 | | * making the hash of it. |
615 | | */ |
616 | | unsigned long int EXPORT_CALL |
617 | | _lou_stringHash(const widechar *c, int lowercase, const TranslationTableHeader *table); |
618 | | |
619 | | /** |
620 | | * Hash function for single characters |
621 | | */ |
622 | | unsigned long int EXPORT_CALL |
623 | | _lou_charHash(widechar c); |
624 | | |
625 | | /** |
626 | | * Return a string in the same format as the characters operand in opcodes |
627 | | */ |
628 | | const char *EXPORT_CALL |
629 | | _lou_showString(widechar const *chars, int length, int forceHex); |
630 | | |
631 | | /** |
632 | | * Print out dot numbers |
633 | | * |
634 | | * @return a string containing the dot numbers. The longest possible |
635 | | * output is "\123456789ABCDEF0/" |
636 | | */ |
637 | | const char *EXPORT_CALL |
638 | | _lou_unknownDots(widechar dots); |
639 | | |
640 | | /** |
641 | | * Return a character string in the format of the dots operand |
642 | | */ |
643 | | const char *EXPORT_CALL |
644 | | _lou_showDots(widechar const *dots, int length); |
645 | | |
646 | | /** |
647 | | * Return a character string where the attributes are indicated |
648 | | * by the attribute letters used in multipass opcodes |
649 | | */ |
650 | | char *EXPORT_CALL |
651 | | _lou_showAttributes(TranslationTableCharacterAttributes a); |
652 | | |
653 | | /** |
654 | | * Return number of the opcode |
655 | | * |
656 | | * @param toFind the opcodes |
657 | | */ |
658 | | TranslationTableOpcode EXPORT_CALL |
659 | | _lou_findOpcodeNumber(const char *tofind); |
660 | | |
661 | | /** |
662 | | * Return the name of the opcode associated with an opcode number |
663 | | * |
664 | | * @param opcode an opcode |
665 | | */ |
666 | | const char *EXPORT_CALL |
667 | | _lou_findOpcodeName(TranslationTableOpcode opcode); |
668 | | |
669 | | /** |
670 | | * Convert string to wide characters |
671 | | * |
672 | | * Takes a character string and produces a sequence of wide characters. |
673 | | * Opposite of _lou_showString. |
674 | | * |
675 | | * @param inString the input string |
676 | | * @param outString the output wide char sequence |
677 | | * @return length of the widechar sequence. |
678 | | */ |
679 | | int EXPORT_CALL |
680 | | _lou_extParseChars(const char *inString, widechar *outString); |
681 | | |
682 | | /** |
683 | | * Convert string to wide characters containing dot patterns |
684 | | * |
685 | | * Takes a character string and produces a sequence of wide characters |
686 | | * containing dot patterns. Opposite of _lou_showDots. |
687 | | * @param inString the input string |
688 | | * @param outString the output wide char sequence |
689 | | * @return length of the widechar sequence. |
690 | | */ |
691 | | int EXPORT_CALL |
692 | | _lou_extParseDots(const char *inString, widechar *outString); |
693 | | |
694 | | int EXPORT_CALL |
695 | | _lou_translate(const char *tableList, const char *displayTableList, const widechar *inbuf, |
696 | | int *inlen, widechar *outbuf, int *outlen, formtype *typeform, char *spacing, |
697 | | int *outputPos, int *inputPos, int *cursorPos, int mode, |
698 | | const TranslationTableRule **rules, int *rulesLen); |
699 | | |
700 | | int EXPORT_CALL |
701 | | _lou_backTranslate(const char *tableList, const char *displayTableList, |
702 | | const widechar *inbuf, int *inlen, widechar *outbuf, int *outlen, |
703 | | formtype *typeform, char *spacing, int *outputPos, int *inputPos, int *cursorPos, |
704 | | int mode, const TranslationTableRule **rules, int *rulesLen); |
705 | | |
706 | | void EXPORT_CALL |
707 | | _lou_resetPassVariables(void); |
708 | | |
709 | | int EXPORT_CALL |
710 | | _lou_handlePassVariableTest(const widechar *instructions, int *IC, int *itsTrue); |
711 | | |
712 | | int EXPORT_CALL |
713 | | _lou_handlePassVariableAction(const widechar *instructions, int *IC); |
714 | | |
715 | | int EXPORT_CALL |
716 | | _lou_pattern_compile(const widechar *input, const int input_max, widechar *expr_data, |
717 | | const int expr_max, TranslationTableHeader *table, const FileInfo *nested); |
718 | | |
719 | | void EXPORT_CALL |
720 | | _lou_pattern_reverse(widechar *expr_data); |
721 | | |
722 | | int EXPORT_CALL |
723 | | _lou_pattern_check(const widechar *input, const int input_start, const int input_minmax, |
724 | | const int input_dir, const widechar *expr_data, |
725 | | const TranslationTableHeader *table); |
726 | | |
727 | | /** |
728 | | * Read a line of widechar's from an input file |
729 | | */ |
730 | | int EXPORT_CALL |
731 | | _lou_getALine(FileInfo *info); |
732 | | |
733 | | #ifdef DEBUG |
734 | | /* Can be inserted in code to be used as a breakpoint in gdb */ |
735 | | void EXPORT_CALL |
736 | | _lou_debugHook(void); |
737 | | #endif |
738 | | |
739 | | /** |
740 | | * Print an out-of-memory message and exit |
741 | | */ |
742 | | void EXPORT_CALL |
743 | | _lou_outOfMemory(void); |
744 | | |
745 | | /** |
746 | | * Helper for logging a widechar buffer |
747 | | */ |
748 | | void EXPORT_CALL |
749 | | _lou_logWidecharBuf(logLevels level, const char *msg, const widechar *wbuf, int wlen); |
750 | | |
751 | | void EXPORT_CALL |
752 | | _lou_logMessage(logLevels level, const char *format, ...); |
753 | | |
754 | | void EXPORT_CALL |
755 | | _lou_freeTableIndex(void); |
756 | | |
757 | | extern int translation_direction; |
758 | | |
759 | | /** |
760 | | * Return 1 if given translation mode is valid. Return 0 otherwise. |
761 | | */ |
762 | | int EXPORT_CALL |
763 | | _lou_isValidMode(int mode); |
764 | | |
765 | | /** |
766 | | * Return the default braille representation for a character. |
767 | | */ |
768 | | widechar EXPORT_CALL |
769 | | _lou_charToFallbackDots(widechar c); |
770 | | |
771 | | static inline int |
772 | 2.10k | isASCII(widechar c) { |
773 | 2.10k | return (c >= 0X20) && (c < 0X7F); |
774 | 2.10k | } Unexecuted instantiation: compileTranslationTable.c:isASCII Unexecuted instantiation: pattern.c:isASCII Unexecuted instantiation: logging.c:isASCII Line | Count | Source | 772 | 2.10k | isASCII(widechar c) { | 773 | 2.10k | return (c >= 0X20) && (c < 0X7F); | 774 | 2.10k | } |
Unexecuted instantiation: metadata.c:isASCII Unexecuted instantiation: fuzz_backtranslate.c:isASCII Unexecuted instantiation: lou_backTranslateString.c:isASCII Unexecuted instantiation: commonTranslationFunctions.c:isASCII Unexecuted instantiation: fuzz_translate_generic.c:isASCII Unexecuted instantiation: lou_translateString.c:isASCII |
775 | | |
776 | | #ifdef __cplusplus |
777 | | } |
778 | | #endif /* __cplusplus */ |
779 | | |
780 | | #endif /* __LOUIS_H_ */ |