c/clang/symg:refine config usage

This commit is contained in:
luoliwoshang
2024-07-30 09:33:05 +08:00
parent 1219230168
commit 67b10d8d38
2 changed files with 25 additions and 10 deletions

View File

@@ -53,6 +53,7 @@ func main() {
config, err := getConf(data)
check(err)
defer config.Delete()
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to parse config file:", cfgFile)
@@ -77,19 +78,24 @@ func check(err error) {
}
}
func getConf(data []byte) (*types.Config, error) {
conf := cjson.ParseBytes(data)
if conf == nil {
return nil, errors.New("failed to parse config")
func getConf(data []byte) (types.Conf, error) {
parsedConf := cjson.ParseBytes(data)
if parsedConf == nil {
return types.Conf{}, errors.New("failed to parse config")
}
config := &types.Config{
Name: getStringItem(conf, "name", ""),
CFlags: getStringItem(conf, "cflags", ""),
Libs: getStringItem(conf, "libs", ""),
Include: getStringArrayItem(conf, "include"),
TrimPrefixes: getStringArrayItem(conf, "trimPrefixes"),
Name: getStringItem(parsedConf, "name", ""),
CFlags: getStringItem(parsedConf, "cflags", ""),
Libs: getStringItem(parsedConf, "libs", ""),
Include: getStringArrayItem(parsedConf, "include"),
TrimPrefixes: getStringArrayItem(parsedConf, "trimPrefixes"),
}
return config, nil
return types.Conf{
JSON: parsedConf,
Config: config,
}, nil
}
func getString(obj *cjson.JSON) (value string) {