Changeset: e9ea484670f4 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e9ea484670f4 Modified Files: clients/mapiclient/dotmonetdb.c clients/mapiclient/dotmonetdb.h clients/mapiclient/mclient.1 clients/mapiclient/mclient.c clients/mapiclient/msqldump.c clients/mapiclient/stethoscope.c clients/mapiclient/tachograph.c clients/mapiclient/tomograph.c Branch: Dec2016 Log Message:
Add database option to .monetdb file. This fixes bug 3445. Thanks to Patrick McPhee for the suggestion and the code. diffs (205 lines): diff --git a/clients/mapiclient/dotmonetdb.c b/clients/mapiclient/dotmonetdb.c --- a/clients/mapiclient/dotmonetdb.c +++ b/clients/mapiclient/dotmonetdb.c @@ -17,7 +17,7 @@ #endif void -parse_dotmonetdb(char **user, char **passwd, char **language, int *save_history, char **output, int *pagewidth) +parse_dotmonetdb(char **user, char **passwd, char **dbname, char **language, int *save_history, char **output, int *pagewidth) { char *cfile; FILE *config = NULL; @@ -52,6 +52,8 @@ parse_dotmonetdb(char **user, char **pas *user = NULL; if (passwd) *passwd = NULL; + if (dbname) + *dbname = NULL; if (language) *language = NULL; if (output) @@ -88,6 +90,10 @@ parse_dotmonetdb(char **user, char **pas if (passwd) *passwd = strdup(q); q = NULL; + } else if (strcmp(buf, "database") == 0) { + if (dbname) + *dbname = strdup(q); + q = NULL; } else if (strcmp(buf, "language") == 0) { /* make sure we don't set garbage */ if (strcmp(q, "sql") != 0 && diff --git a/clients/mapiclient/dotmonetdb.h b/clients/mapiclient/dotmonetdb.h --- a/clients/mapiclient/dotmonetdb.h +++ b/clients/mapiclient/dotmonetdb.h @@ -6,5 +6,5 @@ * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. */ -extern void parse_dotmonetdb(char **user, char **passwd, char **language, +extern void parse_dotmonetdb(char **user, char **passwd, char **dbname, char **language, int *save_history, char **output, int *pagewidth); diff --git a/clients/mapiclient/mclient.1 b/clients/mapiclient/mclient.1 --- a/clients/mapiclient/mclient.1 +++ b/clients/mapiclient/mclient.1 @@ -72,6 +72,7 @@ This file can contain defaults for the f .BR user , .BR password , .BR language , +.BR database , .BR save_history , .BR format , and diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -3034,7 +3034,7 @@ main(int argc, char **argv) #endif /* parse config file first, command line options override */ - parse_dotmonetdb(&user, &passwd, &language, &save_history, &output, &pagewidth); + parse_dotmonetdb(&user, &passwd, &dbname, &language, &save_history, &output, &pagewidth); pagewidthset = pagewidth != 0; if (language) { if (strcmp(language, "sql") == 0) { @@ -3157,7 +3157,9 @@ main(int argc, char **argv) break; case 'd': assert(optarg); - dbname = optarg; + if (dbname) + free(dbname); + dbname = strdup(optarg); break; case 's': assert(optarg); @@ -3255,7 +3257,7 @@ main(int argc, char **argv) if (dbname == NULL && has_fileargs && (fp = fopen(argv[optind], "r")) == NULL) { - dbname = argv[optind]; + dbname = strdup(argv[optind]); optind++; has_fileargs = optind != argc; } @@ -3271,6 +3273,9 @@ main(int argc, char **argv) if (passwd) free(passwd); passwd = NULL; + if (dbname) + free(dbname); + dbname = NULL; if (mid && mapi_error(mid) == MOK) mapi_reconnect(mid); /* actually, initial connect */ diff --git a/clients/mapiclient/msqldump.c b/clients/mapiclient/msqldump.c --- a/clients/mapiclient/msqldump.c +++ b/clients/mapiclient/msqldump.c @@ -99,7 +99,7 @@ main(int argc, char **argv) {0, 0, 0, 0} }; - parse_dotmonetdb(&user, &passwd, NULL, NULL, NULL, NULL); + parse_dotmonetdb(&user, &passwd, &dbname, NULL, NULL, NULL, NULL); while ((c = getopt_long(argc, argv, "h:p:d:Dft:NXu:q?", long_options, NULL)) != -1) { switch (c) { @@ -117,7 +117,9 @@ main(int argc, char **argv) port = atoi(optarg); break; case 'd': - dbname = optarg; + if (dbname) + free(dbname); + dbname = strdup(optarg); break; case 'D': describe = 1; @@ -152,7 +154,7 @@ main(int argc, char **argv) } if (optind == argc - 1) - dbname = argv[optind]; + dbname = strdup(argv[optind]); else if (optind != argc) usage(argv[0], -1); @@ -170,6 +172,8 @@ main(int argc, char **argv) free(user); if (passwd) free(passwd); + if (dbname) + free(dbname); if (mid == NULL) { fprintf(stderr, "failed to allocate Mapi structure\n"); exit(2); diff --git a/clients/mapiclient/stethoscope.c b/clients/mapiclient/stethoscope.c --- a/clients/mapiclient/stethoscope.c +++ b/clients/mapiclient/stethoscope.c @@ -205,7 +205,7 @@ main(int argc, char **argv) } /* parse config file first, command line options override */ - parse_dotmonetdb(&user, &password, NULL, NULL, NULL, NULL); + parse_dotmonetdb(&user, &password, &dbname, NULL, NULL, NULL, NULL); while (1) { int option_index = 0; @@ -221,7 +221,9 @@ main(int argc, char **argv) beat = atoi(optarg ? optarg : "5000"); break; case 'd': - dbname = optarg; + if (dbname) + free(dbname); + dbname = strdup(optarg); break; case 'u': if (user) diff --git a/clients/mapiclient/tachograph.c b/clients/mapiclient/tachograph.c --- a/clients/mapiclient/tachograph.c +++ b/clients/mapiclient/tachograph.c @@ -405,7 +405,7 @@ main(int argc, char **argv) }; /* parse config file first, command line options override */ - parse_dotmonetdb(&user, &password, NULL, NULL, NULL, NULL); + parse_dotmonetdb(&user, &password, &dbname, NULL, NULL, NULL, NULL); while (1) { int option_index = 0; @@ -418,7 +418,9 @@ main(int argc, char **argv) debug = 1; break; case 'd': - dbname = optarg; + if (dbname) + free(dbname); + dbname = strdup(optarg); break; case 'u': if (user) diff --git a/clients/mapiclient/tomograph.c b/clients/mapiclient/tomograph.c --- a/clients/mapiclient/tomograph.c +++ b/clients/mapiclient/tomograph.c @@ -1643,7 +1643,7 @@ main(int argc, char **argv) }; /* parse config file first, command line options override */ - parse_dotmonetdb(&user, &password, NULL, NULL, NULL, NULL); + parse_dotmonetdb(&user, &password, &dbname, NULL, NULL, NULL, NULL); if( argc == 1){ usageTomograph(); @@ -1669,7 +1669,9 @@ main(int argc, char **argv) debug = 1; break; case 'd': - prefix = dbname = optarg; + if (dbname) + free(dbname); + prefix = dbname = strdup(optarg); break; case 'i': inputfile = optarg; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list