Back to index

im-sdk  12.3.91
input-method.c
Go to the documentation of this file.
00001 /*
00002   input-method.c
00003 */
00004 
00005 #ifdef HAVE_CONFIG_H
00006 #include <config.h>
00007 #endif
00008 
00009 #ifdef HAVE_STDLIB_H
00010 #include <stdlib.h>
00011 #endif
00012 #ifdef HAVE_STRING_H
00013 #include <string.h>
00014 #endif
00015 #ifdef HAVE_MEMORY_H
00016 #include <memory.h>
00017 #endif
00018 
00019 #include "iiimcfint.h"
00020 
00021 IIIMF_status
00022 iiimcf_unregister_input_method_list(
00023     int n,
00024     IIIMCF_input_method_rec **ppi
00025 )
00026 {
00027     IIIMCF_input_method_rec **pp, *p;
00028     int i;
00029 
00030     if (!ppi) return IIIMF_STATUS_FAIL;
00031     for (pp = ppi, i = 0; i < n; i++, pp++) {
00032        p = *pp;
00033        if (p) {
00034            if (p->imname) free(p->imname);
00035            if (p->hrn) free(p->hrn);
00036            if (p->domain) free(p->domain);
00037            if (p->pplangs) iiimcf_unregister_langs(p->num_langs, p->pplangs);
00038             if (p->ppimeinfos) iiimcf_unregister_imeinfos(p->num_imeinfos, p->ppimeinfos);
00039            free(p);
00040        }
00041     }
00042     free(ppi);
00043     return IIIMF_STATUS_SUCCESS;
00044 }
00045 
00046 static IIIMF_status
00047 iiimcf_register_input_method_langs(
00048     IIIMP_language *piml,
00049     int *pnum,
00050     IIIMCF_language_rec ***pppl
00051 )
00052 {
00053     IIIMCF_language_rec **ppl, *pl;
00054     IIIMP_language *p;
00055     IIIMP_card16 *pu;
00056     char *plang_id, *pc;
00057     int i, j, n;
00058 
00059     for (n = 0, p = piml; p; p = p->next) n++;
00060     ppl = (IIIMCF_language_rec**) malloc(sizeof(IIIMCF_language_rec*) * n);
00061     if (!ppl) return IIIMF_STATUS_MALLOC;
00062     memset(ppl, 0, sizeof(IIIMCF_language_rec*) * n);
00063 
00064     for (i = 0, p = piml; i < n; i++, p = p->next) {
00065        pl = (IIIMCF_language_rec*) malloc(sizeof(*pl));
00066        if (!pl) {
00067            iiimcf_unregister_langs(n, ppl);
00068            return IIIMF_STATUS_MALLOC;
00069        }
00070        memset(pl, 0, sizeof(*pl));
00071        ppl[i] = pl;
00072        plang_id = (char*) malloc(sizeof(char) * (p->id->len + 1));
00073        if (!plang_id) {
00074            iiimcf_unregister_langs(n, ppl);
00075            return IIIMF_STATUS_MALLOC;
00076        }
00077        for (j = 0, pu = p->id->ptr, pc = plang_id;j < p->id->len; j++) {
00078            *pc++ = (*pu++ & 0x7F);
00079        }
00080        *pc = '\0';
00081        pl->lang_id = plang_id;
00082 
00083        pl->hrn = iiimcf_make_string(p->hrn->ptr, p->hrn->len);
00084        if (!pl->hrn) {
00085            iiimcf_unregister_langs(n, ppl);
00086            return IIIMF_STATUS_MALLOC;
00087        }
00088     }
00089 
00090     *pnum = n;
00091     *pppl = ppl;
00092 
00093     return IIIMF_STATUS_SUCCESS;
00094 }
00095 
00096 static IIIMF_status
00097 iiimcf_register_input_method_imeinfos(
00098     IIIMP_imeinfo *pimi,
00099     int *pnum,
00100     IIIMCF_imeinfo_rec ***pppi
00101 )   
00102 {
00103     IIIMCF_imeinfo_rec **ppi = NULL, *pi;
00104     IIIMP_imeinfo *p;
00105     int i, j, n = 0;
00106     char *ime_id, *pc;
00107     IIIMP_card16 *pu;
00108 
00109     if (!pimi) goto IME_INFO_REGISTER_END;
00110     for (n = 0, p = pimi; p; p = p->next) n++;
00111     ppi = (IIIMCF_imeinfo_rec**) malloc(sizeof(IIIMCF_imeinfo_rec*) * n);
00112     if (!ppi) return IIIMF_STATUS_MALLOC;
00113     memset(ppi, 0, sizeof(IIIMCF_imeinfo_rec*) * n);
00114 
00115     for (i = 0, p = pimi; i < n; i++, p = p->next) {
00116         pi = (IIIMCF_imeinfo_rec*) malloc(sizeof(*pi));
00117         if (!pi) {
00118             iiimcf_unregister_imeinfos(n, ppi);
00119             return IIIMF_STATUS_MALLOC;
00120        }
00121         memset(pi, 0, sizeof(*pi));
00122         ppi[i] = pi;
00123     
00124        pi->enable = p->enable;
00125 
00126        ime_id = (char *) malloc (sizeof (char) * (p->ime_id->len + 1));
00127        if (!ime_id) {
00128             iiimcf_unregister_imeinfos(n, ppi);
00129             return IIIMF_STATUS_MALLOC;
00130        }
00131        for (j = 0, pu = p->ime_id->ptr, pc = ime_id;j < p->ime_id->len; j++) {
00132             *pc++ = (*pu++ & 0x7F);
00133         }
00134         *pc = '\0';
00135         pi->ime_id = ime_id;
00136 
00137        pi->imename = iiimcf_make_string (p->imename->ptr, p->imename->len);
00138         if (!pi->imename) {
00139             iiimcf_unregister_imeinfos(n, ppi);
00140             return IIIMF_STATUS_MALLOC;
00141        }
00142 
00143        pi->version = iiimcf_make_string (p->version->ptr, p->version->len);
00144         if (!pi->version) {
00145             iiimcf_unregister_imeinfos(n, ppi);
00146             return IIIMF_STATUS_MALLOC;
00147        }
00148        pi->description = iiimcf_make_string (p->description->ptr, p->description->len);
00149         if (!pi->description) {
00150             iiimcf_unregister_imeinfos(n, ppi);
00151             return IIIMF_STATUS_MALLOC;
00152        }
00153        pi->author = iiimcf_make_string (p->author->ptr, p->author->len);
00154         if (!pi->author) {
00155             iiimcf_unregister_imeinfos(n, ppi);
00156             return IIIMF_STATUS_MALLOC;
00157        }
00158        pi->copyright = iiimcf_make_string (p->copyright->ptr, p->copyright->len);
00159         if (!pi->copyright) {
00160             iiimcf_unregister_imeinfos(n, ppi);
00161             return IIIMF_STATUS_MALLOC;
00162        }
00163        pi->reserved1 = iiimcf_make_string (p->reserved1->ptr, p->reserved1->len);
00164         if (!pi->reserved1) {
00165             iiimcf_unregister_imeinfos(n, ppi);
00166             return IIIMF_STATUS_MALLOC;
00167        }
00168        pi->reserved2 = iiimcf_make_string (p->reserved2->ptr, p->reserved2->len);
00169         if (!pi->reserved2) {
00170             iiimcf_unregister_imeinfos(n, ppi);
00171             return IIIMF_STATUS_MALLOC;
00172        }
00173     }
00174 
00175 IME_INFO_REGISTER_END:
00176     *pnum = n;
00177     *pppi = ppi;
00178 
00179     return IIIMF_STATUS_SUCCESS;
00180 }
00181 
00182 IIIMF_status
00183 iiimcf_register_input_method_list(
00184     IIIMCF_handle_rec *ph,
00185     IIIMP_inputmethod_descriptor *piiimp_imlist
00186 )
00187 {
00188     IIIMF_status st;
00189     int i, n;
00190     IIIMP_inputmethod_descriptor *pimd;
00191     IIIMCF_input_method_rec **ppi, *pi;
00192 
00193     iiimcf_unregister_input_method_list(ph->num_input_methods,
00194                                    ph->ppinput_methods);
00195 
00196     ph->ppinput_methods = NULL;
00197     ph->num_input_methods = 0;
00198 
00199     for (n = 0, pimd = piiimp_imlist; pimd; pimd = pimd->next) n++;
00200 
00201     ppi = (IIIMCF_input_method_rec**) malloc(sizeof(*ppi) * n);
00202     if (!ppi) return IIIMF_STATUS_MALLOC;
00203     memset(ppi, 0, sizeof(*ppi) * n);
00204 
00205     for (i = 0, pimd = piiimp_imlist;
00206         i < n; i++, pimd = pimd->next) {
00207        pi = (IIIMCF_input_method_rec*) malloc(sizeof(*pi));
00208        if (!pi) {
00209            iiimcf_unregister_input_method_list(n, ppi);
00210            return IIIMF_STATUS_MALLOC;
00211        }
00212        memset(pi, 0, sizeof(*pi));
00213        ppi[i] = pi;
00214        pi->id = pimd->id;
00215        pi->imname = iiimcf_make_string(pimd->idname->ptr, pimd->idname->len);
00216        pi->hrn = iiimcf_make_string(pimd->hrn->ptr, pimd->hrn->len);
00217        pi->domain = iiimcf_make_string(pimd->rdun->ptr, pimd->rdun->len);
00218        if ((!pi->imname) || (!pi->hrn)) {
00219            iiimcf_unregister_input_method_list(n, ppi);
00220            return IIIMF_STATUS_MALLOC;
00221        }
00222        st = iiimcf_register_input_method_langs(pimd->language,
00223                                           &pi->num_langs,
00224                                           &pi->pplangs);
00225        if (st != IIIMF_STATUS_SUCCESS) {
00226            iiimcf_unregister_input_method_list(n, ppi);
00227            return st;
00228        }
00229         st = iiimcf_register_input_method_imeinfos(pimd->imeinfo,
00230                                                 &pi->num_imeinfos,
00231                                                 &pi->ppimeinfos);
00232         if (st != IIIMF_STATUS_SUCCESS) {
00233             iiimcf_unregister_input_method_list(n, ppi);
00234             return st;
00235         }
00236     }
00237 
00238     ph->num_input_methods = n;
00239     ph->ppinput_methods = ppi;
00240 
00241     return IIIMF_STATUS_SUCCESS;
00242 }
00243 
00244 /********************************************************************************
00245                                  APIs
00246 ********************************************************************************/
00247 
00248 IIIMF_status
00249 iiimcf_get_supported_input_methods(
00250     IIIMCF_handle handle,
00251     int *pnum_input_methods,
00252     IIIMCF_input_method **ppinput_methods
00253 )
00254 {
00255 
00256     IIIMCF_handle_rec *ph = (IIIMCF_handle_rec*) handle;
00257 
00258     if (ppinput_methods) *ppinput_methods = ph->ppinput_methods;
00259     if (pnum_input_methods) *pnum_input_methods = ph->num_input_methods;
00260 
00261     return IIIMF_STATUS_SUCCESS;
00262 }
00263 
00264 IIIMF_status
00265 iiimcf_get_input_method_desc(
00266     IIIMCF_input_method input_method,
00267     const IIIMP_card16** pinput_method_idname,
00268     const IIIMP_card16** pinput_method_hrn,
00269     const IIIMP_card16** pinput_method_domain
00270 )
00271 {
00272     IIIMCF_input_method_rec *pi = (IIIMCF_input_method_rec*) input_method;
00273 
00274     if (pinput_method_idname) *pinput_method_idname = pi->imname;
00275     if (pinput_method_hrn) *pinput_method_hrn = pi->hrn;
00276     if (pinput_method_domain) *pinput_method_domain = pi->domain;
00277 
00278     return IIIMF_STATUS_SUCCESS;
00279 }
00280 
00281 IIIMF_status
00282 iiimcf_get_input_method_languages(
00283     IIIMCF_input_method input_method,
00284     int *pinput_method_language_size,
00285     IIIMCF_language **pplanguages
00286 )
00287 {
00288     IIIMCF_input_method_rec *pi = (IIIMCF_input_method_rec*) input_method;
00289 
00290     if (pinput_method_language_size)
00291        *pinput_method_language_size = pi->num_langs;
00292     if (pplanguages)
00293        *pplanguages = pi->pplangs;
00294 
00295     return IIIMF_STATUS_SUCCESS;
00296 }
00297 
00298 IIIMF_status
00299 iiimcf_set_input_method_name (
00300     IIIMCF_input_method input_method,
00301     const IIIMP_card16* input_method_name
00302 )
00303 {
00304     IIIMCF_input_method_rec *pi = (IIIMCF_input_method_rec*) input_method;
00305 
00306     if (pi->imname) free (pi->imname);
00307     pi->imname = input_method_name;
00308 
00309     return IIIMF_STATUS_SUCCESS;
00310 }
00311 
00312 IIIMF_status
00313 iiimcf_get_input_method_imeinfos(
00314     IIIMCF_input_method input_method,
00315     int *pinput_method_imeinfo_size,
00316     const IIIMCF_imeinfo_rec ***ppimeinfos
00317 )
00318 {
00319     IIIMCF_input_method_rec *pi = (IIIMCF_input_method_rec*) input_method;
00320 
00321     if (pinput_method_imeinfo_size)
00322         *pinput_method_imeinfo_size = pi->num_imeinfos;
00323     if (ppimeinfos)
00324         *ppimeinfos = pi->ppimeinfos;
00325 
00326     return IIIMF_STATUS_SUCCESS;
00327 }
00328 
00329 IIIMF_status
00330 iiimcf_is_capability_supported(
00331     IIIMCF_handle handle,
00332     int capability
00333 )
00334 {
00335     IIIMCF_handle_rec *ph = (IIIMCF_handle_rec*) handle;
00336 
00337     if (0 != iiimp_data_s_capability(ph->data_s, capability)) {
00338        return IIIMF_STATUS_SUCCESS;
00339     } else {
00340        return IIIMF_STATUS_FAIL;
00341     }
00342 }
00343 
00344 /* Local Variables: */
00345 /* c-file-style: "iiim-project" */
00346 /* End: */