hcl/go/main.go
hyung-hwan de94b4e66f
Some checks failed
continuous-integration/drone/push Build is failing
added the go wrapper files. work in progress
2023-10-27 18:20:02 +09:00

135 lines
3.1 KiB
Go

package main
/*
#cgo CFLAGS: -I/home/hyung-hwan/xxx/include -g -Wall
#cgo LDFLAGS: -L/home/hyung-hwan/xxx/lib -lhcl -ldl -lquadmath
#include <hcl.h>
#include <stdlib.h>
extern int go_read_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg);
extern int go_scan_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg);
extern int go_print_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg);
int read_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg)
{
return go_read_handler(hcl, cmd, arg);
}
int scan_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg)
{
return go_scan_handler(hcl, cmd, arg);
}
int print_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg)
{
return go_print_handler(hcl, cmd, arg);
}
*/
//import "C"
import (
"fmt"
hcl "hcl/pkg"
"os"
"cfg"
)
/*
func run_hcl() {
var hcl *C.hcl_t = C.hcl_openstd(0, nil)
var src []uint16 = utf16.Encode(([]rune)(
`(printf ">>>>>>>>> [%d]\n" (+ 30 455))
(printf ">>>>>>>>> [%d]\n" (+ 11 455))
#include "a.hcl"
(printf ">>>>>>>>> [%d]\n" (+ 20 455))
`))
if hcl == nil {
log.Printf("Unable to open HCL\n")
} else {
var (
x C.int
logmask C.hcl_bitmask_t
tgt *C.char
empty *C.char
r C.hcl_oop_t
)
logmask = ^C.hcl_bitmask_t(0)
tgt = C.CString("/dev/stderr")
defer C.free(unsafe.Pointer(tgt))
empty = C.CString("")
defer C.free(unsafe.Pointer(empty))
C.hcl_setoption(hcl, C.HCL_LOG_MASK, unsafe.Pointer(&logmask))
C.hcl_setoption(hcl, C.HCL_LOG_TARGET_BCSTR, unsafe.Pointer(tgt))
_ = C.hcl_ignite(hcl, 1000000)
//fmt.Printf ("ignire %d\n", x)
_ = C.hcl_addbuiltinprims(hcl)
//fmt.Printf ("addbuiltinprims %d\n", x)
//_ = C.hcl_attachiostdwithbcstr(hcl, empty, empty, empty)
//x = C.hcl_attachio(hcl, (*[0]byte)(C.read_handler), (*[0]byte)(C.scan_handler), (*[0]byte)(C.print_handler))
x = C.hcl_attachio(hcl, C.hcl_ioimpl_t(C.read_handler), C.hcl_ioimpl_t(C.scan_handler), C.hcl_ioimpl_t(C.print_handler))
if x <= -1 {
log.Printf("unable to attach IO handlers - %d - %s\n", x, C.GoString(C.hcl_geterrbmsg(hcl)))
goto done
}
_ = C.hcl_beginfeed(hcl, nil)
//fmt.Printf ("beginfeed %d\n", x)
_ = C.hcl_feed(hcl, (*C.ushort)(&src[0]), (C.ulong)(len(src)))
//fmt.Printf ("feed %d\n", x)
_ = C.hcl_endfeed(hcl)
//fmt.Printf ("endfeed %d => bclen %d\n", x, C.hcl_getbclen(hcl))
_ = x
C.hcl_decode(hcl, 0, C.hcl_getbclen(hcl))
logmask = 0
C.hcl_setoption(hcl, C.HCL_LOG_MASK, unsafe.Pointer(&logmask))
r = C.hcl_execute(hcl)
if r == nil {
fmt.Printf("Error - %s\n", C.GoString(C.hcl_geterrbmsg(hcl)))
}
done:
C.hcl_close(hcl)
}
}
*/
func main() {
//run_hcl()
/*
var rfh hcl.ReadFileHandler
var sfh hcl.ScanFileHandler
var pfh hcl.PrintFileHandler
*/
fmt.Printf ("bindir = %s\n", cfg.BINDIR)
x, err := hcl.New()
if err != nil {
fmt.Printf("ERROR %s\n", err)
os.Exit(1)
}
x.Ignite(1000000)
x.AddBuiltinPrims()
/*
err = x.AttachIO(&rfh, &sfh, &pfh)
if err != nil {
fmt.Printf("Error - %s", err.Error())
}
x.FeedString(`(printf ">>>>>>>>> [%d]\n" (+ 30 455))
(printf ">>>>>>>>> [%d]\n" (+ 11 455))
#include "a.hcl"
(printf ">>>>>>>>> [%d]\n" (+ 20 455))`)
x.EndFeed()
x.Execute()
x.Close()
*/
}