Back to index

im-sdk  12.3.91
unit_input.c
Go to the documentation of this file.
00001 /*
00002   Copyright 2002-2003 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 <stdio.h>
00048 #ifdef HAVE_STDLIB_H
00049 #include <stdlib.h>
00050 #endif
00051 #ifdef HAVE_STRING_H
00052 #include <string.h>
00053 #endif
00054 #ifdef HAVE_SYS_STAT_H
00055 #include <sys/stat.h>
00056 #endif
00057 #ifdef HAVE_DLFCN_H
00058 #include <dlfcn.h>
00059 #endif
00060 #include <limits.h>
00061 #include <ctype.h>
00062 #include <sys/errno.h>
00063 extern int errno;
00064 
00065 #include "unit_input.h"
00066 #include "xaux_locale.h"
00067 #include "encode.h"
00068 #include "logf.h"
00069 
00070 #define COMMENT '#'
00071 
00072 extern char lename_string[];
00073 extern UTFCHAR lename_utf_string[];
00074 IMLEName leName = {lename_string, lename_utf_string };
00075 IMLocale loc[MAX_SUPPORTED_LOCALES];
00076 int numLocales = 0;
00077 
00078 extern int CpyUTFCHAR(char *, UTFCHAR *);
00079 
00080 keyvalue_pair kvp[] = {
00081        {(char *)"IM_SHIFT_MASK", 1},
00082        {(char *)"IM_CTRL_MASK", 2},
00083        {(char *)"IM_META_MASK", 4},
00084        {(char *)"IM_ALT_MASK", 8},
00085        {(char *)"IM_ALT_GRAPH_MASK", 32},
00086        {(char *)"IM_BUTTON1_MASK", 16},
00087        {(char *)"IM_VK_CANCEL",    3},
00088        {(char *)"IM_VK_CLEAR",     12},
00089        {(char *)"IM_VK_SHIFT",     16},
00090        {(char *)"IM_VK_CONTROL",   17},
00091        {(char *)"IM_VK_ALT",       18},
00092        {(char *)"IM_VK_PAUSE",     19},
00093        {(char *)"IM_VK_CAPS_LOCK",        20},
00094        {(char *)"IM_VK_ESCAPE",    27},
00095        {(char *)"IM_VK_SPACE",     32},
00096        {(char *)"IM_VK_PAGE_UP",   33},
00097        {(char *)"IM_VK_PAGE_DOWN",        34},
00098        {(char *)"IM_VK_END",       35},
00099        {(char *)"IM_VK_HOME",      36},
00100        {(char *)"IM_VK_LEFT",      37},
00101        {(char *)"IM_VK_UP",        38},
00102        {(char *)"IM_VK_RIGHT",     39},
00103        {(char *)"IM_VK_DOWN",      40},
00104        {(char *)"IM_VK_COMMA",     44},
00105        {(char *)"IM_VK_MINUS",     45},
00106        {(char *)"IM_VK_PERIOD",    46},
00107        {(char *)"IM_VK_SLASH",     47},
00108        {(char *)"IM_VK_0",  48},
00109        {(char *)"IM_VK_1",  49},
00110        {(char *)"IM_VK_2",  50},
00111        {(char *)"IM_VK_3",  51},
00112        {(char *)"IM_VK_4",  52},
00113        {(char *)"IM_VK_5",  53},
00114        {(char *)"IM_VK_6",  54},
00115        {(char *)"IM_VK_7",  55},
00116        {(char *)"IM_VK_8",  56},
00117        {(char *)"IM_VK_9",  57},
00118        {(char *)"IM_VK_SEMICOLON",        59},
00119        {(char *)"IM_VK_EQUALS",    61},
00120        {(char *)"IM_VK_A",  65},
00121        {(char *)"IM_VK_B",  66},
00122        {(char *)"IM_VK_C",  67},
00123        {(char *)"IM_VK_D",  68},
00124        {(char *)"IM_VK_E",  69},
00125        {(char *)"IM_VK_F",  70},
00126        {(char *)"IM_VK_G",  71},
00127        {(char *)"IM_VK_H",  72},
00128        {(char *)"IM_VK_I",  73},
00129        {(char *)"IM_VK_J",  74},
00130        {(char *)"IM_VK_K",  75},
00131        {(char *)"IM_VK_L",  76},
00132        {(char *)"IM_VK_M",  77},
00133        {(char *)"IM_VK_N",  78},
00134        {(char *)"IM_VK_O",  79},
00135        {(char *)"IM_VK_P",  80},
00136        {(char *)"IM_VK_Q",  81},
00137        {(char *)"IM_VK_R",  82},
00138        {(char *)"IM_VK_S",  83},
00139        {(char *)"IM_VK_T",  84},
00140        {(char *)"IM_VK_U",  85},
00141        {(char *)"IM_VK_V",  86},
00142        {(char *)"IM_VK_W",  87},
00143        {(char *)"IM_VK_X",  88},
00144        {(char *)"IM_VK_Y",  89},
00145        {(char *)"IM_VK_Z",  90},
00146        {(char *)"IM_VK_OPEN_BRACKET",     91},
00147        {(char *)"IM_VK_BACK_SLASH",       92},
00148        {(char *)"IM_VK_CLOSE_BRACKET",    93},
00149        {(char *)"IM_VK_NUMPAD0",   96},
00150        {(char *)"IM_VK_NUMPAD1",   97},
00151        {(char *)"IM_VK_NUMPAD2",   98},
00152        {(char *)"IM_VK_NUMPAD3",   99},
00153        {(char *)"IM_VK_NUMPAD4",   100},
00154        {(char *)"IM_VK_NUMPAD5",   101},
00155        {(char *)"IM_VK_NUMPAD6",   102},
00156        {(char *)"IM_VK_NUMPAD7",   103},
00157        {(char *)"IM_VK_NUMPAD8",   104},
00158        {(char *)"IM_VK_NUMPAD9",   105},
00159        {(char *)"IM_VK_MULTIPLY",  106},
00160        {(char *)"IM_VK_ADD",       107},
00161        {(char *)"IM_VK_SEPARATER",        108},
00162        {(char *)"IM_VK_SUBTRACT",  109},
00163        {(char *)"IM_VK_DECIMAL",   110},
00164        {(char *)"IM_VK_DIVIDE",    111},
00165        {(char *)"IM_VK_DELETE",    127},
00166        {(char *)"IM_VK_NUM_LOCK",  144},
00167        {(char *)"IM_VK_SCROLL_LOCK",      145},
00168        {(char *)"IM_VK_F1",        112},
00169        {(char *)"IM_VK_F2",        113},
00170        {(char *)"IM_VK_F3",        114},
00171        {(char *)"IM_VK_F4",        115},
00172        {(char *)"IM_VK_F5",        116},
00173        {(char *)"IM_VK_F6",        117},
00174        {(char *)"IM_VK_F7",        118},
00175        {(char *)"IM_VK_F8",        119},
00176        {(char *)"IM_VK_F9",        120},
00177        {(char *)"IM_VK_F10",       121},
00178        {(char *)"IM_VK_F11",       122},
00179        {(char *)"IM_VK_F12",       123},
00180        {(char *)"IM_VK_F13",       61440},
00181        {(char *)"IM_VK_F14",       61441},
00182        {(char *)"IM_VK_F15",       61442},
00183        {(char *)"IM_VK_F16",       61443},
00184        {(char *)"IM_VK_F17",       61444},
00185        {(char *)"IM_VK_F18",       61445},
00186        {(char *)"IM_VK_F19",       61446},
00187        {(char *)"IM_VK_F20",       61447},
00188        {(char *)"IM_VK_F21",       61448},
00189        {(char *)"IM_VK_F22",       61449},
00190        {(char *)"IM_VK_F23",       61450},
00191        {(char *)"IM_VK_F24",       61451},
00192        {(char *)"IM_VK_PRINTSCREEN",      154},
00193        {(char *)"IM_VK_INSERT",    155},
00194        {(char *)"IM_VK_HELP",      156},
00195        {(char *)"IM_VK_META",      157},
00196        {(char *)"IM_VK_BACK_QUOTE",       192},
00197        {(char *)"IM_VK_QUOTE",     222},
00198        {(char *)"IM_VK_KP_UP",     224},
00199        {(char *)"IM_VK_KP_DOWN",   225},
00200        {(char *)"IM_VK_KP_LEFT",   226},
00201        {(char *)"IM_VK_KP_RIGHT",  227},
00202        {(char *)"IM_VK_DEAD_GRAVE",       128},
00203        {(char *)"IM_VK_DEAD_ACUTE",       129},
00204        {(char *)"IM_VK_DEAD_CIRCUMFLEX",  130},
00205        {(char *)"IM_VK_DEAD_TILDE",       131},
00206        {(char *)"IM_VK_DEAD_MACRON",      132},
00207        {(char *)"IM_VK_DEAD_BREVE",       133},
00208        {(char *)"IM_VK_DEAD_ABOVEDOT",    134},
00209        {(char *)"IM_VK_DEAD_DIAERESIS",   135},
00210        {(char *)"IM_VK_DEAD_ABOVERING",   136},
00211        {(char *)"IM_VK_DEAD_DOUBLEACUTE",        137},
00212        {(char *)"IM_VK_DEAD_CARON",       138},
00213        {(char *)"IM_VK_DEAD_CEDILLA",     139},
00214        {(char *)"IM_VK_DEAD_OGONEK",      140},
00215        {(char *)"IM_VK_DEAD_IOTA",        141},
00216        {(char *)"IM_VK_DEAD_VOICED_SOUND",       142},
00217        {(char *)"IM_VK_DEAD_SEMIVOICED_SOUND",   143},
00218        {(char *)"IM_VK_AMPERSAND",        150},
00219        {(char *)"IM_VK_ASTERISK",  151},
00220        {(char *)"IM_VK_QUOTEDBL",  152},
00221        {(char *)"IM_VK_LESS",      153},
00222        {(char *)"IM_VK_GREATER",   160},
00223        {(char *)"IM_VK_BRACELEFT",        161},
00224        {(char *)"IM_VK_BRACERIGHT",       162},
00225        {(char *)"IM_VK_AT",        512},
00226        {(char *)"IM_VK_COLON",     513},
00227        {(char *)"IM_VK_CIRCUMFLEX",       514},
00228        {(char *)"IM_VK_DOLLAR",    515},
00229        {(char *)"IM_VK_EURO_SIGN",        516},
00230        {(char *)"IM_VK_EXCLAMATION_MARK",        517},
00231        {(char *)"IM_VK_INVERTED_EXCLAMATION_MARK",      518},
00232        {(char *)"IM_VK_LEFT_PARENTHESIS",        519},
00233        {(char *)"IM_VK_NUMBER_SIGN",      520},
00234        {(char *)"IM_VK_PLUS",      521},
00235        {(char *)"IM_VK_RIGHT_PARENTHESIS",       522},
00236        {(char *)"IM_VK_UNDERSCORE",       523},
00237        {(char *)"IM_VK_FINAL",     24},
00238        {(char *)"IM_VK_CONVERT",   28},
00239        {(char *)"IM_VK_NONCONVERT",       29},
00240        {(char *)"IM_VK_ACCEPT",    30},
00241        {(char *)"IM_VK_MODECHANGE",       31},
00242        {(char *)"IM_VK_KANA",      21},
00243        {(char *)"IM_VK_KANJI",     25},
00244        {(char *)"IM_VK_ALPHANUMERIC",     240},
00245        {(char *)"IM_VK_KATAKANA",  241},
00246        {(char *)"IM_VK_HIRAGANA",  242},
00247        {(char *)"IM_VK_FULL_WIDTH",       243},
00248        {(char *)"IM_VK_HALF_WIDTH",       244},
00249        {(char *)"IM_VK_ROMAN_CHARACTERS",        245},
00250        {(char *)"IM_VK_ALL_CANDIDATES",   256},
00251        {(char *)"IM_VK_PREVIOUS_CANDIDATE",      257},
00252        {(char *)"IM_VK_CODE_INPUT",       258},
00253        {(char *)"IM_VK_JAPANESE_KATAKANA",       259},
00254        {(char *)"IM_VK_JAPANESE_HIRAGANA",       260},
00255        {(char *)"IM_VK_JAPANESE_ROMAN",   261},
00256        {(char *)"IM_VK_CUT",       65489},
00257        {(char *)"IM_VK_COPY",      65485},
00258        {(char *)"IM_VK_PASTE",     65487},
00259        {(char *)"IM_VK_UNDO",      65483},
00260        {(char *)"IM_VK_AGAIN",     65481},
00261        {(char *)"IM_VK_FIND",      65488},
00262        {(char *)"IM_VK_PROPS",     65482},
00263        {(char *)"IM_VK_STOP",      65480},
00264        {(char *)"IM_VK_COMPOSE",   65312},
00265        {(char *)"IM_VK_ALT_GRAPH",        65406},
00266        {(char *)"IM_VK_UNDEFINED",        0},
00267        {0, 0}
00268 };
00269 
00270 /* 
00271    read profile from file "sysime.cfg" to memory buffer   
00272    the struct of sysime.cfg is as follow:
00273 
00274    # comments
00275    # engine_options can be the path of the dictionary or options that
00276    # the engine can recognize.
00277    [ GENERIC_IM_TABLE ]
00278 
00279    [ locale_name ]
00280    engine_name              engine_path     engine_options default_conv_mode
00281 
00282    for example:
00283    [ HINDI ]  
00284    trans      common/ctim.so 
00285    iscii common/ctim.so 
00286 
00287    [ TAMIL ]  
00288    trans      common/ctim.so 
00289    iscii common/ctim.so 
00290 
00291 */ 
00292 
00293 int unit_ns_read_config(unit_desktop_t *, char *, int);
00294 int unit_ns_callback(int, int, char *, void *);
00295 int get_line(char *buf, int size, char **curptr, char *line);
00296 int set_keyvalues(unit_desktop_t *udp, char *buf, char *Lname);
00297 int open_engine(unit_desktop_t *udp, int locale_id, char *locale_name, 
00298               char *engine_name, char *engine_path, char *engine_options, char *cflag);
00299 
00300 void  
00301 getNEngineIds(unit_desktop_t *udp){
00302     int i,j;
00303     int sflag,eflag;
00304 
00305     for(i=0; i<udp->locale_Num; i++){
00306        sflag=0;
00307        eflag=0;
00308        for(j=0; j<udp->gEngine_Num; j++) {
00309            if(!strcmp(udp->localeList[i].locale_name, udp->modeList[j]->locale_name)){
00310               if(!sflag){
00311                   udp->localeList[i].firstEngineId = udp->modeList[j]->engine_id;
00312                   sflag=1;
00313               }
00314               udp->localeList[i].nEngineId++;
00315               if((i == (udp->locale_Num - 1)) && (j == (udp->gEngine_Num -1)))
00316                   udp->localeList[i].lastEngineId = udp->modeList[j]->engine_id;
00317            }else{
00318               if(sflag && !eflag){
00319                   udp->localeList[i].lastEngineId = udp->modeList[j-1]->engine_id;
00320                   eflag=1;
00321               }
00322            }
00323        }
00324     }
00325 
00326     for(i=0; i<udp->locale_Num; i++)
00327        log_f("getNEngineIds: locale_name [%s], start [%d], last [%d], nEngineIds [%d]\n",udp->localeList[i].locale_name, udp->localeList[i].firstEngineId, udp->localeList[i].lastEngineId, udp->localeList[i].nEngineId);
00328 }
00329 
00330 void  
00331 print_core(unit_desktop_t *udp)
00332 {
00333     int i;
00334 
00335     log_f("gEngine_Num:%d\n", udp->gEngine_Num);
00336     for (i=0; i<udp->gEngine_Num; i++) {
00337        log_f("localeid:%d, imid:%d, ename:%s, lname: %s, cname:%s, status:%d\n", 
00338              udp->gEngine_Info[i]->core.baseinfo.locale_id,
00339              udp->gEngine_Info[i]->core.baseinfo.engine_id,
00340              udp->gEngine_Info[i]->core.baseinfo.ename,
00341              udp->gEngine_Info[i]->core.baseinfo.lname,
00342              udp->gEngine_Info[i]->core.baseinfo.cname,
00343              udp->gEngine_Info[i]->core.baseinfo.status);
00344     }
00345     for (i=0; i<udp->gEngine_Num; i++) {
00346        log_f("print_core: locale_name [%s], engine_name [%s], engine_id [%d], default_state [%s] \n",udp->modeList[i]->locale_name, udp->modeList[i]->engine_name, udp->modeList[i]->engine_id, udp->modeList[i]->default_state);
00347        log_f("print_core: nlocale_name [%s], nlayout_name [%s]\n",udp->modeList[i]->nlocale_name, udp->modeList[i]->nlayout_name);
00348     }
00349     log_f("print_core: udp->nextLocaleKeycode [%d] \n",udp->nextLocaleKeycode);
00350     log_f("print_core: udp->nextLocaleModifier [%d] \n",udp->nextLocaleModifier);
00351     log_f("print_core: udp->prevLocaleKeycode [%d] \n",udp->prevLocaleKeycode);
00352     log_f("print_core: udp->prevLocaleModifier [%d] \n",udp->prevLocaleModifier);
00353     log_f("print_core: udp->layoutNameKeyCode [%d] \n",udp->layoutNameKeyCode);
00354     log_f("print_core: udp->layoutNameModifier [%d] \n",udp->layoutNameModifier);
00355 }
00356 
00357 void 
00358 unit_desktop_init(unit_desktop_t *udp) {
00359     int i;
00360 
00361     if (udp->gEngine_Num > 0)
00362        return;
00363 
00364     udp->gEngine_Num = 0;
00365     udp->locale_Num = 0;
00366     udp->nextLocaleKeycode = 0;
00367     udp->nextLocaleModifier = 0;
00368     udp->prevLocaleKeycode = 0;
00369     udp->prevLocaleModifier = 0;
00370     udp->layoutNameKeyCode = 0;
00371     udp->layoutNameModifier = 0;
00372     udp->curr_hotkey_profile_id = -1;
00373     udp->localeList = (LocaleList *)NULL;
00374     for (i=0; i<MAX_ENGINE_NUM; i++)
00375        udp->gEngine_Info[i] = NULL;
00376 
00377     return;
00378 }
00379 
00380 int 
00381 unit_ns_callback(
00382     int listener_id,
00383     int fsize, 
00384     char *buf, 
00385     void *calldata
00386 )
00387 {
00388     char file_name[PATH_MAX];
00389     FILE *fp;
00390     int fd, size, nfread;
00391     struct stat stat_buf;
00392     char *file_buf;
00393     iml_nsl *nsl = (iml_nsl *) calldata;
00394     unit_desktop_t *udp = nsl->calldata;
00395 
00396     if (!fsize) {
00397        log_f("Namespace not defined, read from default location \n");
00398        snprintf(file_name, sizeof(file_name), "%s/%s/%s",  DEFAULT_ENGINE_PATH, XAUX_LOCALE_NAME, SYSTEM_PROFILE_NAME);
00399        log_f("file name :%s\n",file_name);
00400        fp = fopen(file_name, "r");
00401        if (! fp)
00402            return (-1);
00403        fd = fileno((FILE *)fp);
00404        if (fstat(fd, &stat_buf) < 0) {
00405            return -1;
00406        }
00407        size = stat_buf.st_size;
00408        log_f("size [%d]\n",size);
00409        file_buf = (char *)calloc(size, sizeof(char));
00410        nfread = fread(file_buf, size, 1, fp);
00411        log_f("nfread [%d]\n",nfread);
00412        unit_ns_read_config(udp, file_buf, size);
00413         return 0;
00414     }
00415     unit_ns_read_config(udp, buf, fsize);
00416     return 0;
00417 }
00418     
00419 int
00420 unit_ns_read_config(
00421     unit_desktop_t *udp,
00422     char *buf,
00423     int fsize
00424 )
00425 {
00426     char          line[MAX_LINE_LEN];
00427     char          keyCodeName[NAME_MAX], modifierName[NAME_MAX];
00428     char          locale_name[NAME_MAX], *kptr, *ptr;
00429     char          *engine_name, *engine_path, *engine_options, *conv_flag;
00430     int           len;
00431     int           locale_flag = ENCODE_ERROR;
00432     int           generic_flag = 0;
00433     int           switch_to_next_locale_flag = 0;
00434     int           switch_to_prev_locale_flag = 0;
00435     int           switch_layout_flag = 0;
00436     char          *curr_ptr;
00437 
00438     memset((char *)keyCodeName,'\0',sizeof(keyCodeName));
00439     memset((char *)modifierName,'\0',sizeof(modifierName));
00440 
00441     numLocales = 0;
00442     curr_ptr = 0;
00443     do {
00444         len = get_line(buf, fsize, &curr_ptr, line);
00445 
00446         if (!len) break;
00447         if (len < 0) continue;
00448 
00449         if (line[0] == '[' && line[len-1] == ']') {
00450             /* compute locale_flag */
00451             ptr = line + 1;
00452             while(isspace(*ptr)) ptr++;
00453 
00454             memset((char *)locale_name,'\0',sizeof(locale_name));
00455             /* get locale section name */
00456             kptr = locale_name;
00457             while (*ptr && !isspace(*ptr) && *ptr!=']')
00458                 *(kptr++) = *(ptr++);
00459             *kptr = '\0';
00460 
00461             /* get locale section name */
00462             if (!strcasecmp(locale_name, COMMON_ENGINE_PATH))
00463                 locale_flag = ENCODES_NUM;
00464             else if(!strcasecmp(locale_name, GENERIC_IM_TABLE_NAME)){
00465                 generic_flag = 1;
00466                 continue;
00467             }else if(!strcasecmp(locale_name, SWITCH_TO_NEXT_LOCALE)){
00468                 switch_to_next_locale_flag = 1;
00469                 continue;
00470             }else if(!strcasecmp(locale_name, SWITCH_TO_PREV_LOCALE)){
00471                 switch_to_prev_locale_flag = 1;
00472                 continue;
00473             }else if(!strcasecmp(locale_name, SWITCH_LAYOUT_NAME)){
00474                 switch_layout_flag = 1;
00475                 continue;
00476             }else {
00477                 if(!switch_to_next_locale_flag && (udp->nextLocaleKeycode == 0 && udp->nextLocaleModifier == 0)){
00478                     udp->nextLocaleKeycode = IM_VK_F5;
00479                     udp->nextLocaleModifier = 0;
00480                     continue;
00481                 } else if(!switch_to_prev_locale_flag && (udp->prevLocaleKeycode == 0 && udp->prevLocaleModifier == 0)){
00482                     udp->prevLocaleKeycode = IM_VK_F7;
00483                     udp->prevLocaleModifier = 0;
00484                     continue;
00485                 }else if(!switch_layout_flag && (udp->layoutNameKeyCode == 0 && udp->layoutNameModifier == 0)){
00486                     udp->layoutNameKeyCode = IM_VK_F6;
00487                     udp->layoutNameModifier = 0;
00488                     continue;
00489                 }
00490             }
00491 
00492             if(!generic_flag)
00493                 locale_flag = get_encodeid_from_locale(locale_name);
00494             else{
00495                 locale_flag = ENCODES_NUM;
00496                 if(!udp->localeList){
00497                     udp->localeList = (LocaleList *)calloc(1, sizeof(LocaleList));
00498                 }else{
00499                     udp->localeList = (LocaleList *) realloc((LocaleList *)udp->localeList,
00500                                                              (udp->locale_Num+1)*sizeof(LocaleList));
00501                 }
00502                 if(!udp->localeList)
00503                     log_f("Error in calloc/realloc for LocaleList \n");
00504 
00505                 udp->localeList[udp->locale_Num].locale_name = (char *)strdup(locale_name);
00506                 /* Create the new supported language list */
00507                 loc[udp->locale_Num].id = (char *)strdup(locale_name);
00508                 loc[udp->locale_Num].name = (UTFCHAR *)calloc(strlen(locale_name)+1,sizeof(UTFCHAR));
00509                 CpyUTFCHAR(locale_name, loc[udp->locale_Num].name);
00510 
00511                 udp->localeList[udp->locale_Num].nEngineId = 0;
00512                 log_f("udp->localeList[%d].locale_name [%s]\n",udp->locale_Num, udp->localeList[udp->locale_Num].locale_name);
00513                 udp->locale_Num++;
00514             }
00515             log_f("locale_name:%s, locale_id:%d\n", locale_name, locale_flag);
00516             continue;
00517         }
00518 
00519         if (!strcasecmp(locale_name, SWITCH_TO_NEXT_LOCALE)){
00520             if(switch_to_next_locale_flag) {
00521                 set_keyvalues(udp, line, locale_name);
00522                 switch_to_next_locale_flag = 0;
00523                 continue;
00524             }
00525         }
00526 
00527         if (!strcasecmp(locale_name, SWITCH_TO_PREV_LOCALE)){
00528             if(switch_to_prev_locale_flag) {
00529                 set_keyvalues(udp, line, locale_name);
00530                 switch_to_prev_locale_flag = 0;
00531                 continue;
00532             }
00533         }
00534 
00535         if (!strcasecmp(locale_name, SWITCH_LAYOUT_NAME)){
00536             if (switch_layout_flag){
00537                 set_keyvalues(udp, line, locale_name);
00538                 switch_layout_flag = 0;
00539                 continue;
00540             }
00541         }
00542 
00543         if (locale_flag == ENCODE_ERROR) continue;
00544 
00545         /* get IME language engine name */
00546         ptr = line;
00547         engine_name = line;
00548         while (*ptr && !isspace(*ptr)) ptr++;
00549         if (*ptr) {
00550             *ptr = '\0';
00551             ptr++;
00552         }
00553 
00554         while (*ptr && isspace(*ptr)) ptr++;
00555         engine_path = ptr;
00556 
00557         while (*ptr && !isspace(*ptr)) ptr++;
00558         if (*ptr) {
00559             *ptr = '\0';
00560             ptr++;
00561         }
00562 
00563         while (*ptr && isspace(*ptr)) ptr++;
00564         engine_options = ptr;
00565 
00566         while (*ptr && !isspace(*ptr)) ptr++;
00567         if (*ptr) {
00568             *ptr = '\0';
00569             ptr++;
00570         }
00571         while (*ptr && isspace(*ptr)) ptr++;
00572         conv_flag = ptr;
00573 
00574         log_f("locale_id:%d, locale:%s, Engine Name:%s\n", locale_flag, locale_name, engine_name);
00575         log_f("Engine Path: %s, Engine Options: %s, Conv_flag [%s] \n", engine_path, engine_options, conv_flag);
00576         open_engine(udp, locale_flag, locale_name,
00577                     engine_name, engine_path, engine_options, conv_flag);
00578 
00579     } while (1);
00580 
00581     loc[udp->locale_Num].id = (char *)NULL;
00582     loc[udp->locale_Num].name = (UTFCHAR *)NULL;
00583 
00584     numLocales = udp->locale_Num;
00585 
00586     if ((udp->nextLocaleKeycode == 0) && (udp->nextLocaleModifier == 0)){
00587         udp->nextLocaleKeycode = IM_VK_F5;
00588         udp->nextLocaleModifier = 0;
00589     }
00590 
00591     if ((udp->prevLocaleKeycode == 0) && (udp->prevLocaleModifier == 0)){
00592         udp->prevLocaleKeycode = IM_VK_F5;
00593         udp->prevLocaleModifier = 0;
00594     }
00595     if ((udp->layoutNameKeyCode == 0) && (udp->layoutNameModifier == 0)){
00596         udp->layoutNameKeyCode = IM_VK_F6;
00597         udp->layoutNameModifier = 0;
00598     }
00599 
00600     getNEngineIds(udp);
00601 
00602     /*  
00603      *  print_core(udp); 
00604      */
00605      print_core(udp); 
00606 
00607     return 0;
00608 
00609 }
00610 
00611 int
00612 unit_desktop_add_listener(
00613     unit_desktop_t *udp,
00614     iml_session_t *s
00615 )
00616 {
00617     char          file_name[PATH_MAX];
00618     iml_nsl       *nsl;
00619     void          *nsl_callback;
00620 
00621     nsl_callback = unit_ns_callback;
00622 
00623     nsl = calloc(1, sizeof(iml_nsl));
00624     snprintf(file_name, sizeof(file_name), "%s/%s", XAUX_LOCALE_NAME, SYSTEM_PROFILE_NAME);
00625     nsl->path_name = file_name ;
00626     nsl->calldata = udp ; /* anything unit need */
00627     s->If->m->iml_add_listener(s, "iiim.le.io.listener", nsl_callback, nsl);
00628     return 0;
00629 }
00630 
00631 void
00632 unit_desktop_set_curr_profile_id(
00633     unit_desktop_t *udp,
00634     int profile_id
00635 )
00636 {
00637     udp->curr_hotkey_profile_id = profile_id;
00638 }
00639 
00640 int
00641 unit_desktop_get_curr_profile_id(
00642     unit_desktop_t *udp
00643 )
00644 {
00645     return udp->curr_hotkey_profile_id;
00646 }
00647 
00648 void
00649 unit_desktop_switch_hotkey_profile(
00650     unit_desktop_t *udp,
00651     iml_session_t *s
00652 )
00653 {
00654     iml_hkc       *hkc;
00655     iml_hkc_create_t le_hkc_create;
00656     iml_hkc_free_t le_hkc_free;
00657 
00658     le_hkc_create = (iml_hkc_create_t) (s->desktop->If->hkc_get_function("_hkc_create"));
00659     le_hkc_free = (iml_hkc_free_t) (s->desktop->If->hkc_get_function("_hkc_free"));
00660 
00661     hkc = le_hkc_create("unitle", IML_HKC_TYPE_DESKTOP, s->desktop);
00662 
00663     unit_desktop_set_curr_profile_id(udp, IME_HOTKEY_PROFILE_TWO);
00664     s->desktop->If->switchLEProfile(s, IME_HOTKEY_PROFILE_TWO, &leName);
00665 
00666     le_hkc_free(hkc);
00667 }
00668 
00669 int
00670 unit_desktop_load_engines(
00671     unit_desktop_t *udp,
00672     iml_desktop_t *desktop
00673 )
00674 {
00675     iml_nsc          *nsc;
00676     int              ns_id;
00677     char             file_name[PATH_MAX];
00678     int              fd, size, nread;
00679     char             *file_buf;
00680     struct stat      stat_buf;
00681     /*
00682     struct dirent    *dirp;
00683     DIR              *Dp;
00684     */
00685     FILE             *fp;
00686     iml_nsc_create_t le_nsc_create;
00687     iml_nsc_free_t   le_nsc_free;
00688 #ifdef NSC_FIO_SET
00689     iml_nsc_basic_fioset_t *bfio;
00690 #else
00691     iml_nsc_open_t le_open; 
00692     iml_nsc_stat_t le_stat;
00693     iml_nsc_read_t le_read;
00694     iml_nsc_close_t le_close;
00695     iml_nsc_umask_t le_umask;
00696     /*
00697     iml_nsc_lstat_t le_lstat;
00698     iml_nsc_opendir_t le_opendir;
00699     iml_nsc_readdir_t le_readdir;
00700     iml_nsc_closedir_t le_closedir;
00701     iml_nsc_mkdir_t le_mkdir;
00702     */
00703 #endif
00704 
00705     le_nsc_create = (iml_nsc_create_t) (desktop->If->nsc_get_function("_nsc_create"));
00706     le_nsc_free = (iml_nsc_free_t) (desktop->If->nsc_get_function("_nsc_free"));
00707 
00708     nsc = le_nsc_create("unitle", IML_NSC_TYPE_DESKTOP, desktop);
00709 
00710 #ifdef NSC_FIO_SET
00711     bfio = (iml_nsc_basic_fioset_t *) (desktop->If->nsc_get_function("_nsc_basicfioset"));
00712 #else
00713     le_open = (iml_nsc_open_t) (desktop->If->nsc_get_function("open"));
00714     le_stat = (iml_nsc_stat_t) (desktop->If->nsc_get_function("stat"));
00715     le_read = (iml_nsc_read_t) (desktop->If->nsc_get_function("read"));
00716     le_close = (iml_nsc_close_t) (desktop->If->nsc_get_function("close"));
00717     le_umask = (iml_nsc_umask_t) (desktop->If->nsc_get_function("umask"));
00718     /*
00719     le_lstat = (iml_nsc_lstat_t) (desktop->If->nsc_get_function("lstat"));
00720     le_opendir = (iml_nsc_opendir_t) (desktop->If->nsc_get_function("opendir"));
00721     le_readdir = (iml_nsc_readdir_t) (desktop->If->nsc_get_function("readdir"));
00722     le_closedir = (iml_nsc_closedir_t) (desktop->If->nsc_get_function("closedir"));
00723     le_mkdir = (iml_nsc_mkdir_t) (desktop->If->nsc_get_function("mkdir"));
00724     */
00725 #endif
00726 
00727     if (!le_umask) {
00728       log_f("iml_nsc_umask_t() not supported \n");
00729     }
00730 
00731     size = -1;
00732     snprintf(file_name, sizeof(file_name), "%s/%s/%s/%s", VAR_LE_DIR, XAUX_LOCALE_NAME, desktop->user_name, SYSTEM_PROFILE_NAME);
00733 
00734 #ifdef NSC_FIO_SET
00735     if ((ns_id = bfio->open(nsc, file_name, O_RDWR)) < 0) {
00736 #else
00737     if ((ns_id = le_open(nsc, file_name, O_RDWR )) < 0) {
00738 #endif
00739 /*
00740        log_f("open error [%d] [%s]\n", errno, sys_errlist[errno]);
00741 */
00742        log_f("Namespace not defined, read from default location \n");
00743        snprintf(file_name, sizeof(file_name), "%s/%s/%s",  DEFAULT_ENGINE_PATH, XAUX_LOCALE_NAME, SYSTEM_PROFILE_NAME);
00744        log_f("file name :%s\n",file_name);
00745        fp = fopen(file_name, "r");
00746        if (! fp)
00747            return (-1);
00748        fd = fileno((FILE *)fp);
00749        if (fstat(fd, &stat_buf) < 0) {
00750            return -1;
00751        }
00752        size = stat_buf.st_size;
00753        log_f("size [%d]\n",size);
00754        file_buf = (char *)calloc(size, sizeof(char));
00755        nread = fread(file_buf, size, 1, fp);
00756        log_f("nread [%d]\n",nread);
00757        unit_ns_read_config(udp, file_buf, size);
00758        if (numLocales) {
00759            desktop->If->updateSupportedLocales(desktop, &leName, loc, numLocales);
00760        }
00761        fclose(fp);
00762        return 0;
00763     }
00764 
00765     memset(&stat_buf, '\0', sizeof(stat_buf));
00766 #ifdef NSC_FIO_SET
00767     if ((bfio->stat(nsc, ns_id, &stat_buf)) < 0) {
00768        bfio->close(nsc, ns_id);
00769 #else
00770     if ((le_stat(nsc, file_name, &stat_buf)) < 0) {
00771         le_close(nsc, ns_id);
00772 #endif
00773        le_nsc_free(nsc);
00774        return 0;
00775     }
00776 
00777     if (stat_buf.st_size) {
00778        file_buf = (char *) calloc(stat_buf.st_size, sizeof(char));
00779 #ifdef NSC_FIO_SET
00780        nread = bfio->read(nsc, ns_id, file_buf, stat_buf.st_size);
00781        if (nread <= 0) {
00782            log_f("Error in read file \n");
00783            bfio->close(nsc, ns_id);
00784            return -1;
00785        }
00786 #else
00787         nread = le_read(nsc, ns_id, file_buf, stat_buf.st_size);
00788         if (nread <= 0) {
00789             log_f("Error in read file \n");
00790             le_close(nsc, ns_id);
00791             return -1;
00792         }
00793 #endif
00794        unit_ns_read_config(udp, file_buf, stat_buf.st_size);
00795   
00796        if (numLocales) {
00797            desktop->If->updateSupportedLocales(desktop, &leName, loc, numLocales);
00798        }
00799     }
00800     le_close(nsc, ns_id);
00801     le_nsc_free(nsc);
00802 
00803     /*
00804       memset(&stat_buf, '\0', sizeof(stat_buf));
00805 #ifdef NSC_FIO_SET
00806       if ((bfio->lstat(nsc, file_name, &stat_buf)) < 0) {
00807       bfio->close(nsc, ns_id);
00808       le_nsc_free(nsc);
00809       return 0;
00810       }
00811       bfio->close(nsc, ns_id);
00812 #else
00813       if ((le_lstat(nsc, file_name, &stat_buf)) < 0) {
00814       le_close(nsc, ns_id);
00815       le_nsc_free(nsc);
00816       return 0;
00817       }
00818       le_close(nsc, ns_id);
00819 #endif
00820       log_f("UNIT: file_size from lstat [%ld]\n",stat_buf.st_size);
00821       log_f("UNIT: mtime from lstat [%ld]\n",stat_buf.st_mtime);
00822 
00823 #ifdef NSC_FIO_SET
00824       memset((char *)file_name,'\0',sizeof(file_name));
00825       snprintf(file_name, sizeof(file_name), "%s/%s/%s", VAR_LE_DIR, XAUX_LOCALE_NAME, desktop->user_name);
00826       Dp = bfio->opendir(nsc, file_name);
00827       while ((dirp = bfio->readdir(nsc, Dp)) != NULL) {
00828       log_f("UNIT: d_reclen [%x]\n", dirp->d_reclen);
00829       log_f("UNIT: d_name [%s]\n", dirp->d_name);
00830       }
00831       bfio->closedir(nsc, Dp);
00832 
00833       memset((char *)file_name,'\0',sizeof(file_name));
00834       snprintf(file_name, sizeof(file_name), "%s/%s/%s/%s", VAR_LE_DIR, XAUX_LOCALE_NAME, desktop->user_name, "testMKDIR");
00835 
00836       bfio->mkdir(nsc, file_name, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
00837 #else
00838       memset((char *)file_name,'\0',sizeof(file_name));
00839       snprintf(file_name, sizeof(file_name), "%s/%s/%s", VAR_LE_DIR, XAUX_LOCALE_NAME, desktop->user_name);
00840       Dp = le_opendir(nsc, file_name);
00841       while ((dirp = le_readdir(nsc, Dp)) != NULL) {
00842       log_f("UNIT: d_reclen [%x]\n", dirp->d_reclen);
00843       log_f("UNIT: d_name [%s]\n", dirp->d_name);
00844       }
00845       le_closedir(nsc, Dp);
00846 
00847       memset((char *)file_name,'\0',sizeof(file_name));
00848       snprintf(file_name, sizeof(file_name), "%s/%s/%s/%s", VAR_LE_DIR, XAUX_LOCALE_NAME, desktop->user_name, "testMKDIR");
00849 
00850       le_mkdir(nsc, file_name, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
00851 #endif
00852 
00853       le_nsc_free(nsc);
00854     */
00855 
00856     return 0;
00857 }
00858 
00859 int
00860 get_line (
00861     char *buf,     /* in: pointer to entire buffer */
00862     int size,      /* in: size of entire buffer */
00863     char **curptr, /* inout: pointer to where it was last time
00864                   *        Has to be 0 when 1st time called
00865                   */
00866     char *line     /* out: One line without preceeding/trailing
00867                   *      space
00868                   */
00869 )
00870 {
00871     int line_ptr, n;
00872     char line_buf[MAX_LINE_LEN]; 
00873     char *ptr;
00874 
00875     char *p = ((0 == *curptr)?*curptr=buf:*curptr);
00876     char *pp = p;
00877 
00878     line_ptr = 0;
00879     line[0] = '\0';
00880 
00881     n = *curptr - buf;
00882     if (n >= size) { /* No more data to read */
00883        return 0;
00884     }
00885 
00886     /* get line with no space */
00887     while(1) {
00888         if (*p == '\n' || *p == '\0') {
00889             *p++;
00890             continue;
00891         }
00892 
00893        /* chop one line */
00894        while (*p != '\n') p++ ;
00895        /* pp to p is one line, just as fgets returns */
00896        memcpy(line_buf, pp, p-pp);
00897        line_buf[p-pp]='\0';
00898 
00899        ptr = line_buf;
00900 
00901        /* skip preceding space keys */
00902        while(*ptr && isspace(*ptr)) ptr++;
00903 
00904        /* if is space line, get new line */
00905        if (*ptr == '\n' || *ptr == '\0')
00906            continue;
00907 
00908        while(*ptr != '\n' && *ptr != '\0' && line_ptr < MAX_LINE_LEN)
00909            line[line_ptr++] = *ptr++;
00910 
00911        /* trim right space */
00912        while (isspace(line[line_ptr-1])) line_ptr--;
00913        line[line_ptr] = '\0';
00914 
00915        /* if the line end with '\', then continue read the next line */
00916        if (line[line_ptr-1] == '\\') {
00917            line_ptr--;
00918            line[line_ptr] = '\0';
00919            continue;
00920        } 
00921        break;
00922     }
00923 
00924     *curptr = p+1 ;
00925 
00926     if (line[0] == '\0') return 0;
00927     if (line[0] == COMMENT) return -1; 
00928     return line_ptr;
00929 }
00930 
00931 /* engine_options can be data_path or engine options. */
00932 int 
00933 open_engine(udp, locale_id, locale_name, engine_name, engine_path, engine_options, conv_flag)
00934     unit_desktop_t *udp;
00935 int    locale_id;
00936 char   *locale_name;
00937 char   *engine_name;
00938 char   *engine_path;
00939 char   *engine_options;
00940 char   *conv_flag;
00941 {
00942     int              ret, i;
00943     char             file_name[PATH_MAX];
00944     struct stat      file_buffer;
00945 
00946     void             *so_handler;
00947     IMEMethods       methods;
00948 
00949     int              is_codetable_engine = 0;
00950 
00951     if (udp->gEngine_Num > MAX_ENGINE_NUM) return (-1);
00952     
00953     /* read profile from file to memory buffer  */ 
00954     if (*engine_path) {
00955        if (engine_path[0] != '/') 
00956            snprintf(file_name, sizeof(file_name), "%s/%s/%s",  DEFAULT_ENGINE_PATH, 
00957                    XAUX_LOCALE_NAME, 
00958                    engine_path);
00959        else
00960            snprintf(file_name, sizeof(file_name), "%s", engine_path);
00961     } else {
00962        is_codetable_engine = 1;
00963        snprintf(file_name, sizeof(file_name), "%s/%s/%s/%s.so", DEFAULT_ENGINE_PATH, 
00964                XAUX_LOCALE_NAME, 
00965                locale_name, 
00966                engine_name);
00967     }
00968 
00969     if ((stat(file_name, &file_buffer)) == -1)
00970        { 
00971            if (is_codetable_engine) {
00972               snprintf(file_name, sizeof(file_name),  "%s/%s/%s/%s.so", DEFAULT_ENGINE_PATH, 
00973                       XAUX_LOCALE_NAME, 
00974                       COMMON_ENGINE_PATH, 
00975                       CODETABLE_ENGINE_NAME);
00976               if ((stat(file_name, &file_buffer)) == -1)
00977                   return (-1);
00978            } else {
00979               return (-1);
00980            }
00981        }
00982     log_f("so_file_name:%s\n", file_name);
00983 
00984     so_handler = (void *) dlopen(file_name, RTLD_LAZY);
00985     if (!so_handler) {
00986        log_f("can not open so file: %s\n", file_name);
00987        return (-1);
00988     } else {
00989        methods = (IMEMethods) dlsym(so_handler, "ime_methods");
00990        if (!methods) {
00991            log_f("can not open method tables of file:%s\n", file_name);
00992            dlclose(so_handler);
00993            return(-1);
00994        }
00995     }
00996 
00997     udp->gEngine_Info[udp->gEngine_Num] = (IMEEngineRec *)calloc(1, sizeof(IMEEngineRec));
00998     if (udp->gEngine_Info[udp->gEngine_Num] == NULL) return(0);
00999 
01000     udp->gEngine_Info[udp->gEngine_Num]->core.baseinfo.engine_id = udp->gEngine_Num;
01001     udp->gEngine_Info[udp->gEngine_Num]->core.baseinfo.locale_id = locale_id;
01002     udp->gEngine_Info[udp->gEngine_Num]->core.baseinfo.status = ENGINE_NOT_INITIATED;
01003     udp->gEngine_Info[udp->gEngine_Num]->core.baseinfo.ename = (char *)strdup(engine_name);
01004 
01005     udp->gEngine_Info[udp->gEngine_Num]->core.envinfo.lang_name = (char *)strdup(XAUX_LOCALE_NAME);
01006     udp->gEngine_Info[udp->gEngine_Num]->core.envinfo.locale_name = (char *)strdup(locale_name);
01007     udp->gEngine_Info[udp->gEngine_Num]->core.envinfo.data_path = NULL;
01008     udp->gEngine_Info[udp->gEngine_Num]->core.envinfo.data_ptr = NULL;
01009 
01010     udp->gEngine_Info[udp->gEngine_Num]->core.keymapinfo.bSet = 0;
01011     for (i=0; i<MAX_KEYMAP_KEY_NUM; i++) 
01012        udp->gEngine_Info[udp->gEngine_Num]->core.keymapinfo.keymap[i] = NULL;
01013 
01014     udp->gEngine_Info[udp->gEngine_Num]->so_handler = so_handler;
01015     udp->gEngine_Info[udp->gEngine_Num]->so_methods = methods;
01016 
01017     /* IME_SetValues: set the arguments of this IME */
01018     ret = methods->IME_SetOptions(&(udp->gEngine_Info[udp->gEngine_Num]->core), engine_options);
01019     if (ret == -1) {
01020        log_f("Not successfully set options of the input method engine:%s\n",engine_name);
01021        dlclose(so_handler);
01022        return(-1);
01023     }
01024 
01025     /* IME_Init: get the status, lname, cname, encode information of this Input Method engine */
01026     ret = methods->IME_Init(&(udp->gEngine_Info[udp->gEngine_Num]->core));
01027     if (ret == -1) {
01028        log_f("Not successfully initialize the input method engine:%s\n",engine_name);
01029        dlclose(so_handler);
01030        return(-1);
01031     }
01032 
01033     udp->modeList[udp->gEngine_Num] = (IMEModeList *)calloc(1, sizeof(IMEModeList));
01034     if (udp->modeList[udp->gEngine_Num] == NULL) return(0);
01035 
01036     log_f("open_engine: nlocale_name [%s], nlayout_name [%s]\n",udp->gEngine_Info[udp->gEngine_Num]->core.baseinfo.lname, udp->gEngine_Info[udp->gEngine_Num]->core.baseinfo.cname);
01037     udp->modeList[udp->gEngine_Num]->locale_name = (char *)strdup(locale_name);
01038     udp->modeList[udp->gEngine_Num]->nlocale_name = (char *)strdup(udp->gEngine_Info[udp->gEngine_Num]->core.baseinfo.lname);
01039     udp->modeList[udp->gEngine_Num]->nlayout_name = (char *)strdup(udp->gEngine_Info[udp->gEngine_Num]->core.baseinfo.cname);
01040     udp->modeList[udp->gEngine_Num]->engine_id = udp->gEngine_Num;
01041     udp->modeList[udp->gEngine_Num]->engine_name = (char *)strdup(engine_name);
01042     udp->modeList[udp->gEngine_Num]->default_state = (char *)strdup(conv_flag);
01043 
01044     udp->gEngine_Num++;
01045     return(0);
01046 }
01047 
01048 void 
01049 unit_desktop_done(unit_desktop_t *udp)
01050 {
01051     int i;
01052     char *name;
01053 
01054     for (i=0; i<udp->gEngine_Num; i++) {
01055        name = udp->gEngine_Info[i]->core.baseinfo.ename;
01056        if (name) free(name);
01057 
01058        name = udp->gEngine_Info[i]->core.envinfo.lang_name;
01059        if (name) free(name);
01060 
01061        name = udp->gEngine_Info[i]->core.envinfo.locale_name;
01062        if (name) free(name);
01063 
01064        udp->gEngine_Info[i]->so_methods->IME_Close(&(udp->gEngine_Info[i]->core));
01065        dlclose(udp->gEngine_Info[i]->so_handler);
01066        free((char *)udp->gEngine_Info[i]);
01067 
01068        name = udp->modeList[i]->locale_name;
01069        if (name) free(name);
01070 
01071        name = udp->modeList[i]->nlocale_name;
01072        if (name) free(name);
01073 
01074        name = udp->modeList[i]->nlayout_name;
01075        if (name) free(name);
01076 
01077        name = udp->modeList[i]->engine_name;
01078        if (name) free(name);
01079 
01080        free((char *)udp->modeList[i]);
01081        udp->modeList[i] = 0;
01082     }
01083     udp->gEngine_Num = 0;
01084 
01085     for(i=0; i<udp->locale_Num; i++){
01086        name = udp->localeList[i].locale_name;
01087        if (name) free(name);
01088     }
01089     free((LocaleList *)udp->localeList);
01090     udp->localeList = 0;
01091 }
01092 
01093 int get_key_value(char *key_str){
01094     int i;
01095     for (i = 0; kvp[i].key_name != 0; i++) {
01096         if(!strcmp(kvp[i].key_name, key_str)){
01097             return kvp[i].value;
01098         }
01099     }
01100     return 0;
01101 }
01102 
01103 int set_keyvalues(unit_desktop_t *udp, char *buf, char *Lname){
01104     char *keycode_name, *modifier_name;
01105     char *ptr;
01106     int flag;
01107 
01108     flag = 0;
01109     ptr = buf;
01110     keycode_name = buf;
01111 
01112     while (*ptr && !isspace(*ptr)){
01113        if (isalpha(*ptr)){
01114            flag = 1;
01115        }
01116        ptr++;
01117     }
01118 
01119     if (*ptr) {
01120        *ptr = '\0';
01121        ptr++;
01122     }
01123 
01124     if (!strcasecmp(Lname, SWITCH_TO_NEXT_LOCALE)) {
01125        log_f("SWITCH_TO_NEXT_LOCALE: keycode_name <%s>\n",keycode_name);
01126     } else if (!strcasecmp(Lname, SWITCH_TO_PREV_LOCALE)) {
01127        log_f("SWITCH_TO_PREV_LOCALE: keycode_name <%s>\n",keycode_name);
01128     } else if(!strcasecmp(Lname, SWITCH_LAYOUT_NAME)) {
01129        log_f("SWITCH_LAYOUT: keycode_name <%s>\n",keycode_name);
01130     }
01131    
01132     if (flag){
01133        if ((keycode_name[0] == 'I') && (keycode_name[1] == 'M')){
01134            if (!strcasecmp(Lname, SWITCH_TO_NEXT_LOCALE)) {
01135               udp->nextLocaleKeycode = get_key_value(keycode_name);
01136            } else if (!strcasecmp(Lname, SWITCH_TO_PREV_LOCALE)) {
01137               udp->prevLocaleKeycode = get_key_value(keycode_name);
01138            } else if(!strcasecmp(Lname, SWITCH_LAYOUT_NAME)) {
01139               udp->layoutNameKeyCode = get_key_value(keycode_name); 
01140            }
01141        }else{
01142            if (!strcasecmp(Lname, SWITCH_TO_NEXT_LOCALE)) {
01143               udp->nextLocaleKeycode = (UTFCHAR)strtol(keycode_name, NULL, 16);
01144            } else if (!strcasecmp(Lname, SWITCH_TO_PREV_LOCALE)) {
01145               udp->prevLocaleKeycode = (UTFCHAR)strtol(keycode_name, NULL, 16);
01146            } else if(!strcasecmp(Lname, SWITCH_LAYOUT_NAME)) {
01147               udp->layoutNameKeyCode = (UTFCHAR)strtol(keycode_name, NULL, 16);
01148            }
01149        }
01150     }else{
01151        if (!strcasecmp(Lname, SWITCH_TO_NEXT_LOCALE)) {
01152            udp->nextLocaleKeycode = atoi(keycode_name);
01153        } else if (!strcasecmp(Lname, SWITCH_TO_PREV_LOCALE)) {
01154            udp->prevLocaleKeycode = atoi(keycode_name);
01155        } else if(!strcasecmp(Lname, SWITCH_LAYOUT_NAME)) {
01156            udp->layoutNameKeyCode = atoi(keycode_name);
01157        }
01158     }
01159 
01160     while (*ptr && isspace(*ptr)) ptr++;
01161     modifier_name = ptr;
01162 
01163     while (*ptr && !isspace(*ptr)){
01164        if (isalpha(*ptr)){
01165            flag = 1;
01166        }
01167        ptr++;
01168     }
01169     if (*ptr) {
01170        *ptr = '\0';
01171        ptr++;
01172     }
01173 
01174     if (!strcasecmp(Lname, SWITCH_TO_NEXT_LOCALE)) {
01175        log_f("SWITCH_TO_NEXT_LOCALE: modifier_name <%s>\n",modifier_name);
01176     } else if (!strcasecmp(Lname, SWITCH_TO_PREV_LOCALE)) {
01177        log_f("SWITCH_TO_PREV_LOCALE: modifier_name <%s>\n",modifier_name);
01178     } else if(!strcasecmp(Lname, SWITCH_LAYOUT_NAME)) {
01179        log_f("SWITCH_LAYOUT: modifier_name <%s>\n",modifier_name);
01180     }
01181 
01182     if (flag){
01183        if ((modifier_name[0] == 'I') && (modifier_name[1] == 'M')){
01184            if (!strcasecmp(Lname, SWITCH_TO_NEXT_LOCALE)){
01185               udp->nextLocaleModifier = get_key_value(modifier_name);
01186            } else if (!strcasecmp(Lname, SWITCH_TO_PREV_LOCALE)){
01187               udp->prevLocaleModifier = get_key_value(modifier_name);
01188            }else if(!strcasecmp(Lname, SWITCH_LAYOUT_NAME)){
01189               udp->layoutNameModifier = get_key_value(modifier_name);
01190            }
01191        }else{
01192            if (!strcasecmp(Lname, SWITCH_TO_NEXT_LOCALE)){
01193               udp->nextLocaleModifier = (UTFCHAR)strtol(modifier_name, NULL, 16);
01194            } else if (!strcasecmp(Lname, SWITCH_TO_PREV_LOCALE)){
01195               udp->prevLocaleModifier = (UTFCHAR)strtol(modifier_name, NULL, 16);
01196            }else if(!strcasecmp(Lname, SWITCH_LAYOUT_NAME)){
01197               udp->layoutNameModifier = (UTFCHAR)strtol(modifier_name, NULL, 16);
01198            }
01199        }
01200     }else{
01201        if (!strcasecmp(Lname, SWITCH_TO_NEXT_LOCALE)){
01202            udp->nextLocaleModifier = atoi(modifier_name);
01203        } else if (!strcasecmp(Lname, SWITCH_TO_PREV_LOCALE)){
01204            udp->prevLocaleModifier = atoi(modifier_name);
01205        }else if(!strcasecmp(Lname, SWITCH_LAYOUT_NAME)){
01206            udp->layoutNameModifier = atoi(modifier_name);
01207        }
01208     }
01209     return 1;
01210 }
01211 
01212 /* Local Variables: */
01213 /* c-file-style: "iiim-project" */
01214 /* End: */