diff --git a/include/os/os.h b/include/os/os.h index 41180ba49edf6ecee2482ab70cc419983bd11d8d..254c16efbe598a68c549a6c09e36b077929281bf 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -104,8 +104,6 @@ extern "C" { #include "osTimezone.h" #include "osEnv.h" -void osDefaultInit(); - #ifdef __cplusplus } #endif diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 269c92a670ffed95c2cd2b5d1f76bf97d5615f1b..dca70ce76b057447018fc23d2e911eb492670c84 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -631,7 +631,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) { - osDefaultInit(); + if (tsCfg == NULL) osDefaultInit(); SConfig *pCfg = cfgInit(); if (pCfg == NULL) return -1; diff --git a/source/os/src/osLocale.c b/source/os/src/osLocale.c index d2369ea2a29e2e45979b041e1f2b586c6374c4e3..c2d10f3668ba2856380eccbdadde74f5d6ed23ef 100644 --- a/source/os/src/osLocale.c +++ b/source/os/src/osLocale.c @@ -88,11 +88,11 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) { void taosGetSystemLocale(char *outLocale, char *outCharset) { #ifdef WINDOWS - char *locale = setlocale(LC_CTYPE, "chs"); + char *locale = setlocale(LC_CTYPE, "en_US.UTF-8"); if (locale != NULL) { tstrncpy(outLocale, locale, TD_LOCALE_LEN); } - strcpy(outCharset, "cp936"); + strcpy(outCharset, "UTF-8"); #elif defined(_TD_DARWIN_64) /* diff --git a/tests/script/wtest.bat b/tests/script/wtest.bat index 1aa27202c6a0b3da4da01741d8f2ba67de39bfef..1f089c9d869b8add918291e0807aed45063cf797 100644 --- a/tests/script/wtest.bat +++ b/tests/script/wtest.bat @@ -52,7 +52,7 @@ echo wal 0 >> %TAOS_CFG% echo asyncLog 0 >> %TAOS_CFG% echo locale en_US.UTF-8 >> %TAOS_CFG% echo enableCoreFile 1 >> %TAOS_CFG% -echo charset cp65001 >> %TAOS_CFG% +echo charset UTF-8 >> %TAOS_CFG% set "FILE_NAME=testSuite.sim" if "%1" == "-f" set "FILE_NAME=%2" diff --git a/tools/shell/src/shellCommand.c b/tools/shell/src/shellCommand.c index ef71f3fce6f8b21f09f85ed373233cc5714e6316..ddd4f7a59dbcfa83448c07c9a6652f0a1f467b8c 100644 --- a/tools/shell/src/shellCommand.c +++ b/tools/shell/src/shellCommand.c @@ -21,6 +21,7 @@ #define UP 3 #define DOWN 4 #define PSIZE shell.info.promptSize +#define SHELL_INPUT_MAX_COMMAND_SIZE 10000 typedef struct { char *buffer; @@ -227,6 +228,7 @@ void shellPrintChar(char c, int32_t times) { } void shellPositionCursor(int32_t step, int32_t direction) { +#ifndef WINDOWS if (step > 0) { if (direction == LEFT) { fprintf(stdout, "\033[%dD", step); @@ -239,6 +241,7 @@ void shellPositionCursor(int32_t step, int32_t direction) { } fflush(stdout); } +#endif } void shellUpdateBuffer(SShellCmd *cmd) { @@ -330,10 +333,14 @@ void shellClearScreen(int32_t ecmd_pos, int32_t cursor_pos) { int32_t command_x = ecmd_pos / ws_col; shellPositionCursor(cursor_y, LEFT); shellPositionCursor(command_x - cursor_x, DOWN); +#ifndef WINDOWS fprintf(stdout, "\033[2K"); +#endif for (int32_t i = 0; i < command_x; i++) { shellPositionCursor(1, UP); + #ifndef WINDOWS fprintf(stdout, "\033[2K"); + #endif } fflush(stdout); } @@ -394,6 +401,38 @@ void shellShowOnScreen(SShellCmd *cmd) { fflush(stdout); } +char taosGetConsoleChar() { +#ifdef WINDOWS + static void *console = NULL; + if (console == NULL) { + console = GetStdHandle(STD_INPUT_HANDLE); + } + static TdWchar buf[SHELL_INPUT_MAX_COMMAND_SIZE]; + static char mbStr[5]; + static unsigned long bufLen = 0; + static uint16_t bufIndex = 0, mbStrIndex = 0, mbStrLen = 0; + if (bufLen == 0) { + ReadConsoleW(console, buf, SHELL_INPUT_MAX_COMMAND_SIZE, &bufLen, NULL); + bufIndex = 0; + } + if (mbStrLen == 0){ + mbStrLen = WideCharToMultiByte(CP_UTF8, 0, &buf[bufIndex], 1, mbStr, sizeof(mbStr), NULL, NULL); + mbStrIndex = 0; + bufIndex++; + } + mbStrIndex++; + if (mbStrIndex == mbStrLen) { + mbStrLen = 0; + if (bufIndex == bufLen) { + bufLen = 0; + } + } + return mbStr[mbStrIndex-1]; +#else + return (char)getchar(); // getchar() return an 'int32_t' value +#endif +} + int32_t shellReadCommand(char *command) { SShellHistory *pHistory = &shell.history; SShellCmd cmd = {0}; @@ -407,7 +446,7 @@ int32_t shellReadCommand(char *command) { // Read input. char c; while (1) { - c = (char)getchar(); // getchar() return an 'int32_t' value + c = taosGetConsoleChar(); if (c == EOF) { return c; @@ -417,7 +456,7 @@ int32_t shellReadCommand(char *command) { int32_t count = shellCountPrefixOnes(c); utf8_array[0] = c; for (int32_t k = 1; k < count; k++) { - c = (char)getchar(); + c = taosGetConsoleChar(); utf8_array[k] = c; } shellInsertChar(&cmd, utf8_array, count); @@ -446,6 +485,7 @@ int32_t shellReadCommand(char *command) { shellBackspaceChar(&cmd); break; case '\n': + break; case '\r': #ifdef WINDOWS #else @@ -472,10 +512,10 @@ int32_t shellReadCommand(char *command) { break; } } else if (c == '\033') { - c = (char)getchar(); + c = taosGetConsoleChar(); switch (c) { case '[': - c = (char)getchar(); + c = taosGetConsoleChar(); switch (c) { case 'A': // Up arrow if (hist_counter != pHistory->hstart) { @@ -502,35 +542,35 @@ int32_t shellReadCommand(char *command) { shellMoveCursorLeft(&cmd); break; case '1': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Home key shellPositionCursorHome(&cmd); } break; case '2': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Insert key } break; case '3': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Delete key shellDeleteChar(&cmd); } break; case '4': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // End key shellPositionCursorEnd(&cmd); } break; case '5': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Page up key } break; case '6': - if ((c = (char)getchar()) == '~') { + if ((c = taosGetConsoleChar()) == '~') { // Page down key } break; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 1f29237d38b0441507bef05a39586d8a3b80ca56..2f8a21e47c0d7577e991f9c51e69b26804fc967d 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -393,15 +393,11 @@ void shellPrintNChar(const char *str, int32_t length, int32_t width) { break; } int w = 0; -#ifdef WINDOWS - w = bytes; -#else if(*(str + pos) == '\t' || *(str + pos) == '\n' || *(str + pos) == '\r'){ w = bytes; }else{ w = taosWcharWidth(wc); } -#endif pos += bytes; if (w <= 0) {