Back to index

im-sdk  12.3.91
arithtest.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <EIMIL.h>
00004 
00005 static int
00006 print_event(
00007     EIMIL_handle eh,
00008     EIMIL_event *pev
00009 )
00010 {
00011     fprintf(stderr, "Event:%s", pev->type);
00012     if (pev->pv_val)
00013        fprintf(stderr, " VAL[%d]", pev->pv_val->v.number);
00014     else
00015        fprintf(stderr, " VAL[nil]");
00016 
00017     if (pev->pv_mod)
00018        fprintf(stderr, " MOD[%d]", pev->pv_mod->v.number);
00019     else
00020        fprintf(stderr, " MOD[nil]");
00021 
00022     if (pev->pv_char)
00023        fprintf(stderr, " CH[%c:%X]", pev->pv_char->v.ch, pev->pv_char->v.ch);
00024     else
00025        fprintf(stderr, " CH[nil]");
00026 
00027     if (pev->pv_mtext) {
00028        UTF8 *pstr;
00029 
00030        pstr = EIMIL_convert_UTF32_to_UTF8(pev->pv_mtext->v.mtext.ustr);
00031        fprintf(stderr, " MTEXT[%s]\n", pstr);
00032        free(pstr);
00033     } else {
00034        fprintf(stderr, " MTEXT[nil]\n");
00035     }
00036 
00037     return 1;
00038 }
00039 
00040 int
00041 main(
00042     int argc,
00043     char **argv
00044 )
00045 {
00046     char buf[1024];
00047     unsigned char *pfn;
00048     EIMIL_handle eh, eh2;
00049 
00050     getcwd(buf, sizeof(buf));
00051 
00052     EIMIL_initialize();
00053 
00054     EIMIL_register_class("org.OpenI18N.test", buf);
00055     pfn = EIMIL_find_file("org.OpenI18N.test", "arithtest.xml");
00056 
00057     if (!EIMIL_parse_file(&eh, pfn)) goto error;
00058     EIMIL_register_handler(eh, print_event, NULL, NULL);
00059 
00060     /* test1: i + 2 */
00061     if (!EIMIL_send_event(eh, NULL)) goto error;
00062     if (!EIMIL_send_event(eh, NULL)) goto error;
00063     if (!EIMIL_send_event(eh, NULL)) goto error;
00064     if (!EIMIL_send_event(eh, NULL)) goto error;
00065     if (!EIMIL_send_event(eh, NULL)) goto error;
00066     if (!EIMIL_send_event(eh, NULL)) goto error;
00067     if (!EIMIL_send_event(eh, NULL)) goto error;
00068     if (!EIMIL_send_event(eh, NULL)) goto error;
00069     if (!EIMIL_send_event(eh, NULL)) goto error;
00070 
00071     return 0;
00072 
00073 error:
00074     EIMIL_get_errormsg(eh, &pfn);
00075     fprintf(stderr, "%s\n", pfn);
00076     return 255;
00077 }
00078