From 851b3ca4f9dec5de9decd295c1efbc6b9ce8b5ed Mon Sep 17 00:00:00 2001 From: Meteor Date: Tue, 8 Apr 2025 08:15:05 +0000 Subject: [PATCH] Release-as: pcre/v1.0.0 --- pcre/_demo/html/html.go | 79 ++++++ pcre/go.mod | 5 + pcre/go.sum | 2 + pcre/llcppg.cfg | 23 ++ pcre/llcppg.pub | 23 ++ pcre/llcppg.symb.json | 325 +++++++++++++++++++++ pcre/llpkg.cfg | 8 + pcre/pcre.go | 575 ++++++++++++++++++++++++++++++++++++++ pcre/pcre_autogen_link.go | 3 + pcre/pcreposix.go | 70 +++++ 10 files changed, 1113 insertions(+) create mode 100644 pcre/_demo/html/html.go create mode 100644 pcre/go.mod create mode 100644 pcre/go.sum create mode 100644 pcre/llcppg.cfg create mode 100644 pcre/llcppg.pub create mode 100644 pcre/llcppg.symb.json create mode 100644 pcre/llpkg.cfg create mode 100644 pcre/pcre.go create mode 100644 pcre/pcre_autogen_link.go create mode 100644 pcre/pcreposix.go diff --git a/pcre/_demo/html/html.go b/pcre/_demo/html/html.go new file mode 100644 index 00000000..e5197258 --- /dev/null +++ b/pcre/_demo/html/html.go @@ -0,0 +1,79 @@ +package main + +import ( + "fmt" + "unsafe" + + "github.com/goplus/llgo/c" + "github.com/goplus/llpkg/pcre" +) + +func main() { + pattern := "Hello (\\w+)" + subject := "Hello World, test." + + patternC := c.AllocaCStr(pattern) + + subjectC := c.AllocaCStr(subject) + + var ( + errPtr *int8 + erroffset c.Int + errorcode c.Int + ) + + re := pcre.Compile2( + (*int8)(unsafe.Pointer(patternC)), + 0, + &errorcode, + &errPtr, + &erroffset, + nil, + ) + + if re == nil { + fmt.Printf("Compile fail (code=%d) at offset %d: %s\n", + errorcode, + erroffset, + c.GoString((*c.Char)(unsafe.Pointer(errPtr))), + ) + return + } + + var ovector [30]c.Int + + rc := re.Exec( + nil, + (*int8)(unsafe.Pointer(subjectC)), + c.Int(len(subject)), + 0, + 0, + &ovector[0], + c.Int(len(ovector)), + ) + + if rc < 0 { + fmt.Printf("Match fail: %d\n", rc) + return + } + + for i := 0; i < int(rc); i++ { + var substrPtr *int8 + + ret := pcre.GetSubstring( + (*int8)(unsafe.Pointer(subjectC)), + &ovector[0], + c.Int(rc), + c.Int(i), + &substrPtr, + ) + if ret < 0 { + fmt.Printf("Submatch fail: %d\n", ret) + continue + } + matchedStr := c.GoString((*c.Char)(unsafe.Pointer(substrPtr))) + fmt.Printf("Capture group #%d = %s\n", i, matchedStr) + + pcre.FreeSubstring(substrPtr) + } +} diff --git a/pcre/go.mod b/pcre/go.mod new file mode 100644 index 00000000..19291bce --- /dev/null +++ b/pcre/go.mod @@ -0,0 +1,5 @@ +module github.com/goplus/llpkg/pcre + +go 1.20 + +require github.com/goplus/llgo v0.10.0 diff --git a/pcre/go.sum b/pcre/go.sum new file mode 100644 index 00000000..3288b429 --- /dev/null +++ b/pcre/go.sum @@ -0,0 +1,2 @@ +github.com/goplus/llgo v0.10.0 h1:s3U3cnO3cploF1xCCJleAb16NQFAmHxdUmdrNhRH3hY= +github.com/goplus/llgo v0.10.0/go.mod h1:YfOHsT/g3lc9b4GclLj812YzdSsJr0kd3CCB830TqHE= diff --git a/pcre/llcppg.cfg b/pcre/llcppg.cfg new file mode 100644 index 00000000..035fc86c --- /dev/null +++ b/pcre/llcppg.cfg @@ -0,0 +1,23 @@ +{ + "name": "pcre", + "cflags": "$(pkg-config --cflags pcre)", + "libs": "$(pkg-config --libs pcre)", + "include": [ + "pcre.h", + "pcreposix.h" + ], + "trimPrefixes": ["pcre16_", "pcre32_", "pcre_"], + "cplusplus": false, + "deps": ["c/os", "github.com/goplus/llpkg/zlib@v1.0.0", "github.com/goplus/llpkg/bzip2@v1.0.0"], + "keepUnderScore": false, + "impl": [ + { + "files": [], + "cond": { + "os": [], + "arch": [] + } + } + ], + "mix": false +} diff --git a/pcre/llcppg.pub b/pcre/llcppg.pub new file mode 100644 index 00000000..c7aeeff4 --- /dev/null +++ b/pcre/llcppg.pub @@ -0,0 +1,23 @@ +pcre Pcre +pcre16 Pcre16 +pcre16_callout_block CalloutBlock__1 +pcre16_extra Extra__1 +pcre16_jit_callback JitCallback__1 +pcre16_jit_stack JitStack__1 +pcre32 Pcre32 +pcre32_callout_block CalloutBlock__2 +pcre32_extra Extra__2 +pcre32_jit_callback JitCallback__2 +pcre32_jit_stack JitStack__2 +pcre_callout_block CalloutBlock +pcre_extra Extra +pcre_jit_callback JitCallback +pcre_jit_stack JitStack +real_pcre16_jit_stack RealPcre16JitStack +real_pcre32 RealPcre32 +real_pcre32_jit_stack RealPcre32JitStack +real_pcre8_or_16 RealPcre8Or16 +real_pcre_jit_stack RealPcreJitStack +regex_t RegexT +regmatch_t RegmatchT +regoff_t RegoffT \ No newline at end of file diff --git a/pcre/llcppg.symb.json b/pcre/llcppg.symb.json new file mode 100644 index 00000000..15c05cb6 --- /dev/null +++ b/pcre/llcppg.symb.json @@ -0,0 +1,325 @@ +[{ + "mangle": "pcre16_assign_jit_stack", + "c++": "pcre16_assign_jit_stack(pcre16_extra *, pcre16_jit_callback, void *)", + "go": "(*Extra).AssignJitStack__1" + }, { + "mangle": "pcre16_compile", + "c++": "pcre16_compile(const unsigned short *, int, const char **, int *, const unsigned char *)", + "go": "Compile__1" + }, { + "mangle": "pcre16_compile2", + "c++": "pcre16_compile2(const unsigned short *, int, int *, const char **, int *, const unsigned char *)", + "go": "Compile2__1" + }, { + "mangle": "pcre16_config", + "c++": "pcre16_config(int, void *)", + "go": "Config__1" + }, { + "mangle": "pcre16_copy_named_substring", + "c++": "pcre16_copy_named_substring(const pcre16 *, const unsigned short *, int *, int, const unsigned short *, unsigned short *, int)", + "go": "(*Pcre16).CopyNamedSubstring" + }, { + "mangle": "pcre16_copy_substring", + "c++": "pcre16_copy_substring(const unsigned short *, int *, int, int, unsigned short *, int)", + "go": "CopySubstring__1" + }, { + "mangle": "pcre16_dfa_exec", + "c++": "pcre16_dfa_exec(const pcre16 *, const pcre16_extra *, const unsigned short *, int, int, int, int *, int, int *, int)", + "go": "(*Pcre16).DfaExec" + }, { + "mangle": "pcre16_exec", + "c++": "pcre16_exec(const pcre16 *, const pcre16_extra *, const unsigned short *, int, int, int, int *, int)", + "go": "(*Pcre16).Exec" + }, { + "mangle": "pcre16_free_study", + "c++": "pcre16_free_study(pcre16_extra *)", + "go": "(*Extra).FreeStudy__1" + }, { + "mangle": "pcre16_free_substring", + "c++": "pcre16_free_substring(const unsigned short *)", + "go": "FreeSubstring__1" + }, { + "mangle": "pcre16_free_substring_list", + "c++": "pcre16_free_substring_list(const unsigned short **)", + "go": "FreeSubstringList__1" + }, { + "mangle": "pcre16_fullinfo", + "c++": "pcre16_fullinfo(const pcre16 *, const pcre16_extra *, int, void *)", + "go": "(*Pcre16).Fullinfo" + }, { + "mangle": "pcre16_get_named_substring", + "c++": "pcre16_get_named_substring(const pcre16 *, const unsigned short *, int *, int, const unsigned short *, const unsigned short **)", + "go": "(*Pcre16).GetNamedSubstring" + }, { + "mangle": "pcre16_get_stringnumber", + "c++": "pcre16_get_stringnumber(const pcre16 *, const unsigned short *)", + "go": "(*Pcre16).GetStringnumber" + }, { + "mangle": "pcre16_get_stringtable_entries", + "c++": "pcre16_get_stringtable_entries(const pcre16 *, const unsigned short *, unsigned short **, unsigned short **)", + "go": "(*Pcre16).GetStringtableEntries" + }, { + "mangle": "pcre16_get_substring", + "c++": "pcre16_get_substring(const unsigned short *, int *, int, int, const unsigned short **)", + "go": "GetSubstring__1" + }, { + "mangle": "pcre16_get_substring_list", + "c++": "pcre16_get_substring_list(const unsigned short *, int *, int, const unsigned short ***)", + "go": "GetSubstringList__1" + }, { + "mangle": "pcre16_jit_free_unused_memory", + "c++": "pcre16_jit_free_unused_memory()", + "go": "JitFreeUnusedMemory__1" + }, { + "mangle": "pcre16_jit_stack_alloc", + "c++": "pcre16_jit_stack_alloc(int, int)", + "go": "JitStackAlloc__1" + }, { + "mangle": "pcre16_jit_stack_free", + "c++": "pcre16_jit_stack_free(pcre16_jit_stack *)", + "go": "(*JitStack).JitStackFree__1" + }, { + "mangle": "pcre16_maketables", + "c++": "pcre16_maketables()", + "go": "Maketables__1" + }, { + "mangle": "pcre16_pattern_to_host_byte_order", + "c++": "pcre16_pattern_to_host_byte_order(pcre16 *, pcre16_extra *, const unsigned char *)", + "go": "(*Pcre16).PatternToHostByteOrder" + }, { + "mangle": "pcre16_refcount", + "c++": "pcre16_refcount(pcre16 *, int)", + "go": "(*Pcre16).Refcount" + }, { + "mangle": "pcre16_study", + "c++": "pcre16_study(const pcre16 *, int, const char **)", + "go": "(*Pcre16).Study" + }, { + "mangle": "pcre16_utf16_to_host_byte_order", + "c++": "pcre16_utf16_to_host_byte_order(unsigned short *, const unsigned short *, int, int *, int)", + "go": "Utf16ToHostByteOrder" + }, { + "mangle": "pcre16_version", + "c++": "pcre16_version()", + "go": "Version__1" + }, { + "mangle": "pcre32_assign_jit_stack", + "c++": "pcre32_assign_jit_stack(pcre32_extra *, pcre32_jit_callback, void *)", + "go": "(*Extra).AssignJitStack__2" + }, { + "mangle": "pcre32_compile", + "c++": "pcre32_compile(const unsigned int *, int, const char **, int *, const unsigned char *)", + "go": "Compile__2" + }, { + "mangle": "pcre32_compile2", + "c++": "pcre32_compile2(const unsigned int *, int, int *, const char **, int *, const unsigned char *)", + "go": "Compile2__2" + }, { + "mangle": "pcre32_config", + "c++": "pcre32_config(int, void *)", + "go": "Config__2" + }, { + "mangle": "pcre32_copy_named_substring", + "c++": "pcre32_copy_named_substring(const pcre32 *, const unsigned int *, int *, int, const unsigned int *, unsigned int *, int)", + "go": "(*Pcre32).CopyNamedSubstring" + }, { + "mangle": "pcre32_copy_substring", + "c++": "pcre32_copy_substring(const unsigned int *, int *, int, int, unsigned int *, int)", + "go": "CopySubstring__2" + }, { + "mangle": "pcre32_dfa_exec", + "c++": "pcre32_dfa_exec(const pcre32 *, const pcre32_extra *, const unsigned int *, int, int, int, int *, int, int *, int)", + "go": "(*Pcre32).DfaExec" + }, { + "mangle": "pcre32_exec", + "c++": "pcre32_exec(const pcre32 *, const pcre32_extra *, const unsigned int *, int, int, int, int *, int)", + "go": "(*Pcre32).Exec" + }, { + "mangle": "pcre32_free_study", + "c++": "pcre32_free_study(pcre32_extra *)", + "go": "(*Extra).FreeStudy__2" + }, { + "mangle": "pcre32_free_substring", + "c++": "pcre32_free_substring(const unsigned int *)", + "go": "FreeSubstring__2" + }, { + "mangle": "pcre32_free_substring_list", + "c++": "pcre32_free_substring_list(const unsigned int **)", + "go": "FreeSubstringList__2" + }, { + "mangle": "pcre32_fullinfo", + "c++": "pcre32_fullinfo(const pcre32 *, const pcre32_extra *, int, void *)", + "go": "(*Pcre32).Fullinfo" + }, { + "mangle": "pcre32_get_named_substring", + "c++": "pcre32_get_named_substring(const pcre32 *, const unsigned int *, int *, int, const unsigned int *, const unsigned int **)", + "go": "(*Pcre32).GetNamedSubstring" + }, { + "mangle": "pcre32_get_stringnumber", + "c++": "pcre32_get_stringnumber(const pcre32 *, const unsigned int *)", + "go": "(*Pcre32).GetStringnumber" + }, { + "mangle": "pcre32_get_stringtable_entries", + "c++": "pcre32_get_stringtable_entries(const pcre32 *, const unsigned int *, unsigned int **, unsigned int **)", + "go": "(*Pcre32).GetStringtableEntries" + }, { + "mangle": "pcre32_get_substring", + "c++": "pcre32_get_substring(const unsigned int *, int *, int, int, const unsigned int **)", + "go": "GetSubstring__2" + }, { + "mangle": "pcre32_get_substring_list", + "c++": "pcre32_get_substring_list(const unsigned int *, int *, int, const unsigned int ***)", + "go": "GetSubstringList__2" + }, { + "mangle": "pcre32_jit_free_unused_memory", + "c++": "pcre32_jit_free_unused_memory()", + "go": "JitFreeUnusedMemory__2" + }, { + "mangle": "pcre32_jit_stack_alloc", + "c++": "pcre32_jit_stack_alloc(int, int)", + "go": "JitStackAlloc__2" + }, { + "mangle": "pcre32_jit_stack_free", + "c++": "pcre32_jit_stack_free(pcre32_jit_stack *)", + "go": "(*JitStack).JitStackFree__2" + }, { + "mangle": "pcre32_maketables", + "c++": "pcre32_maketables()", + "go": "Maketables__2" + }, { + "mangle": "pcre32_pattern_to_host_byte_order", + "c++": "pcre32_pattern_to_host_byte_order(pcre32 *, pcre32_extra *, const unsigned char *)", + "go": "(*Pcre32).PatternToHostByteOrder" + }, { + "mangle": "pcre32_refcount", + "c++": "pcre32_refcount(pcre32 *, int)", + "go": "(*Pcre32).Refcount" + }, { + "mangle": "pcre32_study", + "c++": "pcre32_study(const pcre32 *, int, const char **)", + "go": "(*Pcre32).Study" + }, { + "mangle": "pcre32_utf32_to_host_byte_order", + "c++": "pcre32_utf32_to_host_byte_order(unsigned int *, const unsigned int *, int, int *, int)", + "go": "Utf32ToHostByteOrder" + }, { + "mangle": "pcre32_version", + "c++": "pcre32_version()", + "go": "Version__2" + }, { + "mangle": "pcre_assign_jit_stack", + "c++": "pcre_assign_jit_stack(pcre_extra *, pcre_jit_callback, void *)", + "go": "(*Extra).AssignJitStack" + }, { + "mangle": "pcre_compile", + "c++": "pcre_compile(const char *, int, const char **, int *, const unsigned char *)", + "go": "Compile" + }, { + "mangle": "pcre_compile2", + "c++": "pcre_compile2(const char *, int, int *, const char **, int *, const unsigned char *)", + "go": "Compile2" + }, { + "mangle": "pcre_config", + "c++": "pcre_config(int, void *)", + "go": "Config" + }, { + "mangle": "pcre_copy_named_substring", + "c++": "pcre_copy_named_substring(const pcre *, const char *, int *, int, const char *, char *, int)", + "go": "(*Pcre).CopyNamedSubstring" + }, { + "mangle": "pcre_copy_substring", + "c++": "pcre_copy_substring(const char *, int *, int, int, char *, int)", + "go": "CopySubstring" + }, { + "mangle": "pcre_dfa_exec", + "c++": "pcre_dfa_exec(const pcre *, const pcre_extra *, const char *, int, int, int, int *, int, int *, int)", + "go": "(*Pcre).DfaExec" + }, { + "mangle": "pcre_exec", + "c++": "pcre_exec(const pcre *, const pcre_extra *, const char *, int, int, int, int *, int)", + "go": "(*Pcre).Exec" + }, { + "mangle": "pcre_free_study", + "c++": "pcre_free_study(pcre_extra *)", + "go": "(*Extra).FreeStudy" + }, { + "mangle": "pcre_free_substring", + "c++": "pcre_free_substring(const char *)", + "go": "FreeSubstring" + }, { + "mangle": "pcre_free_substring_list", + "c++": "pcre_free_substring_list(const char **)", + "go": "FreeSubstringList" + }, { + "mangle": "pcre_fullinfo", + "c++": "pcre_fullinfo(const pcre *, const pcre_extra *, int, void *)", + "go": "(*Pcre).Fullinfo" + }, { + "mangle": "pcre_get_named_substring", + "c++": "pcre_get_named_substring(const pcre *, const char *, int *, int, const char *, const char **)", + "go": "(*Pcre).GetNamedSubstring" + }, { + "mangle": "pcre_get_stringnumber", + "c++": "pcre_get_stringnumber(const pcre *, const char *)", + "go": "(*Pcre).GetStringnumber" + }, { + "mangle": "pcre_get_stringtable_entries", + "c++": "pcre_get_stringtable_entries(const pcre *, const char *, char **, char **)", + "go": "(*Pcre).GetStringtableEntries" + }, { + "mangle": "pcre_get_substring", + "c++": "pcre_get_substring(const char *, int *, int, int, const char **)", + "go": "GetSubstring" + }, { + "mangle": "pcre_get_substring_list", + "c++": "pcre_get_substring_list(const char *, int *, int, const char ***)", + "go": "GetSubstringList" + }, { + "mangle": "pcre_jit_free_unused_memory", + "c++": "pcre_jit_free_unused_memory()", + "go": "JitFreeUnusedMemory" + }, { + "mangle": "pcre_jit_stack_alloc", + "c++": "pcre_jit_stack_alloc(int, int)", + "go": "JitStackAlloc" + }, { + "mangle": "pcre_jit_stack_free", + "c++": "pcre_jit_stack_free(pcre_jit_stack *)", + "go": "(*JitStack).JitStackFree" + }, { + "mangle": "pcre_maketables", + "c++": "pcre_maketables()", + "go": "Maketables" + }, { + "mangle": "pcre_pattern_to_host_byte_order", + "c++": "pcre_pattern_to_host_byte_order(pcre *, pcre_extra *, const unsigned char *)", + "go": "(*Pcre).PatternToHostByteOrder" + }, { + "mangle": "pcre_refcount", + "c++": "pcre_refcount(pcre *, int)", + "go": "(*Pcre).Refcount" + }, { + "mangle": "pcre_study", + "c++": "pcre_study(const pcre *, int, const char **)", + "go": "(*Pcre).Study" + }, { + "mangle": "pcre_version", + "c++": "pcre_version()", + "go": "Version" + }, { + "mangle": "regcomp", + "c++": "regcomp(regex_t *, const char *, int)", + "go": "(*RegexT).Regcomp" + }, { + "mangle": "regerror", + "c++": "regerror(int, const regex_t *, char *, size_t)", + "go": "Regerror" + }, { + "mangle": "regexec", + "c++": "regexec(const regex_t *, const char *, size_t, regmatch_t *, int)", + "go": "(*RegexT).Regexec" + }, { + "mangle": "regfree", + "c++": "regfree(regex_t *)", + "go": "(*RegexT).Regfree" + }] \ No newline at end of file diff --git a/pcre/llpkg.cfg b/pcre/llpkg.cfg new file mode 100644 index 00000000..5f2dfb3d --- /dev/null +++ b/pcre/llpkg.cfg @@ -0,0 +1,8 @@ +{ + "upstream": { + "package": { + "name": "pcre", + "version": "8.45" + } + } +} diff --git a/pcre/pcre.go b/pcre/pcre.go new file mode 100644 index 00000000..a13fca97 --- /dev/null +++ b/pcre/pcre.go @@ -0,0 +1,575 @@ +package pcre + +import ( + "github.com/goplus/llgo/c" + "unsafe" +) + +const PCRE_MAJOR = 8 +const PCRE_MINOR = 45 +const PCRE_CASELESS = 0x00000001 +const PCRE_MULTILINE = 0x00000002 +const PCRE_DOTALL = 0x00000004 +const PCRE_EXTENDED = 0x00000008 +const PCRE_ANCHORED = 0x00000010 +const PCRE_DOLLAR_ENDONLY = 0x00000020 +const PCRE_EXTRA = 0x00000040 +const PCRE_NOTBOL = 0x00000080 +const PCRE_NOTEOL = 0x00000100 +const PCRE_UNGREEDY = 0x00000200 +const PCRE_NOTEMPTY = 0x00000400 +const PCRE_UTF8 = 0x00000800 +const PCRE_UTF16 = 0x00000800 +const PCRE_UTF32 = 0x00000800 +const PCRE_NO_AUTO_CAPTURE = 0x00001000 +const PCRE_NO_UTF8_CHECK = 0x00002000 +const PCRE_NO_UTF16_CHECK = 0x00002000 +const PCRE_NO_UTF32_CHECK = 0x00002000 +const PCRE_AUTO_CALLOUT = 0x00004000 +const PCRE_PARTIAL_SOFT = 0x00008000 +const PCRE_PARTIAL = 0x00008000 +const PCRE_NEVER_UTF = 0x00010000 +const PCRE_DFA_SHORTEST = 0x00010000 +const PCRE_NO_AUTO_POSSESS = 0x00020000 +const PCRE_DFA_RESTART = 0x00020000 +const PCRE_FIRSTLINE = 0x00040000 +const PCRE_DUPNAMES = 0x00080000 +const PCRE_NEWLINE_CR = 0x00100000 +const PCRE_NEWLINE_LF = 0x00200000 +const PCRE_NEWLINE_CRLF = 0x00300000 +const PCRE_NEWLINE_ANY = 0x00400000 +const PCRE_NEWLINE_ANYCRLF = 0x00500000 +const PCRE_BSR_ANYCRLF = 0x00800000 +const PCRE_BSR_UNICODE = 0x01000000 +const PCRE_JAVASCRIPT_COMPAT = 0x02000000 +const PCRE_NO_START_OPTIMIZE = 0x04000000 +const PCRE_NO_START_OPTIMISE = 0x04000000 +const PCRE_PARTIAL_HARD = 0x08000000 +const PCRE_NOTEMPTY_ATSTART = 0x10000000 +const PCRE_UCP = 0x20000000 +const PCRE_UTF8_ERR0 = 0 +const PCRE_UTF8_ERR1 = 1 +const PCRE_UTF8_ERR2 = 2 +const PCRE_UTF8_ERR3 = 3 +const PCRE_UTF8_ERR4 = 4 +const PCRE_UTF8_ERR5 = 5 +const PCRE_UTF8_ERR6 = 6 +const PCRE_UTF8_ERR7 = 7 +const PCRE_UTF8_ERR8 = 8 +const PCRE_UTF8_ERR9 = 9 +const PCRE_UTF8_ERR10 = 10 +const PCRE_UTF8_ERR11 = 11 +const PCRE_UTF8_ERR12 = 12 +const PCRE_UTF8_ERR13 = 13 +const PCRE_UTF8_ERR14 = 14 +const PCRE_UTF8_ERR15 = 15 +const PCRE_UTF8_ERR16 = 16 +const PCRE_UTF8_ERR17 = 17 +const PCRE_UTF8_ERR18 = 18 +const PCRE_UTF8_ERR19 = 19 +const PCRE_UTF8_ERR20 = 20 +const PCRE_UTF8_ERR21 = 21 +const PCRE_UTF8_ERR22 = 22 +const PCRE_UTF16_ERR0 = 0 +const PCRE_UTF16_ERR1 = 1 +const PCRE_UTF16_ERR2 = 2 +const PCRE_UTF16_ERR3 = 3 +const PCRE_UTF16_ERR4 = 4 +const PCRE_UTF32_ERR0 = 0 +const PCRE_UTF32_ERR1 = 1 +const PCRE_UTF32_ERR2 = 2 +const PCRE_UTF32_ERR3 = 3 +const PCRE_INFO_OPTIONS = 0 +const PCRE_INFO_SIZE = 1 +const PCRE_INFO_CAPTURECOUNT = 2 +const PCRE_INFO_BACKREFMAX = 3 +const PCRE_INFO_FIRSTBYTE = 4 +const PCRE_INFO_FIRSTCHAR = 4 +const PCRE_INFO_FIRSTTABLE = 5 +const PCRE_INFO_LASTLITERAL = 6 +const PCRE_INFO_NAMEENTRYSIZE = 7 +const PCRE_INFO_NAMECOUNT = 8 +const PCRE_INFO_NAMETABLE = 9 +const PCRE_INFO_STUDYSIZE = 10 +const PCRE_INFO_DEFAULT_TABLES = 11 +const PCRE_INFO_OKPARTIAL = 12 +const PCRE_INFO_JCHANGED = 13 +const PCRE_INFO_HASCRORLF = 14 +const PCRE_INFO_MINLENGTH = 15 +const PCRE_INFO_JIT = 16 +const PCRE_INFO_JITSIZE = 17 +const PCRE_INFO_MAXLOOKBEHIND = 18 +const PCRE_INFO_FIRSTCHARACTER = 19 +const PCRE_INFO_FIRSTCHARACTERFLAGS = 20 +const PCRE_INFO_REQUIREDCHAR = 21 +const PCRE_INFO_REQUIREDCHARFLAGS = 22 +const PCRE_INFO_MATCHLIMIT = 23 +const PCRE_INFO_RECURSIONLIMIT = 24 +const PCRE_INFO_MATCH_EMPTY = 25 +const PCRE_CONFIG_UTF8 = 0 +const PCRE_CONFIG_NEWLINE = 1 +const PCRE_CONFIG_LINK_SIZE = 2 +const PCRE_CONFIG_POSIX_MALLOC_THRESHOLD = 3 +const PCRE_CONFIG_MATCH_LIMIT = 4 +const PCRE_CONFIG_STACKRECURSE = 5 +const PCRE_CONFIG_UNICODE_PROPERTIES = 6 +const PCRE_CONFIG_MATCH_LIMIT_RECURSION = 7 +const PCRE_CONFIG_BSR = 8 +const PCRE_CONFIG_JIT = 9 +const PCRE_CONFIG_UTF16 = 10 +const PCRE_CONFIG_JITTARGET = 11 +const PCRE_CONFIG_UTF32 = 12 +const PCRE_CONFIG_PARENS_LIMIT = 13 +const PCRE_STUDY_JIT_COMPILE = 0x0001 +const PCRE_STUDY_JIT_PARTIAL_SOFT_COMPILE = 0x0002 +const PCRE_STUDY_JIT_PARTIAL_HARD_COMPILE = 0x0004 +const PCRE_STUDY_EXTRA_NEEDED = 0x0008 +const PCRE_EXTRA_STUDY_DATA = 0x0001 +const PCRE_EXTRA_MATCH_LIMIT = 0x0002 +const PCRE_EXTRA_CALLOUT_DATA = 0x0004 +const PCRE_EXTRA_TABLES = 0x0008 +const PCRE_EXTRA_MATCH_LIMIT_RECURSION = 0x0010 +const PCRE_EXTRA_MARK = 0x0020 +const PCRE_EXTRA_EXECUTABLE_JIT = 0x0040 + +/* Types */ + +type RealPcre8Or16 struct { + Unused [8]uint8 +} +type Pcre RealPcre8Or16 +type Pcre16 RealPcre8Or16 + +type RealPcre32 struct { + Unused [8]uint8 +} +type Pcre32 RealPcre32 + +type RealPcreJitStack struct { + Unused [8]uint8 +} +type JitStack RealPcreJitStack + +type RealPcre16JitStack struct { + Unused [8]uint8 +} +type JitStack__1 RealPcre16JitStack + +type RealPcre32JitStack struct { + Unused [8]uint8 +} +type JitStack__2 RealPcre32JitStack + +/* + The structure for passing additional data to pcre_exec(). This is defined in + +such as way as to be extensible. Always add new fields at the end, in order to +remain compatible. +*/ +type Extra struct { + Flags c.Ulong + StudyData unsafe.Pointer + MatchLimit c.Ulong + CalloutData unsafe.Pointer + Tables *int8 + MatchLimitRecursion c.Ulong + Mark **int8 + ExecutableJit unsafe.Pointer +} + +/* Same structure as above, but with 16 bit char pointers. */ + +type Extra__1 struct { + Flags c.Ulong + StudyData unsafe.Pointer + MatchLimit c.Ulong + CalloutData unsafe.Pointer + Tables *int8 + MatchLimitRecursion c.Ulong + Mark **uint16 + ExecutableJit unsafe.Pointer +} + +/* Same structure as above, but with 32 bit char pointers. */ + +type Extra__2 struct { + Flags c.Ulong + StudyData unsafe.Pointer + MatchLimit c.Ulong + CalloutData unsafe.Pointer + Tables *int8 + MatchLimitRecursion c.Ulong + Mark **c.Uint + ExecutableJit unsafe.Pointer +} + +/* + The structure for passing out data via the pcre_callout_function. We use a + +structure so that new fields can be added on the end in future versions, +without changing the API of the function, thereby allowing old clients to work +without modification. +*/ +type CalloutBlock struct { + Version c.Int + CalloutNumber c.Int + OffsetVector *c.Int + Subject *int8 + SubjectLength c.Int + StartMatch c.Int + CurrentPosition c.Int + CaptureTop c.Int + CaptureLast c.Int + CalloutData unsafe.Pointer + PatternPosition c.Int + NextItemLength c.Int + Mark *int8 +} + +/* Same structure as above, but with 16 bit char pointers. */ + +type CalloutBlock__1 struct { + Version c.Int + CalloutNumber c.Int + OffsetVector *c.Int + Subject *uint16 + SubjectLength c.Int + StartMatch c.Int + CurrentPosition c.Int + CaptureTop c.Int + CaptureLast c.Int + CalloutData unsafe.Pointer + PatternPosition c.Int + NextItemLength c.Int + Mark *uint16 +} + +/* Same structure as above, but with 32 bit char pointers. */ + +type CalloutBlock__2 struct { + Version c.Int + CalloutNumber c.Int + OffsetVector *c.Int + Subject *c.Uint + SubjectLength c.Int + StartMatch c.Int + CurrentPosition c.Int + CaptureTop c.Int + CaptureLast c.Int + CalloutData unsafe.Pointer + PatternPosition c.Int + NextItemLength c.Int + Mark *c.Uint +} + +// llgo:type C +type JitCallback func(unsafe.Pointer) *JitStack + +// llgo:type C +type JitCallback__1 func(unsafe.Pointer) *JitStack__1 + +// llgo:type C +type JitCallback__2 func(unsafe.Pointer) *JitStack__2 + +/* Exported PCRE functions */ +//go:linkname Compile C.pcre_compile +func Compile(*int8, c.Int, **int8, *c.Int, *int8) *Pcre + +//go:linkname Compile__1 C.pcre16_compile +func Compile__1(*uint16, c.Int, **int8, *c.Int, *int8) *Pcre16 + +//go:linkname Compile__2 C.pcre32_compile +func Compile__2(*c.Uint, c.Int, **int8, *c.Int, *int8) *Pcre32 + +//go:linkname Compile2 C.pcre_compile2 +func Compile2(*int8, c.Int, *c.Int, **int8, *c.Int, *int8) *Pcre + +//go:linkname Compile2__1 C.pcre16_compile2 +func Compile2__1(*uint16, c.Int, *c.Int, **int8, *c.Int, *int8) *Pcre16 + +//go:linkname Compile2__2 C.pcre32_compile2 +func Compile2__2(*c.Uint, c.Int, *c.Int, **int8, *c.Int, *int8) *Pcre32 + +//go:linkname Config C.pcre_config +func Config(c.Int, unsafe.Pointer) c.Int + +//go:linkname Config__1 C.pcre16_config +func Config__1(c.Int, unsafe.Pointer) c.Int + +//go:linkname Config__2 C.pcre32_config +func Config__2(c.Int, unsafe.Pointer) c.Int + +// llgo:link (*Pcre).CopyNamedSubstring C.pcre_copy_named_substring +func (recv_ *Pcre) CopyNamedSubstring(*int8, *c.Int, c.Int, *int8, *int8, c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre16).CopyNamedSubstring C.pcre16_copy_named_substring +func (recv_ *Pcre16) CopyNamedSubstring(*uint16, *c.Int, c.Int, *uint16, *uint16, c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre32).CopyNamedSubstring C.pcre32_copy_named_substring +func (recv_ *Pcre32) CopyNamedSubstring(*c.Uint, *c.Int, c.Int, *c.Uint, *c.Uint, c.Int) c.Int { + return 0 +} + +//go:linkname CopySubstring C.pcre_copy_substring +func CopySubstring(*int8, *c.Int, c.Int, c.Int, *int8, c.Int) c.Int + +//go:linkname CopySubstring__1 C.pcre16_copy_substring +func CopySubstring__1(*uint16, *c.Int, c.Int, c.Int, *uint16, c.Int) c.Int + +//go:linkname CopySubstring__2 C.pcre32_copy_substring +func CopySubstring__2(*c.Uint, *c.Int, c.Int, c.Int, *c.Uint, c.Int) c.Int + +// llgo:link (*Pcre).DfaExec C.pcre_dfa_exec +func (recv_ *Pcre) DfaExec(*Extra, *int8, c.Int, c.Int, c.Int, *c.Int, c.Int, *c.Int, c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre16).DfaExec C.pcre16_dfa_exec +func (recv_ *Pcre16) DfaExec(*Extra__1, *uint16, c.Int, c.Int, c.Int, *c.Int, c.Int, *c.Int, c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre32).DfaExec C.pcre32_dfa_exec +func (recv_ *Pcre32) DfaExec(*Extra__2, *c.Uint, c.Int, c.Int, c.Int, *c.Int, c.Int, *c.Int, c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre).Exec C.pcre_exec +func (recv_ *Pcre) Exec(*Extra, *int8, c.Int, c.Int, c.Int, *c.Int, c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre16).Exec C.pcre16_exec +func (recv_ *Pcre16) Exec(*Extra__1, *uint16, c.Int, c.Int, c.Int, *c.Int, c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre32).Exec C.pcre32_exec +func (recv_ *Pcre32) Exec(*Extra__2, *c.Uint, c.Int, c.Int, c.Int, *c.Int, c.Int) c.Int { + return 0 +} + +//go:linkname FreeSubstring C.pcre_free_substring +func FreeSubstring(*int8) + +//go:linkname FreeSubstring__1 C.pcre16_free_substring +func FreeSubstring__1(*uint16) + +//go:linkname FreeSubstring__2 C.pcre32_free_substring +func FreeSubstring__2(*c.Uint) + +//go:linkname FreeSubstringList C.pcre_free_substring_list +func FreeSubstringList(**int8) + +//go:linkname FreeSubstringList__1 C.pcre16_free_substring_list +func FreeSubstringList__1(**uint16) + +//go:linkname FreeSubstringList__2 C.pcre32_free_substring_list +func FreeSubstringList__2(**c.Uint) + +// llgo:link (*Pcre).Fullinfo C.pcre_fullinfo +func (recv_ *Pcre) Fullinfo(*Extra, c.Int, unsafe.Pointer) c.Int { + return 0 +} + +// llgo:link (*Pcre16).Fullinfo C.pcre16_fullinfo +func (recv_ *Pcre16) Fullinfo(*Extra__1, c.Int, unsafe.Pointer) c.Int { + return 0 +} + +// llgo:link (*Pcre32).Fullinfo C.pcre32_fullinfo +func (recv_ *Pcre32) Fullinfo(*Extra__2, c.Int, unsafe.Pointer) c.Int { + return 0 +} + +// llgo:link (*Pcre).GetNamedSubstring C.pcre_get_named_substring +func (recv_ *Pcre) GetNamedSubstring(*int8, *c.Int, c.Int, *int8, **int8) c.Int { + return 0 +} + +// llgo:link (*Pcre16).GetNamedSubstring C.pcre16_get_named_substring +func (recv_ *Pcre16) GetNamedSubstring(*uint16, *c.Int, c.Int, *uint16, **uint16) c.Int { + return 0 +} + +// llgo:link (*Pcre32).GetNamedSubstring C.pcre32_get_named_substring +func (recv_ *Pcre32) GetNamedSubstring(*c.Uint, *c.Int, c.Int, *c.Uint, **c.Uint) c.Int { + return 0 +} + +// llgo:link (*Pcre).GetStringnumber C.pcre_get_stringnumber +func (recv_ *Pcre) GetStringnumber(*int8) c.Int { + return 0 +} + +// llgo:link (*Pcre16).GetStringnumber C.pcre16_get_stringnumber +func (recv_ *Pcre16) GetStringnumber(*uint16) c.Int { + return 0 +} + +// llgo:link (*Pcre32).GetStringnumber C.pcre32_get_stringnumber +func (recv_ *Pcre32) GetStringnumber(*c.Uint) c.Int { + return 0 +} + +// llgo:link (*Pcre).GetStringtableEntries C.pcre_get_stringtable_entries +func (recv_ *Pcre) GetStringtableEntries(*int8, **int8, **int8) c.Int { + return 0 +} + +// llgo:link (*Pcre16).GetStringtableEntries C.pcre16_get_stringtable_entries +func (recv_ *Pcre16) GetStringtableEntries(*uint16, **uint16, **uint16) c.Int { + return 0 +} + +// llgo:link (*Pcre32).GetStringtableEntries C.pcre32_get_stringtable_entries +func (recv_ *Pcre32) GetStringtableEntries(*c.Uint, **c.Uint, **c.Uint) c.Int { + return 0 +} + +//go:linkname GetSubstring C.pcre_get_substring +func GetSubstring(*int8, *c.Int, c.Int, c.Int, **int8) c.Int + +//go:linkname GetSubstring__1 C.pcre16_get_substring +func GetSubstring__1(*uint16, *c.Int, c.Int, c.Int, **uint16) c.Int + +//go:linkname GetSubstring__2 C.pcre32_get_substring +func GetSubstring__2(*c.Uint, *c.Int, c.Int, c.Int, **c.Uint) c.Int + +//go:linkname GetSubstringList C.pcre_get_substring_list +func GetSubstringList(*int8, *c.Int, c.Int, ***int8) c.Int + +//go:linkname GetSubstringList__1 C.pcre16_get_substring_list +func GetSubstringList__1(*uint16, *c.Int, c.Int, ***uint16) c.Int + +//go:linkname GetSubstringList__2 C.pcre32_get_substring_list +func GetSubstringList__2(*c.Uint, *c.Int, c.Int, ***c.Uint) c.Int + +//go:linkname Maketables C.pcre_maketables +func Maketables() *int8 + +//go:linkname Maketables__1 C.pcre16_maketables +func Maketables__1() *int8 + +//go:linkname Maketables__2 C.pcre32_maketables +func Maketables__2() *int8 + +// llgo:link (*Pcre).Refcount C.pcre_refcount +func (recv_ *Pcre) Refcount(c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre16).Refcount C.pcre16_refcount +func (recv_ *Pcre16) Refcount(c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre32).Refcount C.pcre32_refcount +func (recv_ *Pcre32) Refcount(c.Int) c.Int { + return 0 +} + +// llgo:link (*Pcre).Study C.pcre_study +func (recv_ *Pcre) Study(c.Int, **int8) *Extra { + return nil +} + +// llgo:link (*Pcre16).Study C.pcre16_study +func (recv_ *Pcre16) Study(c.Int, **int8) *Extra__1 { + return nil +} + +// llgo:link (*Pcre32).Study C.pcre32_study +func (recv_ *Pcre32) Study(c.Int, **int8) *Extra__2 { + return nil +} + +// llgo:link (*Extra).FreeStudy C.pcre_free_study +func (recv_ *Extra) FreeStudy() { +} + +// llgo:link (*Extra__1).FreeStudy__1 C.pcre16_free_study +func (recv_ *Extra__1) FreeStudy__1() { +} + +// llgo:link (*Extra__2).FreeStudy__2 C.pcre32_free_study +func (recv_ *Extra__2) FreeStudy__2() { +} + +//go:linkname Version C.pcre_version +func Version() *int8 + +//go:linkname Version__1 C.pcre16_version +func Version__1() *int8 + +//go:linkname Version__2 C.pcre32_version +func Version__2() *int8 + +/* Utility functions for byte order swaps. */ +// llgo:link (*Pcre).PatternToHostByteOrder C.pcre_pattern_to_host_byte_order +func (recv_ *Pcre) PatternToHostByteOrder(*Extra, *int8) c.Int { + return 0 +} + +// llgo:link (*Pcre16).PatternToHostByteOrder C.pcre16_pattern_to_host_byte_order +func (recv_ *Pcre16) PatternToHostByteOrder(*Extra__1, *int8) c.Int { + return 0 +} + +// llgo:link (*Pcre32).PatternToHostByteOrder C.pcre32_pattern_to_host_byte_order +func (recv_ *Pcre32) PatternToHostByteOrder(*Extra__2, *int8) c.Int { + return 0 +} + +//go:linkname Utf16ToHostByteOrder C.pcre16_utf16_to_host_byte_order +func Utf16ToHostByteOrder(*uint16, *uint16, c.Int, *c.Int, c.Int) c.Int + +//go:linkname Utf32ToHostByteOrder C.pcre32_utf32_to_host_byte_order +func Utf32ToHostByteOrder(*c.Uint, *c.Uint, c.Int, *c.Int, c.Int) c.Int + +/* JIT compiler related functions. */ +//go:linkname JitStackAlloc C.pcre_jit_stack_alloc +func JitStackAlloc(c.Int, c.Int) *JitStack + +//go:linkname JitStackAlloc__1 C.pcre16_jit_stack_alloc +func JitStackAlloc__1(c.Int, c.Int) *JitStack__1 + +//go:linkname JitStackAlloc__2 C.pcre32_jit_stack_alloc +func JitStackAlloc__2(c.Int, c.Int) *JitStack__2 + +// llgo:link (*JitStack).JitStackFree C.pcre_jit_stack_free +func (recv_ *JitStack) JitStackFree() { +} + +// llgo:link (*JitStack__1).JitStackFree__1 C.pcre16_jit_stack_free +func (recv_ *JitStack__1) JitStackFree__1() { +} + +// llgo:link (*JitStack__2).JitStackFree__2 C.pcre32_jit_stack_free +func (recv_ *JitStack__2) JitStackFree__2() { +} + +// llgo:link (*Extra).AssignJitStack C.pcre_assign_jit_stack +func (recv_ *Extra) AssignJitStack(JitCallback, unsafe.Pointer) { +} + +// llgo:link (*Extra__1).AssignJitStack__1 C.pcre16_assign_jit_stack +func (recv_ *Extra__1) AssignJitStack__1(JitCallback__1, unsafe.Pointer) { +} + +// llgo:link (*Extra__2).AssignJitStack__2 C.pcre32_assign_jit_stack +func (recv_ *Extra__2) AssignJitStack__2(JitCallback__2, unsafe.Pointer) { +} + +//go:linkname JitFreeUnusedMemory C.pcre_jit_free_unused_memory +func JitFreeUnusedMemory() + +//go:linkname JitFreeUnusedMemory__1 C.pcre16_jit_free_unused_memory +func JitFreeUnusedMemory__1() + +//go:linkname JitFreeUnusedMemory__2 C.pcre32_jit_free_unused_memory +func JitFreeUnusedMemory__2() diff --git a/pcre/pcre_autogen_link.go b/pcre/pcre_autogen_link.go new file mode 100644 index 00000000..b4e16167 --- /dev/null +++ b/pcre/pcre_autogen_link.go @@ -0,0 +1,3 @@ +package pcre + +const LLGoPackage string = "link: $(pkg-config --libs pcre);" diff --git a/pcre/pcreposix.go b/pcre/pcreposix.go new file mode 100644 index 00000000..0f47e5df --- /dev/null +++ b/pcre/pcreposix.go @@ -0,0 +1,70 @@ +package pcre + +import ( + "github.com/goplus/llgo/c" + "unsafe" +) + +const REG_ICASE = 0x0001 +const REG_NEWLINE = 0x0002 +const REG_NOTBOL = 0x0004 +const REG_NOTEOL = 0x0008 +const REG_DOTALL = 0x0010 +const REG_NOSUB = 0x0020 +const REG_UTF8 = 0x0040 +const REG_STARTEND = 0x0080 +const REG_NOTEMPTY = 0x0100 +const REG_UNGREEDY = 0x0200 +const REG_UCP = 0x0400 +const REG_EXTENDED = 0 +const ( + REGASSERT c.Int = 1 + REGBADBR c.Int = 2 + REGBADPAT c.Int = 3 + REGBADRPT c.Int = 4 + REGEBRACE c.Int = 5 + REGEBRACK c.Int = 6 + REGECOLLATE c.Int = 7 + REGECTYPE c.Int = 8 + REGEESCAPE c.Int = 9 + REGEMPTY c.Int = 10 + REGEPAREN c.Int = 11 + REGERANGE c.Int = 12 + REGESIZE c.Int = 13 + REGESPACE c.Int = 14 + REGESUBREG c.Int = 15 + REGINVARG c.Int = 16 + REGNOMATCH c.Int = 17 +) + +/* The structure representing a compiled regular expression. */ + +type RegexT struct { + RePcre unsafe.Pointer + ReNsub uintptr + ReErroffset uintptr +} +type RegoffT c.Int + +type RegmatchT struct { + RmSo RegoffT + RmEo RegoffT +} + +/* The functions */ +// llgo:link (*RegexT).Regcomp C.regcomp +func (recv_ *RegexT) Regcomp(*int8, c.Int) c.Int { + return 0 +} + +// llgo:link (*RegexT).Regexec C.regexec +func (recv_ *RegexT) Regexec(*int8, uintptr, *RegmatchT, c.Int) c.Int { + return 0 +} + +//go:linkname Regerror C.regerror +func Regerror(c.Int, *RegexT, *int8, uintptr) uintptr + +// llgo:link (*RegexT).Regfree C.regfree +func (recv_ *RegexT) Regfree() { +}