瀏覽代碼

initial implementation

michael 27 年之前
父節點
當前提交
369feeff11

+ 53 - 0
docs/heapex/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=heapex setinfo
+
+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/heapex/README

@@ -0,0 +1,6 @@
+These are the example programs that appear in the FPC documentation.
+ 
+Units guide, chapter on heaptrc unit :
+
+heapex.pp contains an example of how to use the heaptrc unit.
+setinfo.pp contains an example of how to use the set_extra_info function.

+ 2 - 0
docs/heapex/foot.tex

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

+ 3 - 0
docs/heapex/head.tex

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

+ 26 - 0
docs/heapex/heapex.pp

@@ -0,0 +1,26 @@
+Program heapex;
+
+{ Program used to demonstrate the usage of heaptrc unit }
+
+Uses heaptrc;
+
+Var P1 : ^Longint;
+    P2 : Pointer;
+    I : longint;
+        
+begin
+  New(P1);
+  // causes previous allocation not to be de-allocated
+  New(P1);
+  Dispose(P1);
+  For I:=1 to 10 do
+    begin
+    GetMem (P2,128);
+    // When I is even, deallocate block. We loose 5 times 128
+    // bytes this way.
+    If (I mod 2) = 0 Then FreeMem(P2,128);
+    end;  
+  GetMem(P2,128);
+  // This will provoke an error and a memory dump
+  Freemem (P2,64);
+end.

+ 58 - 0
docs/heapex/setinfo.pp

@@ -0,0 +1,58 @@
+Program heapex;
+
+{ Program used to demonstrate the usage of heaptrc unit }
+
+Uses heaptrc;
+
+Var P1 : ^Longint;
+    P2 : Pointer;
+    I : longint;
+    Marker : Longint; 
+ 
+Procedure SetMarker (P : pointer);
+
+Type PLongint = ^Longint;
+
+begin
+  PLongint(P)^:=Marker;
+end; 
+    
+Procedure  Part1;
+        
+begin
+  // Blocks allocated here are marked with $FFAAFFAA = -5570646
+  Marker := $FFAAFFAA;
+  New(P1);
+  New(P1);
+  Dispose(P1);
+  For I:=1 to 10 do
+    begin
+    GetMem (P2,128);
+    If (I mod 2) = 0 Then FreeMem(P2,128);
+    end;  
+  GetMem(P2,128);
+end;
+
+Procedure  Part2;
+        
+begin
+  // Blocks allocated here are marked with $FAFAFAFA = -84215046
+  Marker := $FAFAFAFA;
+  New(P1);
+  New(P1);
+  Dispose(P1);
+  For I:=1 to 10 do
+    begin
+    GetMem (P2,128);
+    If (I mod 2) = 0 Then FreeMem(P2,128);
+    end;  
+  GetMem(P2,128);
+end;
+
+begin
+ set_extra_info(SizeOf(Marker),@SetMarker);
+ Writeln ('Part 1');
+ part1;
+ Writeln('Part 2');
+ part2;
+end.

+ 53 - 0
docs/objectex/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=ex1 ex2 ex3 ex4 ex5 ex6 ex7
+
+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) $*

+ 5 - 0
docs/objectex/README

@@ -0,0 +1,5 @@
+These are the example programs that appear in the FPC documentation.
+ 
+Units guide, chapter on Printer unit :
+
+printex.pp contains an example of the AssignLst function.

+ 43 - 0
docs/objectex/ex1.pp

@@ -0,0 +1,43 @@
+Program ex1;
+
+{ Program to demonstrate TRect.Empty }
+
+Uses objects;
+
+
+Var ARect,BRect : TRect;
+    P : TPoint;
+    
+begin
+  With ARect.A do
+    begin
+    X:=10;
+    Y:=10;
+    end;
+  With ARect.B do
+    begin
+    X:=20;
+    Y:=20;
+    end;
+  { Offset B by (5,5) }
+  With BRect.A do
+    begin
+    X:=15;
+    Y:=15;
+    end;
+  With BRect.B do
+    begin
+    X:=25;
+    Y:=25;
+    end;
+  { Point }
+  With P do
+    begin
+    X:=15;
+    Y:=15;
+    end;
+  Writeln ('A empty : ',ARect.Empty);
+  Writeln ('B empty : ',BRect.Empty);
+  Writeln ('A Equals B : ',ARect.Equals(BRect));
+  Writeln ('A Contains (15,15) : ',ARect.Contains(P));
+end.

+ 17 - 0
docs/objectex/ex2.pp

@@ -0,0 +1,17 @@
+Program ex2;
+
+{ Program to demonstrate TRect.Copy }
+
+Uses objects;
+
+Var ARect,BRect,CRect : TRect;
+    
+begin
+  ARect.Assign(10,10,20,20);
+  BRect.Assign(15,15,25,25);
+  CRect.Copy(ARect);
+  If ARect.Equals(CRect) Then
+    Writeln ('ARect equals CRect')
+  Else
+    Writeln ('ARect does not equal CRect !');
+end.

+ 21 - 0
docs/objectex/ex3.pp

@@ -0,0 +1,21 @@
+Program ex3;
+
+{ Program to demonstrate TRect.Union }
+
+Uses objects;
+
+
+Var ARect,BRect,CRect : TRect;
+    
+begin
+  ARect.Assign(10,10,20,20);
+  BRect.Assign(15,15,25,25);
+  { CRect is union of ARect and BRect }
+  CRect.Assign(10,10,25,25);
+  { Calculate it explicitly}
+  ARect.Union(BRect);
+  If ARect.Equals(CRect) Then
+    Writeln ('ARect equals CRect')
+  Else
+    Writeln ('ARect does not equal CRect !');
+end.

+ 25 - 0
docs/objectex/ex4.pp

@@ -0,0 +1,25 @@
+Program ex4;
+
+{ Program to demonstrate TRect.Intersect }
+
+Uses objects;
+
+
+Var ARect,BRect,CRect : TRect;
+    
+begin
+  ARect.Assign(10,10,20,20);
+  BRect.Assign(15,15,25,25);
+  { CRect is intersection of ARect and BRect }
+  CRect.Assign(15,15,20,20);
+  { Calculate it explicitly}
+  ARect.Intersect(BRect);
+  If ARect.Equals(CRect) Then
+    Writeln ('ARect equals CRect')
+  Else
+    Writeln ('ARect does not equal CRect !');
+  BRect.Assign(25,25,30,30);
+  Arect.Intersect(BRect);
+  If ARect.Empty Then
+    Writeln ('ARect is empty');
+end.

+ 19 - 0
docs/objectex/ex5.pp

@@ -0,0 +1,19 @@
+Program ex5;
+
+{ Program to demonstrate TRect.Move }
+
+Uses objects;
+
+
+Var ARect,BRect : TRect;
+    
+begin
+  ARect.Assign(10,10,20,20);
+  ARect.Move(5,5);
+  // Brect should be where new ARect is.
+  BRect.Assign(15,15,25,25);
+  If ARect.Equals(BRect) Then
+    Writeln ('ARect equals BRect')
+  Else
+    Writeln ('ARect does not equal BRect !');
+end.

+ 19 - 0
docs/objectex/ex6.pp

@@ -0,0 +1,19 @@
+Program ex6;
+
+{ Program to demonstrate TRect.Grow }
+
+Uses objects;
+
+
+Var ARect,BRect : TRect;
+    
+begin
+  ARect.Assign(10,10,20,20);
+  ARect.Grow(5,5);
+  // Brect should be where new ARect is.
+  BRect.Assign(5,5,25,25);
+  If ARect.Equals(BRect) Then
+    Writeln ('ARect equals BRect')
+  Else
+    Writeln ('ARect does not equal BRect !');
+end.

+ 17 - 0
docs/objectex/ex7.pp

@@ -0,0 +1,17 @@
+program ex7;
+
+{ Program to demonstrate the TObject.Free call }
+
+Uses Objects;
+
+Var O : PObject;
+
+begin
+  Writeln ('Memavail : ',Memavail);
+  // Allocate memory for object.
+  O:=New(PObject,Init);
+  Writeln ('Memavail : ',Memavail);
+  // Free memory of object.
+  O^.free;
+  Writeln ('Memavail : ',Memavail);
+end.

+ 2 - 0
docs/objectex/foot.tex

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

+ 3 - 0
docs/objectex/head.tex

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