mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 10:46:18 +02:00
+ initial check-in
This commit is contained in:
parent
74511f1753
commit
02f85d2f9b
101
docs/strutex/Makefile
Normal file
101
docs/strutex/Makefile
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
#######################################################################
|
||||||
|
#
|
||||||
|
# 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 execute
|
||||||
|
|
||||||
|
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 ex50 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 ex78 ex79 ex80 \
|
||||||
|
ex81 ex82 ex83 ex84 ex85 ex86 ex87 ex88 ex89 ex90 ex91 ex92 \
|
||||||
|
ex93
|
||||||
|
|
||||||
|
# This might not be the same list as objects, since some of the
|
||||||
|
# tests might be interactive.
|
||||||
|
TOTEST=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 ex35 ex36\
|
||||||
|
ex37 ex39 ex41 ex42 ex43 ex44 ex45 ex46 ex47\
|
||||||
|
ex48 ex49 ex50 ex51 ex52 ex53 ex54 ex55 ex56 ex57 ex58\
|
||||||
|
ex59 ex60 ex61 ex62 ex63 ex64 ex65 ex66 ex67 ex68 ex69 ex70\
|
||||||
|
ex72 ex73 ex74 ex75 ex76 ex77 ex78 ex79 ex80 \
|
||||||
|
ex81 ex82 ex83 ex84 ex85 ex86 ex87 ex88 ex89 ex90 ex91 ex92 \
|
||||||
|
ex93
|
||||||
|
|
||||||
|
LOGFILE=$(addsuffix .log, $(TOTEST))
|
||||||
|
|
||||||
|
|
||||||
|
TEXOBJECTS=$(addsuffix .tex, $(OBJECTS))
|
||||||
|
|
||||||
|
all : $(OBJECTS)
|
||||||
|
|
||||||
|
execute: $(LOGFILE)
|
||||||
|
|
||||||
|
tex : $(TEXOBJECTS)
|
||||||
|
|
||||||
|
onetex : tex
|
||||||
|
$(MAKETEX) $(TEXOBJECTS)
|
||||||
|
|
||||||
|
clean :
|
||||||
|
rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS)
|
||||||
|
rm -f *.ow *.sw *.exe *.dll *.ppw *.tmp *.log *.dat
|
||||||
|
|
||||||
|
$(OBJECTS): %: %.pp
|
||||||
|
$(FPC) $(PPOPTS) $*
|
||||||
|
|
||||||
|
$(TEXOBJECTS): %.tex: %.pp head.tex foot.tex
|
||||||
|
$(PP2TEX) $*
|
||||||
|
|
||||||
|
$(LOGFILE): %.log: %.exe
|
||||||
|
$* > $*.log
|
4
docs/strutex/README
Normal file
4
docs/strutex/README
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
This directory contains the examples for the strutils unit.
|
||||||
|
|
||||||
|
ex1.pp contains an example of the SearchBuf function.
|
||||||
|
ex2.pp contains an example of the WordCount,ExtractWordPos,WordPosition functions.
|
66
docs/strutex/ex1.pp
Normal file
66
docs/strutex/ex1.pp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
{$ifdef fpc}
|
||||||
|
{$mode objfpc}
|
||||||
|
{$h+}
|
||||||
|
{$endif}
|
||||||
|
Program ex1;
|
||||||
|
|
||||||
|
uses StrUtils;
|
||||||
|
|
||||||
|
Const
|
||||||
|
S : PChar = 'Some very long string with some words in it';
|
||||||
|
Starts : Array[1..3] of Integer = (0,10,41);
|
||||||
|
|
||||||
|
Procedure DoTest(Sub:String; Start : Integer; O : TStringSearchOptions);
|
||||||
|
|
||||||
|
Var
|
||||||
|
Res : String;
|
||||||
|
P : PChar;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Write('Searching for "',Sub,'" starting at pos ',Start,' : ');
|
||||||
|
P:=SearchBuf(Pchar(S),Length(S),Start,0,Sub,O);
|
||||||
|
if (P=Nil) then
|
||||||
|
Writeln('Not found')
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Res:=StringOfChar(' ',Length(Sub));
|
||||||
|
SetLength(Res,Length(Sub));
|
||||||
|
Move(P^,Res[1],Length(Sub));
|
||||||
|
Writeln('Found at pos ',(P-PChar(S)),' : ',Res);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure DoTests(Sub : String; O : TStringSearchOptions);
|
||||||
|
|
||||||
|
Var
|
||||||
|
I : Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Writeln('Searching up');
|
||||||
|
For I:=1 to 3 do
|
||||||
|
DoTest(Sub,Starts[i],O);
|
||||||
|
Include(O,soDown);
|
||||||
|
Writeln('Searching down');
|
||||||
|
For I:=1 to 3 do
|
||||||
|
DoTest(Sub,Starts[i],O);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure DoAllTests(S : String);
|
||||||
|
|
||||||
|
begin
|
||||||
|
Writeln('No options');
|
||||||
|
DoTests(S,[]);
|
||||||
|
Writeln('Match case:');
|
||||||
|
DoTests(S,[soMatchCase]);
|
||||||
|
Writeln('Whole word:');
|
||||||
|
DoTests(S,[soWholeWord]);
|
||||||
|
Writeln('Match case, whole word:');
|
||||||
|
DoTests(S,[soMatchCase,soWholeWord]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
DoAllTests('very');
|
||||||
|
DoAllTests('Very');
|
||||||
|
DoAllTests('in');
|
||||||
|
DoAllTests('In');
|
||||||
|
end.
|
25
docs/strutex/ex2.pp
Normal file
25
docs/strutex/ex2.pp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{$mode objfpc}
|
||||||
|
{$h+}
|
||||||
|
Program testp;
|
||||||
|
|
||||||
|
uses sysutils,strutils;
|
||||||
|
|
||||||
|
Const
|
||||||
|
Count = 10000000;
|
||||||
|
Delims = [' ','.'];
|
||||||
|
Var
|
||||||
|
S,T : String;
|
||||||
|
I,N : Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:='THE CAT WAS NEVER SMART ENOUGH TO CATCH THIS FAST LITTLE MOUSE.';
|
||||||
|
For I:=1 to 8 do
|
||||||
|
Write('1234567890');
|
||||||
|
Writeln;
|
||||||
|
Writeln(S);
|
||||||
|
For I:=1 to WordCount(S,Delims) do
|
||||||
|
begin
|
||||||
|
T:=ExtractWordPos(I,S,Delims,N);
|
||||||
|
Writeln('Word ',I:2,' starts at ',N:2,'(',WordPosition(I,S,Delims):2,') : ',T);
|
||||||
|
end;
|
||||||
|
end.
|
9
docs/strutex/newex
Normal file
9
docs/strutex/newex
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/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}
|
||||||
|
rm ex${1}.o
|
8
docs/strutex/template.pp
Normal file
8
docs/strutex/template.pp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Program Example;
|
||||||
|
|
||||||
|
{ This program demonstrates the *** function }
|
||||||
|
|
||||||
|
Uses strutils;
|
||||||
|
|
||||||
|
Begin
|
||||||
|
End.
|
Loading…
Reference in New Issue
Block a user