From d6726a6ade10014408e94943dc118a6eefe2493a Mon Sep 17 00:00:00 2001 From: marco Date: Wed, 31 Aug 2011 19:33:20 +0000 Subject: [PATCH] * --dont-trim avoids trimming while loading XMLs. Mantis #16683 git-svn-id: trunk@18924 - --- utils/fpdoc/dglobals.pp | 39 ++++++++++++++++++++++++++++++++---- utils/fpdoc/fpdoc.pp | 5 ++++- utils/fpdoc/fpdocproj.pas | 2 ++ utils/fpdoc/fpdocxmlopts.pas | 5 +++-- 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/utils/fpdoc/dglobals.pp b/utils/fpdoc/dglobals.pp index e85689dce2..8e0fd98a14 100644 --- a/utils/fpdoc/dglobals.pp +++ b/utils/fpdoc/dglobals.pp @@ -23,7 +23,7 @@ unit dGlobals; interface -uses Classes, DOM, PasTree, PParser, StrUtils; +uses Classes, DOM, PasTree, PParser, StrUtils,uriparser; Var LEOL : Integer; @@ -149,6 +149,7 @@ resourcestring SUsageOption170 = '--warn-no-node Warn if no documentation node was found.'; SUsageOption180 = '--mo-dir=dir Set directory where language files reside to dir'; SUsageOption190 = '--parse-impl (Experimental) try to parse implementation too'; + SUsageOption200 = '--dont-trim Don''t trim XML contents'; 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.'; SUsageFormatSpecific = 'Output format "%s" supports the following options:'; @@ -300,7 +301,7 @@ type function FindLinkedNode(ANode: TDocNode): TDocNode; // Documentation file support - procedure AddDocFile(const AFilename: String); + procedure AddDocFile(const AFilename: String;DontTrim:boolean=false); // Documentation retrieval function FindDocNode(AElement: TPasElement): TDocNode; @@ -1255,7 +1256,34 @@ begin end; end; -procedure TFPDocEngine.AddDocFile(const AFilename: String); +procedure ReadXMLFileALT(OUT ADoc:TXMLDocument;const AFileName:ansistring); +var + Parser: TDOMParser; + Src: TXMLInputSource; + FileStream: TStream; +begin + ADoc := nil; + FileStream := TFileStream.Create(AFilename, fmOpenRead+fmShareDenyWrite); + try + Parser := TDOMParser.Create; // create a parser object + try + Src := TXMLInputSource.Create(FileStream); // and the input source + src.SystemId:=FileNameToUri(AFileName); + try + Parser.Options.PreserveWhitespace := True; + Parser.Parse(Src, ADoc); + finally + Src.Free; // cleanup + end; + finally + Parser.Free; + end; + finally + FileStream.Free; + end; +end; + +procedure TFPDocEngine.AddDocFile(const AFilename: String;DontTrim:boolean=false); function ReadNode(OwnerDocNode: TDocNode; Element: TDOMElement): TDocNode; var @@ -1318,7 +1346,10 @@ var PackageDocNode, TopicNode,ModuleDocNode: TDocNode; begin - ReadXMLFile(Doc, AFilename); + if DontTrim then + ReadXMLFileALT(Doc, AFilename) + else + ReadXMLFile(Doc, AFilename); DescrDocs.Add(Doc); DescrDocNames.Add(AFilename); diff --git a/utils/fpdoc/fpdoc.pp b/utils/fpdoc/fpdoc.pp index c9c500c15b..041b10917a 100644 --- a/utils/fpdoc/fpdoc.pp +++ b/utils/fpdoc/fpdoc.pp @@ -87,6 +87,7 @@ begin Writeln(SUsageOption170); Writeln(SUsageOption180); Writeln(SUsageOption190); + Writeln(SUsageOption200); L:=TStringList.Create; Try Backend:=FProject.OPtions.Backend; @@ -230,6 +231,8 @@ begin FProject.Options.ShowPrivate := False else if s = '--stop-on-parser-error' then FProject.Options.StopOnParseError := True + else if s = '--dont-trim' then + FProject.Options.donttrim := True else begin i := Pos('=', s); @@ -316,7 +319,7 @@ begin 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]); + Engine.AddDocFile(APackage.Descriptions[i],Options.donttrim); Engine.SetPackageName(APackage.Name); Engine.Output:=APackage.Output; Engine.HideProtected:=Options.HideProtected; diff --git a/utils/fpdoc/fpdocproj.pas b/utils/fpdoc/fpdocproj.pas index b72a824d76..65119f4603 100644 --- a/utils/fpdoc/fpdocproj.pas +++ b/utils/fpdoc/fpdocproj.pas @@ -59,6 +59,7 @@ Type FOSTarget: String; FSOPE: Boolean; FWarnNoNode: Boolean; + FDontTrim : Boolean; procedure SetBackendOptions(const AValue: TStrings); Public Constructor Create; @@ -77,6 +78,7 @@ Type Property InterfaceOnly : Boolean Read FIO Write FIO; Property MoDir : String Read FMoDir Write FMODir; Property DefaultPackageName : String Read FDefaultPackageName Write FDefaultPackageName; + Property DontTrim : Boolean Read FDontTrim Write FDontTrim; end; { TFPDocProject } diff --git a/utils/fpdoc/fpdocxmlopts.pas b/utils/fpdoc/fpdocxmlopts.pas index 257afb2b12..9271c8700d 100644 --- a/utils/fpdoc/fpdocxmlopts.pas +++ b/utils/fpdoc/fpdocxmlopts.pas @@ -156,12 +156,12 @@ procedure TXMLFPDocOptions.LoadEngineOptions(Options: TEngineOptions; end; Const - NCount = 10; + NCount = 11; ONames : Array[0..NCount] of string = ('hide-protected','warn-no-node','show-private', 'stop-on-parser-error', 'ostarget','cputarget', 'mo-dir','parse-impl','format', 'language', - 'package'); + 'package','dont-trim'); Var O : TDOMnode; @@ -187,6 +187,7 @@ begin 8 : Options.Backend:=V; 9 : Options.Language:=v; 10 : Options.DefaultPackageName:=V; + 11 : Options.DontTrim:=TrueValue(V); else Options.BackendOptions.add('--'+n); Options.BackendOptions.add(v);