/* * Smart Common Input Method * * Copyright (c) 2002-2005 James Su * * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * * $Id: scim_config_agent.cpp,v 1.10 2005/07/03 08:36:42 suzhe Exp $ * */ #define Uses_STL_IOSTREAM #define Uses_C_LOCALE #define Uses_SCIM_CONFIG_MODULE #define Uses_SCIM_HELPER #define Uses_SCIM_CONFIG_PATH #include "scim_private.h" #include #include using namespace scim; using std::cout; using std::cerr; using std::endl; enum DataType { DATA_TYPE_STRING, DATA_TYPE_INT, DATA_TYPE_DOUBLE, DATA_TYPE_BOOL, DATA_TYPE_STRING_LIST, DATA_TYPE_INT_LIST }; enum Command { DO_NOTHING, GET_DATA, SET_DATA, DEL_KEY }; static String trim_blank (const String &str) { String::size_type begin, len; begin = str.find_first_not_of (" \t\n\v"); if (begin == String::npos) return String (); len = str.find_last_not_of (" \t\n\v") - begin + 1; return str.substr (begin, len); } static String get_param_portion (const String &str) { String::size_type begin = str.find_first_of (" \t\n\v="); if (begin == String::npos) return str; return str.substr (0, begin); } static String get_value_portion (const String &str) { String::size_type begin = str.find_first_of ("="); if (begin == String::npos || (begin + 1) == str.length ()) return String (""); return trim_blank (str.substr (begin + 1, String::npos)); } int main (int argc, char *argv []) { static ConfigModule config_module; ConfigPointer config; std::vector config_list; String def_config; String key; String value; String display; DataType type = DATA_TYPE_STRING; Command cmd = DO_NOTHING; bool reload = false; bool global = false; int i; char *p = getenv ("DISPLAY"); if (p) display = String (p); //get modules list scim_get_config_module_list (config_list); //Use simple Config module as default if available. if (config_list.size ()) { def_config = scim_global_config_read (SCIM_GLOBAL_CONFIG_DEFAULT_CONFIG_MODULE, String ("simple")); if (std::find (config_list.begin (), config_list.end (), def_config) == config_list.end ()) def_config = config_list [0]; } else { cerr << "No config module found.\n"; return -1; } // parse command options i = 0; while (i= argc) break; if (String ("-h") == argv [i] || String ("--help") == argv [i]) { cout << "Usage: " << argv [0] << "