Back to index

im-sdk  12.3.91
EIMIL.h
Go to the documentation of this file.
00001 /*
00002   EIMIL.h
00003 */
00004 
00005 #ifndef _EIMIL_H_
00006 #define _EIMIL_H_
00007 
00008 #ifdef HAVE_CONFIG_H
00009 #include <config.h>
00010 #endif
00011 #include <IMProtocolStruct.h>
00012 
00013 #ifndef ASSERT
00014 #ifdef DEBUG
00015 #define ASSERT(X)                                \
00016 do {                                             \
00017     if (!(X)) {                                         \
00018        fprintf(stderr, "EIMIL ASSERT %s: %s (%s)",      \
00019               #X, __FILE__, __LINE__);           \
00020               abort();                           \
00021     }                                            \
00022 } while(0)
00023 #else
00024 #define ASSERT(X) ((void) 0)
00025 #endif
00026 #endif
00027 
00028 typedef CARD32BIT UTF32;
00029 typedef CARD16BIT UTF16;
00030 typedef CARD8BIT UTF8;
00031 typedef CARD32BIT EIMIL_TID;
00032 typedef CARD32BIT EIMIL_SYMID;
00033 typedef CARD8BIT Ebyte;
00034 typedef void* EIMIL_handle;
00035 #define EIMIL_VOID_HANDLE ((void*)0)
00036 
00037 /*
00038   Constants.
00039  */
00040 
00041 enum EIMIL_CATEGORY {
00042        EIMIL_CAT_VARIABLE,
00043        EIMIL_CAT_PROPERTY,
00044        EIMIL_CAT_FUNCTION,
00045        EIMIL_CAT_EXCEPTION,
00046        EIMIL_CAT_OPERATION,
00047        EIMIL_CAT_OPTIONAL
00048 };
00049 
00050 enum EIMIL_TYPE {
00051 /* bitwise type flags.  */
00052        EIMIL_TYPE_INVALID = 0,
00053        EIMIL_TYPE_NONE = (1 << 0),
00054        EIMIL_TYPE_BOOL = (1 << 1),
00055        EIMIL_TYPE_NUMBER = (1 << 2),
00056        EIMIL_TYPE_CHAR = (1 << 3),
00057        EIMIL_TYPE_MTEXT = (1 << 4),
00058        EIMIL_TYPE_EVENT = (1 << 5),
00059        EIMIL_TYPE_PROP = (1 << 6),
00060 /* special type attribute for unique objects.  */
00061        EIMIL_TYPE_NIL = (1 << 7),
00062        EIMIL_TYPE_T = -1,
00063        EIMIL_TYPE_FEEDBACK = -2,
00064        EIMIL_TYPE_CANDIDATES = -3,
00065 
00066        EIMIL_TYPE_CONST = (1 << 15),
00067        EIMIL_TYPE_ANY = (1 << 16),
00068        EIMIL_TYPE_OPTION1 = (1 << 17),
00069        EIMIL_TYPE_OPTION2 = (1 << 18)
00070 };
00071 
00072 enum EIMIL_SYMBOL_TYPE_ID {
00073        EIMIL_SYMBOL_ID_OPERATION = 1,
00074 
00075        EIMIL_SYMBOL_ID_VARIABLE_NUMBER = 2,
00076        EIMIL_SYMBOL_ID_VARIABLE_BOOL = 3,
00077        EIMIL_SYMBOL_ID_VARIABLE_CHAR = 4,
00078        EIMIL_SYMBOL_ID_VARIABLE_MTEXT = 5,
00079        EIMIL_SYMBOL_ID_VARIABLE_EVENT = 6,
00080        EIMIL_SYMBOL_ID_VARIABLE_PROP = 7,
00081 
00082        EIMIL_SYMBOL_ID_PROPERTY_MASK = 0x10,
00083        EIMIL_SYMBOL_ID_PROPERTY_NUMBER = (EIMIL_SYMBOL_ID_PROPERTY_MASK 
00084                                       | EIMIL_SYMBOL_ID_VARIABLE_NUMBER),
00085        EIMIL_SYMBOL_ID_PROPERTY_BOOL = (EIMIL_SYMBOL_ID_PROPERTY_MASK
00086                                     | EIMIL_SYMBOL_ID_VARIABLE_BOOL),
00087        EIMIL_SYMBOL_ID_PROPERTY_CHAR = (EIMIL_SYMBOL_ID_PROPERTY_MASK
00088                                     | EIMIL_SYMBOL_ID_VARIABLE_CHAR),
00089        EIMIL_SYMBOL_ID_PROPERTY_MTEXT = (EIMIL_SYMBOL_ID_PROPERTY_MASK
00090                                      | EIMIL_SYMBOL_ID_VARIABLE_MTEXT),
00091 
00092        EIMIL_SYMBOL_ID_EXCEPTION = 0x20,
00093 
00094        EIMIL_SYMBOL_ID_PRIVATE = 0x80,
00095        EIMIL_SYMBOL_ID_FUNCTION = 0x81
00096 };
00097 
00098 enum EIMIL_UNIVERSAL_SYMBOL_ID {
00099        EIMIL_SYMBOL_ID_NIL = (EIMIL_SYMBOL_ID_PRIVATE << 16) | 1,
00100        EIMIL_SYMBOL_ID_T = (EIMIL_SYMBOL_ID_PRIVATE << 16) | 2,
00101        EIMIL_SYMBOL_ID_FEEDBACK = (EIMIL_SYMBOL_ID_PRIVATE << 16) | 3,
00102        EIMIL_SYMBOL_ID_CANDIDATES = (EIMIL_SYMBOL_ID_PRIVATE << 16) | 4
00103 };
00104 
00105 /*
00106   value
00107 */
00108 
00109 /*struct EIMIL_value;*/
00110 typedef struct EIMIL_prop EIMIL_prop;
00111 typedef struct EIMIL_mtext_props EIMIL_mtext_props;
00112 typedef struct EIMIL_mtext EIMIL_mtext;
00113 typedef struct EIMIL_event EIMIL_event;
00114 typedef struct EIMIL_value EIMIL_value;
00115 typedef struct EIMIL_exception EIMIL_exception;
00116 typedef struct EIMIL_dependency EIMIL_dependency;
00117 typedef struct EIMIL_operation EIMIL_operation;
00118 typedef struct EIMIL_optional EIMIL_optional;
00119 typedef union EIMIL_object EIMIL_object;
00120 
00121 typedef struct EIMIL_function EIMIL_function;
00122 typedef struct EIMIL_variable EIMIL_variable;
00123 typedef struct EIMIL_tprop EIMIL_tprop;
00124 typedef struct EIMIL_message EIMIL_message;
00125 typedef struct EIMIL_symbol EIMIL_symbol;
00126 
00127 struct EIMIL_prop {
00128     int st;
00129     int end;
00130     EIMIL_symbol *property_sym;
00131     EIMIL_mtext *target;
00132     enum EIMIL_TYPE type;
00133     int size;
00134     EIMIL_value **pvals;
00135 };
00136 
00137 struct EIMIL_mtext_props {
00138     int num;
00139     EIMIL_symbol *property_sym;
00140     EIMIL_value **pprops;
00141 };
00142 
00143 struct EIMIL_mtext {
00144     int len;
00145     UTF32 *ustr;
00146     int slotsnum;
00147     EIMIL_mtext_props *pslots;
00148     int UIdatap;
00149 };
00150 
00151 struct EIMIL_event {
00152     UTF8* type;
00153     EIMIL_value *pv_val;
00154     EIMIL_value *pv_mod;
00155     EIMIL_value *pv_char;
00156     EIMIL_value *pv_mtext;
00157 };
00158 
00159 struct EIMIL_value {
00160     int refcount;
00161     enum EIMIL_TYPE type;
00162     union {
00163        UTF32 ch;
00164        int bool_val;
00165        int number;
00166        EIMIL_prop prop;
00167        EIMIL_mtext mtext;
00168        EIMIL_event event;
00169     } v;
00170 };
00171 
00172 /*
00173   symbol
00174 */
00175 
00176 struct EIMIL_function {
00177     enum EIMIL_TYPE type;
00178     void *def;
00179 };
00180 
00181 struct EIMIL_variable {
00182     enum EIMIL_TYPE type;
00183     int constp;
00184     EIMIL_value *pv;
00185 };
00186 
00187 struct EIMIL_tprop {
00188     enum EIMIL_TYPE type;
00189 };
00190 
00191 struct EIMIL_message {
00192     UTF32 *lang;
00193     UTF32 *msg;
00194 };
00195 
00196 struct EIMIL_exception {
00197     EIMIL_message *msgs;
00198 };
00199 
00200 struct EIMIL_dependency {
00201     int numdepends;
00202     EIMIL_symbol **depends;
00203     int numaffects;
00204     EIMIL_symbol **affects;
00205 };
00206 
00207 struct EIMIL_operation {
00208     int commitnotifyp;
00209     int numdepends;
00210     EIMIL_dependency *pdeps;
00211 };
00212 
00213 struct EIMIL_optional {
00214     int optnum1;
00215     int optnum2;
00216     void *optarg;
00217 };
00218 
00219 union EIMIL_object {
00220     EIMIL_function f;
00221     EIMIL_variable v;
00222     EIMIL_tprop p;
00223     EIMIL_exception e;
00224     EIMIL_operation o;
00225     EIMIL_optional opt;
00226 };
00227 
00228 struct EIMIL_symbol {
00229     enum EIMIL_CATEGORY cat;
00230     EIMIL_SYMID symbolid;
00231     int namelen;
00232     unsigned char *name;
00233     int publicp;
00234     EIMIL_object obj;
00235 };
00236 
00237 /*
00238   Handlers.
00239  */
00240 
00241 enum EIMIL_UICHANGE_FLAGS {
00242        EIMIL_ENABLE_PREEDIT,
00243        EIMIL_DISABLE_PREEDIT,
00244        EIMIL_UPDATE_PREEDIT,
00245 
00246        EIMIL_ENABLE_LOOKUP_CHOICE = 0x100,
00247        EIMIL_DISABLE_LOOKUP_CHOICE,
00248        EIMIL_UPDATE_LOOKUP_CHOICE,
00249 
00250        EIMIL_COMMIT_STRING = 0x200
00251 };
00252 
00253 typedef int (*EIMIL_EVENT_PROC)(
00254     EIMIL_handle eh,
00255     EIMIL_event *pevent
00256 );
00257 typedef int (*EIMIL_UICHANGE_PROC)(
00258     EIMIL_handle eh,
00259     EIMIL_value *pval,
00260     int uichange_flags
00261 );
00262 typedef int (*EIMIL_OPISSUE_PROC)(
00263     EIMIL_handle eh,
00264     EIMIL_symbol *psym
00265 );
00266 
00267 /*
00268   Functions.
00269  */
00270 #ifdef __cplusplus
00271 extern "C" {
00272 #endif
00273 
00274 /* EIMIL */
00275 
00276 extern EIMIL_symbol *pEIMIL_nil_sym, *pEIMIL_t_sym;
00277 extern EIMIL_symbol *pEIMIL_feedback_sym;
00278 extern EIMIL_symbol *pEIMIL_candidates_sym;
00279 
00280 extern EIMIL_value* EIMIL_construct_number(
00281     int number
00282 );
00283 extern EIMIL_value* EIMIL_construct_bool(
00284     int bool_val
00285 );
00286 extern EIMIL_value* EIMIL_construct_char(
00287     UTF32 ch
00288 );
00289 extern EIMIL_value* EIMIL_construct_prop(
00290     EIMIL_symbol *psym
00291 );
00292 extern EIMIL_value* EIMIL_construct_prop2(
00293     enum EIMIL_TYPE type
00294 );
00295 extern EIMIL_value* EIMIL_construct_event(
00296     UTF8 *type,
00297     EIMIL_value *pv_val,
00298     EIMIL_value *pv_mod,
00299     EIMIL_value *pv_char,
00300     EIMIL_value *pv_mtext
00301 );
00302 extern int EIMIL_construct_events_from_IMInputEvent(
00303     IMInputEvent *pimev,
00304     EIMIL_value ***pppevs
00305 );
00306 extern IMInputEvent* EIMIL_convert_event_to_IMInputEvent(
00307     EIMIL_event *pev
00308 );
00309 extern int EIMIL_add_prop(
00310     EIMIL_prop *pprop,
00311     EIMIL_value *pv
00312 );
00313 extern int EIMIL_delete_prop(
00314     EIMIL_prop *pprop,
00315     int idx
00316 );
00317 extern EIMIL_value* EIMIL_copy_value(
00318     EIMIL_value *pv
00319 );
00320 extern int EIMIL_value_equal(
00321     EIMIL_value *pv1,
00322     EIMIL_value *pv2
00323 );
00324 
00325 extern int EIMIL_generate_diff(
00326     EIMIL_symbol *psym,
00327     EIMIL_value *pv2,
00328     IMDifferential *pdiff
00329 );
00330 
00331 extern int EIMIL_duplicate_handle(
00332     EIMIL_handle *peh,
00333     EIMIL_handle eh
00334 );
00335 
00336 extern int EIMIL_free_handle(
00337     EIMIL_handle eh
00338 );
00339 
00340 #if 0
00341 extern EIMIL_symbol* EIMIL_intern(EIMIL_handle eh, char *name);
00342 extern EIMIL_symbol* EIMIL_intern_soft(EIMIL_handle eh, char *name);
00343 extern EIMIL_symbol* EIMIL_lookup_symbol(EIMIL_handle eh, CARD32BIT id);
00344 #endif
00345 
00346 extern int EIMIL_send_event(
00347     EIMIL_handle eh,
00348     EIMIL_value *pv_event
00349 );
00350 
00351 extern void EIMIL_destruct_value(EIMIL_value* pv);
00352 extern void EIMIL_detach_prop_from_mtext(EIMIL_value *pv);
00353 
00354 extern int EIMIL_initialize();
00355 extern int EIMIL_finalize();
00356 
00357 /* EIMILFile */
00358 
00359 extern int EIMIL_register_class(
00360     unsigned char *classname,
00361     unsigned char *dirname
00362 );
00363 extern unsigned char* EIMIL_find_file(
00364     const unsigned char *classname,
00365     const unsigned char *name
00366 );
00367 extern int EIMIL_parse_file(
00368     EIMIL_handle *peh,
00369     const unsigned char *filename
00370 );
00371 
00372 extern int EIMIL_enumerate_class(
00373     unsigned char *classname
00374 );
00375 extern int EIMIL_register_file(
00376     unsigned char *classname
00377 );
00378 extern int EIMIL_file_symbolid(
00379     unsigned char *classname,
00380     unsigned char *name
00381 );
00382 
00383 /* EIMILTextUtil */
00384 extern int EIMIL_UTF32_string_len(
00385     const UTF32 *pstr
00386 );
00387 extern int EIMIL_UTF32_strcmp(
00388     const UTF32 *pstr1,
00389     const UTF32 *pstr2
00390 );
00391 extern int EIMIL_convert_UTF32char_to_UTF8(
00392     UTF32 ch,
00393     UTF8 *p
00394 );
00395 extern UTF8* EIMIL_convert_UTF32_to_UTF8(
00396     const UTF32 *putf32
00397 );
00398 extern int EIMIL_convert_UTF8_to_UTF32char(
00399     const UTF8 *p,
00400     UTF32 *pch
00401 );
00402 extern UTF32* EIMIL_convert_UTF8_to_UTF32(
00403     const UTF8 *putf8
00404 );
00405 extern int EIMIL_adjust_UTF16_pos_to_UTF32(
00406     int pos,
00407     const UTF32 *pbase,
00408     const UTF32 *pbaseend
00409 );
00410 extern int EIMIL_adjust_UTF32_pos_to_UTF16(
00411     int pos,
00412     const UTF32 *pbase,
00413     const UTF32 *pbaseend
00414 );
00415 extern int EIMIL_convert_UTF32_to_UTF16(
00416     const UTF32 *pu32,
00417     int u32len,
00418     UTF16 **ppu16,
00419     int *pu16len
00420 );
00421 extern int EIMIL_convert_UTF16_to_UTF32(
00422     const UTF16 *pu16,
00423     int u16len,
00424     UTF32 **ppu32,
00425     int *pu32len
00426 );
00427 extern EIMIL_value* EIMIL_construct_mtext_from_UTF8(
00428     const unsigned char *in
00429 );
00430 extern EIMIL_value* EIMIL_construct_mtext_from_UTF16(
00431     int len,
00432     const UTF16 *in
00433 );
00434 extern EIMIL_value* EIMIL_construct_mtext_from_UTF32(
00435     int len,
00436     const UTF32 *in
00437 );
00438 extern EIMIL_value* EIMIL_construct_mtext_from_UTF32_char(
00439     UTF32 in
00440 );
00441 
00442 extern EIMIL_value* EIMIL_mtext_concat(
00443     int num,
00444     EIMIL_value **pvs
00445 );
00446 
00447 extern EIMIL_value* EIMIL_mtext_substr(
00448     EIMIL_value *pv_mtext,
00449     int st,
00450     int end
00451 );
00452 
00453 extern EIMIL_value* EIMIL_get_prop_from_mtext(
00454     EIMIL_mtext *pm,
00455     EIMIL_symbol *property_sym,
00456     int pos
00457 );
00458 
00459 extern EIMIL_value* EIMIL_find_prop_from_mtext(
00460     EIMIL_mtext *pm,
00461     EIMIL_symbol *property_sym,
00462     int pos
00463 );
00464 
00465 extern EIMIL_mtext* EIMIL_add_prop_on_mtext(
00466     EIMIL_mtext *pm,
00467     EIMIL_value *pv,
00468     int st,
00469     int end
00470 );
00471 extern EIMIL_mtext* EIMIL_set_prop_on_mtext(
00472     EIMIL_mtext *pm,
00473     EIMIL_value *pv,
00474     int st,
00475     int end
00476 );
00477 
00478 extern int EIMIL_convert_mtext_to_IMText(
00479     IMText *pim,
00480     EIMIL_mtext *psrc
00481 );
00482 extern EIMIL_value* EIMIL_construct_mtext_from_IMText(
00483     IMText *pim
00484 );
00485 extern int EIMIL_sync_mtext(
00486     EIMIL_mtext *pm,
00487     IMDifferential *pdiff
00488 );
00489 
00490 /* EIMILJournal */
00491 extern int EIMIL_journal_prev_val(
00492     EIMIL_handle eh,
00493     EIMIL_TID tid,
00494     EIMIL_symbol *psym,
00495     EIMIL_value **pv
00496 );
00497 extern int EIMIL_journal_record_change(
00498     EIMIL_handle eh,
00499     EIMIL_symbol *psym
00500 );
00501 extern int EIMIL_journal_set_point(
00502     EIMIL_handle eh,
00503     EIMIL_TID *ptid
00504 );
00505 
00506               
00507 #ifdef __cplusplus
00508 }
00509 #endif
00510 
00511 #define EIMIL_ADDREF(v) (((v).refcount)++)
00512 #define EIMIL_RMREF(v) \
00513 ((--((v).refcount) <= 0) ? (EIMIL_destruct_value(&(v)), 0) : 0)
00514 #define EIMIL_RMREF_WITHOUT_DESTRUCTION(v) (--((v).refcount))
00515 #define EIMIL_REFCHECK(v) \
00516 ((((v).refcount) <= 0) ? (EIMIL_destruct_value(&(v)), 0) : 0)
00517 #define EIMIL_REFCHECK_GUARD(v, gv) \
00518 do { \
00519     if (((v).refcount) <= 0) { \
00520        (gv).refcount++; \
00521        EIMIL_destruct_value(&(v)); \
00522        (gv).refcount--; \
00523     } \
00524 } while(0)
00525 
00526 
00527 #endif /* not _EIMIL_H_ */
00528 
00529 /* Local Variables: */
00530 /* c-file-style: "iiim-project" */
00531 /* End: */