1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#! /usr/bin/env crystal
{% if Regex::Engine.resolve.name == "Regex::PCRE2" %}
enum LibPCRE2::BSR : UInt32
UNICODE = 1
ANYCRLF = 2
end
@[Flags]
enum LibPCRE2::COMPILED_WIDTHS : UInt32
U8
U16
U32
Unused
end
enum LibPCRE2::NEWLINE : UInt32
CR = 1
LF = 2
CRLF = 3
ANY = 4
ANYCRLF = 5
NUL = 6
end
def config(kind : UInt32.class, what)
where = uninitialized UInt32
LibPCRE2.config(what, pointerof(where))
where
end
def config(kind : Bool.class, what)
config(UInt32, what) != 0
end
def config(kind : String.class, what)
len = LibPCRE2.config(what, nil)
if len > 0
where = Bytes.new(len - 1)
LibPCRE2.config(what, where)
ret = String.new(where)
end
ret.inspect
end
def config(kind : Enum.class, what)
kind.new(config(UInt32, what))
end
puts <<-EOS
Using PCRE2 #{config(String, LibPCRE2::CONFIG_VERSION)}
* PCRE2_CONFIG_BSR: #{config(LibPCRE2::BSR, LibPCRE2::CONFIG_BSR)}
* PCRE2_CONFIG_COMPILED_WIDTHS: #{config(LibPCRE2::COMPILED_WIDTHS, LibPCRE2::CONFIG_COMPILED_WIDTHS)}
* PCRE2_CONFIG_DEPTHLIMIT: #{config(UInt32, LibPCRE2::CONFIG_DEPTHLIMIT)}
* PCRE2_CONFIG_HEAPLIMIT: #{config(UInt32, LibPCRE2::CONFIG_HEAPLIMIT)}
* PCRE2_CONFIG_JIT: #{config(Bool, LibPCRE2::CONFIG_JIT)}
* PCRE2_CONFIG_JITTARGET: #{config(String, LibPCRE2::CONFIG_JITTARGET)}
* PCRE2_CONFIG_LINKSIZE: #{config(UInt32, LibPCRE2::CONFIG_LINKSIZE)}
* PCRE2_CONFIG_MATCHLIMIT: #{config(UInt32, LibPCRE2::CONFIG_MATCHLIMIT)}
* PCRE2_CONFIG_NEVER_BACKSLASH_C: #{config(Bool, LibPCRE2::CONFIG_NEVER_BACKSLASH_C)}
* PCRE2_CONFIG_NEWLINE: #{config(LibPCRE2::NEWLINE, LibPCRE2::CONFIG_NEWLINE)}
* PCRE2_CONFIG_PARENSLIMIT: #{config(UInt32, LibPCRE2::CONFIG_PARENSLIMIT)}
* PCRE2_CONFIG_UNICODE: #{config(Bool, LibPCRE2::CONFIG_UNICODE)}
* PCRE2_CONFIG_UNICODE_VERSION: #{config(String, LibPCRE2::CONFIG_UNICODE_VERSION)}
EOS
{% else %}
enum LibPCRE::BSR : LibC::Int
UNICODE = 0
ANYCRLF = 1
end
enum LibPCRE::NEWLINE : LibC::Int
CR = 0x000d
LF = 0x000a
CRLF = 0x0d0a
ANYCRLF = -2
ANY = -1
end
lib LibPCRE
CONFIG_UTF8 = 0
CONFIG_NEWLINE = 1
CONFIG_LINK_SIZE = 2
CONFIG_POSIX_MALLOC_THRESHOLD = 3
CONFIG_MATCH_LIMIT = 4
CONFIG_STACKRECURSE = 5
CONFIG_UNICODE_PROPERTIES = 6
CONFIG_MATCH_LIMIT_RECURSION = 7
CONFIG_BSR = 8
CONFIG_UTF16 = 10
CONFIG_JITTARGET = 11
CONFIG_UTF32 = 12
CONFIG_PARENS_LIMIT = 13
end
def config(kind : LibC::Int.class, what)
where = uninitialized LibC::Int
LibPCRE.config(what, pointerof(where))
where
end
def config(kind : LibC::ULong.class, what)
where = uninitialized LibC::ULong
LibPCRE.config(what, pointerof(where))
where
end
def config(kind : Bool.class, what)
config(LibC::Int, what) != 0
end
def config(kind : String.class, what)
where = uninitialized LibC::Char*
LibPCRE.config(what, pointerof(where))
(where ? String.new(where) : nil).inspect
end
def config(kind : Enum.class, what)
kind.new(config(LibC::Int, what))
end
puts <<-EOS
Using PCRE #{String.new(LibPCRE.version).inspect}
* PCRE_CONFIG_BSR: #{config(LibPCRE::BSR, LibPCRE::CONFIG_BSR)}
* PCRE_CONFIG_JIT: #{config(Bool, LibPCRE::CONFIG_JIT)}
* PCRE_CONFIG_JITTARGET: #{config(String, LibPCRE::CONFIG_JITTARGET)}
* PCRE_CONFIG_LINK_SIZE: #{config(LibC::Int, LibPCRE::CONFIG_LINK_SIZE)}
* PCRE_CONFIG_PARENS_LIMIT: #{config(LibC::ULong, LibPCRE::CONFIG_PARENS_LIMIT)}
* PCRE_CONFIG_MATCH_LIMIT: #{config(LibC::ULong, LibPCRE::CONFIG_MATCH_LIMIT)}
* PCRE_CONFIG_MATCH_LIMIT_RECURSION: #{config(LibC::ULong, LibPCRE::CONFIG_MATCH_LIMIT_RECURSION)}
* PCRE_CONFIG_NEWLINE: #{config(LibPCRE::NEWLINE, LibPCRE::CONFIG_NEWLINE)}
* PCRE_CONFIG_POSIX_MALLOC_THRESHOLD: #{config(LibC::Int, LibPCRE::CONFIG_POSIX_MALLOC_THRESHOLD)}
* PCRE_CONFIG_STACKRECURSE: #{config(Bool, LibPCRE::CONFIG_STACKRECURSE)}
* PCRE_CONFIG_UTF16: #{config(Bool, LibPCRE::CONFIG_UTF16)}
* PCRE_CONFIG_UTF32: #{config(Bool, LibPCRE::CONFIG_UTF32)}
* PCRE_CONFIG_UTF8: #{config(Bool, LibPCRE::CONFIG_UTF8)}
* PCRE_CONFIG_UNICODE_PROPERTIES: #{config(Bool, LibPCRE::CONFIG_UNICODE_PROPERTIES)}
EOS
{% end %}
|