+ Initial implementation

This commit is contained in:
michael 2000-06-14 21:09:21 +00:00
parent 59ba2f82cf
commit 984784374a
5 changed files with 100 additions and 0 deletions

15
docs/progex/ctest.c Normal file
View File

@ -0,0 +1,15 @@
#include <string.h>
extern char* SubStr(const char*, int, int);
int main()
{
char *s;
int FromPos, ToPos;
s = strdup("Test");
FromPos = 2;
ToPos = 3;
printf("Result from SubStr: '%s'\n", SubStr(s, FromPos, ToPos));
return 0;
}

23
docs/progex/ctest2.c Normal file
View File

@ -0,0 +1,23 @@
#include <dlfcn.h>
#include <string.h>
int main()
{
void *lib;
char *s;
int FromPos, ToPos;
char* (*SubStr)(const char*, int*, int*);
printf("arh %d\n",RTLD_LAZY);
lib = dlopen("./libcaseudf.so", RTLD_LAZY);
printf("Result from dlopen (library handle): 0x%08x\n", lib);
SubStr = dlsym(lib, "SUBSTR");
printf("Address of SubStr = 0x%08x, last error code = %i\n",
SubStr, dlerror());
s = strdup("Test");
FromPos = 2;
ToPos = 3;
printf("Result from SubStr: '%s'\n", (*SubStr)(s, &FromPos, &ToPos));
dlclose(lib);
return 0;
}

24
docs/progex/plsubs.pp Normal file
View File

@ -0,0 +1,24 @@
program testsubs;
Type
TSubStrFunc = function (const CString: PChar; FromPos, ToPos: longint): PChar; cdecl;
Function dlopen(name : pchar; mode : longint) : pointer; cdecl; external 'dl';
Function dlsym(lib : pointer; name : pchar) : pointer; cdecl;external 'dl';
Function dlclose(lib : pointer) : longint; cdecl; external 'dl';
var
s: PChar;
FromPos, ToPos: Integer;
lib : pointer;
SubStr : TSubStrFunc;
begin
s := 'Test';
FromPos := 2;
ToPos := 3;
lib:=dlopen('libsubs.so',1);
Pointer(Substr):=dlsym(lib,'SubStr');
WriteLn(SubStr(s, FromPos, ToPos));
dlclose(lib);
end.

14
docs/progex/psubs.pp Normal file
View File

@ -0,0 +1,14 @@
program testsubs;
function SubStr(const CString: PChar; FromPos, ToPos: longint): PChar;
cdecl; external 'subs';
var
s: PChar;
FromPos, ToPos: Integer;
begin
s := 'Test';
FromPos := 2;
ToPos := 3;
WriteLn(SubStr(s, FromPos, ToPos));
end.

24
docs/progex/subs.pp Normal file
View File

@ -0,0 +1,24 @@
{
Example library
}
library subs;
function SubStr(CString: PChar; FromPos, ToPos: Longint): PChar; cdecl; export;
var
Length: Integer;
begin
Length := StrLen(CString);
SubStr := CString + Length;
if (FromPos > 0) and (ToPos >= FromPos) then
begin
if Length >= FromPos then
SubStr := CString + FromPos - 1;
if Length > ToPos then
CString[ToPos] := #0;
end;
end;
exports
SubStr;
end.