2
0
peter 25 жил өмнө
parent
commit
ec95ce1f48
6 өөрчлөгдсөн 110 нэмэгдсэн , 45 устгасан
  1. 1 0
      docs/linuxex/README
  2. 71 0
      docs/linuxex/ex71.pp
  3. 7 8
      docs/prog.tex
  4. 17 17
      docs/ref.tex
  5. 13 20
      docs/units.tex
  6. 1 0
      docs/user.tex

+ 1 - 0
docs/linuxex/README

@@ -71,4 +71,5 @@ ex67.pp contains an example of the FSplit function.
 ex68.pp contains an example of the Octal function.
 ex69.pp contains an example of the FNMatch function.
 ex70.pp contains an example of the StringToPPchar function.
+ex71.pp contains an example of the clone function.
 serial.pp contains an example of serial port programming in FPC.

+ 71 - 0
docs/linuxex/ex71.pp

@@ -0,0 +1,71 @@
+program TestC{lone};
+
+uses
+  Linux, Errors, crt;
+
+const
+  Ready : Boolean = false;
+  aChar : Char    = 'a';
+
+function CloneProc( Arg: Pointer ): LongInt; Cdecl;
+begin
+  WriteLn('Hello from the clone ',PChar(Arg));
+  repeat
+    Write(aChar);
+    Select(0,0,0,0,600);
+  until Ready;
+  WriteLn( 'Clone finished.');
+  CloneProc := 1;
+end;
+
+var
+  PID : LongInt;
+
+procedure MainProc;
+begin
+  WriteLn('cloned process PID: ', PID );
+  WriteLn('Press <ESC> to kill ... ' );
+  repeat
+    Write('.');
+    Select(0,0,0,0,300);
+    if KeyPressed then
+      case ReadKey of
+        #27: Ready := true;
+	'a': aChar := 'A';
+	'A': aChar := 'a';
+	'b': aChar := 'b';
+	'B': aChar := 'B';
+      end;	
+  until Ready;
+  WriteLn('Ready.');
+end;
+
+const
+  StackSze = 16384;
+  theFlags = CLONE_VM+CLONE_FS+CLONE_FILES+CLONE_SIGHAND;
+  aMsg     : PChar = 'Oops !';
+
+var
+  theStack : Pointer;
+  ExitStat : LongInt;
+
+begin
+  GetMem(theStack,StackSze);
+  PID := Clone(@CloneProc,
+               Pointer( LongInt(theStack)+StackSze),
+               theFlags,
+               aMsg);
+  if PID < 0 then
+    WriteLn('Error : ', LinuxError, ' when cloning.')
+  else 
+    begin
+    MainProc;
+    case WaitPID(0,@ExitStat,Wait_Untraced or wait_clone) of
+      -1: WriteLn('error:',LinuxError,'; ',StrError(LinuxError));
+       0: WriteLn('error:',LinuxError,'; ',StrError(LinuxError));
+    else 
+      WriteLn('Clone exited with: ',ExitStat shr 8);
+    end;
+    end;
+  FreeMem( theStack, StackSze );
+end.

+ 7 - 8
docs/prog.tex

@@ -19,7 +19,7 @@
 %   Boston, MA 02111-1307, USA.
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Preamble. 
+% Preamble.
 % Uncomment the one you need here. The book version is for the published
 % book version.
 \documentclass{report}
@@ -32,14 +32,13 @@
   \usepackage{html}
   \usepackage{htmllist}
   \latex{\usepackage{fpc}}
+  \html{\input{fpc-html.tex}}
 \else
+  % Uncomment the fpc or fpcbook version, depending on the output format
+  % you want.
   \usepackage{fpc}
+  %\usepackage{fpcbook}
 \fi
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Uncomment the fpc or fpcbook version, depending on the output format 
-% you want.
-%\usepackage{fpc}
-%\usepackage{fpcbook}
 \latex{%
   \ifpdf
   \pdfinfo{/Author(Michael Van Canneyt)
@@ -47,7 +46,7 @@
            /Subject(Free Pascal Programmers' guide)
            /Keywords(Free Pascal)
            }
-\fi
+  \fi
 }
 %
 % Settings
@@ -3049,7 +3048,7 @@ of your program.  This returns zero in the \fpc implementation of the
 system unit, since both code and data are in the same memory space.
 \item [Ptr:] Accepted a segment and offset from an address, and would return
 a pointer to this address. This has been changed in the run-time library, it
-now simply returns the offset. 
+now simply returns the offset.
 \item [memw and mem] These arrays gave access to the \dos memory. \fpc
 supports them on the go32v2 platform, they are mapped into \dos memory
 space. You need the \var{GO32} unit for this. On other platforms, they are

+ 17 - 17
docs/ref.tex

@@ -19,7 +19,7 @@
 %   Boston, MA 02111-1307, USA.
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Preamble. 
+% Preamble.
 % Uncomment the one you need here. The book version is for the published
 % book version.
 %\documentclass{report}
@@ -31,12 +31,12 @@
   \usepackage{html}
   \usepackage{htmllist}
   \latex{\usepackage{fpc}}
+  \html{\input{fpc-html.tex}}
 \else
-b%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Uncomment the fpc or fpcbook version, depending on the output format 
+% Uncomment the fpc or fpcbook version, depending on the output format
 % you want.
   \usepackage{fpc}
-  \usepackage{fpcbook}
+%  \usepackage{fpcbook}
 \fi
 \latex{%
   \ifpdf
@@ -5096,8 +5096,8 @@ None.
 \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. 
+\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}
@@ -5123,8 +5123,8 @@ None.
 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. 
+\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.
@@ -5137,7 +5137,7 @@ 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 
+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}
 
@@ -5153,7 +5153,7 @@ None.
 \Declaration
 function  CompareDWord(var buf1,buf2;len:longint):longint;
 \Description
-\var{CompareDWord} compares two memory regions \var{buf1},\var{buf2} on a 
+\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:
@@ -5179,7 +5179,7 @@ None.
 \Declaration
 function  CompareWord(var buf1,buf2;len:longint):longint;
 \Description
-\var{CompareWord} compares two memory regions \var{buf1},\var{buf2} on a 
+\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:
@@ -5485,8 +5485,8 @@ with value equal to \var{Value}.
 
 This is useful for quickly zeroing out a memory location. If you know
 that the size of the memory location to be filled out is a multiple of
-2 bytes, it is better to use \seep{Fillword}, and if it is a multiple 
-of 4 bytes it's better to use \seep{FillDWord}, these routines are 
+2 bytes, it is better to use \seep{Fillword}, and if it is a multiple
+of 4 bytes it's better to use \seep{FillDWord}, these routines are
 optimized for their respective sizes.
 
 \Errors
@@ -5726,7 +5726,7 @@ error, if you try to increase \var{X} over its maximum value.
 
 \begin{function}{IndexByte}
 \Declaration
-function  IndexByte(var buf;len:longint;b:byte):longint;  
+function  IndexByte(var buf;len:longint;b:byte):longint;
 \Description
 \var{IndexByte} searches the memory at \var{buf} for maximally \var{len}
 positions for the byte \var{b} and returns it's position if it found one.
@@ -5743,8 +5743,8 @@ The position is zero-based.
 
 \begin{function}{IndexChar}
 \Declaration
-function  IndexChar(var buf;len:longint;b:char):longint;  
-function  IndexChar0(var buf;len:longint;b:char):longint;  
+function  IndexChar(var buf;len:longint;b:char):longint;
+function  IndexChar0(var buf;len:longint;b:char):longint;
 \Description
 \var{IndexChar} searches the memory at \var{buf} for maximally \var{len}
 positions for the character \var{b} and returns it's position if it found one.
@@ -5778,7 +5778,7 @@ The position is zero-based.
 
 \begin{function}{IndexWord}
 \Declaration
-function  IndexWord(var buf;len:longint;W:word):longint;  
+function  IndexWord(var buf;len:longint;W:word):longint;
 \var{IndexChar} searches the memory at \var{buf} for maximally \var{len}
 positions for the Word \var{W} and returns it's position if it found one.
 If \var{W} is not found then -1 is returned.

+ 13 - 20
docs/units.tex

@@ -19,7 +19,7 @@
 %   Boston, MA 02111-1307, USA.
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Preamble. 
+% Preamble.
 % Uncomment the one you need here. The book version is for the published
 % book version.
 \documentclass{report}
@@ -27,34 +27,27 @@
 %
 % Preamble
 %
+\usepackage{multicol}
 \ifx\pdfoutput\undefined
   \usepackage{html}
   \usepackage{htmllist}
   \latex{\usepackage{fpc}}
+  \html{\input{fpc-html.tex}}
 \else
+% Uncomment the fpc or fpcbook version, depending on the output format
+% you want.
   \usepackage{fpc}
+  %\usepackage{fpcbook}
 \fi
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% Uncomment the fpc or fpcbook version, depending on the output format 
-% you want.
-\usepackage{fpc}
-%\usepackage{fpcbook}
-\latex{\usepackage{multicol}}
 \latex{%
   \ifpdf
-  \pdfcompresslevel=9
-  \pdfpagewidth=210mm
-  \pdfpageheight=297mm
-%
-\html{\input{fpc-html.tex}}
-%
-\ifpdf
-  \pdfinfo{/Author(Michael Van Canneyt)
-           /Title(Standard units Reference Guide)
-           /Subject(Free Pascal Standard units reference guide)
-           /Keywords(Free Pascal, Units, RTL)
-           }
-\fi
+    \pdfinfo{/Author(Michael Van Canneyt)
+             /Title(Standard units Reference Guide)
+             /Subject(Free Pascal Standard units reference guide)
+             /Keywords(Free Pascal, Units, RTL)
+             }
+  \fi
+}
 %
 % Settings
 %

+ 1 - 0
docs/user.tex

@@ -31,6 +31,7 @@
   \usepackage{html}
   \usepackage{htmllist}
   \latex{\usepackage{fpc}}
+  \html{\input{fpc-html.tex}}
 \else
   \usepackage{fpc}
 %  \usepackage{fpcbook}