Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1c106bfd
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
1c106bfd
编写于
10月 09, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
10月 09, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17235 from taosdata/feat/TD-17777-V30
feat(shell): Supported the word completed by press Tab key for 3.0
上级
329b76ed
c3357340
变更
4
展开全部
显示空白变更内容
内联
并排
Showing
4 changed file
with
888 addition
and
1047 deletion
+888
-1047
tools/shell/inc/shellAuto.h
tools/shell/inc/shellAuto.h
+1
-1
tools/shell/inc/shellTire.h
tools/shell/inc/shellTire.h
+29
-32
tools/shell/src/shellAuto.c
tools/shell/src/shellAuto.c
+539
-686
tools/shell/src/shellTire.c
tools/shell/src/shellTire.c
+319
-328
未找到文件。
tools/shell/inc/shellAuto.h
浏览文件 @
1c106bfd
tools/shell/inc/shellTire.h
浏览文件 @
1c106bfd
...
...
@@ -33,38 +33,35 @@
typedef
struct
STireNode
{
struct
STireNode
**
d
;
bool
end
;
// record end flag
}
STireNode
;
}
STireNode
;
typedef
struct
StrName
{
char
*
name
;
struct
StrName
*
next
;
}
StrName
;
char
*
name
;
struct
StrName
*
next
;
}
StrName
;
typedef
struct
STire
{
char
type
;
// see define TIRE_
STireNode
root
;
StrName
*
head
;
StrName
*
tail
;
StrName
*
head
;
StrName
*
tail
;
int
count
;
// all count
int
ref
;
}
STire
;
}
STire
;
typedef
struct
SMatchNode
{
char
*
word
;
struct
SMatchNode
*
next
;
}
SMatchNode
;
}
SMatchNode
;
typedef
struct
SMatch
{
SMatchNode
*
head
;
SMatchNode
*
tail
;
// append node to tail
int
count
;
char
pre
[
MAX_WORD_LEN
];
}
SMatch
;
}
SMatch
;
// ----------- interface -------------
...
...
tools/shell/src/shellAuto.c
浏览文件 @
1c106bfd
此差异已折叠。
点击以展开。
tools/shell/src/shellTire.c
浏览文件 @
1c106bfd
...
...
@@ -26,17 +26,16 @@ STire* createTire(char type) {
memset
(
tire
,
0
,
sizeof
(
STire
));
tire
->
ref
=
1
;
// init is 1
tire
->
type
=
type
;
tire
->
root
.
d
=
(
STireNode
**
)
taosMemoryCalloc
(
CHAR_CNT
,
sizeof
(
STireNode
*
));
tire
->
root
.
d
=
(
STireNode
**
)
taosMemoryCalloc
(
CHAR_CNT
,
sizeof
(
STireNode
*
));
return
tire
;
}
// free tire node
void
freeTireNode
(
STireNode
*
node
)
{
if
(
node
==
NULL
)
return
;
if
(
node
==
NULL
)
return
;
// nest free sub node on array d
if
(
node
->
d
)
{
if
(
node
->
d
)
{
for
(
int
i
=
0
;
i
<
CHAR_CNT
;
i
++
)
{
freeTireNode
(
node
->
d
[
i
]);
}
...
...
@@ -56,9 +55,9 @@ void freeTire(STire* tire) {
taosMemoryFree
(
tire
->
root
.
d
);
// free from list
StrName
*
item
=
tire
->
head
;
StrName
*
item
=
tire
->
head
;
while
(
item
)
{
StrName
*
next
=
item
->
next
;
StrName
*
next
=
item
->
next
;
// free string
taosMemoryFree
(
item
->
name
);
// free node
...
...
@@ -75,14 +74,14 @@ void freeTire(STire* tire) {
// insert a new word to list
bool
insertToList
(
STire
*
tire
,
char
*
word
)
{
StrName
*
p
=
(
StrName
*
)
taosMemoryMalloc
(
sizeof
(
StrName
));
StrName
*
p
=
(
StrName
*
)
taosMemoryMalloc
(
sizeof
(
StrName
));
p
->
name
=
strdup
(
word
);
p
->
next
=
NULL
;
if
(
tire
->
head
==
NULL
)
{
if
(
tire
->
head
==
NULL
)
{
tire
->
head
=
p
;
tire
->
tail
=
p
;
}
else
{
}
else
{
tire
->
tail
->
next
=
p
;
tire
->
tail
=
p
;
}
...
...
@@ -93,7 +92,7 @@ bool insertToList(STire* tire, char* word) {
// insert a new word to tree
bool
insertToTree
(
STire
*
tire
,
char
*
word
,
int
len
)
{
int
m
=
0
;
STireNode
**
nodes
=
tire
->
root
.
d
;
STireNode
**
nodes
=
tire
->
root
.
d
;
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
m
=
word
[
i
]
-
FIRST_ASCII
;
if
(
m
<
0
||
m
>
CHAR_CNT
)
{
...
...
@@ -102,7 +101,7 @@ bool insertToTree(STire* tire, char* word, int len) {
if
(
nodes
[
m
]
==
NULL
)
{
// no pointer
STireNode
*
p
=
(
STireNode
*
)
taosMemoryMalloc
(
sizeof
(
STireNode
));
STireNode
*
p
=
(
STireNode
*
)
taosMemoryMalloc
(
sizeof
(
STireNode
));
memset
(
p
,
0
,
sizeof
(
STireNode
));
nodes
[
m
]
=
p
;
if
(
i
==
len
-
1
)
{
...
...
@@ -114,7 +113,7 @@ bool insertToTree(STire* tire, char* word, int len) {
if
(
nodes
[
m
]
->
d
==
NULL
)
{
// malloc d
nodes
[
m
]
->
d
=
(
STireNode
**
)
taosMemoryCalloc
(
CHAR_CNT
,
sizeof
(
STireNode
*
));
nodes
[
m
]
->
d
=
(
STireNode
**
)
taosMemoryCalloc
(
CHAR_CNT
,
sizeof
(
STireNode
*
));
}
// move to next node
...
...
@@ -146,7 +145,7 @@ bool insertWord(STire* tire, char* word) {
// delete one word from list
bool
deleteFromList
(
STire
*
tire
,
char
*
word
)
{
StrName
*
item
=
tire
->
head
;
StrName
*
item
=
tire
->
head
;
while
(
item
)
{
if
(
strcmp
(
item
->
name
,
word
)
==
0
)
{
// found, reset empty to delete
...
...
@@ -176,7 +175,7 @@ bool deleteFromTree(STire* tire, char* word, int len) {
return
false
;
}
else
{
// not null
if
(
i
==
len
-
1
)
{
if
(
i
==
len
-
1
)
{
// this is last, only set end false , not free node
nodes
[
m
]
->
end
=
false
;
del
=
true
;
...
...
@@ -184,8 +183,7 @@ bool deleteFromTree(STire* tire, char* word, int len) {
}
}
if
(
nodes
[
m
]
->
d
==
NULL
)
break
;
if
(
nodes
[
m
]
->
d
==
NULL
)
break
;
// move to next node
nodes
=
nodes
[
m
]
->
d
;
}
...
...
@@ -216,9 +214,9 @@ bool deleteWord(STire* tire, char* word) {
return
false
;
}
void
addWordToMatch
(
SMatch
*
match
,
char
*
word
){
void
addWordToMatch
(
SMatch
*
match
,
char
*
word
)
{
// malloc new
SMatchNode
*
node
=
(
SMatchNode
*
)
taosMemoryMalloc
(
sizeof
(
SMatchNode
));
SMatchNode
*
node
=
(
SMatchNode
*
)
taosMemoryMalloc
(
sizeof
(
SMatchNode
));
memset
(
node
,
0
,
sizeof
(
SMatchNode
));
node
->
word
=
strdup
(
word
);
...
...
@@ -234,7 +232,7 @@ void addWordToMatch(SMatch* match, char* word){
// enum all words from node
void
enumAllWords
(
STireNode
**
nodes
,
char
*
prefix
,
SMatch
*
match
)
{
STireNode
*
c
;
STireNode
*
c
;
char
word
[
MAX_WORD_LEN
];
int
len
=
strlen
(
prefix
);
for
(
int
i
=
0
;
i
<
CHAR_CNT
;
i
++
)
{
...
...
@@ -255,18 +253,17 @@ void enumAllWords(STireNode** nodes, char* prefix, SMatch* match) {
addWordToMatch
(
match
,
word
);
}
// nested call next layer
if
(
c
->
d
)
enumAllWords
(
c
->
d
,
word
,
match
);
if
(
c
->
d
)
enumAllWords
(
c
->
d
,
word
,
match
);
}
}
}
// match prefix from list
void
matchPrefixFromList
(
STire
*
tire
,
char
*
prefix
,
SMatch
*
match
)
{
StrName
*
item
=
tire
->
head
;
StrName
*
item
=
tire
->
head
;
int
len
=
strlen
(
prefix
);
while
(
item
)
{
if
(
strncmp
(
item
->
name
,
prefix
,
len
)
==
0
)
{
if
(
strncmp
(
item
->
name
,
prefix
,
len
)
==
0
)
{
// prefix matched
addWordToMatch
(
match
,
item
->
name
);
}
...
...
@@ -304,29 +301,27 @@ void matchPrefixFromTree(STire* tire, char* prefix, SMatch* match) {
if
(
i
==
len
-
1
)
{
// malloc match if not pass by param match
if
(
root
==
NULL
)
{
root
=
(
SMatch
*
)
taosMemoryMalloc
(
sizeof
(
SMatch
));
root
=
(
SMatch
*
)
taosMemoryMalloc
(
sizeof
(
SMatch
));
memset
(
root
,
0
,
sizeof
(
SMatch
));
strcpy
(
root
->
pre
,
prefix
);
}
// prefix is match to end char
if
(
c
->
d
)
enumAllWords
(
c
->
d
,
prefix
,
root
);
if
(
c
->
d
)
enumAllWords
(
c
->
d
,
prefix
,
root
);
}
else
{
// move to next node continue match
if
(
c
->
d
==
NULL
)
break
;
if
(
c
->
d
==
NULL
)
break
;
nodes
=
c
->
d
;
}
}
// return
return
;
return
;
}
SMatch
*
matchPrefix
(
STire
*
tire
,
char
*
prefix
,
SMatch
*
match
)
{
if
(
match
==
NULL
)
{
match
=
(
SMatch
*
)
taosMemoryMalloc
(
sizeof
(
SMatch
));
if
(
match
==
NULL
)
{
match
=
(
SMatch
*
)
taosMemoryMalloc
(
sizeof
(
SMatch
));
memset
(
match
,
0
,
sizeof
(
SMatch
));
}
...
...
@@ -348,10 +343,9 @@ SMatch* matchPrefix(STire* tire, char* prefix, SMatch* match) {
return
match
;
}
// get all items from tires tree
void
enumFromList
(
STire
*
tire
,
SMatch
*
match
)
{
StrName
*
item
=
tire
->
head
;
StrName
*
item
=
tire
->
head
;
while
(
item
)
{
if
(
item
->
name
[
0
]
!=
0
)
{
// not delete
...
...
@@ -365,7 +359,7 @@ void enumFromList(STire* tire, SMatch* match) {
// get all items from tires tree
void
enumFromTree
(
STire
*
tire
,
SMatch
*
match
)
{
char
pre
[
2
]
=
{
0
,
0
};
char
pre
[
2
]
=
{
0
,
0
};
STireNode
*
c
;
// enum first layer
...
...
@@ -380,7 +374,7 @@ void enumFromTree(STire* tire, SMatch* match) {
}
// this branch have data
if
(
c
->
end
)
if
(
c
->
end
)
addWordToMatch
(
match
,
pre
);
else
matchPrefix
(
tire
,
pre
,
match
);
...
...
@@ -389,7 +383,7 @@ void enumFromTree(STire* tire, SMatch* match) {
// get all items from tires tree
SMatch
*
enumAll
(
STire
*
tire
)
{
SMatch
*
match
=
(
SMatch
*
)
taosMemoryMalloc
(
sizeof
(
SMatch
));
SMatch
*
match
=
(
SMatch
*
)
taosMemoryMalloc
(
sizeof
(
SMatch
));
memset
(
match
,
0
,
sizeof
(
SMatch
));
switch
(
tire
->
type
)
{
...
...
@@ -410,16 +404,13 @@ SMatch* enumAll(STire* tire) {
return
match
;
}
// free match result
void
freeMatchNode
(
SMatchNode
*
node
)
{
// first free next
if
(
node
->
next
)
freeMatchNode
(
node
->
next
);
if
(
node
->
next
)
freeMatchNode
(
node
->
next
);
// second free self
if
(
node
->
word
)
taosMemoryFree
(
node
->
word
);
if
(
node
->
word
)
taosMemoryFree
(
node
->
word
);
taosMemoryFree
(
node
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录