diff --git a/src/kit/shell/inc/shell.h b/src/kit/shell/inc/shell.h index 5400d9c5bafff20ecc0a42eacd7ac09ccdd2c08e..54ac45583c525ecfae690a999a70183f289151c3 100644 --- a/src/kit/shell/inc/shell.h +++ b/src/kit/shell/inc/shell.h @@ -68,7 +68,6 @@ void get_history_path(char* history); void cleanup_handler(void* arg); void exitShell(); int shellDumpResult(TAOS* con, char* fname, int* error_no, bool printMode); -void shellPrintNChar(const char* str, int length, int width); void shellGetGrantInfo(void *con); int isCommentLine(char *line); diff --git a/src/kit/shell/src/shellDarwin.c b/src/kit/shell/src/shellDarwin.c index 987087d71f801d351799966fe8b47d347c6bb2d2..98ea6510d7abd2cae75037653102d5487faba41d 100644 --- a/src/kit/shell/src/shellDarwin.c +++ b/src/kit/shell/src/shellDarwin.c @@ -349,31 +349,6 @@ void *shellLoopQuery(void *arg) { return NULL; } -void shellPrintNChar(const char *str, int length, int width) { - int pos = 0, cols = 0; - while (pos < length) { - wchar_t wc; - pos += mbtowc(&wc, str + pos, MB_CUR_MAX); - if (pos > length) { - break; - } - - int w = wcwidth(wc); - if (w > 0) { - if (width > 0 && cols + w > width) { - break; - } - printf("%lc", wc); - cols += w; - } - } - - for (; cols < width; cols++) { - putchar(' '); - } -} - - int get_old_terminal_mode(struct termios *tio) { /* Make sure stdin is a terminal. */ if (!isatty(STDIN_FILENO)) { diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 4ef51eaa5a8ff7e073fa421f0efcd137974ec694..5b4da875de38672df9f1b76ce6c9174b06f4318f 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -435,7 +435,6 @@ static int dumpResultToFile(const char* fname, TAOS_RES* result) { int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - int32_t* length = taos_fetch_lengths(result); int precision = taos_result_precision(result); for (int col = 0; col < num_fields; col++) { @@ -448,6 +447,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* result) { int numOfRows = 0; do { + int32_t* length = taos_fetch_lengths(result); for (int i = 0; i < num_fields; i++) { if (i > 0) { fputc(',', fp); @@ -465,6 +465,39 @@ static int dumpResultToFile(const char* fname, TAOS_RES* result) { } +static void shellPrintNChar(const char *str, int length, int width) { + int pos = 0, cols = 0; + while (pos < length) { + wchar_t wc; + int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX); + if (bytes == 0) { + break; + } + pos += bytes; + if (pos > length) { + break; + } + +#ifdef WINDOWS + int w = bytes; +#else + int w = wcwidth(wc); +#endif + if (w > 0) { + if (width > 0 && cols + w > width) { + break; + } + printf("%lc", wc); + cols += w; + } + } + + for (; cols < width; cols++) { + putchar(' '); + } +} + + static void printField(const char* val, TAOS_FIELD* field, int width, int32_t length, int precision) { if (val == NULL) { int w = width; @@ -523,7 +556,6 @@ static int verticalPrintResult(TAOS_RES* result) { int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - int32_t* length = taos_fetch_lengths(result); int precision = taos_result_precision(result); int maxColNameLen = 0; @@ -537,6 +569,7 @@ static int verticalPrintResult(TAOS_RES* result) { int numOfRows = 0; do { printf("*************************** %d.row ***************************\n", numOfRows + 1); + int32_t* length = taos_fetch_lengths(result); for (int i = 0; i < num_fields; i++) { TAOS_FIELD* field = fields + i; @@ -631,7 +664,6 @@ static int horizontalPrintResult(TAOS_RES* result) { int num_fields = taos_num_fields(result); TAOS_FIELD *fields = taos_fetch_fields(result); - int32_t* length = taos_fetch_lengths(result); int precision = taos_result_precision(result); int width[TSDB_MAX_COLUMNS]; @@ -643,6 +675,7 @@ static int horizontalPrintResult(TAOS_RES* result) { int numOfRows = 0; do { + int32_t* length = taos_fetch_lengths(result); for (int i = 0; i < num_fields; i++) { putchar(' '); printField(row[i], fields + i, width[i], length[i], precision); diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index d8b3e9bb4da07d0c6d333584ddaeee53655a263b..b4b74eae3ab13b4a22e7fa992317fd8f33bc3fbc 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -323,30 +323,6 @@ void *shellLoopQuery(void *arg) { return NULL; } -void shellPrintNChar(const char *str, int length, int width) { - int pos = 0, cols = 0; - while (pos < length) { - wchar_t wc; - pos += mbtowc(&wc, str + pos, MB_CUR_MAX); - if (pos > length) { - break; - } - - int w = wcwidth(wc); - if (w > 0) { - if (width > 0 && cols + w > width) { - break; - } - printf("%lc", wc); - cols += w; - } - } - - for (; cols < width; cols++) { - putchar(' '); - } -} - int get_old_terminal_mode(struct termios *tio) { /* Make sure stdin is a terminal. */ if (!isatty(STDIN_FILENO)) { diff --git a/src/kit/shell/src/shellWindows.c b/src/kit/shell/src/shellWindows.c index 440aa508ab493510d3a7771165f1be8f4fde4a79..48545f537e3848b955195ae261080b307e06a2f9 100644 --- a/src/kit/shell/src/shellWindows.c +++ b/src/kit/shell/src/shellWindows.c @@ -214,32 +214,6 @@ void *shellLoopQuery(void *arg) { return NULL; } -void shellPrintNChar(const char *str, int length, int width) { - int pos = 0, cols = 0; - while (pos < length) { - wchar_t wc; - int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX); - pos += bytes; - if (pos > length) { - break; - } - - int w = bytes; - if (w > 0) { - if (width > 0 && cols + w > width) { - break; - } - printf("%lc", wc); - cols += w; - } - } - - for (; cols < width; cols++) { - putchar(' '); - } -} - - void get_history_path(char *history) { sprintf(history, "%s/%s", ".", HISTORY_FILE); } void exitShell() { exit(EXIT_SUCCESS); }