style: format shell
This commit is contained in:
parent
7845636676
commit
10f99917c9
|
@ -15,9 +15,9 @@
|
||||||
|
|
||||||
#define __USE_XOPEN
|
#define __USE_XOPEN
|
||||||
|
|
||||||
|
#include "shellCommand.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "shellCommand.h"
|
|
||||||
|
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) {
|
||||||
while (--pos >= 0) {
|
while (--pos >= 0) {
|
||||||
*size += 1;
|
*size += 1;
|
||||||
|
|
||||||
if (str[pos] > 0 || countPrefixOnes((unsigned char )str[pos]) > 1) break;
|
if (str[pos] > 0 || countPrefixOnes((unsigned char)str[pos]) > 1) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rc = taosMbToWchar(&wc, str + pos, MB_CUR_MAX);
|
int rc = taosMbToWchar(&wc, str + pos, MB_CUR_MAX);
|
||||||
|
@ -106,8 +106,7 @@ void clearLineBefore(Command *cmd) {
|
||||||
assert(cmd->cursorOffset <= cmd->commandSize && cmd->endOffset >= cmd->screenOffset);
|
assert(cmd->cursorOffset <= cmd->commandSize && cmd->endOffset >= cmd->screenOffset);
|
||||||
|
|
||||||
clearScreen(cmd->endOffset + prompt_size, cmd->screenOffset + prompt_size);
|
clearScreen(cmd->endOffset + prompt_size, cmd->screenOffset + prompt_size);
|
||||||
memmove(cmd->command, cmd->command + cmd->cursorOffset,
|
memmove(cmd->command, cmd->command + cmd->cursorOffset, cmd->commandSize - cmd->cursorOffset);
|
||||||
cmd->commandSize - cmd->cursorOffset);
|
|
||||||
cmd->commandSize -= cmd->cursorOffset;
|
cmd->commandSize -= cmd->cursorOffset;
|
||||||
cmd->cursorOffset = 0;
|
cmd->cursorOffset = 0;
|
||||||
cmd->screenOffset = 0;
|
cmd->screenOffset = 0;
|
||||||
|
|
|
@ -23,31 +23,34 @@
|
||||||
#include "shellCommand.h"
|
#include "shellCommand.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taoserror.h"
|
#include "taoserror.h"
|
||||||
|
#include "tconfig.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "tconfig.h"
|
|
||||||
|
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
|
||||||
/**************** Global variables ****************/
|
/**************** Global variables ****************/
|
||||||
#ifdef _TD_POWER_
|
#ifdef _TD_POWER_
|
||||||
char CLIENT_VERSION[] = "Welcome to the PowerDB shell from %s, Client Version:%s\n"
|
char CLIENT_VERSION[] =
|
||||||
|
"Welcome to the PowerDB shell from %s, Client Version:%s\n"
|
||||||
"Copyright (c) 2020 by PowerDB, Inc. All rights reserved.\n\n";
|
"Copyright (c) 2020 by PowerDB, Inc. All rights reserved.\n\n";
|
||||||
char PROMPT_HEADER[] = "power> ";
|
char PROMPT_HEADER[] = "power> ";
|
||||||
|
|
||||||
char CONTINUE_PROMPT[] = " -> ";
|
char CONTINUE_PROMPT[] = " -> ";
|
||||||
int prompt_size = 7;
|
int prompt_size = 7;
|
||||||
#elif (_TD_TQ_ == true)
|
#elif (_TD_TQ_ == true)
|
||||||
char CLIENT_VERSION[] = "Welcome to the TQ shell from %s, Client Version:%s\n"
|
char CLIENT_VERSION[] =
|
||||||
|
"Welcome to the TQ shell from %s, Client Version:%s\n"
|
||||||
"Copyright (c) 2020 by TQ, Inc. All rights reserved.\n\n";
|
"Copyright (c) 2020 by TQ, Inc. All rights reserved.\n\n";
|
||||||
char PROMPT_HEADER[] = "tq> ";
|
char PROMPT_HEADER[] = "tq> ";
|
||||||
|
|
||||||
char CONTINUE_PROMPT[] = " -> ";
|
char CONTINUE_PROMPT[] = " -> ";
|
||||||
int prompt_size = 4;
|
int prompt_size = 4;
|
||||||
#else
|
#else
|
||||||
char CLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n"
|
char CLIENT_VERSION[] =
|
||||||
|
"Welcome to the TDengine shell from %s, Client Version:%s\n"
|
||||||
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
|
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
|
||||||
char PROMPT_HEADER[] = "taos> ";
|
char PROMPT_HEADER[] = "taos> ";
|
||||||
|
|
||||||
|
@ -344,7 +347,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS_FIELD* pFields = taos_fetch_fields(pSql);
|
TAOS_FIELD *pFields = taos_fetch_fields(pSql);
|
||||||
if (pFields != NULL) { // select and show kinds of commands
|
if (pFields != NULL) { // select and show kinds of commands
|
||||||
int error_no = 0;
|
int error_no = 0;
|
||||||
|
|
||||||
|
@ -521,7 +524,8 @@ static int dumpResultToFile(const char *fname, TAOS_RES *tres) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FILE *fp = fopen(full_path.we_wordv[0], "w");
|
// FILE *fp = fopen(full_path.we_wordv[0], "w");
|
||||||
TdFilePtr pFile = taosOpenFile(full_path.we_wordv[0], TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM);
|
TdFilePtr pFile =
|
||||||
|
taosOpenFile(full_path.we_wordv[0], TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
fprintf(stderr, "ERROR: failed to open file: %s\n", full_path.we_wordv[0]);
|
fprintf(stderr, "ERROR: failed to open file: %s\n", full_path.we_wordv[0]);
|
||||||
wordfree(&full_path);
|
wordfree(&full_path);
|
||||||
|
@ -929,7 +933,7 @@ void read_history() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line != NULL) taosMemoryFree(line);
|
if (line != NULL) taosMemoryFree(line);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1026,7 +1030,7 @@ void source_file(TAOS *con, char *fptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(cmd);
|
taosMemoryFree(cmd);
|
||||||
if(line != NULL) taosMemoryFree(line);
|
if (line != NULL) taosMemoryFree(line);
|
||||||
wordfree(&full_path);
|
wordfree(&full_path);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,27 +14,20 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define __USE_XOPEN
|
#define __USE_XOPEN
|
||||||
#include "os.h"
|
|
||||||
#include "shell.h"
|
|
||||||
#include "tglobal.h"
|
|
||||||
#include "tconfig.h"
|
|
||||||
#include "shellCommand.h"
|
#include "shellCommand.h"
|
||||||
#include "tbase64.h"
|
#include "tglobal.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "version.h"
|
|
||||||
|
|
||||||
#include <wordexp.h>
|
|
||||||
#include <argp.h>
|
#include <argp.h>
|
||||||
#include <termio.h>
|
#include <termio.h>
|
||||||
|
#include <wordexp.h>
|
||||||
|
|
||||||
#define OPT_ABORT 1 /* abort */
|
#define OPT_ABORT 1 /* abort */
|
||||||
|
|
||||||
|
|
||||||
int indicator = 1;
|
int indicator = 1;
|
||||||
|
|
||||||
void insertChar(Command *cmd, char *c, int size);
|
void insertChar(Command *cmd, char *c, int size);
|
||||||
void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen,
|
void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen, int32_t pkgNum, char *pkgType);
|
||||||
int32_t pkgNum, char *pkgType);
|
|
||||||
const char *argp_program_version = version;
|
const char *argp_program_version = version;
|
||||||
const char *argp_program_bug_address = "<support@taosdata.com>";
|
const char *argp_program_bug_address = "<support@taosdata.com>";
|
||||||
static char doc[] = "";
|
static char doc[] = "";
|
||||||
|
@ -45,14 +38,14 @@ static tsem_t cancelSem;
|
||||||
|
|
||||||
static struct argp_option options[] = {
|
static struct argp_option options[] = {
|
||||||
{"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."},
|
{"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."},
|
||||||
{"password", 'p', 0, 0, "The password to use when connecting to the server."},
|
{"password", 'p', NULL, 0, "The password to use when connecting to the server."},
|
||||||
{"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."},
|
{"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."},
|
||||||
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
|
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
|
||||||
{"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."},
|
{"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."},
|
||||||
{"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."},
|
{"config-dir", 'c', "CONFIG_DIR", 0, "Configuration directory."},
|
||||||
{"dump-config", 'C', 0, 0, "Dump configuration."},
|
{"dump-config",'C', NULL, 0, "Dump configuration."},
|
||||||
{"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."},
|
{"commands", 's', "COMMANDS", 0, "Commands to run without enter the shell."},
|
||||||
{"raw-time", 'r', 0, 0, "Output time as uint64_t."},
|
{"raw-time", 'r', NULL, 0, "Output time as uint64_t."},
|
||||||
{"file", 'f', "FILE", 0, "Script to run without enter the shell."},
|
{"file", 'f', "FILE", 0, "Script to run without enter the shell."},
|
||||||
{"directory", 'D', "DIRECTORY", 0, "Use multi-thread to import all SQL files in the directory separately."},
|
{"directory", 'D', "DIRECTORY", 0, "Use multi-thread to import all SQL files in the directory separately."},
|
||||||
{"thread", 'T', "THREADNUM", 0, "Number of threads when using multi-thread to import data."},
|
{"thread", 'T', "THREADNUM", 0, "Number of threads when using multi-thread to import data."},
|
||||||
|
@ -182,18 +175,16 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
||||||
/* Our argp parser. */
|
/* Our argp parser. */
|
||||||
static struct argp argp = {options, parse_opt, args_doc, doc};
|
static struct argp argp = {options, parse_opt, args_doc, doc};
|
||||||
|
|
||||||
char LINUXCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n"
|
char LINUXCLIENT_VERSION[] =
|
||||||
|
"Welcome to the TDengine shell from %s, Client Version:%s\n"
|
||||||
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
|
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
|
||||||
char g_password[SHELL_MAX_PASSWORD_LEN];
|
char g_password[SHELL_MAX_PASSWORD_LEN];
|
||||||
|
|
||||||
static void parse_args(
|
static void parse_args(int argc, char *argv[], SShellArguments *arguments) {
|
||||||
int argc, char *argv[], SShellArguments *arguments) {
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if ((strncmp(argv[i], "-p", 2) == 0)
|
if ((strncmp(argv[i], "-p", 2) == 0) || (strncmp(argv[i], "--password", 10) == 0)) {
|
||||||
|| (strncmp(argv[i], "--password", 10) == 0)) {
|
|
||||||
printf(LINUXCLIENT_VERSION, tsOsName, taos_get_client_info());
|
printf(LINUXCLIENT_VERSION, tsOsName, taos_get_client_info());
|
||||||
if ((strlen(argv[i]) == 2)
|
if ((strlen(argv[i]) == 2) || (strncmp(argv[i], "--password", 10) == 0)) {
|
||||||
|| (strncmp(argv[i], "--password", 10) == 0)) {
|
|
||||||
printf("Enter password: ");
|
printf("Enter password: ");
|
||||||
taosSetConsoleEcho(false);
|
taosSetConsoleEcho(false);
|
||||||
if (scanf("%20s", g_password) > 1) {
|
if (scanf("%20s", g_password) > 1) {
|
||||||
|
@ -225,13 +216,13 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
|
||||||
|
|
||||||
argp_parse(&argp, argc, argv, 0, 0, arguments);
|
argp_parse(&argp, argc, argv, 0, 0, arguments);
|
||||||
if (arguments->abort) {
|
if (arguments->abort) {
|
||||||
#ifndef _ALPINE
|
#ifndef _ALPINE
|
||||||
#if 0
|
#if 0
|
||||||
error(10, 0, "ABORTED");
|
error(10, 0, "ABORTED");
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
abort();
|
abort();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +397,7 @@ void *shellLoopQuery(void *arg) {
|
||||||
taosThreadCleanupPush(cleanup_handler, NULL);
|
taosThreadCleanupPush(cleanup_handler, NULL);
|
||||||
|
|
||||||
char *command = taosMemoryMalloc(MAX_COMMAND_SIZE);
|
char *command = taosMemoryMalloc(MAX_COMMAND_SIZE);
|
||||||
if (command == NULL){
|
if (command == NULL) {
|
||||||
uError("failed to malloc command");
|
uError("failed to malloc command");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -437,7 +428,7 @@ void get_history_path(char *_history) { snprintf(_history, TSDB_FILENAME_LEN, "%
|
||||||
void clearScreen(int ecmd_pos, int cursor_pos) {
|
void clearScreen(int ecmd_pos, int cursor_pos) {
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) {
|
if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) {
|
||||||
//fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n");
|
// fprintf(stderr, "No stream device, and use default value(col 120, row 30)\n");
|
||||||
w.ws_col = 120;
|
w.ws_col = 120;
|
||||||
w.ws_row = 30;
|
w.ws_row = 30;
|
||||||
}
|
}
|
||||||
|
@ -458,7 +449,7 @@ void clearScreen(int ecmd_pos, int cursor_pos) {
|
||||||
void showOnScreen(Command *cmd) {
|
void showOnScreen(Command *cmd) {
|
||||||
struct winsize w;
|
struct winsize w;
|
||||||
if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) {
|
if (ioctl(0, TIOCGWINSZ, &w) < 0 || w.ws_col == 0 || w.ws_row == 0) {
|
||||||
//fprintf(stderr, "No stream device\n");
|
// fprintf(stderr, "No stream device\n");
|
||||||
w.ws_col = 120;
|
w.ws_col = 120;
|
||||||
w.ws_row = 30;
|
w.ws_row = 30;
|
||||||
}
|
}
|
||||||
|
@ -531,13 +522,11 @@ void showOnScreen(Command *cmd) {
|
||||||
void cleanup_handler(void *arg) { resetTerminalMode(); }
|
void cleanup_handler(void *arg) { resetTerminalMode(); }
|
||||||
|
|
||||||
void exitShell() {
|
void exitShell() {
|
||||||
/*int32_t ret =*/ resetTerminalMode();
|
/*int32_t ret =*/resetTerminalMode();
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) {
|
void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { tsem_post(&cancelSem); }
|
||||||
tsem_post(&cancelSem);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *cancelHandler(void *arg) {
|
void *cancelHandler(void *arg) {
|
||||||
setThreadName("cancelHandler");
|
setThreadName("cancelHandler");
|
||||||
|
@ -640,11 +629,11 @@ int main(int argc, char *argv[]) {
|
||||||
con = taos_connect_auth(args.host, args.user, args.auth, args.database, args.port);
|
con = taos_connect_auth(args.host, args.user, args.auth, args.database, args.port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if (taos_init()) {
|
// if (taos_init()) {
|
||||||
printf("Failed to init taos");
|
// printf("Failed to init taos");
|
||||||
exit(EXIT_FAILURE);
|
// exit(EXIT_FAILURE);
|
||||||
}
|
// }
|
||||||
*/
|
|
||||||
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType);
|
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType);
|
||||||
taos_close(con);
|
taos_close(con);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
Loading…
Reference in New Issue