Exemple #1
0
void test_set_easySymbolInput()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_easySymbolInput( ctx, value );
		mode = chewing_get_easySymbolInput( ctx );
		ok( mode == value,
			"easySymbolInput `%d', shall be `%d'", mode, value );

		chewing_set_easySymbolInput( ctx, -1 );
		mode = chewing_get_easySymbolInput( ctx );
		ok( mode == value,
			"easySymbolInput `%d', shall be `%d'", mode, value );

		chewing_set_easySymbolInput( ctx, 2 );
		mode = chewing_get_easySymbolInput( ctx );
		ok( mode == value,
			"easySymbolInput `%d', shall be `%d'", mode, value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
void test_userphrase_auto_learn_hardcode_break()
{
	/* 的 is a hardcode break point, see ChewingIsBreakPoint */
	static const char phrase[] = "\xE7\x9A\x84\xE7\x9A\x84" /* 的的 */;
	static const char bopomofo[] = "\xE3\x84\x89\xE3\x84\x9C\xCB\x99 \xE3\x84\x89\xE3\x84\x9C\xCB\x99" /* ㄉㄜ˙ ㄉㄜ˙ */;
	ChewingContext *ctx;

	remove( TEST_HASH_DIR PLAT_SEPARATOR HASH_FILE );

	chewing_Init( NULL, NULL );

	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );
	chewing_set_addPhraseDirection( ctx, 1 );

	ok( has_userphrase( ctx, bopomofo, phrase ) == 0,
		"`%s' shall not be in userphrase", phrase );

	type_keystroke_by_string( ctx, "2k72k7<E>" );
	ok( has_userphrase( ctx, bopomofo, phrase ) == 0,
		"`%s' shall not be in userphrase", phrase );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #3
0
void test_set_phraseChoiceRearward()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_phraseChoiceRearward( ctx, value );
		mode = chewing_get_phraseChoiceRearward( ctx );
		ok(  mode == value,
			"phraseChoiceRearward `%d' shall be `%d'", mode, value );

		chewing_set_phraseChoiceRearward( ctx, -1 );
		mode = chewing_get_phraseChoiceRearward( ctx );
		ok(  mode == value,
			"phraseChoiceRearward `%d' shall be `%d'", mode, value );

		chewing_set_phraseChoiceRearward( ctx, 2 );
		mode = chewing_get_phraseChoiceRearward( ctx );
		ok(  mode == value,
			"phraseChoiceRearward `%d' shall be `%d'", mode, value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #4
0
void test_set_escCleanAllBuf()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_escCleanAllBuf( ctx, value );
		mode = chewing_get_escCleanAllBuf( ctx );
		ok( mode == value,
			"escCleanAllBuf shall be `%d'", value );

		chewing_set_escCleanAllBuf( ctx, -1 );
		mode = chewing_get_escCleanAllBuf( ctx );
		ok( mode == value,
			"escCleanAllBuf shall be `%d'", value );

		chewing_set_escCleanAllBuf( ctx, 2 );
		mode = chewing_get_escCleanAllBuf( ctx );
		ok( mode == value,
			"escCleanAllBuf shall be `%d'", value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #5
0
void test_set_autoShiftCur()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_autoShiftCur( ctx, value );
		mode = chewing_get_autoShiftCur( ctx );
		ok( mode = chewing_get_autoShiftCur( ctx ) == value,
			"autoShiftCur shall be `%d'", value );

		chewing_set_autoShiftCur( ctx, -1 );
		mode = chewing_get_autoShiftCur( ctx );
		ok( mode = chewing_get_autoShiftCur( ctx ) == value,
			"autoShiftCur shall be `%d'", value );

		chewing_set_autoShiftCur( ctx, 2 );
		mode = chewing_get_autoShiftCur( ctx );
		ok( mode = chewing_get_autoShiftCur( ctx ) == value,
			"autoShiftCur shall be `%d'", value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #6
0
void test_set_selKey()
{
	ChewingContext *ctx;
	int *select_key;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	chewing_set_maxChiSymbolLen( ctx, 16 );

	// XXX: chewing_set_selKey shall accept const char *.
	chewing_set_selKey( ctx,
		ALTERNATE_SELECT_KEY, ARRAY_SIZE( ALTERNATE_SELECT_KEY ));
	select_key = chewing_get_selKey( ctx );
	ok( select_key, "chewing_get_selKey shall not return NULL" );
	ok( !memcmp( select_key, ALTERNATE_SELECT_KEY,
		sizeof( ALTERNATE_SELECT_KEY )),
		"select key shall be ALTERNATE_SELECT_KEY");

	type_keystroke_by_string( ctx, DATA.token );
	ok_preedit_buffer( ctx, DATA.expected );

	chewing_free( select_key );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #7
0
void test_set_spaceAsSelection()
{
	ChewingContext *ctx;
	int value;
	int mode;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( value = 0; value < 2; ++value ) {
		chewing_set_spaceAsSelection( ctx, value );
		mode = chewing_get_spaceAsSelection( ctx );
		ok( mode == value,
			"spaceAsSelection `%d' shall be `%d'", mode, value );

		chewing_set_spaceAsSelection( ctx, -1 );
		mode = chewing_get_spaceAsSelection( ctx );
		ok( mode == value,
			"spaceAsSelection `%d' shall be `%d'", mode, value );

		chewing_set_spaceAsSelection( ctx, 2 );
		mode = chewing_get_spaceAsSelection( ctx );
		ok( mode == value,
			"spaceAsSelection `%d' shall be `%d'", mode, value );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
void test_ShiftRight_add_userphrase()
{
	static const char phrase[] = "\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */;
	static const char bopomofo[] = "\xE3\x84\x98\xE3\x84\x9C\xCB\x8B \xE3\x84\x95\xCB\x8B" /* ㄘㄜˋ ㄕˋ */;
	int cursor;
	ChewingContext *ctx;

	remove( TEST_HASH_DIR PLAT_SEPARATOR HASH_FILE );

	chewing_Init( NULL, NULL );

	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );

	ok( has_userphrase( ctx, bopomofo, phrase ) == 0,
		"`%s' shall not be in userphrase", phrase );

	type_keystroke_by_string( ctx, "hk4g4<L><L><SR><SR><E>" );
	ok_preedit_buffer( ctx, phrase );
	cursor = chewing_cursor_Current( ctx );
	ok( cursor == 2, "cursor position `%d' shall be 2", cursor );
	ok( has_userphrase( ctx, bopomofo, phrase ) == 1,
		"`%s' shall be in userphrase", phrase );

	chewing_delete( ctx );
	chewing_Terminate();
}
MainWindow::MainWindow()
{
  this->_lblChewing = new QLabel();
  this->_lblCommit = new QLabel();
  this->_lblBuffer = new QLabel();
  this->_lblAux = new QLabel();
  this->_lblLine = new QLabel();

  chewing_Init("/usr/share/chewing", ".");
  this->_ct = chewing_new();
  chewing_set_candPerPage(this->_ct, 9);
  chewing_set_maxChiSymbolLen(this->_ct, 20);
  chewing_set_escCleanAllBuf(this->_ct, 1);

  QWidget* container = new QWidget;
  QVBoxLayout* layout = new QVBoxLayout();
  layout->addWidget(new QLabel("Chewing symbol in buffer"));
  layout->addWidget(this->_lblChewing);
  layout->addWidget(new QLabel("Preedit buffer"));
  layout->addWidget(this->_lblBuffer);
  layout->addWidget(new QLabel("Commit output"));
  layout->addWidget(this->_lblCommit);
  layout->addWidget(new QLabel("Aux buffer"));
  layout->addWidget(this->_lblAux);
  layout->addWidget(new QLabel("Final output"));
  layout->addWidget(this->_lblLine);
  container->setLayout(layout);
  this->setCentralWidget(container);
}
Exemple #10
0
void test_CtrlNum_add_phrase_symbol_in_between()
{
	static const char bopomofo[] = "\xE3\x84\x98\xE3\x84\x9C\xCB\x8B \xE3\x84\x95\xCB\x8B" /* ㄘㄜˋ ㄕˋ */;
	int cursor;
	ChewingContext *ctx;

	remove( TEST_HASH_DIR PLAT_SEPARATOR HASH_FILE );

	chewing_Init( NULL, NULL );

	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );
        chewing_set_addPhraseDirection( ctx, 1 );

	ok( has_userphrase( ctx, bopomofo, NULL ) == 0,
		"`%s' shall not be in userphrase", bopomofo );

	type_keystroke_by_string( ctx, "hk4`1g4<C2>" );
	cursor = chewing_cursor_Current( ctx );
	ok( cursor == 3, "cursor position `%d' shall be 3", cursor );

	/*
	 * FIXME: Current buggy here. User phrase shall not be added when there
	 * is a symbol in between.
	 */
	/* ok( has_userphrase( ctx, bopomofo, NULL ) == 0,
		"`%s' shall not be in userphrase", bopomofo ); */

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #11
0
/**
 * @brief initialize the extra input method
 *
 * @param arg
 * @return successful or not
 **/
__EXPORT_API
void* FcitxChewingCreate(FcitxInstance* instance)
{
    if (GetFcitxChewingConfigDesc() == NULL)
        return NULL;
    
    char* user_path = NULL;
    FILE* fp = FcitxXDGGetFileUserWithPrefix("chewing", ".place_holder", "w", NULL);
    if (fp)
        fclose(fp);
    FcitxXDGGetFileUserWithPrefix("chewing", "", NULL, &user_path);
    FcitxLog(INFO, "Chewing storage path %s", user_path);
    if (0 == chewing_Init(CHEWING_DATADIR, user_path)) {
        FcitxLog(DEBUG, "chewing init ok");
    } else {
        FcitxLog(DEBUG, "chewing init failed");
        return NULL;
    }
    
    FcitxChewing* chewing = (FcitxChewing*) fcitx_utils_malloc0(sizeof(FcitxChewing));
    FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(instance);
    FcitxInputState *input = FcitxInstanceGetInputState(instance);
    FcitxCandidateWordSetChoose(FcitxInputStateGetCandidateList(input), DIGIT_STR_CHOOSE);
    
    bindtextdomain("fcitx-chewing", LOCALEDIR);

    chewing->context = chewing_new();
    ChewingContext * c = chewing->context;
    chewing->owner = instance;
    chewing_set_ChiEngMode(c, CHINESE_MODE);
    chewing_set_maxChiSymbolLen(c, 16);
    // chewing will crash without set page
    chewing_set_candPerPage(c, config->iMaxCandWord);
    FcitxCandidateWordSetPageSize(FcitxInputStateGetCandidateList(input), config->iMaxCandWord);
    chewing_set_selKey(c, selKey, 10);
    LoadChewingConfig(&chewing->config);
    ConfigChewing(chewing);

    FcitxInstanceRegisterIM(
        instance,
        chewing,
        "chewing",
        _("Chewing"),
        "chewing",
        FcitxChewingInit,
        FcitxChewingReset,
        FcitxChewingDoInput,
        FcitxChewingGetCandWords,
        NULL,
        NULL,
        FcitxChewingReloadConfig,
        NULL,
        1,
        "zh_TW"
    );
    return chewing;
}
Exemple #12
0
void test_default_value()
{
	int *select_key;
	ChewingContext *ctx;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	select_key = chewing_get_selKey( ctx );
	ok( select_key, "chewing_get_selKey shall not return NULL" );
	ok( !memcmp( select_key, DEFAULT_SELECT_KEY,
		sizeof( DEFAULT_SELECT_KEY )),
		"select key shall be default value");
	chewing_free( select_key );

	ok( chewing_get_candPerPage( ctx ) == DEFAULT_CAND_PER_PAGE,
		"candPerPage shall be default value" );

	ok( chewing_get_maxChiSymbolLen( ctx ) == 0,
		"maxChiSymbolLen shall be 0" );

	ok( chewing_get_addPhraseDirection( ctx ) == 0,
		"addPhraseDirection shall be 0" );

	ok( chewing_get_spaceAsSelection( ctx ) == 0,
		"spaceAsSelection shall be 0" );

	ok( chewing_get_escCleanAllBuf( ctx ) == 0,
		"escCleanAllBuf shall be 0" );

	ok( chewing_get_hsuSelKeyType( ctx ) == 0,
		"hsuSelKeyType shall be 0" );

	ok( chewing_get_autoShiftCur( ctx ) == 0,
		"autoShiftCur shall be 0" );

	ok( chewing_get_easySymbolInput( ctx ) == 0,
		"easySymbolInput shall be 0" );

	ok( chewing_get_phraseChoiceRearward( ctx ) == 0,
		"phraseChoiceRearward shall be 0" );

	ok( chewing_get_ChiEngMode( ctx ) == CHINESE_MODE,
		"ChiEngMode shall be CHINESE_MODE" );

	ok( chewing_get_ShapeMode( ctx ) == HALFSHAPE_MODE,
		"ShapeMode shall be HALFSHAPE_MODE" );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #13
0
void test_ShiftRight_not_entering_chewing()
{
	ChewingContext *ctx;

	chewing_Init( NULL, NULL );

	ctx = chewing_new();
	type_keystroke_by_string( ctx, "<SR>" );
	ok_keystroke_rtn( ctx, KEYSTROKE_IGNORE );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #14
0
void test_type_easy_symbol()
{
	chewing_Init( NULL, NULL );

	ChewingContext *ctx = chewing_new();
	ok( ctx, "chewing_new shall not return NULL" );

	chewing_set_maxChiSymbolLen( ctx, 16 );
	chewing_set_easySymbolInput( ctx, 1 );

	for ( int i = 0; i < ARRAY_SIZE( EASY_SYMBOL ); ++i ) {
		type_keystoke_by_string( ctx, EASY_SYMBOL[i].token );
		ok_commit_buffer( ctx, EASY_SYMBOL[i].expected );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #15
0
void test_deprecated()
{
	ChewingContext *ctx;
	int type;
	ChewingConfigData configure = { 0 };

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	chewing_set_hsuSelKeyType( ctx, HSU_SELKEY_TYPE1 );
	type = chewing_get_hsuSelKeyType( ctx );
	ok( type == HSU_SELKEY_TYPE1, "`%d' shall be `%d'", type, HSU_SELKEY_TYPE1 );

	chewing_Configure( ctx, &configure );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #16
0
void test_set_maxChiSymbolLen()
{
	ChewingContext *ctx;
	int i;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	chewing_set_maxChiSymbolLen( ctx, 16 );
	ok( chewing_get_maxChiSymbolLen( ctx ) == 16,
		"maxChiSymbolLen shall be 16" );

	chewing_set_maxChiSymbolLen( ctx, MIN_CHI_SYMBOL_LEN - 1 );
	ok( chewing_get_maxChiSymbolLen( ctx ) == 16,
		"maxChiSymbolLen shall not change when set to %d",
		MIN_CHI_SYMBOL_LEN - 1 );

	chewing_set_maxChiSymbolLen( ctx, MAX_CHI_SYMBOL_LEN + 1 );
	ok( chewing_get_maxChiSymbolLen( ctx ) == 16,
		"maxChiSymbolLen shall not change when set to %d",
		MAX_CHI_SYMBOL_LEN + 1 );


	// Test auto commit
	chewing_set_maxChiSymbolLen( ctx, MAX_CHI_SYMBOL_LEN );

	// In boundary
	for ( i = 0; i < MAX_CHI_SYMBOL_LEN; ++i )
		type_keystroke_by_string( ctx, "hk4" );
	ok( chewing_commit_Check( ctx ) == 0,
		"auto commit shall not be triggered when entering %d symbols",
		MAX_CHI_SYMBOL_LEN );

	// Out of boundary
	type_keystroke_by_string( ctx, "hk4" );
	ok( chewing_commit_Check( ctx ) == 1,
		"auto commit shall be triggered when entering %d symbols",
		MAX_CHI_SYMBOL_LEN + 1);

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #17
0
static gboolean
chewing_initialize (void)
{
    char *pszChewingHashDir;
    char *pszHome;
    gboolean bWriteMode = FALSE;
    ChewingConfigData dummyConfig;

    pszHome = getenv ("HOME");
    if (!pszHome)
        pszHome = "";

    pszChewingHashDir = malloc (strlen (pszHome) + strlen ("/.chewing/") + 1);
    memset (pszChewingHashDir, 0x00, strlen (pszHome) + strlen ("/.chewing/") + 1);
    sprintf (pszChewingHashDir, "%s/.chewing", pszHome);

    if (chewing_Init (CHEWING_DATADIR, pszChewingHashDir) != 0)
    {
        free (pszChewingHashDir);
        return FALSE;
    }
    free (pszChewingHashDir);
    pszHome = NULL;

    g_pChewingCtx = chewing_new ();
    if (!g_pChewingCtx)
        return FALSE;

    memset (&dummyConfig, 0x00, sizeof (ChewingConfigData));

    chewing_config_open (bWriteMode);

    chewing_config_load (&dummyConfig);

    chewing_config_set (g_pChewingCtx);

    chewing_config_close ();

    hime_chewing_cb_register ();

    return TRUE;
}
Exemple #18
0
void test_symbol_cand_page()
{
	ChewingContext *ctx;

	chewing_Init( NULL, NULL );

	ctx = chewing_new();

	chewing_set_candPerPage( ctx, 10 );
	chewing_set_maxChiSymbolLen( ctx, 16 );

	chewing_handle_Default( ctx, '`' );
	ok( chewing_cand_CurrentPage( ctx ) == 0, "current page shall be 0" );
	ok( chewing_cand_TotalPage( ctx ) == 2, "total page shall be 2" );

	ok_candidate( ctx, CAND, ARRAY_SIZE( CAND ) );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #19
0
void test_type_symbol()
{
	ChewingContext *ctx;
	int i;

	chewing_Init( NULL, NULL );

	ctx = chewing_new();

	chewing_set_candPerPage( ctx, 10 );
	chewing_set_maxChiSymbolLen( ctx, 16 );

	for (i = 0; i < ARRAY_SIZE(SYMBOL); ++i ) {
		type_keystroke_by_string( ctx, SYMBOL[i].token );
		ok_preedit_buffer( ctx, "" );
		ok_commit_buffer( ctx, SYMBOL[i].expected );
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #20
0
void test_mode_change()
{
	chewing_Init( NULL, NULL );

	ChewingContext *ctx = chewing_new();
	ok( ctx, "chewing_new shall not return NULL" );

	chewing_set_maxChiSymbolLen( ctx, 16 );

	type_keystoke_by_string( ctx, CHINESE.token );
	ok_commit_buffer( ctx, CHINESE.expected );

	chewing_set_easySymbolInput( ctx, 1 );
	type_keystoke_by_string( ctx, EASY_SYMBOL[0].token );
	ok_commit_buffer( ctx, EASY_SYMBOL[0].expected );

	chewing_set_easySymbolInput( ctx, 0 );
	type_keystoke_by_string( ctx, CHINESE.token );
	ok_commit_buffer( ctx, CHINESE.expected );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #21
0
void test_userphrase_auto_learn()
{
	static const char bopomofo[] = "\xE3\x84\x8E\xE3\x84\x9C \xE3\x84\x8E\xE3\x84\x9C" /* ㄎㄜ ㄎㄜ */;
	ChewingContext *ctx;

	remove( TEST_HASH_DIR PLAT_SEPARATOR HASH_FILE );

	chewing_Init( NULL, NULL );

	ctx = chewing_new();
	chewing_set_maxChiSymbolLen( ctx, 16 );
        chewing_set_addPhraseDirection( ctx, 1 );

	ok( has_userphrase( ctx, bopomofo, NULL ) == 0,
		"`%s' shall not be in userphrase", bopomofo );

	type_keystroke_by_string( ctx, "dk dk <E>" );
	ok( has_userphrase( ctx, bopomofo, NULL ) == 1,
		"`%s' shall be in userphrase", bopomofo );

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #22
0
void test_set_candPerPage()
{
	const int VALUE[] = {
		MIN_CAND_PER_PAGE,
		MAX_CAND_PER_PAGE,
	};

	const int INVALID_VALUE[] = {
		MIN_CAND_PER_PAGE - 1,
		MAX_CAND_PER_PAGE + 1,
	};

	ChewingContext *ctx;
	int i;
	int j;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( i = 0; i < ARRAY_SIZE( VALUE ); ++i ) {
		chewing_set_candPerPage( ctx, VALUE[i] );
		ok( chewing_get_candPerPage( ctx ) == VALUE[i],
			"candPerPage shall be `%d'", VALUE[i] );

		for ( j = 0; j < ARRAY_SIZE( INVALID_VALUE ); ++j ) {
			// mode shall not change when set mode has invalid value.
			chewing_set_candPerPage( ctx, INVALID_VALUE[j] );
			ok( chewing_get_candPerPage( ctx ) == VALUE[i],
				"candPerPage shall be `%d'", VALUE[i] );
		}
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #23
0
void test_set_ShapeMode()
{
	const int VALUE[] = {
		HALFSHAPE_MODE,
		FULLSHAPE_MODE,
	};

	const int INVALID_VALUE[] = {
		-1,
		2,
	};

	ChewingContext *ctx;
	int i;
	int j;

	chewing_Init( 0, 0 );

	ctx = chewing_new();

	for ( i = 0; i < ARRAY_SIZE( VALUE ); ++i ) {
		chewing_set_ShapeMode( ctx, VALUE[i] );
		ok( chewing_get_ShapeMode( ctx ) == VALUE[i],
			"ShapeMode shall be `%d'", VALUE[i] );

		for ( j = 0; j < ARRAY_SIZE( INVALID_VALUE ); ++j ) {
			// mode shall not change when set mode has invalid value.
			chewing_set_ShapeMode( ctx, INVALID_VALUE[j] );
			ok( chewing_get_ShapeMode( ctx ) == VALUE[i],
				"ShapeMode shall be `%d'", VALUE[i] );
		}
	}

	chewing_delete( ctx );
	chewing_Terminate();
}
Exemple #24
0
int main( int argc, char *argv[] )
#endif
{
	ChewingContext *ctx;
	char *prefix = CHEWING_DATA_PREFIX;
	int i;
	int ctrl_shifted;

	/* 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" ) );

	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 );

	while ( 1 ) {
		i = get_keystroke();
		switch ( i ) {
			case KEY_LEFT:
				chewing_handle_Left( ctx );
				break;
			case KEY_SLEFT:
				chewing_handle_ShiftLeft( ctx );
				break;
			case KEY_RIGHT:
				chewing_handle_Right( ctx );
				break;
			case KEY_SRIGHT:
				chewing_handle_ShiftRight( ctx );
				break;
			case KEY_UP:
				chewing_handle_Up( ctx );
				break;
			case KEY_DOWN:
				chewing_handle_Down( ctx );
				break;
			case KEY_SPACE:
				chewing_handle_Space( ctx );
				break;
			case KEY_ENTER:
				chewing_handle_Enter( ctx );
				break;
			case KEY_BACKSPACE:
				chewing_handle_Backspace( ctx );
				break;
			case KEY_ESC:
				chewing_handle_Esc( ctx );
				break;
			case KEY_DELETE:
				chewing_handle_Del( ctx );
				break;
			case KEY_HOME:
				chewing_handle_Home( ctx );
				break;
			case KEY_END:
				chewing_handle_End( ctx );
				break;
			case KEY_TAB:
				chewing_handle_Tab( ctx );
				break;			
			case KEY_CAPSLOCK:
				chewing_handle_Capslock( ctx );
				break;
			case END:
				goto end;
			default:
				ctrl_shifted = ( i - KEY_CTRL_BASE );
				if ( ( ctrl_shifted >= '0' ) && ( ctrl_shifted <= '9' ) ) {
					chewing_handle_CtrlNum( ctx, ctrl_shifted );
				} else {
					chewing_handle_Default( ctx, (char) i );
				}
				break;
		}
		commit_string( ctx );
#ifdef USED_IN_SIMULATION
		if ( i == KEY_ENTER )
			compare_per_run();
#endif
	}
end:
	/* Free Chewing IM handle */
	chewing_delete( ctx );
	
	/* Termate Chewing services */
	chewing_Terminate();
#ifndef USED_IN_SIMULATION
	printf( "\n" );
#endif
	return 0;
}
Exemple #25
0
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;
}
Exemple #26
0
bool Chewing::LoadDataFiles(const char *dataDir, const char *userDir)
{
	chewing_Init(dataDir, userDir);
	return true; 
}
Exemple #27
0
void Chewing::ReloadSymbolTable(const char* dataDir, const char* userDir )
{
	chewing_Terminate();
	chewing_Init(dataDir, userDir);
}
Exemple #28
0
int main()
{
	ChewingContext *ct;
	char *buf;
	int counter;

	/*
	 * Initialize Chewing input method engine
	 * Parameter 1:data path
	 * Parameter 2:path to keep user-defined phrases
	 */
	chewing_Init("../data/", ".");
	ct = chewing_new();

	/* Chinese mode by default */
	if (chewing_get_ChiEngMode(ct) == CHINESE_MODE)
		printf("Chinese mode!\n");

	/* Set the selection keys, otherwise you can not select candidates. */
	chewing_set_selKey(ct, selKeys, 9);
	/* Set the legth of maximum Chinese symbol */
	chewing_set_maxChiSymbolLen(ct, 10);
	/* Set the amount of candidates per page */
	chewing_set_candPerPage(ct, 9);

	/*
	 * Sequence 1:'綠茶'
	 */
	chewing_handle_Default(ct, 'x');	/* ㄌ */
	chewing_handle_Default(ct, 'm');	/* ㄩ */
	chewing_handle_Default(ct, '4');	/* ˋ */
	chewing_handle_Default(ct, 't');	/* ㄔ */
	chewing_handle_Default(ct, '8');	/* ㄚ */
	chewing_handle_Default(ct, '6');	/* ˊ */
	/* commit buffer to output area */
	chewing_handle_Enter(ct);

	/* Copy stribf from output area */
	buf = chewing_commit_String(ct);
	printf("%s\n", buf);
	free(buf);

	/*
	 * Sequence 2:Input 'ㄓ' and select candidates
	 */
	chewing_handle_Default(ct, '5');
	chewing_handle_Space(ct);
	/*
	 * The expected key to enter candidate selection is 'Down'.
	 * If 'Down' is not triggered, we can not use the further
	 * chewing_cand_Enumerate() to get the detailed listing.
	 */
	chewing_handle_Down(ct);

	/*
	 * Start the enumeration of candidate.  It follows the typical iterator design.
	 * (1) chewing_cand_Enumerate(): specify the iterator by ChewingContext
	 * (2) chewing_cand_hasNext(): find out the next element in iterator
	 * (3) chewing_cand_String(): get the current element and advance
	 */
	chewing_cand_Enumerate(ct);
	counter = 0;
	while (chewing_cand_hasNext(ct)) {
		counter += 1;
		char *s = chewing_cand_String(ct);
		printf("%s ", s);
		free(s);
		if (counter == 5) {
			counter = 0;
			printf("\n");
		}
	}
	printf("\nSelecting 13rd:");

	/*
	 * 剛才按下了↓,目前正在選字。
	 * 我想選第13個字,那就必須換頁,然後選第二頁的第4個字(9+4=13)
	 * 換頁的按鍵是空白鍵
	 * (一頁有多少候選字的設定,在  chewing_set_candPerPage(ct, 9); 這個呼叫中)
	 */
	chewing_handle_Space(ct);
	chewing_handle_Default(ct, '4');
	chewing_handle_Enter(ct);

	buf = chewing_commit_String(ct);
	printf("%s\n", buf);
	free(buf);

	/* Finalize Chewing input method engine */
	chewing_delete(ct);
	chewing_Terminate();
	return 0;
}