initial implementation

This commit is contained in:
michael 1998-12-14 23:17:44 +00:00
parent 981e423a9e
commit 369feeff11
17 changed files with 372 additions and 0 deletions

53
docs/heapex/Makefile Normal file
View File

@ -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
docs/heapex/README Normal file
View File

@ -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
docs/heapex/foot.tex Normal file
View File

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

3
docs/heapex/head.tex Normal file
View File

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

26
docs/heapex/heapex.pp Normal file
View File

@ -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
docs/heapex/setinfo.pp Normal file
View File

@ -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
docs/objectex/Makefile Normal file
View File

@ -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
docs/objectex/README Normal file
View File

@ -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
docs/objectex/ex1.pp Normal file
View File

@ -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
docs/objectex/ex2.pp Normal file
View File

@ -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
docs/objectex/ex3.pp Normal file
View File

@ -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
docs/objectex/ex4.pp Normal file
View File

@ -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
docs/objectex/ex5.pp Normal file
View File

@ -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
docs/objectex/ex6.pp Normal file
View File

@ -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
docs/objectex/ex7.pp Normal file
View File

@ -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
docs/objectex/foot.tex Normal file
View File

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

3
docs/objectex/head.tex Normal file
View File

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