!411 添加解析器指令,以支持DBus

Merge pull request !411 from a-alpha/alpha-dev
This commit is contained in:
a-alpha 2024-06-18 02:59:52 +00:00 committed by Gitee
commit 0ca0183230
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 81 additions and 23 deletions

View File

@ -29,10 +29,10 @@
package Interpreter package Interpreter
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"strings" "os/exec"
"os/exec" "strings"
) )
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -62,6 +62,44 @@ func
return rc return rc
} }
func
(iio InterIO) RecvBetween(delim_s string) (ret string, rc error ) {
output := ""
list:=strings.Split(delim_s, "%s")
if(len(list)<2){
return "", nil
}
start:=list[0]
end:=list[1]
find_start :=0
for {
recv, _, err := iio.Reader.ReadLine()
if (nil != err) {
return "", err
} // if ( ...
// rev start
if strings.Contains(string(recv), start) {
find_start=1
continue
}
if (find_start == 1) {
// rev end
if strings.Contains(string(recv), end) {
break
}
output += string(recv)
}
} // for { ...
//fmt.Println("RecvBetween:", output)
ret = output
rc = nil
/* */
return output, rc
}
func func
(iio InterIO) RecvUntil(delim_s string) (ret string, rc error) { (iio InterIO) RecvUntil(delim_s string) (ret string, rc error) {
output := "" output := ""
@ -113,15 +151,15 @@ func
(iio InterIO) Recv(n int) (string, error) { (iio InterIO) Recv(n int) (string, error) {
var out []byte var out []byte
var rc error var rc error
for i := 0; i < n ; i++ { for i := 0; i < n ; i++ {
c, rc1 := iio.Reader.ReadByte() c, rc1 := iio.Reader.ReadByte()
out = append(out, c) out = append(out, c)
rc = rc1 rc = rc1
} }
outstring := strings.TrimRight(string(out)," ")
return string(out), rc return outstring, rc
} }
func func

View File

@ -28,9 +28,6 @@
package Interpreter package Interpreter
import (
)
const ( const (
// 注释的属于"不定义命令",即命令不合理 // 注释的属于"不定义命令",即命令不合理
INTERPRETER_CMD_LEN int = 3 INTERPRETER_CMD_LEN int = 3
@ -41,9 +38,10 @@ const (
//INTERPRETER_CMD_SEND_POC_CHECK string = "<?:" //INTERPRETER_CMD_SEND_POC_CHECK string = "<?:"
INTERPRETER_CMD_RECV_POC_CHECK string = ">?:" INTERPRETER_CMD_RECV_POC_CHECK string = ">?:"
INTERPRETER_CMD_RECV_POC_CHECK_RC string = "??:" INTERPRETER_CMD_RECV_POC_CHECK_RC string = "??:"
INTERPRETER_CMD_RECV_BETWEEN string = ">#:"
) )
var errMap = map[string]string{ var ERRORMAP = map[string]string{
"0":"signal: segmentation fault (core dumped)", "0":"signal: segmentation fault (core dumped)",
"1":"signal: aborted (core dumped)", "1":"signal: aborted (core dumped)",
"2":"exit status 1", "2":"exit status 1",

View File

@ -51,42 +51,64 @@ const (
A_DEBUG_LEVEL_WARNING int = 2 A_DEBUG_LEVEL_WARNING int = 2
A_DEBUG_LEVEL_ERROR int = 3 A_DEBUG_LEVEL_ERROR int = 3
A_DEBUG_LEVEL_STR_INFO string = "info" A_DEBUG_LEVEL_STR_INFO string = "[+] Info"
A_DEBUG_LEVEL_STR_NOTE string = "note" A_DEBUG_LEVEL_STR_NOTE string = "[*] Note"
A_DEBUG_LEVEL_STR_WARNING string = "warning" A_DEBUG_LEVEL_STR_WARNING string = "[!] Warning"
A_DEBUG_LEVEL_STR_ERROR string = "error" A_DEBUG_LEVEL_STR_ERROR string = "[-] Error"
A_DEBUG_LEVEL_COLOUR_INFO string = "G"
A_DEBUG_LEVEL_COLOUR_NOTE string = "B"
A_DEBUG_LEVEL_COLOUR_WARNING string = "Y"
A_DEBUG_LEVEL_COLOUR_ERROR string = "R"
) )
func func
A_DEBUG(head string, args ...interface{}) { A_DEBUG(colour string,head string, args ...interface{}) {
if (true == A_DEBUG_NEED_HEAD) { if (true == A_DEBUG_NEED_HEAD) {
fmt.Print(head) switch colour {
case "G":
fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 32, head, 0x1B)
case "B":
fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 34, head, 0x1B)
case "Y":
fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 33, head, 0x1B)
case "R":
fmt.Printf("%c[%d;%d;%dm%s%c[0m", 0x1B, 0, 0, 31, head, 0x1B)
}
}
switch colour {
case "G":
fmt.Printf("%c[%d;%d;%dm%s%c[0m\n", 0x1B, 0, 0, 32, args, 0x1B)
case "B":
fmt.Printf("%c[%d;%d;%dm%s%c[0m\n", 0x1B, 0, 0, 34, args, 0x1B)
case "Y":
fmt.Printf("%c[%d;%d;%dm%s%c[0m\n", 0x1B, 0, 0, 33, args, 0x1B)
case "R":
fmt.Printf("%c[%d;%d;%dm%s%c[0m\n", 0x1B, 0, 0, 31, args[0], 0x1B)
} }
fmt.Println(args...)
} }
func func
A_DEBUG_INFO(args ...interface{}) { A_DEBUG_INFO(args ...interface{}) {
if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_INFO) { if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_INFO) {
A_DEBUG(A_DEBUG_LEVEL_STR_INFO + ":", args...) A_DEBUG(A_DEBUG_LEVEL_COLOUR_INFO,A_DEBUG_LEVEL_STR_INFO + ":", args...)
} }
} }
func func
A_DEBUG_NOTE(args ...interface{}) { A_DEBUG_NOTE(args ...interface{}) {
if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_NOTE) { if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_NOTE) {
A_DEBUG(A_DEBUG_LEVEL_STR_NOTE + ":", args...) A_DEBUG(A_DEBUG_LEVEL_COLOUR_NOTE,A_DEBUG_LEVEL_STR_NOTE + ":", args...)
} }
} }
func func
A_DEBUG_WARNING(args ...interface{}) { A_DEBUG_WARNING(args ...interface{}) {
if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_WARNING) { if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_WARNING) {
A_DEBUG(A_DEBUG_LEVEL_STR_WARNING + ":", args...) A_DEBUG(A_DEBUG_LEVEL_COLOUR_WARNING,A_DEBUG_LEVEL_STR_WARNING + ":", args...)
} }
} }
func func
A_DEBUG_ERROR(args ...interface{}) { A_DEBUG_ERROR(args ...interface{}) {
if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_ERROR) { if (A_DEBUG_LEVEL <= A_DEBUG_LEVEL_ERROR) {
A_DEBUG(A_DEBUG_LEVEL_STR_ERROR + ":", args...) A_DEBUG(A_DEBUG_LEVEL_COLOUR_ERROR,A_DEBUG_LEVEL_STR_ERROR + ":", args...)
} }
} }