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 #ifdef _WIN32
43 #define PATH_SEP ';'
44 #define DIR_SEP '\\'
45 #else
46 #define PATH_SEP ':'
47 #define DIR_SEP '/'
48 #endif
49
50 #ifdef _MSC_VER
51 #define strcasecmp _stricmp
52 #endif
53
54 #define NUMSWAPS 50
55 #define NUMVAR 50
56 #define LETSIGNSIZE 128
57 #define SEQPATTERNSIZE 128
58 #define CHARSIZE sizeof(widechar)
59 #define DEFAULTRULESIZE 50
60
61 typedef struct intCharTupple {
62 int key;
63 char value;
64 } intCharTupple;
65
66 /* HASHNUM must be prime */
67 #define HASHNUM 1123
68
69 #define MAXPASS 4
70 #define MAXSTRING 2048
71
72 #define MAX_EMPH_CLASSES 10 // {emph_1...emph_10} in typeforms enum (liblouis.h)
73
74 typedef unsigned int TranslationTableOffset;
75 #define OFFSETSIZE sizeof(TranslationTableOffset)
76
77 typedef enum {
78 CTC_Space = 0x1,
79 CTC_Letter = 0x2,
80 CTC_Digit = 0x4,
81 CTC_Punctuation = 0x8,
82 CTC_UpperCase = 0x10,
83 CTC_LowerCase = 0x20,
84 CTC_Math = 0x40,
85 CTC_Sign = 0x80,
86 CTC_LitDigit = 0x100,
87 CTC_Class1 = 0x200,
88 CTC_Class2 = 0x400,
89 CTC_Class3 = 0x800,
90 CTC_Class4 = 0x1000,
91 CTC_SeqDelimiter = 0x2000,
92 CTC_SeqBefore = 0x4000,
93 CTC_SeqAfter = 0x8000,
94 CTC_UserDefined0 = 0x10000, // class 5
95 CTC_UserDefined1 = 0x20000,
96 CTC_UserDefined2 = 0x40000,
97 CTC_UserDefined3 = 0x80000,
98 CTC_UserDefined4 = 0x100000,
99 CTC_UserDefined5 = 0x200000,
100 CTC_UserDefined6 = 0x400000,
101 CTC_UserDefined7 = 0x800000, // class 12
102 CTC_CapsMode = 0x1000000,
103 CTC_EmphMode = 0x2000000,
104 CTC_NumericMode = 0x4000000,
105 CTC_NumericNoContract = 0x8000000,
106 CTC_EndOfInput = 0x10000000, // only used by pattern matcher
107 CTC_EmpMatch = 0x20000000, // only used in TranslationTableRule->before and
108 // TranslationTableRule->after
109 CTC_MidEndNumericMode = 0x40000000,
110 // 33 more bits available in a unsigned long long (at least 64 bits)
111 // currently used for classes 13 to 45
112 CTC_Class13 = 0x80000000,
113 } TranslationTableCharacterAttribute;
114
115 typedef enum {
116 pass_first = '`',
117 pass_last = '~',
118 pass_lookback = '_',
119 pass_string = '\"',
120 pass_dots = '@',
121 pass_omit = '?',
122 pass_startReplace = '[',
123 pass_endReplace = ']',
124 pass_startGroup = '{',
125 pass_endGroup = '}',
126 pass_variable = '#',
127 pass_not = '!',
128 pass_search = '/',
129 pass_any = 'a',
130 pass_digit = 'd',
131 pass_litDigit = 'D',
132 pass_letter = 'l',
133 pass_math = 'm',
134 pass_punctuation = 'p',
135 pass_sign = 'S',
136 pass_space = 's',
137 pass_uppercase = 'U',
138 pass_lowercase = 'u',
139 pass_class1 = 'w',
140 pass_class2 = 'x',
141 pass_class3 = 'y',
142 pass_class4 = 'z',
143 pass_attributes = '$',
144 pass_groupstart = '{',
145 pass_groupend = '}',
146 pass_groupreplace = ';',
147 pass_swap = '%',
148 pass_hyphen = '-',
149 pass_until = '.',
150 pass_eq = '=',
151 pass_lt = '<',
152 pass_gt = '>',
153 pass_endTest = 32,
154 pass_plus = '+',
155 pass_copy = '*',
156 pass_leftParen = '(',
157 pass_rightParen = ')',
158 pass_comma = ',',
159 pass_lteq = 130,
160 pass_gteq = 131,
161 pass_invalidToken = 132,
162 pass_noteq = 133,
163 pass_and = 134,
164 pass_or = 135,
165 pass_nameFound = 136,
166 pass_numberFound = 137,
167 pass_boolean = 138,
168 pass_class = 139,
169 pass_define = 140,
170 pass_emphasis = 141,
171 pass_group = 142,
172 pass_mark = 143,
173 pass_repGroup = 143,
174 pass_script = 144,
175 pass_noMoreTokens = 145,
176 pass_replace = 146,
177 pass_if = 147,
178 pass_then = 148,
179 pass_all = 255
180 } pass_Codes;
181
182 typedef unsigned long long TranslationTableCharacterAttributes;
183
184 typedef struct {
185 TranslationTableOffset next;
186 widechar lookFor;
187 widechar found;
188 } CharOrDots;
189
190 typedef struct {
191 TranslationTableOffset next;
192 TranslationTableOffset definitionRule;
193 TranslationTableOffset otherRules;
194 TranslationTableCharacterAttributes attributes;
195 widechar realchar;
196 widechar uppercase;
197 widechar lowercase;
198 } TranslationTableCharacter;
199
200 typedef enum { /* Op codes */
201 CTO_IncludeFile,
202 CTO_Locale, /* Deprecated, do not use */
203 CTO_Undefined,
204 /* Do not change the order of the following opcodes! */
205 CTO_CapsLetter,
206 CTO_BegCapsWord,
207 CTO_EndCapsWord,
208 CTO_BegCaps,
209 CTO_EndCaps,
210 CTO_BegCapsPhrase,
211 CTO_EndCapsPhrase,
212 CTO_LenCapsPhrase,
213 /* End of ordered opcodes */
214 CTO_LetterSign,
215 CTO_NoLetsignBefore,
216 CTO_NoLetsign,
217 CTO_NoLetsignAfter,
218 CTO_NumberSign,
219 CTO_NumericModeChars,
220 CTO_MidEndNumericModeChars,
221 CTO_NumericNoContractChars,
222 CTO_SeqDelimiter,
223 CTO_SeqBeforeChars,
224 CTO_SeqAfterChars,
225 CTO_SeqAfterPattern,
226 CTO_SeqAfterExpression,
227 CTO_EmphClass,
228
229 /* Do not change the order of the following opcodes! */
230 CTO_EmphLetter,
231 CTO_BegEmphWord,
232 CTO_EndEmphWord,
233 CTO_BegEmph,
234 CTO_EndEmph,
235 CTO_BegEmphPhrase,
236 CTO_EndEmphPhrase,
237 CTO_LenEmphPhrase,
238 /* End of ordered opcodes */
239
240 CTO_CapsModeChars,
241 CTO_EmphModeChars,
242 CTO_BegComp,
243 CTO_CompBegEmph1,
244 CTO_CompEndEmph1,
245 CTO_CompBegEmph2,
246 CTO_CompEndEmph2,
247 CTO_CompBegEmph3,
248 CTO_CompEndEmph3,
249 CTO_CompCapSign,
250 CTO_CompBegCaps,
251 CTO_CompEndCaps,
252 CTO_EndComp,
253 CTO_NoContractSign,
254 CTO_MultInd,
255 CTO_CompDots,
256 CTO_Comp6,
257 CTO_Class, /* define a character class */
258 CTO_After, /* only match if after character in class */
259 CTO_Before, /* only match if before character in class 30 */
260 CTO_NoBack,
261 CTO_NoFor,
262 CTO_EmpMatchBefore,
263 CTO_EmpMatchAfter,
264 CTO_SwapCc,
265 CTO_SwapCd,
266 CTO_SwapDd,
267 CTO_Space,
268 CTO_Digit,
269 CTO_Punctuation,
270 CTO_Math,
271 CTO_Sign,
272 CTO_Letter,
273 CTO_UpperCase,
274 CTO_LowerCase,
275 CTO_Grouping,
276 CTO_UpLow,
277 CTO_LitDigit,
278 CTO_Display,
279 CTO_Replace,
280 CTO_Context,
281 CTO_Correct,
282 CTO_Pass2,
283 CTO_Pass3,
284 CTO_Pass4,
285 CTO_Repeated,
286 CTO_RepWord,
287 CTO_CapsNoCont,
288 CTO_Always,
289 CTO_ExactDots,
290 CTO_NoCross,
291 CTO_Syllable,
292 CTO_NoCont,
293 CTO_CompBrl,
294 CTO_Literal,
295 CTO_LargeSign,
296 CTO_WholeWord,
297 CTO_PartWord,
298 CTO_JoinNum,
299 CTO_JoinableWord,
300 CTO_LowWord,
301 CTO_Contraction,
302 CTO_SuffixableWord, /** whole word or beginning of word */
303 CTO_PrefixableWord, /** whole word or end of word */
304 CTO_BegWord, /** beginning of word only */
305 CTO_BegMidWord, /** beginning or middle of word */
306 CTO_MidWord, /** middle of word only 20 */
307 CTO_MidEndWord, /** middle or end of word */
308 CTO_EndWord, /** end of word only */
309 CTO_PrePunc, /** punctuation in string at beginning of word */
310 CTO_PostPunc, /** punctuation in string at end of word */
311 CTO_BegNum, /** beginning of number */
312 CTO_MidNum, /** middle of number, e.g., decimal point */
313 CTO_EndNum, /** end of number */
314 CTO_DecPoint,
315 CTO_Hyphen,
316 // CTO_Apostrophe,
317 // CTO_Initial,
318 CTO_NoBreak,
319 CTO_Match,
320 CTO_BackMatch,
321 CTO_Attribute,
322 CTO_None,
323
324 /* More internal opcodes */
325 CTO_LetterRule,
326 CTO_NumberRule,
327 CTO_NoContractRule,
328
329 /* Start of (11 x 9) internal opcodes values that match
330 * {"singlelettercaps"..."lenemphphrase"}
331 * Do not change the order of the following opcodes! */
332 CTO_CapsLetterRule,
333 CTO_BegCapsWordRule,
334 CTO_EndCapsWordRule,
335 CTO_BegCapsRule,
336 CTO_EndCapsRule,
337 CTO_BegCapsPhraseRule,
338 CTO_EndCapsPhraseBeforeRule,
339 CTO_EndCapsPhraseAfterRule,
340 CTO_Emph1LetterRule,
341 CTO_BegEmph1WordRule,
342 CTO_EndEmph1WordRule,
343 CTO_BegEmph1Rule,
344 CTO_EndEmph1Rule,
345 CTO_BegEmph1PhraseRule,
346 CTO_EndEmph1PhraseBeforeRule,
347 CTO_EndEmph1PhraseAfterRule,
348 CTO_Emph2LetterRule,
349 CTO_BegEmph2WordRule,
350 CTO_EndEmph2WordRule,
351 CTO_BegEmph2Rule,
352 CTO_EndEmph2Rule,
353 CTO_BegEmph2PhraseRule,
354 CTO_EndEmph2PhraseBeforeRule,
355 CTO_EndEmph2PhraseAfterRule,
356 CTO_Emph3LetterRule,
357 CTO_BegEmph3WordRule,
358 CTO_EndEmph3WordRule,
359 CTO_BegEmph3Rule,
360 CTO_EndEmph3Rule,
361 CTO_BegEmph3PhraseRule,
362 CTO_EndEmph3PhraseBeforeRule,
363 CTO_EndEmph3PhraseAfterRule,
364 CTO_Emph4LetterRule,
365 CTO_BegEmph4WordRule,
366 CTO_EndEmph4WordRule,
367 CTO_BegEmph4Rule,
368 CTO_EndEmph4Rule,
369 CTO_BegEmph4PhraseRule,
370 CTO_EndEmph4PhraseBeforeRule,
371 CTO_EndEmph4PhraseAfterRule,
372 CTO_Emph5LetterRule,
373 CTO_BegEmph5WordRule,
374 CTO_EndEmph5WordRule,
375 CTO_BegEmph5Rule,
376 CTO_EndEmph5Rule,
377 CTO_BegEmph5PhraseRule,
378 CTO_EndEmph5PhraseBeforeRule,
379 CTO_EndEmph5PhraseAfterRule,
380 CTO_Emph6LetterRule,
381 CTO_BegEmph6WordRule,
382 CTO_EndEmph6WordRule,
383 CTO_BegEmph6Rule,
384 CTO_EndEmph6Rule,
385 CTO_BegEmph6PhraseRule,
386 CTO_EndEmph6PhraseBeforeRule,
387 CTO_EndEmph6PhraseAfterRule,
388 CTO_Emph7LetterRule,
389 CTO_BegEmph7WordRule,
390 CTO_EndEmph7WordRule,
391 CTO_BegEmph7Rule,
392 CTO_EndEmph7Rule,
393 CTO_BegEmph7PhraseRule,
394 CTO_EndEmph7PhraseBeforeRule,
395 CTO_EndEmph7PhraseAfterRule,
396 CTO_Emph8LetterRule,
397 CTO_BegEmph8WordRule,
398 CTO_EndEmph8WordRule,
399 CTO_BegEmph8Rule,
400 CTO_EndEmph8Rule,
401 CTO_BegEmph8PhraseRule,
402 CTO_EndEmph8PhraseBeforeRule,
403 CTO_EndEmph8PhraseAfterRule,
404 CTO_Emph9LetterRule,
405 CTO_BegEmph9WordRule,
406 CTO_EndEmph9WordRule,
407 CTO_BegEmph9Rule,
408 CTO_EndEmph9Rule,
409 CTO_BegEmph9PhraseRule,
410 CTO_EndEmph9PhraseBeforeRule,
411 CTO_EndEmph9PhraseAfterRule,
412 CTO_Emph10LetterRule,
413 CTO_BegEmph10WordRule,
414 CTO_EndEmph10WordRule,
415 CTO_BegEmph10Rule,
416 CTO_EndEmph10Rule,
417 CTO_BegEmph10PhraseRule,
418 CTO_EndEmph10PhraseBeforeRule,
419 CTO_EndEmph10PhraseAfterRule,
420 /* End of ordered (10 x 9) internal opcodes */
421
422 CTO_BegCompRule,
423 CTO_CompBegEmph1Rule,
424 CTO_CompEndEmph1Rule,
425 CTO_CompBegEmph2Rule,
426 CTO_CompEndEmrh2Rule,
427 CTO_CompBegEmph3Rule,
428 CTO_CompEndEmph3Rule,
429 CTO_CompCapSignRule,
430 CTO_CompBegCapsRule,
431 CTO_CompEndCapsRule,
432 CTO_EndCompRule,
433 CTO_CapsNoContRule,
434 CTO_All
435 } TranslationTableOpcode;
436
437 typedef struct {
438 TranslationTableOffset charsnext; /** next chars entry */
439 TranslationTableOffset dotsnext; /** next dots entry */
440 TranslationTableCharacterAttributes after; /** character types which must follow */
441 TranslationTableCharacterAttributes before; /** character types which must precede */
442 TranslationTableOffset patterns; /** before and after patterns */
443 TranslationTableOpcode opcode; /** rule for testing validity of replacement */
444 short charslen; /** length of string to be replaced */
445 short dotslen; /** length of replacement string */
446 widechar charsdots[DEFAULTRULESIZE]; /** find and replacement strings */
447 } TranslationTableRule;
448
449 typedef struct /* state transition */
450 {
451 widechar ch;
452 widechar newState;
453 } HyphenationTrans;
454
455 typedef union {
456 HyphenationTrans *pointer;
457 TranslationTableOffset offset;
458 } PointOff;
459
460 typedef struct /* one state */
461 {
462 PointOff trans;
463 TranslationTableOffset hyphenPattern;
464 widechar fallbackState;
465 widechar numTrans;
466 } HyphenationState;
467
468 typedef struct CharacterClass {
469 struct CharacterClass *next;
470 TranslationTableCharacterAttributes attribute;
471 widechar length;
472 widechar name[1];
473 } CharacterClass;
474
475 typedef struct RuleName {
476 struct RuleName *next;
477 TranslationTableOffset ruleOffset;
478 widechar length;
479 widechar name[1];
480 } RuleName;
481
482 typedef struct {
483 TranslationTableOffset tableSize;
484 TranslationTableOffset bytesUsed;
485 TranslationTableOffset charToDots[HASHNUM];
486 TranslationTableOffset dotsToChar[HASHNUM];
487 TranslationTableOffset ruleArea[1]; /** Space for storing all rules and values */
488 } DisplayTableHeader;
489
490 /**
491 * Translation table header
492 */
493 typedef struct { /* translation table */
494 int capsNoCont;
495 int numPasses;
496 int corrections;
497 int syllables;
498 int usesSequences;
499 int usesNumericMode;
500 int usesEmphMode;
501 TranslationTableOffset tableSize;
502 TranslationTableOffset bytesUsed;
503 TranslationTableOffset undefined;
504 TranslationTableOffset letterSign;
505 TranslationTableOffset numberSign;
506 TranslationTableOffset noContractSign;
507 widechar seqPatterns[SEQPATTERNSIZE];
508 char *emphClasses[MAX_EMPH_CLASSES + 1];
509 int seqPatternsCount;
510 widechar seqAfterExpression[SEQPATTERNSIZE];
511 int seqAfterExpressionLength;
512
513 /* emphRules, including caps. */
514 TranslationTableOffset emphRules[MAX_EMPH_CLASSES + 1][9];
515
516 /* state needed during compilation */
517 CharacterClass *characterClasses;
518 TranslationTableCharacterAttributes nextCharacterClassAttribute;
519 RuleName *ruleNames;
520
521 TranslationTableOffset begComp;
522 TranslationTableOffset compBegEmph1;
523 TranslationTableOffset compEndEmph1;
524 TranslationTableOffset compBegEmph2;
525 TranslationTableOffset compEndEmph2;
526 TranslationTableOffset compBegEmph3;
527 TranslationTableOffset compEndEmph3;
528 TranslationTableOffset compCapSign;
529 TranslationTableOffset compBegCaps;
530 TranslationTableOffset compEndCaps;
531 TranslationTableOffset endComp;
532 TranslationTableOffset hyphenStatesArray;
533 widechar noLetsignBefore[LETSIGNSIZE];
534 int noLetsignBeforeCount;
535 widechar noLetsign[LETSIGNSIZE];
536 int noLetsignCount;
537 widechar noLetsignAfter[LETSIGNSIZE];
538 int noLetsignAfterCount;
539 TranslationTableOffset characters[HASHNUM]; /** Character definitions */
540 TranslationTableOffset dots[HASHNUM]; /** Dot definitions */
541 TranslationTableOffset compdotsPattern[256];
542 TranslationTableOffset swapDefinitions[NUMSWAPS];
543 TranslationTableOffset forPassRules[MAXPASS + 1];
544 TranslationTableOffset backPassRules[MAXPASS + 1];
545 TranslationTableOffset forRules[HASHNUM]; /** chains of forward rules */
546 TranslationTableOffset backRules[HASHNUM]; /** Chains of backward rules */
547 TranslationTableOffset ruleArea[1]; /** Space for storing all rules and values */
548 } TranslationTableHeader;
549
550 typedef enum {
551 alloc_typebuf,
552 alloc_wordBuffer,
553 alloc_emphasisBuffer,
554 alloc_destSpacing,
555 alloc_passbuf,
556 alloc_posMapping1,
557 alloc_posMapping2,
558 alloc_posMapping3
559 } AllocBuf;
560
561 #define MAXPASSBUF 3
562
563 typedef enum {
564 capsRule = 0,
565 emph1Rule = 1,
566 emph2Rule = 2,
567 emph3Rule = 3,
568 emph4Rule = 4,
569 emph5Rule = 5,
570 emph6Rule = 6,
571 emph7Rule = 7,
572 emph8Rule = 8,
573 emph9Rule = 9,
574 emph10Rule = 10
575 } EmphRuleNumber;
576
577 typedef enum {
578 begPhraseOffset = 0,
579 endPhraseBeforeOffset = 1,
580 endPhraseAfterOffset = 2,
581 begOffset = 3,
582 endOffset = 4,
583 letterOffset = 5,
584 begWordOffset = 6,
585 endWordOffset = 7,
586 lenPhraseOffset = 8
587 } EmphCodeOffset;
588
589 /* Grouping the begin, end, word and symbol bits and using the type of
590 * a single bit group for representing the emphasis classes allows us
591 * to do simple bit operations. */
592
593 typedef struct {
594 unsigned int begin : 16;
595 unsigned int end : 16;
596 unsigned int word : 16;
597 unsigned int symbol : 16;
598 } EmphasisInfo;
599
600 /* An emphasis class is a bit field that contains a single "1" */
601 typedef unsigned int EmphasisClass;
602
603 typedef enum { noEncoding, bigEndian, littleEndian, ascii8 } EncodingType;
604
605 typedef struct {
606 const char *fileName;
607 FILE *in;
608 int lineNumber;
609 EncodingType encoding;
610 int status;
611 int linelen;
612 int linepos;
613 int checkencoding[2];
614 widechar line[MAXSTRING];
615 } FileInfo;
616
617 /* The following function definitions are hooks into
618 * compileTranslationTable.c. Some are used by other library modules.
619 * Others are used by tools like lou_allround.c and lou_debug.c. */
620
621 /**
622 * Comma separated list of directories to search for tables.
623 */
624 char *EXPORT_CALL
625 _lou_getTablePath(void);
626
627 /**
628 * Resolve tableList against base.
629 */
630 char **EXPORT_CALL
631 _lou_resolveTable(const char *tableList, const char *base);
632
633 /**
634 * The default table resolver
635 */
636 char **EXPORT_CALL
637 _lou_defaultTableResolver(const char *tableList, const char *base);
638
639 /**
640 * Return single-cell dot pattern corresponding to a character.
641 * TODO: move to commonTranslationFunctions.c
642 */
643 widechar EXPORT_CALL
644 _lou_getDotsForChar(widechar c, const DisplayTableHeader *table);
645
646 /**
647 * Return character corresponding to a single-cell dot pattern.
648 * TODO: move to commonTranslationFunctions.c
649 */
650 widechar EXPORT_CALL
651 _lou_getCharFromDots(widechar d, const DisplayTableHeader *table);
652
653 void EXPORT_CALL
654 _lou_getTable(const char *tableList, const char *displayTableList,
655 const TranslationTableHeader **translationTable,
656 const DisplayTableHeader **displayTable);
657
658 const TranslationTableHeader *EXPORT_CALL
659 _lou_getTranslationTable(const char *tableList);
660
661 const DisplayTableHeader *EXPORT_CALL
662 _lou_getDisplayTable(const char *tableList);
663
664 int EXPORT_CALL
665 _lou_compileTranslationRule(const char *tableList, const char *inString);
666
667 int EXPORT_CALL
668 _lou_compileDisplayRule(const char *tableList, const char *inString);
669
670 /**
671 * Allocate memory for internal buffers
672 *
673 * Used by lou_translateString.c and lou_backTranslateString.c ONLY
674 * to allocate memory for internal buffers.
675 * TODO: move to utils.c
676 */
677 void *EXPORT_CALL
678 _lou_allocMem(AllocBuf buffer, int index, int srcmax, int destmax);
679
680 /**
681 * Hash function for character strings
682 *
683 * @param lowercase Whether to convert the string to lowercase because
684 * making the hash of it.
685 */
686 unsigned long int EXPORT_CALL
687 _lou_stringHash(const widechar *c, int lowercase, const TranslationTableHeader *table);
688
689 /**
690 * Hash function for single characters
691 */
692 unsigned long int EXPORT_CALL
693 _lou_charHash(widechar c);
694
695 /**
696 * Return a string in the same format as the characters operand in opcodes
697 */
698 const char *EXPORT_CALL
699 _lou_showString(widechar const *chars, int length, int forceHex);
700
701 /**
702 * Print out dot numbers
703 *
704 * @return a string containing the dot numbers. The longest possible
705 * output is "\123456789ABCDEF0/"
706 */
707 const char *EXPORT_CALL
708 _lou_unknownDots(widechar dots);
709
710 /**
711 * Return a character string in the format of the dots operand
712 */
713 const char *EXPORT_CALL
714 _lou_showDots(widechar const *dots, int length);
715
716 /**
717 * Return a character string where the attributes are indicated
718 * by the attribute letters used in multipass opcodes
719 */
720 char *EXPORT_CALL
721 _lou_showAttributes(TranslationTableCharacterAttributes a);
722
723 /**
724 * Return number of the opcode
725 *
726 * @param toFind the opcodes
727 */
728 TranslationTableOpcode EXPORT_CALL
729 _lou_findOpcodeNumber(const char *tofind);
730
731 /**
732 * Return the name of the opcode associated with an opcode number
733 *
734 * @param opcode an opcode
735 */
736 const char *EXPORT_CALL
737 _lou_findOpcodeName(TranslationTableOpcode opcode);
738
739 /**
740 * Convert string to wide characters
741 *
742 * Takes a character string and produces a sequence of wide characters.
743 * Opposite of _lou_showString.
744 *
745 * @param inString the input string
746 * @param outString the output wide char sequence
747 * @return length of the widechar sequence.
748 */
749 int EXPORT_CALL
750 _lou_extParseChars(const char *inString, widechar *outString);
751
752 /**
753 * Convert string to wide characters containing dot patterns
754 *
755 * Takes a character string and produces a sequence of wide characters
756 * containing dot patterns. Opposite of _lou_showDots.
757 * @param inString the input string
758 * @param outString the output wide char sequence
759 * @return length of the widechar sequence.
760 */
761 int EXPORT_CALL
762 _lou_extParseDots(const char *inString, widechar *outString);
763
764 int EXPORT_CALL
765 _lou_translate(const char *tableList, const char *displayTableList, const widechar *inbuf,
766 int *inlen, widechar *outbuf, int *outlen, formtype *typeform, char *spacing,
767 int *outputPos, int *inputPos, int *cursorPos, int mode,
768 const TranslationTableRule **rules, int *rulesLen);
769
770 int EXPORT_CALL
771 _lou_backTranslate(const char *tableList, const char *displayTableList,
772 const widechar *inbuf, int *inlen, widechar *outbuf, int *outlen,
773 formtype *typeform, char *spacing, int *outputPos, int *inputPos, int *cursorPos,
774 int mode, const TranslationTableRule **rules, int *rulesLen);
775
776 void EXPORT_CALL
777 _lou_resetPassVariables(void);
778
779 int EXPORT_CALL
780 _lou_handlePassVariableTest(const widechar *instructions, int *IC, int *itsTrue);
781
782 int EXPORT_CALL
783 _lou_handlePassVariableAction(const widechar *instructions, int *IC);
784
785 int EXPORT_CALL
786 _lou_pattern_compile(const widechar *input, const int input_max, widechar *expr_data,
787 const int expr_max, const TranslationTableHeader *t);
788
789 void EXPORT_CALL
790 _lou_pattern_reverse(widechar *expr_data);
791
792 int EXPORT_CALL
793 _lou_pattern_check(const widechar *input, const int input_start, const int input_minmax,
794 const int input_dir, const widechar *expr_data, const TranslationTableHeader *t);
795
796 /**
797 * Read a line of widechar's from an input file
798 */
799 int EXPORT_CALL
800 _lou_getALine(FileInfo *info);
801
802 #ifdef DEBUG
803 /* Can be inserted in code to be used as a breakpoint in gdb */
804 void EXPORT_CALL
805 _lou_debugHook(void);
806 #endif
807
808 /**
809 * Print an out-of-memory message and exit
810 */
811 void EXPORT_CALL
812 _lou_outOfMemory(void);
813
814 /**
815 * Helper for logging a widechar buffer
816 */
817 void EXPORT_CALL
818 _lou_logWidecharBuf(logLevels level, const char *msg, const widechar *wbuf, int wlen);
819
820 void EXPORT_CALL
821 _lou_logMessage(logLevels level, const char *format, ...);
822
823 extern int translation_direction;
824
825 /**
826 * Return 1 if given translation mode is valid. Return 0 otherwise.
827 */
828 int EXPORT_CALL
829 _lou_isValidMode(int mode);
830
831 /**
832 * Return the default braille representation for a character.
833 */
834 widechar EXPORT_CALL
835 _lou_charToFallbackDots(widechar c);
836
837 static inline int
isASCII(widechar c)838 isASCII(widechar c) {
839 return (c >= 0X20) && (c < 0X7F);
840 }
841
842 #ifdef __cplusplus
843 }
844 #endif /* __cplusplus */
845
846 #endif /* __LOUIS_H_ */
847