|
@@ -16,7 +16,7 @@
|
|
|
program FPDoc;
|
|
|
|
|
|
uses
|
|
|
- SysUtils, Classes, Gettext, DOM, XMLWrite, PasTree, PParser, custapp,
|
|
|
+ SysUtils, Classes, Gettext, custapp,
|
|
|
dGlobals, // GLobal definitions, constants.
|
|
|
dwriter, // TFPDocWriter definition.
|
|
|
dwlinear, // Linear (abstract) writer
|
|
@@ -27,13 +27,8 @@ uses
|
|
|
dw_ipflin, // IPF writer (new linear output)
|
|
|
dw_man, // Man page writer
|
|
|
dw_linrtf, // linear RTF writer
|
|
|
- dw_txt, fpdocproj, fpdocxmlopts; // TXT writer
|
|
|
+ dw_txt, fpdocproj, mkfpdoc; // TXT writer
|
|
|
|
|
|
-const
|
|
|
- DefOSTarget = {$I %FPCTARGETOS%};
|
|
|
- DefCPUTarget = {$I %FPCTARGETCPU%};
|
|
|
- DefFPCVersion = {$I %FPCVERSION%};
|
|
|
- DefFPCDate = {$I %FPCDATE%};
|
|
|
|
|
|
Type
|
|
|
|
|
@@ -41,16 +36,16 @@ Type
|
|
|
|
|
|
TFPDocAplication = Class(TCustomApplication)
|
|
|
private
|
|
|
- FProject : TFPDocProject;
|
|
|
- FProjectFile : Boolean;
|
|
|
+ FCreator : TFPDocCreator;
|
|
|
FPackage : TFPDocPackage;
|
|
|
+ FDryRun,
|
|
|
+ FProjectFile : Boolean;
|
|
|
FWriteProjectFile : String;
|
|
|
Protected
|
|
|
+ procedure OutputLog(Sender: TObject; const Msg: String);
|
|
|
procedure ParseCommandLine;
|
|
|
procedure Parseoption(const S: String);
|
|
|
Procedure Usage(AnExitCode : Byte);
|
|
|
- Procedure CreateProjectFile(Const AFileName : String);
|
|
|
- procedure CreateDocumentation(APackage : TFPDocPackage; Options : TEngineOptions);
|
|
|
Procedure DoRun; override;
|
|
|
Public
|
|
|
Constructor Create(AOwner : TComponent); override;
|
|
@@ -91,9 +86,11 @@ begin
|
|
|
Writeln(SUsageOption190);
|
|
|
Writeln(SUsageOption200);
|
|
|
Writeln(SUsageOption210);
|
|
|
+ Writeln(SUsageOption220);
|
|
|
+ Writeln(SUsageOption230);
|
|
|
L:=TStringList.Create;
|
|
|
Try
|
|
|
- Backend:=FProject.OPtions.Backend;
|
|
|
+ Backend:=FCreator.OPtions.Backend;
|
|
|
If (Backend='') then
|
|
|
begin
|
|
|
Writeln;
|
|
@@ -126,20 +123,10 @@ begin
|
|
|
Halt(AnExitCode);
|
|
|
end;
|
|
|
|
|
|
-procedure TFPDocAplication.CreateProjectFile(const AFileName: String);
|
|
|
-begin
|
|
|
- With TXMLFPDocOptions.Create(Self) do
|
|
|
- try
|
|
|
- SaveOptionsToFile(FProject,AFileName);
|
|
|
- finally
|
|
|
- Free;
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
destructor TFPDocAplication.Destroy;
|
|
|
|
|
|
begin
|
|
|
- FreeAndNil(FProject);
|
|
|
+ FreeAndNil(FCreator);
|
|
|
Inherited;
|
|
|
end;
|
|
|
|
|
@@ -153,6 +140,10 @@ begin
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
+procedure TFPDocAplication.OutputLog(Sender: TObject; const Msg: String);
|
|
|
+begin
|
|
|
+ Writeln(StdErr,Msg);
|
|
|
+end;
|
|
|
|
|
|
procedure TFPDocAplication.ParseCommandLine;
|
|
|
|
|
@@ -179,14 +170,14 @@ begin
|
|
|
s:=ParamStr(I);
|
|
|
If ProjectOpt(S) then
|
|
|
ParseOption(s);
|
|
|
- If (FProject.Packages.Count=1) then
|
|
|
- FPackage:=FProject.Packages[0]
|
|
|
- else if (FProject.Options.DefaultPackageName<>'') then
|
|
|
- Fpackage:=FProject.Packages.FindPackage(FProject.Options.DefaultPackageName);
|
|
|
+ If (FCreator.Packages.Count=1) then
|
|
|
+ FPackage:=FCreator.Packages[0]
|
|
|
+ else if (FCreator.Options.DefaultPackageName<>'') then
|
|
|
+ Fpackage:=FCreator.Packages.FindPackage(FCreator.Options.DefaultPackageName);
|
|
|
end;
|
|
|
- If FProject.Packages.Count=0 then
|
|
|
+ If FCreator.Project.Packages.Count=0 then
|
|
|
begin
|
|
|
- FPackage:=FProject.Packages.Add as TFPDocPackage;
|
|
|
+ FPackage:=FCreator.Packages.Add as TFPDocPackage;
|
|
|
end;
|
|
|
// Check package
|
|
|
for i := 1 to ParamCount do
|
|
@@ -233,15 +224,15 @@ begin
|
|
|
if (s = '-h') or (s = '--help') then
|
|
|
Usage(0)
|
|
|
else if s = '--hide-protected' then
|
|
|
- FProject.Options.HideProtected := True
|
|
|
+ FCreator.Options.HideProtected := True
|
|
|
else if s = '--warn-no-node' then
|
|
|
- FProject.Options.WarnNoNode := True
|
|
|
+ FCreator.Options.WarnNoNode := True
|
|
|
else if s = '--show-private' then
|
|
|
- FProject.Options.ShowPrivate := False
|
|
|
+ FCreator.Options.ShowPrivate := False
|
|
|
else if s = '--stop-on-parser-error' then
|
|
|
- FProject.Options.StopOnParseError := True
|
|
|
+ FCreator.Options.StopOnParseError := True
|
|
|
else if s = '--dont-trim' then
|
|
|
- FProject.Options.donttrim := True
|
|
|
+ FCreator.Options.donttrim := True
|
|
|
else
|
|
|
begin
|
|
|
i := Pos('=', s);
|
|
@@ -258,12 +249,7 @@ begin
|
|
|
if (Cmd = '--project') or (Cmd='-p') then
|
|
|
begin
|
|
|
FProjectFile:=True;
|
|
|
- With TXMLFPDocOptions.Create(self) do
|
|
|
- try
|
|
|
- LoadOptionsFromFile(FProject,Arg);
|
|
|
- finally
|
|
|
- Free;
|
|
|
- end;
|
|
|
+ FCreator.LoadProjectFile(Arg);
|
|
|
end
|
|
|
else if (Cmd = '--descr') then
|
|
|
AddToFileList(SelectedPackage.Descriptions, Arg)
|
|
@@ -273,14 +259,18 @@ begin
|
|
|
If FindWriterClass(Arg)=-1 then
|
|
|
WriteLn(StdErr, Format(SCmdLineInvalidFormat, [Arg]))
|
|
|
else
|
|
|
- FProject.Options.BackEnd:=Arg;
|
|
|
+ FCreator.Options.BackEnd:=Arg;
|
|
|
end
|
|
|
else if (Cmd = '-l') or (Cmd = '--lang') then
|
|
|
- FProject.Options.Language := Arg
|
|
|
+ FCreator.Options.Language := Arg
|
|
|
else if (Cmd = '-i') or (Cmd = '--input') then
|
|
|
AddToFileList(SelectedPackage.Inputs, Arg)
|
|
|
else if (Cmd = '-o') or (Cmd = '--output') then
|
|
|
SelectedPackage.Output := Arg
|
|
|
+ else if (Cmd = '-v') or (Cmd = '--verbose') then
|
|
|
+ FCreator.Verbose:=true
|
|
|
+ else if (Cmd = '-n') or (Cmd = '--dry-run') then
|
|
|
+ FDryRun:=True
|
|
|
else if Cmd = '--content' then
|
|
|
SelectedPackage.ContentFile := Arg
|
|
|
else if Cmd = '--import' then
|
|
@@ -288,91 +278,28 @@ begin
|
|
|
else if Cmd = '--package' then
|
|
|
begin
|
|
|
If FProjectFile then
|
|
|
- FPackage:=FProject.Packages.FindPackage(Arg)
|
|
|
+ FPackage:=FCreator.Packages.FindPackage(Arg)
|
|
|
else
|
|
|
FPackage.Name:=Arg;
|
|
|
end
|
|
|
else if Cmd = '--ostarget' then
|
|
|
- FProject.Options.OSTarget := Arg
|
|
|
+ FCreator.Options.OSTarget := Arg
|
|
|
else if Cmd = '--cputarget' then
|
|
|
- FProject.Options.CPUTarget := Arg
|
|
|
+ FCreator.Options.CPUTarget := Arg
|
|
|
else if Cmd = '--mo-dir' then
|
|
|
- FProject.Options.modir := Arg
|
|
|
+ FCreator.Options.modir := Arg
|
|
|
else if Cmd = '--parse-impl' then
|
|
|
- FProject.Options.InterfaceOnly:=false
|
|
|
+ FCreator.Options.InterfaceOnly:=false
|
|
|
else if Cmd = '--write-project' then
|
|
|
FWriteProjectFile:=Arg
|
|
|
else
|
|
|
begin
|
|
|
- FProject.Options.BackendOptions.Add(Cmd);
|
|
|
- FProject.Options.BackendOptions.Add(Arg);
|
|
|
+ FCreator.Options.BackendOptions.Add(Cmd);
|
|
|
+ FCreator.Options.BackendOptions.Add(Arg);
|
|
|
end;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-
|
|
|
-procedure TFPDocAplication.CreateDocumentation(APackage : TFPDocPackage; Options : TEngineOptions);
|
|
|
-
|
|
|
-var
|
|
|
- i,j: Integer;
|
|
|
- WriterClass : TFPDocWriterClass;
|
|
|
- Writer : TFPDocWriter;
|
|
|
- Engine : TFPDocEngine;
|
|
|
- Cmd,Arg : String;
|
|
|
-
|
|
|
-begin
|
|
|
- Engine:=TFPDocEngine.Create;
|
|
|
- try
|
|
|
- For J:=0 to Apackage.Imports.Count-1 do
|
|
|
- begin
|
|
|
- Arg:=Apackage.Imports[j];
|
|
|
- i := Pos(',', Arg);
|
|
|
- Engine.ReadContentFile(Copy(Arg,1,i-1),Copy(Arg,i+1,Length(Arg)));
|
|
|
- end;
|
|
|
- for i := 0 to APackage.Descriptions.Count - 1 do
|
|
|
- Engine.AddDocFile(APackage.Descriptions[i],Options.donttrim);
|
|
|
- Engine.SetPackageName(APackage.Name);
|
|
|
- Engine.Output:=APackage.Output;
|
|
|
- Engine.HideProtected:=Options.HideProtected;
|
|
|
- Engine.HidePrivate:=Not Options.ShowPrivate;
|
|
|
- if Length(Options.Language) > 0 then
|
|
|
- TranslateDocStrings(Options.Language);
|
|
|
- for i := 0 to Fpackage.Inputs.Count - 1 do
|
|
|
- try
|
|
|
- ParseSource(Engine, APackage.Inputs[i], Options.OSTarget, Options.CPUTarget);
|
|
|
- except
|
|
|
- on e: EParserError do
|
|
|
- If Options.StopOnParseError then
|
|
|
- Raise
|
|
|
- else
|
|
|
- WriteLn(StdErr, Format('%s(%d,%d): %s',
|
|
|
- [e.Filename, e.Row, e.Column, e.Message]));
|
|
|
- end;
|
|
|
- WriterClass:=GetWriterClass(Options.Backend);
|
|
|
- Writer:=WriterClass.Create(Engine.Package,Engine);
|
|
|
- Writeln('Writing doc');
|
|
|
- With Writer do
|
|
|
- Try
|
|
|
- If Options.BackendOptions.Count>0 then
|
|
|
- for I:=0 to ((Options.BackendOptions.Count-1) div 2) do
|
|
|
- begin
|
|
|
- Cmd:=Options.BackendOptions[I*2];
|
|
|
- Arg:=Options.BackendOptions[I*2+1];
|
|
|
- If not InterPretOption(Cmd,Arg) then
|
|
|
- WriteLn(StdErr, Format(SCmdLineInvalidOption,[Cmd+'='+Arg]));
|
|
|
- end;
|
|
|
- WriteDoc;
|
|
|
- Finally
|
|
|
- Free;
|
|
|
- end;
|
|
|
- if Length(FPackage.ContentFile) > 0 then
|
|
|
- Engine.WriteContentFile(FPackage.ContentFile);
|
|
|
- finally
|
|
|
- FreeAndNil(Engine);
|
|
|
- end;
|
|
|
-end;
|
|
|
-
|
|
|
-
|
|
|
Procedure TFPDocAplication.DoRun;
|
|
|
|
|
|
begin
|
|
@@ -387,9 +314,9 @@ begin
|
|
|
WriteLn;
|
|
|
ParseCommandLine;
|
|
|
if (FWriteProjectFile<>'') then
|
|
|
- CreateProjectFile(FWriteProjectFile)
|
|
|
+ FCreator.CreateProjectFile(FWriteProjectFile)
|
|
|
else
|
|
|
- CreateDocumentation(FPackage,FProject.Options);
|
|
|
+ FCreator.CreateDocumentation(FPackage,FDryRun);
|
|
|
WriteLn(SDone);
|
|
|
Terminate;
|
|
|
end;
|
|
@@ -398,10 +325,8 @@ constructor TFPDocAplication.Create(AOwner: TComponent);
|
|
|
begin
|
|
|
inherited Create(AOwner);
|
|
|
StopOnException:=true;
|
|
|
- FProject:=TFPDOCproject.Create(Nil);
|
|
|
- FProject.Options.StopOnParseError:=False;
|
|
|
- FProject.Options.CPUTarget:=DefCPUTarget;
|
|
|
- FProject.Options.OSTarget:=DefOSTarget;
|
|
|
+ FCreator:=TFPDocCreator.Create(Self);
|
|
|
+ FCreator.OnLog:=@OutputLog;
|
|
|
end;
|
|
|
|
|
|
begin
|