void DataSetNum( long _index ) { char buf[ MAXLEN ], *p; int i = 0; strcpy( buf, data[ _index ].str ); strtok( buf, " \n\t" ); data[ _index ].freq = atoi( strtok( NULL, " \n\t" ) ); for ( p = strtok( NULL, " \n\t" ); p; p = strtok( NULL, " \n\t" ) ) data[ _index ].num[ i++ ] = UintFromPhone( p ); }
int main (int argc, char *argv[]) { char *u8phone; char rt[10]; uint16_t phone; uint16_t expect; u8phone = "\xE3\x84\x86\xE3\x84\xA3" /* ㄆㄣ */; phone = UintFromPhone(u8phone); expect = 1104; ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'", u8phone, phone, expect); u8phone = "\xE3\x84\x8A\xE3\x84\xA7\xE3\x84\xA2" /* ㄊㄧㄢ */; phone = UintFromPhone(u8phone); expect = 3272; ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'", u8phone, phone, expect); u8phone = "\xE3\x84\x92\xE3\x84\xA7\xE3\x84\x9A\xCB\x8B" /* ㄒㄧㄚˋ */; phone = UintFromPhone(u8phone); expect = 7308; ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'", u8phone, phone, expect); u8phone = "\xE3\x84\x8A\xE3\x84\xA7\xE6\xB8\xAC" /* ㄊㄧ測 */; phone = UintFromPhone(u8phone); expect = 0; ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'", u8phone, phone, expect); u8phone = "\xE3\x84\x8E\xE3\x84\x8E" /* ㄎㄎ */; phone = UintFromPhone(u8phone); expect = 0; ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'", u8phone, phone, expect); u8phone = "\xE3\x84\xA8\xE3\x84\x8E" /* ㄨㄎ */; phone = UintFromPhone(u8phone); expect = 0; ok (phone == expect, "UintFromPhone `%s' shall be `%d', got `%d'", u8phone, phone, expect); PhoneFromKey( rt, "dj", 0, 1 ); ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8" /* ㄎㄨ */ ), "dj"); PhoneFromKey( rt, "dj6", 0, 1 ); ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x8A" /* ㄎㄨˊ */ ), "dj6"); PhoneFromKey( rt, "dj3", 0, 1 ); ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x87" /* ㄎㄨˇ */ ), "dj3"); PhoneFromKey( rt, "dj4", 0, 1 ); ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x8B" /* ㄎㄨˋ */ ), "dj4"); PhoneFromKey( rt, "dj7", 0, 1 ); ok (!strcmp(rt, "\xE3\x84\x8E\xE3\x84\xA8\xCB\x99" /* ㄎㄨ˙ */ ), "dj7"); return exit_status(); }
int DoWord( char *buf ) { char keyBuf[ 128 ], phoneBuf[ 128 ]; int phoneInx[ ZUIN_SIZE ]; memset( phoneInx, 0, sizeof( phoneInx ) ); sscanf( buf, "%s %s", keyBuf, word_data[ nWord ].word ); if ( strlen( keyBuf ) > ZUIN_SIZE ) return DO_WORD_ERROR; PhoneFromKey( phoneBuf, keyBuf, KB_DEFAULT, 1 ); word_data[ nWord ].num[0] = UintFromPhone( phoneBuf ); nWord++ ; return 0; }