1 /*  esecannaserver --- pseudo canna server that wraps another IME.
2  *  Copyright (C) 1999-2000 Yasuhiro Take
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 
19 #ifndef __misc_h__
20 #define __misc_h__
21 
22 #ifndef TRUE
23 
24 #define TRUE 1
25 #define FALSE 0
26 
27 #endif
28 
29 typedef struct {
30   size_t size;
31   char *buf;
32 } buffer_t;
33 
34 #ifndef __uchar_t__
35 #define __uchar_t__
36 typedef unsigned char uchar;
37 #endif
38 
39 #define ISSJISKANJI1(_c) ((((_c) & 0xff) >= 0x81 && ((_c) & 0xff) <= 0x9f) || \
40 			  (((_c) & 0xff) >= 0xe0 && ((_c) & 0xff) <= 0xfc))
41 
42 #define ISSJISKANA(_c) (((_c) & 0xff) >= 0xa0 && ((_c) & 0xff) <= 0xdf)
43 
44 
45 #define ISSJIS_ZENKAKU_HIRAGANA(_c1,_c2) (((_c1) & 0xff) == 0x82 && \
46 					  ((_c2) & 0xff) >= 0x9f && \
47 					  ((_c2) & 0xff) <= 0xf1)
48 
49 #define ISSJIS_ZENKAKU_KATAKANA(_c1,_c2) (((_c1) & 0xff) == 0x83 && \
50 					  ((_c2) & 0xff) >= 0x40 && \
51 					  ((_c2) & 0xff) <= 0x94)
52 
53 #define ISSJIS_ZENKAKU_VU(_c1,_c2) (((_c1) & 0xff) == 0x83 && \
54 				    ((_c2) & 0xff) == 0x94)
55 
56 #define MYFREE(_p) {if(_p) {free(_p); _p=NULL;} }
57 
58 
59 typedef void (*signalhandler_t)(int);
60 
61 int m_daemonize(char *pid_path);
62 
63 #ifndef __misc_c__
64 extern int m_message_level;
65 #endif
66 
67 #define MSG_DEBUG 0
68 #define MSG_NOTICE 1
69 
70 int m_message_init(char *logfilepath);
71 int m_message_term();
72 int m_message_debug(const char *fmt, ...);
73 int m_message_notice(const char *fmt, ...);
74 
75 #define m_msg_dbg m_message_debug
76 #define m_msg m_message_notice
77 
78 int buffer_free(buffer_t *b);
79 int buffer_check(buffer_t *b, size_t required_size);
80 int buffer_clear(buffer_t *b);
81 
82 void *m_memdup(void *src, size_t n);
83 
84 char *m_makepath(char *dir, char *file);
85 int m_splitpath(char *path, char **dir, char **file);
86 
87 char *m_netaddr2ascii(uint netaddr, char *ascii);
88 
89 int m_socket_read(int fd, char *ptr, int totalsize);
90 int m_socket_write(int fd, char *ptr, int totalsize);
91 
92 int m_count_canna_mode(int mode);
93 int m_get_canna_mode(int mode, int n);
94 int m_count_valid_canna_mode(int mode);
95 
96 int cannawc2euc(ushort *src, int srclen, char *dest, int destlen);
97 int euc2cannawc(char *src, int srclen, ushort *dest, int destlen);
98 int cannawcstrlen(ushort *ws);
99 int euc2sjis(uchar *euc, int euclen, uchar *sjis, int sjislen);
100 int sjis2euc(uchar *sjis, int sjislen, uchar *euc, int euclen);
101 
102 int m_replace_string(uchar *eucbuf, char *pre, char *post);
103 int m_convert_zen2han(uchar *sjisbuf);
104 int m_convert_hankana2zenkana(uchar *euc, int len);
105 int m_convert_zenkana2zenhira(uchar *src, uchar *dst, int len);
106 int m_convert_zenhira2zenkata(uchar *euc_hira, int slen, uchar *euc_kata);
107 
108 int m_setup_signal(signalhandler_t handler);
109 int m_copy_file(char *from, char *to);
110 int m_copy_file_fp(FILE *from, FILE *to);
111 
112 int m_exist_hankata(uchar *euc);
113 int m_is_zenkata_string(uchar *euc);
114 int m_is_hiragana_string(uchar *euc);
115 
116 int m_reconvroma(uchar *src, uchar *dst);
117 
118 /* system() */
119 
120 int m_system_clear();
121 int m_system_register_file(int fd);
122 int m_system(char *command);
123 
124 /* ����ե������ɤ߹��ߴؿ� */
125 
126 int m_conf1_parse(char *line, char **ope_r, char **val_r);
127 int m_conf_string(char *ope, char *opestr, char *val, char **val_r);
128 int m_conf_multiple_choice(char *ope, char *opestr, char *val, char **choice,
129 			   int choice_n, int case_sensitive);
130 int m_conf_tof(char *ope, char *opestr, char *val, char *str1, char *str2,
131 	       int case_sensitive);
132 int m_conf_isequal(char *ope, char *opestr, char *val, char *valstr);
133 
134 #define M_CONF_YESNO(_ope,_opestr,_val) m_conf_tof((_ope),(_opestr),(_val), \
135 						   "NO","YES",TRUE)
136 
137 #define M_CONF_IYESNO(_ope,_opestr,_val) m_conf_tof((_ope),(_opestr),(_val), \
138 						    "NO","YES",FALSE)
139 
140 #define M_CONF_ONOFF(_ope,_opestr,_val) m_conf_tof((_ope),(_opestr),(_val), \
141 						   "OFF","ON",TRUE)
142 
143 #define M_CONF_IONOFF(_ope,_opestr,_val) m_conf_tof((_ope),(_opestr),(_val), \
144 						    "OFF","ON",FALSE)
145 
146 #define M_CONF_TORF(_ope,_opestr,_val) m_conf_tof((_ope),(_opestr),(_val), \
147 						  "FALSE", "ON", TRUE)
148 
149 #define M_CONF_ITORF(_ope,_opestr,_val) m_conf_tof((_ope),(_opestr),(_val), \
150 						   "FALSE", "TRUE", FALSE)
151 
152 
153 
154 
155 
156 
157 #endif
158