Optimize all the code style for all the test programes

This commit is contained in:
lionsoul 2020-02-18 10:44:29 +08:00
parent cdd37b06f0
commit 584fd65e0e
7 changed files with 128 additions and 120 deletions

View File

@ -1,11 +1,10 @@
/* /*
* dynamatic array test program. * dynamatic array test program.
* *
* @author chenxin * @author lionsoul<chenxin619315@gmail.com>
* @email chenxin619315@gmail.com
*/ */
#include "friso_API.h"
#include "friso_API.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>

View File

@ -5,8 +5,9 @@
* defferent threads/proccess use defferent friso_task_t. * defferent threads/proccess use defferent friso_task_t.
* and you could share the friso_config_t if you wish... * and you could share the friso_config_t if you wish...
* *
* @author chenxin <chenxin619315@gmail.com> * @author lionsoul<chenxin619315@gmail.com>
*/ */
#include "friso_API.h" #include "friso_API.h"
#include "friso.h" #include "friso.h"
@ -68,12 +69,13 @@ int main(int argc, char **argv)
friso_config_t config; friso_config_t config;
friso_task_t task; friso_task_t task;
//get the lexicon directory // get the lexicon directory from command line arguments
for ( i = 0; i < argc; i++ ) { for ( i = 0; i < argc; i++ ) {
if ( strcasecmp( "-init", argv[i] ) == 0 ) { if ( strcasecmp( "-init", argv[i] ) == 0 ) {
__path__ = argv[i+1]; __path__ = argv[i+1];
} }
} }
if ( __path__ == NULL ) { if ( __path__ == NULL ) {
println("Usage: friso -init lexicon path"); println("Usage: friso -init lexicon path");
exit(0); exit(0);
@ -82,7 +84,7 @@ int main(int argc, char **argv)
s_time = clock(); s_time = clock();
//initialize //initialize
friso = friso_new(); friso = friso_new();
config = friso_new_config(); config = friso_new_config();
/*friso_dic_t dic = friso_dic_new(); /*friso_dic_t dic = friso_dic_new();
friso_dic_load_from_ifile( dic, __path__, __LENGTH__ ); friso_dic_load_from_ifile( dic, __path__, __LENGTH__ );
@ -124,7 +126,7 @@ int main(int argc, char **argv)
print("friso>> "); print("friso>> ");
getLine( stdin, line ); getLine( stdin, line );
//exit the programe //exit the programe
if ( strcasecmp( line, "quit" ) == 0 ) { if (strcasecmp( line, "quit" ) == 0) {
___EXIT_INFO___ ___EXIT_INFO___
} }
@ -135,9 +137,14 @@ int main(int argc, char **argv)
s_time = clock(); s_time = clock();
while ( ( config->next_token( friso, config, task ) ) != NULL ) { while ( ( config->next_token( friso, config, task ) ) != NULL ) {
//printf("%s[%d, %d, %d] ", task->token->word, // printf(
// task->token->offset, task->token->length, task->token->rlen ); // "%s[%d, %d, %d] ",
printf("%s ", task->token->word ); // task->token->word,
// task->token->offset,
// task->token->length,
// task->token->rlen
// );
printf("%s ", task->token->word);
} }
//} //}
e_time = clock(); e_time = clock();
@ -145,13 +152,12 @@ int main(int argc, char **argv)
} }
friso_free_task( task ); friso_free_task(task);
//error block. //error block.
err: err:
friso_free_config(config); friso_free_config(config);
friso_free(friso); friso_free(friso);
return 0; return 0;
} }

View File

@ -1,11 +1,10 @@
/** /**
* File Explain. * hashmap testing program
* *
* @author chenxin * @author lionsoul<chenxin619315@gmail.com>
* @see http://www.webssky.com
*/ */
#include "friso_API.h"
#include "friso_API.h"
#include <stdio.h> #include <stdio.h>
void print_hash_info( friso_hash_t _hash ) { void print_hash_info( friso_hash_t _hash ) {
@ -17,51 +16,51 @@ int main(int argc, char **argv)
{ {
friso_hash_t _hash = new_hash_table(); friso_hash_t _hash = new_hash_table();
char *names[] = { char *names[] = {
"陈满文", "阳清华", "陈满文", "阳清华",
"陈鑫", "罗江艳", "陈鑫", "罗江艳",
"小燕子", "比比", "小燕子", "比比",
"张仁芳", "阳建", "张仁芳", "阳建",
"陈配", "李恒", "陈配", "李恒",
"张志刚", "张怡少", "张志刚", "张怡少",
"阳江波", "蔡再利", "阳江波", "蔡再利",
"阳绘章", "尹唐文", "阳绘章", "尹唐文",
"谭志鹏", "肖路德", "谭志鹏", "肖路德",
"潘凯", "刘潇", "潘凯", "刘潇",
"马朝辉", "张强", "马朝辉", "张强",
"殷美林", "元明清", "殷美林", "元明清",
"周安", "郭桥安", "周安", "郭桥安",
"刘敏", "黄广华", "刘敏", "黄广华",
"李胜", "黄海清" "李胜", "黄海清"
}; };
//char *str[] = {"陈鑫", "张仁芳", "比比"}; //char *str[] = {"陈鑫", "张仁芳", "比比"};
char **str = names; char **str = names;
int j, len = 30; int j, len = 30;
print_hash_info( _hash ); print_hash_info( _hash );
for ( j = 0; j < len; j++) { for (j = 0; j < len; j++) {
hash_put_mapping( _hash, names[j], names[j] ); hash_put_mapping(_hash, names[j], names[j]);
} }
print_hash_info( _hash ); print_hash_info(_hash);
printf("Press any key to continue."); printf("Press any key to continue.");
getchar(); getchar();
//remove mappings //remove mappings
for ( j = 0; j < len; j++ ) { for (j = 0; j < len; j++) {
printf("Exist %s?%2d\n", str[j], hash_exist_mapping( _hash, str[j] )); printf("Exist %s?%2d\n", str[j], hash_exist_mapping(_hash, str[j]));
printf("Now, remove %s\n", str[j]); printf("Now, remove %s\n", str[j]);
hash_remove_mapping( _hash, str[j] ); hash_remove_mapping(_hash, str[j]);
printf("Exist %s?%2d\n", str[j], hash_exist_mapping( _hash, str[j] )); printf("Exist %s?%2d\n", str[j], hash_exist_mapping(_hash, str[j]));
printf("*********************************\n"); printf("*********************************\n");
} }
printf("Press any key to continue."); printf("Press any key to continue.");
getchar(); getchar();
print_hash_info( _hash ); print_hash_info(_hash);
//free the table //free the table
free_hash_table( _hash, 0 ); free_hash_table(_hash, 0);
return 0; return 0;
} }

View File

@ -1,11 +1,10 @@
/* /*
* lex functions test program. * lex functions test program.
* *
* @author chenxin * @author lionsoul<chenxin619315@gmail.com>
* @see http://www.webssky.com
*/ */
#include "friso.h"
#include "friso.h"
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
@ -29,66 +28,69 @@ int main(int argc, char **argv)
friso = friso_new(); friso = friso_new();
friso->dic = friso_dic_new(); friso->dic = friso_dic_new();
//__CJK_WORDS__ //__CJK_WORDS__
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-main.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-main.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-admin.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-admin.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-chars.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-chars.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-cn-mz.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-cn-mz.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-cn-place.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-cn-place.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-company.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-company.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-festival.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-festival.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-flname.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-flname.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-food.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-food.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-lang.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-lang.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-nation.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-nation.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-net.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-net.lex", __LENGTH__);
friso_dic_load( friso, __LEX_CJK_WORDS__, "../dict/lex-org.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_WORDS__, "../dict/lex-org.lex", __LENGTH__);
//__CJK_UNITS__ //__CJK_UNITS__
friso_dic_load( friso, __LEX_CJK_UNITS__, "../dict/lex-units.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CJK_UNITS__, "../dict/lex-units.lex", __LENGTH__);
//__MIX_WORDS__ //__MIX_WORDS__
friso_dic_load( friso, __LEX_ECM_WORDS__, "../dict/lex-mixed.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_ECM_WORDS__, "../dict/lex-mixed.lex", __LENGTH__);
//__CN_LNAME__ //__CN_LNAME__
friso_dic_load( friso, __LEX_CN_LNAME__, "../dict/lex-lname.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CN_LNAME__, "../dict/lex-lname.lex", __LENGTH__);
//__CN_SNAME__ //__CN_SNAME__
friso_dic_load( friso, __LEX_CN_SNAME__, "../dict/lex-sname.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CN_SNAME__, "../dict/lex-sname.lex", __LENGTH__);
//__CN_DNAME1__ //__CN_DNAME1__
friso_dic_load( friso, __LEX_CN_DNAME1__, "../dict/lex-dname-1.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CN_DNAME1__, "../dict/lex-dname-1.lex", __LENGTH__);
//__CN_DNAME2__ //__CN_DNAME2__
friso_dic_load( friso, __LEX_CN_DNAME2__, "../dict/lex-dname-2.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CN_DNAME2__, "../dict/lex-dname-2.lex", __LENGTH__);
//__CN_LNA__ //__CN_LNA__
friso_dic_load( friso, __LEX_CN_LNA__, "../dict/lex-lna.lex", __LENGTH__ ); friso_dic_load(friso, __LEX_CN_LNA__, "../dict/lex-lna.lex", __LENGTH__ );
e_time = clock(); e_time = clock();
printf("Done, cost: %f sec, size=%d\n", ( double ) ( e_time - s_time ) / CLOCKS_PER_SEC, \ printf("Done, cost: %f sec, size=%d\n", ( double ) ( e_time - s_time ) / CLOCKS_PER_SEC, \
friso_all_dic_size( friso->dic ) ); friso_all_dic_size( friso->dic ) );
while ( 1 ) { while (1) {
printf("friso-%d>> ", lex); printf("friso-%d>> ", lex);
scanf("%s", _line); scanf("%s", _line);
if ( strcmp( _line, "quit" ) == 0 ) { if (strcmp( _line, "quit" ) == 0) {
break; break;
} else if ( strcmp( _line, "help" ) == 0 ) { } else if ( strcmp(_line, "help") == 0 ) {
___PRINT_HELP_INFO___ ___PRINT_HELP_INFO___
} else if ( strcmp( _line, "#set" ) == 0 ) { } else if ( strcmp( _line, "#set" ) == 0 ) {
printf("lex_t>> "); printf("lex_t>> ");
scanf("%d", &lex); scanf("%d", &lex);
} else {
s_time = clock();
e = friso_dic_get( friso->dic, lex, _line );
e_time = clock();
if ( e != NULL ) {
printf("word=%s, syn=%s, fre=%d, cost:%fsec\n",
e->word, e->syn==NULL? "NULL" : (char *)e->syn->items[0], e->fre,
(double) ( e_time - s_time ) / CLOCKS_PER_SEC );
} else { } else {
printf("%s was not found.\n", _line); s_time = clock();
e = friso_dic_get( friso->dic, lex, _line );
e_time = clock();
if (e != NULL) {
printf(
"word=%s, syn=%s, fre=%d, cost:%fsec\n",
e->word, e->syn==NULL? "NULL" : (char *)e->syn->items[0],
e->fre,
(double) ( e_time - s_time ) / CLOCKS_PER_SEC
);
} else {
printf("%s was not found.\n", _line);
}
} }
} }
}
//friso_dic_free( friso->dic ); // friso_dic_free( friso->dic );
friso_free(friso); friso_free(friso);
return 0; return 0;

View File

@ -1,11 +1,10 @@
/* /*
* link list test programe. * link list test programe.
* *
* @author chenxin * @author lionsoul<chenxin619315@gmail.com>
* @email chenxin619315@gmail.com
*/ */
#include "friso_API.h"
#include "friso_API.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -13,12 +12,12 @@ int main( int argc, char **args ) {
friso_link_t link; friso_link_t link;
fstring keys[] = { fstring keys[] = {
"chenmanwen", "yangqinghua", "chenmanwen", "yangqinghua",
"chenxin", "luojiangyan", "xiaoyanzi", "bibi", "chenxin", "luojiangyan", "xiaoyanzi", "bibi",
"zhangrenfang", "yangjian", "zhangrenfang", "yangjian",
"liuxiao", "pankai", "liuxiao", "pankai",
"chenpei", "liheng", "zhangzhigang", "zhgangyishao", "yangjiangbo", "chenpei", "liheng", "zhangzhigang", "zhgangyishao", "yangjiangbo",
"caizaili", "panpan", "xiaolude", "yintanwen" "caizaili", "panpan", "xiaolude", "yintanwen"
}; };
int j, len = sizeof( keys ) / sizeof( fstring ); int j, len = sizeof( keys ) / sizeof( fstring );
@ -28,15 +27,15 @@ int main( int argc, char **args ) {
printf("size=%d\n", link->size ); printf("size=%d\n", link->size );
for ( j = 0; j < len; j++ ) { for ( j = 0; j < len; j++ ) {
//link_add( link, keys[j] ); //link_add( link, keys[j] );
link_list_add_last( link, keys[j] ); link_list_add_last( link, keys[j] );
} }
printf("size=%d\n", link->size ); printf("size=%d\n", link->size );
for ( j = 0; j < len / 2; j++ ) { for ( j = 0; j < len / 2; j++ ) {
//printf("idx=%d, remove %s\n", j, ( fstring ) link_remove( link, 0 ) ); //printf("idx=%d, remove %s\n", j, ( fstring ) link_remove( link, 0 ) );
printf("idx=%d, remove %s\n", j, ( fstring ) link_list_remove_first( link ) ); printf("idx=%d, remove %s\n", j, ( fstring ) link_list_remove_first( link ) );
} }
printf("size=%d\n", link->size ); printf("size=%d\n", link->size );

View File

@ -1,17 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#include "friso_API.h"
/** /**
* friso fstring split test program . * friso fstring split test program .
* *
* @author chenxin<chenxin619315@gmail.com> * @author lionsoul<chenxin619315@gmail.com>
* @date 2013-06-09 */
*/
#include "friso_API.h"
#include <stdio.h>
#include <stdlib.h>
int main ( int argc, char **args ) int main ( int argc, char **args )
{ {
fstring source = ",I am a chinese,,my name is chenxin,and i am the author of friso,bug report email chenxin619315@gmail.com,qq:1187582057"; fstring source = ",I am a chinese,,my name is Lion,and i am the author of friso,bug report email chenxin619315@gmail.com,qq:1187582057";
char buffer[128]; char buffer[128];
string_split_t split = new_string_split(",", source ); string_split_t split = new_string_split(",", source );
@ -20,11 +19,10 @@ int main ( int argc, char **args )
printf("sst->delLen=%d\n", split->delLen); printf("sst->delLen=%d\n", split->delLen);
while ( string_split_next(split, buffer) != NULL) { while ( string_split_next(split, buffer) != NULL) {
printf("buffer:%s\n", buffer); printf("buffer:%s\n", buffer);
} }
free_string_split(split); free_string_split(split);
return 0; return 0;
} }

View File

@ -1,10 +1,10 @@
/* /*
* fstring handle mode test program. * fstring handle mode test program.
* *
* @author chenxin <chenxin619315@gmail.com> * @author lionsoul<chenxin619315@gmail.com>
*/ */
#include "friso_API.h"
#include "friso_API.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -19,14 +19,19 @@ int main( int argc, char **args ) {
printf("str=%s, length=%d\n", str, length ); printf("str=%s, length=%d\n", str, length );
for ( t = 0; t < length; t += bytes ) { for (t = 0; t < length; t += bytes) {
bytes = get_utf8_bytes( *(str + t) ); bytes = get_utf8_bytes(*(str + t));
if ( bytes == 0 ) continue; if ( bytes == 0 ) {
for ( j = 0; j < bytes; j++ ) continue;
word[j] = *(str + t + j ); }
word[j] = '\0';
string_buffer_append( sb, word ); for ( j = 0; j < bytes; j++ ) {
printf("word=%s\n", word ); word[j] = *(str + t + j );
}
word[j] = '\0';
string_buffer_append( sb, word );
printf("word=%s\n", word );
} }
printf("length=%d, buffer=%s\n", sb->length, sb->buffer ); printf("length=%d, buffer=%s\n", sb->length, sb->buffer );