File: ctb_internal.h

package info (click to toggle)
brltty 6.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,776 kB
  • sloc: ansic: 150,447; java: 13,484; sh: 9,667; xml: 5,702; tcl: 2,634; makefile: 2,328; awk: 713; lisp: 366; python: 321; ml: 301
file content (194 lines) | stat: -rw-r--r-- 5,938 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2025 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU Lesser General Public License, as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any
 * later version. Please see the file LICENSE-LGPL for details.
 *
 * Web Page: http://brltty.app/
 *
 * This software is maintained by Dave Mielke <dave@mielke.cc>.
 */

#ifndef BRLTTY_INCLUDED_CTB_INTERNAL
#define BRLTTY_INCLUDED_CTB_INTERNAL

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#define BYTE unsigned char

#define HASHNUM 1087
#define CTH(x) (((x[0]<<8)+x[1])%HASHNUM)

typedef uint32_t ContractionTableOffset;

typedef enum {
  CTC_Space       = 0X01,
  CTC_Letter      = 0X02,
  CTC_Digit       = 0X04,
  CTC_Punctuation = 0X08,
  CTC_UpperCase   = 0X10,
  CTC_LowerCase   = 0X20
} ContractionTableCharacterAttribute;
typedef uint32_t ContractionTableCharacterAttributes;

typedef struct {
  wchar_t value;
  ContractionTableOffset rules;
  ContractionTableOffset always;
  ContractionTableCharacterAttributes attributes;
} ContractionTableCharacter;

typedef enum {
  CTO_CapitalSign, /*dot pattern for capital sign*/
  CTO_BeginCapitalSign, /*dot pattern for beginning capital block*/
  CTO_EndCapitalSign, /*dot pattern for ending capital block*/

  CTO_LetterSign, /*dot pattern for letter sign*/
  CTO_NumberSign, /*number sign*/

  CTO_Literal, /*don't translate this string*/
  CTO_Always, /*always use this contraction*/
  CTO_Repeatable, /*take just the first, i.e. multiple blanks*/

  CTO_LargeSign, /*and, for, of, the, with*/
  CTO_LastLargeSign, /*a*/
  CTO_WholeWord, /*whole word contraction*/
  CTO_JoinedWord, /*to, by, into*/
  CTO_LowWord, /*enough, were, was, etc.*/
  CTO_Contraction, /*multiletter word sign that needs letsign*/

  CTO_SuffixableWord, /*whole word or beginning of word*/
  CTO_PrefixableWord, /*whole word or end of word*/
  CTO_BegWord, /*beginning of word only*/
  CTO_BegMidWord, /*beginning or middle of word*/
  CTO_MidWord, /*middle of word only*/
  CTO_MidEndWord, /*middle or end of word*/
  CTO_EndWord, /*end of word only*/

  CTO_PrePunc, /*punctuation in string at beginning of word*/
  CTO_PostPunc, /*punctuation in string at end of word*/

  CTO_BegNum, /*beginning of number*/
  CTO_MidNum, /*middle of number, e.g., decimal point*/
  CTO_EndNum, /*end of number*/

  CTO_Class, /*define a character class*/
  CTO_After, /*only match if after character in class*/
  CTO_Before, /*only match if before character in class*/

  CTO_Replace, /*replace text*/

  CTO_None /*for internal use only*/
} ContractionTableOpcode;

extern const wchar_t *getContractionTableOpcodeName (ContractionTableOpcode opcode);

typedef struct {
  ContractionTableOffset next; /*next entry*/
  ContractionTableOpcode opcode; /*rule for testing validity of replacement*/
  ContractionTableCharacterAttributes after; /*character types which must foollow*/
  ContractionTableCharacterAttributes before; /*character types which must precede*/
  BYTE findlen; /*length of string to be replaced*/
  BYTE replen; /*length of replacement string*/
  wchar_t findrep[]; /*find and replacement strings*/
} ContractionTableRule;

typedef struct {
  ContractionTableOffset capitalSign; /*capitalization sign*/
  ContractionTableOffset beginCapitalSign; /*begin capitals sign*/
  ContractionTableOffset endCapitalSign; /*end capitals sign*/
  ContractionTableOffset letterSign; /*letter sign*/
  ContractionTableOffset numberSign; /*number sign*/
  ContractionTableOffset characters;
  uint32_t characterCount;
  ContractionTableOffset rules[HASHNUM]; /*locations of multi-character rules in table*/
} ContractionTableHeader;

typedef struct {
  const ContractionTableRule *always;
  ContractionTableCharacterAttributes attributes;

  wchar_t value;
  wchar_t uppercase;
  wchar_t lowercase;
} CharacterEntry;

typedef struct {
  void (*destroy) (ContractionTable *table);
} ContractionTableManagementMethods;

typedef struct ContractionTableTranslationMethodsStruct ContractionTableTranslationMethods;
typedef const ContractionTableTranslationMethods *GetContractionTableTranslationMethodsFunction (void);
extern GetContractionTableTranslationMethodsFunction getContractionTableTranslationMethods_native;
extern GetContractionTableTranslationMethodsFunction getContractionTableTranslationMethods_external;
extern GetContractionTableTranslationMethodsFunction getContractionTableTranslationMethods_louis;

typedef struct {
  union {
    ContractionTableHeader *fields;
    const unsigned char *bytes;
  } header;

  size_t size;
} InternalContractionTable;

struct ContractionTableStruct {
  const ContractionTableManagementMethods *managementMethods;
  const ContractionTableTranslationMethods *translationMethods;

  struct {
    CharacterEntry *array;
    unsigned int size;
    unsigned int count;
  } characters;

  struct {
    ContractionTableRule **array;
    unsigned int size;
    unsigned int count;
  } rules;

  union {
    InternalContractionTable internal;

    struct {
      char *command;
      FILE *standardInput;
      FILE *standardOutput;
      unsigned commandStarted:1;

      struct {
        char *buffer;
        size_t size;
      } input;
    } external;

#ifdef LOUIS_TABLES_DIRECTORY
    struct {
      char *tableList;
    } louis;
#endif /* LOUIS_TABLES_DIRECTORY */
  } data;
};

extern int startContractionCommand (ContractionTable *table);
extern void stopContractionCommand (ContractionTable *table);

extern const unsigned char *getInternalContractionTableBytes (void);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* BRLTTY_INCLUDED_CTB_INTERNAL */