libtranscript
 All Data Structures Functions Variables Enumerations Enumerator Modules
moduledefs.h
1 /* Copyright (C) 2011 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef TRANSCRIPT_MODULEDEFS_H
15 #define TRANSCRIPT_MODULEDEFS_H
16 #include <stdlib.h>
17 #include <stdint.h>
18 
19 #include <transcript/transcript.h>
20 #include <transcript/api.h>
21 #include <transcript/handle.h>
22 #include <transcript/utf.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 enum {
29  TRANSCRIPT_DUMMY = 0,
30  TRANSCRIPT_FULL_MODULE_V1, /* Provides all functions itself. */
31  TRANSCRIPT_STATE_TABLE_V1, /* Provides a set of state tables. See state_table_converter for details. */
32  TRANSCRIPT_SBCS_TABLE_V1 /* Simple set of tables for SBCSs. See sbcs_converter for details. */
33 };
34 
35 enum {
36  TRANSCRIPT_HANDLING_UNASSIGNED = (1<<14),
37  TRANSCRIPT_INTERNAL = (1<<15)
38 };
39 
40 #define MAX_CHAR_BYTES_V1 4
41 
42 typedef struct {
43  const uint8_t bytes[MAX_CHAR_BYTES_V1];
44  const uint8_t from_state;
45  const uint8_t to_state;
46  const uint8_t len;
47 } shift_state_v1_t;
48 
49 typedef struct {
50  const uint16_t codepoints[19];
51  const uint8_t bytes[31];
52  const uint8_t codepoints_length;
53  const uint8_t bytes_length;
54  const uint8_t flags;
55 } multi_mapping_v1_t;
56 
57 typedef struct {
58  const uint32_t codepoint;
59  const char codepage_bytes[MAX_CHAR_BYTES_V1];
60  const uint16_t sort_idx;
61  const uint8_t from_unicode_flags;
62  const uint8_t to_unicode_flags;
63 } variant_mapping_v1_t;
64 
65 typedef struct {
66  const variant_mapping_v1_t *simple_mappings;
67  const uint16_t nr_mappings, flags;
68 } variant_v1_t;
69 
70 typedef struct {
71  const uint8_t *flags;
72  const uint16_t *indices;
73  const uint8_t default_flags;
74  const uint8_t flags_type;
75 } flags_v1_t;
76 
77 typedef struct {
78  const uint16_t base, mul;
79  const uint8_t low, next_state, action;
80 } entry_v1_t;
81 
82 typedef struct {
83  const entry_v1_t *entries;
84  const uint16_t base;
85  const uint8_t map[256];
86 } state_v1_t;
87 
88 typedef struct {
89  const state_v1_t *codepage_states;
90  const state_v1_t *unicode_states;
91  const shift_state_v1_t *shift_states;
92 
93  const uint16_t *codepage_mappings;
94  const uint8_t *unicode_mappings;
95 
96  const flags_v1_t codepage_flags;
97  const flags_v1_t unicode_flags;
98 
99  const uint8_t subchar[MAX_CHAR_BYTES_V1];
100 
101  const uint16_t flags;
102 
103  const uint8_t subchar_len;
104  const uint8_t subchar1;
105  const uint8_t nr_shift_states;
106  const uint8_t single_size;
107 } converter_v1_t;
108 
109 typedef struct {
110  const converter_v1_t *converter;
111  const variant_v1_t *variant;
112  const multi_mapping_v1_t * const *codepage_sorted_multi_mappings;
113  const multi_mapping_v1_t * const *codepoint_sorted_multi_mappings;
114  uint32_t nr_multi_mappings;
115 } converter_tables_v1_t;
116 
117 typedef struct {
118  const uint8_t *codepoint_to_byte_flags;
119  const uint8_t (*codepoint_to_byte_data)[32];
120  const uint8_t (*codepoint_to_byte_idx1)[32];
121  const uint8_t codepoint_to_byte_idx0[64];
122  const uint16_t byte_to_codepoint[256];
123  const uint16_t byte_to_codepoint_flags[32];
124  const uint8_t flags;
125  const uint8_t subchar;
126 } sbcs_converter_v1_t;
127 
128 TRANSCRIPT_API uint32_t transcript_get_generic_fallback(uint32_t codepoint);
129 TRANSCRIPT_API transcript_error_t transcript_handle_unassigned(transcript_t *handle, uint32_t codepoint, char **outbuf,
130  const char *outbuflimit, int flags);
131 TRANSCRIPT_API int transcript_probe_converter_nolock(const char *name);
132 
133 #define HANDLE_UNASSIGNED(_code) \
134  switch (transcript_handle_unassigned((transcript_t *) handle, codepoint, outbuf, outbuflimit, flags)) { \
135  case TRANSCRIPT_UNASSIGNED: \
136  _code \
137  break; \
138  case TRANSCRIPT_SUCCESS: \
139  break; \
140  case TRANSCRIPT_NO_SPACE: \
141  return TRANSCRIPT_NO_SPACE; \
142  case TRANSCRIPT_FALLBACK: \
143  return TRANSCRIPT_FALLBACK; \
144  default: \
145  return TRANSCRIPT_INTERNAL_ERROR; \
146  }
147 
148 #define TRANSCRIPT_ALIAS_OPEN(_func, _name) \
149  TRANSCRIPT_EXPORT transcript_t *transcript_open_##_name(const char *name, transcript_utf_t utf_type, \
150  int flags, transcript_error_t *error) { return _func(name, utf_type, flags, error); }
151 #define TRANSCRIPT_ALIAS_PROBE(_func, _name) \
152  TRANSCRIPT_EXPORT int transcript_probe_##_name(const char *name) { return _func(name); }
153 
154 #define TRANSCRIPT_ARRAY_SIZE(name) (sizeof(name) / sizeof(name[0]))
155 
156 #ifdef __cplusplus
157 }; /* extern "C" */
158 #endif
159 
160 #endif
transcript_error_t
Error values.
Definition: transcript.h:91
An opaque structure describing a converter and its state.
Definition: handle.h:28
transcript_error_t transcript_handle_unassigned(transcript_t *handle, uint32_t codepoint, char **outbuf, const char *outbuflimit, int flags)
Handle an unassigned codepoint in a from-Unicode conversion.
Definition: transcript.c:576