From c17d15cf72e6e8dc74ede323924e3ddd95c0fe49 Mon Sep 17 00:00:00 2001 From: michael Date: Fri, 2 Dec 2011 18:44:58 +0000 Subject: [PATCH] * Start of project file manipulation program git-svn-id: trunk@19725 - --- .gitattributes | 2 + utils/fpdoc/mkfpdocproj.lpi | 69 ++++++++++++++++++ utils/fpdoc/mkfpdocproj.pp | 141 ++++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 utils/fpdoc/mkfpdocproj.lpi create mode 100644 utils/fpdoc/mkfpdocproj.pp diff --git a/.gitattributes b/.gitattributes index 7d754145de..66c5e21b83 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12910,6 +12910,8 @@ utils/fpdoc/intl/fpdocstr.de.po svneol=native#text/plain utils/fpdoc/intl/makeskel.de.po svneol=native#text/plain utils/fpdoc/makeskel.lpi svneol=native#text/plain utils/fpdoc/makeskel.pp svneol=native#text/plain +utils/fpdoc/mkfpdocproj.lpi svneol=native#text/plain +utils/fpdoc/mkfpdocproj.pp svneol=native#text/plain utils/fpdoc/sample-project.xml svneol=native#text/plain utils/fpdoc/sh_pas.pp svneol=native#text/plain utils/fpdoc/testunit.pp svneol=native#text/plain diff --git a/utils/fpdoc/mkfpdocproj.lpi b/utils/fpdoc/mkfpdocproj.lpi new file mode 100644 index 0000000000..a8525a91fd --- /dev/null +++ b/utils/fpdoc/mkfpdocproj.lpi @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/utils/fpdoc/mkfpdocproj.pp b/utils/fpdoc/mkfpdocproj.pp new file mode 100644 index 0000000000..40dbede0da --- /dev/null +++ b/utils/fpdoc/mkfpdocproj.pp @@ -0,0 +1,141 @@ +program mkfpdocproj; + +{$mode objfpc}{$H+} + +uses + Classes, SysUtils, fpdocproj, fpdocxmlopts, CustApp; + +type + + { TManageFPDocProjectApplication } + + TManageFPDocProjectApplication = class(TCustomApplication) + private + procedure ParseOptions; + protected + FRecurse : boolean; + FDirectory, + FMask, + FPackageName, + FInputFileName, + FOutputFileName : String; + FProject : TFPDocProject; + FPackage : TFPDocPackage; + procedure ReadOptionFile(const AFileName: String); + procedure Usage(AExitCode: Integer); + procedure WriteOptionFile(const AFileName: String); + procedure AddFilesFromDirectory(ADirectory, AMask: String; ARecurse: Boolean); + procedure DoRun; override; + public + constructor Create(TheOwner: TComponent); override; + end; + +{ TManageFPDocProjectApplication } + +procedure TManageFPDocProjectApplication.Usage(AExitCode : Integer); + +begin + // to be filled + Halt(AExitCode); +end; + +procedure TManageFPDocProjectApplication.ParseOptions; + +Var + PN : String; + +begin + FInputFileName:=GetOptionValue('i','input'); + FOutputFileName:=GetOptionValue('o','output'); + FPackageName:=GetOptionValue('p','package'); + if (FOutputFileName='') then + FOutputFileName:=FInputFileName; + FDirectory:=GetOptionValue('d','directory'); + FMask:=GetOptionValue('m','mask'); + FRecurse:=HasOption('r','recurse'); + if HasOption('h','help') then + Usage(0); +end; + +Procedure TManageFPDocProjectApplication.AddFilesFromDirectory(ADirectory,AMask : String; ARecurse : Boolean); + +Var + Info : TSearchRec; + D : String; + +begin + if (AMask='') then + AMask:='*.xml'; + D:=ADirectory; + if (D<>'') then + D:=includeTrailingPathDelimiter(D); + If FindFirst(D+AMask,0,info)=0 then + try + Repeat + if ((Info.Attr and faDirectory)=0) then + FPackage.Descriptions.add(D+Info.Name); + Until (FindNext(Info)<>0); + finally + FindClose(Info); + end; + If ARecurse and (FindFirst(ADirectory+AMask,0,info)=0) then + try + Repeat + if ((Info.Attr and faDirectory)<>0) then + AddFilesFromDirectory(IncludeTrailingPathDelimiter(D+Info.Name),AMask,ARecurse); + Until (FindNext(Info)<>0); + finally + FindClose(Info); + end; +end; + +procedure TManageFPDocProjectApplication.ReadOptionFile(Const AFileName : String); + +begin + With TXMLFPDocOptions.Create(Self) do + try + LoadOptionsFromFile(FProject,AFileName); + finally + Free; + end; +end; + +procedure TManageFPDocProjectApplication.WriteOptionFile(Const AFileName : String); + +begin + With TXMLFPDocOptions.Create(Self) do + try + SaveOptionsToFile(FProject,AFileName); + finally + Free; + end; +end; + +procedure TManageFPDocProjectApplication.DoRun; + +begin + ParseOptions; + ReadOptionFile(FInputFileName); + FPackage:=FProject.Packages.FindPackage(FPackageName); + If (FDirectory<>'') or (FMask<>'') then + AddFilesFromDirectory(FDirectory,FMask, FRecurse); + WriteOptionFile(FOutputFileName); + Terminate; +end; + +constructor TManageFPDocProjectApplication.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + StopOnException:=True; + FProject:=TFPDocProject.Create(Self); +end; + +var + Application: TManageFPDocProjectApplication; +begin + Application:=TManageFPDocProjectApplication.Create(nil); + Application.Title:='Program to manipulate FPDoc project files'; + Application.Run; + Application.Free; +end. +