Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
10f99917
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
10f99917
编写于
4月 18, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
style: format shell
上级
78456366
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
93 addition
and
101 deletion
+93
-101
tools/shell/src/shellCommand.c
tools/shell/src/shellCommand.c
+5
-6
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+31
-27
tools/shell/src/shellMain.c
tools/shell/src/shellMain.c
+57
-68
未找到文件。
tools/shell/src/shellCommand.c
浏览文件 @
10f99917
...
...
@@ -15,9 +15,9 @@
#define __USE_XOPEN
#include "shellCommand.h"
#include "os.h"
#include "shell.h"
#include "shellCommand.h"
#include <regex.h>
...
...
@@ -48,7 +48,7 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) {
while
(
--
pos
>=
0
)
{
*
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
);
...
...
@@ -106,8 +106,7 @@ void clearLineBefore(Command *cmd) {
assert
(
cmd
->
cursorOffset
<=
cmd
->
commandSize
&&
cmd
->
endOffset
>=
cmd
->
screenOffset
);
clearScreen
(
cmd
->
endOffset
+
prompt_size
,
cmd
->
screenOffset
+
prompt_size
);
memmove
(
cmd
->
command
,
cmd
->
command
+
cmd
->
cursorOffset
,
cmd
->
commandSize
-
cmd
->
cursorOffset
);
memmove
(
cmd
->
command
,
cmd
->
command
+
cmd
->
cursorOffset
,
cmd
->
commandSize
-
cmd
->
cursorOffset
);
cmd
->
commandSize
-=
cmd
->
cursorOffset
;
cmd
->
cursorOffset
=
0
;
cmd
->
screenOffset
=
0
;
...
...
@@ -235,8 +234,8 @@ int isReadyGo(Command *cmd) {
sprintf
(
total
,
"%s%s"
,
cmd
->
buffer
,
cmd
->
command
);
char
*
reg_str
=
"(^.*;
\\
s*$)|(^
\\
s*$)|(^
\\
s*exit
\\
s*$)|(^
\\
s*q
\\
s*$)|(^
\\
s*quit
\\
s*$)|(^"
"
\\
s*clear
\\
s*$)"
;
"(^.*;
\\
s*$)|(^
\\
s*$)|(^
\\
s*exit
\\
s*$)|(^
\\
s*q
\\
s*$)|(^
\\
s*quit
\\
s*$)|(^"
"
\\
s*clear
\\
s*$)"
;
if
(
regex_match
(
total
,
reg_str
,
REG_EXTENDED
|
REG_ICASE
))
{
taosMemoryFree
(
total
);
return
1
;
...
...
tools/shell/src/shellEngine.c
浏览文件 @
10f99917
...
...
@@ -23,40 +23,43 @@
#include "shellCommand.h"
#include "taosdef.h"
#include "taoserror.h"
#include "tconfig.h"
#include "tglobal.h"
#include "ttypes.h"
#include "tutil.h"
#include "tconfig.h"
#include <regex.h>
#include <wordexp.h>
/**************** Global variables ****************/
#ifdef _TD_POWER_
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
"
;
char
PROMPT_HEADER
[]
=
"power> "
;
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
"
;
char
PROMPT_HEADER
[]
=
"power> "
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
7
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
7
;
#elif (_TD_TQ_ == true)
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
"
;
char
PROMPT_HEADER
[]
=
"tq> "
;
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
"
;
char
PROMPT_HEADER
[]
=
"tq> "
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
4
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
4
;
#else
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
"
;
char
PROMPT_HEADER
[]
=
"taos> "
;
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
"
;
char
PROMPT_HEADER
[]
=
"taos> "
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
6
;
char
CONTINUE_PROMPT
[]
=
" -> "
;
int
prompt_size
=
6
;
#endif
int64_t
result
=
0
;
SShellHistory
history
;
int64_t
result
=
0
;
SShellHistory
history
;
#define DEFAULT_MAX_BINARY_DISPLAY_WIDTH 30
extern
int32_t
tsMaxBinaryDisplayWidth
;
...
...
@@ -339,12 +342,12 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
atomic_store_64
(
&
result
,
0
);
freeResultWithRid
(
oresult
);
taos_free_result
(
pSql
);
taos_free_result
(
pSql
);
return
;
}
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pSql
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pSql
);
if
(
pFields
!=
NULL
)
{
// select and show kinds of commands
int
error_no
=
0
;
...
...
@@ -361,7 +364,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
}
else
{
printf
(
"Query interrupted (%s), %d row(s) in set (%.6fs)
\n
"
,
taos_errstr
(
pSql
),
numOfRows
,
(
et
-
st
)
/
1E6
);
}
taos_free_result
(
pSql
);
taos_free_result
(
pSql
);
}
else
{
int
num_rows_affacted
=
taos_affected_rows
(
pSql
);
taos_free_result
(
pSql
);
...
...
@@ -521,7 +524,8 @@ static int dumpResultToFile(const char *fname, TAOS_RES *tres) {
}
// 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
)
{
fprintf
(
stderr
,
"ERROR: failed to open file: %s
\n
"
,
full_path
.
we_wordv
[
0
]);
wordfree
(
&
full_path
);
...
...
@@ -901,8 +905,8 @@ void read_history() {
memset
(
history
.
hist
,
0
,
sizeof
(
char
*
)
*
MAX_HISTORY_SIZE
);
history
.
hstart
=
0
;
history
.
hend
=
0
;
char
*
line
=
NULL
;
int
read_size
=
0
;
char
*
line
=
NULL
;
int
read_size
=
0
;
char
f_history
[
TSDB_FILENAME_LEN
];
get_history_path
(
f_history
);
...
...
@@ -929,7 +933,7 @@ void read_history() {
}
}
if
(
line
!=
NULL
)
taosMemoryFree
(
line
);
if
(
line
!=
NULL
)
taosMemoryFree
(
line
);
taosCloseFile
(
&
pFile
);
}
...
...
@@ -1026,7 +1030,7 @@ void source_file(TAOS *con, char *fptr) {
}
taosMemoryFree
(
cmd
);
if
(
line
!=
NULL
)
taosMemoryFree
(
line
);
if
(
line
!=
NULL
)
taosMemoryFree
(
line
);
wordfree
(
&
full_path
);
taosCloseFile
(
&
pFile
);
}
...
...
tools/shell/src/shellMain.c
浏览文件 @
10f99917
...
...
@@ -14,45 +14,38 @@
*/
#define __USE_XOPEN
#include "os.h"
#include "shell.h"
#include "tglobal.h"
#include "tconfig.h"
#include "shellCommand.h"
#include "t
base64
.h"
#include "t
global
.h"
#include "tlog.h"
#include "version.h"
#include <wordexp.h>
#include <argp.h>
#include <termio.h>
#include <wordexp.h>
#define OPT_ABORT 1
/* abort */
int
indicator
=
1
;
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
void
taosNetTest
(
char
*
role
,
char
*
host
,
int32_t
port
,
int32_t
pkgLen
,
int32_t
pkgNum
,
char
*
pkgType
);
void
insertChar
(
Command
*
cmd
,
char
*
c
,
int
size
);
void
taosNetTest
(
char
*
role
,
char
*
host
,
int32_t
port
,
int32_t
pkgLen
,
int32_t
pkgNum
,
char
*
pkgType
);
const
char
*
argp_program_version
=
version
;
const
char
*
argp_program_bug_address
=
"<support@taosdata.com>"
;
static
char
doc
[]
=
""
;
static
char
args_doc
[]
=
""
;
TdThread
pid
;
TdThread
pid
;
static
tsem_t
cancelSem
;
static
struct
argp_option
options
[]
=
{
{
"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."
},
{
"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."
},
{
"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."
},
{
"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."
},
{
"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."
},
...
...
@@ -70,7 +63,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
/* Get the input argument from argp_parse, which we
know is a pointer to our arguments structure. */
SShellArguments
*
arguments
=
state
->
input
;
wordexp_t
full_path
;
wordexp_t
full_path
;
switch
(
key
)
{
case
'h'
:
...
...
@@ -80,7 +73,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
break
;
case
'P'
:
if
(
arg
)
{
arguments
->
port
=
atoi
(
arg
);
arguments
->
port
=
atoi
(
arg
);
}
else
{
fprintf
(
stderr
,
"Invalid port
\n
"
);
return
-
1
;
...
...
@@ -182,35 +175,33 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
/* Our argp parser. */
static
struct
argp
argp
=
{
options
,
parse_opt
,
args_doc
,
doc
};
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
"
;
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
"
;
char
g_password
[
SHELL_MAX_PASSWORD_LEN
];
static
void
parse_args
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
if
((
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
LINUXCLIENT_VERSION
,
tsOsName
,
taos_get_client_info
());
if
((
strlen
(
argv
[
i
])
==
2
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
"Enter password: "
);
taosSetConsoleEcho
(
false
);
if
(
scanf
(
"%20s"
,
g_password
)
>
1
)
{
fprintf
(
stderr
,
"password reading error
\n
"
);
}
taosSetConsoleEcho
(
true
);
if
(
EOF
==
getchar
())
{
fprintf
(
stderr
,
"getchar() return EOF
\n
"
);
}
}
else
{
tstrncpy
(
g_password
,
(
char
*
)(
argv
[
i
]
+
2
),
SHELL_MAX_PASSWORD_LEN
);
strcpy
(
argv
[
i
],
"-p"
);
}
arguments
->
password
=
g_password
;
arguments
->
is_use_passwd
=
true
;
static
void
parse_args
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
if
((
strncmp
(
argv
[
i
],
"-p"
,
2
)
==
0
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
LINUXCLIENT_VERSION
,
tsOsName
,
taos_get_client_info
());
if
((
strlen
(
argv
[
i
])
==
2
)
||
(
strncmp
(
argv
[
i
],
"--password"
,
10
)
==
0
))
{
printf
(
"Enter password: "
);
taosSetConsoleEcho
(
false
);
if
(
scanf
(
"%20s"
,
g_password
)
>
1
)
{
fprintf
(
stderr
,
"password reading error
\n
"
);
}
taosSetConsoleEcho
(
true
);
if
(
EOF
==
getchar
())
{
fprintf
(
stderr
,
"getchar() return EOF
\n
"
);
}
}
else
{
tstrncpy
(
g_password
,
(
char
*
)(
argv
[
i
]
+
2
),
SHELL_MAX_PASSWORD_LEN
);
strcpy
(
argv
[
i
],
"-p"
);
}
arguments
->
password
=
g_password
;
arguments
->
is_use_passwd
=
true
;
}
}
}
void
shellParseArgument
(
int
argc
,
char
*
argv
[],
SShellArguments
*
arguments
)
{
...
...
@@ -225,20 +216,20 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
argp_parse
(
&
argp
,
argc
,
argv
,
0
,
0
,
arguments
);
if
(
arguments
->
abort
)
{
#ifndef _ALPINE
#if 0
#ifndef _ALPINE
#if 0
error(10, 0, "ABORTED");
#endif
#else
abort
();
#endif
#endif
#else
abort
();
#endif
}
}
int32_t
shellReadCommand
(
TAOS
*
con
,
char
*
command
)
{
unsigned
hist_counter
=
history
.
hend
;
char
utf8_array
[
10
]
=
"
\0
"
;
Command
cmd
;
char
utf8_array
[
10
]
=
"
\0
"
;
Command
cmd
;
memset
(
&
cmd
,
0
,
sizeof
(
cmd
));
cmd
.
buffer
=
(
char
*
)
taosMemoryCalloc
(
1
,
MAX_COMMAND_SIZE
);
cmd
.
command
=
(
char
*
)
taosMemoryCalloc
(
1
,
MAX_COMMAND_SIZE
);
...
...
@@ -247,7 +238,7 @@ int32_t shellReadCommand(TAOS *con, char *command) {
// Read input.
char
c
;
while
(
1
)
{
c
=
(
char
)
getchar
();
// getchar() return an 'int' value
c
=
(
char
)
getchar
();
// getchar() return an 'int' value
if
(
c
==
EOF
)
{
return
c
;
...
...
@@ -406,13 +397,13 @@ void *shellLoopQuery(void *arg) {
taosThreadCleanupPush
(
cleanup_handler
,
NULL
);
char
*
command
=
taosMemoryMalloc
(
MAX_COMMAND_SIZE
);
if
(
command
==
NULL
){
if
(
command
==
NULL
)
{
uError
(
"failed to malloc command"
);
return
NULL
;
}
int32_t
err
=
0
;
do
{
// Read command from shell.
memset
(
command
,
0
,
MAX_COMMAND_SIZE
);
...
...
@@ -423,12 +414,12 @@ void *shellLoopQuery(void *arg) {
}
resetTerminalMode
();
}
while
(
shellRunCommand
(
con
,
command
)
==
0
);
taosMemoryFreeClear
(
command
);
exitShell
();
taosThreadCleanupPop
(
1
);
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
)
{
struct
winsize
w
;
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_row
=
30
;
}
...
...
@@ -458,13 +449,13 @@ void clearScreen(int ecmd_pos, int cursor_pos) {
void
showOnScreen
(
Command
*
cmd
)
{
struct
winsize
w
;
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_row
=
30
;
}
TdWchar
wc
;
int
size
=
0
;
int
size
=
0
;
// Print out the command.
char
*
total_string
=
taosMemoryMalloc
(
MAX_COMMAND_SIZE
);
...
...
@@ -531,13 +522,11 @@ void showOnScreen(Command *cmd) {
void
cleanup_handler
(
void
*
arg
)
{
resetTerminalMode
();
}
void
exitShell
()
{
/*int32_t ret =*/
resetTerminalMode
();
/*int32_t ret =*/
resetTerminalMode
();
taos_cleanup
();
exit
(
EXIT_SUCCESS
);
}
void
shellQueryInterruptHandler
(
int32_t
signum
,
void
*
sigInfo
,
void
*
context
)
{
tsem_post
(
&
cancelSem
);
}
void
shellQueryInterruptHandler
(
int32_t
signum
,
void
*
sigInfo
,
void
*
context
)
{
tsem_post
(
&
cancelSem
);
}
void
*
cancelHandler
(
void
*
arg
)
{
setThreadName
(
"cancelHandler"
);
...
...
@@ -554,7 +543,7 @@ void *cancelHandler(void *arg) {
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
taos_stop_query(pSql);
taosReleaseRef(tscObjRef, rid);
#endif
#endif
#else
resetTerminalMode
();
printf
(
"
\n
Receive ctrl+c or other signal, quit shell.
\n
"
);
...
...
@@ -640,11 +629,11 @@ int main(int argc, char *argv[]) {
con
=
taos_connect_auth
(
args
.
host
,
args
.
user
,
args
.
auth
,
args
.
database
,
args
.
port
);
}
/*
if (taos_init()) {
printf("Failed to init taos");
exit(EXIT_FAILURE);
}
*/
//
if (taos_init()) {
//
printf("Failed to init taos");
//
exit(EXIT_FAILURE);
//
}
taosNetTest
(
args
.
netTestRole
,
args
.
host
,
args
.
port
,
args
.
pktLen
,
args
.
pktNum
,
args
.
pktType
);
taos_close
(
con
);
exit
(
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录