| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <stddef.h> |
| 4 |
#include <stdint.h> |
| 5 |
|
| 6 |
#if defined(_WIN32) && defined(OPENCC_PLUGIN_BUILD) |
| 7 |
#define OPENCC_PLUGIN_EXPORT __declspec(dllexport) |
| 8 |
#elif !defined(_WIN32) |
| 9 |
#define OPENCC_PLUGIN_EXPORT __attribute__((visibility("default"))) |
| 10 |
#else |
| 11 |
#define OPENCC_PLUGIN_EXPORT |
| 12 |
#endif |
| 13 |
|
| 14 |
#ifdef __cplusplus |
| 15 |
extern "C" { |
| 16 |
#endif |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#define OPENCC_SEGMENTATION_PLUGIN_ABI_MAJOR 2 |
| 31 |
#define OPENCC_SEGMENTATION_PLUGIN_ABI_MINOR 0 |
| 32 |
|
| 33 |
enum { |
| 34 |
OPENCC_ERROR_UNKNOWN = 1, |
| 35 |
OPENCC_ERROR_INVALID_ARGUMENT = 2, |
| 36 |
OPENCC_ERROR_PLUGIN_NOT_FOUND = 3, |
| 37 |
OPENCC_ERROR_PLUGIN_LOAD_FAILED = 4, |
| 38 |
OPENCC_ERROR_PLUGIN_SYMBOL_MISSING = 5, |
| 39 |
OPENCC_ERROR_PLUGIN_ABI_MISMATCH = 6, |
| 40 |
OPENCC_ERROR_PLUGIN_TYPE_MISMATCH = 7, |
| 41 |
OPENCC_ERROR_PLUGIN_DESCRIPTOR_INVALID = 8, |
| 42 |
OPENCC_ERROR_PLUGIN_RESOURCE_MISSING = 9, |
| 43 |
OPENCC_ERROR_PLUGIN_RUNTIME_FAILURE = 10, |
| 44 |
}; |
| 45 |
|
| 46 |
typedef struct { |
| 47 |
size_t struct_size; |
| 48 |
const char* key; |
| 49 |
const char* value; |
| 50 |
} opencc_kv_pair_t; |
| 51 |
|
| 52 |
typedef struct opencc_segmentation_handle opencc_segmentation_handle_t; |
| 53 |
|
| 54 |
typedef struct { |
| 55 |
size_t struct_size; |
| 56 |
int code; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
const char* message; |
| 65 |
} opencc_error_t; |
| 66 |
|
| 67 |
typedef struct { |
| 68 |
size_t struct_size; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
uint32_t* codepoint_lengths; |
| 74 |
size_t segment_count; |
| 75 |
} opencc_segment_length_array_t; |
| 76 |
|
| 77 |
typedef struct { |
| 78 |
size_t struct_size; |
| 79 |
const opencc_kv_pair_t* config; |
| 80 |
size_t config_size; |
| 81 |
opencc_segmentation_handle_t** out; |
| 82 |
opencc_error_t* error; |
| 83 |
} opencc_segmentation_create_args_t; |
| 84 |
|
| 85 |
typedef struct { |
| 86 |
size_t struct_size; |
| 87 |
opencc_segmentation_handle_t* handle; |
| 88 |
const char* utf8_text; |
| 89 |
opencc_segment_length_array_t* segment_lengths; |
| 90 |
opencc_error_t* error; |
| 91 |
} opencc_segmentation_segment_args_t; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
typedef struct { |
| 100 |
size_t struct_size; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
uint16_t abi_major; |
| 115 |
uint16_t abi_minor; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
const char* plugin_name; |
| 122 |
const char* segmentation_type; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
int (*create)(opencc_segmentation_create_args_t* args); |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
int (*segment)(opencc_segmentation_segment_args_t* args); |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
void (*free_segment_lengths)(opencc_segment_length_array_t* segment_lengths); |
| 168 |
void (*destroy)(opencc_segmentation_handle_t* handle); |
| 169 |
void (*free_error)(opencc_error_t* error); |
| 170 |
} opencc_segmentation_plugin_v2; |
| 171 |
|
| 172 |
OPENCC_PLUGIN_EXPORT const opencc_segmentation_plugin_v2* |
| 173 |
opencc_get_segmentation_plugin_v2(void); |
| 174 |
|
| 175 |
#ifdef __cplusplus |
| 176 |
} |
| 177 |
#endif |