|
|
|
@ -24,10 +24,8 @@ unsigned int validatePortNumber(unsigned int portNumber){ |
|
|
|
|
void printHelp(){ |
|
|
|
|
printf("Usage: %s [options]\n", PACKAGE_NAME); |
|
|
|
|
printf( "Options are:\n" ); |
|
|
|
|
printf( "\t --database DATABASE A sqlite3 database file (Defatult: %s)\n", DEFAULT_DATABASE ); |
|
|
|
|
printf( "\t --config CONFIG A config file (Default: %s)\n", DEFAULT_CONFIG ); |
|
|
|
|
printf( "\t --port PORT The listening port (Default: %i)\n", DEFAULT_PORT ); |
|
|
|
|
printf( "\t --help Display version information.\n"); |
|
|
|
|
printf( "\t --config OPTION VALUE Sets config option OPTION to VALUE\n" ); |
|
|
|
|
printf( "\t --print-config Prints current config\n" ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char**argv){ |
|
|
|
@ -39,24 +37,15 @@ int main(int argc, char**argv){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for ( unsigned int i = 1; i < argc; i++ ){ |
|
|
|
|
if ( strcmp( argv[i], "--database" ) == 0 ){ |
|
|
|
|
if ( i + 1 < argc ){ |
|
|
|
|
database = argv[++i]; |
|
|
|
|
if ( strcmp( argv[i], "--config" ) == 0 ){ |
|
|
|
|
if ( i + 2 < argc ){ |
|
|
|
|
setConfig( defaultconfig, argv[i + 1], argv[i + 2] ); |
|
|
|
|
} else { |
|
|
|
|
printf("--database requires a positional argument\n"); |
|
|
|
|
} |
|
|
|
|
} else if ( strcmp( argv[i], "--config" ) == 0 ){ |
|
|
|
|
if ( i + 1 < argc ){ |
|
|
|
|
config = argv[++i]; |
|
|
|
|
} else { |
|
|
|
|
printf("--config requires a positional argument\n"); |
|
|
|
|
} |
|
|
|
|
} else if ( strcmp( argv[i], "--port" ) == 0 ){ |
|
|
|
|
if ( i + 1 < argc ){ |
|
|
|
|
port = validatePortNumber( atoi(argv[++i]) ); |
|
|
|
|
} else { |
|
|
|
|
printf("--port requires a positional argument\n"); |
|
|
|
|
printf("--config requires 2 positional arguments\n"); |
|
|
|
|
} |
|
|
|
|
} else if ( strcmp( argv[i], "--print-config" ) == 0 ){ |
|
|
|
|
printConfig(defaultconfig); |
|
|
|
|
return 0; |
|
|
|
|
} else if ( strcmp( argv[i], "--help" ) == 0 ){ |
|
|
|
|
printHelp(); |
|
|
|
|
return 0; |
|
|
|
|