Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f03055c3
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看板
提交
f03055c3
编写于
8月 05, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
shell: change shell record source file command
上级
e99782f4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
22 addition
and
9 deletion
+22
-9
tools/shell/src/shellEngine.c
tools/shell/src/shellEngine.c
+22
-9
未找到文件。
tools/shell/src/shellEngine.c
浏览文件 @
f03055c3
...
@@ -22,7 +22,8 @@
...
@@ -22,7 +22,8 @@
static
bool
shellIsEmptyCommand
(
const
char
*
cmd
);
static
bool
shellIsEmptyCommand
(
const
char
*
cmd
);
static
int32_t
shellRunSingleCommand
(
char
*
command
);
static
int32_t
shellRunSingleCommand
(
char
*
command
);
static
int32_t
shellRunCommand
(
char
*
command
);
static
void
shellRecordCommandToHistory
(
char
*
command
);
static
int32_t
shellRunCommand
(
char
*
command
,
bool
recordHistory
);
static
void
shellRunSingleCommandImp
(
char
*
command
);
static
void
shellRunSingleCommandImp
(
char
*
command
);
static
char
*
shellFormatTimestamp
(
char
*
buf
,
int64_t
val
,
int32_t
precision
);
static
char
*
shellFormatTimestamp
(
char
*
buf
,
int64_t
val
,
int32_t
precision
);
static
int32_t
shellDumpResultToFile
(
const
char
*
fname
,
TAOS_RES
*
tres
);
static
int32_t
shellDumpResultToFile
(
const
char
*
fname
,
TAOS_RES
*
tres
);
...
@@ -101,11 +102,7 @@ int32_t shellRunSingleCommand(char *command) {
...
@@ -101,11 +102,7 @@ int32_t shellRunSingleCommand(char *command) {
return
0
;
return
0
;
}
}
int32_t
shellRunCommand
(
char
*
command
)
{
void
shellRecordCommandToHistory
(
char
*
command
)
{
if
(
shellIsEmptyCommand
(
command
))
{
return
0
;
}
SShellHistory
*
pHistory
=
&
shell
.
history
;
SShellHistory
*
pHistory
=
&
shell
.
history
;
if
(
pHistory
->
hstart
==
pHistory
->
hend
||
if
(
pHistory
->
hstart
==
pHistory
->
hend
||
pHistory
->
hist
[(
pHistory
->
hend
+
SHELL_MAX_HISTORY_SIZE
-
1
)
%
SHELL_MAX_HISTORY_SIZE
]
==
NULL
||
pHistory
->
hist
[(
pHistory
->
hend
+
SHELL_MAX_HISTORY_SIZE
-
1
)
%
SHELL_MAX_HISTORY_SIZE
]
==
NULL
||
...
@@ -120,6 +117,14 @@ int32_t shellRunCommand(char *command) {
...
@@ -120,6 +117,14 @@ int32_t shellRunCommand(char *command) {
pHistory
->
hstart
=
(
pHistory
->
hstart
+
1
)
%
SHELL_MAX_HISTORY_SIZE
;
pHistory
->
hstart
=
(
pHistory
->
hstart
+
1
)
%
SHELL_MAX_HISTORY_SIZE
;
}
}
}
}
}
int32_t
shellRunCommand
(
char
*
command
,
bool
recordHistory
)
{
if
(
shellIsEmptyCommand
(
command
))
{
return
0
;
}
if
(
recordHistory
)
shellRecordCommandToHistory
(
command
);
char
quote
=
0
,
*
cmd
=
command
;
char
quote
=
0
,
*
cmd
=
command
;
for
(
char
c
=
*
command
++
;
c
!=
0
;
c
=
*
command
++
)
{
for
(
char
c
=
*
command
++
;
c
!=
0
;
c
=
*
command
++
)
{
...
@@ -826,11 +831,15 @@ void shellSourceFile(const char *file) {
...
@@ -826,11 +831,15 @@ void shellSourceFile(const char *file) {
size_t
cmd_len
=
0
;
size_t
cmd_len
=
0
;
char
*
line
=
NULL
;
char
*
line
=
NULL
;
char
fullname
[
PATH_MAX
]
=
{
0
};
char
fullname
[
PATH_MAX
]
=
{
0
};
char
sourceFileCommand
[
PATH_MAX
+
8
]
=
{
0
};
if
(
taosExpandDir
(
file
,
fullname
,
PATH_MAX
)
!=
0
)
{
if
(
taosExpandDir
(
file
,
fullname
,
PATH_MAX
)
!=
0
)
{
tstrncpy
(
fullname
,
file
,
PATH_MAX
);
tstrncpy
(
fullname
,
file
,
PATH_MAX
);
}
}
sprintf
(
sourceFileCommand
,
"source %s;"
,
fullname
);
shellRecordCommandToHistory
(
sourceFileCommand
);
TdFilePtr
pFile
=
taosOpenFile
(
fullname
,
TD_FILE_READ
|
TD_FILE_STREAM
);
TdFilePtr
pFile
=
taosOpenFile
(
fullname
,
TD_FILE_READ
|
TD_FILE_STREAM
);
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
fprintf
(
stderr
,
"failed to open file %s
\r\n
"
,
fullname
);
fprintf
(
stderr
,
"failed to open file %s
\r\n
"
,
fullname
);
...
@@ -853,9 +862,13 @@ void shellSourceFile(const char *file) {
...
@@ -853,9 +862,13 @@ void shellSourceFile(const char *file) {
continue
;
continue
;
}
}
if
(
line
[
read_len
-
1
]
==
'\r'
)
{
line
[
read_len
-
1
]
=
' '
;
}
memcpy
(
cmd
+
cmd_len
,
line
,
read_len
);
memcpy
(
cmd
+
cmd_len
,
line
,
read_len
);
printf
(
"%s%s
\r\n
"
,
shell
.
info
.
promptHeader
,
cmd
);
printf
(
"%s%s
\r\n
"
,
shell
.
info
.
promptHeader
,
cmd
);
shellRunCommand
(
cmd
);
shellRunCommand
(
cmd
,
false
);
memset
(
cmd
,
0
,
TSDB_MAX_ALLOWED_SQL_LEN
);
memset
(
cmd
,
0
,
TSDB_MAX_ALLOWED_SQL_LEN
);
cmd_len
=
0
;
cmd_len
=
0
;
}
}
...
@@ -977,7 +990,7 @@ void *shellThreadLoop(void *arg) {
...
@@ -977,7 +990,7 @@ void *shellThreadLoop(void *arg) {
}
}
taosResetTerminalMode
();
taosResetTerminalMode
();
}
while
(
shellRunCommand
(
command
)
==
0
);
}
while
(
shellRunCommand
(
command
,
true
)
==
0
);
taosMemoryFreeClear
(
command
);
taosMemoryFreeClear
(
command
);
shellWriteHistory
();
shellWriteHistory
();
...
@@ -1019,7 +1032,7 @@ int32_t shellExecute() {
...
@@ -1019,7 +1032,7 @@ int32_t shellExecute() {
if
(
pArgs
->
commands
!=
NULL
)
{
if
(
pArgs
->
commands
!=
NULL
)
{
printf
(
"%s%s
\r\n
"
,
shell
.
info
.
promptHeader
,
pArgs
->
commands
);
printf
(
"%s%s
\r\n
"
,
shell
.
info
.
promptHeader
,
pArgs
->
commands
);
char
*
cmd
=
strdup
(
pArgs
->
commands
);
char
*
cmd
=
strdup
(
pArgs
->
commands
);
shellRunCommand
(
cmd
);
shellRunCommand
(
cmd
,
true
);
taosMemoryFree
(
cmd
);
taosMemoryFree
(
cmd
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录