int show_commit_string_uim_agent_context(uim_agent_context *ua) { int ret; if (ua == NULL) { return -1; } else { ret = show_commit_string(ua->comstr); if (ret > 0) { reset_commit_string(ua->comstr); ua->comstr = NULL; } return ret; } }
int main( int argc, char *argv[] ) { ChewingContext *ctx; FILE *fout; FILE *fout2; char *prefix = CHEWING_DATA_PREFIX; char *out_file = "tmp.txt"; char *out_file2 = "tmp_out.txt"; int ch; int width, height; int add_phrase_length; /*if ( argc < 2 ) { fprintf( stderr, "usage: genkeystroke filename\n" ); exit( 1 ); } else { fout = fopen( argv[ 1 ], "w" );*/ fout = fopen( out_file, "w" ); if ( ! fout ) { fprintf( stderr, "Error: failed to open %s\n", out_file ); exit( 1 ); } fout2 = fopen( out_file2, "w" ); if ( ! fout2 ) { fprintf( stderr, "Error: failed to open %s\n", out_file2 ); exit( 1 ); } /*}*/ /* Initialize curses library */ setlocale(LC_CTYPE, ""); initscr(); if ( has_colors() == TRUE ) { start_color(); init_pair( 1, COLOR_WHITE, COLOR_BLUE ); init_pair( 2, COLOR_RED, COLOR_YELLOW ); init_pair( 3, COLOR_WHITE, COLOR_RED ); hasColor = 1; } cbreak(); noecho(); keypad( stdscr, 1 ); getmaxyx( stdscr, height, width ); start_color(); clear(); refresh(); /* Initialize libchewing */ /* for the sake of testing, we should not change existing hash data */ chewing_Init( prefix, TEST_HASH_DIR ); /* Request handle to ChewingContext */ ctx = chewing_new(); /* Set keyboard type */ chewing_set_KBType( ctx, chewing_KBStr2Num( "KB_DEFAULT" ) ); /* Fill configuration values */ chewing_set_candPerPage( ctx, 9 ); chewing_set_maxChiSymbolLen( ctx, 16 ); chewing_set_addPhraseDirection( ctx, 1 ); chewing_set_selKey( ctx, selKey_define, 10 ); chewing_set_spaceAsSelection( ctx, 1 ); chewing_set_autoShiftCur( ctx, 1 ); chewing_set_phraseChoiceRearward( ctx, 1 ); clear(); mvaddstr( 0, 0, "Any key to start testing..." ); while ( TRUE ) { ch = getch(); switch ( ch ) { case KEY_LEFT: chewing_handle_Left( ctx ); fprintf( fout, "<L>" ); break; case KEY_SLEFT: chewing_handle_ShiftLeft( ctx ); fprintf( fout, "<SL>" ); break; case KEY_RIGHT: chewing_handle_Right( ctx ); fprintf( fout, "<R>" ); break; case KEY_SRIGHT: chewing_handle_ShiftRight( ctx ); fprintf( fout, "<SR>" ); break; case KEY_UP: chewing_handle_Up( ctx ); fprintf( fout, "<U>" ); break; case KEY_DOWN: chewing_handle_Down( ctx ); fprintf( fout, "<D>" ); break; case KEY_SPACE: chewing_handle_Space( ctx ); fprintf( fout, " " ); break; case KEY_ENTER: chewing_handle_Enter( ctx ); fprintf( fout, "<E>" ); break; case KEY_BACKSPACE: chewing_handle_Backspace( ctx ); fprintf( fout, "<B>" ); break; case KEY_ESC: chewing_handle_Esc( ctx ); fprintf( fout, "<EE>" ); break; case KEY_DC: chewing_handle_Del( ctx ); fprintf( fout, "<DC>" ); break; case KEY_HOME: chewing_handle_Home( ctx ); fprintf( fout, "<H>" ); break; case KEY_END: chewing_handle_End( ctx ); fprintf( fout, "<EN>" ); break; case KEY_TAB: chewing_handle_Tab( ctx ); fprintf( fout, "<T>" ); break; case CTRL_0: case CTRL_1: case CTRL_2: case CTRL_3: case CTRL_4: case CTRL_5: case CTRL_6: case CTRL_7: case CTRL_8: case CTRL_9: add_phrase_length = ( ch - CTRL_0 + '0' ); chewing_handle_CtrlNum( ctx, add_phrase_length ); fprintf( fout, "<C%c>", add_phrase_length ); break; case KEY_CTRL_('B'): /* emulate CapsLock */ chewing_handle_Capslock( ctx ); fprintf( fout, "<CB>"); break; case KEY_CTRL_('D'): case EOF: goto end; case KEY_CTRL_('H'): /* emulate Shift */ if ( chewing_get_ShapeMode( ctx ) == FULLSHAPE_MODE ) chewing_set_ShapeMode( ctx, HALFSHAPE_MODE ); else chewing_set_ShapeMode( ctx, FULLSHAPE_MODE ); break; default: chewing_handle_Default( ctx, (char) ch ); fprintf( fout, "%c", (char) ch ); break; } drawline( 0, 0 ); drawline( 2, 0 ); show_interval_buffer( 3, 0, ctx ); drawline( 4, 0 ); show_choose_buffer( 5, 0, ctx ); drawline( 6, 0 ); show_zuin_buffer( 7, 0, ctx ); show_full_shape( 7, 5, ctx ); drawline( 8, 0 ); mvaddstr( 9, 0, "Ctrl + d : leave" ); mvaddstr( 9, 20, "Ctrl + b : toggle Eng/Chi mode" ); mvaddstr( 10, 0, "F1, F2, F3, ..., F9 : Add user defined phrase"); mvaddstr( 11, 0, "Crtl + h : toggle Full/Half shape mode" ); show_commit_string( ctx ); store_commit_string( ctx, fout2 ); show_userphrase( 7, 12, ctx ); show_edit_buffer( 1, 0, ctx ); } end: endwin(); /* Release Chewing context */ chewing_delete( ctx ); /* Termate Chewing services */ chewing_Terminate(); fprintf( fout, "\n" ); fprintf( fout2, "\n" ); fclose( fout ); fclose( fout2 ); return 0; }