Back to index

im-sdk  12.3.91
le.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 #include <stdio.h>
00043 #include <string.h>
00044 #include <stdlib.h>
00045 #include <ctype.h>
00046 #include <limits.h>
00047 
00048 #include "le.h"
00049 #include "encode.h"
00050 #include "xaux_locale.h"
00051 #include "le_proc.h"
00052 
00053 Bool if_le_OpenIF(iml_if_t *);
00054 Bool if_le_CloseIF(iml_if_t *);
00055 Bool if_le_GetIFValue(iml_if_t *, IMArgList, int);
00056 Bool if_le_SetIFValue(iml_if_t *, IMArgList, int);
00057 Bool if_le_OpenDesktop(iml_desktop_t *, IMArgList, int);
00058 Bool if_le_CloseDesktop(iml_desktop_t *);
00059 Bool if_le_CreateSC(iml_session_t *, IMArgList, int);
00060 Bool if_le_DestroySC(iml_session_t *);
00061 Bool if_le_GetSCValue(iml_session_t *, IMArgList, int);
00062 Bool if_le_SetSCValue(iml_session_t *, IMArgList, int);
00063 IMText *if_le_ResetSC(iml_session_t *);
00064 void if_le_SetSCFocus(iml_session_t *);
00065 void if_le_UnsetSCFocus(iml_session_t *);
00066 void if_le_SendEvent(iml_session_t *, IMInputEvent * ev);
00067 int get_list_of_supported_locales();
00068 Bool is_trigger_on_required(unit_desktop_t *udp, char *locale);
00069 unit_desktop_t *create_unit_desktop();
00070 void add_unit_desktop(unit_desktop_t *udp);
00071 unit_desktop_t * find_unit_desktop_by_sc(iml_session_t *);
00072 int CpyUTFCHAR(char *src, UTFCHAR *dest);
00073 IMHotkeyProfileStruct *get_hkp_from_hkm(int);
00074 
00075 /* IF Method */
00076 if_methods_t le_methods = {
00077        if_le_OpenIF,
00078        if_le_CloseIF,
00079        if_le_GetIFValue,
00080        if_le_SetIFValue,
00081        if_le_OpenDesktop,
00082        if_le_CloseDesktop,
00083        if_le_CreateSC,
00084        if_le_DestroySC,
00085        if_le_GetSCValue,
00086        if_le_SetSCValue,
00087        if_le_ResetSC,
00088        if_le_SetSCFocus,
00089        if_le_UnsetSCFocus,
00090        if_le_SendEvent
00091 };
00092 
00093 extern char lename_string[];
00094 extern UTFCHAR lename_utf_string[];
00095 extern char default_locale_id;
00096 extern void get_line(char *buf, int size, char **curptr, char *line);
00097 extern void unit_desktop_init(unit_desktop_t *udp);
00098 extern int unit_desktop_add_listener(unit_desktop_t *udp, iml_session_t *s);
00099 extern int unit_desktop_load_engines(unit_desktop_t *udp, iml_desktop_t *desktop);
00100 extern void unit_desktop_set_curr_profile_id(unit_desktop_t *udp, int profile_id);
00101 extern int unit_desktop_get_curr_profile_id(unit_desktop_t *udp);
00102 extern void unit_desktop_switch_hotkey_profile(unit_desktop_t *udp, iml_session_t *s);
00103 extern void unit_desktop_done(unit_desktop_t *udp);
00104 
00105 extern IMEBufferRec *ime_buffer_malloc();
00106 extern void ime_buffer_free(IMEBuffer);
00107 extern void proc_key_event(unit_desktop_t *, iml_session_t *, IMKeyListEvent *);
00108 extern void process_hotkey_event(unit_desktop_t *, iml_session_t *, IMKeyListEvent *);
00109 extern void proc_key_switch_conversion_event(unit_desktop_t *, iml_session_t *, int, char *);
00110 extern IMHotkeyManagerStruct *parse_hotkey_config_file(IMLEName *, char *);
00111 extern void printHotkeyManager(IMHotkeyManagerStruct *);
00112 
00113 IMLEName lename = {lename_string, lename_utf_string };
00114 static IMObjectDescriptorStruct *objects = NULL;
00115 
00116 static IMHotkeyManagerStruct *g_hkms = NULL;
00117 
00118 static Bool add_listener_flag = False;
00119 IMLocale locales[MAX_SUPPORTED_LOCALES];
00120 int n_Supported_Locales;
00121 unit_if_t *UIf;
00122 
00123 /* htt_server get the IF information when start htt_server */
00124 
00125 /* if_GetHotKeyInfo:
00126    returns Unit L/E specific hotkey profile struct
00127    a_le_name : this should match to unit's lename which was
00128    previously set as IF_LE_NAME in If_GetIfInfo().
00129 */
00130 
00131 IMHotkeyManagerStruct *
00132 if_GetHotKeyInfo (
00133     IMLEName *a_le_name
00134 )
00135 {
00136     char file_name[PATH_MAX];
00137 
00138     snprintf(file_name, sizeof(file_name),"%s/%s/%s", 
00139                  DEFAULT_ENGINE_PATH, XAUX_LOCALE_NAME, HOTKEY_CONFIG_FILE);
00140 
00141     log_f("if_GetHotkeyInfo: file_name [%s]\n", file_name);
00142 
00143     g_hkms = parse_hotkey_config_file(a_le_name, file_name);
00144 
00145     /*
00146      * printHotkeyManager(g_hkms);
00147      */
00148 
00149     return g_hkms;
00150 }
00151 
00152 void 
00153 if_GetIfInfo(
00154     IMArgList args, 
00155     int num_args
00156 )
00157 {
00158     int i;
00159 
00160     log_f("if_GetIfInfo == num_args:%d\n", num_args);
00161 
00162     n_Supported_Locales =  get_list_of_supported_locales();
00163     log_f("n_Supported_Locales [%d]\n",n_Supported_Locales);
00164 
00165     for (i = 0; i < num_args; i++, args++) {
00166        switch (args->id) {
00167          case IF_VERSION:
00168           args->value = (IMArgVal) "1.2";
00169           break;
00170          case IF_METHOD_TABLE:
00171           args->value = (IMArgVal) & le_methods;
00172           break;
00173          case IF_LE_NAME:
00174           args->value = (IMArgVal) & lename;
00175           break;
00176          case IF_SUPPORTED_LOCALES:
00177           args->value = (IMArgVal) & locales;
00178           break;
00179          case IF_SUPPORTED_OBJECTS:
00180           args->value = (IMArgVal) objects; 
00181           break;
00182          case IF_NEED_THREAD_LOCK:
00183           args->value = (IMArgVal) True;
00184           break;
00185          default:
00186           break;
00187        }
00188     }
00189 }
00190 
00191 /* Open the IF interface */
00192 Bool 
00193 if_le_OpenIF(
00194     iml_if_t * If
00195 )
00196 {
00197     log_f("if_le_OpenIF ====\n");
00198 
00199     UIf = 0;
00200 
00201     return True;
00202 }
00203 
00204 /* Close the IF interface */
00205 Bool 
00206 if_le_CloseIF(
00207     iml_if_t * If
00208 )
00209 {
00210     int i;
00211 
00212     log_f("if_le_CloseIF === \n");
00213 
00214     for (i=0 ; i<n_Supported_Locales ; i++){
00215        if (locales[i].id != NULL) {
00216            free(locales[i].id);
00217            locales[i].id = NULL;
00218        }
00219        if (locales[i].name != NULL) {
00220            free(locales[i].name);
00221            locales[i].name = NULL;
00222        }
00223     }
00224 
00225     if (UIf)
00226        free(UIf);
00227 
00228     /*
00229       Free the allocated memory for hotkey profile under UNIT
00230     */
00231 
00232     if (g_hkms) {
00233        if (g_hkms->hkps) {
00234            for (i=0; i<g_hkms->num_hotkey_profiles; i++) {
00235               if (g_hkms->hkps[i].hks)
00236                   free(g_hkms->hkps[i].hks);
00237            }
00238            free(g_hkms->hkps);
00239        }
00240        free(g_hkms);
00241     }
00242 
00243     return True;
00244 }
00245 
00246 Bool 
00247 if_le_GetIFValue(
00248     iml_if_t * If, 
00249     IMArgList args, 
00250     int num_args
00251 )
00252 {
00253     log_f("if_le_GetIFValue()\n");
00254     return True;
00255 }
00256 
00257 Bool 
00258 if_le_SetIFValue(
00259     iml_if_t * If, 
00260     IMArgList args, 
00261     int num_args
00262 )
00263 {
00264     log_f("if_le_SetIFValue()\n");
00265     return True;
00266 }
00267 
00268 unit_if_t *
00269 unit_if() 
00270 {
00271     if (!UIf) {
00272        UIf = (unit_if_t *)calloc(1, sizeof(unit_if_t));
00273        UIf->create_unit_desktop = create_unit_desktop;
00274        UIf->add_unit_desktop = add_unit_desktop;
00275        UIf->find_unit_desktop_by_sc = find_unit_desktop_by_sc;
00276        UIf->ud_count = 0;
00277     } 
00278     if (!UIf) 
00279        log_f("calloc/realloc error in unit_if() \n");
00280 
00281     return UIf;
00282 }
00283 
00284 unit_desktop_t *
00285 create_unit_desktop() 
00286 {
00287     unit_desktop_t *udp = (unit_desktop_t *) calloc(1, sizeof(unit_desktop_t));
00288     udp->next = unit_if()->ud_list;
00289     return udp;
00290 }
00291 
00292 void 
00293 add_unit_desktop(
00294     unit_desktop_t *udp
00295 ) 
00296 {
00297     udp->unit_desktop_init = unit_desktop_init;
00298     udp->unit_desktop_add_listener = unit_desktop_add_listener;
00299     udp->unit_desktop_load_engines = unit_desktop_load_engines;
00300     udp->unit_desktop_set_curr_profile_id = unit_desktop_set_curr_profile_id;
00301     udp->unit_desktop_get_curr_profile_id = unit_desktop_get_curr_profile_id;
00302     udp->unit_desktop_switch_hotkey_profile = unit_desktop_switch_hotkey_profile;
00303     udp->unit_desktop_done = unit_desktop_done;
00304     unit_if()->ud_list = udp;
00305     unit_if()->ud_count++;
00306     return;
00307 }
00308 
00309 unit_desktop_t *
00310 find_unit_desktop_by_sc(
00311     iml_session_t *s
00312 ) 
00313 {
00314     unit_desktop_list udl, *prev;
00315 
00316     if (UIf->ud_list == NULL) {
00317        return (unit_desktop_t *) NULL; 
00318     }
00319     for (prev = &UIf->ud_list; (udl = *prev) != 0; prev = &udl->next) {
00320         if (udl->s) {
00321            if (udl->s->desktop == s->desktop)
00322               return udl;
00323         } else if ((udl->s == 0) && (udl->next == NULL)) {
00324            return udl;
00325        }
00326     }
00327     return (unit_desktop_t *) NULL; 
00328 }
00329 
00330 Bool 
00331 if_le_OpenDesktop(
00332     iml_desktop_t * desktop, 
00333     IMArgList args, 
00334     int num_args
00335 )
00336 {
00337     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *)calloc(1,sizeof(MyDataPerDesktop));
00338     unit_desktop_t *udp = (unit_desktop_t *) 0;
00339 
00340     udp = unit_if()->create_unit_desktop();
00341     unit_if()->add_unit_desktop(udp);
00342     udp->unit_desktop_init(udp); 
00343     log_f("if_le_OpenDesktop: udp [0x%x]\n", (unsigned int) udp);
00344     udp->unit_desktop_load_engines(udp, desktop);
00345 
00346     desktop_data->current_session = 0;
00347     desktop_data->root_session = 0;
00348     desktop_data->aux_locale_id = default_locale_id;
00349     desktop_data->udp = udp;
00350 
00351     desktop->specific_data = (void *) desktop_data;
00352 
00353     add_listener_flag = False;
00354 
00355     return True;
00356 }
00357 
00358 Bool 
00359 if_le_CloseDesktop(
00360     iml_desktop_t * desktop
00361 )
00362 {
00363     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) desktop->specific_data;
00364     unit_desktop_t *temp, *prev;
00365     int i;
00366 
00367     log_f("if_le_CloseDesktop: udp [0x%x] \n", (unsigned int) desktop_data->udp);
00368     for (i=0; i<MAX_ENGINE_NUM; i++) {
00369        if (desktop_data->ime_args[i] != (IMEArgList) NULL)
00370            free((char *)desktop_data->ime_args[i]);
00371     }
00372     if (UIf && (UIf->ud_count > 0)) {
00373        temp = desktop_data->udp;
00374        prev = UIf->ud_list; /* Starting of the node */
00375         if (temp == prev) {
00376            if (temp->next == NULL) {
00377               unit_desktop_done(temp);
00378               UIf->ud_count--;
00379               free(temp);
00380            } else if (temp->next != NULL) {
00381               prev = temp->next;
00382               unit_desktop_done(temp);
00383               UIf->ud_count--;
00384               free(temp);
00385               UIf->ud_list = prev;
00386            }
00387        } else {
00388            while ((prev->next != temp) && (prev->next != NULL)) {
00389               prev = prev->next;
00390            }
00391            prev->next = temp->next;
00392            if (temp->next == NULL)
00393               temp->next = prev;
00394            unit_desktop_done(temp);
00395            UIf->ud_count--;
00396            free(temp);
00397        }
00398     }
00399     free(desktop_data);
00400 
00401     return True;
00402 }
00403 
00404 Bool 
00405 if_le_CreateSC(
00406     iml_session_t *s, 
00407     IMArgList args, 
00408     int num_args
00409 )
00410 {
00411     int i;
00412     iml_desktop_t *desktop = s->desktop;
00413     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) desktop->specific_data;
00414     MyDataPerSession *p = (MyDataPerSession *) calloc(1, sizeof(MyDataPerSession));
00415     log_f("if_le_CreateSC: udp [0x%x] \n", (unsigned int) desktop_data->udp);
00416 
00417     desktop_data->current_session = 0;
00418     p->paletteaux_status.engine_id = 0xff;
00419     desktop_data->udp->s = 0;
00420     
00421     /* Allocate memory for input method session context */
00422     p->ime_buffer = (IMEBuffer)ime_buffer_malloc();
00423     p->locale = NULL;
00424 
00425     s->specific_data = (void*) p;
00426 
00427     /* set aux proxy data */
00428     p->protocol_type = UNKNOWN_IMP;
00429     p->client_type = UNKNOWN_CLIENT;
00430     for (i = 0; i < num_args; i++, args++) {
00431        switch (args->id) {
00432          case UI_PROTOCOL_TYPE:
00433           if (args->value) {
00434               log_f("UI_PROTOCOL_TYPE: value: %s\n", args->value);
00435               if (!strcmp (UI_PROTOCOL_TYPE_XIMP, args->value))
00436                  p->protocol_type = XIMP;
00437           }
00438           break;
00439          case UI_CLIENT_TYPE:
00440           if (args->value) {
00441               log_f("UI_CLIENT_TYPE: value: %s\n", args->value);
00442               if (!strcmp (UI_CLIENT_TYPE_X, args->value))
00443                  p->client_type = X11_CLIENT;
00444           }
00445           break;
00446        }
00447     }
00448     if (p->protocol_type == XIMP && p->client_type == X11_CLIENT)
00449        if (desktop_data->root_session == 0)
00450            desktop_data->root_session = s;
00451 
00452     return True;
00453 }
00454 
00455 Bool 
00456 if_le_DestroySC(
00457     iml_session_t * s
00458 )
00459 {
00460     iml_desktop_t *desktop = s->desktop;
00461     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *) desktop->specific_data;
00462     MyDataPerSession *p = (MyDataPerSession *) s->specific_data;
00463 
00464     log_f("if_le_DestroySC: udp [0x%x] \n", (unsigned int) desktop_data->udp);
00465 
00466     desktop_data->current_session = 0;
00467     desktop_data->udp->s = 0;
00468 
00469     if (p->locale != NULL) {
00470        free((char *)p->locale);
00471        p->locale = NULL;
00472     }
00473 
00474     ime_buffer_free(p->ime_buffer);
00475     free((char *) p);
00476 
00477     if (s == desktop_data->root_session)
00478        desktop_data->root_session = 0;
00479 
00480     return True;
00481 }
00482 
00483 Bool 
00484 if_le_GetSCValue(
00485     iml_session_t * s, 
00486     IMArgList args, 
00487     int num_args
00488 )
00489 {
00490     log_f("if_le_GetSCValue(s=%x)\n\n", (unsigned int) s);
00491     return True;
00492 }
00493 
00494 Bool 
00495 if_le_SetSCValue(
00496     iml_session_t * s, 
00497     IMArgList args, 
00498     int num_args
00499 )
00500 {
00501     int i;
00502     IMArg *p = args;
00503     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *)(s->desktop->specific_data);
00504     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00505     unit_desktop_t *udp = desktop_data->udp;
00506 
00507     log_f("if_le_SetSCValue: udp [0x%x]\n", (unsigned int) desktop_data->udp);
00508 
00509     desktop_data->current_session = s;
00510     desktop_data->udp->s = s;
00511 
00512     for (i = 0; i < num_args; i++, p++) {
00513        switch (p->id) {
00514          case SC_CLIENT_LOCALE:
00515           log_f("if_le_SetSCValue(): SC_CLIENT_LOCALE: [%s]\n",p->value);
00516           if (session_data->locale != NULL) {
00517               free((char *)session_data->locale);
00518               session_data->locale = NULL;
00519           }
00520           session_data->locale = (char *)strdup(p->value);
00521           break;
00522          case SC_TRIGGER_ON_NOTIFY:
00523           proc_key_switch_conversion_event(udp, s, CONVERSION_ON, (char *)session_data->locale);
00524            udp->unit_desktop_switch_hotkey_profile(udp, s);
00525           break;
00526                 
00527          case SC_TRIGGER_OFF_NOTIFY:
00528           log_f("SC_TRIGGER_OFF_NOTIFY\n");
00529           proc_key_switch_conversion_event(udp, s, CONVERSION_OFF, (char *)NULL);
00530           break;
00531                 
00532          case SC_REALIZE:
00533           log_f("SC_REALIZE [0x%x] \n", s);
00534           if (is_trigger_on_required(udp, session_data->locale)) {
00535             proc_key_switch_conversion_event(udp, s, CONVERSION_ON, (char *)session_data->locale);
00536           }
00537           session_data->hkp_notify_flag = False;
00538           break;
00539 
00540          default:
00541           break;
00542        }
00543     }
00544   
00545     return True;
00546 }
00547 
00548 IMText *
00549 if_le_ResetSC(
00550     iml_session_t * s
00551 )
00552 {
00553     log_f("if_le_ResetSC(s=%x)\n\n", (unsigned int) s);
00554     return (IMText *) NULL;
00555 }
00556 
00557 void 
00558 if_le_SetSCFocus(
00559     iml_session_t * s
00560 )
00561 {
00562     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *)(s->desktop->specific_data);
00563     MyDataPerSession *session_data = (MyDataPerSession *) s->specific_data;
00564     unit_desktop_t *udp = desktop_data->udp;
00565 
00566     log_f("if_le_SetSCFocus() s:%x, current_session:%x, udp:0x%x\n", (unsigned int)s, (unsigned int)desktop_data->current_session, (unsigned int)desktop_data->udp);
00567 
00568     desktop_data->current_session = s;
00569     desktop_data->udp->s = s;
00570     le_status_draw(udp, s);
00571     if (!session_data->hkp_notify_flag) {
00572       udp->unit_desktop_switch_hotkey_profile(udp, s);
00573       session_data->hkp_notify_flag = True;
00574     }
00575     /*
00576       if (s->desktop->session_count == 1) {
00577       if (!add_listener_flag) {
00578       log_f("if_le_SetSCFocus() : Loading Engines ...\n");
00579       udp = unit_if()->ud_list;
00580       udp->unit_desktop_add_listener(udp, s); 
00581       add_listener_flag = True;
00582       }
00583       }
00584     */
00585     return;
00586 }
00587 
00588 void 
00589 if_le_UnsetSCFocus(
00590     iml_session_t * s
00591 )
00592 {
00593     log_f("if_le_UnsetSCFocus() s:%x\n", (unsigned int) s);
00594 }
00595 
00596 void 
00597 if_le_SendEvent(
00598     iml_session_t * s, 
00599     IMInputEvent * ev
00600 )
00601 {
00602     MyDataPerDesktop *desktop_data = (MyDataPerDesktop *)(s->desktop->specific_data);
00603     unit_desktop_t *udp = desktop_data->udp;
00604 
00605     log_f("if_le_SendEvent session=%x\n", (unsigned int) s);
00606     if (ev) {
00607        if (ev->type == IM_EventKeyList) {
00608            log_f("Keyboard Event\n");
00609            proc_key_event(udp, s, (IMKeyListEvent *)ev);
00610        } else if (ev->type == IM_HotkeyEvent) {
00611            log_f("Hotkey Event\n");
00612            process_hotkey_event(udp, s, (IMKeyListEvent *)ev);
00613         }
00614     }
00615 }
00616 
00617 Bool 
00618 is_trigger_on_required(
00619     unit_desktop_t *udp,
00620     char *locale
00621 )
00622 {
00623     int i;
00624 
00625     for (i=0 ; i<udp->gEngine_Num ; i++) {
00626         /*
00627         log_f("udp->modeList[%d]->locale_name [%s], locale [%s]\n", i, udp->modeList[i]->locale_name, locale);
00628         log_f("udp->modeList[%d]->default_state [%s]\n", i, udp->modeList[i]->default_state);
00629         */
00630        if ((!strcmp(udp->modeList[i]->locale_name, locale)) && (!strcmp(udp->modeList[i]->default_state, (char *)"CONV_ON")))
00631            return True;
00632     }
00633     return False;
00634 }
00635 
00636 int 
00637 get_list_of_supported_locales()
00638 {
00639     char      file_name[PATH_MAX], line[MAX_LINE_LEN]; 
00640     char        *file_buf, *curr_ptr;
00641     char      keyCodeName[NAME_MAX], modifierName[NAME_MAX];
00642     char      locale_name[NAME_MAX], *kptr, *ptr;
00643     
00644     int       len, n, nfread, fsize, fd;
00645     int       locale_flag = ENCODE_ERROR;
00646     int       generic_flag = 0;
00647     int       switch_to_next_locale_flag = 0;
00648     int       switch_to_prev_locale_flag = 0;
00649     int       switch_layout_flag = 0;
00650     FILE      *fp;
00651     struct stat buf;
00652 
00653     n = 0;
00654 
00655     memset((char *)keyCodeName,'\0',sizeof(keyCodeName));
00656     memset((char *)modifierName,'\0',sizeof(modifierName));
00657 
00658     snprintf(file_name, sizeof(file_name), "%s/%s/%s",  DEFAULT_ENGINE_PATH, 
00659             XAUX_LOCALE_NAME, 
00660             SYSTEM_PROFILE_NAME);
00661 
00662     log_f("get_list_of_supported_locales: file name :%s\n",file_name);
00663     fp = fopen(file_name, "r");
00664     if (! fp)
00665        return (-1);
00666 
00667     fd = fileno((FILE *)fp);
00668     if (fstat(fd, &buf) < 0) {
00669         return -1;
00670     }
00671     fsize = buf.st_size;
00672     log_f("get_list_of_supported_locales: fsize [%d]\n",fsize);
00673     file_buf = (char *)calloc(fsize, sizeof(char));
00674     nfread = fread(file_buf, fsize, 1, fp);
00675     log_f("get_list_of_supported_locales: nfread [%d]\n",nfread);
00676 
00677     curr_ptr = 0;
00678 
00679     do {
00680         get_line(file_buf, fsize, &curr_ptr, line);
00681 
00682        if (line[0] == '\0') break;
00683        if (line[0] == '#') continue;
00684 
00685        len = strlen(line);
00686        if (line[0] == '[' && line[len-1] == ']') {
00687            /* compute locale_flag */
00688            ptr = line + 1;
00689            while(isspace(*ptr)) ptr++;
00690 
00691            memset((char *)locale_name,'\0',sizeof(locale_name));
00692            /* get locale section name */
00693            kptr = locale_name;
00694            while (*ptr && !isspace(*ptr) && *ptr!=']') 
00695               *(kptr++) = *(ptr++);
00696            *kptr = '\0';
00697 
00698            /* get locale section name */
00699            if (!strcasecmp(locale_name, COMMON_ENGINE_PATH))
00700               locale_flag = ENCODES_NUM;
00701            else if(!strcasecmp(locale_name, GENERIC_IM_TABLE_NAME)){
00702               generic_flag = 1;
00703               continue;
00704            }else if(!strcasecmp(locale_name, SWITCH_TO_NEXT_LOCALE)){
00705                 switch_to_next_locale_flag = 1;
00706               continue;
00707            }else if(!strcasecmp(locale_name, SWITCH_TO_PREV_LOCALE)){
00708               switch_to_prev_locale_flag = 1;
00709               continue;
00710            }else if(!strcasecmp(locale_name, SWITCH_LAYOUT_NAME)){
00711               switch_layout_flag = 1;
00712               continue;
00713            } 
00714 
00715            if(!generic_flag)
00716               locale_flag = get_encodeid_from_locale(locale_name);
00717            else{
00718               locale_flag = ENCODES_NUM;
00719 
00720               locales[n].id = (char *)strdup(locale_name);
00721               locales[n].name = (UTFCHAR *)calloc(strlen(locale_name)+1,sizeof(UTFCHAR));
00722               CpyUTFCHAR(locale_name, locales[n].name);
00723               n++;
00724            }
00725            continue;
00726        }else
00727            continue;
00728     } while (1);
00729     locales[n].id = (char *)NULL;
00730     locales[n].name = (UTFCHAR *)NULL;
00731     fclose(fp);
00732     return(n);
00733 }
00734 
00735 int 
00736 CpyUTFCHAR(
00737     char *src, 
00738     UTFCHAR *dest
00739 )
00740 {
00741     int i;
00742 
00743     for(i=0;*src;i++){
00744        *dest++ = *src++;
00745     }
00746     *dest = 0;
00747     return i;
00748 }
00749 
00750 IMHotkeyProfileStruct *
00751 get_hkp_from_hkm(
00752     int profile_id
00753 )
00754 {
00755     int i;
00756     IMHotkeyProfileStruct *hkp = NULL;
00757 
00758     if (g_hkms) {
00759        if (g_hkms->hkps) {
00760            for (i=0; i<g_hkms->num_hotkey_profiles; i++) {
00761               if (g_hkms->hkps[i].profile_id == profile_id) {
00762                   hkp = (IMHotkeyProfileStruct *) calloc(1, sizeof(IMHotkeyProfileStruct));
00763                   hkp->profile_id = g_hkms->hkps[i].profile_id;
00764                   hkp->scope = g_hkms->hkps[i].scope;
00765                   hkp->name = g_hkms->hkps[i].name;
00766                   hkp->num_hotkeys = g_hkms->hkps[i].num_hotkeys;
00767                   hkp->hks = g_hkms->hkps[i].hks;
00768                   return hkp;
00769                 }
00770            }
00771        }
00772     }
00773     return hkp;
00774 }
00775 
00776 /* Local Variables: */
00777 /* c-file-style: "iiim-project" */
00778 /* End: */