00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "korebot.h"
00012
00013 static int kb_init_done = 0;
00014
00015 struct option opts[] = {
00016 { "kb-debug" , 1 , 0 , 'd' } ,
00017 { "kb-version" , 1 , 0 , 'v' } ,
00018 { NULL , 0 , 0 , 0 }
00019 };
00020
00021
00025 int kb_init( int argc , char * argv[] )
00026 {
00027 int opt, rc;
00028
00029 if ( kb_init_done == 0 ) {
00030
00031 for (;;) {
00032 opt = getopt_long( argc , argv , "" , opts , NULL );
00033 if ( opt == -1 )
00034 break;
00035
00036 switch( opt ) {
00037
00038 case 'd':
00039 kb_set_debug_level(atoi(optarg));
00040 break;
00041
00042
00043 case 'v':
00044 kb_msg( "libkorebot v%u.%u [%s]" ,
00045 KB_VERSION , KB_REVISION , __DATE__ );
00046 break;
00047
00048 default:
00049 break;
00050 }
00051 }
00052
00053 if ((rc = kb_config_init( argc, argv )) < 0 )
00054 return rc;
00055
00056 if ((rc = knet_init( argc , argv )) < 0)
00057 return rc;
00058
00059 atexit( kb_exit );
00060
00061 kb_init_done = 1;
00062 }
00063
00064 return 1;
00065 }
00066
00067
00074 void kb_exit(void)
00075 {
00076 if ( kb_init_done ) {
00077 knet_exit();
00078 kb_config_exit();
00079 kb_init_done = 0;
00080 }
00081 }