1 /*
2  * Copyright (C) 2020 The HIME team, Taiwan
3  * Copyright (C) 2004-2011 Edward Der-Hua Liu, Hsin-Chu, Taiwan
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation version 2.1
8  * of the License.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef GTAB_H
21 #define GTAB_H
22 
23 #include "hime.h"
24 
25 typedef enum {
26     GTAB_space_auto_first_none = 0,    // use the value set by .cin
27     GTAB_space_auto_first_any = 1,     // boshiamy, dayi
28     GTAB_space_auto_first_full = 2,    // simplex
29     GTAB_space_auto_first_nofull = 4,  // windows ar30 cj
30     GTAB_space_auto_first_dayi = 8     // dayi: input:2   select:1
31 } GTAB_space_pressed_E;
32 
33 typedef struct {
34     u_char key[4]; /* If I use u_long key, the struc size will be 8 */
35     u_char ch[CH_SZ];
36 } ITEM;
37 
38 typedef struct {
39     u_char key[8]; /* If I use u_long key, the struc size will be 8 */
40     u_char ch[CH_SZ];
41 } ITEM64;
42 
43 typedef struct {
44     char quick1[46][10][CH_SZ];
45     char quick2[46][46][10][CH_SZ];
46 } QUICK_KEYS;
47 
48 enum {
49     FLAG_KEEP_KEY_CASE = 1,
50     FLAG_GTAB_SYM_KBM = 2,  // auto close, auto switch to default input method
51     FLAG_PHRASE_AUTO_SKIP_ENDKEY = 4,
52     FLAG_AUTO_SELECT_BY_PHRASE = 8,
53     FLAG_GTAB_DISP_PARTIAL_MATCH = 0x10,
54     FLAG_GTAB_DISP_FULL_MATCH = 0x20,
55     FLAG_GTAB_VERTICAL_SELECTION = 0x40,
56     FLAG_GTAB_PRESS_FULL_AUTO_SEND = 0x80,
57     FLAG_GTAB_UNIQUE_AUTO_SEND = 0x100,
58 };
59 
60 enum {
61     GTAB_OPTION_AUTO = 0,
62     GTAB_OPTION_YES = 1,
63     GTAB_OPTION_NO = 2,
64 };
65 
66 /* avoid conflict with /usr/include/chewing/global.h */
67 #undef MAX_SELKEY
68 #define MAX_SELKEY 16
69 
70 struct TableHead {
71     int version;
72     u_int flag;
73     char cname[32];  /* prompt */
74     char selkey[12]; /* select keys */
75     GTAB_space_pressed_E space_style;
76     int KeyS;      /* number of keys needed */
77     int MaxPress;  /* Max len of keystroke  ar30:4  changjei:5 */
78     int M_DUP_SEL; /* how many keys used to select */
79     int DefC;      /* Defined characters */
80     QUICK_KEYS qkeys;
81 
82     union {
83         struct {
84             char endkey[99];
85             char keybits;
86             char selkey2[10];
87         };
88 
89         char dummy[128];  // for future use
90     };
91 };
92 
93 #define KeyBits1(inm) (inm->keybits)
94 #define KeyBits (cur_inmd->keybits)
95 #define MAX_GTAB_KEYS (1 << KeyBits)
96 
97 #define MAX_TAB_KEY_NUM (32 / KeyBits)
98 #define MAX_TAB_KEY_NUM1(inm) (32 / KeyBits1 (inm))
99 #define MAX_TAB_KEY_NUM64 (64 / KeyBits)
100 #define MAX_TAB_KEY_NUM641(inm) (64 / KeyBits1 (inm))
101 
102 struct _HIME_module_callback_functions;
103 typedef u_int gtab_idx1_t;
104 
105 typedef struct {
106     ITEM *tbl;
107     ITEM64 *tbl64;
108     QUICK_KEYS *qkeys;
109     int use_quick;
110     u_int flag;
111 #define MAX_CNAME (4 * CH_SZ + 1)
112     char *cname;
113     char *keycol;
114     int KeyS;              /* number of keys needed */
115     int MaxPress;          /* Max len of keystrike  ar30:5  changjei:5 */
116     int DefChars;          /* defined chars */
117     char *keyname;         // including ?*
118     char *keyname_lookup;  // used by boshiamy only
119     gtab_idx1_t *idx1;
120     char *keymap;
121     char *selkey;
122     u_char *sel1st;
123     int M_DUP_SEL;
124     int phrnum;
125     int *phridx;
126     char *phrbuf;
127     char *filename, *filename_append;
128     time_t file_modify_time;
129     gboolean key64;     // db is 64 bit-long key
130     gboolean disabled;  // will not be display in the selection menu
131     gboolean in_cycle;  ///< whether the input method can be switched with Ctrl-Shift
132     int max_keyN;
133     char *endkey;  // only pinin/ar30 use it
134     GTAB_space_pressed_E space_style;
135     char *icon;
136     u_char kmask, keybits, last_k_bitn, method_type;
137     char WILD_QUES, WILD_STAR;
138     struct _HIME_module_callback_functions *mod_cb_funcs;
139     char key_ch;
140 } INMD;
141 
142 enum {
143     method_type_GTAB = 1,
144     method_type_PHO = 3,
145     method_type_TSIN = 6,
146     method_type_MODULE = 12,
147     method_type_SYMBOL_TABLE = 13,
148     method_type_EN = 14,
149 };
150 
151 extern INMD *inmd;
152 extern int inmdN;
153 
154 u_int64_t CONVT2 (INMD *inmd, int i);
155 extern INMD *cur_inmd;
156 void load_gtab_list (gboolean);
157 char current_method_type ();
158 
159 #define LAST_K_bitN (cur_inmd->last_k_bitn)
160 
161 #define KEY_MASK ((1 << cur_inmd->keybits) - 1);
162 
163 #define GTAB_LIST "gtab.list"
164 
165 #if 1
166 #define NEED_SWAP (__BYTE_ORDER == __BIG_ENDIAN && 0)
167 #else
168 #define NEED_SWAP (1)
169 #endif
170 
171 #define tblch2(inm, i) (inm->key64 ? inm->tbl64[i].ch : inm->tbl[i].ch)
172 #define Max_tab_key_num1(inm) (inm->key64 ? MAX_TAB_KEY_NUM641 (inm) : MAX_TAB_KEY_NUM1 (inm))
173 #define Max_tab_key_num Max_tab_key_num1 (cur_inmd)
174 
175 #endif /* GTAB_H */
176