2021-12-21 06:42:30 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2021-12-24 11:19:36 -05:00
|
|
|
"fmt"
|
2021-12-21 06:42:30 -05:00
|
|
|
"log"
|
|
|
|
"os"
|
2021-12-25 09:28:59 -05:00
|
|
|
"pndpd/modules"
|
2021-12-22 07:01:30 -05:00
|
|
|
"pndpd/pndp"
|
2021-12-21 06:42:30 -05:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func readConfig(dest string) {
|
|
|
|
file, err := os.Open(dest)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2021-12-25 08:21:07 -05:00
|
|
|
defer func(file *os.File) {
|
|
|
|
_ = file.Close()
|
|
|
|
}(file)
|
2021-12-21 06:42:30 -05:00
|
|
|
|
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := scanner.Text()
|
2021-12-25 09:28:59 -05:00
|
|
|
if strings.HasPrefix(line, "//") || strings.TrimSpace(line) == "" {
|
2021-12-21 06:42:30 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(line, "debug") {
|
2021-12-24 11:19:36 -05:00
|
|
|
if strings.Contains(line, "on") {
|
|
|
|
pndp.GlobalDebug = true
|
|
|
|
fmt.Println("DEBUG ON")
|
2021-12-21 06:42:30 -05:00
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
2021-12-25 09:28:59 -05:00
|
|
|
|
2021-12-27 11:24:21 -05:00
|
|
|
if strings.HasSuffix(line, "{") {
|
2021-12-25 09:28:59 -05:00
|
|
|
option := strings.TrimSuffix(strings.TrimSpace(line), "{")
|
|
|
|
option = strings.TrimSpace(option)
|
2021-12-27 11:24:21 -05:00
|
|
|
module, command := modules.GetCommand(option)
|
|
|
|
var lines = make([]string, 0)
|
|
|
|
if module != nil {
|
|
|
|
for {
|
|
|
|
if !scanner.Scan() {
|
|
|
|
break
|
2021-12-25 09:28:59 -05:00
|
|
|
}
|
2021-12-27 11:24:21 -05:00
|
|
|
line := strings.TrimSpace(scanner.Text())
|
|
|
|
if strings.Contains(line, "}") {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
lines = append(lines, line)
|
2021-12-25 09:28:59 -05:00
|
|
|
}
|
2021-12-27 11:24:21 -05:00
|
|
|
modules.ExecuteInit(module, modules.CallbackInfo{
|
|
|
|
CallbackType: modules.Config,
|
|
|
|
Command: command,
|
|
|
|
Arguments: lines,
|
|
|
|
})
|
2021-12-25 09:28:59 -05:00
|
|
|
}
|
2021-12-21 06:42:30 -05:00
|
|
|
}
|
|
|
|
|
2021-12-24 11:19:36 -05:00
|
|
|
}
|
2021-12-27 11:24:21 -05:00
|
|
|
if modules.ExistsBlockingModule() {
|
|
|
|
modules.ExecuteComplete()
|
|
|
|
waitForSignal()
|
|
|
|
modules.ShutdownAll()
|
2021-12-24 11:19:36 -05:00
|
|
|
}
|
|
|
|
|
2021-12-27 11:24:21 -05:00
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
panic(err)
|
2021-12-24 11:19:36 -05:00
|
|
|
}
|
|
|
|
|
2021-12-21 06:42:30 -05:00
|
|
|
}
|