Browse Source

+ initial check-in

michael 21 years ago
parent
commit
12e7e06a6b

+ 73 - 0
docs/unutilex/Makefile

@@ -0,0 +1,73 @@
+#######################################################################
+#
+# Makefile to compile all examples and convert them to LaTeX
+# 
+#######################################################################
+
+# Compiler
+
+ifndef FPC
+ifdef PP
+FPC=$(PP)
+endif
+endif
+ifndef FPC
+FPCPROG:=$(strip $(wildcard $(addsuffix /fpc$(SRCEXEEXT),$(SEARCHPATH))))
+ifneq ($(FPCPROG),)
+FPCPROG:=$(firstword $(FPCPROG))
+FPC:=$(shell $(FPCPROG) -PB)
+ifneq ($(findstring Error,$(FPC)),)
+override FPC=ppc386
+endif
+else
+override FPC=ppc386
+endif
+endif
+override FPC:=$(subst $(SRCEXEEXT),,$(FPC))
+override FPC:=$(subst \,/,$(FPC))$(SRCEXEEXT)
+
+# 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=ex3 ex34 ex4 ex47 ex48 ex67 ex69 ex70 
+
+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
+	$(FPC) $(PPOPTS) $*
+
+$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
+	$(PP2TEX) $*

+ 80 - 0
docs/unutilex/README

@@ -0,0 +1,80 @@
+These are the example programs that appear in the FPC documentation.
+ 
+Units guide, Linux unit :
+
+ex1.pp contains an example of the FpGetEpochTime function.
+ex2.pp contains an example of the FpGetTimeOfDay function.
+ex3.pp contains an example of the FpEpochToLocal function.
+ex4.pp contains an example of the FpLocalToEpoch function.
+ex5.pp contains an example of the FpGetTime function.
+ex6.pp contains an example of the FpGetDate function.
+ex7.pp contains an example of the FpExecve function.
+ex8.pp contains an example of the FpExecv function.
+ex9.pp contains an example of the FpExecvp function.
+ex10.pp contains an example of the FpExecl function.
+ex11.pp contains an example of the FpExecle function.
+ex11.pp contains an example of the FpExeclp function.
+ex13.pp contains an example of the FpShell function.
+ex14.pp contains an example of the FpFork function.
+ex15.pp contains an example of the FpNice, FpSet- and FpGetPriority functions.
+ex16.pp contains an example of the FpGetPid and FpGetPPid functions.
+ex17.pp contains an example of the FpGetUid and FpGetEUid functions.
+ex18.pp contains an example of the FpGetGid and FpGetEgid functions.
+ex19.pp contains an example of the FpOpen, FpWrite and FpCLose functions.
+ex20.pp contains an example of the FpRead and FpTuncate functions.
+ex21.pp contains an example of the FpLink and FpUnLink functions.
+ex22.pp contains an example of the FpSymLink and FpUnLink functions.
+ex23.pp contains an example of the FpChmod function.
+ex24.pp contains an example of the FpChown function.
+ex25.pp contains an example of the FpUTime function.
+ex26.pp contains an example of the FpAccess function.
+ex27.pp contains an example of the FpUmask function.
+ex28.pp contains an example of the FpFStat function.
+ex29.pp contains an example of the FpLStat function.
+ex30.pp contains an example of the FpFSStat function.
+ex31.pp contains an example of the FpDup function.
+ex32.pp contains an example of the FpDup2 function.
+ex33.pp contains an example of the FpSelect function.
+ex34.pp contains an example of the FpSelectText function.
+ex35.pp contains an example of the FpOpenDir, FpReadDir FpTelldir and FpSeekDir functions.
+ex36.pp contains an example of the FpAssignPipe function.
+ex37.pp contains an example of the FpPOpen and PClose functions.
+ex38.pp contains an example of the FpAssignStream function.
+ex39.pp contains an example of the FpGetDomainName function.
+ex40.pp contains an example of the FpGetHostName function.
+ex41.pp contains an example of the FpGetEnv function.
+ex42.pp contains an example of the FpSysInfo function.
+ex43.pp contains an example of the FpUname function.
+ex44.pp contains an example of the FpOctal function.
+ex45.pp contains an example of the FpFExpand function.
+ex46.pp contains an example of the FpFSearch function.
+ex47.pp contains an example of the FpDirName function.
+ex48.pp contains an example of the FpBaseName function.
+ex49.pp contains an example of the FpGlob function.
+ex51.pp contains an example of the FpStringToPPChar function.
+ex52.pp contains an example of the FpGetFS function.
+ex53.pp contains an example of the FpS_ISLNK and related functions.
+ex54.pp contains an example of the FpIOCtl function.
+ex55.pp contains an example of the FpTCGetAttr,TCSetAttr,CFMakeRaw functions.
+ex56.pp contains an example of the FpShell function.
+ex57.pp contains an example of the FpSigAction function.
+ex58.pp contains an example of the FpSignal function.
+ex59.pp contains an example of the FpAlarm function.
+ex60.pp contains an example of the FpGetDateTime function.
+ex61.pp contains an example of the FpCreateShellArgV function.
+ex62.pp contains an example of the FpReadLink function.
+ex63.pp contains an example of the FpFRename function.
+ex64.pp contains an example of the FpSysInfo function.
+ex64.pp contains an example of the FpSigRaise function.
+ex66.pp contains an example of the FpMMap function.
+ex67.pp contains an example of the FpFSplit function.
+ex68.pp contains an example of the FpOctal function.
+ex69.pp contains an example of the FpFNMatch function.
+ex70.pp contains an example of the FpStringToPPchar function.
+ex71.pp contains an example of the Fpclone function.
+ex72.pp contains an example of the FpNanoSleep function.
+ex73.pp contains an example of the FpSleep function.
+ex74.pp contains an example of the FpGetGroups function.
+
+serial.pp contains an example of serial port programming in FPC.
+ex75.pp contains an example of the setsid function.

+ 13 - 0
docs/unutilex/ex3.pp

@@ -0,0 +1,13 @@
+Program Example3;
+
+{ Program to demonstrate the EpochToLocal function. }
+
+Uses Unix,UnixUtil;
+
+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.

+ 22 - 0
docs/unutilex/ex34.pp

@@ -0,0 +1,22 @@
+Program Example33;
+
+{ Program to demonstrate the SelectText function. }
+
+Uses Unix;
+
+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.tv_sec:=2;
+  tv.tv_sec:=0;
+  if SelectText (Input,@tv)>0 then 
+    Writeln ('Thank you !')
+  else
+    Writeln ('Too late !');
+end.

+ 19 - 0
docs/unutilex/ex4.pp

@@ -0,0 +1,19 @@
+Program Example4;
+
+{ Program to demonstrate the LocalToEpoch function. }
+
+Uses UnixUtil;
+
+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.

+ 12 - 0
docs/unutilex/ex47.pp

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

+ 12 - 0
docs/unutilex/ex48.pp

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

+ 16 - 0
docs/unutilex/ex67.pp

@@ -0,0 +1,16 @@
+Program Example67;
+
+uses UnixUtil;
+
+{ 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.

+ 27 - 0
docs/unutilex/ex69.pp

@@ -0,0 +1,27 @@
+Program Example69;
+
+{ Program to demonstrate the FNMatch function. }
+
+Uses unixutil;
+
+  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.

+ 22 - 0
docs/unutilex/ex70.pp

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

+ 2 - 0
docs/unutilex/foot.tex

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

+ 3 - 0
docs/unutilex/head.tex

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

+ 8 - 0
docs/unutilex/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}