* basic framework for actions

git-svn-id: trunk@6306 -
This commit is contained in:
peter 2007-02-02 19:27:16 +00:00
parent 0e54433c75
commit f2747f1e40
13 changed files with 3379 additions and 345 deletions

3
.gitattributes vendored
View File

@ -8204,6 +8204,7 @@ utils/fpmc/test.mc -text
utils/fppkg/Makefile svneol=native#text/plain
utils/fppkg/Makefile.fpc svneol=native#text/plain
utils/fppkg/README svneol=native#text/plain
utils/fppkg/contnrs20.pp svneol=native#text/plain
utils/fppkg/fpmkcnst.inc svneol=native#text/plain
utils/fppkg/fpmktype.pp svneol=native#text/plain
utils/fppkg/fpmkunit.pp svneol=native#text/plain
@ -8240,6 +8241,7 @@ utils/fppkg/lnet/sys/lspawnfcgiunix.inc svneol=native#text/plain
utils/fppkg/lnet/sys/lspawnfcgiwin.inc svneol=native#text/plain
utils/fppkg/lnet/sys/osunits.inc svneol=native#text/plain
utils/fppkg/pkgdownload.pp svneol=native#text/plain
utils/fppkg/pkgfpmake.pp svneol=native#text/plain
utils/fppkg/pkghandler.pp svneol=native#text/plain
utils/fppkg/pkglibcurl.pp svneol=native#text/plain
utils/fppkg/pkglnet.pas svneol=native#text/plain
@ -8252,6 +8254,7 @@ utils/fppkg/pkgwget.pp svneol=native#text/plain
utils/fppkg/rep2xml.lpi svneol=native#text/plain
utils/fppkg/rep2xml.lpr svneol=native#text/plain
utils/fppkg/reptest.pp svneol=native#text/plain
utils/fppkg/streamcoll20.pp svneol=native#text/plain
utils/fppkg/testdownload.pp svneol=native#text/plain
utils/fprcp/Makefile svneol=native#text/plain
utils/fprcp/Makefile.fpc svneol=native#text/plain

2344
utils/fppkg/contnrs20.pp Executable file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="/"/>
<PathDelim Value="\"/>
<Version Value="5"/>
<General>
<Flags>
@ -10,7 +10,7 @@
<MainUnitHasTitleStatement Value="False"/>
</Flags>
<MainUnit Value="0"/>
<IconPath Value="./"/>
<IconPath Value=".\"/>
<TargetFileExt Value=""/>
<ActiveEditorIndexAtStart Value="0"/>
</General>
@ -21,6 +21,7 @@
</VersionInfo>
<PublishOptions>
<Version Value="2"/>
<DestinationDirectory Value="$(TestDir)\publishedproject\"/>
<IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
@ -28,35 +29,36 @@
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<Units Count="11">
<Units Count="20">
<Unit0>
<Filename Value="fppkg.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="fppkg"/>
<CursorPos X="1" Y="244"/>
<TopLine Value="215"/>
<CursorPos X="32" Y="231"/>
<TopLine Value="212"/>
<EditorIndex Value="0"/>
<UsageCount Value="21"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit0>
<Unit1>
<Filename Value="pkgropts.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pkgropts"/>
<CursorPos X="3" Y="25"/>
<TopLine Value="1"/>
<EditorIndex Value="1"/>
<UsageCount Value="21"/>
<CursorPos X="19" Y="25"/>
<TopLine Value="22"/>
<EditorIndex Value="6"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit1>
<Unit2>
<Filename Value="fpmkcnst.inc"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="21"/>
<SyntaxHighlighter Value="Text"/>
<CursorPos X="64" Y="8"/>
<TopLine Value="1"/>
<UsageCount Value="33"/>
</Unit2>
<Unit3>
<Filename Value="fpmktype.pp"/>
@ -64,197 +66,290 @@
<UnitName Value="fpmktype"/>
<CursorPos X="3" Y="41"/>
<TopLine Value="1"/>
<EditorIndex Value="3"/>
<UsageCount Value="21"/>
<EditorIndex Value="9"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit3>
<Unit4>
<Filename Value="fpmkunit.pp"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="21"/>
<SyntaxHighlighter Value="Text"/>
<UnitName Value="fpmkunit"/>
<CursorPos X="1" Y="1"/>
<TopLine Value="1"/>
<EditorIndex Value="1"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit4>
<Unit5>
<Filename Value="fprepos.pp"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="21"/>
<SyntaxHighlighter Value="Text"/>
<UnitName Value="fprepos"/>
<CursorPos X="27" Y="28"/>
<TopLine Value="2"/>
<EditorIndex Value="5"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit5>
<Unit6>
<Filename Value="fpxmlrep.pp"/>
<IsPartOfProject Value="True"/>
<UsageCount Value="21"/>
<UsageCount Value="33"/>
<SyntaxHighlighter Value="Text"/>
</Unit6>
<Unit7>
<Filename Value="pkghandler.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pkghandler"/>
<CursorPos X="19" Y="60"/>
<TopLine Value="17"/>
<EditorIndex Value="6"/>
<UsageCount Value="21"/>
<CursorPos X="52" Y="51"/>
<TopLine Value="32"/>
<EditorIndex Value="13"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit7>
<Unit8>
<Filename Value="pkgmkconv.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pkgmkconv"/>
<CursorPos X="20" Y="7"/>
<TopLine Value="1"/>
<EditorIndex Value="5"/>
<UsageCount Value="21"/>
<CursorPos X="1" Y="46"/>
<TopLine Value="20"/>
<EditorIndex Value="11"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit8>
<Unit9>
<Filename Value="pkgdownload.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pkgdownload"/>
<CursorPos X="13" Y="96"/>
<TopLine Value="56"/>
<EditorIndex Value="4"/>
<UsageCount Value="21"/>
<CursorPos X="32" Y="18"/>
<TopLine Value="5"/>
<EditorIndex Value="10"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit9>
<Unit10>
<Filename Value="pkgmessages.pp"/>
<IsPartOfProject Value="True"/>
<UnitName Value="pkgmessages"/>
<CursorPos X="26" Y="9"/>
<CursorPos X="69" Y="12"/>
<TopLine Value="1"/>
<EditorIndex Value="2"/>
<UsageCount Value="21"/>
<EditorIndex Value="8"/>
<UsageCount Value="33"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
<Filename Value="streamcoll.pp"/>
<UnitName Value="streamcoll"/>
<CursorPos X="66" Y="88"/>
<TopLine Value="65"/>
<UsageCount Value="9"/>
</Unit11>
<Unit12>
<Filename Value="streamcoll20.pp"/>
<UnitName Value="streamcoll"/>
<CursorPos X="3" Y="15"/>
<TopLine Value="1"/>
<UsageCount Value="9"/>
</Unit12>
<Unit13>
<Filename Value="..\..\..\fpc20\rtl\objpas\classes\classesh.inc"/>
<CursorPos X="17" Y="1345"/>
<TopLine Value="1326"/>
<EditorIndex Value="2"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
<Filename Value="..\..\..\fpc20\rtl\inc\objpash.inc"/>
<CursorPos X="38" Y="277"/>
<TopLine Value="269"/>
<EditorIndex Value="12"/>
<UsageCount Value="16"/>
<Loaded Value="True"/>
</Unit14>
<Unit15>
<Filename Value="..\..\..\fpc20\fcl\inc\contnrs.pp"/>
<UnitName Value="contnrs"/>
<CursorPos X="1" Y="19"/>
<TopLine Value="1"/>
<UsageCount Value="9"/>
</Unit15>
<Unit16>
<Filename Value="contnrs20.pp"/>
<UnitName Value="contnrs"/>
<CursorPos X="43" Y="32"/>
<TopLine Value="1"/>
<EditorIndex Value="3"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit16>
<Unit17>
<Filename Value="pkgfpmake.pp"/>
<UnitName Value="pkgfpmake"/>
<CursorPos X="45" Y="85"/>
<TopLine Value="1"/>
<EditorIndex Value="7"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
<Filename Value="pkgwget.pp"/>
<UnitName Value="pkgwget"/>
<CursorPos X="23" Y="6"/>
<TopLine Value="1"/>
<EditorIndex Value="4"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit18>
<Unit19>
<Filename Value="pkglnet.pas"/>
<UnitName Value="pkglnet"/>
<CursorPos X="5" Y="140"/>
<TopLine Value="103"/>
<UsageCount Value="10"/>
</Unit19>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="fppkg.pp"/>
<Caret Line="245" Column="5" TopLine="222"/>
<Caret Line="218" Column="42" TopLine="206"/>
</Position1>
<Position2>
<Filename Value="fppkg.pp"/>
<Caret Line="278" Column="1" TopLine="245"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="70" Column="18" TopLine="56"/>
</Position2>
<Position3>
<Filename Value="fppkg.pp"/>
<Caret Line="245" Column="5" TopLine="222"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="10" Column="5" TopLine="1"/>
</Position3>
<Position4>
<Filename Value="fppkg.pp"/>
<Caret Line="249" Column="12" TopLine="222"/>
<Filename Value="pkgmkconv.pp"/>
<Caret Line="679" Column="46" TopLine="666"/>
</Position4>
<Position5>
<Filename Value="pkghandler.pp"/>
<Caret Line="58" Column="65" TopLine="35"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="67" Column="1" TopLine="39"/>
</Position5>
<Position6>
<Filename Value="pkghandler.pp"/>
<Caret Line="47" Column="51" TopLine="24"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="28" Column="1" TopLine="8"/>
</Position6>
<Position7>
<Filename Value="pkghandler.pp"/>
<Caret Line="54" Column="1" TopLine="31"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="43" Column="26" TopLine="24"/>
</Position7>
<Position8>
<Filename Value="pkghandler.pp"/>
<Caret Line="47" Column="1" TopLine="47"/>
<Filename Value="pkgmessages.pp"/>
<Caret Line="11" Column="20" TopLine="1"/>
</Position8>
<Position9>
<Filename Value="pkghandler.pp"/>
<Caret Line="54" Column="3" TopLine="31"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="51" Column="11" TopLine="32"/>
</Position9>
<Position10>
<Filename Value="pkghandler.pp"/>
<Caret Line="59" Column="3" TopLine="36"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="35" Column="3" TopLine="20"/>
</Position10>
<Position11>
<Filename Value="pkghandler.pp"/>
<Caret Line="53" Column="6" TopLine="30"/>
<Filename Value="fppkg.pp"/>
<Caret Line="99" Column="19" TopLine="76"/>
</Position11>
<Position12>
<Filename Value="pkghandler.pp"/>
<Caret Line="40" Column="47" TopLine="30"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="56" Column="6" TopLine="37"/>
</Position12>
<Position13>
<Filename Value="pkghandler.pp"/>
<Caret Line="53" Column="6" TopLine="30"/>
<Filename Value="fppkg.pp"/>
<Caret Line="86" Column="26" TopLine="76"/>
</Position13>
<Position14>
<Filename Value="pkghandler.pp"/>
<Caret Line="55" Column="10" TopLine="30"/>
<Caret Line="47" Column="1" TopLine="22"/>
</Position14>
<Position15>
<Filename Value="pkghandler.pp"/>
<Caret Line="50" Column="14" TopLine="9"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="56" Column="23" TopLine="37"/>
</Position15>
<Position16>
<Filename Value="pkghandler.pp"/>
<Caret Line="53" Column="6" TopLine="30"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="58" Column="16" TopLine="39"/>
</Position16>
<Position17>
<Filename Value="pkghandler.pp"/>
<Caret Line="40" Column="10" TopLine="17"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="74" Column="1" TopLine="55"/>
</Position17>
<Position18>
<Filename Value="fppkg.pp"/>
<Caret Line="46" Column="1" TopLine="23"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="25" Column="1" TopLine="1"/>
</Position18>
<Position19>
<Filename Value="fppkg.pp"/>
<Caret Line="289" Column="1" TopLine="266"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="105" Column="23" TopLine="75"/>
</Position19>
<Position20>
<Filename Value="fppkg.pp"/>
<Caret Line="254" Column="1" TopLine="241"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="89" Column="17" TopLine="70"/>
</Position20>
<Position21>
<Filename Value="fppkg.pp"/>
<Caret Line="46" Column="42" TopLine="23"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="100" Column="34" TopLine="71"/>
</Position21>
<Position22>
<Filename Value="fppkg.pp"/>
<Caret Line="33" Column="28" TopLine="23"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="86" Column="13" TopLine="70"/>
</Position22>
<Position23>
<Filename Value="fppkg.pp"/>
<Caret Line="47" Column="42" TopLine="23"/>
<Caret Line="29" Column="1" TopLine="20"/>
</Position23>
<Position24>
<Filename Value="fppkg.pp"/>
<Caret Line="253" Column="42" TopLine="230"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="90" Column="23" TopLine="71"/>
</Position24>
<Position25>
<Filename Value="fppkg.pp"/>
<Caret Line="254" Column="37" TopLine="231"/>
<Filename Value="pkgfpmake.pp"/>
<Caret Line="88" Column="1" TopLine="72"/>
</Position25>
<Position26>
<Filename Value="fppkg.pp"/>
<Caret Line="259" Column="9" TopLine="236"/>
<Caret Line="42" Column="25" TopLine="17"/>
</Position26>
<Position27>
<Filename Value="fppkg.pp"/>
<Caret Line="234" Column="16" TopLine="203"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="51" Column="19" TopLine="42"/>
</Position27>
<Position28>
<Filename Value="fppkg.pp"/>
<Caret Line="278" Column="63" TopLine="255"/>
<Filename Value="pkghandler.pp"/>
<Caret Line="214" Column="24" TopLine="181"/>
</Position28>
<Position29>
<Filename Value="fppkg.pp"/>
<Caret Line="283" Column="1" TopLine="255"/>
<Caret Line="233" Column="19" TopLine="199"/>
</Position29>
<Position30>
<Filename Value="fppkg.pp"/>
<Caret Line="282" Column="9" TopLine="259"/>
<Caret Line="231" Column="39" TopLine="214"/>
</Position30>
</JumpHistory>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<PathDelim Value="\"/>
<CodeGeneration>
<Generate Value="Faster"/>
<Checks>
<IOChecks Value="True"/>
<RangeChecks Value="True"/>
<OverflowChecks Value="True"/>
<StackChecks Value="True"/>
</Checks>
<Optimizations>
<OptimizationLevel Value="0"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="True"/>
</Debugging>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>

View File

@ -11,41 +11,23 @@ uses
// Repository handler objects
fprepos, fpxmlrep,fpmktype, pkgropts,
// Package Handler components
pkghandler, pkgmkconv, pkgdownload, pkgmessages;
pkghandler, pkgmkconv, pkgdownload, pkgfpmake, pkgmessages;
Type
TRunMode = (rmHelp,rmCompile,rmBuild,rmInstall,rmArchive,rmClean,rmDownload,rmUpdate);
{ TMakeTool }
TMakeTool = Class(TCustomApplication)
Private
FDefaults: TPackagerOptions;
FConvertOnly,
FLogging : Boolean;
FCompiler : String;
FRunMode : TRunMode;
FHaveMakefile : Boolean;
FHaveFpmake : Boolean;
FFPMakeSrc : String;
FFPMakeBin : String;
FVerbose: TVerbosities;
FPackages : TStrings;
Procedure Log(Msg : String);
Procedure Error(Msg : String);
Procedure Error(Fmt : String; Args : Array of const);
Function GetCompiler : String;
procedure ShowUsage;
Public
Procedure DownloadFile(Const URL,Dest : String);
Function GetConfigFileName : String;
Procedure LoadDefaults;
Procedure ProcessCommandLine;
procedure CreateFPMake;
procedure CompileFPMake(Extra : Boolean);
Function RunFPMake : Integer;
Procedure DoRun; Override;
Property Verbose : TVerbosities Read FVerbose Write FVerbose;
procedure ExecuteAction(const AAction:string;const Args:TActionArgs);
end;
EMakeToolError = Class(Exception);
@ -53,78 +35,6 @@ Type
{ TMakeTool }
procedure TMakeTool.CompileFPMake(Extra: Boolean);
Var
O,C : String;
begin
C:=GetCompiler;
O:=FFPmakeSrc;
If Extra then
O:='-Fafpmkext '+O;
Log(SLogCompilingFPMake+C+' '+O);
If ExecuteProcess(C,O)<>0 then
Error(SErrFailedToCompileFPCMake)
end;
procedure TMakeTool.CreateFPMake;
begin
Log(SLogGeneratingFPMake);
With TMakeFileConverter.Create(Nil) do
try
ConvertFile('Makefile.fpc','fpmake.pp');
finally
Free;
end;
end;
Function TMakeTool.RunFPMake : Integer;
Function MaybeQuote(Const S : String) : String;
begin
If Pos(' ',S)=0 then
Result:=S
else
Result:='"'+S+'"';
end;
Var
I : integer;
D,O : String;
begin
Log(SLogRunningFPMake);
D:=IncludeTrailingPathDelimiter(GetCurrentDir);
O:='';
For I:=1 to ParamCount do
begin
If (O<>'') then
O:=O+' ';
O:=O+MaybeQuote(ParamStr(I));
end;
Result:=ExecuteProcess(D+FFPMakeBin,O);
end;
procedure TMakeTool.Log(Msg: String);
begin
If FLogging then
Writeln(stdErr,Msg);
end;
procedure TMakeTool.Error(Msg: String);
begin
Raise EMakeToolError.Create(Msg);
end;
procedure TMakeTool.Error(Fmt: String; Args: array of const);
begin
Raise EMakeToolError.CreateFmt(Fmt,Args);
end;
function TMakeTool.GetCompiler: String;
begin
If (FCompiler='') then
@ -151,22 +61,16 @@ begin
Result:=FCompiler
else
begin
Result:=FileSearch(FCompiler,GetEnvironmentVariable('PATH'));
Result:=FileSearch(FCompiler+ExeExt,GetEnvironmentVariable('PATH'));
If (Result='') then
Result:=FCompiler;
Result:=FCompiler+ExeExt;
end;
end;
procedure TMakeTool.DownloadFile(const URL, Dest: String);
begin
end;
function TMakeTool.GetConfigFileName: String;
var
G : Boolean;
begin
if HasOption('C','config-file') then
Result:=GetOptionValue('C','config-file')
@ -181,13 +85,32 @@ begin
end
end;
procedure TMakeTool.LoadDefaults;
begin
Verbosity:=[vError,vInfo,vCommands,vDebug];
FDefaults:=TPackagerOptions.Create;
FDefaults.LoadFromFile(GetConfigFileName);
end;
procedure TMakeTool.ShowUsage;
begin
Writeln('Usage: ',Paramstr(0),' [options] <action> <package>');
Writeln('Options:');
Writeln(' -r --compiler Set compiler');
Writeln(' -h --help This help');
Writeln(' -v --verbose Set verbosity');
Writeln('Actions:');
Writeln(' update Update available packages');
Writeln(' listpackages List available packages');
Writeln(' build Build package');
Writeln(' install Install package');
Writeln(' download Download package');
Writeln(' convertmk Convert Makefile.fpc to fpmake.pp');
end;
procedure TMakeTool.ProcessCommandLine;
Function CheckOption(Index : Integer;Short,Long : String): Boolean;
@ -208,122 +131,133 @@ procedure TMakeTool.ProcessCommandLine;
begin
if (Length(ParamStr(Index))>1) and (Paramstr(Index)[2]<>'-') then
begin
If Index<ParamCount then
begin
Inc(Index);
Result:=Paramstr(Index);
end
else
Error(SErrNeedArgument,[Index,ParamStr(Index)]);
If Index<ParamCount then
begin
Inc(Index);
Result:=Paramstr(Index);
end
else
Error(SErrNeedArgument,[Index,ParamStr(Index)]);
end
else If length(ParamStr(Index))>2 then
begin
P:=Pos('=',Paramstr(Index));
If (P=0) then
Error(SErrNeedArgument,[Index,ParamStr(Index)])
else
begin
Result:=Paramstr(Index);
Delete(Result,1,P);
end;
P:=Pos('=',Paramstr(Index));
If (P=0) then
Error(SErrNeedArgument,[Index,ParamStr(Index)])
else
begin
Result:=Paramstr(Index);
Delete(Result,1,P);
end;
end;
end;
Var
I : Integer;
GlobalOpts : Boolean;
cmd : string;
Action : string;
ParaPackages : TStringList;
HasAction : Boolean;
begin
I:=0;
FLogging:=False;
FRunMode:=rmhelp;
FConvertOnly:=False;
GlobalOpts:=True;
FPackages:=TStringList.Create;
// We can't use the TCustomApplication option handling,
// because they cannot handle [general opts] [command] [cmd-opts] [args]
While (I<ParamCount) do
begin
Inc(I);
// Check options.
if CheckOption(I,'r','compiler') then
FDefaults.Compiler:=OptionArg(I)
else if CheckOption(I,'v','verbose') then
Include(FVerbose,StringToVerbosity(OptionArg(I)))
else if CheckOption(I,'h','help') then
FRunMode:=rmhelp
else if (Length(Paramstr(i))>0) and (Paramstr(I)[1]='-') then
Raise EMakeToolError.CreateFmt(SErrInvalidArgument,[I,ParamStr(i)])
else
If GlobalOpts then
begin
// It's a command.
Cmd:=Paramstr(I);
if (Cmd='convert') then
FConvertOnly:=True
else if (Cmd='compile') then
FRunMode:=rmCompile
else if (Cmd='build') then
FRunMode:=rmBuild
else if (Cmd='install') then
FRunMode:=rmInstall
else if (cmd='clean') then
FRunMode:=rmClean
else if (cmd='archive') then
FRunMode:=rmarchive
else if (cmd='download') then
FRunMode:=rmDownload
else if (cmd='update') then
FRunMode:=rmUpdate
try
I:=0;
HasAction:=false;
ParaPackages:=TStringList.Create;
// We can't use the TCustomApplication option handling,
// because they cannot handle [general opts] [command] [cmd-opts] [args]
While (I<ParamCount) do
begin
Inc(I);
// Check options.
if CheckOption(I,'r','compiler') then
FDefaults.Compiler:=OptionArg(I)
else if CheckOption(I,'v','verbose') then
Include(Verbosity,StringToVerbosity(OptionArg(I)))
else if CheckOption(I,'h','help') then
begin
ShowUsage;
halt(0);
end
else if (Length(Paramstr(i))>0) and (Paramstr(I)[1]='-') then
Raise EMakeToolError.CreateFmt(SErrInvalidArgument,[I,ParamStr(i)])
else
Raise EMakeToolError.CreateFmt(SErrInvalidCommand,[Cmd]);
end
else // It's a package name.
// It's a command or target.
begin
if HasAction then
ParaPackages.Add(Paramstr(i))
else
begin
Action:=Paramstr(i);
HasAction:=true;
end;
end;
end;
if HasAction then
begin
if GetPkgHandler(Action)<>nil then
begin
for i:=0 to ParaPackages.Count-1 do
ActionStack.Push(Action,[ParaPackages[i]])
end
else
Raise EMakeToolError.CreateFmt(SErrInvalidCommand,[Action]);
end
else
ShowUsage;
finally
FreeAndNil(ParaPackages);
end;
end;
procedure TMakeTool.ExecuteAction(const AAction:string;const Args:TActionArgs);
var
pkghandlerclass : TPackageHandlerClass;
i : integer;
logargs : string;
begin
if vDebug in Verbosity then
begin
logargs:='';
for i:=Low(Args) to High(Args) do
begin
FPackages.Add(Paramstr(i));
if logargs='' then
logargs:=Args[i]
else
logargs:=logargs+','+Args[i];
end;
Log(vDebug,SLogRunAction,[AAction,logargs]);
end;
pkghandlerclass:=GetPkgHandler(AAction);
With pkghandlerclass.Create(FDefaults) do
try
Execute(Args);
finally
Free;
end;
end;
procedure TMakeTool.DoRun;
var
Action : string;
Args : TActionArgs;
begin
LoadDefaults;
Try
ProcessCommandLine;
If FConvertOnly then
CreateFPMake
else
begin
FHaveMakefile:=FileExists('Makefile.fpc');
FFPMakeSrc:='fpmake.pp';
FHaveFpmake:=FileExists(FFPMakeSrc);
If Not FHaveFPMake then
begin
FHaveFPMake:=FileExists('fpmake.pas');
If FHaveFPMake then
FFPMakeSrc:='fpmake.pas';
end;
if Not (FHaveFPMake or FHaveMakeFile) then
Error(SErrMissingConfig);
If (Not FHaveFPMake) or (FileAge(FFPMakeSrc)<FileAge('Makefile.fpc')) then
CreateFPMake;
{$ifndef unix}
FFPMakeBin:='fpmake.exe';
{$else}
FFPMakeBin:='fpmake';
{$endif}
if FileAge(FFPMakeBin)<FileAge(FFPMakeSrc) then
CompileFPMake(FRunMode in [rmArchive,rmDownload]);
Halt(RunFPMake);
end;
repeat
if not ActionStack.Pop(Action,Args) then
break;
ExecuteAction(Action,Args);
until false;
Terminate;
except
On E : Exception do
begin
Writeln(StdErr,Format(SErrRunning,[E.Message]));
Halt(1);
Writeln(StdErr,Format(SErrRunning,[E.Message]));
Halt(1);
end;
end;
end;

View File

@ -16,7 +16,15 @@ unit fprepos;
interface
uses classes,sysutils,streamcoll,contnrs,fpmktype;
uses
classes,sysutils,
contnrs,
{$ifdef ver2_0}
streamcoll20,
{$else}
streamcoll,
{$endif}
fpmktype;
Const
StreamVersion : Integer = 1;

View File

@ -234,7 +234,7 @@ const
'RenameTo', 'System', 'Features',
'PWD', 'HELP', 'LAST');
procedure Writedbg(const ar: array of const);
procedure Writedbg(const ar: array of string);
{$ifdef debug}
var
i: Integer;

110
utils/fppkg/pkgfpmake.pp Executable file
View File

@ -0,0 +1,110 @@
unit pkgfpmake;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,pkghandler;
type
{ TFPMakeCompiler }
TFPMakeCompiler = Class(TPackagehandler)
Private
Procedure CompileFPMake;
Public
Function Execute(const Args:array of string):boolean;override;
end;
{ TFPMakeRunner }
TFPMakeRunner = Class(TPackagehandler)
Private
Function RunFPMake : Integer;
Public
Function Execute(const Args:array of string):boolean;override;
end;
implementation
uses
pkgmessages;
{ TFPMakeCompiler }
Procedure TFPMakeCompiler.CompileFPMake;
Var
O,C : String;
FPMakeSrc : string;
HaveFpmake : boolean;
begin
{ Check for fpmake source }
FPMakeSrc:='fpmake.pp';
HaveFpmake:=FileExists(FPMakeSrc);
If Not HaveFPMake then
begin
HaveFPMake:=FileExists('fpmake.pas');
If HaveFPMake then
FPMakeSrc:='fpmake.pas';
end;
if Not HaveFPMake then
Error(SErrMissingFPMake);
{ Call compiler }
C:=Defaults.Compiler;
O:=FPmakeSrc;
Log(vCommands,SLogCompilingFPMake+C+' '+O);
If ExecuteProcess(C,O)<>0 then
Error(SErrFailedToCompileFPCMake)
end;
function TFPMakeCompiler.Execute(const Args:array of string):boolean;
begin
{$warning TODO Check arguments}
CompileFPMake;
result:=true;
end;
{ TFPMakeRunner }
Function TFPMakeRunner.RunFPMake : Integer;
Function MaybeQuote(Const S : String) : String;
begin
If Pos(' ',S)=0 then
Result:=S
else
Result:='"'+S+'"';
end;
Var
I : integer;
FPMakeBin,
D,O : String;
begin
FPMakeBin:='fpmake'+ExeExt;
D:=IncludeTrailingPathDelimiter(GetCurrentDir);
O:='';
For I:=1 to ParamCount do
begin
If (O<>'') then
O:=O+' ';
O:=O+MaybeQuote(ParamStr(I));
end;
Log(vCommands,SLogRunningFPMake+D+FPMakeBin+' '+O);
Result:=ExecuteProcess(D+FPMakeBin,O);
end;
function TFPMakeRunner.Execute(const Args:array of string):boolean;
begin
{$warning TODO Check arguments}
result:=(RunFPMake=0);
end;
end.

View File

@ -4,51 +4,115 @@ unit pkghandler;
interface
uses Classes,SysUtils, fpmktype;
uses Classes,SysUtils, fpmktype, pkgropts;
Const
{$ifdef unix}
ExeExt = '';
{$else unix}
ExeExt = '.exe';
{$endif unix}
Type
TVerbosity = (vError,vInfo,vCommands,vDebug);
TVerbosities = Set of TVerbosity;
TMessageEvent = Procedure (Sender : TObject; Const Msg : String) of object;
{ TActionStack }
TActionArgs = array of string;
TActionStackItem = record
Action : string;
Args : TActionArgs;
end;
PActionStackItem = ^TActionStackItem;
TActionStack = class
private
FList : TFPList;
public
constructor Create;
destructor Destroy;
procedure Push(const AAction:string;const Args:TActionArgs);
procedure Push(const AAction:string;const Args:array of string);
function Pop(out AAction:string;out Args:TActionArgs):boolean;
end;
{ TPackageHandler }
TPackageHandler = Class(TComponent)
private
FBackupFile: Boolean;
FOnMessage: TMessageEvent;
FVerbosity: TVerbosities;
FBackupFile : Boolean;
FDefaults : TPackagerOptions;
Protected
Procedure Error(Const Msg : String);
Procedure Error(Const Fmt : String; Args : Array of const);
Public
Procedure BackupFile(Const FileName : String);
Constructor Create(AOwner : TComponent); override;
Procedure Verbose(Msg : String);
Procedure Verbose(Fmt : String; Args : Array of const);
Procedure Verbose(Level : TVerbosity; Msg : String);
Procedure Verbose(Level : TVerbosity; Fmt : String; Args : Array of const);
Public
Constructor Create(ADefaults:TPackagerOptions);
Function Execute(const Args:array of string):boolean; virtual; abstract;
Property BackupFiles : Boolean Read FBackupFile Write FBackupFile;
Property OnMessage : TMessageEvent Read FOnMessage Write FOnMessage;
Property Verbosity : TVerbosities Read FVerbosity Write FVerbosity;
Property Defaults:TPackagerOptions Read FDefaults;
end;
TPackageHandlerClass = class(TPackageHandler);
EPackageHandler = Class(EInstallerError);
// Actions/PkgHandler
procedure RegisterPkgHandler(const AAction:string;pkghandlerclass:TPackageHandlerClass);
function GetPkgHandler(const AAction:string):TPackageHandlerClass;
// Logging
Function StringToVerbosity (S : String) : TVerbosity;
Function VerbosityToString (V : TVerbosity): String;
Procedure Log(Level: TVerbosity;Msg : String);
Procedure Log(Level: TVerbosity;Fmt : String; const Args : array of const);
Procedure Error(Msg : String);
Procedure Error(Fmt : String; const Args : array of const);
// Utils
function maybequoted(const s:ansistring):ansistring;
var
Verbosity : TVerbosities;
ActionStack : TActionStack;
Implementation
uses pkgmessages,typinfo;
uses
typinfo,
{$ifdef ver2_0}
contnrs20,
{$else ver2_0}
contnrs,
{$endif ver2_0}
pkgmessages;
var
PkgHandlerList : TFPHashObjectList;
procedure RegisterPkgHandler(const AAction:string;pkghandlerclass:TPackageHandlerClass);
begin
if PkgHandlerList.Find(AAction)<>nil then
begin
Raise EPackageHandler.CreateFmt(SErrActionAlreadyRegistered,[AAction]);
exit;
end;
PkgHandlerList.Add(AAction,pkghandlerclass);
end;
function GetPkgHandler(const AAction:string):TPackageHandlerClass;
begin
result:=TPackageHandlerClass(PkgHandlerList.Find(AAction));
if result=nil then
Raise EPackageHandler.CreateFmt(SErrActionNotFound,[AAction]);
end;
function StringToVerbosity(S: String): TVerbosity;
Var
I : integer;
begin
I:=GetEnumValue(TypeInfo(TVerbosity),'v'+S);
If (I<>-1) then
@ -63,58 +127,157 @@ begin
Delete(Result,1,1);// Delete 'v'
end;
procedure Log(Level:TVerbosity;Msg: String);
begin
if Level in Verbosity then
Writeln(stdErr,Msg);
end;
Procedure Log(Level:TVerbosity; Fmt:String; const Args:array of const);
begin
Log(Level,Format(Fmt,Args));
end;
procedure Error(Msg: String);
begin
Raise EPackageHandler.Create(Msg);
end;
procedure Error(Fmt: String; const Args: array of const);
begin
Raise EPackageHandler.CreateFmt(Fmt,Args);
end;
function maybequoted(const s:ansistring):ansistring;
const
{$IFDEF MSWINDOWS}
FORBIDDEN_CHARS = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
'{', '}', '''', '`', '~'];
{$ELSE}
FORBIDDEN_CHARS = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
'{', '}', '''', ':', '\', '`', '~'];
{$ENDIF}
var
s1 : ansistring;
i : integer;
quoted : boolean;
begin
quoted:=false;
s1:='"';
for i:=1 to length(s) do
begin
case s[i] of
'"' :
begin
quoted:=true;
s1:=s1+'\"';
end;
' ',
#128..#255 :
begin
quoted:=true;
s1:=s1+s[i];
end;
else begin
if s[i] in FORBIDDEN_CHARS then
quoted:=True;
s1:=s1+s[i];
end;
end;
end;
if quoted then
maybequoted:=s1+'"'
else
maybequoted:=s;
end;
{ TPackageHandler }
procedure TPackageHandler.Error(const Msg: String);
begin
Raise EPackageHandler.CreateFmt('%s : %s',[ClassName,Msg]);
end;
procedure TPackageHandler.Error(const Fmt: String; Args: Array of const);
begin
Error(Format(Fmt,Args));
end;
procedure TPackageHandler.BackupFile(const FileName: String);
Var
BFN : String;
begin
BFN:=FileName+'.bak';
If not RenameFile(FileName,BFN) then
Error(SErrBackupFailed,[FileName,BFN]);
end;
constructor TPackageHandler.Create(AOwner: TComponent);
constructor TPackageHandler.Create(ADefaults:TPackagerOptions);
begin
inherited Create(AOwner);
FVerbosity:=[vError];
inherited Create(nil);
FDefaults:=ADefaults;
end;
procedure TPackageHandler.Verbose(Msg: String);
{ TActionStack }
constructor TActionStack.Create;
begin
Verbose(vInfo,Msg);
FList:=TFPList.Create;
end;
procedure TPackageHandler.Verbose(Fmt: String; Args: array of const);
destructor TActionStack.Destroy;
begin
Verbose(vInfo,Fmt,Args);
FreeAndNil(FList);
end;
procedure TPackageHandler.Verbose(Level: TVerbosity; Msg: String);
procedure TActionStack.Push(const AAction:string;const Args:TActionArgs);
var
ActionItem : PActionStackItem;
begin
If (Level in FVerbosity) and Assigned(FOnMessage) then
FOnMessage(Self,Msg);
New(ActionItem);
ActionItem^.Action:=AAction;
ActionItem^.Args:=Args;
FList.Add(ActionItem);
end;
procedure TPackageHandler.Verbose(Level: TVerbosity; Fmt: String;
Args: array of const);
procedure TActionStack.Push(const AAction:string;const Args:array of string);
var
ActionArgs : TActionArgs;
i : integer;
begin
// Save a format call
If (Level in FVerbosity) and Assigned(FOnMessage) then
Verbose(Level,Format(Fmt,Args));
SetLength(ActionArgs,high(Args)+1);
for i:=low(Args) to high(Args) do
ActionArgs[i]:=Args[i];
Push(AAction,ActionArgs);
end;
function TActionStack.Pop(out AAction:string;out Args:TActionArgs):boolean;
var
ActionItem : PActionStackItem;
Idx : integer;
begin
Result:=false;
if FList.Count=0 then
exit;
// Retrieve Item from stack
Idx:=FList.Count-1;
ActionItem:=PActionStackItem(FList[Idx]);
FList.Delete(Idx);
// Copy contents and dispose stack item
AAction:=ActionItem^.Action;
Args:=ActionItem^.Args;
dispose(ActionItem);
Result:=true;
end;
initialization
PkgHandlerList:=TFPHashObjectList.Create(true);
ActionStack:=TActionStack.Create;
finalization
FreeAndNil(PkgHandlerList);
FreeAndNil(ActionStack);
end.

View File

@ -39,7 +39,7 @@ Type
implementation
uses
pkgmessages, uriparser;
pkghandler,pkgmessages, uriparser;
{ TLNetDownloader }

View File

@ -8,8 +8,11 @@ interface
Resourcestring
SErrInValidArgument = 'Invalid command-line argument at position %d : %s';
SErrNeedArgument = 'Option at position %d (%s) needs an argument';
SErrMissingConfig = 'Missing configuration Makefile.fpc or fpmake.pp';
SErrMissingFPMake = 'Missing configuration fpmake.pp';
SErrMissingMakefilefpc = 'Missing configuration Makefile.fpc';
SErrRunning = 'The FPC make tool encountered the following error: %s';
SErrActionAlreadyRegistered= 'Action "%s" is already registered';
SErrActionNotFound = 'Action "%s" is not supported';
SErrFailedToCompileFPCMake = 'Could not compile fpmake driver program';
SErrNoFTPDownload = 'This binary has no support for FTP downloads.';
SErrNoHTTPDownload = 'This binary has no support for HTTP downloads.';
@ -25,10 +28,12 @@ Resourcestring
SErrLoginFailed = 'FTP LOGIN command failed.';
SErrCWDFailed = 'FTP CWD "%s" command failed.';
SErrGETFailed = 'FTP GET "%s" command failed.';
SLogGeneratingFPMake = 'Generating fpmake.pp';
SLogCompilingFPMake = 'Compiling fpmake.pp: ';
SLogRunningFPMake = 'Running fpmake';
SLogRunAction = 'Action: %s %s';
implementation
end.

View File

@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils,pkghandler;
{ TMakeFileConverter }
Type
TSectionType = (stNone,stPackage,stTarget,stclean,stinstall,stCompiler,
stDefault,stRequire,stRules,stPrerules);
@ -39,14 +39,16 @@ Type
Procedure StartInstaller(Src : TStrings);
Procedure EndInstaller(Src : TStrings);
Function GetLine (L : TStrings; Var I : Integer) : String;
Public
procedure ConvertFile(const AFileName: String; Src: TStrings; Dir,OS : String);
Procedure ConvertFile(Const Source,Dest: String);
Public
Function Execute(const Args:array of string):boolean;override;
end;
implementation
uses typinfo;
uses typinfo,pkgmessages;
Function GetWord(var S : String; Sep : Char) : String;
@ -680,6 +682,7 @@ Var
L : TStrings;
begin
Log(vInfo,SLogGeneratingFPMake);
L:=TStringList.Create;
Try
StartInstaller(L);
@ -691,5 +694,11 @@ begin
end;
end;
end.
function TMakeFileConverter.Execute(const Args:array of string):boolean;
begin
{$warning TODO Check arguments}
ConvertFile(Args[1],Args[2]);
result:=true;
end;
end.

View File

@ -21,7 +21,7 @@ Type
implementation
uses process,pkgmessages;
uses process,pkghandler,pkgmessages;
Constructor TWGetDownloader.Create(AOWner : TComponent);
@ -70,4 +70,4 @@ end;
initialization
DownloaderClass:=TWGetDownloader;
end.
end.

363
utils/fppkg/streamcoll20.pp Executable file
View File

@ -0,0 +1,363 @@
{
This file is part of the Free Component Library (FCL)
Copyright (c) 1999-2000 by the Free Pascal development team
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{$ifndef ver2_0}
{$fatal This unit is only for compiling with 2.0.x, use the streamcoll from the FCL}
{$endif}
{$mode objfpc}
{$h+}
unit streamcoll20;
interface
uses
Classes,SysUtils;
type
TStreamCollectionItem = Class(TCollectionItem)
Protected
Procedure WriteInteger(S : TStream; AValue : Integer);
Procedure WriteBoolean(S : TStream; AValue : Boolean);
Procedure WriteString(S : TStream; AValue : String);
Procedure WriteCurrency(S : TStream; AValue : Currency);
Procedure WriteDateTime(S : TStream; AValue : TDateTime);
Procedure WriteFloat(S : TStream; AValue : Double);
Function ReadInteger(S : TStream) : Integer;
Function ReadBoolean(S : TStream) : Boolean;
Function ReadString(S : TStream) : String;
Function ReadCurrency(S : TStream) : Currency;
Function ReadDateTime(S : TStream) : TDateTime;
Function ReadFloat(S : TStream) : Double;
Procedure LoadFromStream(S : TStream; Streamversion : Integer); virtual; abstract;
Procedure SaveToStream(S : TStream); virtual; abstract;
end;
TStreamCollection = Class(TCollection)
Private
FStreaming : Boolean;
Protected
Procedure WriteInteger(S : TStream; AValue : Integer);
Procedure WriteBoolean(S : TStream; AValue : Boolean);
Procedure WriteString(S : TStream; AValue : String);
Procedure WriteCurrency(S : TStream; AValue : Currency);
Procedure WriteDateTime(S : TStream; AValue : TDateTime);
Procedure WriteFloat(S : TStream; AValue : Double);
Function ReadInteger(S : TStream) : Integer;
Function ReadBoolean(S : TStream) : Boolean;
Function ReadString(S : TStream) : String;
Function ReadCurrency(S : TStream) : Currency;
Function ReadDateTime(S : TStream) : TDateTime;
Function ReadFloat(S : TStream) : Double;
Procedure DoSaveToStream(S : TStream); virtual;
Function CurrentStreamVersion : Integer; Virtual;
Procedure DoLoadFromStream(S : TStream; Streamversion : Integer); virtual;
Public
Procedure LoadFromStream(S : TStream);
Procedure SaveToStream(S : TStream);
Property Streaming : Boolean Read FStreaming;
end;
EStreamColl = Class(Exception);
Procedure ColWriteInteger(S : TStream; AValue : Integer);
Procedure ColWriteBoolean(S : TStream; AValue : Boolean);
Procedure ColWriteString(S : TStream; AValue : String);
Procedure ColWriteCurrency(S : TStream; AValue : Currency);
Procedure ColWriteDateTime(S : TStream; AValue : TDateTime);
Procedure ColWriteFloat(S : TStream; AValue : Double);
Function ColReadInteger(S : TStream) : Integer;
Function ColReadBoolean(S : TStream) : Boolean;
Function ColReadString(S : TStream) : String;
Function ColReadCurrency(S : TStream) : Currency;
Function ColReadDateTime(S : TStream) : TDateTime;
Function ColReadFloat(S : TStream) : Double;
implementation
Resourcestring
SErrIllegalStreamVersion = 'Illegal stream version: %d > %d.';
Procedure ColWriteInteger(S : TStream; AValue : Integer);
begin
S.WriteBuffer(AValue,SizeOf(Integer));
end;
Procedure ColWriteBoolean(S : TStream; AValue : Boolean);
begin
ColWriteInteger(S,Ord(AValue));
end;
Procedure ColWriteString(S : TStream; AValue : String);
Var
L : Integer;
begin
L:=Length(AValue);
ColWriteInteger(S,L);
If (L>0) then
S.WriteBuffer(AValue[1],L);
end;
Procedure ColWriteCurrency(S : TStream; AValue : Currency);
begin
S.WriteBuffer(AValue,SizeOf(Currency));
end;
Procedure ColWriteDateTime(S : TStream; AValue : TDateTime);
begin
S.WriteBuffer(AValue,SizeOf(TDateTime));
end;
Procedure ColWriteFloat(S : TStream; AValue : Double);
begin
S.WriteBuffer(AValue,SizeOf(Double));
end;
Function ColReadInteger(S : TStream) : Integer;
begin
S.ReadBuffer(Result,SizeOf(Integer));
end;
Function ColReadBoolean(S : TStream) : Boolean;
Var
I : Integer;
begin
S.ReadBuffer(I,SizeOf(Integer));
Result:=(I<>0);
end;
Function ColReadString(S : TStream) : String;
Var
L : Integer;
begin
L:=ColReadInteger(S);
SetLength(Result,L);
If (L>0) then
S.ReadBuffer(Result[1],L);
end;
Function ColReadCurrency(S : TStream) : Currency;
begin
S.ReadBuffer(Result,SizeOf(Currency));
end;
Function ColReadDateTime(S : TStream) : TDateTime;
begin
S.ReadBuffer(Result,SizeOf(TDateTime));
end;
Function ColReadFloat(S : TStream) : Double;
begin
S.ReadBuffer(Result,SizeOf(Double));
end;
{ TStreamCollectionItem }
function TStreamCollectionItem.ReadBoolean(S: TStream): Boolean;
begin
Result:=ColReadBoolean(S);
end;
function TStreamCollectionItem.ReadCurrency(S: TStream): Currency;
begin
Result:=ColReadCurrency(S);
end;
function TStreamCollectionItem.ReadDateTime(S: TStream): TDateTime;
begin
Result:=ColReadDateTime(S);
end;
function TStreamCollectionItem.ReadFloat(S: TStream): Double;
begin
Result:=ColReadFloat(S);
end;
function TStreamCollectionItem.ReadInteger(S: TStream): Integer;
begin
Result:=ColReadinteger(S);
end;
function TStreamCollectionItem.ReadString(S: TStream): String;
begin
Result:=ColReadString(S);
end;
procedure TStreamCollectionItem.WriteBoolean(S: TStream; AValue: Boolean);
begin
ColWriteBoolean(S,AValue);
end;
procedure TStreamCollectionItem.WriteCurrency(S: TStream;
AValue: Currency);
begin
ColWriteCurrency(S,AValue);
end;
procedure TStreamCollectionItem.WriteDateTime(S: TStream;
AValue: TDateTime);
begin
ColWriteDateTime(S,AValue);
end;
procedure TStreamCollectionItem.WriteFloat(S: TStream; AValue: Double);
begin
ColWriteFloat(S,AValue);
end;
procedure TStreamCollectionItem.WriteInteger(S: TStream; AValue: Integer);
begin
ColWriteInteger(S,AValue);
end;
procedure TStreamCollectionItem.WriteString(S: TStream; AValue: String);
begin
ColWriteString(S,AValue);
end;
{ TStreamCollection }
function TStreamCollection.CurrentStreamVersion: Integer;
begin
Result:=0;
end;
procedure TStreamCollection.DoLoadFromStream(S: TStream;
Streamversion: Integer);
begin
If (Streamversion>CurrentStreamVersion) then
Raise EStreamColl.CreateFmt(SErrIllegalStreamVersion,[Streamversion,CurrentStreamVersion]);
end;
procedure TStreamCollection.DoSaveToStream(S: TStream);
begin
// Do nothing.
end;
procedure TStreamCollection.LoadFromStream(S: TStream);
Var
I,V,C : Integer;
begin
FStreaming:=True;
Try
V:=ReadInteger(S);
DoLoadFromStream(S,V);
Clear;
C:=ReadInteger(S);
For I:=1 to C do
With Add as TStreamCollectionItem do
LoadFromStream(S,V);
Finally
FStreaming:=False;
end;
end;
function TStreamCollection.ReadBoolean(S: TStream): Boolean;
begin
Result:=ColReadBoolean(S);
end;
function TStreamCollection.ReadCurrency(S: TStream): Currency;
begin
Result:=ColReadCurrency(S);
end;
function TStreamCollection.ReadDateTime(S: TStream): TDateTime;
begin
Result:=ColReadDateTime(S);
end;
function TStreamCollection.ReadFloat(S: TStream): Double;
begin
Result:=ColReadFloat(S);
end;
function TStreamCollection.ReadInteger(S: TStream): Integer;
begin
Result:=ColReadInteger(S);
end;
function TStreamCollection.ReadString(S: TStream): String;
begin
Result:=ColReadString(S);
end;
procedure TStreamCollection.SaveToStream(S: TStream);
Var
I : Integer;
begin
FStreaming:=True;
Try
WriteInteger(S,CurrentStreamVersion);
DoSaveToStream(S);
WriteInteger(S,Count);
For I:=0 to Count-1 do
With TStreamCollectionItem(Items[i]) do
SaveToStream(S);
Finally
FStreaming:=False;
end;
end;
procedure TStreamCollection.WriteBoolean(S: TStream; AValue: Boolean);
begin
ColWriteBoolean(S,AValue);
end;
procedure TStreamCollection.WriteCurrency(S: TStream; AValue: Currency);
begin
ColWriteCurrency(S,AValue);
end;
procedure TStreamCollection.WriteDateTime(S: TStream; AValue: TDateTime);
begin
ColWriteDateTime(S,AValue);
end;
procedure TStreamCollection.WriteFloat(S: TStream; AValue: Double);
begin
ColWriteFloat(S,AValue);
end;
procedure TStreamCollection.WriteInteger(S: TStream; AValue: Integer);
begin
ColWriteInteger(S,AValue);
end;
procedure TStreamCollection.WriteString(S: TStream; AValue: String);
begin
ColWriteString(S,AValue);
end;
end.