From 3b9b02de832c5cec0524880d251c41d92cd46a3e Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Tue, 31 Oct 2023 21:17:08 +0900 Subject: [PATCH] changed 'sed' to use -e for an expression --- Makefile.am | 2 +- Makefile.in | 2 +- go/cb.go | 22 ++++++++++++---------- go/hcl.go | 23 ++++++++++++++++++++--- main.go | 32 ++++++++++++++------------------ 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/Makefile.am b/Makefile.am index 2add1bc..ade16c2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,7 +45,7 @@ hclgo_LINK = mv -f hclgo.bin hclgo$(EXEEXT) || echo "FAILED TO LINK" hclgo.bin: cp -pf $(srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change - sed -ri "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod + sed -r -i -e "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod echo -e "\nreplace cfg => $(abs_builddir)/go/cfg" >> $(builddir)/go.mod [ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true CGO_CFLAGS="-I$(abs_srcdir)/lib -I$(abs_builddir)/lib $(CFLAGS)" \ diff --git a/Makefile.in b/Makefile.in index 1dc7c95..ff91cdb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -940,7 +940,7 @@ clean-local: @ENABLE_HCLGO_TRUE@hclgo.bin: @ENABLE_HCLGO_TRUE@ cp -pf $(srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true @ENABLE_HCLGO_TRUE@ chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change -@ENABLE_HCLGO_TRUE@ sed -ri "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod +@ENABLE_HCLGO_TRUE@ sed -r -i -e "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod @ENABLE_HCLGO_TRUE@ echo -e "\nreplace cfg => $(abs_builddir)/go/cfg" >> $(builddir)/go.mod @ENABLE_HCLGO_TRUE@ [ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true @ENABLE_HCLGO_TRUE@ CGO_CFLAGS="-I$(abs_srcdir)/lib -I$(abs_builddir)/lib $(CFLAGS)" \ diff --git a/go/cb.go b/go/cb.go index 968ba86..10bdb86 100644 --- a/go/cb.go +++ b/go/cb.go @@ -9,7 +9,11 @@ import "C" import ( // "bufio" // "io" + "bufio" + "io" "os" + "sync" + "unsafe" // "sync" // "unsafe" ) @@ -19,7 +23,6 @@ type IOHandle struct { ioif interface{} } -/* type IOHandleTable struct { mtx sync.Mutex handles []IOHandle @@ -348,10 +351,10 @@ func (p *ScanFileHandler) Open(g *HCL) error { ) f = os.Stdin - //f, err = os.Open("/dev/stdin") - //if err != nil { - // return err - //} + //f, err = os.Open("/dev/stdin") + //if err != nil { + // return err + //} p.r = bufio.NewReader(f) p.f = f @@ -407,10 +410,10 @@ func (p *PrintFileHandler) Open(g *HCL) error { // err error ) -// f, err = os.OpenFile("/dev/stdout", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) -// if err != nil { -// return err -// } + // f, err = os.OpenFile("/dev/stdout", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) + // if err != nil { + // return err + // } f = os.Stdout @@ -455,4 +458,3 @@ func (p *PrintFileHandler) Flush() error { //fmt.Fprintf(os.Stderr, "XXXXXXXXXX flush porint\n") return p.w.Flush() } -*/ diff --git a/go/hcl.go b/go/hcl.go index e98741d..924cd0f 100644 --- a/go/hcl.go +++ b/go/hcl.go @@ -12,13 +12,23 @@ import ( "unsafe" ) +type IOImpl interface { + Open(g *HCL, name string, includer_name string) (int, error) + Close(fd int) + Read(fd int, buf []rune) (int, error) + Write(data []rune) error + WriteBytes(data []byte) error + Flush() error +} + type HCL struct { c *C.hcl_t inst_no int io struct { - r IOHandle - w IOHandle + r IOImpl + s IOImpl + p IOImpl } } @@ -82,7 +92,14 @@ func (hcl *HCL) AddBuiltinPrims() error { return nil } -func (hcl *HCL) AttachIO() error { +func (hcl *HCL) AttachIO(r IOImpl, w IOImpl, p IOImpl) error { + hcl.io.r = r + hcl.io.s = s + hcl.io.p = p + if C.hcl_attachio(hcl.c, go_read_handler, go_scan_handler, go_print_handler) <= -1 { + // TODO: restore to the old value.. + return fmt.Errorf("unable to attach I/O handlers: %s", string(ucstr_to_rune_slice(C.hcl_geterrstr(hcl.c)))) + } return nil } diff --git a/main.go b/main.go index a1dafb2..85e97dd 100644 --- a/main.go +++ b/main.go @@ -29,10 +29,11 @@ int print_handler (hcl_t* hcl, hcl_iocmd_t cmd, void* arg) //import "C" import ( - "fmt" - hcl "code.miflux.com/hyung-hwan/hcl/go" - "os" _ "cfg" + "fmt" + "os" + + hcl "code.miflux.com/hyung-hwan/hcl/go" ) /* @@ -105,11 +106,9 @@ func main() { var x *hcl.HCL = nil var err error = nil - /* - var rfh hcl.ReadFileHandler - var sfh hcl.ScanFileHandler - var pfh hcl.PrintFileHandler - */ + var rfh hcl.ReadFileHandler + var sfh hcl.ScanFileHandler + var pfh hcl.PrintFileHandler x, err = hcl.New() if err != nil { @@ -127,21 +126,18 @@ func main() { goto oops } - /* - err = x.AttachIO(&rfh, &sfh, &pfh) - if err != nil { - fmt.Printf("Error - %s", err.Error()) - } - x.FeedString(`(printf ">>>>>>>>> [%d]\n" (+ 30 455)) - + 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.EndFeed() + x.Execute() - */ x.Close() os.Exit(0)