1 /*
2   uim-help.c: uim help launcher.
3 
4   Copyright (c) 2003-2013 uim Project https://github.com/uim/uim
5 
6   All rights reserved.
7 
8   Redistribution and use in source and binary forms, with or without
9   modification, are permitted provided that the following conditions
10   are met:
11 
12   1. Redistributions of source code must retain the above copyright
13      notice, this list of conditions and the following disclaimer.
14   2. Redistributions in binary form must reproduce the above copyright
15      notice, this list of conditions and the following disclaimer in the
16      documentation and/or other materials provided with the distribution.
17   3. Neither the name of authors nor the names of its contributors
18      may be used to endorse or promote products derived from this software
19      without specific prior written permission.
20 
21   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
22   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24   ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
25   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31   SUCH DAMAGE.
32 
33 */
34 
35 #include <config.h>
36 #include <stdio.h>
37 #include <string.h>
38 
39 #include "uim.h"
40 #include "uim-scm.h"
41 #include "uim-helper.h"
42 #include "uim-scm-abbrev.h"
43 
44 int uim_fd = -1;
45 
46 static void
uim_help_disconnect_cb(void)47 uim_help_disconnect_cb(void)
48 {
49   uim_fd = -1;
50 }
51 
52 static int
uim_help_get_current_branch(void)53 uim_help_get_current_branch(void)
54 {
55   uim_fd = uim_helper_init_client_fd(uim_help_disconnect_cb);
56   uim_helper_client_get_prop_list();
57 
58   /* TODO: trap signal */
59   uim_scm_callf("uim-help-set-branch!", "o", MAKE_INT(uim_fd));
60 
61   uim_helper_close_client_fd(uim_fd);
62   return 1;
63 }
64 
65 int
main(int argc,char * argv[])66 main(int argc, char *argv[])
67 {
68   uim_lisp args, exit_status_;
69   int exit_status;
70 
71   /* TODO: be able to suppress ordinary initialization process */
72   uim_init();
73 
74   uim_scm_require_file("uim-help.scm");
75 
76   if (!uim_help_get_current_branch())
77     return 1;
78 
79   args = uim_scm_null();
80   exit_status_ = uim_scm_f();
81   uim_scm_gc_protect(&args);
82   uim_scm_gc_protect(&exit_status_);
83 
84   args = uim_scm_array2list((void **)argv, argc,
85 			    (uim_lisp (*)(void *))uim_scm_make_str);
86   exit_status_ = uim_scm_callf("uim-help", "o", args);
87   exit_status  = uim_scm_c_int(exit_status_);
88 
89   uim_quit();
90 
91   return exit_status;
92 }
93