Open Chinese Convert  0.4.3
A project for conversion between Traditional and Simplified Chinese
 All Data Structures Files Functions Variables Groups Pages
common.h
1 /*
2  * Open Chinese Convert
3  *
4  * Copyright 2010-2013 BYVoid <byvoid@byvoid.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __COMMON_H_
20 #define __COMMON_H_
21 
22 #include <assert.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stddef.h>
27 
28 #include "opencc_types.h"
29 
30 #define INFINITY_INT ((~0U) >> 1)
31 
32 #ifdef ENABLE_GETTEXT
33 # include <libintl.h>
34 # include <locale.h>
35 # define _(STRING) dgettext(PACKAGE_NAME, STRING)
36 #else // ENABLE_GETTEXT
37 # define _(STRING) STRING
38 #endif // ENABLE_GETTEXT
39 
40 #ifndef PKGDATADIR
41 #define PKGDATADIR ""
42 #endif
43 
44 struct SConfig;
45 struct SConverter;
46 struct SDict;
47 struct SDictGroup;
48 struct SDictChain;
49 struct SDictMeta;
50 
51 typedef struct SConfig Config;
52 typedef struct SConverter Converter;
53 typedef struct SDict Dict;
54 typedef struct SDictGroup DictGroup;
55 typedef struct SDictChain DictChain;
56 typedef struct SDictMeta DictMeta;
57 
58 struct SDict {
59  opencc_dictionary_type type;
60  Dict* dict;
61 };
62 
63 #define DICTIONARY_MAX_COUNT 128
64 struct SDictGroup {
65  DictChain* dict_chain;
66  size_t count;
67  Dict* dicts[DICTIONARY_MAX_COUNT];
68 };
69 
70 #define DICTIONARY_GROUP_MAX_COUNT 128
71 struct SDictChain {
72  Config* config;
73  size_t count;
74  DictGroup* groups[DICTIONARY_GROUP_MAX_COUNT];
75 };
76 
77 struct SDictMeta {
78  opencc_dictionary_type dict_type;
79  char* file_name;
80  size_t index;
81  size_t stamp;
82 };
83 
84 struct SConfig {
85  char* title;
86  char* description;
87  DictChain* dict_chain;
88  char* file_path;
89  DictMeta dicts[DICTIONARY_MAX_COUNT];
90  size_t dicts_count;
91  size_t stamp;
92 };
93 
94 struct SConverter {
95  opencc_conversion_mode conversion_mode;
96  DictChain* dict_chain;
97  DictGroup* current_dict_group;
98  void* data;
99 };
100 
101 #endif // __COMMON_H_