3
Copyright (c) 2003-2006 uim Project http://uim.freedesktop.org/
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions
11
1. Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
2. Redistributions in binary form must reproduce the above copyright
14
notice, this list of conditions and the following disclaimer in the
15
documentation and/or other materials provided with the distribution.
16
3. Neither the name of authors nor the names of its contributors
17
may be used to endorse or promote products derived from this software
18
without specific prior written permission.
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52
#define MANA_COMMAND "mana"
58
static char *mana_ipc_send_command(int *pid, FILE **read_fp, FILE **write_fp, const char *str);
59
static uim_lisp mana_init(void);
60
static uim_lisp mana_eval(uim_lisp buf_);
61
static uim_lisp eucjp_string_length(uim_lisp str_);
68
mana_ipc_send_command(int *pid,
69
FILE **read_fp, FILE **write_fp,
72
char *tmp = strdup("");
75
struct sigaction act, oact;
77
act.sa_handler = SIG_IGN;
78
sigemptyset(&act.sa_mask);
81
sigaction(SIGPIPE, &act, &oact);
83
fputs(str, *write_fp);
86
if (fflush(*write_fp) != 0) {
92
while (!feof(*read_fp)) {
93
fgets(buf, sizeof(buf), *read_fp);
95
if (strcmp(buf, "err") == 0)
96
fprintf(stderr, "mana not found\n");
98
fprintf(stderr, "%s", buf);
108
sigaction(SIGPIPE, &oact, NULL);
113
sigaction(SIGPIPE, &oact, NULL);
119
sigaction(SIGPIPE, &oact, NULL);
121
if (feof(*read_fp)) {
131
while (fgets (buf, sizeof(buf), *read_fp) != NULL) {
133
tmp = realloc(tmp, strlen(tmp) + strlen(buf) + 1);
136
if (strchr( buf, '\n' )) {
153
mana_pid = uim_ipc_open_command(0, &mana_r, &mana_w, MANA_COMMAND);
159
fl = fcntl(fd, F_GETFL);
160
fcntl(fd, F_SETFL, fl | O_NONBLOCK);
161
fgets(buf, sizeof(buf), mana_r);
162
fcntl(fd, F_SETFL, fl);
168
mana_r = mana_w = NULL;
169
fprintf(stderr, "mana not found\n");
177
log = fopen("mana.log", "w");
184
mana_eval(uim_lisp buf_)
186
const char *buf = uim_scm_refer_c_str(buf_);
194
ret_buf = mana_ipc_send_command(&mana_pid, &mana_r, &mana_w, buf);
205
eval_buf = malloc(strlen("'") + strlen(ret_buf) + 1);
206
sprintf(eval_buf, "'%s", ret_buf);
207
ret = uim_scm_eval_c_string(eval_buf);
215
eucjp_string_length(uim_lisp str_)
217
const unsigned char *str = (const unsigned char *)uim_scm_refer_c_str(str_);
218
int len = strlen((const char *)str);
225
for (i = 0; i < len; i++) {
232
return uim_scm_make_int(ascii + (mbyte / 2));
236
uim_plugin_instance_init(void)
238
uim_scm_init_subr_0("mana-lib-init", mana_init);
239
uim_scm_init_subr_1("mana-lib-eval", mana_eval);
240
uim_scm_init_subr_1("mana-lib-eucjp-string-length", eucjp_string_length);
244
uim_plugin_instance_quit(void)
247
mana_ipc_send_command(&mana_pid, &mana_r, &mana_w, "(quit)\n");