-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
156 lines (143 loc) · 3.38 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"bufio"
"bytes"
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strings"
"time"
core "./core"
)
func calliapi(s []string, api *core.API) {
switch s[0] {
case "0x5":
api.PrintStructure()
case "0x24":
api.NewElement(s[1:])
case "0x25":
api.ElementsChangeID(s[1:])
case "0xF9":
log.Println(s[1])
}
}
// This function provides an execution of and connection with xcutables
func xcute(xcutable *core.Xcutable, api *core.API, chan_completed chan<- bool) {
var stderr bytes.Buffer
path := Path_Format(xcutable.REF)
cmd := exec.Command("go", "run", path)
stdout, err := cmd.StdoutPipe()
if err != nil {
panic(err)
}
cmd.Stderr = &stderr
err = cmd.Start()
if err != nil {
panic(err)
}
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
params := strings.Split(scanner.Text(), "\x10")
calliapi(params, api)
}
err = cmd.Wait()
if err != nil {
fmt.Println(stderr.String())
fmt.Println(err)
panic(err)
}
chan_completed <- true
}
// This function goes through each of xcutables and calls xcute function
func xcute_man(xcutables []*core.Xcutable, api *core.API, chan_comm chan<- bool) {
for x := range xcutables {
chan_completed := make(chan bool)
go xcute(xcutables[x], api, chan_completed)
<-chan_completed
}
chan_comm <- true
}
var Paths []string
// This function parses the given path and returns
// Paths slice as tokens to give necessary paths
func Path_Parse(given_path string) {
var charbuf []byte
if runtime.GOOS == "windows" {
Paths = append(Paths, string(given_path[0:2]))
given_path = given_path[3:]
}
for i := 0; i < len(given_path); i++ {
if string(given_path[i]) == "/" ||
string(given_path[i]) == "\\" {
Paths = append(Paths, string(charbuf))
charbuf = []byte{}
} else {
charbuf = append(charbuf, given_path[i])
}
}
Paths = append(Paths, string(charbuf))
}
// This function formats given path by dots "."
// and returns fully formatted path to use
func Path_Format(path string) string {
if string(path[:2]) == "E:" {
return path
}
var slash string = "/"
if runtime.GOOS == "windows" {
slash = "\\"
}
var bytemap []byte = []byte(path)
for i := range bytemap {
if bytemap[i] == 47 && slash == "\\" {
bytemap[i] = 92
} else if bytemap[i] == 92 && slash == "/" {
bytemap[i] = 47
}
}
path = string(bytemap)
if string(path[0]) == "." {
folding := len(Paths)-1
j := 0
for string(path[j]) == "." && folding > 1 {
folding--
j++
}
i := 0
making_path := ""
for ; i < folding; i++ {
making_path = making_path + string(Paths[i]) + slash
}
return making_path + path[j:]
} else {
making_path := ""
for i := 0; i < len(Paths)-1; i++ {
making_path = making_path + string(Paths[i]) + slash
}
return making_path + path
}
}
func main() {
// Parsing the path
Path_Parse(os.Args[1])
fmt.Println("FILE:", os.Args[1])
i := time.Now()
page, tree, _, spoterr := core.SPOT(os.Args[1])
if spoterr != nil {
fmt.Print(spoterr.Error())
}
api := core.API{Page: page, Tree: &tree}
fmt.Println("Spawned in", time.Since(i).Nanoseconds(), "nanoseconds")
//core.PrintPOT(api.Page, *api.Tree)
//fmt.Println(objmap)
chan_comm := make(chan bool)
go xcute_man(page.XCUTABLES, &api, chan_comm)
<-chan_comm
fmt.Println("Program took", time.Since(i).Milliseconds(), "milliseconds")
// ADD EVERYTHING ON PREBUILD
//core.PrintPOT(api.Page, *api.Tree)
//fmt.Println(core.ObjMap)
//fmt.Scanln()
}