|
|
|
@ -2,6 +2,7 @@ package starainrt
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"errors"
|
|
|
|
|
"io"
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
@ -115,7 +116,7 @@ func GetINIValue(filepath, rem, conn string, kv []string) (bool, map[string]stri
|
|
|
|
|
v2 += string(b)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
keypar := regexp.MustCompile("^" + v2 + ".*?" + conn + "(.*)")
|
|
|
|
|
keypar := regexp.MustCompile("^" + v2 + ".*?" + conn + "(.*?)" + "(" + rem + "|$)")
|
|
|
|
|
if keypar.Match([]byte(txt)) {
|
|
|
|
|
i++
|
|
|
|
|
kekka := keypar.FindSubmatch([]byte(txt))
|
|
|
|
@ -133,3 +134,64 @@ func GetINIValue(filepath, rem, conn string, kv []string) (bool, map[string]stri
|
|
|
|
|
}
|
|
|
|
|
return true, outputstr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ReadINIConfig(filepath string) (map[string]map[string]string, error) {
|
|
|
|
|
var result map[string]map[string]string
|
|
|
|
|
result = make(map[string]map[string]string)
|
|
|
|
|
if !Exists(filepath) {
|
|
|
|
|
return result, errors.New("file not exists")
|
|
|
|
|
}
|
|
|
|
|
data, err := ioutil.ReadFile(filepath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
|
|
|
|
strdata := string(data)
|
|
|
|
|
datas := strings.Split(strdata, "\n")
|
|
|
|
|
var inseg, nolabel bool = false, false
|
|
|
|
|
var segname string
|
|
|
|
|
jump:
|
|
|
|
|
if nolabel {
|
|
|
|
|
segname = "unnamed"
|
|
|
|
|
inseg = true
|
|
|
|
|
}
|
|
|
|
|
for _, v := range datas {
|
|
|
|
|
v = strings.TrimSpace(v)
|
|
|
|
|
if ok, _ := regexp.MatchString("^#", v); ok {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
segfind := regexp.MustCompile(`\[(.*)\]`)
|
|
|
|
|
if !inseg {
|
|
|
|
|
if ok, _ := regexp.MatchString(`(.*?)=(.*)`, v); ok {
|
|
|
|
|
nolabel = true
|
|
|
|
|
goto jump
|
|
|
|
|
}
|
|
|
|
|
if !segfind.MatchString(v) {
|
|
|
|
|
continue
|
|
|
|
|
} else {
|
|
|
|
|
tmp := segfind.FindStringSubmatch(v)
|
|
|
|
|
segname = tmp[1]
|
|
|
|
|
inseg = true
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if segfind.MatchString(v) {
|
|
|
|
|
tmp := segfind.FindStringSubmatch(v)
|
|
|
|
|
segname = tmp[1]
|
|
|
|
|
inseg = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if fn := strings.Index(v, "#"); fn >= 0 {
|
|
|
|
|
v = v[0:fn]
|
|
|
|
|
}
|
|
|
|
|
if ok, _ := regexp.MatchString(`(.*?)=(.*)`, v); ok {
|
|
|
|
|
regtmp := regexp.MustCompile(`(.*?)=(.*)`)
|
|
|
|
|
tmp := regtmp.FindStringSubmatch(v)
|
|
|
|
|
if result[segname] == nil {
|
|
|
|
|
result[segname] = make(map[string]string)
|
|
|
|
|
}
|
|
|
|
|
result[segname][strings.TrimSpace(tmp[1])] = strings.TrimSpace(tmp[2])
|
|
|
|
|
} else {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result, nil
|
|
|
|
|
}
|
|
|
|
|