comments support, script loading support
This commit is contained in:
parent
654e8bd55b
commit
bd22b84699
11 changed files with 145 additions and 69 deletions
|
|
@ -18,11 +18,9 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"io"
|
||||
"bufio"
|
||||
"gitlab.com/whom/shs/log"
|
||||
"gitlab.com/whom/shs/ast"
|
||||
"gitlab.com/whom/shs/util"
|
||||
"gitlab.com/whom/shs/stdlib"
|
||||
)
|
||||
|
||||
|
|
@ -35,32 +33,10 @@ func InitFromConfig(configFile string) (ast.VarTable, ast.FuncTable) {
|
|||
p := ast.GetVar("HOME", vars)
|
||||
configFile = p.Value() + "/" + configFile
|
||||
|
||||
cfile, err := os.Open(configFile)
|
||||
if err != nil {
|
||||
log.Log(log.DEBUG,
|
||||
"unable to open config file: " + err.Error(),
|
||||
"config")
|
||||
return vars, funcs
|
||||
}
|
||||
|
||||
r := bufio.NewReader(cfile)
|
||||
text, err := r.ReadString('\n')
|
||||
for err != io.EOF {
|
||||
if err != nil {
|
||||
log.Log(log.ERR,
|
||||
"unable to read from config file: " + err.Error(),
|
||||
"config")
|
||||
break
|
||||
}
|
||||
|
||||
// Eval lines in config
|
||||
ast.Lex(text).Eval(funcs, vars, false)
|
||||
text, err = r.ReadString('\n')
|
||||
}
|
||||
util.LoadScript(configFile, vars, funcs)
|
||||
|
||||
log.Log(log.DEBUG,
|
||||
"config file fully evaluated",
|
||||
"config")
|
||||
cfile.Close()
|
||||
return vars, funcs
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue