Back to index

im-sdk  12.3.91
main.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 
00043 #ifdef HAVE_CONFIG_H
00044 #include <config.h>
00045 #endif
00046 
00047 #include <strings.h>
00048 #include <locale.h>
00049 #include <stdlib.h>
00050 #include <unistd.h>
00051 #include <X11/Intrinsic.h>
00052 #include <X11/Shell.h>
00053 #ifdef USE_IMP_MANAGER
00054 #include "IMProtocolManager.hh"
00055 #else
00056 #include "XIMProtocol.hh"
00057 #ifdef SUPPORT_R6IM
00058 #include "R6IMProtocol.hh"
00059 #endif
00060 #endif
00061 #include "IMArg.h"
00062 #include "IMProtocol.hh"
00063 #include "IMTriggerKeyList.hh"
00064 
00065 #include "ResourceDB.hh"
00066 
00067 #define SetArg(arg, n, d) ((void)( (arg).id = (n), (arg).value = (char*)(d) ))
00068 
00069 static IMProtocol *ximp = 0;
00070 #ifdef SUPPORT_R6IM
00071 static IMProtocol *r6im = 0;
00072 #endif
00073 
00074 static XrmOptionDescRec rdb_options[] = {
00075    {(char*)"-if",    (char*)"*engineModule",     XrmoptionSepArg, 0},
00076    {(char*)"-port",  (char*)"*portNumber",              XrmoptionSepArg, 0},
00077    {(char*)"-ximp40",       (char*)"*ximp40",           XrmoptionNoArg, (XPointer)"true"},
00078    {(char*)"-iiimp", (char*)"*iiimp",            XrmoptionNoArg, (XPointer)"true"},
00079    {(char*)"-fs",    (char*)"*fontSet",          XrmoptionSepArg, NULL},
00080    {(char*)"-lucbg", (char*)"*lookupBackground", XrmoptionSepArg, NULL},
00081    {(char*)"-staticEventFlow",     (char*)"*staticEventFlow", XrmoptionNoArg, (XPointer)"true"},
00082    {(char*)"-noProps", (char*)"*HttProps",              XrmoptionNoArg, (XPointer)"false"}
00083    /* -noProps option is only used for debugging purpose,
00084       and must not be a public interface. */
00085 };
00086 
00087 static char *
00088 check_locale(int argc, char *argv[]) {
00089   int i;
00090 
00091   for (i = 1; i < argc; i++) {
00092     if(!strcmp(argv[i], "-lc_basiclocale"))
00093       return (argv[i+1]);
00094   }
00095   return (char *)"";
00096 }
00097 
00098 #if 0
00099 static int
00100 check_xsunim(int argc, char *argv[]) {
00101   int i;
00102 
00103   for (i = 1; i < argc; i++) {
00104     if(!strcmp(argv[i], "-use_xsunim"))
00105       return True;
00106   }
00107   return False;
00108 }
00109 #endif
00110 
00111 void
00112 initialize(int argc, char *argv[]) { 
00113   XtAppContext app = (XtAppContext)0;
00114   const char *class_name = "Iiimx";
00115   const char *app_name = "iiimx";
00116 
00117 #ifdef USE_IMP_MANAGER
00118   ximp = IMProtocolManager::getInstance(IMProtocolManager::XIMP40);
00119 #else
00120   ximp = new XIMProtocol(0, 0);
00121 #endif
00122   if (!ximp) exit(1);
00123 
00124 #ifdef SUPPORT_R6IM
00125 #ifdef USE_IMP_MANAGER
00126   r6im = IMProtocolManager::getInstance(IMProtocolManager::R6IMP);
00127 #else
00128   r6im = new R6IMProtocol(0, 0);
00129 #endif
00130 #endif
00131 
00132   // just workaround
00133 #ifndef linux
00134   XInitThreads();
00135 #endif
00136 
00137   setlocale(LC_ALL, check_locale(argc, argv));
00138   char *primary_locale = strdup(setlocale(LC_CTYPE, (char*)0));
00139   // strip modifier
00140   char *p = strchr(primary_locale, '@');
00141   if (p) *p = '\0';
00142   // strip encoding
00143   p = strchr(primary_locale, '.');
00144   if (p) *p = '\0';
00145   // strip territory. can we ?
00146   // p = strchr(primary_locale, '_');
00147   // if (p) *p = '\0';
00148 
00149   XSetLocaleModifiers("");
00150 
00151   Widget toplevel = XtOpenApplication(&app, class_name,
00152                                   rdb_options,
00153                                   XtNumber(rdb_options),
00154                                   &argc, argv,
00155                                   0, // fallback resources
00156                                   applicationShellWidgetClass,
00157                                   0, 0); // args and num_args
00158   int n;
00159 
00160   ResourceDB *resource = new ResourceDB(toplevel);
00161 
00162   char *trigger_keys = 0;
00163   IMTriggerKeyList key_list;
00164   Bool disable_status_area;
00165   Bool static_event_flow;
00166 
00167   char *if_name = 0;
00168 
00169   char *font_name = 0;
00170   n = 0;
00171   IMArg res[5];
00172   SetArg(res[n], ResourceDB::RDB_CONV_ON_KEY, &trigger_keys); n++;
00173   SetArg(res[n], ResourceDB::RDB_IF_NAME, &if_name); n++;
00174   SetArg(res[n], ResourceDB::RDB_FS_NAME, &font_name); n++;
00175   SetArg(res[n], ResourceDB::RDB_DISABLE_STATUS_AREA, &disable_status_area); n++;
00176   SetArg(res[n], ResourceDB::RDB_STATIC_EVENT_FLOW, &static_event_flow); n++;
00177   resource->getValues(res, n);
00178 
00179   if (trigger_keys) {
00180     if (!static_event_flow) {
00181       key_list.add(trigger_keys);
00182     }
00183     XtFree(trigger_keys);
00184   }
00185 
00186   // for XIMP initialization
00187   n = 0;
00188   IMArg args[15];
00189   SetArg(args[n], IMProtocol::ServerName, app_name); n++;
00190   SetArg(args[n], IMProtocol::VendorName, "Sun"); n++;
00191   SetArg(args[n], IMProtocol::PrimaryInputLocale, primary_locale); n++;
00192   SetArg(args[n], IMProtocol::ConversionOnKeys, &key_list); n++;
00193   SetArg(args[n], IMProtocol::DisplayConnection, XtDisplay(toplevel)); n++;
00194   if (if_name && if_name[0]) {
00195     SetArg(args[n], IMProtocol::IFName, if_name); n++;
00196   }
00197   if (font_name && font_name[0]) {
00198     SetArg(args[n], IMProtocol::DefaultFontName, font_name); n++;
00199   }
00200   SetArg(args[n], IMProtocol::AppName, "IIIMX XIM Server"); n++;
00201   SetArg(args[n], IMProtocol::DisableStatusArea, disable_status_area); n++;
00202 
00203   ximp->set_values(args, n);
00204 
00205 #ifdef SUPPORT_R6IM
00206   // for X11R6 IMP initialization
00207   n = 0;
00208   Display *display2 = XOpenDisplay("");   // must be different from XIMP
00209   SetArg(args[n], IMProtocol::ServerName, app_name); n++;
00210   SetArg(args[n], IMProtocol::VendorName, "Sun"); n++;
00211   SetArg(args[n], IMProtocol::PrimaryInputLocale, primary_locale); n++;
00212   SetArg(args[n], IMProtocol::ConversionOnKeys, &key_list); n++;
00213   SetArg(args[n], IMProtocol::DisplayConnection, display2); n++;
00214   if (if_name && if_name[0]) {
00215     SetArg(args[n], IMProtocol::IFName, if_name); n++;
00216   }
00217   if (font_name && font_name[0]) {
00218     SetArg(args[n], IMProtocol::DefaultFontName, font_name); n++;
00219   }
00220   SetArg(args[n], IMProtocol::AppName, "IIIMX XIM Server"); n++;
00221   SetArg(args[n], IMProtocol::DisableStatusArea, disable_status_area); n++;
00222 
00223   const char *transport = "X/"; // use X
00224   SetArg(args[n], IMProtocol::TransportAddress, transport); n++;
00225   r6im->set_values(args, n);
00226 #endif
00227 
00228   return;
00229 }
00230 
00231 void
00232 run() {
00233 #ifndef linux
00234   ximp->run();
00235 #endif
00236 #ifdef SUPPORT_R6IM
00237   r6im->run();
00238 #endif
00239 }
00240 
00241 int
00242 main(int argc, char *argv[]) {
00243   initialize(argc, argv);
00244   run();
00245   while(1) {
00246     sleep(10000000);
00247   }
00248   return 0;
00249 }