Let the database engine to load be specified on the command-line

This commit is contained in:
Pierre Pronchery 2013-07-17 00:54:49 +02:00
parent 17da73f5a0
commit 2bbcf869f4

View File

@ -24,21 +24,21 @@
/* client */ /* client */
/* private */ /* private */
/* prototypes */ /* prototypes */
static int _client(void); static int _client(char const * engine);
static int _usage(void); static int _usage(void);
/* functions */ /* functions */
/* client */ /* client */
static int _client(void) static int _client(char const * engine)
{ {
Config * config; Config * config;
Database * db; Database * db;
char buf[BUFSIZ]; char buf[BUFSIZ];
if((config = config_new()) == NULL if((config = config_new()) == NULL
|| (db = database_new("pgsql", config, NULL)) == NULL) || (db = database_new(engine, config, NULL)) == NULL)
{ {
error_print("client"); error_print("client");
return 2; return 2;
@ -61,7 +61,8 @@ static int _client(void)
/* usage */ /* usage */
static int _usage(void) static int _usage(void)
{ {
fputs("Usage: client\n", stderr); fputs("Usage: client -d engine\n"
" -d Database engine to load\n", stderr);
return 1; return 1;
} }
@ -72,14 +73,18 @@ static int _usage(void)
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
int o; int o;
char const * engine = NULL;
while((o = getopt(argc, argv, "")) != -1) while((o = getopt(argc, argv, "d:")) != -1)
switch(o) switch(o)
{ {
case 'd':
engine = optarg;
break;
default: default:
return _usage(); return _usage();
} }
if(optind != argc) if(engine == NULL || optind != argc)
return _usage(); return _usage();
return (_client() == 0) ? 0 : 2; return (_client(engine) == 0) ? 0 : 2;
} }