aboutsummaryrefslogtreecommitdiff
path: root/backend/parser/parser.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/parser/parser.go')
-rw-r--r--backend/parser/parser.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/backend/parser/parser.go b/backend/parser/parser.go
new file mode 100644
index 0000000..562b8c0
--- /dev/null
+++ b/backend/parser/parser.go
@@ -0,0 +1,43 @@
1package parser
2
3import (
4 "bufio"
5 "fmt"
6 "log"
7 "os/exec"
8 "strconv"
9 "strings"
10)
11
12func ProcessDemo(demoPath string) (int, int, error) {
13 cmd := exec.Command("bash", "-c", fmt.Sprintf(`echo "FEXBash" && ./backend/parser/parser %s`, demoPath))
14 stdout, err := cmd.StdoutPipe()
15 if err != nil {
16 log.Println(err)
17 return 0, 0, err
18 }
19 cmd.Start()
20 scanner := bufio.NewScanner(stdout)
21 var cmTicks, portalCount int
22 for scanner.Scan() {
23 line := scanner.Text()
24 if strings.Contains(line, "CM ticks") {
25 cmTicksStr := strings.TrimSpace(strings.Split(line, ":")[1])
26 cmTicks, err = strconv.Atoi(cmTicksStr)
27 if err != nil {
28 return 0, 0, err
29 }
30 }
31 if strings.Contains(line, "Portal count") {
32 portalCountStr := strings.TrimSpace(strings.Split(line, ":")[1])
33 portalCount, err = strconv.Atoi(portalCountStr)
34 if err != nil {
35 return 0, 0, err
36 }
37 }
38 }
39 cmd.Wait()
40 // We don't check for error in wait, since FEXBash always gives segmentation fault
41 // Wanted output is retrieved, so it's okay (i think)
42 return portalCount, cmTicks, nil
43}