aboutsummaryrefslogtreecommitdiffstats
path: root/cbinding.go
diff options
context:
space:
mode:
Diffstat (limited to 'cbinding.go')
-rw-r--r--cbinding.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/cbinding.go b/cbinding.go
new file mode 100644
index 0000000..7866539
--- /dev/null
+++ b/cbinding.go
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2019-2021 WireGuard LLC. All Rights Reserved.
+ */
+
+package syntax
+
+// #include "highlighter.h"
+// #include <stdlib.h>
+import "C"
+import (
+ "unsafe"
+)
+
+func highlightConfigC(config string) []highlightSpan {
+ b := append([]byte(config), 0)
+ highlights := C.highlight_config((*C.char)(unsafe.Pointer(&b[0])))
+ if highlights == nil {
+ return nil
+ }
+ var ret []highlightSpan
+ for i := highlights; i._type != C.HighlightEnd; i = (*C.struct_highlight_span)(unsafe.Add(unsafe.Pointer(i), unsafe.Sizeof(*i))) {
+ ret = append(ret, highlightSpan{highlight(i._type), int(i.start), int(i.len)})
+ }
+ C.free(unsafe.Pointer(highlights))
+ return ret
+}