Changeset: e018e3dc308b for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e018e3dc308b Modified Files: clients/mapiclient/mclient.c Branch: Mar2018 Log Message:
Sanitize options. Order them consistently in the two places they occur and use bool where appropriate. diffs (260 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -1414,7 +1414,7 @@ SQLdebugRendering(MapiHdl hdl) } static void -SQLpagemove(int *len, int fields, int *ps, int *silent) +SQLpagemove(int *len, int fields, int *ps, bool *silent) { char buf[512]; ssize_t sz; @@ -1427,11 +1427,11 @@ SQLpagemove(int *len, int fields, int *p if (buf[0] == 'c') *ps = 0; if (buf[0] == 'q') - *silent = 1; + *silent = true; while (sz > 0 && buf[sz - 1] != '\n') sz = mnstr_readline(fromConsole, buf, sizeof(buf)); } - if (*silent == 0) + if (!*silent) SQLseparator(len, fields, '-'); } @@ -1443,7 +1443,8 @@ SQLrenderer(MapiHdl hdl) int *len = NULL, *hdr = NULL, *numeric = NULL; char **rest = NULL; char buf[50]; - int ps = rowsperpage, silent = 0; + int ps = rowsperpage; + bool silent = false; int64_t rows = 0; croppedfields = 0; @@ -2260,7 +2261,7 @@ mydestroy(void *private) #endif static int -doFile(Mapi mid, stream *fp, bool useinserts, int interactive, int save_history) +doFile(Mapi mid, stream *fp, bool useinserts, bool interactive, int save_history) { char *line = NULL; char *buf = NULL; @@ -2282,7 +2283,7 @@ doFile(Mapi mid, stream *fp, bool useins && formatter != TESTformatter #endif ) { - interactive = 1; + interactive = true; setPrompt(); prompt = promptbuf; fromConsole = fp; @@ -3005,17 +3006,17 @@ main(int argc, char **argv) char *output = NULL; /* output format as string */ FILE *fp = NULL; int trace = 0; - int dump = 0; + bool dump = false; bool useinserts = false; int c = 0; Mapi mid; int save_history = 0; - int interactive = 0; - int has_fileargs = 0; + bool interactive = false; + bool has_fileargs = false; int option_index = 0; - int settz = 1; - int autocommit = 1; /* autocommit mode default on */ - char user_set_as_flag = 0; + bool settz = true; + bool autocommit = true; /* autocommit mode default on */ + bool user_set_as_flag = false; static struct option long_options[] = { {"autocommit", 0, 0, 'a'}, {"database", 1, 0, 'd'}, @@ -3072,15 +3073,15 @@ main(int argc, char **argv) mode = SQL; } - while ((c = getopt_long(argc, argv, "aDNd:e" + while ((c = getopt_long(argc, argv, "ad:De" #ifdef HAVE_ICONV "E:" #endif - "f:h:it:L:l:n:" + "f:h:Hil:L:n:Np:r:s:t:u:vw:Xz" #ifdef HAVE_POPEN "|:" #endif - "w:r:p:s:Xu:vzHP?", + "?", long_options, &option_index)) != -1) { switch (c) { case 0: @@ -3092,7 +3093,16 @@ main(int argc, char **argv) #endif break; case 'a': - autocommit = 0; + autocommit = false; + break; + case 'd': + assert(optarg); + if (dbname) + free(dbname); + dbname = strdup(optarg); + break; + case 'D': + dump = true; break; case 'e': echoquery = 1; @@ -3103,9 +3113,21 @@ main(int argc, char **argv) encoding = optarg; break; #endif - case 'L': + case 'f': + assert(optarg); + if (output != NULL) + free(output); + output = strdup(optarg); /* output format */ + break; + case 'h': assert(optarg); - logfile = strdup(optarg); + host = optarg; + break; + case 'H': + save_history = 1; + break; + case 'i': + interactive = true; break; case 'l': assert(optarg); @@ -3130,25 +3152,28 @@ main(int argc, char **argv) exit(-1); } break; + case 'L': + assert(optarg); + logfile = strdup(optarg); + break; case 'n': assert(optarg); nullstring = optarg; break; - case 'u': + case 'N': + useinserts = true; + break; + case 'p': assert(optarg); - if (user) - free(user); - user = strdup(optarg); - user_set_as_flag = 1; + port = atoi(optarg); break; - case 'f': + case 'r': assert(optarg); - if (output != NULL) - free(output); - output = strdup(optarg); /* output format */ + rowsperpage = atoi(optarg); break; - case 'i': - interactive = 1; + case 's': + assert(optarg); + command = optarg; break; case 't': if (optarg != NULL) { @@ -3164,50 +3189,12 @@ main(int argc, char **argv) } } break; - case 'h': - assert(optarg); - host = optarg; - break; - case 'p': - assert(optarg); - port = atoi(optarg); - break; - case 'D': - dump = 1; - break; - case 'N': - useinserts = true; - break; - case 'd': - assert(optarg); - if (dbname) - free(dbname); - dbname = strdup(optarg); - break; - case 's': + case 'u': assert(optarg); - command = optarg; - break; - case 'w': - assert(optarg); - pagewidth = atoi(optarg); - pagewidthset = pagewidth != 0; - break; - case 'r': - assert(optarg); - rowsperpage = atoi(optarg); - break; -#ifdef HAVE_POPEN - case '|': - assert(optarg); - pager = optarg; - break; -#endif - case 'X': - trace = MAPI_TRACE; - break; - case 'H': - save_history = 1; + if (user) + free(user); + user = strdup(optarg); + user_set_as_flag = true; break; case 'v': mnstr_printf(toConsole, @@ -3226,9 +3213,23 @@ main(int argc, char **argv) "character encoding: %s\n", encoding ? encoding : "utf-8 (default)"); #endif return 0; + case 'w': + assert(optarg); + pagewidth = atoi(optarg); + pagewidthset = pagewidth != 0; + break; + case 'X': + trace = MAPI_TRACE; + break; case 'z': - settz = 0; + settz = false; break; +#ifdef HAVE_POPEN + case '|': + assert(optarg); + pager = optarg; + break; +#endif case '?': /* a bit of a hack: look at the option that the * current `c' is based on and see if we recognize _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list