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);
@ -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 ) {
@ -38,30 +37,30 @@ int main(int argc, char **argv)
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,47 +28,47 @@ 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>> ");
@ -78,17 +77,20 @@ int main(int argc, char **argv)
s_time = clock(); s_time = clock();
e = friso_dic_get( friso->dic, lex, _line ); e = friso_dic_get( friso->dic, lex, _line );
e_time = clock(); e_time = clock();
if ( e != NULL ) { if (e != NULL) {
printf("word=%s, syn=%s, fre=%d, cost:%fsec\n", printf(
e->word, e->syn==NULL? "NULL" : (char *)e->syn->items[0], e->fre, "word=%s, syn=%s, fre=%d, cost:%fsec\n",
(double) ( e_time - s_time ) / CLOCKS_PER_SEC ); 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); 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>

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 );
@ -27,4 +26,3 @@ int main ( int argc, char **args )
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,11 +19,16 @@ 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;
}
for ( j = 0; j < bytes; j++ ) {
word[j] = *(str + t + j ); word[j] = *(str + t + j );
}
word[j] = '\0'; word[j] = '\0';
string_buffer_append( sb, word ); string_buffer_append( sb, word );
printf("word=%s\n", word ); printf("word=%s\n", word );