1 /*
2  * Copyright (C) 2020 The HIME team, Taiwan
3  * Copyright (C) 1995-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 HIME_PHO_H
21 #define HIME_PHO_H
22 
23 typedef u_short phokey_t;
24 
25 typedef struct {
26     char selkeyN;
27     struct {
28         char num, typ;
29     } phokbm[128][3];  // for 26 keys pho, it may have up-to 3 pho char for a key
30 } PHOKBM;
31 
32 extern PHOKBM phkbm;
33 
34 typedef struct {
35     char ch[CH_SZ];
36     int count;
37 } PHO_ITEM;
38 
39 typedef struct {
40     phokey_t key;
41     u_short start;
42 } PHO_IDX;
43 
44 typedef struct {
45     char pinyin[7];
46     phokey_t key;
47 } PIN_JUYIN;
48 
49 #define MAX_PHRASE_LEN (32)
50 #define MAX_PHRASE_STR_LEN (MAX_PHRASE_LEN * CH_SZ + 1)
51 
52 #define Min(a, b) ((a) < (b) ? (a) : (b))
53 
54 #define TSIN_HASH_N (256)
55 
56 extern char phofname[128];
57 extern u_short idxnum_pho;
58 extern PHO_IDX *idx_pho;
59 extern int ch_pho_ofs;
60 extern PHO_ITEM *ch_pho;
61 extern int ch_phoN;
62 extern PIN_JUYIN *pin_juyin;
63 extern int pin_juyinN;
64 extern int text_pho_N;
65 
66 void pho_load ();
67 extern char *pho_chars[];
68 char *phokey_to_str (phokey_t kk);
69 int utf8_pho_keys (char *big5, phokey_t *phkeys);
70 void prph (phokey_t kk);
71 void prphs (phokey_t *ks, int ksN);
72 phokey_t pho2key (char typ_pho[]);
73 gboolean save_phrase_to_db (void *phkeys, char *utf8str, int len, usecount_t usecount);
74 int lookup (u_char *s);
75 int find_match (char *str, int *eq_N, usecount_t *usecount);
76 char *phokey_to_str2 (phokey_t kk, int last_number);
77 char *pho_idx_str (int idx);
78 char *pho_idx_str2 (int idx, int *is_phrase);
79 
80 #define MAX_PH_BF (90)
81 
82 #define MAX_PH_BF_EXT (MAX_PH_BF + MAX_PHRASE_LEN + 1)
83 
84 #define TSIN_HASH_SHIFT 6
85 #define TSIN_HASH_SHIFT_32 24
86 #define TSIN_HASH_SHIFT_64 56
87 
88 #define PHO_CHAR_LEN 3
89 
90 #define L_BRACKET_NO 22
91 #define R_BRACKET_NO 23
92 #define BACK_QUOTE_NO 24
93 
94 #define PHO_PHRASE_ESCAPE 0x1b
95 #define PHO_PINYIN_TONE1 -1
96 
97 #endif /* HIME_PHO_H */
98