Changeset: f952edb15c7a for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f952edb15c7a Modified Files: clients/mapiclient/mclient.c Branch: Mar2018 Log Message:
Use bool. diffs (truncated from 335 to 300 lines): diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c --- a/clients/mapiclient/mclient.c +++ b/clients/mapiclient/mclient.c @@ -71,11 +71,11 @@ static stream *fromConsole = NULL; static char *language = NULL; static char *logfile = NULL; static char promptbuf[16]; -static int echoquery = 0; +static bool echoquery = false; #ifdef HAVE_ICONV static char *encoding; #endif -static int errseen = 0; +static bool errseen = false; #define setPrompt() sprintf(promptbuf, "%.*s>", (int) sizeof(promptbuf) - 2, language) #define debugMode() (strncmp(promptbuf, "mdb", 3) == 0) @@ -94,7 +94,7 @@ enum formatters { }; static enum formatters formatter = NOformatter; char *separator = NULL; /* column separator for CSV/TAB format */ -int csvheader = 0; /* include header line in CSV format */ +bool csvheader = false; /* include header line in CSV format */ #define DEFWIDTH 80 @@ -123,9 +123,9 @@ static char *pager = 0; /* use external #endif static int rowsperpage = 0; /* for SQL pagination */ static int pagewidth = 0; /* -1: take whatever is necessary, >0: limit */ -static int pagewidthset = 0; /* whether the user set the width explicitly */ +static bool pagewidthset = false; /* whether the user set the width explicitly */ static int croppedfields = 0; /* whatever got cropped/truncated */ -static char firstcrop = 1; /* first time we see cropping/truncation */ +static bool firstcrop = true; /* first time we see cropping/truncation */ enum modifiers { NOmodifier, @@ -259,13 +259,13 @@ static enum itimers { T_PERF // return detailed performance } timermode = T_NONE; -static int timerHumanCalled = 0; +static bool timerHumanCalled = false; static void timerHuman(int64_t sqloptimizer, int64_t maloptimizer, int64_t querytime, int singleinstr, int total) { timertype t = th - t0; - timerHumanCalled = 1; + timerHumanCalled = true; /* * report only the times we do actually measure: @@ -571,7 +571,8 @@ utf8skip(char *s, size_t i) static int SQLrow(int *len, int *numeric, char **rest, int fields, int trim, char wm) { - int i, more, first = 1; + int i; + bool more, first = true; char *t; int rows = 0; /* return number of output lines printed */ size_t ulen; @@ -598,7 +599,7 @@ SQLrow(int *len, int *numeric, char **re cutafter[i] = -1; do { - more = 0; + more = false; for (i = 0; i < fields; i++) { if (rest[i] == NULL || *rest[i] == 0) { mnstr_printf(toConsole, "%c %*s ", @@ -697,7 +698,7 @@ SQLrow(int *len, int *numeric, char **re if (cutafter[i] == 0) rest[i] = NULL; if (rest[i]) - more = 1; + more = true; } else { mnstr_printf(toConsole, "%c", first ? '|' : i > 0 && cutafter[i - 1] == 0 ? '>' : ':'); @@ -736,7 +737,7 @@ SQLrow(int *len, int *numeric, char **re mnstr_printf(toConsole, "%c%s\n", first ? '|' : i > 0 && cutafter[i - 1] == 0 ? '>' : ':', wm ? ">" : ""); - first = 0; + first = false; rows++; } while (more); @@ -1667,8 +1668,8 @@ SQLrenderer(MapiHdl hdl) croppedfields, croppedfields != 1 ? "s" : ""); if (fields != printfields || croppedfields > 0) { mnstr_printf(toConsole, "!"); - if (firstcrop == 1) { - firstcrop = 0; + if (firstcrop) { + firstcrop = false; mnstr_printf(toConsole, "\nnote: to disable dropping columns and/or truncating fields use \\w-1"); } } @@ -1686,7 +1687,7 @@ setFormatter(const char *s) if (separator) free(separator); separator = NULL; - csvheader = 0; + csvheader = false; #ifdef _TWO_DIGIT_EXPONENT if (formatter == TESTformatter) _set_output_format(0); @@ -1712,7 +1713,7 @@ setFormatter(const char *s) separator[strlen(separator) - 1] = 0; } else separator = strdup(s + 4); - csvheader = 1; + csvheader = true; } else if (strcmp(s, "tab") == 0) { formatter = CSVformatter; separator = strdup("\t"); @@ -1824,7 +1825,7 @@ format_result(Mapi mid, MapiHdl hdl, int setWidth(); - timerHumanCalled = 0; + timerHumanCalled = false; do { /* handle errors first */ @@ -1836,7 +1837,7 @@ format_result(Mapi mid, MapiHdl hdl, int mapi_noexplain(mid, NULL); } mapi_explain_result(hdl, stderr); - errseen = 1; + errseen = true; /* don't need to print something like '0 * tuples' if we got an error */ continue; @@ -1983,7 +1984,7 @@ format_result(Mapi mid, MapiHdl hdl, int if (mnstr_errnr(toConsole)) { mnstr_clearerr(toConsole); fprintf(stderr, "write error\n"); - errseen = 1; + errseen = true; } #ifdef HAVE_POPEN end_pager(saveFD); @@ -2008,7 +2009,7 @@ doRequest(Mapi mid, const char *buf) mapi_noexplain(mid, NULL); } mapi_explain(mid, stderr); - errseen = 1; + errseen = true; return 1; } @@ -2040,7 +2041,7 @@ doRequest(Mapi mid, const char *buf) hdl = NULL; \ } else \ mapi_explain(mid, stderr); \ - errseen = 1; \ + errseen = true; \ break_or_continue; \ case MTIMEOUT: \ /* lost contact with the server */ \ @@ -2055,7 +2056,7 @@ doRequest(Mapi mid, const char *buf) hdl = NULL; \ } else \ mapi_explain(mid, stderr); \ - errseen = 1; \ + errseen = true; \ timerEnd(); \ if (buf) \ free(buf); \ @@ -2064,7 +2065,7 @@ doRequest(Mapi mid, const char *buf) return 1; \ } -static int +static bool doFileBulk(Mapi mid, stream *fp) { char *buf = NULL; @@ -2079,7 +2080,7 @@ doFileBulk(Mapi mid, stream *fp) fprintf(stderr, "cannot allocate memory for send buffer\n"); if (fp) close_stream(fp); - return 1; + return true; } timerStart(); @@ -2100,7 +2101,7 @@ doFileBulk(Mapi mid, stream *fp) buf[length] = 0; if (strlen(buf) < (size_t) length) { fprintf(stderr, "NULL byte in input\n"); - errseen = 1; + errseen = true; break; } } @@ -2260,7 +2261,7 @@ mydestroy(void *private) } #endif -static int +static bool doFile(Mapi mid, stream *fp, bool useinserts, bool interactive, int save_history) { char *line = NULL; @@ -2319,12 +2320,12 @@ doFile(Mapi mid, stream *fp, bool useins exit(2); } do { - int seen_null_byte = 0; + bool seen_null_byte = false; if (prompt) { char *p = hdl ? "more>" : prompt; /* clear errors when interactive */ - errseen = 0; + errseen = false; #ifdef HAVE_LIBREADLINE rl.prompt = p; #else @@ -2343,8 +2344,8 @@ doFile(Mapi mid, stream *fp, bool useins break; if (!seen_null_byte && strlen(buf + length) < (size_t) l) { fprintf(stderr, "NULL byte in input on line %d of input\n", lineno); - seen_null_byte = 1; - errseen = 1; + seen_null_byte = true; + errseen = true; if (hdl) { mapi_close_handle(hdl); hdl = NULL; @@ -2359,7 +2360,7 @@ doFile(Mapi mid, stream *fp, bool useins } else { fprintf(stderr,"Malloc failure"); length = 0; - errseen = 1; + errseen = true; if (hdl) { mapi_close_handle(hdl); hdl = NULL; @@ -2436,12 +2437,12 @@ doFile(Mapi mid, stream *fp, bool useins rowsperpage = atoi(line + 2); continue; case 'd': { - char hasWildcard = 0; - char hasSchema = 0; - char wantsSystem = 0; + bool hasWildcard = false; + bool hasSchema = false; + bool wantsSystem = false; unsigned int x = 0; char *p, *q; - char escaped = 0; + bool escaped = false; if (mode != SQL) break; while (my_isspace(line[length - 1])) @@ -2466,7 +2467,7 @@ doFile(Mapi mid, stream *fp, bool useins x |= MD_SCHEMA; break; case 'S': - wantsSystem = 1; + wantsSystem = true; break; default: fprintf(stderr, "unknown sub-command for \\d: %c\n", *line); @@ -2491,22 +2492,22 @@ doFile(Mapi mid, stream *fp, bool useins /* SQL escape */ *q++ = *p++; } else { - escaped = 0; + escaped = false; } } else { - escaped = 1; + escaped = true; } } else { if (!escaped) { *q++ = tolower((int) *p); if (*p == '*') { *p = '%'; - hasWildcard = 1; + hasWildcard = true; } else if (*p == '?') { *p = '_'; - hasWildcard = 1; + hasWildcard = true; } else if (*p == '.') { - hasSchema = 1; + hasSchema = true; } } else { *q++ = *p; @@ -2545,7 +2546,7 @@ doFile(Mapi mid, stream *fp, bool useins _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list