github.com/gotranspile/cxgo@v0.3.7/libs/glob.go (about) 1 package libs 2 3 import ( 4 "github.com/gotranspile/cxgo/runtime/stdio" 5 "github.com/gotranspile/cxgo/types" 6 ) 7 8 const ( 9 globH = "glob.h" 10 ) 11 12 func init() { 13 RegisterLibrary(globH, func(c *Env) *Library { 14 gint := c.Go().Int() 15 intT := types.IntT(4) 16 sizeT := intT 17 strT := c.C().String() 18 globT := types.NamedT("stdio.Glob", types.StructT([]*types.Field{ 19 {Name: types.NewIdentGo("gl_pathc", "Num", sizeT)}, 20 {Name: types.NewIdentGo("gl_pathv", "Paths", c.PtrT(strT))}, 21 {Name: types.NewIdentGo("gl_offs", "Reserve", sizeT)}, 22 {Name: types.NewIdentGo("Glob", "Glob", c.FuncTT(intT, strT, intT, c.FuncTT(intT, strT, intT)))}, 23 {Name: types.NewIdentGo("Free", "Free", c.FuncTT(nil))}, 24 })) 25 return &Library{ 26 Imports: map[string]string{ 27 "libc": RuntimeLibc, 28 "stdio": RuntimePrefix + "stdio", 29 }, 30 Types: map[string]types.Type{ 31 "glob_t": globT, 32 }, 33 Idents: map[string]*types.Ident{ 34 "GLOB_NOESCAPE": c.NewIdent("GLOB_NOESCAPE", "stdio.GlobNoEscape", stdio.GlobNoEscape, gint), 35 }, 36 // TODO 37 Header: ` 38 #include <` + stddefH + `> 39 40 const _cxgo_go_int GLOB_NOESCAPE = 1; 41 42 typedef struct { 43 size_t gl_pathc; /* Count of paths matched so far */ 44 char **gl_pathv; /* List of matched pathnames. */ 45 size_t gl_offs; /* Slots to reserve in gl_pathv. */ 46 _cxgo_sint32 (*Glob)(const char *pattern, _cxgo_sint32 flags, 47 _cxgo_sint32 (*errfunc) (const char *epath, _cxgo_sint32 eerrno)); 48 void (*Free)(void); 49 } glob_t; 50 #define glob(pattern, flags, errfunc, g) ((glob_t*)g)->Glob(pattern, flags, errfunc) 51 #define globfree(g) ((glob_t*)g)->Free() 52 `, 53 } 54 }) 55 }