unit oniguruma; interface uses Windows; //#define ONIGURUMA const ONIGURUMA_VERSION_MAJOR = 2; ONIGURUMA_VERSION_MINOR = 2; ONIGURUMA_VERSION_TEENY = 6; (* PART: character encoding *) type UChar = Byte; PUChar = ^UChar; OnigCodePoint = LongInt; POnigCodePoint = ^OnigCodePoint; PPOnigCodePoint = ^POnigCodePoint; OnigDistance = cardinal; const ONIG_INFINITE_DISTANCE = not OnigDistance(0); type OnigCodePointRange = record from: OnigCodePoint; _to: OnigCodePoint; end; POnigCodePointRange = ^OnigCodePointRange; const ONIGENC_FOLD_MATCH_MAX_TARGET_NUM_SIZE = 16; type OnigEncFoldMatchInfo = record target_num: integer; target_byte_len: array[0..ONIGENC_FOLD_MATCH_MAX_TARGET_NUM_SIZE-1] of integer; target_str: array[0..ONIGENC_FOLD_MATCH_MAX_TARGET_NUM_SIZE-1] of PUChar; end; POnigEncFoldMatchInfo = ^OnigEncFoldMatchInfo; PPOnigEncFoldMatchInfo = ^POnigEncFoldMatchInfo; OnigEncodingType = record (* const *) len_table: array[0..256-1] of Char; (* const *) name: PChar; max_enc_len: integer; is_fold_match: integer; ctype_support_level: integer; (* sb-only/full *) is_continuous_sb_mb: integer; (* code point is continuous from sb to mb *) mbc_to_code: function(p: PUChar; _end: PUChar): OnigCodePoint; code_to_mbclen: function(code: OnigCodePoint): integer; code_to_mbc: function(code: OnigCodePoint; buf: PUChar): integer; mbc_to_lower: function(p, lower: PUChar): integer; mbc_is_case_ambig: function(p: PUChar): integer; code_is_ctype: function(code: OnigCodePoint; ctype: cardinal): integer; get_ctype_code_range: function(ctype: integer; nsb, nmb: PInteger; sbr, mbr: array of POnigCodePointRange): integer; left_adjust_char_head: function(start, s: PUChar): PUChar; is_allowed_reverse_match: function(p, e: PUChar): integer; get_all_fold_match_code: function(codes: PPOnigCodePoint): integer; get_fold_match_info: function(p, _end: PUChar; info: PPOnigEncFoldMatchInfo): integer; end; OnigEncoding = ^OnigEncodingType; type TOnigEncodingTypeFunc = function: OnigEncodingType; cdecl; const OnigDLL = 'onig.dll'; function ONIG_ENCODING_ASCII: Pointer; function ONIG_ENCODING_UTF8: Pointer; function ONIG_ENCODING_EUC_JP: Pointer; function ONIG_ENCODING_SJIS: Pointer; (* match result region type *) type POnigRegion = ^OnigRegion; PPOnigRegion = ^POnigRegion; OnigRegion = record (* struct re_registers *) allocated: integer; num_regs: integer; beg: pinteger; _end: pinteger; (* extended *) list: PPOnigRegion; (* capture history. list[1]-list[31] *) end; const ONIG_REGION_NOTPOS = -1; type OnigErrorInfo = record par, par_end: PUChar; end; POnigErrorInfo = ^OnigErrorInfo; const ONIG_ENCODING_UNDEF = OnigEncoding(0); (* PART: regular expression *) (* constants *) ONIG_MAX_ERROR_MESSAGE_LEN = 90; (* options *) ONIG_OPTION_NONE = 0; ONIG_OPTION_DEFAULT = ONIG_OPTION_NONE; (* normal return *) ONIG_NORMAL = 0; ONIG_MISMATCH = -1; ONIG_NO_SUPPORT_CONFIG = -2; type OnigOptionType = cardinal; TErrorMessage = array[0..ONIG_MAX_ERROR_MESSAGE_LEN-1] of char; (* syntax *) OnigSyntaxType = record op, op2, behavior: cardinal; options: OnigOptionType; (* default option *) end; POnigSyntaxType = ^OnigSyntaxType; OnigRepeatRange = record lower, upper: integer; end; POnigRepeatRange = ^OnigRepeatRange; const ONIG_CHAR_TABLE_SIZE = 256; type PPregex_t = ^Pregex_t; Pregex_t = ^regex_t; regex_t = record (* struct re_pattern_buffer *) (* common members of BBuf(bytes-buffer) *) p: PUChar; (* compiled pattern *) used: cardinal; (* used space for p *) alloc: cardinal; (* allocated space for p *) state: integer; (* normal, searching, compiling *) num_mem: integer; (* used memory(...) num counted from 1 *) num_repeat: integer; (* OP_REPEAT/OP_REPEAT_NG id-counter *) num_null_check: integer; (* OP_NULL_CHECK_START/END id counter *) num_call: integer; (* number of subexp call *) capture_history: cardinal; (* (?@...) flag (1-31) *) bt_mem_start: cardinal; (* need backtrack flag *) bt_mem_end: cardinal; (* need backtrack flag *) stack_pop_level: integer; repeat_range_alloc: integer; repeat_range: POnigRepeatRange; enc: OnigEncoding; options: OnigOptionType; syntax: POnigSyntaxType; name_table: Pointer; (* optimization info (string search, char-map and anchors) *) optimize: integer; (* optimize flag *) threshold_len: integer; (* search str-length for apply optimize *) anchor: integer; (* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF *) anchor_dmin: OnigDistance; (* (SEMI_)END_BUF anchor distance *) anchor_dmax: OnigDistance; (* (SEMI_)END_BUF anchor distance *) sub_anchor: integer; (* start-anchor for exact or map *) exact: PUChar; exact_end: PUChar; map: array[0..ONIG_CHAR_TABLE_SIZE-1] of UChar; (* used as BM skip or char-map *) int_map: pinteger; (* BM skip for exact_len > 255 *) int_map_backward: pinteger; (* BM skip for backward search *) dmin: OnigDistance; (* min-distance of exact or map *) dmax: OnigDistance; (* max-distance of exact or map *) (* regex_t link chain *) chain: Pregex_t; (* escape compile-conflict *) end; function ONIG_SYNTAX_RUBY: Pointer; function ONIG_SYNTAX_DEFAULT: Pointer; function onig_search(reg: Pregex_t; str, _end, start, range: PUChar; region: POnigRegion; option: OnigOptionType): integer; cdecl; external OnigDLL; function onig_region_new: POnigRegion; cdecl; external OnigDLL; procedure onig_region_free(region: POnigRegion; free_self: integer); cdecl; external OnigDLL; (* Oniguruma Native API *) function onig_new(var reg: Pregex_t; pattern, pattern_end: PUChar; option: OnigOptionType; enc: OnigEncoding; syntax: POnigSyntaxType; var einfo: OnigErrorInfo): integer; cdecl; external OnigDLL; procedure onig_free(reg: Pregex_t); cdecl; external OnigDLL; function onig_end: integer; cdecl; external OnigDLL; function onig_error_code_to_str(s: TErrorMessage; err_code: integer): integer; cdecl; external OnigDLL; varargs; (* default syntax *) //function OnigDefaultSyntax: POnigSyntaxType; cdecl; external OnigDLL; (* #define ONIG_ENCODING_ASCII (&OnigEncodingASCII) #define ONIG_ENCODING_ISO_8859_1 (&OnigEncodingISO_8859_1) #define ONIG_ENCODING_ISO_8859_2 (&OnigEncodingISO_8859_2) #define ONIG_ENCODING_ISO_8859_3 (&OnigEncodingISO_8859_3) #define ONIG_ENCODING_ISO_8859_4 (&OnigEncodingISO_8859_4) #define ONIG_ENCODING_ISO_8859_5 (&OnigEncodingISO_8859_5) #define ONIG_ENCODING_ISO_8859_6 (&OnigEncodingISO_8859_6) #define ONIG_ENCODING_ISO_8859_7 (&OnigEncodingISO_8859_7) #define ONIG_ENCODING_ISO_8859_8 (&OnigEncodingISO_8859_8) #define ONIG_ENCODING_ISO_8859_9 (&OnigEncodingISO_8859_9) #define ONIG_ENCODING_ISO_8859_10 (&OnigEncodingISO_8859_10) #define ONIG_ENCODING_ISO_8859_11 (&OnigEncodingISO_8859_11) #define ONIG_ENCODING_ISO_8859_13 (&OnigEncodingISO_8859_13) #define ONIG_ENCODING_ISO_8859_14 (&OnigEncodingISO_8859_14) #define ONIG_ENCODING_ISO_8859_15 (&OnigEncodingISO_8859_15) #define ONIG_ENCODING_ISO_8859_16 (&OnigEncodingISO_8859_16) #define ONIG_ENCODING_UTF8 (&OnigEncodingUTF8) #define ONIG_ENCODING_EUC_JP (&OnigEncodingEUC_JP) #define ONIG_ENCODING_EUC_TW (&OnigEncodingEUC_TW) #define ONIG_ENCODING_EUC_KR (&OnigEncodingEUC_KR) #define ONIG_ENCODING_EUC_CN (&OnigEncodingEUC_CN) #define ONIG_ENCODING_SJIS (&OnigEncodingSJIS) #define ONIG_ENCODING_KOI8 (&OnigEncodingKOI8) #define ONIG_ENCODING_KOI8_R (&OnigEncodingKOI8_R) #define ONIG_ENCODING_BIG5 (&OnigEncodingBIG5) *) implementation function GetProcAddr(Symbol: PChar): Pointer; {$IFDEF LINUX} var Handle: Pointer; begin Result := nil; Handle := dlopen(OnigDLL, RTLD_LAZY or RTLD_GLOBAL); if Handle = nil then Exit; Result := dlsym(Handle, Symbol); if Result = nil then dlclose(Handle); end; {$ENDIF} {$IFDEF MSWINDOWS} var Module: HMODULE; begin //Module := LoadLibrary(OnigDLL); Module := LoadLibraryExA(OnigDLL, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if Module = 0 then Halt; Result := GetProcAddress(Module, Symbol); if Result = nil then Halt; end; {$ENDIF} function GetInt(Symbol: PChar): integer; begin Result := integer(GetProcAddr(Symbol)^); end; procedure SetInt(Symbol: PChar; v: integer); begin integer(GetProcAddr(Symbol)^) := v; end; function ONIG_ENCODING_ASCII: Pointer; begin Result := GetProcAddr('OnigEncodingASCII'); end; function ONIG_ENCODING_UTF8: Pointer; begin Result := GetProcAddr('OnigEncodingUTF8'); end; function ONIG_ENCODING_EUC_JP: Pointer; begin Result := GetProcAddr('OnigEncodingEUC_JP'); end; function ONIG_ENCODING_SJIS: Pointer; begin Result := GetProcAddr('OnigEncodingSJIS'); end; function ONIG_SYNTAX_RUBY: Pointer; begin Result := GetProcAddr('OnigSyntaxRuby'); end; function ONIG_SYNTAX_DEFAULT: Pointer; begin Result := Pointer(GetProcAddr('OnigDefaultSyntax')^); end; initialization end.