Ver Fonte

+ Implemented CompareXXXX examples

michael há 25 anos atrás
pai
commit
0ead4e14d1
7 ficheiros alterados com 276 adições e 1 exclusões
  1. 109 0
      docs/ref.tex
  2. 1 1
      docs/refex/Makefile
  3. 4 0
      docs/refex/README
  4. 54 0
      docs/refex/ex100.pp
  5. 36 0
      docs/refex/ex101.pp
  6. 36 0
      docs/refex/ex102.pp
  7. 36 0
      docs/refex/ex99.pp

+ 109 - 0
docs/ref.tex

@@ -5080,6 +5080,115 @@ None.
 
 \FPCexample{ex9}
 
+\begin{function}{CompareByte}
+\Declaration
+function CompareByte(var buf1,buf2;len:longint):longint;
+\Description
+\var{CompareByte} compares two memory regions \var{buf1},\var{buf2} on a 
+byte-per-byte basis for a total of \var{len} bytes. 
+
+The function returns one of the following values:
+\begin{description}
+\item[-1] if \var{buf1} and \var{buf2} contain different bytes
+in the first \var{len} bytes, and the first such byte is smaller in \var{buf1}
+than the byte at the same position in \var{buf2}.
+\item[0]  if the first \var{len} bytes in \var{buf1} and \var{buf2} are
+equal.
+\item [1] if \var{buf1} and \var{buf2} contain different bytes
+in the first \var{len} bytes, and the first such byte is larger in \var{buf1}
+than the byte at the same position in \var{buf2}.
+\end{description}
+\Errors
+None.
+\SeeAlso
+\seef{CompareChar},\seef{CompareWord},\seef{CompareDWord}
+\end{function}
+
+\FPCexample{ex99}
+
+\begin{function}{CompareChar}
+\Declaration
+function  CompareChar(var buf1,buf2;len:longint):longint;
+function  CompareChar0(var buf1,buf2;len:longint):longint;
+\Description
+\var{CompareChar} compares two memory regions \var{buf1},\var{buf2} on a 
+character-per-character basis for a total of \var{len} characters. 
+
+The \var{CompareChar0} variant compares \var{len} bytes, or until
+a zero character is found.
+
+The function returns one of the following values:
+\begin{description}
+\item[-1] if \var{buf1} and \var{buf2} contain different characters
+in the first \var{len} positions, and the first such character is smaller in \var{buf1}
+than the character at the same position in \var{buf2}.
+\item[0]  if the first \var{len} characters in \var{buf1} and \var{buf2} are
+equal.
+\item [1] if \var{buf1} and \var{buf2} contain different characters
+in the first \var{len} positions, and the first such character is larger in 
+\var{buf1} than the character at the same position in \var{buf2}.
+\end{description}
+
+\Errors
+None.
+\SeeAlso
+\seef{CompareByte},\seef{CompareWord},\seef{CompareDWord}
+\end{function}
+
+\FPCexample{ex100}
+
+\begin{function}{CompareDWord}
+\Declaration
+function  CompareDWord(var buf1,buf2;len:longint):longint;
+\Description
+\var{CompareDWord} compares two memory regions \var{buf1},\var{buf2} on a 
+DWord-per-DWord basis for a total of \var{len} DWords. (A DWord is 4 bytes).
+
+The function returns one of the following values:
+\begin{description}
+\item[-1] if \var{buf1} and \var{buf2} contain different DWords
+in the first \var{len} DWords, and the first such DWord is smaller in \var{buf1}
+than the DWord at the same position in \var{buf2}.
+\item[0]  if the first \var{len} DWords in \var{buf1} and \var{buf2} are
+equal.
+\item [1] if \var{buf1} and \var{buf2} contain different DWords
+in the first \var{len} DWords, and the first such DWord is larger in \var{buf1}
+than the DWord at the same position in \var{buf2}.
+\end{description}
+\Errors
+None.
+\SeeAlso
+\seef{CompareChar},\seef{CompareByte},\seef{CompareWord},
+\end{function}
+
+\FPCexample{ex101}
+
+\begin{function}{CompareWord}
+\Declaration
+function  CompareWord(var buf1,buf2;len:longint):longint;
+\Description
+\var{CompareWord} compares two memory regions \var{buf1},\var{buf2} on a 
+Word-per-Word basis for a total of \var{len} Words. (A Word is 2 bytes).
+
+The function returns one of the following values:
+\begin{description}
+\item[-1] if \var{buf1} and \var{buf2} contain different Words
+in the first \var{len} Words, and the first such Word is smaller in \var{buf1}
+than the Word at the same position in \var{buf2}.
+\item[0]  if the first \var{len} Words in \var{buf1} and \var{buf2} are
+equal.
+\item [1] if \var{buf1} and \var{buf2} contain different Words
+in the first \var{len} Words, and the first such Word is larger in \var{buf1}
+than the Word at the same position in \var{buf2}.
+\end{description}
+\Errors
+None.
+\SeeAlso
+\seef{CompareChar},\seef{CompareByte},\seef{CompareWord},
+\end{function}
+
+\FPCexample{ex102}
+
 \begin{function}{Concat}
 \Declaration
 Function Concat (S1,S2 [,S3, ... ,Sn]) : String;

+ 1 - 1
docs/refex/Makefile

@@ -39,7 +39,7 @@ OBJECTS=ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 ex10 ex11 ex12 ex13 ex14 \
         ex54 ex55 ex56 ex57 ex58 ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 \
         ex67 ex68 ex69 ex70 ex71 ex72 ex73 ex74 ex75 ex76 ex77 ex78 ex79 \
 	ex80 ex81 ex82 ex83 ex84 ex85 ex86 ex87 ex88 ex89 \
-	ex90 ex91 ex92 ex93 ex94 ex95 ex96 ex97 ex98
+	ex90 ex91 ex92 ex93 ex94 ex95 ex96 ex97 ex98 ex99 ex100 ex101 ex102
 
 TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
 

+ 4 - 0
docs/refex/README

@@ -101,3 +101,7 @@ ex95.pp contains an example of the SetResourceStrings function.
 ex96.pp contains an example of the Assigned function.
 ex97.pp contains an example of the StringOfChar function.
 ex98.pp contains an example of the exitproc function.
+ex99.pp contains an example of the CompareByte function.
+ex100.pp contains an example of the CompareChar function.
+ex101.pp contains an example of the CompareDWord function.
+ex102.pp contains an example of the CompareWord function.

+ 54 - 0
docs/refex/ex100.pp

@@ -0,0 +1,54 @@
+Program Example100;
+
+{ Program to demonstrate the CompareChar function. }
+
+Const 
+  ArraySize     = 100;
+  HalfArraySize = ArraySize Div 2;
+  
+Var 
+  Buf1,Buf2 : Array[1..ArraySize] of char;
+  I : longint;
+  
+  Procedure CheckPos(Len : Longint);
+  
+  Begin
+    Write('First ',Len,' characters are ');
+    if CompareChar(Buf1,Buf2,Len)<>0 then
+      Write('NOT ');
+    Writeln('equal');  
+  end;
+
+  Procedure CheckNullPos(Len : Longint);
+  
+  Begin
+    Write('First ',Len,' non-null characters are ');
+    if CompareChar0(Buf1,Buf2,Len)<>0 then
+      Write('NOT ');
+    Writeln('equal');  
+  end;
+
+begin
+  For I:=1 to ArraySize do
+    begin
+    Buf1[i]:=chr(I);
+    If I<=HalfArraySize Then
+      Buf2[I]:=chr(I)
+    else
+      Buf2[i]:=chr(HalfArraySize-I);
+    end; 
+  CheckPos(HalfArraySize div 2);
+  CheckPos(HalfArraySize);
+  CheckPos(HalfArraySize+1);
+  CheckPos(HalfArraySize + HalfArraySize Div 2);
+  For I:=1 to 4 do
+    begin
+    buf1[Random(ArraySize)+1]:=Chr(0);
+    buf2[Random(ArraySize)+1]:=Chr(0);
+    end;
+  Randomize;  
+  CheckNullPos(HalfArraySize div 2);
+  CheckNullPos(HalfArraySize);
+  CheckNullPos(HalfArraySize+1);
+  CheckNullPos(HalfArraySize + HalfArraySize Div 2);
+end.

+ 36 - 0
docs/refex/ex101.pp

@@ -0,0 +1,36 @@
+Program Example101;
+
+{ Program to demonstrate the CompareDWord function. }
+
+Const 
+  ArraySize     = 100;
+  HalfArraySize = ArraySize Div 2;
+  
+Var 
+  Buf1,Buf2 : Array[1..ArraySize] of Dword;
+  I : longint;
+  
+  Procedure CheckPos(Len : Longint);
+  
+  Begin
+    Write('First ',Len,' DWords are ');
+    if CompareDWord(Buf1,Buf2,Len)<>0 then
+      Write('NOT ');
+    Writeln('equal');  
+  end;
+
+
+begin
+  For I:=1 to ArraySize do
+    begin
+    Buf1[i]:=I;
+    If I<=HalfArraySize Then
+      Buf2[I]:=I
+    else
+      Buf2[i]:=HalfArraySize-I;
+    end; 
+  CheckPos(HalfArraySize div 2);
+  CheckPos(HalfArraySize);
+  CheckPos(HalfArraySize+1);
+  CheckPos(HalfArraySize + HalfArraySize Div 2);
+end.

+ 36 - 0
docs/refex/ex102.pp

@@ -0,0 +1,36 @@
+Program Example102;
+
+{ Program to demonstrate the CompareWord function. }
+
+Const 
+  ArraySize     = 100;
+  HalfArraySize = ArraySize Div 2;
+  
+Var 
+  Buf1,Buf2 : Array[1..ArraySize] of Word;
+  I : longint;
+  
+  Procedure CheckPos(Len : Longint);
+  
+  Begin
+    Write('First ',Len,' words are ');
+    if CompareWord(Buf1,Buf2,Len)<>0 then
+      Write('NOT ');
+    Writeln('equal');  
+  end;
+
+
+begin
+  For I:=1 to ArraySize do
+    begin
+    Buf1[i]:=I;
+    If I<=HalfArraySize Then
+      Buf2[I]:=I
+    else
+      Buf2[i]:=HalfArraySize-I;
+    end; 
+  CheckPos(HalfArraySize div 2);
+  CheckPos(HalfArraySize);
+  CheckPos(HalfArraySize+1);
+  CheckPos(HalfArraySize + HalfArraySize Div 2);
+end.

+ 36 - 0
docs/refex/ex99.pp

@@ -0,0 +1,36 @@
+Program Example99;
+
+{ Program to demonstrate the CompareByte function. }
+
+Const 
+  ArraySize     = 100;
+  HalfArraySize = ArraySize Div 2;
+  
+Var 
+  Buf1,Buf2 : Array[1..ArraySize] of byte;
+  I : longint;
+  
+  Procedure CheckPos(Len : Longint);
+  
+  Begin
+    Write('First ',Len,' positions are ');
+    if CompareByte(Buf1,Buf2,Len)<>0 then
+      Write('NOT ');
+    Writeln('equal');  
+  end;
+
+
+begin
+  For I:=1 to ArraySize do
+    begin
+    Buf1[i]:=I;
+    If I<=HalfArraySize Then
+      Buf2[I]:=I
+    else
+      Buf2[i]:=HalfArraySize-I;
+    end; 
+  CheckPos(HalfArraySize div 2);
+  CheckPos(HalfArraySize);
+  CheckPos(HalfArraySize+1);
+  CheckPos(HalfArraySize + HalfArraySize Div 2);
+end.