+ Initial check-in

This commit is contained in:
michael 2004-10-22 21:57:33 +00:00
parent df286942a7
commit 8c0567c570
70 changed files with 1656 additions and 0 deletions

75
docs/bunixex/Makefile Normal file
View File

@ -0,0 +1,75 @@
#######################################################################
#
# 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=ex1 ex16 ex17 ex18 ex19 ex20 ex21 ex23 ex24 ex25 ex26 ex27 ex28 \
ex31 ex32 ex33 ex35 ex36 ex41 ex53 ex54 ex57 ex58 ex59 ex7 ex72 \
ex73 ex8
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
docs/bunixex/README Normal file
View File

@ -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.

10
docs/bunixex/ex1.pp Normal file
View File

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

9
docs/bunixex/ex16.pp Normal file
View File

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

9
docs/bunixex/ex17.pp Normal file
View File

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

9
docs/bunixex/ex18.pp Normal file
View File

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

19
docs/bunixex/ex19.pp Normal file
View File

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

46
docs/bunixex/ex20.pp Normal file
View File

@ -0,0 +1,46 @@
Program Example20;
{ Program to demonstrate the fdRead and fdTruncate functions. }
Uses BaseUnix;
Const Data : string[10] = '1234567890';
Var FD : cint;
l : longint;
begin
FD:=fpOpen('test.dat',o_wronly or o_creat,&666);
if fd>0 then
begin
{ Fill file with data }
for l:=1 to 10 do
if fpWrite (FD,Data[1],10)<>10 then
begin
writeln ('Error when writing !');
halt(1);
end;
fpClose(FD);
FD:=fpOpen('test.dat',o_rdonly);
{ Read data again }
If FD>0 then
begin
For l:=1 to 5 do
if fpRead (FD,Data[1],10)<>10 then
begin
Writeln ('Error when Reading !');
Halt(2);
end;
fpClose(FD);
{ Truncating file at 60 bytes }
{ For truncating, file must be open or write }
FD:=fpOpen('test.dat',o_wronly,&666);
if FD>0 then
begin
if fpfTruncate(FD,60)<>0 then
Writeln('Error when truncating !');
fpClose (FD);
end;
end;
end;
end.

31
docs/bunixex/ex21.pp Normal file
View File

@ -0,0 +1,31 @@
Program Example21;
{ Program to demonstrate the Link and UnLink functions. }
Uses BaseUnix;
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 fpLink ('test.txt','new.txt')<>0 then
writeln ('Error when linking !');
{ Removing test.txt still leaves new.txt }
If fpUnlink ('test.txt')<>0 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 FPUnlink ('new.txt')<>0 then
Writeln ('Error when unlinking !');
end.

19
docs/bunixex/ex23.pp Normal file
View File

@ -0,0 +1,19 @@
Program Example23;
{ Program to demonstrate the Chmod function. }
Uses BaseUnix,Unix;
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);
fpChmod ('testex21',&777);
{ File is now executable }
execl ('./testex21');
end.

29
docs/bunixex/ex24.pp Normal file
View File

@ -0,0 +1,29 @@
Program Example24;
{ Program to demonstrate the Chown function. }
Uses BaseUnix;
Var UID : TUid;
GID : TGid;
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 fpChown ('test.txt',UID,GID)<>0 then
if fpgeterrno=ESysEPERM then
Writeln ('You are not root !')
else
Writeln ('Chmod failed with exit code : ',fpgeterrno)
else
Writeln ('Changed owner successfully !');
end.

24
docs/bunixex/ex25.pp Normal file
View File

@ -0,0 +1,24 @@
Program Example25;
{ Program to demonstrate the UTime function. }
Uses BaseUnix,Unix,UnixUtil;
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 Fputime('ex25.pp',@utim)<>0 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
docs/bunixex/ex26.pp Normal file
View File

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

10
docs/bunixex/ex27.pp Normal file
View File

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

39
docs/bunixex/ex28.pp Normal file
View File

@ -0,0 +1,39 @@
program example28;
{ Program to demonstrate the FStat function. }
uses BaseUnix;
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 fpstat ('test.fil',info)<>0 then
begin
writeln('Fstat failed. Errno : ',fpgeterrno);
halt (1);
end;
writeln;
writeln ('Result of fstat on file ''test.fil''.');
writeln ('Inode : ',info.st_ino);
writeln ('Mode : ',info.st_mode);
writeln ('nlink : ',info.st_nlink);
writeln ('uid : ',info.st_uid);
writeln ('gid : ',info.st_gid);
writeln ('rdev : ',info.st_rdev);
writeln ('Size : ',info.st_size);
writeln ('Blksize : ',info.st_blksize);
writeln ('Blocks : ',info.st_blocks);
writeln ('atime : ',info.st_atime);
writeln ('mtime : ',info.st_mtime);
writeln ('ctime : ',info.st_ctime);
{ Remove file }
erase (f);
end.

15
docs/bunixex/ex31.pp Normal file
View File

@ -0,0 +1,15 @@
program Example31;
{ Program to demonstrate the Dup function. }
uses baseunix;
var f : text;
begin
if fpdup (output,f)<>0 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
docs/bunixex/ex32.pp Normal file
View File

@ -0,0 +1,22 @@
program Example31;
{ Program to demonstrate the Dup function. }
uses BaseUnix;
var f : text;
i : longint;
begin
Assign (f,'text.txt');
Rewrite (F);
For i:=1 to 10 do writeln (F,'Line : ',i);
if fpdup2 (output,f)<>0 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.}
fpUnlink ('text.txt');
end.

25
docs/bunixex/ex33.pp Normal file
View File

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

46
docs/bunixex/ex35.pp Normal file
View File

@ -0,0 +1,46 @@
Program Example35;
{ Program to demonstrate the
OpenDir,ReadDir, SeekDir and TellDir functions. }
Uses BaseUnix;
Var TheDir : PDir;
ADirent : PDirent;
Entry : Longint;
begin
TheDir:=fpOpenDir('./.');
Repeat
// Entry:=fpTellDir(TheDir);
ADirent:=fpReadDir (TheDir^);
If ADirent<>Nil then
With ADirent^ do
begin
Writeln ('Entry No : ',Entry);
Writeln ('Inode : ',d_fileno);
// Writeln ('Offset : ',d_off);
Writeln ('Reclen : ',d_reclen);
Writeln ('Name : ',pchar(@d_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
// fpSeekDir (TheDir,Entry); // not implemented for various platforms
ADirent:=fpReadDir (TheDir^);
If ADirent<>Nil then
With ADirent^ do
begin
Writeln ('Entry No : ',Entry);
Writeln ('Inode : ',d_fileno);
// Writeln ('Offset : ',off);
Writeln ('Reclen : ',d_reclen);
Writeln ('Name : ',pchar(@d_name[0]));
end;
end;
Until Entry=-1;
fpCloseDir (TheDir^);
end.

25
docs/bunixex/ex36.pp Normal file
View File

@ -0,0 +1,25 @@
Program Example36;
{ Program to demonstrate the AssignPipe function. }
Uses BaseUnix,Unix;
Var pipi,pipo : Text;
s : String;
begin
Writeln ('Assigning Pipes.');
If assignpipe(pipi,pipo)<>0 then
Writeln('Error assigning pipes !',fpgeterrno);
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.

9
docs/bunixex/ex41.pp Normal file
View File

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

27
docs/bunixex/ex53.pp Normal file
View File

@ -0,0 +1,27 @@
Program Example53;
{ Program to demonstrate the S_ISLNK function. }
Uses BaseUnix,Unix;
Var Info : Stat;
begin
if fpLStat (paramstr(1),@info)=0 then
begin
if fpS_ISLNK(info.st_mode) then
Writeln ('File is a link');
if fpS_ISREG(info.st_mode) then
Writeln ('File is a regular file');
if fpS_ISDIR(info.st_mode) then
Writeln ('File is a directory');
if fpS_ISCHR(info.st_mode) then
Writeln ('File is a character device file');
if fpS_ISBLK(info.st_mode) then
Writeln ('File is a block device file');
if fpS_ISFIFO(info.st_mode) then
Writeln ('File is a named pipe (FIFO)');
if fpS_ISSOCK(info.st_mode) then
Writeln ('File is a socket');
end;
end.

19
docs/bunixex/ex54.pp Normal file
View File

@ -0,0 +1,19 @@
Program Example54;
uses BaseUnix,Termio;
{ Program to demonstrate the IOCtl function. }
var
tios : Termios;
begin
{$ifdef FreeBSD}
fpIOCtl(1,TIOCGETA,@tios); // these constants are very OS dependant.
// see the tcgetattr example for a better way
{$endif}
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.

38
docs/bunixex/ex57.pp Normal file
View File

@ -0,0 +1,38 @@
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 BaseUnix;
Var
oa,na : PSigActionRec;
Procedure DoSig(sig : cint);cdecl;
begin
writeln('Receiving signal: ',sig);
end;
begin
new(na);
new(oa);
na^.sa_Handler:=TSigaction(@DoSig);
fillchar(na^.Sa_Mask,sizeof(na^.sa_mask),#0);
na^.Sa_Flags:=0;
{$ifdef Linux} // Linux specific
na^.Sa_Restorer:=Nil;
{$endif}
if fpSigAction(SigUsr1,na,oa)<>0 then
begin
writeln('Error: ',fpgeterrno,'.');
halt(1);
end;
Writeln ('Send USR1 signal or press <ENTER> to exit');
readln;
end.

27
docs/bunixex/ex58.pp Normal file
View File

@ -0,0 +1,27 @@
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 BaseUnix;
Procedure DoSig(sig : cint);cdecl;
begin
writeln('Receiving signal: ',sig);
end;
begin
if fpSignal(SigUsr1,SignalHandler(@DoSig))=signalhandler(SIG_ERR) then
begin
writeln('Error: ',fpGetErrno,'.');
halt(1);
end;
Writeln ('Send USR1 signal or press <ENTER> to exit');
readln;
end.

21
docs/bunixex/ex59.pp Normal file
View File

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

21
docs/bunixex/ex7.pp Normal file
View File

@ -0,0 +1,21 @@
Program Example7;
{ Program to demonstrate the Execve function. }
Uses BaseUnix, 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 }
fpExecVe ('/bin/ls',pp,envp);
end.

27
docs/bunixex/ex72.pp Normal file
View File

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

17
docs/bunixex/ex73.pp Normal file
View File

@ -0,0 +1,17 @@
program example73;
{ Program to demonstrate the FpSleep function. }
uses BaseUnix;
Var
Res : Longint;
begin
Write('Sleep returned : ');
Flush(Output);
Res:=(fpSleep(10));
Writeln(res);
If (res<>0) then
Writeln('Remaining seconds : ',res);
end.

20
docs/bunixex/ex8.pp Normal file
View File

@ -0,0 +1,20 @@
Program Example8;
{ Program to demonstrate the Execv function. }
Uses Unix, 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 }
fpExecv ('/bin/ls',pp);
end.

2
docs/bunixex/foot.tex Normal file
View File

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

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

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

8
docs/bunixex/newex Normal file
View File

@ -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}

75
docs/unixex/Makefile Normal file
View File

@ -0,0 +1,75 @@
#######################################################################
#
# 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=ex1 ex10 ex11 ex12 ex15 ex22 ex29 ex36 ex37 ex38 ex39 ex40 ex45 ex46\
ex49 ex5 ex56 ex6 ex60 ex61 ex62 ex65 ex66 ex76 ex77 ex79 ex8 ex80 \
ex9 ex91
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
docs/unixex/README Normal file
View File

@ -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.

51
docs/unixex/doit Normal file
View File

@ -0,0 +1,51 @@
rm ex13.pp
rm ex14.pp
rm ex16.pp
rm ex17.pp
rm ex18.pp
rm ex19.pp
rm ex2.pp
rm ex20.pp
rm ex21.pp
rm ex23.pp
rm ex24.pp
rm ex25.pp
rm ex26.pp
rm ex27.pp
rm ex28.pp
rm ex3.pp
rm ex30.pp
rm ex31.pp
rm ex32.pp
rm ex33.pp
rm ex34.pp
rm ex35.pp
rm ex4.pp
rm ex41.pp
rm ex42.pp
rm ex43.pp
rm ex44.pp
rm ex47.pp
rm ex48.pp
rm ex51.pp
rm ex52.pp
rm ex53.pp
rm ex54.pp
rm ex55.pp
rm ex57.pp
rm ex58.pp
rm ex59.pp
rm ex63.pp
rm ex64.pp
rm ex67.pp
rm ex68.pp
rm ex69.pp
rm ex7.pp
rm ex70.pp
rm serial.pp
rm ex71.pp
rm ex73.pp
rm ex72.pp
rm ex74.pp
rm ex75.pp
rm ex78.pp

10
docs/unixex/ex1.pp Normal file
View File

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

11
docs/unixex/ex10.pp Normal file
View File

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

12
docs/unixex/ex11.pp Normal file
View File

@ -0,0 +1,12 @@
Program Example11;
{ Program to demonstrate the Execle function. }
Uses Unix, 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
docs/unixex/ex12.pp Normal file
View File

@ -0,0 +1,12 @@
Program Example12;
{ Program to demonstrate the Execlp function. }
Uses Unix, 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.

14
docs/unixex/ex15.pp Normal file
View File

@ -0,0 +1,14 @@
Program Example15;
{ Program to demonstrate the Nice and Get/SetPriority functions. }
Uses BaseUnix,Unix;
begin
writeln ('Setting priority to 5');
fpsetpriority (prio_process,fpgetpid,5);
writeln ('New priority = ',fpgetpriority (prio_process,fpgetpid));
writeln ('Doing nice 10');
fpnice (10);
writeln ('New Priority = ',fpgetpriority (prio_process,fpgetpid));
end.

33
docs/unixex/ex22.pp Normal file
View File

@ -0,0 +1,33 @@
Program Example22;
{ Program to demonstrate the SymLink and UnLink functions. }
Uses baseunix,Unix;
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 fpSymLink ('test.txt','new.txt')<>0 then
writeln ('Error when symlinking !');
{ Removing test.txt still leaves new.txt
Pointing now to a non-existent file ! }
If fpUnlink ('test.txt')<>0 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 fpUnlink ('new.txt')<>0 then
Writeln ('Error when unlinking !');
end.

63
docs/unixex/ex29.pp Normal file
View File

@ -0,0 +1,63 @@
program example29;
{ Program to demonstrate the LStat function. }
uses BaseUnix,Unix;
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 fpstat ('test.fil',info)<>0 then
begin
writeln('Fstat failed. Errno : ',fpgeterrno);
halt (1);
end;
writeln;
writeln ('Result of stat on file ''test.fil''.');
writeln ('Inode : ',info.st_ino);
writeln ('Mode : ',info.st_mode);
writeln ('nlink : ',info.st_nlink);
writeln ('uid : ',info.st_uid);
writeln ('gid : ',info.st_gid);
writeln ('rdev : ',info.st_rdev);
writeln ('Size : ',info.st_size);
writeln ('Blksize : ',info.st_blksize);
writeln ('Blocks : ',info.st_blocks);
writeln ('atime : ',info.st_atime);
writeln ('mtime : ',info.st_mtime);
writeln ('ctime : ',info.st_ctime);
If fpSymLink ('test.fil','test.lnk')<>0 then
writeln ('Link failed ! Errno :',fpgeterrno);
if fplstat ('test.lnk',@info)<>0 then
begin
writeln('LStat failed. Errno : ',fpgeterrno);
halt (1);
end;
writeln;
writeln ('Result of fstat on file ''test.lnk''.');
writeln ('Inode : ',info.st_ino);
writeln ('Mode : ',info.st_mode);
writeln ('nlink : ',info.st_nlink);
writeln ('uid : ',info.st_uid);
writeln ('gid : ',info.st_gid);
writeln ('rdev : ',info.st_rdev);
writeln ('Size : ',info.st_size);
writeln ('Blksize : ',info.st_blksize);
writeln ('Blocks : ',info.st_blocks);
writeln ('atime : ',info.st_atime);
writeln ('mtime : ',info.st_mtime);
writeln ('ctime : ',info.st_ctime);
{ Remove file and link }
erase (f);
fpunlink ('test.lnk');
end.

25
docs/unixex/ex36.pp Normal file
View File

@ -0,0 +1,25 @@
Program Example36;
{ Program to demonstrate the AssignPipe function. }
Uses BaseUnix,Unix;
Var pipi,pipo : Text;
s : String;
begin
Writeln ('Assigning Pipes.');
If assignpipe(pipi,pipo)<>0 then
Writeln('Error assigning pipes !',fpgeterrno);
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
docs/unixex/ex37.pp Normal file
View File

@ -0,0 +1,35 @@
Program Example37;
{ Program to demonstrate the Popen function. }
uses BaseUnix,Unix;
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);
fpchmod ('test21a',&755);
popen (f,'./test21a arg1 arg2','W');
if fpgeterrno<>0 then
writeln ('error from POpen : errno : ', fpgeterrno);
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
docs/unixex/ex38.pp Normal file
View File

@ -0,0 +1,51 @@
Program Example38;
{ Program to demonstrate the AssignStream function. }
Uses BaseUnix,Unix;
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 fpgeterrno<>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
docs/unixex/ex39.pp Normal file
View File

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

9
docs/unixex/ex40.pp Normal file
View File

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

9
docs/unixex/ex45.pp Normal file
View File

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

9
docs/unixex/ex46.pp Normal file
View File

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

22
docs/unixex/ex49.pp Normal file
View File

@ -0,0 +1,22 @@
Program Example49;
{ Program to demonstrate the Glob and GlobFree functions. }
Uses BaseUnix,Unix;
Var G1,G2 : PGlob;
begin
G1:=Glob ('*');
if fpgeterrno=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
docs/unixex/ex5.pp Normal file
View File

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

13
docs/unixex/ex56.pp Normal file
View File

@ -0,0 +1,13 @@
program example56;
uses Unix;
{ 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.

12
docs/unixex/ex6.pp Normal file
View File

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

13
docs/unixex/ex60.pp Normal file
View File

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

24
docs/unixex/ex61.pp Normal file
View File

@ -0,0 +1,24 @@
Program ex61;
{ Example program to demonstrate the CreateShellArgV function }
// note: CreateShellArgV is reasonbly obsolete in 1.9.x due to the new fpexec functions
uses Unix;
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
docs/unixex/ex62.pp Normal file
View File

@ -0,0 +1,28 @@
Program Example62;
{ Program to demonstrate the ReadLink function. }
Uses BaseUnix,Unix;
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 fpSymLink ('test.txt','new.txt')<>0 then
writeln ('Error when symlinking !');
S:=fpReadLink('new.txt');
If S='' then
Writeln ('Error reading link !')
Else
Writeln ('Link points to : ',S);
{ Now remove links }
If fpUnlink ('new.txt')<>0 then
Writeln ('Error when unlinking !');
If fpUnlink ('test.txt')<>0 then
Writeln ('Error when unlinking !');
end.

33
docs/unixex/ex65.pp Normal file
View File

@ -0,0 +1,33 @@
Program example64;
{ Program to demonstrate the SigRaise function.}
uses Unix,BaseUnix;
Var
oa,na : PSigActionRec;
Procedure DoSig(sig : Longint);cdecl;
begin
writeln('Receiving signal: ',sig);
end;
begin
new(na);
new(oa);
na^.sa_handler:=TSigaction(@DoSig);
fillchar(na^.Sa_Mask,sizeof(na^.Sa_Mask),#0);
na^.Sa_Flags:=0;
{$ifdef Linux}
// this member is linux only, and afaik even there arcane
na^.Sa_Restorer:=Nil;
{$endif}
if fpSigAction(SigUsr1,na,oa)<>0 then
begin
writeln('Error: ',fpgeterrno);
halt(1);
end;
Writeln('Sending USR1 (',sigusr1,') signal to self.');
SigRaise(sigusr1);
end.

33
docs/unixex/ex66.pp Normal file
View File

@ -0,0 +1,33 @@
Program Example66;
{ Program to demonstrate the MMap function. }
Uses BaseUnix,Unix;
Var S : String;
fd : cint;
Len : longint;
// args : tmmapargs;
P : PChar;
begin
s:='This is the string';
Len:=Length(S);
fd:=fpOpen('testfile.txt',O_wrOnly or o_creat);
If fd=-1 then
Halt(1);
If fpWrite(fd,S[1],Len)=-1 then
Halt(2);
fpClose(fd);
fd:=fpOpen('testfile.txt',O_rdOnly);
if fd=-1 then
Halt(3);
P:=Pchar(fpmmap(nil,len+1 ,PROT_READ or PROT_WRITE,MAP_PRIVATE,fd,0));
If longint(P)=-1 then
Halt(4);
Writeln('Read in memory :',P);
fpclose(fd);
if fpMUnMap(P,Len)<>0 Then
Halt(fpgeterrno);
end.

12
docs/unixex/ex76.pp Normal file
View File

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

11
docs/unixex/ex77.pp Normal file
View File

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

21
docs/unixex/ex79.pp Normal file
View File

@ -0,0 +1,21 @@
Program Example79;
{ Program to demonstrate the FpExecVP function. }
Uses Unix, strings;
Const Arg0 : PChar = 'ls';
Arg1 : Pchar = '-l';
Var PP : PPchar;
begin
GetMem (PP,3*SizeOf(Pchar));
PP[0]:=Arg0;
PP[1]:=Arg1;
PP[2]:=Nil;
{ Execute 'ls -l', with current environment. }
{ 'ls' is looked for in PATH environment variable.}
fpExecvp ('ls',pp);
end.

20
docs/unixex/ex8.pp Normal file
View File

@ -0,0 +1,20 @@
Program Example8;
{ Program to demonstrate the Execv function. }
Uses Unix, 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 }
fpExecv ('/bin/ls',pp);
end.

13
docs/unixex/ex80.pp Normal file
View File

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

22
docs/unixex/ex9.pp Normal file
View File

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

44
docs/unixex/ex91.pp Normal file
View File

@ -0,0 +1,44 @@
program Example30;
{ Program to demonstrate the FSStat function. }
uses BaseUnix,Unix,UnixType;
var s : string;
fd : cint;
info : tstatfs;
begin
writeln ('Info about current partition : ');
s:='.';
while s<>'q' do
begin
Fd:=fpOpen(S,O_RDOnly);
if (fd>=0) then
begin
if fstatfs (fd,info)<>0 then
begin
writeln('Fstat failed. Errno : ',fpgeterrno);
halt (1);
end;
FpClose(fd);
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);
{$ifdef FreeBSD}
writeln ('fsid : ',info.fsid[0]);
{$else}
writeln ('fsid : ',info.fsid[0]);
writeln ('Namelen : ',info.namelen);
{$endif}
write ('Type name of file to do fsstat. (q quits) :');
readln (s)
end;
end;
end.

2
docs/unixex/foot.tex Normal file
View File

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

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

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

8
docs/unixex/newex Normal file
View File

@ -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}

8
docs/unixex/template.pp Normal file
View File

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