mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-01 21:10:14 +02:00
* Implemented project file writing functionality, based on patch from Hans-Peter Diettrich
git-svn-id: trunk@19724 -
This commit is contained in:
parent
37abdd52df
commit
e07646a653
@ -150,6 +150,8 @@ resourcestring
|
|||||||
SUsageOption180 = '--mo-dir=dir Set directory where language files reside to dir';
|
SUsageOption180 = '--mo-dir=dir Set directory where language files reside to dir';
|
||||||
SUsageOption190 = '--parse-impl (Experimental) try to parse implementation too';
|
SUsageOption190 = '--parse-impl (Experimental) try to parse implementation too';
|
||||||
SUsageOption200 = '--dont-trim Don''t trim XML contents';
|
SUsageOption200 = '--dont-trim Don''t trim XML contents';
|
||||||
|
SUsageOption210 = '--write-project=file Do not write documentation, create project file instead';
|
||||||
|
|
||||||
SUsageFormats = 'The following output formats are supported by this fpdoc:';
|
SUsageFormats = 'The following output formats are supported by this fpdoc:';
|
||||||
SUsageBackendHelp = 'Specify an output format, combined with --help to get more help for this backend.';
|
SUsageBackendHelp = 'Specify an output format, combined with --help to get more help for this backend.';
|
||||||
SUsageFormatSpecific = 'Output format "%s" supports the following options:';
|
SUsageFormatSpecific = 'Output format "%s" supports the following options:';
|
||||||
|
@ -114,7 +114,7 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="10"/>
|
<Version Value="11"/>
|
||||||
<Target>
|
<Target>
|
||||||
<Filename Value="fpdoc"/>
|
<Filename Value="fpdoc"/>
|
||||||
</Target>
|
</Target>
|
||||||
|
@ -44,10 +44,12 @@ Type
|
|||||||
FProject : TFPDocProject;
|
FProject : TFPDocProject;
|
||||||
FProjectFile : Boolean;
|
FProjectFile : Boolean;
|
||||||
FPackage : TFPDocPackage;
|
FPackage : TFPDocPackage;
|
||||||
|
FWriteProjectFile : String;
|
||||||
Protected
|
Protected
|
||||||
procedure ParseCommandLine;
|
procedure ParseCommandLine;
|
||||||
procedure Parseoption(const S: String);
|
procedure Parseoption(const S: String);
|
||||||
Procedure Usage(AnExitCode : Byte);
|
Procedure Usage(AnExitCode : Byte);
|
||||||
|
Procedure CreateProjectFile(Const AFileName : String);
|
||||||
procedure CreateDocumentation(APackage : TFPDocPackage; Options : TEngineOptions);
|
procedure CreateDocumentation(APackage : TFPDocPackage; Options : TEngineOptions);
|
||||||
Procedure DoRun; override;
|
Procedure DoRun; override;
|
||||||
Public
|
Public
|
||||||
@ -88,6 +90,7 @@ begin
|
|||||||
Writeln(SUsageOption180);
|
Writeln(SUsageOption180);
|
||||||
Writeln(SUsageOption190);
|
Writeln(SUsageOption190);
|
||||||
Writeln(SUsageOption200);
|
Writeln(SUsageOption200);
|
||||||
|
Writeln(SUsageOption210);
|
||||||
L:=TStringList.Create;
|
L:=TStringList.Create;
|
||||||
Try
|
Try
|
||||||
Backend:=FProject.OPtions.Backend;
|
Backend:=FProject.OPtions.Backend;
|
||||||
@ -123,6 +126,16 @@ begin
|
|||||||
Halt(AnExitCode);
|
Halt(AnExitCode);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TFPDocAplication.CreateProjectFile(const AFileName: String);
|
||||||
|
begin
|
||||||
|
With TXMLFPDocOptions.Create(Self) do
|
||||||
|
try
|
||||||
|
SaveOptionsToFile(FProject,AFileName);
|
||||||
|
finally
|
||||||
|
Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
destructor TFPDocAplication.Destroy;
|
destructor TFPDocAplication.Destroy;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -188,11 +201,7 @@ begin
|
|||||||
If Not (ProjectOpt(s) or PackageOpt(S)) then
|
If Not (ProjectOpt(s) or PackageOpt(S)) then
|
||||||
ParseOption(s);
|
ParseOption(s);
|
||||||
end;
|
end;
|
||||||
if (FPackage=Nil) or (FPackage.Name='') then
|
SelectedPackage; // Will print error if none available.
|
||||||
begin
|
|
||||||
Writeln(SNeedPackageName);
|
|
||||||
Usage(1);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFPDocAplication.Parseoption(Const S : String);
|
procedure TFPDocAplication.Parseoption(Const S : String);
|
||||||
@ -291,6 +300,8 @@ begin
|
|||||||
FProject.Options.modir := Arg
|
FProject.Options.modir := Arg
|
||||||
else if Cmd = '--parse-impl' then
|
else if Cmd = '--parse-impl' then
|
||||||
FProject.Options.InterfaceOnly:=false
|
FProject.Options.InterfaceOnly:=false
|
||||||
|
else if Cmd = '--write-project' then
|
||||||
|
FWriteProjectFile:=Arg
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
FProject.Options.BackendOptions.Add(Cmd);
|
FProject.Options.BackendOptions.Add(Cmd);
|
||||||
@ -375,7 +386,10 @@ begin
|
|||||||
WriteLn(SCopyright);
|
WriteLn(SCopyright);
|
||||||
WriteLn;
|
WriteLn;
|
||||||
ParseCommandLine;
|
ParseCommandLine;
|
||||||
CreateDocumentation(FPackage,FProject.Options);
|
if (FWriteProjectFile<>'') then
|
||||||
|
CreateProjectFile(FWriteProjectFile)
|
||||||
|
else
|
||||||
|
CreateDocumentation(FPackage,FProject.Options);
|
||||||
WriteLn(SDone);
|
WriteLn(SDone);
|
||||||
Terminate;
|
Terminate;
|
||||||
end;
|
end;
|
||||||
|
@ -8,9 +8,6 @@ uses
|
|||||||
Classes, SysUtils, fpdocproj, dom;
|
Classes, SysUtils, fpdocproj, dom;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
|
|
||||||
{ TXMLFPocOptions }
|
|
||||||
|
|
||||||
{ TXMLFPDocOptions }
|
{ TXMLFPDocOptions }
|
||||||
|
|
||||||
TXMLFPDocOptions = Class(TComponent)
|
TXMLFPDocOptions = Class(TComponent)
|
||||||
@ -20,15 +17,21 @@ Type
|
|||||||
Procedure LoadPackage(APackage : TFPDocPackage; E : TDOMElement); virtual;
|
Procedure LoadPackage(APackage : TFPDocPackage; E : TDOMElement); virtual;
|
||||||
Procedure LoadPackages(Packages : TFPDocPackages; E : TDOMElement);
|
Procedure LoadPackages(Packages : TFPDocPackages; E : TDOMElement);
|
||||||
Procedure LoadEngineOptions(Options : TEngineOptions; E : TDOMElement); virtual;
|
Procedure LoadEngineOptions(Options : TEngineOptions; E : TDOMElement); virtual;
|
||||||
|
Procedure SaveEngineOptions(Options : TEngineOptions; XML : TXMLDocument; AParent : TDOMElement); virtual;
|
||||||
|
procedure SaveDescription(const ADescription: String; XML: TXMLDocument; AParent: TDOMElement); virtual;
|
||||||
|
procedure SaveInputFile(const AInputFile: String; XML: TXMLDocument; AParent: TDOMElement);virtual;
|
||||||
|
Procedure SavePackage(APackage : TFPDocPackage; XML : TXMLDocument; AParent : TDOMElement); virtual;
|
||||||
Public
|
Public
|
||||||
Procedure LoadOptionsFromFile(AProject : TFPDocProject; Const AFileName : String);
|
Procedure LoadOptionsFromFile(AProject : TFPDocProject; Const AFileName : String);
|
||||||
Procedure LoadFromXML(AProject : TFPDocProject; XML : TXMLDocument); virtual;
|
Procedure LoadFromXML(AProject : TFPDocProject; XML : TXMLDocument); virtual;
|
||||||
|
Procedure SaveOptionsToFile(AProject : TFPDocProject; Const AFileName : String);
|
||||||
|
procedure SaveToXML(AProject : TFPDocProject; ADoc: TXMLDocument); virtual;
|
||||||
end;
|
end;
|
||||||
EXMLFPdoc = Class(Exception);
|
EXMLFPdoc = Class(Exception);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
Uses XMLRead;
|
Uses XMLRead, XMLWrite;
|
||||||
|
|
||||||
Resourcestring
|
Resourcestring
|
||||||
SErrInvalidRootNode = 'Invalid options root node: Got "%s", expected "docproject"';
|
SErrInvalidRootNode = 'Invalid options root node: Got "%s", expected "docproject"';
|
||||||
@ -36,6 +39,9 @@ Resourcestring
|
|||||||
SErrNoInputFile = 'unit tag without file attribute found';
|
SErrNoInputFile = 'unit tag without file attribute found';
|
||||||
SErrNoDescrFile = 'description tag without file attribute';
|
SErrNoDescrFile = 'description tag without file attribute';
|
||||||
|
|
||||||
|
const
|
||||||
|
ProjectTemplate = 'template-project.xml';
|
||||||
|
|
||||||
{ TXMLFPDocOptions }
|
{ TXMLFPDocOptions }
|
||||||
|
|
||||||
Function IndexOfString(S : String; List : Array of string) : Integer;
|
Function IndexOfString(S : String; List : Array of string) : Integer;
|
||||||
@ -97,7 +103,7 @@ Var
|
|||||||
begin
|
begin
|
||||||
APackage.Name:=E['name'];
|
APackage.Name:=E['name'];
|
||||||
APackage.output:=E['output'];
|
APackage.output:=E['output'];
|
||||||
APackage.ContentFile:=E['contentfile'];
|
APackage.ContentFile:=E['content'];
|
||||||
N:=E.FirstChild;
|
N:=E.FirstChild;
|
||||||
While (N<>Nil) do
|
While (N<>Nil) do
|
||||||
begin
|
begin
|
||||||
@ -197,8 +203,155 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TXMLFPDocOptions.LoadOptionsFromFile(AProject: TFPDocProject;
|
procedure TXMLFPDocOptions.SaveToXML(AProject: TFPDocProject; ADoc: TXMLDocument);
|
||||||
const AFileName: String);
|
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
E,PE: TDOMElement;
|
||||||
|
|
||||||
|
begin
|
||||||
|
E:=ADoc.CreateElement('docproject');
|
||||||
|
ADoc.AppendChild(E);
|
||||||
|
E:=ADoc.CreateElement('options');
|
||||||
|
ADoc.DocumentElement.AppendChild(E);
|
||||||
|
SaveEngineOptions(AProject.Options,ADoc,E);
|
||||||
|
E:=ADoc.CreateElement('packages');
|
||||||
|
ADoc.DocumentElement.AppendChild(E);
|
||||||
|
for i := 0 to AProject.Packages.Count - 1 do
|
||||||
|
begin
|
||||||
|
PE:=ADoc.CreateElement('package');
|
||||||
|
E.AppendChild(PE);
|
||||||
|
SavePackage(AProject.Packages[i],ADoc,PE);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure TXMLFPDocOptions.SaveEngineOptions(Options : TEngineOptions; XML : TXMLDocument; AParent : TDOMElement);
|
||||||
|
|
||||||
|
procedure AddStr(const n, v: string);
|
||||||
|
var
|
||||||
|
E : TDOMElement;
|
||||||
|
begin
|
||||||
|
if (v='') then
|
||||||
|
Exit;
|
||||||
|
E:=XML.CreateElement('option');
|
||||||
|
AParent.AppendChild(E);
|
||||||
|
E['name'] := n;
|
||||||
|
E['value'] := v;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure AddBool(const AName: string; B: Boolean);
|
||||||
|
|
||||||
|
begin
|
||||||
|
if B then
|
||||||
|
AddStr(Aname,'true')
|
||||||
|
else
|
||||||
|
AddStr(Aname,'false');
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
n: string;
|
||||||
|
|
||||||
|
begin
|
||||||
|
AddStr('ostarget', Options.OSTarget);
|
||||||
|
AddStr('cputarget', Options.CPUTarget);
|
||||||
|
AddStr('mo-dir', Options.MoDir);
|
||||||
|
AddStr('format', Options.Backend);
|
||||||
|
AddStr('language', Options.Language);
|
||||||
|
AddStr('package', Options.DefaultPackageName);
|
||||||
|
AddBool('hide-protected', Options.HideProtected);
|
||||||
|
AddBool('warn-no-node', Options.WarnNoNode);
|
||||||
|
AddBool('show-private', Options.ShowPrivate);
|
||||||
|
AddBool('stop-on-parser-error', Options.StopOnParseError);
|
||||||
|
AddBool('parse-impl', Options.InterfaceOnly);
|
||||||
|
AddBool('dont-trim', Options.DontTrim);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure TXMLFPDocOptions.SaveInputFile(Const AInputFile : String; XML : TXMLDocument; AParent: TDOMElement);
|
||||||
|
|
||||||
|
Function GetNextWord(Var s : string) : String;
|
||||||
|
|
||||||
|
Const
|
||||||
|
WhiteSpace = [' ',#9,#10,#13];
|
||||||
|
|
||||||
|
var
|
||||||
|
i,j: integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
I:=1;
|
||||||
|
While (I<=Length(S)) and (S[i] in WhiteSpace) do
|
||||||
|
Inc(I);
|
||||||
|
J:=I;
|
||||||
|
While (J<=Length(S)) and (not (S[J] in WhiteSpace)) do
|
||||||
|
Inc(J);
|
||||||
|
if (I<=Length(S)) then
|
||||||
|
Result:=Copy(S,I,J-I);
|
||||||
|
Delete(S,1,J);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Var
|
||||||
|
S,W,F,O : String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
S:=AInputFile;
|
||||||
|
While (S<>'') do
|
||||||
|
begin
|
||||||
|
W:=GetNextWord(S);
|
||||||
|
If (W<>'') then
|
||||||
|
begin
|
||||||
|
if W[1]='-' then
|
||||||
|
begin
|
||||||
|
if (O<>'') then
|
||||||
|
O:=O+' ';
|
||||||
|
o:=O+W;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
F:=W;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
AParent['file']:=F;
|
||||||
|
AParent['options']:=O;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure TXMLFPDocOptions.SaveDescription(Const ADescription : String; XML : TXMLDocument; AParent: TDOMElement);
|
||||||
|
|
||||||
|
begin
|
||||||
|
AParent['file']:=ADescription;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Procedure TXMLFPDocOptions.SavePackage(APackage: TFPDocPackage; XML : TXMLDocument; AParent: TDOMElement);
|
||||||
|
|
||||||
|
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
E,PE : TDomElement;
|
||||||
|
|
||||||
|
begin
|
||||||
|
AParent['name']:=APackage.Name;
|
||||||
|
AParent['output']:=APackage.Output;
|
||||||
|
AParent['content']:=APackage.ContentFile;
|
||||||
|
// Units
|
||||||
|
PE:=XML.CreateElement('units');
|
||||||
|
AParent.AppendChild(PE);
|
||||||
|
for i:=0 to APackage.Inputs.Count-1 do
|
||||||
|
begin
|
||||||
|
E:=XML.CreateElement('unit');
|
||||||
|
PE.AppendChild(E);
|
||||||
|
SaveInputFile(APackage.Inputs[i],XML,E);
|
||||||
|
end;
|
||||||
|
// Descriptions
|
||||||
|
PE:=XML.CreateElement('descriptions');
|
||||||
|
AParent.AppendChild(PE);
|
||||||
|
for i:=0 to APackage.Descriptions.Count-1 do
|
||||||
|
begin
|
||||||
|
E:=XML.CreateElement('description');
|
||||||
|
PE.AppendChild(E);
|
||||||
|
SaveDescription(APackage.Descriptions[i],XML,E);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TXMLFPDocOptions.LoadOptionsFromFile(AProject: TFPDocProject; const AFileName: String);
|
||||||
|
|
||||||
Var
|
Var
|
||||||
XML : TXMLDocument;
|
XML : TXMLDocument;
|
||||||
@ -232,5 +385,20 @@ begin
|
|||||||
LoadEngineOptions(AProject.Options,N as TDOMElement);
|
LoadEngineOptions(AProject.Options,N as TDOMElement);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Procedure TXMLFPDocOptions.SaveOptionsToFile(AProject: TFPDocProject; const AFileName: String);
|
||||||
|
|
||||||
|
Var
|
||||||
|
XML : TXMLDocument;
|
||||||
|
|
||||||
|
begin
|
||||||
|
XML:=TXMLDocument.Create;
|
||||||
|
try
|
||||||
|
SaveToXML(AProject,XML);
|
||||||
|
WriteXMLFile(XML, AFileName);
|
||||||
|
finally
|
||||||
|
XML.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user