libtranscript
|
00001 /* Copyright (C) 2011 G.P. Halkes 00002 This program is free software: you can redistribute it and/or modify 00003 it under the terms of the GNU General Public License version 3, as 00004 published by the Free Software Foundation. 00005 00006 This program is distributed in the hope that it will be useful, 00007 but WITHOUT ANY WARRANTY; without even the implied warranty of 00008 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00009 GNU General Public License for more details. 00010 00011 You should have received a copy of the GNU General Public License 00012 along with this program. If not, see <http://www.gnu.org/licenses/>. 00013 */ 00014 #ifndef TRANSCRIPT_MODULEDEFS_H 00015 #define TRANSCRIPT_MODULEDEFS_H 00016 #include <stdlib.h> 00017 #include <stdint.h> 00018 00019 #include <transcript/transcript.h> 00020 #include <transcript/api.h> 00021 #include <transcript/handle.h> 00022 #include <transcript/utf.h> 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 enum { 00029 TRANSCRIPT_DUMMY = 0, 00030 TRANSCRIPT_FULL_MODULE_V1, /* Provides all functions itself. */ 00031 TRANSCRIPT_STATE_TABLE_V1, /* Provides a set of state tables. See state_table_converter for details. */ 00032 TRANSCRIPT_SBCS_TABLE_V1 /* Simple set of tables for SBCSs. See sbcs_converter for details. */ 00033 }; 00034 00035 enum { 00036 TRANSCRIPT_HANDLING_UNASSIGNED = (1<<14), 00037 TRANSCRIPT_INTERNAL = (1<<15) 00038 }; 00039 00040 #define MAX_CHAR_BYTES_V1 4 00041 00042 typedef struct { 00043 const uint8_t bytes[MAX_CHAR_BYTES_V1]; 00044 const uint8_t from_state; 00045 const uint8_t to_state; 00046 const uint8_t len; 00047 } shift_state_v1_t; 00048 00049 typedef struct { 00050 const uint16_t codepoints[19]; 00051 const uint8_t bytes[31]; 00052 const uint8_t codepoints_length; 00053 const uint8_t bytes_length; 00054 const uint8_t flags; 00055 } multi_mapping_v1_t; 00056 00057 typedef struct { 00058 const uint32_t codepoint; 00059 const char codepage_bytes[MAX_CHAR_BYTES_V1]; 00060 const uint16_t sort_idx; 00061 const uint8_t from_unicode_flags; 00062 const uint8_t to_unicode_flags; 00063 } variant_mapping_v1_t; 00064 00065 typedef struct { 00066 const variant_mapping_v1_t *simple_mappings; 00067 const uint16_t nr_mappings, flags; 00068 } variant_v1_t; 00069 00070 typedef struct { 00071 const uint8_t *flags; 00072 const uint16_t *indices; 00073 const uint8_t default_flags; 00074 const uint8_t flags_type; 00075 } flags_v1_t; 00076 00077 typedef struct { 00078 const uint16_t base, mul; 00079 const uint8_t low, next_state, action; 00080 } entry_v1_t; 00081 00082 typedef struct { 00083 const entry_v1_t *entries; 00084 const uint16_t base; 00085 const uint8_t map[256]; 00086 } state_v1_t; 00087 00088 typedef struct { 00089 const state_v1_t *codepage_states; 00090 const state_v1_t *unicode_states; 00091 const shift_state_v1_t *shift_states; 00092 00093 const uint16_t *codepage_mappings; 00094 const uint8_t *unicode_mappings; 00095 00096 const flags_v1_t codepage_flags; 00097 const flags_v1_t unicode_flags; 00098 00099 const uint8_t subchar[MAX_CHAR_BYTES_V1]; 00100 00101 const uint16_t flags; 00102 00103 const uint8_t subchar_len; 00104 const uint8_t subchar1; 00105 const uint8_t nr_shift_states; 00106 const uint8_t single_size; 00107 } converter_v1_t; 00108 00109 typedef struct { 00110 const converter_v1_t *converter; 00111 const variant_v1_t *variant; 00112 const multi_mapping_v1_t * const *codepage_sorted_multi_mappings; 00113 const multi_mapping_v1_t * const *codepoint_sorted_multi_mappings; 00114 uint32_t nr_multi_mappings; 00115 } converter_tables_v1_t; 00116 00117 typedef struct { 00118 const uint8_t *codepoint_to_byte_flags; 00119 const uint8_t (*codepoint_to_byte_data)[32]; 00120 const uint8_t (*codepoint_to_byte_idx1)[32]; 00121 const uint8_t codepoint_to_byte_idx0[64]; 00122 const uint16_t byte_to_codepoint[256]; 00123 const uint16_t byte_to_codepoint_flags[32]; 00124 const uint8_t flags; 00125 const uint8_t subchar; 00126 } sbcs_converter_v1_t; 00127 00128 TRANSCRIPT_API uint32_t transcript_get_generic_fallback(uint32_t codepoint); 00129 TRANSCRIPT_API transcript_error_t transcript_handle_unassigned(transcript_t *handle, uint32_t codepoint, char **outbuf, 00130 const char *outbuflimit, int flags); 00131 TRANSCRIPT_API int transcript_probe_converter_nolock(const char *name); 00132 00133 #define HANDLE_UNASSIGNED(_code) \ 00134 switch (transcript_handle_unassigned((transcript_t *) handle, codepoint, outbuf, outbuflimit, flags)) { \ 00135 case TRANSCRIPT_UNASSIGNED: \ 00136 _code \ 00137 break; \ 00138 case TRANSCRIPT_SUCCESS: \ 00139 break; \ 00140 case TRANSCRIPT_NO_SPACE: \ 00141 return TRANSCRIPT_NO_SPACE; \ 00142 case TRANSCRIPT_FALLBACK: \ 00143 return TRANSCRIPT_FALLBACK; \ 00144 default: \ 00145 return TRANSCRIPT_INTERNAL_ERROR; \ 00146 } 00147 00148 #define TRANSCRIPT_ALIAS_OPEN(_func, _name) \ 00149 TRANSCRIPT_EXPORT transcript_t *transcript_open_##_name(const char *name, transcript_utf_t utf_type, \ 00150 int flags, transcript_error_t *error) { return _func(name, utf_type, flags, error); } 00151 #define TRANSCRIPT_ALIAS_PROBE(_func, _name) \ 00152 TRANSCRIPT_EXPORT int transcript_probe_##_name(const char *name) { return _func(name); } 00153 00154 #define TRANSCRIPT_ARRAY_SIZE(name) (sizeof(name) / sizeof(name[0])) 00155 00156 #ifdef __cplusplus 00157 }; /* extern "C" */ 00158 #endif 00159 00160 #endif