Browse Source

+ Initial move

michael 21 years ago
parent
commit
f28bcb9231
78 changed files with 1871 additions and 0 deletions
  1. 60 0
      docs/olinuxex/Makefile
  2. 76 0
      docs/olinuxex/README
  3. 10 0
      docs/olinuxex/ex1.pp
  4. 11 0
      docs/olinuxex/ex10.pp
  5. 12 0
      docs/olinuxex/ex11.pp
  6. 12 0
      docs/olinuxex/ex12.pp
  7. 11 0
      docs/olinuxex/ex13.pp
  8. 24 0
      docs/olinuxex/ex14.pp
  9. 14 0
      docs/olinuxex/ex15.pp
  10. 9 0
      docs/olinuxex/ex16.pp
  11. 9 0
      docs/olinuxex/ex17.pp
  12. 9 0
      docs/olinuxex/ex18.pp
  13. 19 0
      docs/olinuxex/ex19.pp
  14. 17 0
      docs/olinuxex/ex2.pp
  15. 46 0
      docs/olinuxex/ex20.pp
  16. 31 0
      docs/olinuxex/ex21.pp
  17. 33 0
      docs/olinuxex/ex22.pp
  18. 21 0
      docs/olinuxex/ex23.pp
  19. 28 0
      docs/olinuxex/ex24.pp
  20. 24 0
      docs/olinuxex/ex25.pp
  21. 13 0
      docs/olinuxex/ex26.pp
  22. 10 0
      docs/olinuxex/ex27.pp
  23. 39 0
      docs/olinuxex/ex28.pp
  24. 63 0
      docs/olinuxex/ex29.pp
  25. 13 0
      docs/olinuxex/ex3.pp
  26. 33 0
      docs/olinuxex/ex30.pp
  27. 15 0
      docs/olinuxex/ex31.pp
  28. 22 0
      docs/olinuxex/ex32.pp
  29. 25 0
      docs/olinuxex/ex33.pp
  30. 22 0
      docs/olinuxex/ex34.pp
  31. 46 0
      docs/olinuxex/ex35.pp
  32. 25 0
      docs/olinuxex/ex36.pp
  33. 35 0
      docs/olinuxex/ex37.pp
  34. 51 0
      docs/olinuxex/ex38.pp
  35. 9 0
      docs/olinuxex/ex39.pp
  36. 19 0
      docs/olinuxex/ex4.pp
  37. 9 0
      docs/olinuxex/ex40.pp
  38. 9 0
      docs/olinuxex/ex41.pp
  39. 22 0
      docs/olinuxex/ex42.pp
  40. 20 0
      docs/olinuxex/ex43.pp
  41. 9 0
      docs/olinuxex/ex44.pp
  42. 9 0
      docs/olinuxex/ex45.pp
  43. 9 0
      docs/olinuxex/ex46.pp
  44. 12 0
      docs/olinuxex/ex47.pp
  45. 12 0
      docs/olinuxex/ex48.pp
  46. 22 0
      docs/olinuxex/ex49.pp
  47. 12 0
      docs/olinuxex/ex5.pp
  48. 15 0
      docs/olinuxex/ex51.pp
  49. 11 0
      docs/olinuxex/ex52.pp
  50. 27 0
      docs/olinuxex/ex53.pp
  51. 15 0
      docs/olinuxex/ex54.pp
  52. 30 0
      docs/olinuxex/ex55.pp
  53. 13 0
      docs/olinuxex/ex56.pp
  54. 37 0
      docs/olinuxex/ex57.pp
  55. 28 0
      docs/olinuxex/ex58.pp
  56. 21 0
      docs/olinuxex/ex59.pp
  57. 12 0
      docs/olinuxex/ex6.pp
  58. 13 0
      docs/olinuxex/ex60.pp
  59. 22 0
      docs/olinuxex/ex61.pp
  60. 28 0
      docs/olinuxex/ex62.pp
  61. 9 0
      docs/olinuxex/ex63.pp
  62. 36 0
      docs/olinuxex/ex64.pp
  63. 31 0
      docs/olinuxex/ex65.pp
  64. 37 0
      docs/olinuxex/ex66.pp
  65. 16 0
      docs/olinuxex/ex67.pp
  66. 11 0
      docs/olinuxex/ex68.pp
  67. 27 0
      docs/olinuxex/ex69.pp
  68. 21 0
      docs/olinuxex/ex7.pp
  69. 22 0
      docs/olinuxex/ex70.pp
  70. 71 0
      docs/olinuxex/ex71.pp
  71. 27 0
      docs/olinuxex/ex72.pp
  72. 20 0
      docs/olinuxex/ex8.pp
  73. 22 0
      docs/olinuxex/ex9.pp
  74. 2 0
      docs/olinuxex/foot.tex
  75. 3 0
      docs/olinuxex/head.tex
  76. 8 0
      docs/olinuxex/newex
  77. 167 0
      docs/olinuxex/serial.pp
  78. 8 0
      docs/olinuxex/template.pp

+ 60 - 0
docs/olinuxex/Makefile

@@ -0,0 +1,60 @@
+#######################################################################
+#
+# 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 ex8 ex9 ex10 ex11 ex12 ex13 ex14 \
+        ex15 ex16 ex17 ex18 ex19 ex20 ex21 ex22 ex23 ex24 ex25 ex26 ex27 \
+        ex28 ex29 ex30 ex31 ex32 ex33 ex34 ex35 ex36 ex37 ex38 ex39 ex40 \
+        ex41 ex42 ex43 ex44 ex45 ex46 ex47 ex48 ex49 ex51 ex52 ex53 ex54 ex55 \
+        ex56 ex57 ex58 ex59 ex60 ex61 ex62 ex63  ex64 ex65 ex66 \
+        ex67 ex68 ex69 ex70 ex71 ex72
+# ex73 ex74 ex75 ex76 ex77
+
+TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
+
+all : $(OBJECTS)
+
+tex : $(TEXOBJECTS)
+
+onetex : tex
+	$(MAKETEX) $(TEXOBJECTS)
+
+clean : 
+	rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS)
+	rm -f *.ow *.sw *.exe *.dll
+ 
+$(OBJECTS): %: %.pp
+	$(PP) $(PPOPTS) $*
+
+$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
+	$(PP2TEX) $*

+ 76 - 0
docs/olinuxex/README

@@ -0,0 +1,76 @@
+These are the example programs that appear in the FPC documentation.
+ 
+Units guide, Linux unit :
+
+ex1.pp contains an example of the GetEpochTime function.
+ex2.pp contains an example of the GetTimeOfDay function.
+ex3.pp contains an example of the EpochToLocal function.
+ex4.pp contains an example of the LocalToEpoch function.
+ex5.pp contains an example of the GetTime function.
+ex6.pp contains an example of the GetDate function.
+ex7.pp contains an example of the Execve function.
+ex8.pp contains an example of the Execv function.
+ex9.pp contains an example of the Execvp function.
+ex10.pp contains an example of the Execl function.
+ex11.pp contains an example of the Execle function.
+ex11.pp contains an example of the Execlp function.
+ex13.pp contains an example of the Shell function.
+ex14.pp contains an example of the Fork function.
+ex15.pp contains an example of the Nice, Set- and GetPriority functions.
+ex16.pp contains an example of the GetPid and GetPPid functions.
+ex17.pp contains an example of the GetUid and GetEUid functions.
+ex18.pp contains an example of the GetGid and GetEgid functions.
+ex19.pp contains an example of the fdOpen, fdWrite and fdCLose functions.
+ex20.pp contains an example of the fdRead and fdTuncate functions.
+ex21.pp contains an example of the Link and UnLink functions.
+ex22.pp contains an example of the SymLink and UnLink functions.
+ex23.pp contains an example of the Chmod function.
+ex24.pp contains an example of the Chown function.
+ex25.pp contains an example of the UTime function.
+ex26.pp contains an example of the Access function.
+ex27.pp contains an example of the Umask function.
+ex28.pp contains an example of the FStat function.
+ex29.pp contains an example of the LStat function.
+ex30.pp contains an example of the FSStat function.
+ex31.pp contains an example of the Dup function.
+ex32.pp contains an example of the Dup2 function.
+ex33.pp contains an example of the Select function.
+ex34.pp contains an example of the SelectText function.
+ex35.pp contains an example of the OpenDir, ReadDir Telldir and SeekDir functions.
+ex36.pp contains an example of the AssignPipe function.
+ex37.pp contains an example of the POpen and PClose functions.
+ex38.pp contains an example of the AssignStream function.
+ex39.pp contains an example of the GetDomainName function.
+ex40.pp contains an example of the GetHostName function.
+ex41.pp contains an example of the GetEnv function.
+ex42.pp contains an example of the SysInfo function.
+ex43.pp contains an example of the Uname function.
+ex44.pp contains an example of the Octal function.
+ex45.pp contains an example of the FExpand function.
+ex46.pp contains an example of the FSearch function.
+ex47.pp contains an example of the DirName function.
+ex48.pp contains an example of the BaseName function.
+ex49.pp contains an example of the Glob function.
+ex51.pp contains an example of the StringToPPChar function.
+ex52.pp contains an example of the GetFS function.
+ex53.pp contains an example of the S_ISLNK and related functions.
+ex54.pp contains an example of the IOCtl function.
+ex55.pp contains an example of the TCGetAttr,TCSetAttr,CFMakeRaw functions.
+ex56.pp contains an example of the Shell function.
+ex57.pp contains an example of the SigAction function.
+ex58.pp contains an example of the Signal function.
+ex59.pp contains an example of the Alarm function.
+ex60.pp contains an example of the GetDateTime function.
+ex61.pp contains an example of the CreateShellArgV function.
+ex62.pp contains an example of the ReadLink function.
+ex63.pp contains an example of the FRename function.
+ex64.pp contains an example of the SysInfo function.
+ex64.pp contains an example of the SigRaise function.
+ex66.pp contains an example of the MMap function.
+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.
+ex72.pp contains an example of the NanoSleep function.
+serial.pp contains an example of serial port programming in FPC.

+ 10 - 0
docs/olinuxex/ex1.pp

@@ -0,0 +1,10 @@
+Program Example1;
+
+{ Program to demonstrate the GetEpochTime function. }
+
+Uses oldlinux;
+
+begin
+  Write ('Secs past the start of the Epoch (00:00 1/1/1980) : ');
+  Writeln (GetEpochTime);
+end.

+ 11 - 0
docs/olinuxex/ex10.pp

@@ -0,0 +1,11 @@
+Program Example10;
+
+{ Program to demonstrate the Execl function. }
+
+Uses oldlinux, strings;
+
+begin
+  { Execute 'ls -l', with current environment. }
+  { 'ls' is NOT looked for in PATH environment variable.}
+  Execl ('/bin/ls -l');
+end.

+ 12 - 0
docs/olinuxex/ex11.pp

@@ -0,0 +1,12 @@
+Program Example11;
+
+{ Program to demonstrate the Execle function. }
+
+Uses oldlinux, strings;
+
+begin
+  { Execute 'ls -l', with current environment. }
+  { 'ls' is NOT looked for in PATH environment variable.}
+  { envp is defined in the system unit.}
+  Execle ('/bin/ls -l',envp);
+end.

+ 12 - 0
docs/olinuxex/ex12.pp

@@ -0,0 +1,12 @@
+Program Example12;
+
+{ Program to demonstrate the Execlp function. }
+
+Uses oldlinux, strings;
+
+begin
+  { Execute 'ls -l', with current environment. }
+  { 'ls' is looked for in PATH environment variable.}
+  { envp is defined in the system unit.}
+  Execlp ('ls -l',envp);
+end.

+ 11 - 0
docs/olinuxex/ex13.pp

@@ -0,0 +1,11 @@
+Program Example13;
+
+{ Program to demonstrate the Shell function. }
+
+Uses oldlinux;
+
+begin
+  { This will send the output of 'ls -l' to the file ls.out }
+  { thanks to the shell's redirection functionality }
+  Shell ('ls -l >ls.out')
+end.

+ 24 - 0
docs/olinuxex/ex14.pp

@@ -0,0 +1,24 @@
+Program Example14;
+
+{ Program to demonstrate the Fork and WaitPidfunction. }
+
+Uses oldlinux;
+
+Var PID, ExitStatus : Longint;
+  
+begin
+  Writeln ('Spawning a child');
+  PID:=Fork;
+  If PID=0 then
+    begin 
+    Writeln ('Hello From the Child !!');
+    Writeln ('Exiting with exit status 1 !');
+    Halt (1);
+    end
+  Else 
+    begin
+    Writeln ('Spawned child with PID : ',PID);
+    WaitPid (PID,@ExitStatus,0);
+    Writeln ('Child exited with status : ',ExitStatus shr 8);
+    end; 
+end.

+ 14 - 0
docs/olinuxex/ex15.pp

@@ -0,0 +1,14 @@
+Program Example15;
+
+{ Program to demonstrate the Nice and Get/SetPriority functions. }
+
+Uses oldlinux;
+
+begin
+  writeln ('Setting priority to 5');
+  setpriority (prio_process,getpid,5);
+  writeln ('New priority = ',getpriority (prio_process,getpid));
+  writeln ('Doing nice 10');
+  nice (10);
+  writeln ('New Priority = ',getpriority (prio_process,getpid));
+end.

+ 9 - 0
docs/olinuxex/ex16.pp

@@ -0,0 +1,9 @@
+Program Example16;
+
+{ Program to demonstrate the GetPid, GetPPid function. }
+
+Uses oldlinux;
+
+begin
+  Writeln ('Process Id = ',getpid,' Parent process Id = ',getppid);
+end.

+ 9 - 0
docs/olinuxex/ex17.pp

@@ -0,0 +1,9 @@
+Program Example17;
+
+{ Program to demonstrate the GetUid and GetEUid functions. }
+
+Uses oldlinux;
+
+begin
+  writeln ('User Id = ',getuid,' Effective user Id = ',geteuid);
+end.

+ 9 - 0
docs/olinuxex/ex18.pp

@@ -0,0 +1,9 @@
+Program Example18;
+
+{ Program to demonstrate the GetGid and GetEGid functions. }
+
+Uses oldlinux;
+
+begin
+ writeln ('Group Id = ',getgid,' Effective group Id = ',getegid);
+end.

+ 19 - 0
docs/olinuxex/ex19.pp

@@ -0,0 +1,19 @@
+Program Example19;
+
+{ Program to demonstrate the fdOpen, fdwrite and fdCLose functions. }
+
+Uses oldlinux;
+
+Const Line : String[80] = 'This is easy writing !';
+
+Var FD : Longint;
+
+begin
+  FD:=fdOpen ('Test.dat',Open_WrOnly or Open_Creat);
+  if FD>0 then
+    begin
+    if length(Line)<>fdwrite (FD,Line[1],Length(Line)) then
+      Writeln ('Error when writing to file !');
+    fdClose(FD);
+    end;
+end.

+ 17 - 0
docs/olinuxex/ex2.pp

@@ -0,0 +1,17 @@
+Program Example2;
+
+{ Program to demonstrate the GetTimeOfDay function. }
+
+Uses oldlinux;
+
+Var TV : TimeVal;
+    TZ : TimeZone;
+
+begin
+  GetTimeOfDay (TV);
+  Writeln ('Seconds              : ',tv.sec);
+  Writeln ('Milliseconds         : ',tv.usec);
+  Writeln ('Minutes west of GMT  : ',tz.minuteswest);
+  Writeln ('Daylight Saving Time : ',tz.dsttime);
+  Writeln ('Seconds in 1 call    : ',GetTimeOfDay);
+end.

+ 46 - 0
docs/olinuxex/ex20.pp

@@ -0,0 +1,46 @@
+Program Example20;
+
+{ Program to demonstrate the fdRead and fdTruncate functions. }
+
+Uses oldlinux;
+
+Const Data : string[10] = '12345687890';
+
+Var FD : Longint;
+    l : longint;
+        
+begin
+  FD:=fdOpen('test.dat',open_wronly or open_creat,octal(666));
+  if fd>0 then
+    begin
+    { Fill file with data } 
+    for l:=1 to 10 do
+      if fdWrite (FD,Data[1],10)<>10 then
+        begin
+        writeln ('Error when writing !');
+        halt(1);
+        end;
+    fdClose(FD);
+    FD:=fdOpen('test.dat',open_rdonly);
+    { Read data again }
+    If FD>0 then
+      begin
+      For l:=1 to 5 do 
+        if fdRead (FD,Data[1],10)<>10 then
+          begin
+          Writeln ('Error when Reading !');
+          Halt(2);
+          end;
+      fdCLose(FD);
+      { Truncating file at 60 bytes }
+      { For truncating, file must be open or write }    
+      FD:=fdOpen('test.dat',open_wronly,octal(666));
+      if FD>0 then
+        begin 
+        if not fdTruncate(FD,60) then
+           Writeln('Error when truncating !');
+        fdClose (FD);
+        end;
+      end;
+    end;
+end.

+ 31 - 0
docs/olinuxex/ex21.pp

@@ -0,0 +1,31 @@
+Program Example21;
+
+{ Program to demonstrate the Link and UnLink functions. }
+
+Uses oldlinux;
+
+Var F : Text;
+    S : String;
+begin
+  Assign (F,'test.txt');
+  Rewrite (F);
+  Writeln (F,'This is written to test.txt');
+  Close(f);
+  { new.txt and test.txt are now the same file }
+  if not Link ('test.txt','new.txt') then
+    writeln ('Error when linking !');
+  { Removing test.txt still leaves new.txt }
+  If not Unlink ('test.txt') then
+    Writeln ('Error when unlinking !');
+  Assign (f,'new.txt');
+  Reset (F);
+  While not EOF(f) do 
+    begin
+    Readln(F,S);
+    Writeln ('> ',s);
+    end;
+ Close (f);
+ { Remove new.txt also }
+ If not Unlink ('new.txt') then
+   Writeln ('Error when unlinking !');
+end.

+ 33 - 0
docs/olinuxex/ex22.pp

@@ -0,0 +1,33 @@
+Program Example22;
+
+{ Program to demonstrate the SymLink and UnLink functions. }
+
+Uses oldlinux;
+
+Var F : Text;
+    S : String;
+    
+begin
+  Assign (F,'test.txt');
+  Rewrite (F);
+  Writeln (F,'This is written to test.txt');
+  Close(f);
+  { new.txt and test.txt are now the same file }
+  if not SymLink ('test.txt','new.txt') then
+    writeln ('Error when symlinking !');
+  { Removing test.txt still leaves new.txt
+    Pointing now to a non-existent file ! }
+  If not Unlink ('test.txt') then
+    Writeln ('Error when unlinking !');
+  Assign (f,'new.txt');
+  { This should fail, since the symbolic link
+    points to a non-existent file! }
+  {$i-}
+  Reset (F);
+  {$i+}
+  If IOResult=0 then
+    Writeln ('This shouldn''t happen'); 
+ { Now remove new.txt also }
+ If not Unlink ('new.txt') then
+   Writeln ('Error when unlinking !');
+end.

+ 21 - 0
docs/olinuxex/ex23.pp

@@ -0,0 +1,21 @@
+Program Example23;
+
+{ Program to demonstrate the Chmod function. }
+
+Uses oldlinux;
+
+Var F : Text;
+
+begin
+  { Create a file }
+  Assign (f,'testex21');
+  Rewrite (F);
+  Writeln (f,'#!/bin/sh');
+  Writeln (f,'echo Some text for this file');
+  Close (F);
+  { Octal() makes the correct number from a
+    number that LOOKS octal }
+  Chmod ('testex21',octal (777)); 
+  { File is now executable  }
+  execl ('./testex21');    
+end.

+ 28 - 0
docs/olinuxex/ex24.pp

@@ -0,0 +1,28 @@
+Program Example24;
+
+{ Program to demonstrate the Chown function. }
+
+Uses oldlinux;
+
+Var UID,GID : Longint;
+    F : Text;
+    
+begin
+  
+  Writeln ('This will only work if you are root.');
+  Write ('Enter a UID : ');readln(UID);
+  Write ('Enter a GID : ');readln(GID);
+  Assign (f,'test.txt');
+  Rewrite (f);
+  Writeln (f,'The owner of this file should become : ');
+  Writeln (f,'UID : ',UID);
+  Writeln (f,'GID : ',GID);
+  Close (F);
+  if not Chown ('test.txt',UID,GID) then
+    if LinuxError=Sys_EPERM then
+      Writeln ('You are not root !')
+    else
+      Writeln ('Chmod failed with exit code : ',LinuxError)
+  else
+    Writeln ('Changed owner successfully !');
+end.

+ 24 - 0
docs/olinuxex/ex25.pp

@@ -0,0 +1,24 @@
+Program Example25;
+
+{ Program to demonstrate the UTime function. }
+
+Uses oldlinux;
+
+Var utim : utimbuf;
+    year,month,day,hour,minute,second : Word;
+       
+begin
+  { Set access and modification time of executable source }
+  GetTime (hour,minute,second);
+  GetDate (year,month,day);  
+  utim.actime:=LocalToEpoch(year,month,day,hour,minute,second);
+  utim.modtime:=utim.actime;
+  if not Utime('ex25.pp',utim) then
+    writeln ('Call to UTime failed !')
+  else
+    begin
+    Write ('Set access and modification times to : ');
+    Write (Hour:2,':',minute:2,':',second,', ');
+    Writeln (Day:2,'/',month:2,'/',year:4);
+    end;
+end.

+ 13 - 0
docs/olinuxex/ex26.pp

@@ -0,0 +1,13 @@
+Program Example26;
+
+{ Program to demonstrate the Access function. }
+
+Uses oldlinux;
+
+begin
+  if Access ('/etc/passwd',W_OK) then
+    begin
+    Writeln ('Better check your system.');
+    Writeln ('I can write to the /etc/passwd file !');
+    end;
+end.

+ 10 - 0
docs/olinuxex/ex27.pp

@@ -0,0 +1,10 @@
+Program Example27;
+
+{ Program to demonstrate the Umask function. }
+
+Uses oldlinux;
+
+begin
+  Writeln ('Old Umask was : ',Umask(Octal(111)));
+  WRiteln ('New Umask is  : ',Octal(111));
+end.

+ 39 - 0
docs/olinuxex/ex28.pp

@@ -0,0 +1,39 @@
+program example28;
+
+{ Program to demonstrate the FStat function. }
+
+uses oldlinux;
+    
+var f : text;    
+    i : byte;
+    info : stat;
+    
+begin
+  { Make a file }
+  assign (f,'test.fil');
+  rewrite (f);
+  for i:=1 to 10 do writeln (f,'Testline # ',i);
+  close (f);
+  { Do the call on made file. }
+  if not fstat ('test.fil',info) then 
+     begin
+     writeln('Fstat failed. Errno : ',linuxerror);
+     halt (1);
+     end;
+  writeln;
+  writeln ('Result of fstat on file ''test.fil''.');
+  writeln ('Inode   : ',info.ino);
+  writeln ('Mode    : ',info.mode);
+  writeln ('nlink   : ',info.nlink);
+  writeln ('uid     : ',info.uid);
+  writeln ('gid     : ',info.gid);
+  writeln ('rdev    : ',info.rdev);
+  writeln ('Size    : ',info.size);
+  writeln ('Blksize : ',info.blksze);
+  writeln ('Blocks  : ',info.blocks);
+  writeln ('atime   : ',info.atime);
+  writeln ('mtime   : ',info.mtime);
+  writeln ('ctime   : ',info.ctime);
+  { Remove file }  
+  erase (f);    
+end.

+ 63 - 0
docs/olinuxex/ex29.pp

@@ -0,0 +1,63 @@
+program example29;
+
+{ Program to demonstrate the LStat function. }
+
+uses oldlinux;
+    
+var f : text;    
+    i : byte;
+    info : stat;
+    
+begin
+  { Make a file }
+  assign (f,'test.fil');
+  rewrite (f);
+  for i:=1 to 10 do writeln (f,'Testline # ',i);
+  close (f);
+  { Do the call on made file. }
+  if not fstat ('test.fil',info) then 
+     begin
+     writeln('Fstat failed. Errno : ',linuxerror);
+     halt (1);
+     end;
+  writeln;
+  writeln ('Result of fstat on file ''test.fil''.');
+  writeln ('Inode   : ',info.ino);
+  writeln ('Mode    : ',info.mode);
+  writeln ('nlink   : ',info.nlink);
+  writeln ('uid     : ',info.uid);
+  writeln ('gid     : ',info.gid);
+  writeln ('rdev    : ',info.rdev);
+  writeln ('Size    : ',info.size);
+  writeln ('Blksize : ',info.blksze);
+  writeln ('Blocks  : ',info.blocks);
+  writeln ('atime   : ',info.atime);
+  writeln ('mtime   : ',info.mtime);
+  writeln ('ctime   : ',info.ctime);
+
+  If not SymLink ('test.fil','test.lnk') then
+    writeln ('Link failed ! Errno :',linuxerror);
+
+  if not lstat ('test.lnk',info) then 
+     begin
+     writeln('LStat failed. Errno : ',linuxerror);
+     halt (1);
+     end;
+  writeln;
+  writeln ('Result of fstat on file ''test.lnk''.');
+  writeln ('Inode   : ',info.ino);
+  writeln ('Mode    : ',info.mode);
+  writeln ('nlink   : ',info.nlink);
+  writeln ('uid     : ',info.uid);
+  writeln ('gid     : ',info.gid);
+  writeln ('rdev    : ',info.rdev);
+  writeln ('Size    : ',info.size);
+  writeln ('Blksize : ',info.blksze);
+  writeln ('Blocks  : ',info.blocks);
+  writeln ('atime   : ',info.atime);
+  writeln ('mtime   : ',info.mtime);
+  writeln ('ctime   : ',info.ctime);
+  { Remove file and link }  
+  erase (f);
+  unlink ('test.lnk');    
+end.

+ 13 - 0
docs/olinuxex/ex3.pp

@@ -0,0 +1,13 @@
+Program Example3;
+
+{ Program to demonstrate the EpochToLocal function. }
+
+Uses oldlinux;
+
+Var Year,month,day,hour,minute,seconds : Word;
+
+begin
+  EpochToLocal (GetEpochTime,Year,month,day,hour,minute,seconds);
+  Writeln ('Current date : ',Day:2,'/',Month:2,'/',Year:4);
+  Writeln ('Current time : ',Hour:2,':',minute:2,':',seconds:2);
+end.

+ 33 - 0
docs/olinuxex/ex30.pp

@@ -0,0 +1,33 @@
+program Example30;
+
+{ Program to demonstrate the FSStat function. }
+
+uses oldlinux;
+    
+var s : string; 
+    info : statfs;
+    
+begin
+  writeln ('Info about current partition : ');
+  s:='.';
+  while s<>'q' do 
+    begin
+    if not fsstat (s,info) then
+       begin
+       writeln('Fstat failed. Errno : ',linuxerror);
+       halt (1);
+       end;
+    writeln;
+    writeln ('Result of fsstat on file ''',s,'''.');
+    writeln ('fstype  : ',info.fstype);
+    writeln ('bsize   : ',info.bsize);
+    writeln ('bfree   : ',info.bfree);
+    writeln ('bavail  : ',info.bavail);
+    writeln ('files   : ',info.files);
+    writeln ('ffree   : ',info.ffree);
+    writeln ('fsid    : ',info.fsid);
+    writeln ('Namelen : ',info.namelen);
+    write ('Type name of file to do fsstat. (q quits) :');
+    readln (s)
+    end;
+end.

+ 15 - 0
docs/olinuxex/ex31.pp

@@ -0,0 +1,15 @@
+program Example31;
+
+{ Program to demonstrate the Dup function. }
+
+uses oldlinux;
+
+var f : text;
+
+begin
+  if not dup (output,f) then 
+    Writeln ('Dup Failed !');
+  writeln ('This is written to stdout.');
+  writeln (f,'This is written to the dup file, and flushed');flush(f);
+  writeln
+end.

+ 22 - 0
docs/olinuxex/ex32.pp

@@ -0,0 +1,22 @@
+program Example31;
+
+{ Program to demonstrate the Dup function. }
+
+uses oldlinux;
+
+var f : text;
+    i : longint;
+    
+begin
+  Assign (f,'text.txt');
+  Rewrite (F);
+  For i:=1 to 10 do writeln (F,'Line : ',i);
+  if not dup2 (output,f) then 
+    Writeln ('Dup2 Failed !');
+  writeln ('This is written to stdout.');
+  writeln (f,'This is written to the dup file, and flushed');
+  flush(f);
+  writeln;
+  { Remove file. Comment this if you want to check flushing.}
+  Unlink ('text.txt');
+end.

+ 25 - 0
docs/olinuxex/ex33.pp

@@ -0,0 +1,25 @@
+Program Example33;
+
+{ Program to demonstrate the Select function. }
+
+Uses oldlinux;
+
+Var FDS : FDSet;
+
+begin
+  FD_Zero (FDS);
+  FD_Set (0,FDS);
+  Writeln ('Press the <ENTER> to continue the program.');
+  { Wait until File descriptor 0 (=Input) changes }
+  Select (1,@FDS,nil,nil,nil);
+  { Get rid of <ENTER> in buffer }
+  readln;
+  Writeln ('Press <ENTER> key in less than 2 seconds...');
+  FD_Zero (FDS);
+  FD_Set (0,FDS);
+  if Select (1,@FDS,nil,nil,2000)>0 then 
+    Writeln ('Thank you !')
+    { FD_ISSET(0,FDS) would be true here. }
+  else
+    Writeln ('Too late !');
+end.

+ 22 - 0
docs/olinuxex/ex34.pp

@@ -0,0 +1,22 @@
+Program Example33;
+
+{ Program to demonstrate the SelectText function. }
+
+Uses oldlinux;
+
+Var tv : TimeVal;
+    
+begin
+  Writeln ('Press the <ENTER> to continue the program.');
+  { Wait until File descriptor 0 (=Input) changes }
+  SelectText (Input,nil);
+  { Get rid of <ENTER> in buffer }
+  readln;
+  Writeln ('Press <ENTER> key in less than 2 seconds...');
+  tv.sec:=2;
+  tv.usec:=0;
+  if SelectText (Input,@tv)>0 then 
+    Writeln ('Thank you !')
+  else
+    Writeln ('Too late !');
+end.

+ 46 - 0
docs/olinuxex/ex35.pp

@@ -0,0 +1,46 @@
+Program Example35;
+
+{ Program to demonstrate the 
+  OpenDir,ReadDir, SeekDir and TellDir functions. }
+
+Uses oldlinux;
+
+Var TheDir : PDir;
+    ADirent : PDirent;
+    Entry : Longint;
+
+begin
+  TheDir:=OpenDir('./.');
+  Repeat 
+    Entry:=TellDir(TheDir);
+    ADirent:=ReadDir (TheDir);
+    If ADirent<>Nil then
+      With ADirent^ do
+        begin
+        Writeln ('Entry No : ',Entry);
+        Writeln ('Inode    : ',ino);
+        Writeln ('Offset   : ',off);
+        Writeln ('Reclen   : ',reclen);
+        Writeln ('Name     : ',pchar(@name[0]));
+        end;
+  Until ADirent=Nil;
+  Repeat
+    Write ('Entry No. you would like to see again (-1 to stop): ');
+    ReadLn (Entry);
+    If Entry<>-1 then 
+      begin
+      SeekDir (TheDir,Entry);
+      ADirent:=ReadDir (TheDir);
+      If ADirent<>Nil then
+        With ADirent^ do
+          begin
+          Writeln ('Entry No : ',Entry);
+          Writeln ('Inode    : ',ino);
+          Writeln ('Offset   : ',off);
+          Writeln ('Reclen   : ',reclen);
+          Writeln ('Name     : ',pchar(@name[0]));
+          end;
+    end;
+  Until Entry=-1;
+  CloseDir (TheDir);
+end.

+ 25 - 0
docs/olinuxex/ex36.pp

@@ -0,0 +1,25 @@
+Program Example36;
+
+{ Program to demonstrate the AssignPipe function. }
+
+Uses oldlinux;
+
+Var pipi,pipo : Text;
+    s : String;
+    
+begin
+  Writeln ('Assigning Pipes.');
+  If Not assignpipe(pipi,pipo) then
+    Writeln('Error assigning pipes !',LinuxError);
+  Writeln ('Writing to pipe, and flushing.');
+  Writeln (pipo,'This is a textstring');close(pipo);
+  Writeln ('Reading from pipe.');
+  While not eof(pipi) do 
+    begin
+    Readln (pipi,s);
+    Writeln ('Read from pipe : ',s);
+    end;
+  close (pipi);
+  writeln ('Closed pipes.');
+  writeln
+end.

+ 35 - 0
docs/olinuxex/ex37.pp

@@ -0,0 +1,35 @@
+Program Example37;
+
+{ Program to demonstrate the Popen function. }
+
+uses oldlinux;
+
+var f : text;
+    i : longint;
+    
+begin
+  writeln ('Creating a shell script to which echoes its arguments');
+  writeln ('and input back to stdout');
+  assign (f,'test21a');
+  rewrite (f);
+  writeln (f,'#!/bin/sh');
+  writeln (f,'echo this is the child speaking.... ');
+  writeln (f,'echo got arguments \*"$*"\*');
+  writeln (f,'cat');
+  writeln (f,'exit 2');
+  writeln (f);
+  close (f);
+  chmod ('test21a',octal (755));
+  popen (f,'./test21a arg1 arg2','W');
+  if linuxerror<>0 then 
+     writeln ('error from POpen : Linuxerror : ', Linuxerror);
+  for i:=1 to 10 do 
+    writeln (f,'This is written to the pipe, and should appear on stdout.');
+  Flush(f);
+  Writeln ('The script exited with status : ',PClose (f));
+  writeln;
+  writeln ('Press <return> to remove shell script.');
+  readln;
+  assign (f,'test21a');
+  erase (f)
+end.

+ 51 - 0
docs/olinuxex/ex38.pp

@@ -0,0 +1,51 @@
+Program Example38;
+
+{ Program to demonstrate the AssignStream function. }
+
+Uses oldlinux;
+
+Var Si,So : Text;
+    S : String;
+    i : longint;
+        
+begin
+  if not (paramstr(1)='-son') then
+    begin
+    Writeln ('Calling son');
+    Assignstream (Si,So,'./ex38 -son');
+    if linuxerror<>0 then 
+      begin
+      writeln ('AssignStream failed !');
+      halt(1);
+      end;
+    Writeln ('Speaking to son');
+    For i:=1 to 10 do 
+      begin
+      writeln (so,'Hello son !');
+      if ioresult<>0 then writeln ('Can''t speak to son...');
+      end;
+    For i:=1 to 3 do writeln (so,'Hello chap !');
+    close (so);
+    while not eof(si) do
+      begin
+      readln (si,s);
+      writeln ('Father: Son said : ',S);
+      end;
+    Writeln ('Stopped conversation');
+    Close (Si);
+    Writeln ('Put down phone');
+    end
+  Else
+    begin
+    Writeln ('This is the son ');
+    While not eof (input) do 
+      begin
+      readln (s);
+      if pos ('Hello son !',S)<>0 then
+         Writeln ('Hello Dad !')
+      else 
+         writeln ('Who are you ?');
+      end;
+    close (output);
+    end 
+end.

+ 9 - 0
docs/olinuxex/ex39.pp

@@ -0,0 +1,9 @@
+Program Example39;
+
+{ Program to demonstrate the GetDomainName function. }
+
+Uses oldlinux;
+
+begin
+  Writeln ('Domain name of this machine is : ',GetDomainName);
+end.

+ 19 - 0
docs/olinuxex/ex4.pp

@@ -0,0 +1,19 @@
+Program Example4;
+
+{ Program to demonstrate the LocalToEpoch function. }
+
+Uses oldlinux;
+
+Var year,month,day,hour,minute,second : Word;
+
+begin
+  Write ('Year    : ');readln(Year);
+  Write ('Month   : ');readln(Month);
+  Write ('Day     : ');readln(Day);
+  Write ('Hour    : ');readln(Hour);
+  Write ('Minute  : ');readln(Minute);
+  Write ('Seonds  : ');readln(Second);
+  Write ('This is : ');
+  Write (LocalToEpoch(year,month,day,hour,minute,second));
+  Writeln (' seconds past 00:00 1/1/1980');
+end.

+ 9 - 0
docs/olinuxex/ex40.pp

@@ -0,0 +1,9 @@
+Program Example40;
+
+{ Program to demonstrate the GetHostName function. }
+
+Uses oldlinux;
+
+begin
+  Writeln ('Name of this machine is : ',GetHostName);
+end.

+ 9 - 0
docs/olinuxex/ex41.pp

@@ -0,0 +1,9 @@
+Program Example41;
+
+{ Program to demonstrate the GetEnv function. }
+
+Uses oldlinux;
+
+begin
+  Writeln ('Path is : ',Getenv('PATH'));
+end.

+ 22 - 0
docs/olinuxex/ex42.pp

@@ -0,0 +1,22 @@
+Program Example42;
+
+{ Program to demonstrate the SysInfo function. }
+
+Uses oldlinux;
+
+Var Info : TSysinfo;
+
+begin
+  If SysInfo (Info) then
+    With info do
+      begin
+      Writeln ('Uptime        : ',uptime);
+      Writeln ('Load          : ',loads[1],'/',Loads[2],'/',Loads[3]);
+      Writeln ('Total ram     : ',TotalRam  div 1024,'Kb.');
+      Writeln ('Free ram      : ',FreeRam   div 1024,'Kb.');
+      Writeln ('Shared ram    : ',SharedRam div 1024,'Kb.');
+      Writeln ('Total swap    : ',Totalswap div 1024,'Kb.');
+      Writeln ('Free swap     : ',FreeSwap  Div 1024,'Kb.');
+      Writeln ('No. Processes : ',procs);
+      end;
+end.

+ 20 - 0
docs/olinuxex/ex43.pp

@@ -0,0 +1,20 @@
+Program Example43;
+
+{ Program to demonstrate the Uname function. }
+
+Uses oldlinux;
+
+Var UN : utsname;
+
+begin
+  if Uname (UN) then
+    With UN do
+      begin
+      Writeln ('Name       : ',pchar(@sysname[0]));
+      Writeln ('Nodename   : ',pchar(@Nodename[0]));
+      Writeln ('release    : ',pchar(@Release[0]));
+      Writeln ('Version    : ',pchar(@Version[0]));
+      Writeln ('Machine    : ',pchar(@Machine[0]));
+      Writeln ('Domainname : ',pchar(@domainname[0]));
+      end;
+end.

+ 9 - 0
docs/olinuxex/ex44.pp

@@ -0,0 +1,9 @@
+Program Example44;
+
+{ Program to demonstrate the Octal function. }
+
+Uses oldlinux;
+
+begin
+  Writeln ('Octal(666) : ',octal(666));
+end.

+ 9 - 0
docs/olinuxex/ex45.pp

@@ -0,0 +1,9 @@
+Program Example45;
+
+{ Program to demonstrate the FExpand function. }
+
+Uses oldlinux;
+
+begin
+  Writeln ('This program is in : ',FExpand(Paramstr(0)));
+end.

+ 9 - 0
docs/olinuxex/ex46.pp

@@ -0,0 +1,9 @@
+Program Example46;
+
+{ Program to demonstrate the FSearch function. }
+
+Uses oldlinux,strings;
+
+begin
+  Writeln ('ls is in : ',FSearch ('ls',strpas(Getenv('PATH'))));
+end.

+ 12 - 0
docs/olinuxex/ex47.pp

@@ -0,0 +1,12 @@
+Program Example47;
+
+{ Program to demonstrate the DirName function. }
+
+Uses oldlinux;
+
+Var S : String;
+
+begin
+  S:=FExpand(Paramstr(0));
+  Writeln ('This program is in directory : ',Dirname(S));
+end.

+ 12 - 0
docs/olinuxex/ex48.pp

@@ -0,0 +1,12 @@
+Program Example48;
+
+{ Program to demonstrate the BaseName function. }
+
+Uses oldlinux;
+
+Var S : String;
+
+begin
+  S:=FExpand(Paramstr(0));
+  Writeln ('This program is called : ',Basename(S,''));
+end.

+ 22 - 0
docs/olinuxex/ex49.pp

@@ -0,0 +1,22 @@
+Program Example49;
+
+{ Program to demonstrate the Glob and GlobFree functions. }
+
+Uses oldlinux;
+
+Var G1,G2 : PGlob;
+
+begin
+  G1:=Glob ('*');
+  if LinuxError=0 then
+    begin
+    G2:=G1;
+    Writeln ('Files in this directory : ');
+    While g2<>Nil do
+      begin
+      Writeln (g2^.name);
+      g2:=g2^.next;
+      end;
+    GlobFree (g1);
+    end;
+end.

+ 12 - 0
docs/olinuxex/ex5.pp

@@ -0,0 +1,12 @@
+Program Example5;
+
+{ Program to demonstrate the GetTime function. }
+
+Uses oldlinux;
+
+Var Hour, Minute, Second : Word;
+
+begin
+  GetTime (Hour, Minute, Second);
+  Writeln ('Time : ',Hour:2,':',Minute:2,':',Second:2);
+end.

+ 15 - 0
docs/olinuxex/ex51.pp

@@ -0,0 +1,15 @@
+Program Example51;
+
+{ Program to demonstrate the StringToPPChar function. }
+
+Uses oldlinux;
+
+var P : PPChar;
+    S : String;
+begin
+  S:='/bin/ls -l -F';
+  P:=StringToPPChar(S);
+  Writeln ('Name     : ',p^); inc(longint(p),4);
+  writeln ('Option 1 : ',p^); inc(longint(p),4);
+  writeln ('Option 2 : ',p^);
+  end.

+ 11 - 0
docs/olinuxex/ex52.pp

@@ -0,0 +1,11 @@
+Program Example52;
+
+{ Program to demonstrate the GetFS function. }
+
+Uses oldlinux;
+
+begin
+  Writeln ('File descriptor of input  ',getfs(input));
+  Writeln ('File descriptor of output ',getfs(output));
+  Writeln ('File descriptor of stderr ',getfs(stderr));
+end.

+ 27 - 0
docs/olinuxex/ex53.pp

@@ -0,0 +1,27 @@
+Program Example53;
+
+{ Program to demonstrate the S_ISLNK function. }
+
+Uses oldlinux;
+
+Var Info : Stat;
+
+begin
+  if LStat (paramstr(1),info) then
+    begin
+    if S_ISLNK(info.mode) then 
+      Writeln ('File is a link');
+    if S_ISREG(info.mode) then 
+      Writeln ('File is a regular file');
+    if S_ISDIR(info.mode) then 
+      Writeln ('File is a directory');
+    if S_ISCHR(info.mode) then 
+      Writeln ('File is a character device file');
+    if S_ISBLK(info.mode) then 
+      Writeln ('File is a block device file');
+    if S_ISFIFO(info.mode) then 
+      Writeln ('File is a named pipe (FIFO)');
+    if S_ISSOCK(info.mode) then 
+      Writeln ('File is a socket');
+    end;
+end.

+ 15 - 0
docs/olinuxex/ex54.pp

@@ -0,0 +1,15 @@
+Program Example54;
+
+uses oldlinux;
+
+{ Program to demonstrate the IOCtl function. }
+
+var
+  tios : Termios;
+begin
+  IOCtl(1,TCGETS,@tios);
+  WriteLn('Input Flags  : $',hexstr(tios.c_iflag,8));
+  WriteLn('Output Flags : $',hexstr(tios.c_oflag,8));
+  WriteLn('Line Flags   : $',hexstr(tios.c_lflag,8));
+  WriteLn('Control Flags: $',hexstr(tios.c_cflag,8));
+end.

+ 30 - 0
docs/olinuxex/ex55.pp

@@ -0,0 +1,30 @@
+Program Example55;
+
+uses oldlinux;
+
+{ Program to demonstrate the TCGetAttr/TCSetAttr/CFMakeRaw functions. }
+
+procedure ShowTermios(var tios:Termios);
+begin
+  WriteLn('Input Flags  : $',hexstr(tios.c_iflag,8)+#13);
+  WriteLn('Output Flags : $',hexstr(tios.c_oflag,8));
+  WriteLn('Line Flags   : $',hexstr(tios.c_lflag,8));
+  WriteLn('Control Flags: $',hexstr(tios.c_cflag,8));
+end;
+
+var
+  oldios,
+  tios : Termios;
+begin
+  WriteLn('Old attributes:');
+  TCGetAttr(1,tios);
+  ShowTermios(tios);
+  oldios:=tios;
+  Writeln('Setting raw terminal mode');  
+  CFMakeRaw(tios);
+  TCSetAttr(1,TCSANOW,tios);
+  WriteLn('Current attributes:');
+  TCGetAttr(1,tios);
+  ShowTermios(tios);
+  TCSetAttr(1,TCSANOW,oldios);
+end.

+ 13 - 0
docs/olinuxex/ex56.pp

@@ -0,0 +1,13 @@
+program example56;
+
+uses oldlinux;
+
+{ Program to demonstrate the Shell function }
+
+Var S : Longint;
+
+begin
+  Writeln ('Output of ls -l *.pp');
+  S:=Shell ('ls -l *.pp');
+  Writeln ('Command exited wwith status : ',S);
+end.

+ 37 - 0
docs/olinuxex/ex57.pp

@@ -0,0 +1,37 @@
+Program example57;
+
+{ Program to demonstrate the SigAction function.}
+
+{ 
+do a kill -USR1 pid from another terminal to see what happens.
+replace pid with the real pid of this program. 
+You can get this pid by running 'ps'.
+}
+
+uses oldlinux;
+
+Var
+   oa,na : PSigActionRec;
+   
+Procedure DoSig(sig : Longint);cdecl;
+
+begin
+   writeln('Receiving signal: ',sig);
+end; 
+
+begin
+   new(na);
+   new(oa);
+   na^.Handler.sh:=@DoSig;
+   na^.Sa_Mask:=0;
+   na^.Sa_Flags:=0;
+   na^.Sa_Restorer:=Nil;
+   SigAction(SigUsr1,na,oa);
+   if LinuxError<>0 then
+     begin
+     writeln('Error: ',linuxerror,'.');
+     halt(1);
+     end;
+   Writeln ('Send USR1 signal or press <ENTER> to exit'); 
+   readln;
+end.

+ 28 - 0
docs/olinuxex/ex58.pp

@@ -0,0 +1,28 @@
+Program example58;
+
+{ Program to demonstrate the Signal function.}
+
+{ 
+do a kill -USR1 pid from another terminal to see what happens.
+replace pid with the real pid of this program. 
+You can get this pid by running 'ps'.
+}
+
+uses oldlinux;
+
+Procedure DoSig(sig : Longint);cdecl;
+
+begin
+   writeln('Receiving signal: ',sig);
+end; 
+
+begin
+   SigNal(SigUsr1,@DoSig);
+   if LinuxError<>0 then
+     begin
+     writeln('Error: ',linuxerror,'.');
+     halt(1);
+     end;
+   Writeln ('Send USR1 signal or press <ENTER> to exit'); 
+   readln;
+end.

+ 21 - 0
docs/olinuxex/ex59.pp

@@ -0,0 +1,21 @@
+Program Example59;
+
+{ Program to demonstrate the Alarm function. }
+
+Uses oldlinux;
+
+Procedure AlarmHandler(Sig : longint);cdecl;
+
+begin
+  Writeln ('Got to alarm handler');
+end;
+
+begin
+  Writeln('Setting alarm handler');
+  Signal(SIGALRM,@AlarmHandler);
+  Writeln ('Scheduling Alarm in 10 seconds');
+  Alarm(10);
+  Writeln ('Pausing');
+  Pause;
+  Writeln ('Pause returned');
+end.

+ 12 - 0
docs/olinuxex/ex6.pp

@@ -0,0 +1,12 @@
+Program Example6;
+
+{ Program to demonstrate the GetDate function. }
+
+Uses oldlinux;
+
+Var Year, Month, Day : Word;
+
+begin
+ GetDate (Year, Month, Day);
+ Writeln ('Date : ',Day:2,'/',Month:2,'/',Year:4);
+end.

+ 13 - 0
docs/olinuxex/ex60.pp

@@ -0,0 +1,13 @@
+Program Example6;
+
+{ Program to demonstrate the GetDateTime function. }
+
+Uses oldlinux;
+
+Var Year, Month, Day, Hour, min, sec : Word;
+
+begin
+ GetDateTime (Year, Month, Day, Hour, min, sec);
+ Writeln ('Date : ',Day:2,'/',Month:2,'/',Year:4);
+ Writeln ('Time : ',Hour:2,':',Min:2,':',Sec:2);
+end.

+ 22 - 0
docs/olinuxex/ex61.pp

@@ -0,0 +1,22 @@
+Program ex61;
+
+{ Example program to demonstrate the CreateShellArgV function }
+
+uses oldlinux;
+
+Var
+  S: String;
+  PP : PPchar;
+   I : longint;
+    
+begin
+  S:='script -a -b -c -d -e fghijk';
+  PP:=CreateShellArgV(S);
+  I:=0;
+  If PP<>Nil then
+    While PP[i]<>Nil do
+      begin
+      Writeln ('Got : "',PP[i],'"');
+      Inc(i);
+      end;
+end.

+ 28 - 0
docs/olinuxex/ex62.pp

@@ -0,0 +1,28 @@
+Program Example62;
+
+{ Program to demonstrate the ReadLink function. }
+
+Uses oldlinux;
+
+Var F : Text;
+    S : String;
+    
+begin
+  Assign (F,'test.txt');
+  Rewrite (F);
+  Writeln (F,'This is written to test.txt');
+  Close(f);
+  { new.txt and test.txt are now the same file }
+  if not SymLink ('test.txt','new.txt') then
+    writeln ('Error when symlinking !');
+  S:=ReadLink('new.txt');
+  If S='' then 
+    Writeln ('Error reading link !')
+  Else   
+    Writeln ('Link points to : ',S);
+ { Now remove links }
+ If not Unlink ('new.txt') then
+   Writeln ('Error when unlinking !');
+ If not Unlink ('test.txt') then
+   Writeln ('Error when unlinking !');
+end.

+ 9 - 0
docs/olinuxex/ex63.pp

@@ -0,0 +1,9 @@
+Program Example63;
+
+{ Program to demonstrate the FRename function. }
+
+Uses oldlinux;
+
+begin
+  FRename (paramstr(1),paramstr(2));
+end.

+ 36 - 0
docs/olinuxex/ex64.pp

@@ -0,0 +1,36 @@
+program Example64;
+
+{ Example to demonstrate the SysInfo function }
+
+Uses oldlinux;
+
+Function Mb(L : Longint) : longint;
+
+begin
+  Mb:=L div (1024*1024);
+end;
+   
+Var Info : TSysInfo;
+    D,M,Secs,H : longint;
+
+begin
+  If Not SysInfo(Info) then 
+    Halt(1);
+  With Info do
+    begin
+    D:=Uptime div (3600*24);
+    UpTime:=UpTime mod (3600*24);
+    h:=uptime div 3600;
+    uptime:=uptime mod 3600;
+    m:=uptime div 60;
+    secs:=uptime mod 60;
+    Writeln('Uptime : ',d,'days, ',h,' hours, ',m,' min, ',secs,' s.');
+    Writeln('Loads  : ',Loads[1],'/',Loads[2],'/',Loads[3]);
+    Writeln('Total Ram  : ',Mb(totalram),'Mb.');
+    Writeln('Free Ram   : ',Mb(freeram),'Mb.');
+    Writeln('Shared Ram : ',Mb(sharedram),'Mb.');
+    Writeln('Buffer Ram : ',Mb(bufferram),'Mb.');
+    Writeln('Total Swap : ',Mb(totalswap),'Mb.');
+    Writeln('Free Swap  : ',Mb(freeswap),'Mb.');
+    end;
+end.

+ 31 - 0
docs/olinuxex/ex65.pp

@@ -0,0 +1,31 @@
+Program example64;
+
+{ Program to demonstrate the SigRaise function.}
+
+uses oldlinux;
+
+Var
+   oa,na : PSigActionRec;
+   
+Procedure DoSig(sig : Longint);cdecl;
+
+begin
+   writeln('Receiving signal: ',sig);
+end; 
+
+begin
+   new(na);
+   new(oa);
+   na^.handler.sh:=@DoSig;
+   na^.Sa_Mask:=0;
+   na^.Sa_Flags:=0;
+   na^.Sa_Restorer:=Nil;
+   SigAction(SigUsr1,na,oa);
+   if LinuxError<>0 then
+     begin
+     writeln('Error: ',linuxerror,'.');
+     halt(1);
+     end;
+   Writeln('Sending USR1 (',sigusr1,') signal to self.');
+   SigRaise(sigusr1);
+end.

+ 37 - 0
docs/olinuxex/ex66.pp

@@ -0,0 +1,37 @@
+Program Example66;
+
+{ Program to demonstrate the MMap function. }
+
+Uses oldlinux;
+
+Var S : String;
+    fd,Len : Longint;
+    args : tmmapargs;
+    P : PChar;
+        
+begin
+  S:='This is a string'#0;
+  Len:=Length(S);
+  fd:=fdOpen('testfile.txt',Open_wrOnly or open_creat);
+  If fd=-1 then 
+    Halt(1);
+  If fdWrite(fd,S[1],Len)=-1 then
+    Halt(2);
+  fdClose(fd);
+  fdOpen('testfile.txt',Open_rdOnly);
+  if fd=-1 then
+    Halt(3);
+  args.address:=0;
+  args.offset:=0;
+  args.size:=Len+1;
+  args.fd:=Fd;
+  args.flags:=MAP_PRIVATE;
+  args.prot:=PROT_READ or PROT_WRITE;
+  P:=Pchar(mmap(args));
+  If longint(P)=-1 then
+    Halt(4);
+  Writeln('Read in memory  :',P);
+  fdclose(fd);
+  if Not MUnMap(P,Len) Then
+    Halt(LinuxError);
+end.

+ 16 - 0
docs/olinuxex/ex67.pp

@@ -0,0 +1,16 @@
+Program Example67;
+
+uses oldlinux;
+
+{ Program to demonstrate the FSplit function. }
+
+var
+  Path,Name,Ext : string;
+  
+begin
+  FSplit(ParamStr(1),Path,Name,Ext);
+  WriteLn('Split ',ParamStr(1),' in:');
+  WriteLn('Path     : ',Path);
+  WriteLn('Name     : ',Name);
+  WriteLn('Extension: ',Ext);
+end.

+ 11 - 0
docs/olinuxex/ex68.pp

@@ -0,0 +1,11 @@
+Program Example68;
+
+{ Program to demonstrate the Octal function. }
+
+Uses oldlinux;
+
+begin
+  Writeln('Mode 777 : ', Octal(777));
+  Writeln('Mode 644 : ', Octal(644));
+  Writeln('Mode 755 : ', Octal(755));
+end.

+ 27 - 0
docs/olinuxex/ex69.pp

@@ -0,0 +1,27 @@
+Program Example69;
+
+{ Program to demonstrate the FNMatch function. }
+
+Uses oldlinux;
+
+  Procedure TestMatch(Pattern,Name : String);
+  
+  begin
+    Write ('"',Name,'" ');
+    If FNMatch (Pattern,Name) then
+      Write ('matches')
+    else
+      Write ('does not match');
+    Writeln(' "',Pattern,'".');
+  end;
+  
+begin
+  TestMatch('*','FileName');
+  TestMatch('.*','FileName');
+  TestMatch('*a*','FileName');
+  TestMatch('?ile*','FileName');
+  TestMatch('?','FileName');
+  TestMatch('.?','FileName');
+  TestMatch('?a*','FileName');
+  TestMatch('??*me?','FileName');
+end.

+ 21 - 0
docs/olinuxex/ex7.pp

@@ -0,0 +1,21 @@
+Program Example7;
+
+{ Program to demonstrate the Execve function. }
+
+Uses oldlinux, strings;
+
+Const Arg0 : PChar = '/bin/ls';
+      Arg1 : Pchar = '-l';
+      
+Var PP : PPchar;
+
+
+begin
+  GetMem (PP,3*SizeOf(Pchar));
+  PP[0]:=Arg0;
+  PP[1]:=Arg1;
+  PP[3]:=Nil;
+  { Execute '/bin/ls -l', with current environment }
+  { Envp is defined in system.inc }
+  ExecVe ('/bin/ls',pp,envp);
+end.

+ 22 - 0
docs/olinuxex/ex70.pp

@@ -0,0 +1,22 @@
+Program Example70;
+
+{ Program to demonstrate the StringToPPchar function. }
+
+Uses oldlinux;
+
+Var S : String;
+    P : PPChar;
+    I : longint;
+    
+begin
+  // remark whitespace at end.
+  S:='This is a string with words. ';
+  P:=StringToPPChar(S);
+  I:=0;
+  While P[i]<>Nil do
+    begin
+    Writeln('Word ',i,' : ',P[i]);
+    Inc(I);
+    end;
+  FreeMem(P,i*SizeOf(Pchar));  
+end.

+ 71 - 0
docs/olinuxex/ex71.pp

@@ -0,0 +1,71 @@
+program TestC{lone};
+
+uses
+  oldlinux, 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,Nil,Nil,Nil,Nil);
+  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,Nil,Nil,Nil,Nil);
+    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.

+ 27 - 0
docs/olinuxex/ex72.pp

@@ -0,0 +1,27 @@
+program example72;
+
+{ Program to demonstrate the NanoSleep function. } 
+
+uses oldlinux;
+
+Var
+  Req,Rem : TimeSpec;
+  Res : Longint;
+  
+begin
+  With Req do
+    begin
+    tv_sec:=10;
+    tv_nsec:=100;
+    end;
+  Write('NanoSleep returned : ');
+  Flush(Output);
+  Res:=(NanoSleep(Req,rem));
+  Writeln(res);
+  If (res<>0) then
+    With rem do
+      begin
+      Writeln('Remaining seconds     : ',tv_sec);
+      Writeln('Remaining nanoseconds : ',tv_nsec);
+      end;
+end.

+ 20 - 0
docs/olinuxex/ex8.pp

@@ -0,0 +1,20 @@
+Program Example8;
+
+{ Program to demonstrate the Execv function. }
+
+Uses oldlinux, strings;
+
+Const Arg0 : PChar = '/bin/ls';
+      Arg1 : Pchar = '-l';
+      
+Var PP : PPchar;
+
+
+begin
+  GetMem (PP,3*SizeOf(Pchar));
+  PP[0]:=Arg0;
+  PP[1]:=Arg1;
+  PP[3]:=Nil;
+  { Execute '/bin/ls -l', with current environment }
+  Execv ('/bin/ls',pp);
+end.

+ 22 - 0
docs/olinuxex/ex9.pp

@@ -0,0 +1,22 @@
+Program Example9;
+
+{ Program to demonstrate the Execvp function. }
+
+Uses oldlinux, strings;
+
+Const Arg0 : PChar = 'ls';
+      Arg1 : Pchar = '-l';
+      
+Var PP : PPchar;
+
+
+begin
+  GetMem (PP,3*SizeOf(Pchar));
+  PP[0]:=Arg0;
+  PP[1]:=Arg1;
+  PP[3]:=Nil;
+  { Execute 'ls -l', with current environment. }
+  { 'ls' is looked for in PATH environment variable.}
+  { Envp is defined in the system unit. }
+  Execvp ('ls',pp,envp);
+end.

+ 2 - 0
docs/olinuxex/foot.tex

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

+ 3 - 0
docs/olinuxex/head.tex

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

+ 8 - 0
docs/olinuxex/newex

@@ -0,0 +1,8 @@
+#!/bin/sh
+if [ -e ex${1}.pp ]; then
+  mv ex${1}.pp ex${1}.pp.orig
+fi
+sed -e s/Example/Example$1/ -e s/\\\*\\\*\\\*/$2/ <template.pp >ex${1}.pp
+echo "ex${1}.pp contains an example of the $2 function." >>README
+joe ex${1}.pp
+ppc386 ex${1}.pp && ex${1}

+ 167 - 0
docs/olinuxex/serial.pp

@@ -0,0 +1,167 @@
+program Terminal_test;
+{******************************************************************************
+ * Really really budget attempt at Serial IO with Linux and FPC.
+ * My first FPC program. Re-built and refined on 12/6/99
+ * Written under X windows with nedit 5.0.2 (Not a bad editor)
+ * This SHOULD work without including the CRT Unit, However it has problems
+ * With reading from the keyboard unless the CRT unit is included ?!?
+ *
+ * Designed to talk to an RS485 Buss, using RTS as the Tx/Rx Select Pin
+ * No Copyrights or warrantys.
+ * Let me know if it's of some use to you.
+ * Brad Campbell ([email protected])
+ ******************************************************************************}
+uses oldlinux, Crt;
+
+Const DTR : Cardinal = TIOCM_DTR;
+Const RTS : Cardinal = TIOCM_RTS;
+
+Var	FD		: Longint;
+	InChr		: String[1];
+	InStr		: String[80];
+	Quit		: Boolean;
+	InLen, Loop	: Integer;
+	tios		: Termios;
+	fds		: FDSet;
+
+
+Procedure DumpFlags;
+begin
+IOCtl(FD,TIOCMGET,@tios);
+Writeln('Input   Flags    : $',hexstr(tios.c_iflag,8));
+Writeln('Output  Flags    : $',hexstr(tios.c_oflag,8));
+Writeln('Local   Flags    : $',hexstr(tios.c_lflag,8));
+Writeln('Control Flags    : $',hexstr(tios.c_cflag,8));
+End;
+
+
+Procedure RS485RX;
+Begin
+IOCtl(FD,TIOCMBIS,@RTS);
+End;
+
+Procedure RS485TX;
+Begin
+IOCtl(FD,TIOCMBIC,@RTS);
+End;
+
+
+Procedure DtrOn;
+Begin
+IOCtl(FD,TIOCMBIS,@DTR);
+End;
+
+Procedure DtrOff;
+Begin
+IOCtl(FD,TIOCMBIC,@DTR);
+End;
+
+Procedure SendToRemote(OutString : String);
+Begin
+Rs485TX;	{Switch Buss to Transmit}
+if fdWrite(FD,OutString[1],Length(OutString)) <> Length(OutString) then 
+	Writeln('Write Error');
+{Write(OutString);} {Uncomment for Local Echo}
+TCDrain(FD);	{Block Program until all data sent out port has left UART}
+RS485RX;	{Switch Buss back to Recieve}
+End;
+
+
+{ Not limited to baud selection I have here, it's just all I use }
+Procedure SetBaudrate;
+Var	NewBaud : LongInt;
+Begin
+Writeln;
+Writeln('New Baud Rate (300,1200,2400,4800, 9600,19200,38400) ? ');
+Readln(NewBaud);
+Case NewBaud of 
+   300 : NewBaud := B300;
+  1200 : NewBaud := B1200;
+  2400 : NewBaud := B2400;
+  4800 : NewBaud := B4800;
+  9600 : NewBaud := B9600;
+ 19200 : NewBaud := B19200;
+ 38400 : NewBaud := B38400;
+Else
+	Begin
+	Writeln('Invalid Baud Rate. Baud not Changed');
+	Writeln;
+	NewBaud := 0;
+	End;
+End;
+
+{ Sets Baud Rate Here }
+If NewBaud <> 0 then 
+	Begin
+		IOCtl(FD,TCGETS,@tios);		{Get IOCTL TermIOS Settings}
+		CFSetOSpeed(tios,NewBaud);	{Set Relevant Bits}
+		IOCtl(FD,TCSETS,@tios);		{Put them back with IOCTL}
+		Writeln('New Baudrate ',HexStr(NewBaud,2),' Set');
+		{This line just prints what the constant equates to for
+		 Information Only}
+	End;
+End;
+
+
+Begin
+Quit := False;
+Writeln('Brad''s Dumb Terminal Test prog v0.2');
+Writeln('Ctrl-C to exit program');
+Writeln('Ctrl-D to set Baud Rate');
+Writeln('Uses /dev/ttyS0 (Com 1)');
+Writeln;
+
+FD:=fdOpen('/dev/ttyS0',Open_RdWr or Open_NonBlock or Open_Excl);
+{Open Port Read/Write, Not Blocking and Exclusive}
+
+if FD > 0 then Begin
+
+Writeln('Port Open');
+
+FLock(FD,LOCK_EX);
+{Attempt to Lock the port, I'm not sure this is strictly nessecary}
+
+Writeln('Port Locked');
+
+{Set Comms Parms, 9600 Baud, 8 Data Bits, Reciever Enabled,
+ Modem Control Lines Ignored}
+{Read man 3 termios for More options}
+
+IOCtl(FD,TCGETS,@tios);
+tios.c_cflag := B9600 Or CS8 Or CREAD Or CLOCAL;
+tios.c_lflag := 0;
+tios.c_oflag := 0;
+tios.c_iflag := 0;
+IOCtl(FD,TCSETS,@tios);
+
+DumpFlags;	{This is for information only and dumps the contents of
+		 the Termios registers}
+
+Repeat
+FD_Zero (FDS);		{Clear File Descriptors Array}
+FD_Set (0,FDS);		{Input from Keyboard}
+FD_SET (FD,FDS);	{Input from Serial Port}
+
+Select(FD+1,@FDS,nil,nil,nil);	{Will Wait for input from above}
+
+If FD_ISSET(0,FDS) then		{Has there been a key pressed ?}
+	If fdRead(0,InChr[1],80) <> 0 then
+		Begin
+       		if InChr[1] = Chr(3) then Quit := True;
+		if InChr[1] = Chr(4) then SetBaudRate;
+		SendToRemote(InChr[1]);
+		End;
+
+If FD_ISSET(FD,FDS) then	{Have we data waiting in UART ? }
+	Begin
+		InLen := fdRead(FD,InStr[1],80); 
+		If InLen > 0 then 
+		For Loop := 1 to Inlen do
+        	Write(InStr[Loop]);
+	End;
+Until Quit = True;	{Were Outa Here}
+FLock(FD,LOCK_UN);	{Unlock Port}
+fdClose(FD);		{Close Port}
+End
+Else Writeln('Open Port Error');	{We failed to Open/Lock the UART}
+End.

+ 8 - 0
docs/olinuxex/template.pp

@@ -0,0 +1,8 @@
+Program Example;
+
+{ Program to demonstrate the *** function. }
+
+Uses oldlinux;
+
+begin
+end.