Back to index

im-sdk  12.3.91
IIIMPUtil.cpp
Go to the documentation of this file.
00001 #include <config.h>
00002 #include <stdlib.h>
00003 #include "IIIMPUtil.hh"
00004 
00005 IIIMP_string*
00006 convert_IMText_to_iiimp_string(
00007     IIIMP_data_s *data_s,
00008     IMText *pimtext
00009 )
00010 {
00011     return iiimp_string_new(data_s,
00012                          pimtext->char_length,
00013                          pimtext->text.utf_chars);
00014 }
00015 
00016 IIIMP_text*
00017 convert_IMText_to_iiimp_text(
00018     IIIMP_data_s *data_s,
00019     IMText *pimtext
00020 )
00021 {
00022     unsigned int i, j;
00023     IIIMP_text *ptext;
00024     IIIMP_char_with_feedback *phead;
00025 
00026     if (!pimtext) {
00027        phead = NULL;
00028     } else {
00029        // convert IIIMP feedback.
00030 
00031        const int IIIMP_FEEDBACK_MAX_SLOTS = 32;
00032        IIIMP_feedback_attr fbattrtmp[IIIMP_FEEDBACK_MAX_SLOTS];
00033        IIIMP_char_with_feedback *pcur, *pcur2;
00034        IIIMP_feedback_attr_list *pattr;
00035        IMFeedbackList *pfbl;
00036        IMFeedback *pfb;
00037        UTFCHAR *pu;
00038 
00039        phead = pcur = NULL;
00040        for (i = 0, pu= pimtext->text.utf_chars, pfbl = pimtext->feedback;
00041             i < pimtext->char_length;
00042             i++, pu++, pfbl++) {
00043            if (pfbl->count_feedbacks > (sizeof(fbattrtmp) / sizeof(fbattrtmp[0]))) {
00044               goto error;
00045            }
00046            for (j = 0, pfb = pfbl->feedbacks;
00047                j < pfbl->count_feedbacks;
00048                j++, pfb++) {
00049               fbattrtmp[j].nbyte = 8; // !!!! Is it correct?  I regard nbyte member
00050               // as byte size of IIIMP stream representation,
00051               // not structure system-dependent size.
00052               fbattrtmp[j].id = pfb->type;
00053               fbattrtmp[j].feedback = pfb->value;
00054            }
00055 
00056            pattr = iiimp_feedback_attr_list_new(data_s, pfbl->count_feedbacks, fbattrtmp);
00057            if (!pattr) goto error;
00058            pcur2 = iiimp_char_with_feedback_new(data_s, *pu, pattr);
00059            if (!pcur2) {
00060               iiimp_feedback_attr_list_delete(data_s, pattr);
00061               goto error;
00062            }
00063            if (pcur) {
00064               pcur->next = pcur2;
00065               pcur = pcur2;
00066            } else {
00067               phead = pcur = pcur2;
00068            }
00069        }
00070     }
00071 
00072 #if 0 // TODO!!
00073     {
00074        // convert IIIMP annotation
00075        IMAnnotation *pima;
00076        IMAnnotationValue *pimav;
00077 
00078        for (i = 0, pima = pimtext->annotations;
00079             i < pimtext->count_annotations;
00080             i++, pima++) {
00081            for (j = 0, pimav = pima->values;
00082                j < pima->num_values;
00083                j++, pimav++) {
00084               pimav = iiimp_annotation_new(data_s, ...);
00085            }
00086        
00087        }
00088     }
00089 #endif
00090 
00091     ptext = iiimp_text_new(data_s, phead, NULL);
00092     if (!ptext) goto error;
00093 
00094     return ptext;
00095 
00096 error:
00097     if (phead) iiimp_char_with_feedback_delete(data_s, phead);
00098     return NULL;
00099 }
00100 
00101 
00102 IIIMP_contents*
00103 convert_IMText_to_iiimp_contents_string(
00104     IIIMP_data_s *data_s,
00105     IMText *pimtext
00106 )
00107 {
00108     IIIMP_string *pstr = convert_IMText_to_iiimp_string(data_s, pimtext);
00109     if (!pstr) return NULL;
00110     return iiimp_contents_string_new(data_s, pstr);
00111 }
00112 
00113 IIIMP_contents*
00114 convert_IMText_to_iiimp_contents_text(
00115     IIIMP_data_s *data_s,
00116     IMText *pimtext
00117 )
00118 {
00119     IIIMP_text *ptext = convert_IMText_to_iiimp_text(data_s, pimtext);
00120     if (!ptext) return NULL;
00121     IIIMP_contents *pcont = iiimp_contents_text_new(data_s, ptext);
00122     if (!pcont) {
00123        iiimp_text_delete(data_s, ptext);
00124        return NULL;
00125     }
00126 
00127     return pcont;
00128 }
00129 
00130 
00131 ICAttribute
00132 convert_iiimp_icattr(
00133     IIIMP_icattribute *pattr
00134 )
00135 {
00136     // TODO character subsets...
00137     ICAttribute icattr;
00138     for (; pattr; pattr = pattr->next) {
00139        switch (pattr->id) {
00140          case IIIMP_ICATTRIBUTE_INPUT_LANGUAGE:
00141           icattr.set_inputlanguage(CONV_IIIMP_STR(pattr->value.input_language));
00142           break;
00143          case IIIMP_ICATTRIBUTE_CHARACTER_SUBSETS:
00144          {
00145              int i;
00146              IIIMP_card32 *p = pattr->value.character_subsets->ptr;
00147              int n = pattr->value.character_subsets->count;
00148              IMCharSubsets imcs;
00149 
00150              for (i = 0; i < n; i++, p++) {
00151                 imcs.add_csidx(*p);
00152              }
00153              icattr.set_charsubsets(imcs);
00154          }
00155          break;
00156          case IIIMP_ICATTRIBUTE_INPUT_METHOD_NAME:
00157          {
00158            if (pattr->value.input_method_name)
00159              {
00160               IIIMP_card16 *imename = pattr->value.input_method_name->ptr;
00161               IIIMP_card16 *lename, *p;
00162               const char ime_delimiter = '-';
00163               int i = 0, len = pattr->value.input_method_name->len;
00164 
00165               /* check whether the name of input method engine is included,
00166                * set it to inputengine if yes.
00167                */
00168               p = lename = imename;
00169               while (i < len && *p && *p != ime_delimiter) { ++p; ++i;}
00170               if (i != len && *p == ime_delimiter)
00171                 {
00172                    *p++ = 0x0;
00173                    imename = p;
00174 
00175                    icattr.set_inputengine (u16string (imename, len - i));
00176                    icattr.set_inputmethod (u16string (lename, i));
00177                 }
00178               else
00179                    icattr.set_inputmethod(CONV_IIIMP_STR(pattr->value.input_method_name));
00180              }
00181           }
00182           break;
00183 #if 0
00184          case IIIMP_ICATTRIBUTE_INPUT_METHOD:
00185 #endif
00186          default:
00187           break;
00188        }
00189     }
00190 
00191     return icattr;
00192 }
00193 
00194 IIIMP_card16
00195 convert_IMObject_type_to_iiimp_predefined_attribid(
00196     enum IMObject::OBJTYPE otype
00197 )
00198 {
00199     switch (otype){
00200       case IMObject::EIMIL_CONFIG:
00201        return IIIMP_IMATTRIBUTE_CHARACTER_CONVERSION_DEFINITION_RULE;
00202       case IMObject::IMDESCRIPTOR:
00203        return IIIMP_IMATTRIBUTE_INPUT_METHOD_LIST;
00204       case IMObject::BINARY_GUI:
00205        return IIIMP_IMATTRIBUTE_BINARY_GUI_OBJECT;
00206       case IMObject::BINARY_LWE:
00207        return IIIMP_IMATTRIBUTE_BINARY_LIGHT_WEIGHT_ENGINE_OBJECT;
00208       case IMObject::JAVA_GUI:
00209        return IIIMP_IMATTRIBUTE_JAR_GUI_OBJECT;
00210       case IMObject::JAVA_LWE:
00211        return IIIMP_IMATTRIBUTE_JAR_LIGHT_WEIGHT_ENGINE_OBJECT;
00212       case IMObject::SCRIPT_GUI:
00213        return IIIMP_IMATTRIBUTE_SCRIPT_GUI_OBJECT;
00214       case IMObject::SCRIPT_LWE:
00215        return IIIMP_IMATTRIBUTE_SCRIPT_LIGHT_WEIGHT_ENGINE_OBJECT;
00216 
00217       case IMObject::UNKNOWN:
00218       case IMObject::OPERATION:
00219       case IMObject::NUMBER_VARIABLE:
00220       case IMObject::BOOL_VARIABLE:
00221       case IMObject::CHAR_VARIABLE:
00222       case IMObject::MTEXT_VARIABLE:
00223       case IMObject::EVENT_VARIABLE:
00224 
00225       case IMObject::NUMBER_PROPERTY:
00226       case IMObject::BOOL_PROPERTY:
00227       case IMObject::CHAR_PROPERTY:
00228       case IMObject::MTEXT_PROPERTY:
00229       case IMObject::EVENT_PROPERTY:
00230       default:
00231        ERROR_INTERNAL("Cannot convert this object type %d to IIIMP category.");
00232    }
00233     return 0;
00234 }
00235 
00236 /* Local Variables: */
00237 /* c-file-style: "iiim-project" */
00238 /* End: */