📄 pcre.pas
字号:
PCREStudyExportName = 'pcre_study';
PCREVersionExportName = 'pcre_version';
PCREMallocExportName = 'pcre_malloc';
PCREFreeExportName = 'pcre_free';
PCREStackMallocExportName = 'pcre_stack_malloc';
PCREStackFreeExportName = 'pcre_stack_free';
PCRECalloutExportName = 'pcre_callout';
INVALID_MODULEHANDLE_VALUE = TModuleHandle(0);
var
PCRELib: TModuleHandle = INVALID_MODULEHANDLE_VALUE;
{$ENDIF ~PCRE_STATICLINK}
procedure SetPCREMallocCallback(const Value: pcre_malloc_callback);
begin
{$IFDEF PCRE_STATICLINK}
pcre_malloc_user := Value;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_malloc_func) then
LoadPCRE;
if Assigned(pcre_malloc_func) then
pcre_malloc_func^ := Value
else if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
{$ENDIF ~PCRE_STATICLINK}
end;
function GetPCREMallocCallback: pcre_malloc_callback;
begin
{$IFDEF PCRE_STATICLINK}
Result := pcre_malloc_user;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_malloc_func) then
LoadPCRE;
if not Assigned(pcre_malloc_func) then
begin
Result := nil;
if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
end
else
Result := pcre_malloc_func^;
{$ENDIF ~PCRE_STATICLINK}
end;
function CallPCREMalloc(Size: Integer): Pointer;
begin
{$IFDEF PCRE_STATICLINK}
Result := pcre_malloc(Size);
{$ELSE ~PCRE_STATICLINK}
Result := pcre_malloc_func^(Size);
{$ENDIF ~PCRE_STATICLINK}
end;
procedure SetPCREFreeCallback(const Value: pcre_free_callback);
begin
{$IFDEF PCRE_STATICLINK}
pcre_free_user := Value;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_free_func) then
LoadPCRE;
if Assigned(pcre_free_func) then
pcre_free_func^ := Value
else if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
{$ENDIF ~PCRE_STATICLINK}
end;
function GetPCREFreeCallback: pcre_free_callback;
begin
{$IFDEF PCRE_STATICLINK}
Result := pcre_free_user;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_free_func) then
LoadPCRE;
if not Assigned(pcre_free_func) then
begin
Result := nil;
if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
end
else
Result := pcre_free_func^
{$ENDIF ~PCRE_STATICLINK}
end;
procedure CallPCREFree(P: Pointer);
begin
{$IFDEF PCRE_STATICLINK}
pcre_free(P);
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_free_func) then
LoadPCRE;
pcre_free_func^(P);
{$ENDIF ~PCRE_STATICLINK}
end;
procedure SetPCREStackMallocCallback(const Value: pcre_stack_malloc_callback);
begin
{$IFDEF PCRE_STATICLINK}
pcre_stack_malloc_user := Value;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_stack_malloc_func) then
LoadPCRE;
if Assigned(pcre_stack_malloc_func) then
pcre_stack_malloc_func^ := Value
else if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
{$ENDIF ~PCRE_STATICLINK}
end;
function GetPCREStackMallocCallback: pcre_stack_malloc_callback;
begin
{$IFDEF PCRE_STATICLINK}
Result := pcre_stack_malloc_user;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_stack_malloc_func) then
LoadPCRE;
if not Assigned(pcre_stack_malloc_func) then
begin
Result := nil;
if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
end
else
Result := pcre_stack_malloc_func^;
{$ENDIF ~PCRE_STATICLINK}
end;
function CallPCREStackMalloc(Size: Integer): Pointer;
begin
{$IFDEF PCRE_STATICLINK}
Result := pcre_stack_malloc(Size);
{$ELSE ~PCRE_STATICLINK}
Result := pcre_stack_malloc_func^(Size);
{$ENDIF ~PCRE_STATICLINK}
end;
procedure SetPCREStackFreeCallback(const Value: pcre_stack_free_callback);
begin
{$IFDEF PCRE_STATICLINK}
pcre_stack_free_user := Value;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_stack_free_func) then
LoadPCRE;
if Assigned(pcre_stack_free_func) then
pcre_stack_free_func^ := Value
else if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
{$ENDIF ~PCRE_STATICLINK}
end;
function GetPCREStackFreeCallback: pcre_stack_free_callback;
begin
{$IFDEF PCRE_STATICLINK}
Result := pcre_stack_free_user;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_stack_free_func) then
LoadPCRE;
if not Assigned(pcre_stack_free_func) then
begin
Result := nil;
if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
end
else
Result := pcre_stack_free_func^;
{$ENDIF ~PCRE_STATICLINK}
end;
procedure CallPCREStackFree(P: Pointer);
begin
{$IFDEF PCRE_STATICLINK}
pcre_stack_free(P);
{$ELSE ~PCRE_STATICLINK}
pcre_stack_free_func^(P);
{$ENDIF ~PCRE_STATICLINK}
end;
procedure SetPCRECalloutCallback(const Value: pcre_callout_callback);
begin
{$IFDEF PCRE_STATICLINK}
pcre_callout_user := Value;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_callout_func) then
LoadPCRE;
if Assigned(pcre_callout_func) then
pcre_callout_func^ := Value
else if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
{$ENDIF ~PCRE_STATICLINK}
end;
function GetPCRECalloutCallback: pcre_callout_callback;
begin
{$IFDEF PCRE_STATICLINK}
Result := pcre_callout_user;
{$ELSE ~PCRE_STATICLINK}
if not Assigned(pcre_callout_func) then
LoadPCRE;
if not Assigned(pcre_callout_func) then
begin
Result := nil;
if Assigned(LibNotLoadedHandler) then
LibNotLoadedHandler;
end
else
Result := pcre_callout_func^;
{$ENDIF ~PCRE_STATICLINK}
end;
function CallPCRECallout(var callout_block: pcre_callout_block): Integer;
begin
{$IFDEF PCRE_STATICLINK}
Result := pcre_callout(callout_block);
{$ELSE ~PCRE_STATICLINK}
Result := pcre_callout_func^(callout_block);
{$ENDIF ~PCRE_STATICLINK}
end;
{$IFNDEF PCRE_STATICLINK}
procedure InitPCREFuncPtrs(const Value: Pointer);
begin
{$IFDEF PCRE_LINKONREQUEST}
@pcre_compile := Value;
@pcre_compile2 := Value;
@pcre_config := Value;
@pcre_copy_named_substring := Value;
@pcre_copy_substring := Value;
@pcre_dfa_exec := Value;
@pcre_exec := Value;
@pcre_free_substring := Value;
@pcre_free_substring_list := Value;
@pcre_fullinfo := Value;
@pcre_get_named_substring := Value;
@pcre_get_stringnumber := Value;
@pcre_get_stringtable_entries := Value;
@pcre_get_substring := Value;
@pcre_get_substring_list := Value;
@pcre_info := Value;
@pcre_maketables := Value;
@pcre_refcount := Value;
@pcre_study := Value;
@pcre_version := Value;
{$ENDIF PCRE_LINKONREQUEST}
pcre_malloc_func := nil;
pcre_free_func := nil;
pcre_stack_malloc_func := nil;
pcre_stack_free_func := nil;
pcre_callout_func := nil;
end;
{$ENDIF ~PCRE_STATICLINK}
function IsPCRELoaded: Boolean;
begin
{$IFDEF PCRE_STATICLINK}
Result := True;
{$ELSE ~PCRE_STATICLINK}
Result := PCRELib <> INVALID_MODULEHANDLE_VALUE;
{$ENDIF ~PCRE_STATICLINK}
end;
function LoadPCRE: Boolean;
{$IFDEF PCRE_STATICLINK}
begin
Result := True;
end;
{$ELSE ~PCRE_STATICLINK}
function GetSymbol(SymbolName: PChar): Pointer;
begin
{$IFDEF MSWINDOWS}
Result := GetProcAddress(PCRELib, PChar(SymbolName));
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
Result := dlsym(PCRELib, PChar(SymbolName));
{$ENDIF UNIX}
end;
begin
Result := PCRELib <> INVALID_MODULEHANDLE_VALUE;
if Result then
Exit;
if PCRELib = INVALID_MODULEHANDLE_VALUE then
{$IFDEF MSWINDOWS}
PCRELib := SafeLoadLibrary(libpcremodulename);
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
PCRELib := dlopen(PChar(libpcremodulename), RTLD_NOW);
{$ENDIF UNIX}
Result := PCRELib <> INVALID_MODULEHANDLE_VALUE;
if Result then
begin
{$IFDEF PCRE_LINKONREQUEST}
@pcre_compile := GetSymbol(PCRECompileExportName);
@pcre_compile2 := GetSymbol(PCRECompile2ExportName);
@pcre_config := GetSymbol(PCREConfigExportName);
@pcre_copy_named_substring := GetSymbol(PCRECopyNamedSubstringExportName);
@pcre_copy_substring := GetSymbol(PCRECopySubStringExportName);
@pcre_dfa_exec := GetSymbol(PCREDfaExecExportName);
@pcre_exec := GetSymbol(PCREExecExportName);
@pcre_free_substring := GetSymbol(PCREFreeSubStringExportName);
@pcre_free_substring_list := GetSymbol(PCREFreeSubStringListExportName);
@pcre_fullinfo := GetSymbol(PCREFullInfoExportName);
@pcre_get_named_substring := GetSymbol(PCREGetNamedSubstringExportName);
@pcre_get_stringnumber := GetSymbol(PCREGetStringNumberExportName);
@pcre_get_stringtable_entries := GetSymbol(PCREGetStringTableEntriesExportName);
@pcre_get_substring := GetSymbol(PCREGetSubStringExportName);
@pcre_get_substring_list := GetSymbol(PCREGetSubStringListExportName);
@pcre_info := GetSymbol(PCREInfoExportName);
@pcre_maketables := GetSymbol(PCREMakeTablesExportName);
@pcre_refcount := GetSymbol(PCRERefCountExportName);
@pcre_study := GetSymbol(PCREStudyExportName);
@pcre_version := GetSymbol(PCREVersionExportName);
{$ENDIF PCRE_LINKONREQUEST}
pcre_malloc_func := GetSymbol(PCREMallocExportName);
pcre_free_func := GetSymbol(PCREFreeExportName);
pcre_stack_malloc_func := GetSymbol(PCREStackMallocExportName);
pcre_stack_free_func := GetSymbol(PCREStackFreeExportName);
pcre_callout_func := GetSymbol(PCRECalloutExportName);
end
else
InitPCREFuncPtrs(@LibNotLoadedHandler);
end;
{$ENDIF ~PCRE_STATICLINK}
procedure UnloadPCRE;
begin
{$IFNDEF PCRE_STATICLINK}
if PCRELib <> INVALID_MODULEHANDLE_VALUE then
{$IFDEF MSWINDOWS}
FreeLibrary(PCRELib);
{$ENDIF MSWINDOWS}
{$IFDEF UNIX}
dlclose(Pointer(PCRELib));
{$ENDIF UNIX}
PCRELib := INVALID_MODULEHANDLE_VALUE;
InitPCREFuncPtrs(@LibNotLoadedHandler);
{$ENDIF ~PCRE_STATICLINK}
end;
{$IFDEF PCRE_LINKDLL}
function pcre_compile; external libpcremodulename name PCRECompileExportName;
function pcre_compile2; external libpcremodulename name PCRECompile2ExportName;
function pcre_config; external libpcremodulename name PCREConfigExportName;
function pcre_copy_named_substring; external libpcremodulename name PCRECopyNamedSubStringExportName;
function pcre_copy_substring; external libpcremodulename name PCRECopySubStringExportName;
function pcre_dfa_exec; external libpcremodulename name PCREDfaExecExportName;
function pcre_exec; external libpcremodulename name PCREExecExportName;
procedure pcre_free_substring; external libpcremodulename name PCREFreeSubStringExportName;
procedure pcre_free_substring_list; external libpcremodulename name PCREFreeSubStringListExportName;
function pcre_fullinfo; external libpcremodulename name PCREFullInfoExportName;
function pcre_get_named_substring; external libpcremodulename name PCREGetNamedSubStringExportName;
function pcre_get_stringnumber; external libpcremodulename name PCREGetStringNumberExportName;
function pcre_get_stringtable_entries; external libpcremodulename name PCREGetStringTableEntriesExportName;
function pcre_get_substring; external libpcremodulename name PCREGetSubStringExportName;
function pcre_get_substring_list; external libpcremodulename name PCREGetSubStringListExportName;
function pcre_info; external libpcremodulename name PCREInfoExportName;
function pcre_maketables; external libpcremodulename name PCREMakeTablesExportName;
function pcre_refcount; external libpcremodulename name PCRERefCountExportName;
function pcre_study; external libpcremodulename name PCREStudyExportName;
function pcre_version; external libpcremodulename name PCREVersionExportName;
{$ENDIF PCRE_LINKDLL}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -