Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f299f87e7 | ||
|
|
3f3bfb2a97 | ||
|
|
46e451cc42 | ||
|
|
60f5aaad3f | ||
|
|
a4b4afdffd | ||
|
|
f82f388867 | ||
| 4df88d8680 | |||
|
|
2edb74f0e4 | ||
| a4b2a61e2c | |||
|
|
886e2dc188 | ||
|
|
8452db76d1 | ||
| ef1b483b5f |
10
option.go
10
option.go
@@ -30,10 +30,12 @@ func init() {
|
|||||||
//"--"
|
//"--"
|
||||||
{"--header", 10, parseHeader, nil},
|
{"--header", 10, parseHeader, nil},
|
||||||
{"--insecure", 15, parseInsecure, nil},
|
{"--insecure", 15, parseInsecure, nil},
|
||||||
{"--task", 10, parseITask, &extract{re: "--task +(.+)", execute: extractData}},
|
|
||||||
{"--user-agent", 15, parseUserAgent, &extract{re: "--user-agent +(.+)", execute: extractData}},
|
{"--user-agent", 15, parseUserAgent, &extract{re: "--user-agent +(.+)", execute: extractData}},
|
||||||
{"--user", 15, parseUser, &extract{re: "--user +(.+)", execute: extractData}},
|
{"--user", 15, parseUser, &extract{re: "--user +(.+)", execute: extractData}},
|
||||||
{"--connect-timeout", 15, parseTimeout, &extract{re: "--connect-timeout +(.+)", execute: extractData}},
|
{"--connect-timeout", 15, parseTimeout, &extract{re: "--connect-timeout +(.+)", execute: extractData}},
|
||||||
|
// 自定义
|
||||||
|
{"--task", 10, parseITask, &extract{re: "--task +(.+)", execute: extractData}},
|
||||||
|
{"--crontab", 10, parseCrontab, &extract{re: "--crontab +(.+)", execute: extractData}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, oe := range oelist {
|
for _, oe := range oelist {
|
||||||
@@ -79,7 +81,7 @@ func (oe *optionExecute) BuildFunction(curl *CURL, soption string) *parseFunctio
|
|||||||
|
|
||||||
func judgeOptions(u *CURL, soption string) *parseFunction {
|
func judgeOptions(u *CURL, soption string) *parseFunction {
|
||||||
word := trieStrWord(soption)
|
word := trieStrWord(soption)
|
||||||
if ioe := optionTrie.SearchMostPrefix(&word); ioe != nil {
|
if ioe := optionTrie.SearchDepth(&word); ioe != nil {
|
||||||
oe := ioe.(*optionExecute)
|
oe := ioe.(*optionExecute)
|
||||||
return oe.BuildFunction(u, soption)
|
return oe.BuildFunction(u, soption)
|
||||||
}
|
}
|
||||||
@@ -93,6 +95,10 @@ func extractData(re, soption string) string {
|
|||||||
return strings.Trim(datas[1], "'")
|
return strings.Trim(datas[1], "'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseCrontab(u *CURL, value string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func parseITask(u *CURL, value string) {
|
func parseITask(u *CURL, value string) {
|
||||||
u.ITask = value
|
u.ITask = value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,14 @@ func ParseRawCURL(scurl string) (cURL *CURL, err error) {
|
|||||||
scurl = strings.TrimSpace(scurl)
|
scurl = strings.TrimSpace(scurl)
|
||||||
scurl = strings.TrimLeft(scurl, "curl")
|
scurl = strings.TrimLeft(scurl, "curl")
|
||||||
|
|
||||||
mathches := regexp.MustCompile(`--[^ ]+ +'[^']+'|--[^ ]+ +[^ ]+|-[A-Za-z] +'[^']+'|-[A-Za-z] +[^ ]+| '[^']+'|--[a-z]+ {0,}`).FindAllString(scurl, -1)
|
mathches := regexp.MustCompile(
|
||||||
|
`--[^ ]+ +'[^']+'|`+
|
||||||
|
`--[^ ]+ +[^ ]+|`+
|
||||||
|
`-[A-Za-z] +'[^']+'|`+
|
||||||
|
`-[A-Za-z] +[^ ]+|`+
|
||||||
|
` '[^']+'|`+
|
||||||
|
`--[a-z]+ {0,}`,
|
||||||
|
).FindAllString(scurl, -1)
|
||||||
for _, m := range mathches {
|
for _, m := range mathches {
|
||||||
m = strings.TrimSpace(m)
|
m = strings.TrimSpace(m)
|
||||||
switch v := m[0]; v {
|
switch v := m[0]; v {
|
||||||
|
|||||||
243
structure.go
243
structure.go
@@ -1,6 +1,12 @@
|
|||||||
package curl2info
|
package curl2info
|
||||||
|
|
||||||
import "container/heap"
|
import (
|
||||||
|
"container/heap"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
)
|
||||||
|
|
||||||
// trieWord Trie 需要的Word接口
|
// trieWord Trie 需要的Word接口
|
||||||
type trieWord interface {
|
type trieWord interface {
|
||||||
@@ -104,7 +110,7 @@ func (trie *hTrie) Remove(word string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SearchMostPrefix Returns if the word is in the trie.
|
// SearchMostPrefix Returns if the word is in the trie.
|
||||||
func (trie *hTrie) SearchMostPrefix(iword trieWord) interface{} {
|
func (trie *hTrie) SearchDepth(iword trieWord) interface{} {
|
||||||
cur := trie
|
cur := trie
|
||||||
word := iword.GetWord()
|
word := iword.GetWord()
|
||||||
|
|
||||||
@@ -117,6 +123,8 @@ func (trie *hTrie) SearchMostPrefix(iword trieWord) interface{} {
|
|||||||
cur = next
|
cur = next
|
||||||
if cur.isWord {
|
if cur.isWord {
|
||||||
result = cur.value
|
result = cur.value
|
||||||
|
} else {
|
||||||
|
result = nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return result
|
return result
|
||||||
@@ -242,3 +250,234 @@ func (pqe *pQueueExecute) Len() int {
|
|||||||
// }
|
// }
|
||||||
// return content
|
// return content
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// CNode 循环链表 三色标记 不确定是否会清除循环引用, 网上说会
|
||||||
|
type CNode struct {
|
||||||
|
value interface{}
|
||||||
|
prev *CNode
|
||||||
|
next *CNode
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetValue 获取到Node的值
|
||||||
|
func (node *CNode) GetValue() interface{} {
|
||||||
|
return node.value
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetValue 获取到Node的值
|
||||||
|
func (node *CNode) SetValue(value interface{}) {
|
||||||
|
node.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
// CircularLinked 循环链表
|
||||||
|
type CircularLinked struct {
|
||||||
|
cursor *CNode
|
||||||
|
head *CNode
|
||||||
|
tail *CNode
|
||||||
|
size uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCircularLinked create a CircularLinked
|
||||||
|
func NewCircularLinked(values ...interface{}) *CircularLinked {
|
||||||
|
list := &CircularLinked{}
|
||||||
|
if len(values) > 0 {
|
||||||
|
list.Append(values...)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cursor get current Cursor
|
||||||
|
func (list *CircularLinked) Cursor() *CNode {
|
||||||
|
if list.cursor == nil {
|
||||||
|
list.cursor = list.head
|
||||||
|
}
|
||||||
|
return list.cursor
|
||||||
|
}
|
||||||
|
|
||||||
|
// MoveNext get next Cursor
|
||||||
|
func (list *CircularLinked) MoveNext() *CNode {
|
||||||
|
if list.cursor == nil {
|
||||||
|
list.cursor = list.head
|
||||||
|
}
|
||||||
|
list.cursor = list.cursor.next
|
||||||
|
return list.cursor
|
||||||
|
}
|
||||||
|
|
||||||
|
// MovePrev get prev Cursor
|
||||||
|
func (list *CircularLinked) MovePrev() *CNode {
|
||||||
|
if list.cursor == nil {
|
||||||
|
list.cursor = list.head
|
||||||
|
}
|
||||||
|
list.cursor = list.cursor.prev
|
||||||
|
return list.cursor
|
||||||
|
}
|
||||||
|
|
||||||
|
// CursorToHead cursor move to head
|
||||||
|
func (list *CircularLinked) CursorToHead() *CNode {
|
||||||
|
list.cursor = list.head
|
||||||
|
return list.cursor
|
||||||
|
}
|
||||||
|
|
||||||
|
// CursorToTail cursor move to tail
|
||||||
|
func (list *CircularLinked) CursorToTail() *CNode {
|
||||||
|
list.cursor = list.tail
|
||||||
|
return list.cursor
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetLoopValues 获取从头到尾的值
|
||||||
|
func (list *CircularLinked) GetLoopValues() []*CNode {
|
||||||
|
var result []*CNode
|
||||||
|
|
||||||
|
if list.head != nil {
|
||||||
|
result = append(result, list.head)
|
||||||
|
for cur := list.head.next; cur != list.head; cur = cur.next {
|
||||||
|
result = append(result, cur)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append a value (one or more) at the end of the list (same as Append())
|
||||||
|
func (list *CircularLinked) Append(values ...interface{}) {
|
||||||
|
for _, value := range values {
|
||||||
|
node := &CNode{value: value}
|
||||||
|
if list.size == 0 {
|
||||||
|
list.head = node
|
||||||
|
list.tail = node
|
||||||
|
node.next = node
|
||||||
|
node.prev = node
|
||||||
|
} else {
|
||||||
|
list.tail.next = node
|
||||||
|
node.next = list.head
|
||||||
|
node.prev = list.tail
|
||||||
|
list.tail = node
|
||||||
|
}
|
||||||
|
list.size++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove 移除一些节点
|
||||||
|
func (list *CircularLinked) Remove(node *CNode) {
|
||||||
|
|
||||||
|
switch list.size {
|
||||||
|
case 0:
|
||||||
|
list.errorNotInList(node)
|
||||||
|
case 1:
|
||||||
|
if list.head == node {
|
||||||
|
list.head = nil
|
||||||
|
list.tail = nil
|
||||||
|
node.next = nil
|
||||||
|
node.prev = nil
|
||||||
|
list.cursor = nil
|
||||||
|
list.size--
|
||||||
|
} else {
|
||||||
|
list.errorNotInList(node)
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
|
||||||
|
node.prev = nil
|
||||||
|
node.next = nil
|
||||||
|
|
||||||
|
switch node {
|
||||||
|
case list.head:
|
||||||
|
list.head = list.tail
|
||||||
|
list.tail.prev = list.head
|
||||||
|
list.head.next = list.tail
|
||||||
|
list.cursor = list.head
|
||||||
|
list.size--
|
||||||
|
case list.tail:
|
||||||
|
list.tail = list.head
|
||||||
|
list.tail.prev = list.head
|
||||||
|
list.head.next = list.tail
|
||||||
|
list.cursor = list.head
|
||||||
|
list.size--
|
||||||
|
default:
|
||||||
|
list.errorNotInList(node)
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
switch node {
|
||||||
|
case list.head:
|
||||||
|
_, next := list.cutAndSplice(node)
|
||||||
|
list.size--
|
||||||
|
list.head = next
|
||||||
|
if list.cursor == node {
|
||||||
|
list.cursor = next
|
||||||
|
}
|
||||||
|
case list.tail:
|
||||||
|
prev, _ := list.cutAndSplice(node)
|
||||||
|
list.size--
|
||||||
|
list.tail = prev
|
||||||
|
if list.cursor == node {
|
||||||
|
list.cursor = prev
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
_, next := list.cutAndSplice(node)
|
||||||
|
list.size--
|
||||||
|
if list.cursor == node {
|
||||||
|
list.cursor = next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// LookCursor for list show
|
||||||
|
func (list *CircularLinked) LookCursor() string {
|
||||||
|
cursor := list.Cursor()
|
||||||
|
|
||||||
|
content := "->["
|
||||||
|
cur := list.head
|
||||||
|
if list.size != 0 {
|
||||||
|
for size := uint64(0); size < list.size; size++ {
|
||||||
|
if cursor == cur {
|
||||||
|
content += "(" + spew.Sprint(cur.value) + ")" + ", "
|
||||||
|
} else {
|
||||||
|
content += spew.Sprint(cur.value) + ", "
|
||||||
|
}
|
||||||
|
|
||||||
|
cur = cur.next
|
||||||
|
}
|
||||||
|
}
|
||||||
|
content = strings.TrimRight(content, ", ")
|
||||||
|
showlen := len(content)
|
||||||
|
if showlen >= 64 {
|
||||||
|
showlen = 64
|
||||||
|
}
|
||||||
|
content += "]" + content[0:showlen] + " ..."
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear for list show
|
||||||
|
func (list *CircularLinked) Clear() {
|
||||||
|
if list.size != 0 {
|
||||||
|
list.head.prev = nil
|
||||||
|
list.tail.next = nil
|
||||||
|
list.head = nil
|
||||||
|
list.tail = nil
|
||||||
|
list.cursor = nil
|
||||||
|
list.size = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size for list show
|
||||||
|
func (list *CircularLinked) Size() uint64 {
|
||||||
|
return list.size
|
||||||
|
}
|
||||||
|
|
||||||
|
func (list *CircularLinked) errorNotInList(node *CNode) {
|
||||||
|
log.Println("the node value ", spew.Sprint(node), " is not in list")
|
||||||
|
}
|
||||||
|
|
||||||
|
// cutAndSplice 不考虑边界情况 上层使用的是否判断
|
||||||
|
func (list *CircularLinked) cutAndSplice(node *CNode) (prev, next *CNode) {
|
||||||
|
prev = node.prev
|
||||||
|
next = node.next
|
||||||
|
|
||||||
|
prev.next = next
|
||||||
|
next.prev = prev
|
||||||
|
|
||||||
|
node.prev = nil
|
||||||
|
node.next = nil
|
||||||
|
|
||||||
|
return prev, next
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user