1 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
4 * Smart Common Input Method
6 * Copyright (c) 2004-2005 James Su <suzhe@tsinghua.org.cn>
7 * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23 * Boston, MA 02111-1307 USA
25 * Modifications by Samsung Electronics Co., Ltd.
26 * 1. Call set_arg_info () before run_helper ()
28 * $Id: scim_helper_launcher.cpp,v 1.6 2005/05/16 01:25:46 suzhe Exp $
32 #define Uses_SCIM_HELPER_MODULE
33 #define Uses_SCIM_GLOBAL_CONFIG
34 #define Uses_SCIM_CONFIG_PATH
36 #include "scim_private.h"
43 static String sanitize_string (const char *str, int maxlen = 32)
46 static char acceptables[] =
47 "abcdefghijklmnopqrstuvwxyz"
48 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
53 newstr = new char[maxlen + 1];
57 memset (newstr, 0x00, sizeof (char) * (maxlen + 1));
60 while (len < maxlen && str[len] != '\0' && strchr (acceptables, str[len]) != NULL) {
61 newstr[len] = str[len];
71 int main (int argc, char *argv [])
79 //bool daemon = false;
81 char *p = getenv ("DISPLAY");
82 if (p) display = String (p);
84 //In the normal situation, config should be set by CMD,
85 //if not provide, we assume have something wrong in
86 //server side, so using simple config as default
87 config = scim_global_config_read (SCIM_GLOBAL_CONFIG_DEFAULT_CONFIG_MODULE, String ("simple"));
90 if (++i >= argc) break;
92 if (String ("-c") == argv [i] ||
93 String ("--config") == argv [i]) {
95 std::cerr << "No argument for option " << argv [i-1] << "\n";
102 if (String ("-d") == argv [i] ||
103 String ("--daemon") == argv [i]) {
108 if (String ("--display") == argv [i]) {
110 std::cerr << "No argument for option " << argv [i-1] << "\n";
117 if (String ("-h") == argv [i] ||
118 String ("--help") == argv [i]) {
119 std::cout << "Usage: " << argv [0] << " [options] module appid\n\n"
120 << "The options are:\n"
121 << " -c, --config name Use specified config module, default is \"simple\".\n"
122 << " -d, --daemon Run as daemon.\n"
123 << " --display name run setup on a specified DISPLAY.\n"
124 << " -h, --help Show this help message.\n"
125 << "module The name of the Helper module\n"
126 << "appid The appid of the Helper to be launched.\n";
130 if (String ("-v") == argv [i] ||
131 String ("--verbose") == argv [i]) {
133 std::cerr << "No argument for option " << argv [i-1] << "\n";
136 DebugOutput::set_verbose_level (atoi (argv [i]));
140 if (String ("-m") == argv [i] ||
141 String ("--mask") == argv [i]) {
143 std::cerr << "No argument for option " << argv [i-1] << "\n";
146 if (String (argv [i]) != "none") {
147 std::vector<String> debug_mask_list;
148 scim_split_string_list (debug_mask_list, argv [i], ',');
149 DebugOutput::disable_debug (SCIM_DEBUG_AllMask);
150 for (size_t k=0; k<debug_mask_list.size (); k++)
151 DebugOutput::enable_debug_by_name (debug_mask_list [k]);
156 if (String ("-o") == argv [i] ||
157 String ("--output") == argv [i]) {
159 std::cerr << "No argument for option " << argv [i-1] << "\n";
162 DebugOutput::set_output (sanitize_string (argv [i]));
169 helper = String (argv [i]);
172 appid = String (argv [i]);
177 String exec = sanitize_string (argv[0]);
179 if (exec != String (SCIM_HELPER_LAUNCHER_PROGRAM)) {
180 /* 3rd party shared object type IME */
181 helper = String ("lib") + exec.substr (exec.find_last_of (SCIM_PATH_DELIM) + 1);
185 SCIM_DEBUG_MAIN(1) << "scim-helper-launcher: " << config << " " << display << " " << helper << " " << appid << "\n";
186 ISF_SAVE_LOG ("Helper ISE (%s %s) is launching...", helper.c_str (), appid.c_str ());
188 if (!helper.length ()) {
189 ISF_SAVE_LOG ("Module name is missing");
191 std::cerr << "Module name is missing.\n";
195 HelperModule helper_module (helper);
197 if (!helper_module.valid () || helper_module.number_of_helpers () == 0) {
198 ISF_SAVE_LOG ("Unable to load helper module(%s)", helper.c_str ());
200 std::cerr << "Unable to load helper module(" << helper << ")\n";
204 ConfigPointer config_pointer = ConfigBase::get (true, config);
206 if (config_pointer.null ()) {
207 config_pointer = new DummyConfig ();
210 // if (daemon) scim_daemon ();
212 helper_module.set_arg_info (argc, argv);
213 helper_module.run_helper (appid, config_pointer, display);
214 helper_module.unload ();
216 if (!config_pointer.null ())
217 config_pointer.reset ();
219 ISF_SAVE_LOG ("Helper ISE (%s) is destroyed!!!", appid.c_str ());
223 vi:ts=4:nowrap:ai:expandtab