提交 7259c0a6 编写于 作者: A AlexDuan

init source

上级 7f9169ca
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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
...@@ -27,10 +27,13 @@ ...@@ -27,10 +27,13 @@
#define MAX_IP_SIZE 20 #define MAX_IP_SIZE 20
#define MAX_HISTORY_SIZE 1000 #define MAX_HISTORY_SIZE 1000
#define MAX_COMMAND_SIZE 1048586 #define MAX_COMMAND_SIZE 1048586
#define DOUBLE_COMMAND_SIZE 2*MAX_COMMAND_SIZE
#define HISTORY_FILE ".taos_history" #define HISTORY_FILE ".taos_history"
#define DEFAULT_RES_SHOW_NUM 100 #define DEFAULT_RES_SHOW_NUM 100
#define TAB_KEY 9
typedef struct SShellHistory { typedef struct SShellHistory {
char* hist[MAX_HISTORY_SIZE]; char* hist[MAX_HISTORY_SIZE];
int hstart; int hstart;
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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");
}
...@@ -368,7 +368,7 @@ void *shellLoopQuery(void *arg) { ...@@ -368,7 +368,7 @@ void *shellLoopQuery(void *arg) {
pthread_cleanup_push(cleanup_handler, NULL); pthread_cleanup_push(cleanup_handler, NULL);
char *command = malloc(MAX_COMMAND_SIZE); char *command = malloc(DOUBLE_COMMAND_SIZE);
if (command == NULL){ if (command == NULL){
tscError("failed to malloc command"); tscError("failed to malloc command");
return NULL; return NULL;
...@@ -378,7 +378,7 @@ void *shellLoopQuery(void *arg) { ...@@ -378,7 +378,7 @@ void *shellLoopQuery(void *arg) {
do { do {
// Read command from shell. // Read command from shell.
memset(command, 0, MAX_COMMAND_SIZE); memset(command, 0, DOUBLE_COMMAND_SIZE);
set_terminal_mode(); set_terminal_mode();
err = shellReadCommand(con, command); err = shellReadCommand(con, command);
if (err) { if (err) {
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "shellCommand.h" #include "shellCommand.h"
#include "tkey.h" #include "tkey.h"
#include "tulog.h" #include "tulog.h"
#include "autoTab.h"
#define OPT_ABORT 1 /* �Cabort */ #define OPT_ABORT 1 /* �Cabort */
...@@ -239,6 +240,8 @@ int32_t shellReadCommand(TAOS *con, char *command) { ...@@ -239,6 +240,8 @@ int32_t shellReadCommand(TAOS *con, char *command) {
if (c == EOF) { if (c == EOF) {
return c; return c;
} else if (c == TAB_KEY) {
pressTabKey(con, &cmd);
} }
if (c < 0) { // For UTF-8 if (c < 0) { // For UTF-8
...@@ -393,7 +396,7 @@ void *shellLoopQuery(void *arg) { ...@@ -393,7 +396,7 @@ void *shellLoopQuery(void *arg) {
pthread_cleanup_push(cleanup_handler, NULL); pthread_cleanup_push(cleanup_handler, NULL);
char *command = malloc(MAX_COMMAND_SIZE); char *command = malloc(DOUBLE_COMMAND_SIZE);
if (command == NULL){ if (command == NULL){
uError("failed to malloc command"); uError("failed to malloc command");
return NULL; return NULL;
...@@ -403,7 +406,7 @@ void *shellLoopQuery(void *arg) { ...@@ -403,7 +406,7 @@ void *shellLoopQuery(void *arg) {
do { do {
// Read command from shell. // Read command from shell.
memset(command, 0, MAX_COMMAND_SIZE); memset(command, 0, DOUBLE_COMMAND_SIZE);
set_terminal_mode(); set_terminal_mode();
err = shellReadCommand(con, command); err = shellReadCommand(con, command);
if (err) { if (err) {
......
...@@ -95,6 +95,7 @@ SShellArguments args = { ...@@ -95,6 +95,7 @@ SShellArguments args = {
*/ */
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
/*setlocale(LC_ALL, "en_US.UTF-8"); */ /*setlocale(LC_ALL, "en_US.UTF-8"); */
printf("hello wolrd shellmain.\n");
if (!checkVersion()) { if (!checkVersion()) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
......
...@@ -301,13 +301,13 @@ int32_t shellReadCommand(TAOS *con, char command[]) { ...@@ -301,13 +301,13 @@ int32_t shellReadCommand(TAOS *con, char command[]) {
void *shellLoopQuery(void *arg) { void *shellLoopQuery(void *arg) {
TAOS *con = (TAOS *)arg; TAOS *con = (TAOS *)arg;
char *command = malloc(MAX_COMMAND_SIZE); char *command = malloc(DOUBLE_COMMAND_SIZE);
if (command == NULL) return NULL; if (command == NULL) return NULL;
int32_t err = 0; int32_t err = 0;
do { do {
memset(command, 0, MAX_COMMAND_SIZE); memset(command, 0, DOUBLE_COMMAND_SIZE);
shellPrintPrompt(); shellPrintPrompt();
// Read command from shell. // Read command from shell.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册