/
bash.go
47 lines (38 loc) · 862 Bytes
/
bash.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
package main
/*
#cgo pkg-config: bash
#include "builtins.h"
extern struct builtin goenable_struct;
*/
import "C"
import (
"strings"
"github.com/johnstarich/goenable/cutils"
)
func init() {
C.goenable_struct.name = C.CString(Name())
longDoc := strings.Split(Usage(), "\n")
C.goenable_struct.long_doc = (**C.char)(cutils.CStringArray(longDoc))
C.goenable_struct.short_doc = C.CString(UsageShort())
}
//export goenable_builtin
func goenable_builtin(list *C.WORD_LIST) C.int {
args := make([]string, 0)
for list != nil {
args = append(args, C.GoString(list.word.word))
list = list.next
}
return C.int(Run(args))
}
//export goenable_builtin_load
func goenable_builtin_load(cName *C.char) C.int {
name := C.GoString(cName)
if Load(name) {
return 1
}
return 0
}
//export goenable_builtin_unload
func goenable_builtin_unload() {
Unload()
}