!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

@ -31,8 +31,8 @@ package Interpreter
import (
"bufio"
"bytes"
"strings"
"os/exec"
"strings"
)
////////////////////////////////////////////////////////////////
@ -62,6 +62,44 @@ func
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
(iio InterIO) RecvUntil(delim_s string) (ret string, rc error) {
output := ""
@ -120,8 +158,8 @@ func
out = append(out, c)
rc = rc1
}
return string(out), rc
outstring := strings.TrimRight(string(out)," ")
return outstring, rc
}
func

View File

@ -28,9 +28,6 @@
package Interpreter
import (
)
const (
// 注释的属于"不定义命令",即命令不合理
INTERPRETER_CMD_LEN int = 3
@ -41,9 +38,10 @@ const (
//INTERPRETER_CMD_SEND_POC_CHECK string = "<?:"
INTERPRETER_CMD_RECV_POC_CHECK 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)",
"1":"signal: aborted (core dumped)",
"2":"exit status 1",

View File

@ -51,42 +51,64 @@ const (
A_DEBUG_LEVEL_WARNING int = 2
A_DEBUG_LEVEL_ERROR int = 3
A_DEBUG_LEVEL_STR_INFO string = "info"
A_DEBUG_LEVEL_STR_NOTE string = "note"
A_DEBUG_LEVEL_STR_WARNING string = "warning"
A_DEBUG_LEVEL_STR_ERROR string = "error"
A_DEBUG_LEVEL_STR_INFO string = "[+] Info"
A_DEBUG_LEVEL_STR_NOTE string = "[*] Note"
A_DEBUG_LEVEL_STR_WARNING string = "[!] Warning"
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
A_DEBUG(head string, args ...interface{}) {
A_DEBUG(colour string,head string, args ...interface{}) {
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
A_DEBUG_INFO(args ...interface{}) {
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
A_DEBUG_NOTE(args ...interface{}) {
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
A_DEBUG_WARNING(args ...interface{}) {
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
A_DEBUG_ERROR(args ...interface{}) {
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...)
}
}