Browse Source

+ Initial implementation

michael 25 years ago
parent
commit
8592278ad0
6 changed files with 114 additions and 0 deletions
  1. 53 0
      docs/dynlibex/Makefile
  2. 6 0
      docs/dynlibex/README
  3. 2 0
      docs/dynlibex/foot.tex
  4. 3 0
      docs/dynlibex/head.tex
  5. 23 0
      docs/dynlibex/plsubs.pp
  6. 27 0
      docs/dynlibex/subs.pp

+ 53 - 0
docs/dynlibex/Makefile

@@ -0,0 +1,53 @@
+#######################################################################
+#
+# Makefile to compile all examples and convert them to LaTeX
+# 
+#######################################################################
+
+# Compiler
+PP=ppc386
+
+# Unit directory
+# UNITDIR=/usr/lib/ppc/0.99.0/linuxunits
+
+
+# Any options you wish to pass.
+PPOPTS=
+
+# Script to convert the programs to LaTeX examples which can be included.
+PP2TEX=../pp2tex
+
+# Script to collect all examples in 1 file.
+MAKETEX=make1tex
+
+#######################################################################
+# No need to edit after this line.
+#######################################################################
+
+ifdef UNITDIR
+PPOPTS:=$(PPOPTS) -Up$(UNITDIR);
+endif
+
+.SUFFIXES: .pp .tex
+
+.PHONY: all tex clean
+
+OBJECTS=plsubs subs
+
+TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
+
+all : $(OBJECTS)
+
+tex : $(TEXOBJECTS)
+
+onetex : tex
+	$(MAKETEX) $(TEXOBJECTS)
+
+clean : 
+	rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS)
+ 
+$(OBJECTS): %: %.pp
+	$(PP) $(PPOPTS) $*
+
+$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
+	$(PP2TEX) $*

+ 6 - 0
docs/dynlibex/README

@@ -0,0 +1,6 @@
+These are the example programs that appear in the FPC documentation.
+ 
+Units guide, chapter on dynlibs unit :
+
+subs.pp   : library used in dynlibs function.
+plsubs.pp : example to show loading of libraries.

+ 2 - 0
docs/dynlibex/foot.tex

@@ -0,0 +1,2 @@
+\end{verbatim}
+\end{FPCList}

+ 3 - 0
docs/dynlibex/head.tex

@@ -0,0 +1,3 @@
+\begin{FPCList}
+\item[Example]
+\begin{verbatim}

+ 23 - 0
docs/dynlibex/plsubs.pp

@@ -0,0 +1,23 @@
+program testsubs;
+
+uses dynlibs;
+
+Type
+  TSubStrFunc = 
+    function(const CString:PChar;FromPos,ToPos: longint):PChar;cdecl;
+
+var
+  s: PChar;
+  FromPos, ToPos: Integer;
+  lib : TLibHandle;
+  SubStr : TSubStrFunc;
+  
+begin
+  s := 'Test';
+  FromPos := 2;
+  ToPos := 3;
+  lib:=LoadLibrary('libsubs.so');
+  Pointer(Substr):=GetProcedureAddress(lib,'SubStr');
+  WriteLn(SubStr(s, FromPos, ToPos));
+  UnLoadLibrary(lib);
+end.

+ 27 - 0
docs/dynlibex/subs.pp

@@ -0,0 +1,27 @@
+{
+  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.