Skip to content

Commit

Permalink
fixed bugs in linux, the real-string arg support
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Apr 4, 2014
1 parent 96c9ea9 commit efbb558
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
4 changes: 2 additions & 2 deletions pinyin.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ PHP_MINFO_FUNCTION(pinyin)
php_info_print_table_start();
php_info_print_table_header(2, "pinyin support", "enabled");
php_info_print_table_row(2, "author", "Rex Lee");
php_info_print_table_row(2, "version", "0.3.0");
php_info_print_table_row(2, "function", "pinyin(string cnchar) return a string which is the pinyin.");
php_info_print_table_row(2, "version", "0.3.3");
php_info_print_table_row(2, "function", "string pinyin(string)");
php_info_print_table_end();

}
Expand Down
24 changes: 9 additions & 15 deletions py_pinyin.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ i_HashTable* pinyin_init(){
memset(tmp, 0, sizeof(char)*4);
strncpy(tmp, (cnchar+JMP*(i)), JMP);

//printf("key: %s\tvalue: %s\n", tmp, (pinyin+index[i]+1));
tmp_py=(pinyin+index[i]+1);

ht_insert(&dict, tmp, tmp_py);
}

Expand All @@ -56,7 +56,7 @@ i_HashTable* pinyin_init(){
* @return pinyin string
*/
char* pinyin_get(char* cn){
char single_cn_buf[3];
char single_cn_buf[JMP+1];
unsigned int len=0;
unsigned int len_pybuf=0;
unsigned int flag_cnchar_buf=0;
Expand All @@ -68,26 +68,22 @@ char* pinyin_get(char* cn){
len_pybuf=(len/2)*7+1;
pybuf_pos=pybuf=(char*)malloc(len_pybuf);
memset(pybuf,0,len_pybuf);
memset(single_cn_buf,0,3);
memset(single_cn_buf,0,JMP+1);

// strip ascii
for (i = 0; i < len; ++i)
{

if(cn[i]<0){ // chinese char
if(0==flag_cnchar_buf){
single_cn_buf[0]=cn[i];
flag_cnchar_buf=1;

//printf("0[%d] put into buff\n", cn[i]);
if((JMP-1)!=flag_cnchar_buf){
single_cn_buf[flag_cnchar_buf]=cn[i];
++flag_cnchar_buf;
}else{
char* single_cn_pinyin=NULL;
unsigned int len_of_py=0;
HashNode* result_node=NULL;

//printf("1[%d] put into buff\n", cn[i]);

single_cn_buf[1]=cn[i];
single_cn_buf[flag_cnchar_buf]=cn[i];
flag_cnchar_buf=0;
// translate

Expand All @@ -99,18 +95,16 @@ char* pinyin_get(char* cn){
pybuf_pos+=len_of_py;
}else{
single_cn_pinyin=(char*)result_node->nValue;
//printf("result: %s\n", single_cn_pinyin);
len_of_py=strlen(single_cn_pinyin);
strncpy(pybuf_pos,single_cn_pinyin,len_of_py);
pybuf_pos+=len_of_py;
}

memset(single_cn_buf, 0, 3);
memset(single_cn_buf, 0, JMP+1);
}
}else{ // other
//printf("~[%d] put into buff\n", cn[i]);
memset(pybuf_pos,cn[i],1);
pybuf_pos+=1;
++pybuf_pos;
}
}

Expand Down
6 changes: 3 additions & 3 deletions test_pinyin.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

int main(int argc, char const *argv[])
{
char* rst;int i=0;char* source="わたしわ李俊, and my English name is Rex Lee. 网名是独孤影! ^_^";
char* rst;int i=0;char* source="わたしわ李俊, and my English name is Rex Lee. 网名是独孤影! ^_^";
//HashNode* result_node;

pinyin_init();
Expand All @@ -16,12 +16,12 @@ int main(int argc, char const *argv[])
}
}*/

//source="";
//source="Ò»";
//result_node=(HashNode*)ht_lookup(&dict, source);
//rst=(char*)result_node->pNext->nValue;

rst=pinyin_get(source);
printf("%s\n%s", source, rst);

return 0;
}
}

0 comments on commit efbb558

Please sign in to comment.