Back to index

im-sdk  12.3.91
le_object.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 #include "le_info.h"
00004 #include "le_object.h"
00005 
00006 extern char lename_string[];
00007 extern UTFCHAR lename_utf_string[];
00008 
00009 static IMLEName lename = { lename_string, lename_utf_string };
00010 
00011 #define  LE_VERSION    "2.0"
00012 
00013 extern LeInfoRec *le_info;
00014 extern UTFCHAR *le_locale_name[];
00015 
00016 IMLocale locales[MAX_SUPPORT_LOCALES];
00017 
00018 LeObjectRec *le_object_new()
00019 {
00020     LeObjectRec *le_object = NULL;
00021     IMObjectDescriptorStruct *im_objects, *l;
00022 
00023     int i, j, num_input_methods;
00024     int num_locales;
00025 
00026     if (le_info == NULL || le_info->num_input_methods <= 0)
00027         return NULL;
00028 
00029     le_object = (LeObjectRec *) calloc(1, sizeof(LeObjectRec));
00030     if (le_object == NULL)
00031         return NULL;
00032 
00033     /* initilize the IMObjectDescriptorStruct */
00034     im_objects = (IMObjectDescriptorStruct *) calloc(2, sizeof(IMObjectDescriptorStruct));
00035     if (im_objects == NULL) {
00036         free ((char *)locales);
00037        free ((char *)le_object);
00038        return NULL;
00039     }
00040 
00041     l = im_objects;
00042     l->leid = lename_string;       /* engine id */
00043     l->type = IM_DOWNLOADINGOBJECT_BINGUI_TYPE;  /* object type */
00044     l->name = lename_utf_string;
00045     l->name_length = UTFCHARLen(lename_utf_string);
00046     l->domain = "com.sun";
00047     l->scope = lename_string;
00048 
00049     l->path = NULL;
00050     l->signature = "";
00051     l->basepath = NULL;            /* only for CCDEF */
00052     l->encoding = NULL;            /* only for CCDEF */
00053 
00054     /* initilize the le_object info */
00055     le_object->version = LE_VERSION;
00056 
00057     le_object->lename = (IMLEName *) &lename;
00058 
00059     memset(locales, 0, MAX_SUPPORT_LOCALES * sizeof (IMLocale));
00060 
00061     num_locales = 0;
00062     for (i = 0; i < le_info->num_input_methods; i ++) {
00063         MSymbol m_lang = le_info->input_methods[i]->language;
00064         char *lang = msymbol_name(m_lang);
00065         char *standard_lang_name;
00066         int find = 0;
00067 
00068         if (m_lang == Mt)
00069             continue;
00070 
00071         if (le_info_check_language_disabled(le_info, lang))
00072             continue;
00073 
00074         standard_lang_name = (char *)le_info_get_standard_language_name(lang);
00075         if (!standard_lang_name || !*standard_lang_name)
00076             continue;
00077 
00078         for (j = 0; j < num_locales; j++) {
00079             if (!strcasecmp(locales[j].id, standard_lang_name)) {
00080                 find = 1;
00081                 break;
00082             }
00083         }
00084 
00085         if (find == 0) {
00086             locales[num_locales].id = (char *)strdup(standard_lang_name);
00087             locales[num_locales].name = (UTFCHAR *)calloc(strlen(standard_lang_name)+1,sizeof(UTFCHAR));
00088            for (j = 0; j < strlen(standard_lang_name); j++)
00089                 locales[num_locales].name[j] = standard_lang_name[j];
00090             num_locales ++;
00091             if (num_locales >= MAX_SUPPORT_LOCALES - 1)
00092                 break;
00093         }
00094     }
00095     locales[num_locales].id = NULL;
00096     locales[num_locales].name = NULL;
00097 
00098     le_object->locales = (IMLocale **) &locales;
00099 
00100     le_object->objects = im_objects;
00101 
00102     return le_object;
00103 }
00104 
00105 void le_object_destroy(LeObjectRec *le_object)
00106 {
00107     int i;
00108     IMObjectDescriptorStruct *im_objects;
00109 
00110     if (le_object != NULL) {
00111         im_objects = le_object->objects;
00112         if (im_objects != NULL)
00113             free((char *) im_objects);
00114 
00115         free((char *) le_object);
00116     }
00117 
00118     for (i = 0; i < MAX_SUPPORT_LOCALES; i++) {
00119         if (locales[i].id)
00120             free ((char *)locales[i].id);
00121         if (locales[i].name)
00122             free ((char *)locales[i].name);
00123     }
00124 
00125     return;
00126 }