From 7259c0a61e9942abe6212fbcc37132a3db27cf56 Mon Sep 17 00:00:00 2001 From: AlexDuan <417921451@qq.com> Date: Sat, 2 Oct 2021 12:36:05 +0800 Subject: [PATCH] init source --- src/kit/shell/inc/autoTab.h | 30 ++++++++++++++++++ src/kit/shell/inc/shell.h | 3 ++ src/kit/shell/src/autoTab.c | 54 ++++++++++++++++++++++++++++++++ src/kit/shell/src/shellDarwin.c | 4 +-- src/kit/shell/src/shellLinux.c | 7 +++-- src/kit/shell/src/shellMain.c | 1 + src/kit/shell/src/shellWindows.c | 4 +-- 7 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 src/kit/shell/inc/autoTab.h create mode 100644 src/kit/shell/src/autoTab.c diff --git a/src/kit/shell/inc/autoTab.h b/src/kit/shell/inc/autoTab.h new file mode 100644 index 0000000000..7fd35c2059 --- /dev/null +++ b/src/kit/shell/inc/autoTab.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef __AUTOTAB__ +#define __AUTOTAB__ + +#include "taos.h" +#include "shellCommand.h" + +// main entry +void pressTabKey(TAOS* con, Command* pcmd); + +// show help +void showHelp(); +// auto filling match words with pre +void autoFilling(char* pre, TAOS* conn, Command * pcmd); + +#endif diff --git a/src/kit/shell/inc/shell.h b/src/kit/shell/inc/shell.h index f207a866dd..d3ae40367d 100644 --- a/src/kit/shell/inc/shell.h +++ b/src/kit/shell/inc/shell.h @@ -27,10 +27,13 @@ #define MAX_IP_SIZE 20 #define MAX_HISTORY_SIZE 1000 #define MAX_COMMAND_SIZE 1048586 +#define DOUBLE_COMMAND_SIZE 2*MAX_COMMAND_SIZE #define HISTORY_FILE ".taos_history" #define DEFAULT_RES_SHOW_NUM 100 +#define TAB_KEY 9 + typedef struct SShellHistory { char* hist[MAX_HISTORY_SIZE]; int hstart; diff --git a/src/kit/shell/src/autoTab.c b/src/kit/shell/src/autoTab.c new file mode 100644 index 0000000000..a5a2838b56 --- /dev/null +++ b/src/kit/shell/src/autoTab.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _BSD_SOURCE +#define _GNU_SOURCE +#define _XOPEN_SOURCE +#define _DEFAULT_SOURCE + +#include "autoTab.h" +#include "os.h" +#include "shellCommand.h" + + +// main entry +void pressTabKey(TAOS* con, Command* pcmd) { + if(pcmd->commandSize == 0) { + // insert help + showHelp(); + showOnScreen(pcmd); + } else { + autoFilling(pcmd->command, con, pcmd); + } + +} + +void autoFilling(char* pre, TAOS* conn, Command * pcmd) { + // first level + + // second level + + + +} + +void showHelp() { + printf("You can run below command: \n"); + printf(" create database \n"); + printf(" create table \n"); + printf(" show databases \n"); + printf(" use databases \n"); + printf(" describe table \n"); +} diff --git a/src/kit/shell/src/shellDarwin.c b/src/kit/shell/src/shellDarwin.c index a1413be1ce..a70b532018 100644 --- a/src/kit/shell/src/shellDarwin.c +++ b/src/kit/shell/src/shellDarwin.c @@ -368,7 +368,7 @@ void *shellLoopQuery(void *arg) { pthread_cleanup_push(cleanup_handler, NULL); - char *command = malloc(MAX_COMMAND_SIZE); + char *command = malloc(DOUBLE_COMMAND_SIZE); if (command == NULL){ tscError("failed to malloc command"); return NULL; @@ -378,7 +378,7 @@ void *shellLoopQuery(void *arg) { do { // Read command from shell. - memset(command, 0, MAX_COMMAND_SIZE); + memset(command, 0, DOUBLE_COMMAND_SIZE); set_terminal_mode(); err = shellReadCommand(con, command); if (err) { diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index 93783b2055..f891766a4f 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -20,6 +20,7 @@ #include "shellCommand.h" #include "tkey.h" #include "tulog.h" +#include "autoTab.h" #define OPT_ABORT 1 /* �Cabort */ @@ -239,6 +240,8 @@ int32_t shellReadCommand(TAOS *con, char *command) { if (c == EOF) { return c; + } else if (c == TAB_KEY) { + pressTabKey(con, &cmd); } if (c < 0) { // For UTF-8 @@ -393,7 +396,7 @@ void *shellLoopQuery(void *arg) { pthread_cleanup_push(cleanup_handler, NULL); - char *command = malloc(MAX_COMMAND_SIZE); + char *command = malloc(DOUBLE_COMMAND_SIZE); if (command == NULL){ uError("failed to malloc command"); return NULL; @@ -403,7 +406,7 @@ void *shellLoopQuery(void *arg) { do { // Read command from shell. - memset(command, 0, MAX_COMMAND_SIZE); + memset(command, 0, DOUBLE_COMMAND_SIZE); set_terminal_mode(); err = shellReadCommand(con, command); if (err) { diff --git a/src/kit/shell/src/shellMain.c b/src/kit/shell/src/shellMain.c index 5c9dc0995d..5acff19652 100644 --- a/src/kit/shell/src/shellMain.c +++ b/src/kit/shell/src/shellMain.c @@ -95,6 +95,7 @@ SShellArguments args = { */ int main(int argc, char* argv[]) { /*setlocale(LC_ALL, "en_US.UTF-8"); */ + printf("hello wolrd shellmain.\n"); if (!checkVersion()) { exit(EXIT_FAILURE); diff --git a/src/kit/shell/src/shellWindows.c b/src/kit/shell/src/shellWindows.c index cb707d9331..b7bda30f89 100644 --- a/src/kit/shell/src/shellWindows.c +++ b/src/kit/shell/src/shellWindows.c @@ -301,13 +301,13 @@ int32_t shellReadCommand(TAOS *con, char command[]) { void *shellLoopQuery(void *arg) { TAOS *con = (TAOS *)arg; - char *command = malloc(MAX_COMMAND_SIZE); + char *command = malloc(DOUBLE_COMMAND_SIZE); if (command == NULL) return NULL; int32_t err = 0; do { - memset(command, 0, MAX_COMMAND_SIZE); + memset(command, 0, DOUBLE_COMMAND_SIZE); shellPrintPrompt(); // Read command from shell. -- GitLab