Prechádzať zdrojové kódy

+ New structure for writers. Implemented TXT writer

michael 20 rokov pred
rodič
commit
0716489afd

+ 35 - 35
utils/fpdoc/Makefile

@@ -1,5 +1,5 @@
 #
 #
-# Don't edit, this file is generated by FPCMake Version 1.9.8 [2005/01/11]
+# Don't edit, this file is generated by FPCMake Version 1.9.8 [2005/01/12]
 #
 #
 default: all
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-sunos i386-qnx i386-netware i386-openbsd i386-wdosx i386-emx i386-watcom i386-netwlibc m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-sunos x86_64-linux x86_64-freebsd arm-linux
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-sunos i386-qnx i386-netware i386-openbsd i386-wdosx i386-emx i386-watcom i386-netwlibc m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-sunos x86_64-linux x86_64-freebsd arm-linux
@@ -332,103 +332,103 @@ ifeq ($(FULL_TARGET),arm-linux)
 override TARGET_PROGRAMS+=fpdoc makeskel unitdiff
 override TARGET_PROGRAMS+=fpdoc makeskel unitdiff
 endif
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 ifeq ($(FULL_TARGET),i386-linux)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-go32v2)
 ifeq ($(FULL_TARGET),i386-go32v2)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-win32)
 ifeq ($(FULL_TARGET),i386-win32)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-os2)
 ifeq ($(FULL_TARGET),i386-os2)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-freebsd)
 ifeq ($(FULL_TARGET),i386-freebsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-beos)
 ifeq ($(FULL_TARGET),i386-beos)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netbsd)
 ifeq ($(FULL_TARGET),i386-netbsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-sunos)
 ifeq ($(FULL_TARGET),i386-sunos)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-qnx)
 ifeq ($(FULL_TARGET),i386-qnx)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netware)
 ifeq ($(FULL_TARGET),i386-netware)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-openbsd)
 ifeq ($(FULL_TARGET),i386-openbsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-wdosx)
 ifeq ($(FULL_TARGET),i386-wdosx)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-emx)
 ifeq ($(FULL_TARGET),i386-emx)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-watcom)
 ifeq ($(FULL_TARGET),i386-watcom)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-netwlibc)
 ifeq ($(FULL_TARGET),i386-netwlibc)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-linux)
 ifeq ($(FULL_TARGET),m68k-linux)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-freebsd)
 ifeq ($(FULL_TARGET),m68k-freebsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-netbsd)
 ifeq ($(FULL_TARGET),m68k-netbsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-amiga)
 ifeq ($(FULL_TARGET),m68k-amiga)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-atari)
 ifeq ($(FULL_TARGET),m68k-atari)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-openbsd)
 ifeq ($(FULL_TARGET),m68k-openbsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),m68k-palmos)
 ifeq ($(FULL_TARGET),m68k-palmos)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-linux)
 ifeq ($(FULL_TARGET),powerpc-linux)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-netbsd)
 ifeq ($(FULL_TARGET),powerpc-netbsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-macos)
 ifeq ($(FULL_TARGET),powerpc-macos)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-darwin)
 ifeq ($(FULL_TARGET),powerpc-darwin)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),powerpc-morphos)
 ifeq ($(FULL_TARGET),powerpc-morphos)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-linux)
 ifeq ($(FULL_TARGET),sparc-linux)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-netbsd)
 ifeq ($(FULL_TARGET),sparc-netbsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),sparc-sunos)
 ifeq ($(FULL_TARGET),sparc-sunos)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-linux)
 ifeq ($(FULL_TARGET),x86_64-linux)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),x86_64-freebsd)
 ifeq ($(FULL_TARGET),x86_64-freebsd)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),arm-linux)
 ifeq ($(FULL_TARGET),arm-linux)
-override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+override CLEAN_UNITS+=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 endif
 endif
 ifeq ($(FULL_TARGET),i386-linux)
 ifeq ($(FULL_TARGET),i386-linux)
 override CLEAN_FILES+=dwriter.rst fpdoc.rst dglobals.rst makeskel.rst
 override CLEAN_FILES+=dwriter.rst fpdoc.rst dglobals.rst makeskel.rst
@@ -2555,5 +2555,5 @@ ifneq ($(wildcard fpcmake.loc),)
 include fpcmake.loc
 include fpcmake.loc
 endif
 endif
 fpdoc$(EXEEXT): fpdoc.pp dglobals.pp dwriter.pp dw_xml.pp sh_pas.pp dw_html.pp\
 fpdoc$(EXEEXT): fpdoc.pp dglobals.pp dwriter.pp dw_xml.pp sh_pas.pp dw_html.pp\
-  dw_latex.pp
+  dw_latex.pp dwlinear.pp dw_txt.pp
 makeskel$(EXEEXT): makeskel.pp dglobals.pp
 makeskel$(EXEEXT): makeskel.pp dglobals.pp

+ 3 - 3
utils/fpdoc/Makefile.fpc

@@ -11,7 +11,7 @@ packages=fcl
 
 
 [target]
 [target]
 programs=fpdoc makeskel unitdiff
 programs=fpdoc makeskel unitdiff
-rst=dwriter fpdoc dglobals makeskel
+rst=dwriter fpdoc dglobals makeskel dwlinear
 # removed to reduce dependencies of rpm.
 # removed to reduce dependencies of rpm.
 #dirs_linux_i386=fpde
 #dirs_linux_i386=fpde
 #dirs_win32=fpde
 #dirs_win32=fpde
@@ -26,11 +26,11 @@ fpcpackage=y
 fpcdir=../..
 fpcdir=../..
 
 
 [clean]
 [clean]
-units=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf
+units=dglobals dwriter dw_xml sh_pas dw_html dw_latex dw_ipf dw_txt
 files=dwriter.rst fpdoc.rst dglobals.rst makeskel.rst
 files=dwriter.rst fpdoc.rst dglobals.rst makeskel.rst
 
 
 [rules]
 [rules]
 fpdoc$(EXEEXT): fpdoc.pp dglobals.pp dwriter.pp dw_xml.pp sh_pas.pp dw_html.pp\
 fpdoc$(EXEEXT): fpdoc.pp dglobals.pp dwriter.pp dw_xml.pp sh_pas.pp dw_html.pp\
-  dw_latex.pp
+  dw_latex.pp dwlinear.pp dw_txt.pp
 
 
 makeskel$(EXEEXT): makeskel.pp dglobals.pp
 makeskel$(EXEEXT): makeskel.pp dglobals.pp

+ 21 - 1
utils/fpdoc/dglobals.pp

@@ -80,6 +80,23 @@ resourcestring
   SDocNext = 'Next';
   SDocNext = 'Next';
   SDocPrevious = 'Previous';
   SDocPrevious = 'Previous';
 
 
+  // Various backend constants
+  SDocChapter    = 'Chapter';
+  SDocSection    = 'Section';
+  SDocSubSection = 'Subsection';
+  SDocTable      = 'Table';
+  SDocListing    = 'Listing';
+
+  STitle = 'FPDoc - Free Pascal Documentation Tool';
+  SCopyright = '(c) 2000 - 2003 Areca Systems GmbH / Sebastian Guenther, [email protected]';
+  SCmdLineHelp = 'See documentation for usage.';
+  SCmdLineInvalidOption = 'Ignoring unknown option "%s"';
+  SCmdLineInvalidFormat = 'Invalid format "%s" specified';
+  SCmdLineOutputOptionMissing = 'Need an output filename, please specify one with --output=<filename>';
+  SWritingPages = 'Writing %d pages...';
+  SNeedPackageName = 'No package name specified. Please specify one using the --package option.';
+  SDone = 'Done.';
+
 Const
 Const
   SVisibility: array[TPasMemberVisibility] of string =
   SVisibility: array[TPasMemberVisibility] of string =
        ('Default', 'Private', 'Protected', 'Public',
        ('Default', 'Private', 'Protected', 'Public',
@@ -1152,7 +1169,10 @@ end.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.6  2005-01-09 15:59:50  michael
+  Revision 1.7  2005-01-12 21:11:41  michael
+  + New structure for writers. Implemented TXT writer
+
+  Revision 1.6  2005/01/09 15:59:50  michael
   + Split out latex writer to linear and latex writer
   + Split out latex writer to linear and latex writer
 
 
   Revision 1.5  2004/08/28 18:47:48  michael
   Revision 1.5  2004/08/28 18:47:48  michael

+ 60 - 9
utils/fpdoc/dw_html.pp

@@ -80,12 +80,17 @@ type
   end;
   end;
 
 
 
 
+  { THTMLWriter }
+
   THTMLWriter = class(TFPDocWriter)
   THTMLWriter = class(TFPDocWriter)
   private
   private
-    FAllocator: TFileAllocator;
+    FOnTest: TNotifyEvent;
     FPackage: TPasPackage;
     FPackage: TPasPackage;
     function GetPageCount: Integer;
     function GetPageCount: Integer;
+    procedure SetOnTest(const AValue: TNotifyEvent);
   protected
   protected
+    FAllocator: TFileAllocator;
+    Procedure CreateAllocator; virtual;
     CurDirectory: String;	// relative to curdir of process
     CurDirectory: String;	// relative to curdir of process
     BaseDirectory: String;	// relative path to package base directory
     BaseDirectory: String;	// relative path to package base directory
     PageInfos: TObjectList;	// list of TPageInfo objects
     PageInfos: TObjectList;	// list of TPageInfo objects
@@ -214,8 +219,7 @@ type
     procedure CreateProcPageBody(AProc: TPasProcedureBase);
     procedure CreateProcPageBody(AProc: TPasProcedureBase);
     Procedure CreateTopicLinks(Node : TDocNode; PasElement : TPasElement);
     Procedure CreateTopicLinks(Node : TDocNode; PasElement : TPasElement);
   public
   public
-    constructor Create(AEngine: TFPDocEngine; AAllocator: TFileAllocator;
-      APackage: TPasPackage);
+    constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
     destructor Destroy; override;
     destructor Destroy; override;
 
 
     // Single-page generation
     // Single-page generation
@@ -233,9 +237,15 @@ type
     property Package: TPasPackage read FPackage;
     property Package: TPasPackage read FPackage;
     property PageCount: Integer read GetPageCount;
     property PageCount: Integer read GetPageCount;
 
 
-    property OnTest: TNotifyEvent;
+    property OnTest: TNotifyEvent read FOnTest write SetOnTest;
+    Function InterPretOption(Const Cmd,Arg : String) : boolean; override;
+    Procedure WriteDoc; override;
   end;
   end;
 
 
+  THTMWriter = class(THTMLWriter)
+  Protected
+    Procedure CreateAllocator; override;
+  end;
 
 
 
 
 implementation
 implementation
@@ -334,8 +344,7 @@ end;
 
 
 
 
 
 
-constructor THTMLWriter.Create(AEngine: TFPDocEngine; AAllocator: TFileAllocator;
-  APackage: TPasPackage);
+constructor THTMLWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
 
 
   procedure AddPage(AElement: TPasElement; ASubpageIndex: Integer);
   procedure AddPage(AElement: TPasElement; ASubpageIndex: Integer);
   var
   var
@@ -491,8 +500,8 @@ constructor THTMLWriter.Create(AEngine: TFPDocEngine; AAllocator: TFileAllocator
 var
 var
   i: Integer;
   i: Integer;
 begin
 begin
-  inherited Create(AEngine);
-  FAllocator := AAllocator;
+  inherited ;
+  CreateAllocator;
   FPackage := APackage;
   FPackage := APackage;
   OutputNodeStack := TList.Create;
   OutputNodeStack := TList.Create;
 
 
@@ -2810,6 +2819,21 @@ begin
   FinishElementPage(AProc);
   FinishElementPage(AProc);
 end;
 end;
 
 
+Function THTMLWriter.InterPretOption(Const Cmd,Arg : String) : boolean;
+
+begin
+  Result:=True;
+  if Cmd = '--html-search' then
+    SearchPage := Arg
+  else
+    Result:=False;
+end;
+
+procedure THTMLWriter.WriteDoc;
+begin
+   WriteLn(Format(SWritingPages, [PageCount]));
+   WriteHTMLPages;
+end;
 
 
 // private methods
 // private methods
 
 
@@ -2818,12 +2842,39 @@ begin
   Result := PageInfos.Count;
   Result := PageInfos.Count;
 end;
 end;
 
 
+procedure THTMLWriter.SetOnTest(const AValue: TNotifyEvent);
+begin
+  if FOnTest=AValue then exit;
+    FOnTest:=AValue;
+end;
+
+procedure THTMLWriter.CreateAllocator;
+begin
+  FAllocator:=TLongNameFileAllocator.Create('.html');
+end;
+
+
+procedure THTMWriter.CreateAllocator;
+begin
+  FAllocator:=TShortNameFileAllocator.Create('.htm');
+end;
+
+initialization
+  // Do not localize.
+  RegisterWriter(THTMLWriter,'html','HTML output using fpdoc.css stylesheet.');
+  RegisterWriter(THTMWriter,'htm','HTM (8.3 filenames) output using fpdoc.css stylesheet.');
+finalization
+  UnRegisterWriter('html');
+  UnRegisterWriter('htm');
 end.
 end.
 
 
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.13  2005-01-09 15:59:50  michael
+  Revision 1.14  2005-01-12 21:11:41  michael
+  + New structure for writers. Implemented TXT writer
+
+  Revision 1.13  2005/01/09 15:59:50  michael
   + Split out latex writer to linear and latex writer
   + Split out latex writer to linear and latex writer
 
 
   Revision 1.12  2004/12/20 19:01:11  peter
   Revision 1.12  2004/12/20 19:01:11  peter

+ 23 - 28
utils/fpdoc/dw_ipf.pp

@@ -22,29 +22,23 @@ unit dw_IPF;
 
 
 interface
 interface
 
 
-uses DOM, dGlobals, PasTree;
+uses SysUtils, Classes, dWriter, DOM, dGlobals, PasTree;
 
 
 const
 const
   IPFHighLight : Boolean = False;
   IPFHighLight : Boolean = False;
-  TexExtension   : String = '.ipf';
-
-procedure CreateIPFDocForPackage(APackage: TPasPackage; AEngine: TFPDocEngine);
-
-
-implementation
-
-uses SysUtils, Classes, dWriter;
+  IPFExtension   : String = '.ipf';
 
 
 type
 type
   TLabelType = (ltConst,ltVar,ltType,ltFunction,ltProcedure,ltClass,
   TLabelType = (ltConst,ltVar,ltType,ltFunction,ltProcedure,ltClass,
                 ltChapter,ltSection,ltSubsection,
                 ltChapter,ltSection,ltSubsection,
                 ltTable,ltFigure);
                 ltTable,ltFigure);
 
 
+  { TIPFWriter }
+
   TIPFWriter = class(TFPDocWriter)
   TIPFWriter = class(TFPDocWriter)
   protected
   protected
     f: Text;
     f: Text;
     FLink: String;
     FLink: String;
-    Package: TPasPackage;
     PackageName: String;
     PackageName: String;
     Module: TPasModule;
     Module: TPasModule;
     ModuleName: String;
     ModuleName: String;
@@ -146,11 +140,16 @@ type
     procedure SortElementList(List : TList);
     procedure SortElementList(List : TList);
     Function  ShowMember(M : TPasElement) : boolean;
     Function  ShowMember(M : TPasElement) : boolean;
   public
   public
-    constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine);
-    procedure WriteDoc;
+    constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
+    procedure WriteDoc; override;
   end;
   end;
 
 
 
 
+implementation
+
+
+
+
 
 
 constructor TIPFWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
 constructor TIPFWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
 
 
@@ -235,8 +234,7 @@ constructor TIPFWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
 var
 var
   i: Integer;
   i: Integer;
 begin
 begin
-  inherited Create(AEngine);
-  Package := APackage;
+  inherited ;
 
 
   { Allocate labels for all elements for which we are going to create
   { Allocate labels for all elements for which we are going to create
     documentation. This is needed for links to work correctly. }
     documentation. This is needed for links to work correctly. }
@@ -256,7 +254,7 @@ var
 begin
 begin
   PackageName := LowerCase(Copy(Package.Name, 2, 255));
   PackageName := LowerCase(Copy(Package.Name, 2, 255));
   If (Engine.OutPut='') then
   If (Engine.OutPut='') then
-    Engine.Output:=PackageName+TexExtension;
+    Engine.Output:=PackageName+IPFExtension;
   Assign(f, Engine.Output);
   Assign(f, Engine.Output);
   Rewrite(f);
   Rewrite(f);
   try
   try
@@ -1366,25 +1364,22 @@ begin
   Writeln(':h1.'+{EscapeTex(}ChapterName{)});
   Writeln(':h1.'+{EscapeTex(}ChapterName{)});
 end;
 end;
 
 
-procedure CreateIPFDocForPackage(APackage: TPasPackage; AEngine: TFPDocEngine);
-var
-  Writer: TIPFWriter;
-begin
-  Writer := TIPFWriter.Create(APackage, AEngine);
-  try
-    Writer.WriteDoc;
-  finally
-    Writer.Free;
-  end;
-end;
 
 
 
 
+initialization
+  // Do not localize.
+  RegisterWriter(TIPFWriter,'ipf','IPF output.');
+finalization
+  UnRegisterWriter('ipf');
 end.
 end.
 
 
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.1  2003-10-08 11:41:54  yuri
+  Revision 1.2  2005-01-12 21:11:41  michael
+  + New structure for writers. Implemented TXT writer
+
+  Revision 1.1  2003/10/08 11:41:54  yuri
   + Initial OS/2 IPF support added
   + Initial OS/2 IPF support added
 
 
   Revision 1.4  2003/03/18 19:28:44  michael
   Revision 1.4  2003/03/18 19:28:44  michael
@@ -1426,4 +1421,4 @@ end.
 
 
   Revision 1.5  2001/12/17 13:41:18  jonas
   Revision 1.5  2001/12/17 13:41:18  jonas
     * OsPathSeparator -> PathDelim
     * OsPathSeparator -> PathDelim
-}
+}

+ 24 - 2
utils/fpdoc/dw_latex.pp

@@ -30,7 +30,7 @@ Procedure CreateLaTeXDocForPackage(APackage: TPasPackage; AEngine: TFPDocEngine)
 
 
 implementation
 implementation
 
 
-uses SysUtils, Classes, dwLinear;
+uses SysUtils, Classes, dwLinear, dwriter;
 
 
 
 
 Type
 Type
@@ -124,6 +124,8 @@ Type
     procedure DescrEndTableRow; override;
     procedure DescrEndTableRow; override;
     procedure DescrBeginTableCell; override;
     procedure DescrBeginTableCell; override;
     procedure DescrEndTableCell; override;
     procedure DescrEndTableCell; override;
+    // TFPDocWriter class methods
+    Function InterPretOption(Const Cmd,Arg : String) : boolean; override;
   end;
   end;
 
 
 
 
@@ -666,12 +668,32 @@ begin
   WriteLn('\end{FPCltable}');
   WriteLn('\end{FPCltable}');
 end;
 end;
 
 
+Function TLatexWriter.InterPretOption(Const Cmd,Arg : String) : boolean;
+
+begin
+  Result:=True;
+  if (cmd= '--latex-highlight') then
+    LatexHighLight:=True
+  else if Cmd = '--latex-extension' then
+     TexExtension:=Arg
+  else
+    Result:=False;
+end;
+
+initialization
+  // Do not localize.
+  RegisterWriter(TLaTeXWriter,'latex','Latex output using fpc.sty class.');
+finalization
+  UnRegisterWriter('latex');
 end.
 end.
 
 
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.8  2005-01-09 15:59:50  michael
+  Revision 1.9  2005-01-12 21:11:41  michael
+  + New structure for writers. Implemented TXT writer
+
+  Revision 1.8  2005/01/09 15:59:50  michael
   + Split out latex writer to linear and latex writer
   + Split out latex writer to linear and latex writer
 
 
   Revision 1.7  2004/11/15 18:01:16  michael
   Revision 1.7  2004/11/15 18:01:16  michael

+ 696 - 0
utils/fpdoc/dw_txt.pp

@@ -0,0 +1,696 @@
+{
+    $Id$
+
+    FPDoc  -  Free Pascal Documentation Tool
+    Copyright (C) 2005 by Michael Van Canneyt
+
+    * Text output generator
+
+    See the file COPYING, 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.
+}
+{$mode objfpc}
+{$H+}
+unit dw_txt;
+
+interface
+
+uses DOM, dGlobals, PasTree, dwriter;
+
+const
+  TxtHighLight : Boolean = False;
+  TxtExtension   : String = '.txt';
+
+Var
+  LEOL : Integer;
+  
+Procedure CreateTxtDocForPackage(APackage: TPasPackage; AEngine: TFPDocEngine);
+
+implementation
+
+uses SysUtils, Classes, dwLinear;
+
+Const
+  MaxListLevel     = 10;
+  DefaultLineWidth = 72;
+  
+Type
+ { TTxtWriter }
+
+  TTXTWriter = class(TLinearWriter)
+  protected
+    LineWidth : Integer;
+    FCheckEOL : Boolean;
+    FCurrentPos : Integer;
+    FListLevel,
+    FChapterCount,
+    FSectionCount,
+    FSubSectionCount,
+    FSubSubSectionCount,
+    FTableCount : Integer;
+    FInVerbatim : Boolean;
+    FLists : Array [0..MaxListLevel] of integer;
+    Inlist,
+    TableRowStartFlag,
+    TableCaptionWritten: Boolean;
+    procedure Write(const s: String); override;
+    procedure WriteLn(const s: String); override;
+    procedure NewLine;
+    // Private methods
+    procedure WriteLine(LineLength : Integer; DoubleLine : Boolean);
+    Procedure WriteLine(DoubleLine : Boolean);
+    procedure NewListLevel(Initial : Integer);
+    procedure declistlevel;
+    Procedure WriteUnderline(Const Msg : String; DoubleLine : Boolean);
+    // Linear documentation methods overrides;
+    procedure WriteLabel(Const S : String); override;
+    procedure WriteIndex(Const S : String); override;
+    Procedure WriteExampleFile(FN : String); override;
+    procedure StartUnitOverview(AModuleName,AModuleLabel : String);override;
+    procedure WriteUnitEntry(UnitRef : TPasType); override;
+    Procedure EndUnitOverview; override;
+    function  GetLabel(AElement: TPasElement): String; override;
+    procedure StartListing(Frames: Boolean; const name: String); override;
+    procedure EndListing; override;
+    procedure WriteCommentLine; override;
+    procedure WriteComment(Comment : String);override;
+    procedure StartSection(SectionName : String);override;
+    procedure StartSubSection(SubSectionName : String);override;
+    procedure StartSubSubSection(SubSubSectionName : String);override;
+    procedure StartChapter(ChapterName : String); override;
+    procedure StartOverview(WithAccess : Boolean); override;
+    procedure EndOverview; override;
+    procedure WriteOverviewMember(ALabel,AName,Access,ADescr : String); override;
+    procedure WriteOverviewMember(ALabel,AName,ADescr : String); override;
+    Class Function FileNameExtension : String; override;
+    // Description node conversion
+    procedure DescrBeginBold; override;
+    procedure DescrEndBold; override;
+    procedure DescrBeginItalic; override;
+    procedure DescrEndItalic; override;
+    procedure DescrBeginEmph; override;
+    procedure DescrEndEmph; override;
+    procedure DescrWriteFileEl(const AText: DOMString); override;
+    procedure DescrWriteKeywordEl(const AText: DOMString); override;
+    procedure DescrWriteVarEl(const AText: DOMString); override;
+    procedure DescrBeginLink(const AId: DOMString); override;
+    procedure DescrEndLink; override;
+    procedure DescrWriteLinebreak; override;
+    procedure DescrBeginParagraph; override;
+    procedure DescrBeginCode(HasBorder: Boolean; const AHighlighterName: String); override;
+    procedure DescrWriteCodeLine(const ALine: String); override;
+    procedure DescrEndCode; override;
+    procedure DescrEndParagraph; override;
+    procedure DescrBeginOrderedList; override;
+    procedure DescrEndOrderedList; override;
+    procedure DescrBeginUnorderedList; override;
+    procedure DescrEndUnorderedList; override;
+    procedure DescrBeginDefinitionList; override;
+    procedure DescrEndDefinitionList; override;
+    procedure DescrBeginListItem; override;
+    procedure DescrEndListItem; override;
+    procedure DescrBeginDefinitionTerm; override;
+    procedure DescrEndDefinitionTerm; override;
+    procedure DescrBeginDefinitionEntry; override;
+    procedure DescrEndDefinitionEntry; override;
+    procedure DescrBeginSectionTitle; override;
+    procedure DescrBeginSectionBody; override;
+    procedure DescrEndSection; override;
+    procedure DescrBeginRemark; override;
+    procedure DescrEndRemark; override;
+    procedure DescrBeginTable(ColCount: Integer; HasBorder: Boolean); override;
+    procedure DescrEndTable; override;
+    procedure DescrBeginTableCaption; override;
+    procedure DescrEndTableCaption; override;
+    procedure DescrBeginTableHeadRow; override;
+    procedure DescrEndTableHeadRow; override;
+    procedure DescrBeginTableRow; override;
+    procedure DescrEndTableRow; override;
+    procedure DescrBeginTableCell; override;
+    procedure DescrEndTableCell; override;
+  Public
+    Constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
+    Class Procedure Usage(List : TStrings) ; override;
+    Function InterpretOption(Const Cmd,Arg : String) : Boolean; override;
+  end;
+
+
+procedure TTxtWriter.WriteUnderline(Const Msg : String; DoubleLine : Boolean);
+
+Var
+  L : Integer;
+
+begin
+  L:=Length(Msg);
+  Writeln(Msg);
+  WriteLine(L,DoubleLine);
+end;
+
+procedure TTxtWriter.WriteLine(DoubleLine : Boolean);
+
+begin
+  Writeline(LineWidth,DoubleLine);
+end;
+
+Function FindSpace(Const S : String; P : Integer) : Integer;
+
+Var
+  I,L : Integer;
+
+begin
+  Result:=0;
+  I:=P;
+  L:=Length(S);
+  While (I>0) and (I<=L) and not (S[i] in [#10,#13,' ',#9]) do
+    Dec(i);
+  If (I=0) then
+    begin
+    I:=P;
+    While (I<=L) and not (S[i] in [#10,#13,' ',#9]) do
+      Inc(i);
+    end;
+  Result:=I;
+end;
+
+
+procedure TTXTWriter.Write(const s: String);
+
+Var
+  N : String;
+  L : Integer;
+  
+begin
+  If Length(S)=0 then
+    exit;
+  N:=S;
+  Repeat
+    If ((FCurrentPos+Length(N))>LineWidth) then
+      begin
+      L:=FindSpace(N,LineWidth-FCurrentPos+1);
+      inherited Write(Copy(N,1,L-1));
+      inherited Write(LineEnding);
+      FCurrentPos:=0;
+      end
+    else
+      begin
+      L:=Length(N)+1;
+      inherited Write(Copy(N,1,L-1));
+      Inc(FCurrentPos,L);
+      If FCheckEOL then
+        If (L>=LEOL) then
+          If (Copy(N,L-LEOL,LEOL)=LineEnding) then
+            FCurrentPos:=0;
+      end;
+    Delete(N,1,L);
+  Until (Length(N)=0);
+end;
+
+procedure TTXTWriter.WriteLn(const s: String);
+begin
+  FCheckEOL:=False;
+  Try
+    inherited WriteLn(s);
+    FCurrentPos:=0;
+  Finally
+    FCheckEOL:=False;
+  end;
+end;
+
+procedure TTxtWriter.NewLine;
+
+begin
+  If Not FCurrentPos=0 then
+    Writeln('');
+end;
+
+procedure TTxtWriter.WriteLine(LineLength : Integer; DoubleLine : Boolean);
+
+begin
+  NewLine;
+  If DoubleLine then
+    Writeln(StringOfChar('=',LineLength))
+  else
+    Writeln(StringOfChar('-',LineLength));
+end;
+
+
+function TTxtWriter.GetLabel(AElement: TPasElement): String;
+
+begin
+  if AElement.ClassType = TPasUnresolvedTypeRef then
+    Result := Engine.ResolveLink(Module, AElement.Name)
+  else
+  begin
+    Result := AElement.PathName;
+    Result := LowerCase(Copy(Result, 2, Length(Result) - 1));
+  end;
+end;
+
+procedure TTxtWriter.DescrBeginBold;
+begin
+end;
+
+procedure TTxtWriter.DescrEndBold;
+begin
+end;
+
+procedure TTxtWriter.DescrBeginItalic;
+begin
+end;
+
+procedure TTxtWriter.DescrEndItalic;
+begin
+end;
+
+procedure TTxtWriter.DescrBeginEmph;
+begin
+end;
+
+procedure TTxtWriter.DescrEndEmph;
+begin
+end;
+
+procedure TTxtWriter.DescrWriteFileEl(const AText: DOMString);
+begin
+  DescrWriteText(AText);
+end;
+
+procedure TTxtWriter.DescrWriteKeywordEl(const AText: DOMString);
+begin
+  DescrWriteText(AText);
+end;
+
+procedure TTxtWriter.DescrWriteVarEl(const AText: DOMString);
+begin
+  DescrWriteText(AText);
+end;
+
+procedure TTxtWriter.DescrBeginLink(const AId: DOMString);
+begin
+  Write('[');
+end;
+
+procedure TTxtWriter.DescrEndLink;
+begin
+  Write('] ');
+end;
+
+procedure TTxtWriter.DescrWriteLinebreak;
+begin
+  WriteLn('');
+end;
+
+procedure TTxtWriter.DescrBeginParagraph;
+begin
+  // Do nothing
+end;
+
+procedure TTxtWriter.DescrEndParagraph;
+begin
+  WriteLn('');
+end;
+
+procedure TTxtWriter.DescrBeginCode(HasBorder: Boolean;
+  const AHighlighterName: String);
+begin
+  StartListing(HasBorder,'');
+end;
+
+procedure TTxtWriter.DescrWriteCodeLine(const ALine: String);
+begin
+  WriteLn(ALine);
+end;
+
+procedure TTxtWriter.DescrEndCode;
+begin
+  EndListing
+end;
+
+procedure TTxtWriter.NewListLevel(Initial : Integer);
+
+begin
+  Inc(FListLevel);
+  If (FListLevel<MaxListLevel) then
+    FLists[FListLevel]:=0;
+end;
+
+procedure TTxtWriter.DecListLevel;
+
+begin
+  If (FListLevel>0) then
+    Dec(FListLevel)
+end;
+
+procedure TTxtWriter.DescrBeginOrderedList;
+begin
+  NewListLevel(0);
+end;
+
+procedure TTxtWriter.DescrEndOrderedList;
+begin
+  DecListLevel;
+end;
+
+procedure TTxtWriter.DescrBeginUnorderedList;
+begin
+  NewListLevel(-1);
+end;
+
+procedure TTxtWriter.DescrEndUnorderedList;
+begin
+  DecListLevel;
+end;
+
+procedure TTxtWriter.DescrBeginDefinitionList;
+begin
+  NewListLevel(-2);
+end;
+
+procedure TTxtWriter.DescrEndDefinitionList;
+begin
+  DecListLevel;
+end;
+
+procedure TTxtWriter.DescrBeginListItem;
+begin
+  If FLists[FListLevel]>=0 then
+    begin
+    Inc(FLists[FListLevel]);
+    WriteF('%d. ',[FLists[FListLevel]]);
+    end;
+  Write('   ');
+end;
+
+procedure TTxtWriter.DescrEndListItem;
+begin
+  WriteLn('');
+end;
+
+procedure TTxtWriter.DescrBeginDefinitionTerm;
+begin
+  Write('<<');
+end;
+
+procedure TTxtWriter.DescrEndDefinitionTerm;
+begin
+  WriteLn('>>:');
+end;
+
+procedure TTxtWriter.DescrBeginDefinitionEntry;
+begin
+  // Do nothing
+end;
+
+procedure TTxtWriter.DescrEndDefinitionEntry;
+begin
+  WriteLn('');
+end;
+
+procedure TTxtWriter.DescrBeginSectionTitle;
+begin
+  Inc(FSectionCount);
+  WritelnF('%s %d.%d: ',[SDocSection,FChapterCount,FSectionCount]);
+end;
+
+procedure TTxtWriter.DescrBeginSectionBody;
+begin
+  WriteLn('');
+end;
+
+procedure TTxtWriter.DescrEndSection;
+begin
+  // Do noting
+end;
+
+procedure TTxtWriter.DescrBeginRemark;
+begin
+  WriteLn(SDocRemark+': ');
+end;
+
+procedure TTxtWriter.DescrEndRemark;
+begin
+  WriteLn('');
+end;
+
+procedure TTxtWriter.DescrBeginTable(ColCount: Integer; HasBorder: Boolean);
+
+begin
+  WriteLine(False);
+end;
+
+procedure TTxtWriter.DescrEndTable;
+begin
+  WriteLine(False);
+end;
+
+procedure TTxtWriter.DescrBeginTableCaption;
+begin
+  // Do nothing.
+end;
+
+procedure TTxtWriter.DescrEndTableCaption;
+begin
+  Inc(FTableCount);
+  WriteF('%s %d :',[SDoctable,FTableCount]);
+  TableCaptionWritten := True;
+end;
+
+procedure TTxtWriter.DescrBeginTableHeadRow;
+begin
+  if not TableCaptionWritten then
+    DescrEndTableCaption;
+  TableRowStartFlag := True;
+end;
+
+procedure TTxtWriter.DescrEndTableHeadRow;
+begin
+  WriteLine(False);
+end;
+
+procedure TTxtWriter.DescrBeginTableRow;
+begin
+  if not TableCaptionWritten then
+    DescrEndTableCaption;
+  TableRowStartFlag := True;
+end;
+
+procedure TTxtWriter.DescrEndTableRow;
+begin
+  WriteLn('');
+end;
+
+procedure TTxtWriter.DescrBeginTableCell;
+begin
+  if TableRowStartFlag then
+    TableRowStartFlag := False
+  else
+    Write('    ');
+end;
+
+procedure TTxtWriter.DescrEndTableCell;
+begin
+  // Do nothing
+end;
+
+constructor TTXTWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
+begin
+  inherited Create(APackage, AEngine);
+  LineWidth:=DefaultLineWidth;
+end;
+
+procedure TTXTWriter.Usage(List: TStrings);
+begin
+  inherited Usage(List);
+end;
+
+function TTXTWriter.InterpretOption(const Cmd, Arg: String): Boolean;
+begin
+  if cmd='--linewidth' then
+    begin
+    LineWidth:=StrToIntDef(Arg,DefaultLineWidth);
+    Result:=True;
+    end
+  else
+    Result:=inherited InterpretOption(Cmd, Arg);
+end;
+
+procedure TTxtWriter.WriteLabel(const s: String);
+begin
+end;
+
+procedure TTxtWriter.WriteIndex(const s : String);
+begin
+end;
+
+procedure TTxtWriter.StartListing(Frames: Boolean; const name: String);
+begin
+  FInVerbatim:=True;
+  If (Name<>'') then
+    WritelnF('%s : %s',[SDocListing,Name]);
+  If Frames then
+    WriteLine(False)
+  else
+    WriteLn('');
+end;
+
+procedure TTxtWriter.EndListing;
+begin
+  FInVerbatim:=False;
+end;
+
+procedure TTxtWriter.WriteCommentLine;
+
+begin
+end;
+
+procedure TTxtWriter.WriteComment(Comment : String);
+begin
+end;
+
+procedure TTxtWriter.StartChapter(ChapterName : String);
+begin
+  Inc(FChapterCount);
+  FSectionCount:=0;
+  FSubSectionCount:=0;
+  Writeln('');
+  WriteLine(True);
+  WritelnF('%s %d : %s',[SDocChapter,FChapterCount,ChapterName]);
+  WriteLine(True);
+  Writeln('');
+end;
+
+procedure TTxtWriter.StartSection(SectionName : String);
+begin
+  Inc(FSectionCount);
+  FSubSectionCount:=0;
+  Writeln('');
+  WriteLine(False);
+  WritelnF('%s %d.%d : %s',[SDocSection,FChapterCount,FSectionCount,SectionName]);
+  WriteLine(False);
+  Writeln('');
+end;
+
+procedure TTxtWriter.StartSubSection(SubSectionName : String);
+begin
+  Inc(FSubSectionCount);
+  Writeln('');
+  WritelnF('%d.%d.%d : %s',[FChapterCount,FSectionCount,FSubSectionCount,SubSectionName]);
+  WriteLine(False);
+  Writeln('');
+end;
+
+procedure TTxtWriter.StartSubSubSection(SubSubSectionName : String);
+begin
+  Writeln('');
+  Writeln(SubSubSectionName);
+  Writeln('');
+end;
+
+procedure CreateTxtDocForPackage(APackage: TPasPackage; AEngine: TFPDocEngine);
+var
+  Writer: TTxtWriter;
+begin
+  Writer := TTxtWriter.Create(APackage, AEngine);
+  try
+    Writer.WriteDoc;
+  finally
+    Writer.Free;
+  end;
+end;
+
+procedure TTxtWriter.WriteExampleFile(FN : String);
+
+Var
+  L : TStringList;
+  I : Integer;
+
+begin
+  Write(SDocExample);
+  Writeln(' '+ExtractFileName(FN));
+  If (FN<>'') and FileExists(FN) then
+    begin
+    WriteLine(False);
+    L:=TStringList.Create;
+    Try
+      L.LoadFromFile(FN);
+      For I:=0 to L.Count-1 do
+        Writeln(L[i]);
+    finally   
+      L.Free;
+    end;
+    WriteLine(False);
+    end;  
+end;
+
+procedure TTxtWriter.StartOverview(WithAccess : Boolean);
+
+begin
+  If WithAccess then
+    WriteUnderLine(Format('%.30s %.10s %s',[EscapeText(SDocProperty), EscapeText(SDocAccess), EscapeText(SDocDescription)]),False)
+  else
+    WriteUnderLine(Format('%.30s %s',[EscapeText(SDocMethod), EscapeText(SDocDescription)]),False);
+end;
+
+procedure TTxtWriter.EndOverview;
+
+begin
+  WriteLine(False);
+end;
+
+procedure TTxtWriter.WriteOverviewMember(ALabel,AName,Access,ADescr : String);
+
+begin
+  WriteLnF('%.30s %.10s  %s',[AName,Access,ADescr]);
+end;
+
+procedure TTxtWriter.WriteOverviewMember(ALabel,AName,ADescr : String);
+
+begin
+  WriteLnF('%.30s %s ',[AName,ADescr]);
+end;
+
+function TTxtWriter.FileNameExtension: String;
+begin
+  Result:=TxtExtension;
+end;
+
+procedure TTxtWriter.StartUnitOverview(AModuleName,AModuleLabel : String);
+
+begin
+  WriteUnderLine('Unit Name',False);
+end;
+
+procedure TTxtWriter.WriteUnitEntry(UnitRef : TPasType);
+
+begin
+  Writeln(EscapeText(UnitRef.Name));
+end;
+
+procedure TTxtWriter.EndUnitOverview;
+
+begin
+  Writeln('');
+end;
+
+
+initialization
+  // Do not localize.
+  LEOL:=Length(LineEnding);
+  RegisterWriter(TTXTWriter,'txt','Plain text.');
+finalization
+  UnRegisterWriter('txt');
+end.
+
+
+{
+  $Log$
+  Revision 1.1  2005-01-12 21:11:41  michael
+  + New structure for writers. Implemented TXT writer
+
+  Revision 1.8  2005/01/09 15:59:50  michael
+  + Split out Txt writer to linear and Txt writer
+}

+ 30 - 5
utils/fpdoc/dw_xml.pp

@@ -22,14 +22,24 @@ unit dw_XML;
 
 
 interface
 interface
 
 
-uses DOM, PasTree;
+uses DOM, PasTree, dwriter;
+
+Type
+
+  { TXMLWriter }
+
+  TXMLWriter = Class(TFPDocWriter)
+    function ModuleToXMLStruct(AModule: TPasModule): TXMLDocument;
+    Procedure WriteDoc; override;
+  end;
+  
 
 
-function ModuleToXMLStruct(AModule: TPasModule): TXMLDocument;
 
 
 
 
 implementation
 implementation
 
 
-function ModuleToXMLStruct(AModule: TPasModule): TXMLDocument;
+function TXMLWriter.ModuleToXMLStruct(AModule: TPasModule): TXMLDocument;
+
 var
 var
   ModuleElement: TDOMElement;
   ModuleElement: TDOMElement;
 
 
@@ -81,6 +91,7 @@ var
     end;
     end;
   end;
   end;
 
 
+
 begin
 begin
   Result := TXMLDocument.Create;
   Result := TXMLDocument.Create;
   Result.AppendChild(Result.CreateComment(' Generated using FPDoc - (c) 2000-2003 Sebastian Guenther, [email protected] '));
   Result.AppendChild(Result.CreateComment(' Generated using FPDoc - (c) 2000-2003 Sebastian Guenther, [email protected] '));
@@ -88,16 +99,30 @@ begin
   ModuleElement := Result.CreateElement('unit');
   ModuleElement := Result.CreateElement('unit');
   ModuleElement['name'] := AModule.Name;
   ModuleElement['name'] := AModule.Name;
   Result.DocumentElement.AppendChild(ModuleElement);
   Result.DocumentElement.AppendChild(ModuleElement);
-
   ProcessSection(AModule.InterfaceSection, 'interface');
   ProcessSection(AModule.InterfaceSection, 'interface');
 end;
 end;
 
 
+{ TXMLWriter }
+
+procedure TXMLWriter.WriteDoc;
+begin
+
+end;
+
+initialization
+  // Do not localize.
+  RegisterWriter(TXMLWriter,'xml','fpdoc XML output.');
+finalization
+  UnRegisterWriter('xml');
 end.
 end.
 
 
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.2  2005-01-09 15:59:50  michael
+  Revision 1.3  2005-01-12 21:11:41  michael
+  + New structure for writers. Implemented TXT writer
+
+  Revision 1.2  2005/01/09 15:59:50  michael
   + Split out latex writer to linear and latex writer
   + Split out latex writer to linear and latex writer
 
 
   Revision 1.1  2003/03/17 23:03:20  michael
   Revision 1.1  2003/03/17 23:03:20  michael

+ 30 - 17
utils/fpdoc/dwlinear.pp

@@ -12,15 +12,15 @@ Type
 
 
   TLinearWriter = Class(TFPDocWriter)
   TLinearWriter = Class(TFPDocWriter)
     FStream : TStream;
     FStream : TStream;
-    Package: TPasPackage;
     PackageName: String;
     PackageName: String;
     Module: TPasModule;
     Module: TPasModule;
     ModuleName: String;
     ModuleName: String;
   Protected
   Protected
+
     // Writing support.
     // Writing support.
-    procedure Write(const s: String);
+    procedure Write(const s: String); virtual;
+    procedure WriteLn(const s: String); virtual;
     procedure WriteF(const s: String; const Args: array of const);
     procedure WriteF(const s: String; const Args: array of const);
-    procedure WriteLn(const s: String);
     procedure WriteLnF(const s: String; const Args: array of const);
     procedure WriteLnF(const s: String; const Args: array of const);
     Function  PushWriteContext(S : TStream) : TStream;
     Function  PushWriteContext(S : TStream) : TStream;
     Procedure PopWriteContext(S : TSTream);
     Procedure PopWriteContext(S : TSTream);
@@ -76,8 +76,8 @@ Type
     procedure EndUnitOverview; virtual; Abstract;
     procedure EndUnitOverview; virtual; Abstract;
     Class Function FileNameExtension : String;virtual; Abstract;
     Class Function FileNameExtension : String;virtual; Abstract;
   Public
   Public
-    Constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine);
-    procedure WriteDoc;
+    Constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); override;
+    procedure WriteDoc; override;
     // Linear Documentation writing methods.
     // Linear Documentation writing methods.
     Procedure ProcessPackage;
     Procedure ProcessPackage;
     Procedure ProcessTopics(DocNode : TDocNode; Alevel : Integer);
     Procedure ProcessTopics(DocNode : TDocNode; Alevel : Integer);
@@ -267,56 +267,64 @@ end;
 Procedure TLinearWriter.StartProcedure;
 Procedure TLinearWriter.StartProcedure;
 
 
 begin
 begin
-  Writeln(SDocProcedure);
+  Writeln(SDocProcedure+':');
 end;
 end;
 
 
 Procedure TLinearWriter.StartSynopsis;
 Procedure TLinearWriter.StartSynopsis;
 
 
 begin
 begin
-  Writeln(SDocSynopsis);
+  Writeln('');
+  Writeln(SDocSynopsis+':');
 end;
 end;
 
 
 Procedure TLinearWriter.StartDeclaration;
 Procedure TLinearWriter.StartDeclaration;
 
 
 begin
 begin
-  Writeln(SDocDeclaration);
+  Writeln('');
+  Writeln(SDocDeclaration+':');
 end;
 end;
 
 
 Procedure TLinearWriter.StartVisibility;
 Procedure TLinearWriter.StartVisibility;
 
 
 begin
 begin
-  Writeln(SDocVisibility);
+  Writeln('');
+  Writeln(SDocVisibility+':');
 end;
 end;
 
 
 Procedure TLinearWriter.StartDescription;
 Procedure TLinearWriter.StartDescription;
 
 
 begin
 begin
-  Writeln(SDocDescription);
+  Writeln('');
+  Writeln(SDocDescription+':');
 end;
 end;
 
 
 Procedure TLinearWriter.StartAccess;
 Procedure TLinearWriter.StartAccess;
 
 
 begin
 begin
-  Writeln(SDocAccess);
+  Writeln('');
+  Writeln(SDocAccess+':');
 end;
 end;
 
 
 Procedure TLinearWriter.StartErrors;
 Procedure TLinearWriter.StartErrors;
 
 
 begin
 begin
-  Writeln(SDocErrors);
+  Writeln('');
+  Writeln(SDocErrors+':');
 end;
 end;
 
 
 Procedure TLinearWriter.StartSeealso;
 Procedure TLinearWriter.StartSeealso;
 
 
 begin
 begin
-  Writeln(SDocSeeAlso);
+  Writeln('');
+  Writeln(SDocSeeAlso+':');
 end;
 end;
 
 
 
 
 Procedure TLinearWriter.StartProperty;
 Procedure TLinearWriter.StartProperty;
 
 
 begin
 begin
-  Writeln(SDocProperty);
+  Writeln('');
+  Writeln(SDocProperty+':');
 end;
 end;
 
 
 Procedure TLinearWriter.EndProcedure;
 Procedure TLinearWriter.EndProcedure;
@@ -655,6 +663,7 @@ begin
     StartSubSection(SDocConstants,EscapeText(ModuleName));
     StartSubSection(SDocConstants,EscapeText(ModuleName));
     for i := 0 to ASection.Consts.Count - 1 do
     for i := 0 to ASection.Consts.Count - 1 do
       begin
       begin
+      DescrBeginParaGraph;
       ConstDecl := TPasConst(ASection.Consts[i]);
       ConstDecl := TPasConst(ASection.Consts[i]);
       StartListing(False,'');
       StartListing(False,'');
       WriteLn(EscapeText(ConstDecl.GetDeclaration(True)));
       WriteLn(EscapeText(ConstDecl.GetDeclaration(True)));
@@ -662,6 +671,7 @@ begin
       WriteLabel(ConstDecl);
       WriteLabel(ConstDecl);
       WriteIndex(ConstDecl);
       WriteIndex(ConstDecl);
       WriteDescr(ConstDecl);
       WriteDescr(ConstDecl);
+      DescrEndParaGraph;
       end;
       end;
     end;
     end;
 end;
 end;
@@ -717,6 +727,7 @@ begin
     StartSubSection(SDocTypes,ModuleName+'Types');
     StartSubSection(SDocTypes,ModuleName+'Types');
     for i := 0 to ASection.Types.Count - 1 do
     for i := 0 to ASection.Types.Count - 1 do
     begin
     begin
+      DescrBeginParaGraph;
       TypeDecl := TPasType(ASection.Types[i]);
       TypeDecl := TPasType(ASection.Types[i]);
       StartListing(False,'');
       StartListing(False,'');
       Writeln(EscapeText(TypeDecl.GetDeclaration(True)));
       Writeln(EscapeText(TypeDecl.GetDeclaration(True)));
@@ -728,6 +739,7 @@ begin
         WriteENumElements(TypeDecl as TPasEnumType);
         WriteENumElements(TypeDecl as TPasEnumType);
         end;
         end;
       WriteDescr(TypeDecl);
       WriteDescr(TypeDecl);
+      DescrEndParaGraph;
     end;
     end;
   end;
   end;
 end;
 end;
@@ -742,6 +754,7 @@ begin
     StartSubsection(SDocVariables,ModuleName+'Variables');
     StartSubsection(SDocVariables,ModuleName+'Variables');
     for i := 0 to ASection.Variables.Count - 1 do
     for i := 0 to ASection.Variables.Count - 1 do
     begin
     begin
+      DescrBeginParaGraph;
       VarDecl := TPasVariable(ASection.Variables[i]);
       VarDecl := TPasVariable(ASection.Variables[i]);
       StartListing(False,'');
       StartListing(False,'');
       WriteLn(EscapeText(VarDecl.GetDeclaration(True)));
       WriteLn(EscapeText(VarDecl.GetDeclaration(True)));
@@ -749,6 +762,7 @@ begin
       WriteLabel(VarDecl);
       WriteLabel(VarDecl);
       WriteIndex(VarDecl);
       WriteIndex(VarDecl);
       WriteDescr(VarDecl);
       WriteDescr(VarDecl);
+      DescrEndParaGraph;
     end;
     end;
   end;
   end;
 end;
 end;
@@ -933,7 +947,7 @@ begin
         Writeln(',');
         Writeln(',');
       S:=TDomElement(Node)['id'];
       S:=TDomElement(Node)['id'];
       DescrBeginLink(S);
       DescrBeginLink(S);
-      Writeln(EscapeText(S));
+      Write(EscapeText(S));
       DescrEndLink();
       DescrEndLink();
       end;
       end;
     Node:=Node.NextSibling;
     Node:=Node.NextSibling;
@@ -1138,8 +1152,7 @@ constructor TLinearWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
 var
 var
   i: Integer;
   i: Integer;
 begin
 begin
-  inherited Create(AEngine);
-  Package := APackage;
+  inherited ;
 
 
   { Allocate labels for all elements for which we are going to create
   { Allocate labels for all elements for which we are going to create
     documentation. This is needed for links to work correctly. }
     documentation. This is needed for links to work correctly. }

+ 170 - 14
utils/fpdoc/dwriter.pp

@@ -24,7 +24,7 @@ unit dWriter;
 
 
 interface
 interface
 
 
-uses Classes, DOM, dGlobals, PasTree;
+uses Classes, DOM, dGlobals, PasTree, SysUtils;
 
 
 resourcestring
 resourcestring
   SErrFileWriting = 'An error occured during writing of file "%s": %s';
   SErrFileWriting = 'An error occured during writing of file "%s": %s';
@@ -49,8 +49,9 @@ resourcestring
   SErrUnknownLinkID = 'Warning: Target ID of <link> is unknown: "%s"';
   SErrUnknownLinkID = 'Warning: Target ID of <link> is unknown: "%s"';
   SErrUnknownPrintShortID = 'Warning: Target ID of <printshort> is unknown: "%s"';
   SErrUnknownPrintShortID = 'Warning: Target ID of <printshort> is unknown: "%s"';
   SErrUnknownLink = 'Could not resolve link to "%s"';
   SErrUnknownLink = 'Could not resolve link to "%s"';
-
-
+  SErralreadyRegistered = 'Class for output format "%s" already registered';
+  SErrUnknownWriterClass = 'Unknown output format "%s"';
+  
 type
 type
   // Phony element for pas pages.
   // Phony element for pas pages.
 
 
@@ -63,10 +64,14 @@ type
     Subtopics : TList;
     Subtopics : TList;
   end;
   end;
 
 
+  { TFPDocWriter }
+
   TFPDocWriter = class
   TFPDocWriter = class
   private
   private
-    FEngine : TFPDocEngine;
-    FTopics : TList;
+    FEngine  : TFPDocEngine;
+    FPackage : TPasPackage;
+
+    FTopics  : TList;
   protected
   protected
 
 
     procedure Warning(AContext: TPasElement; const AMsg: String);
     procedure Warning(AContext: TPasElement; const AMsg: String);
@@ -139,22 +144,156 @@ type
     procedure DescrBeginTableCell; virtual; abstract;
     procedure DescrBeginTableCell; virtual; abstract;
     procedure DescrEndTableCell; virtual; abstract;
     procedure DescrEndTableCell; virtual; abstract;
   public
   public
-    constructor Create(AEngine: TFPDocEngine);
+    Constructor Create(APackage: TPasPackage; AEngine: TFPDocEngine); virtual;
     destructor Destroy;  override;
     destructor Destroy;  override;
     property Engine : TFPDocEngine read FEngine;
     property Engine : TFPDocEngine read FEngine;
+    Property Package : TPasPackage read FPackage;
     Property Topics : TList Read FTopics;
     Property Topics : TList Read FTopics;
+    // Should return True if option was succesfully interpreted.
+    Function InterpretOption(Const Cmd,Arg : String) : Boolean; Virtual;
+    Class Procedure Usage(List : TStrings); virtual;
+    procedure WriteDoc; virtual; Abstract;
   end;
   end;
 
 
+  TFPDocWriterClass = Class of TFPDocWriter;
+  EFPDocWriterError = Class(Exception);
+  
+// Register backend
+Procedure RegisterWriter(AClass : TFPDocWriterClass; Const AName,ADescr : String);
+// UnRegister backend
+Procedure UnRegisterWriter(Const AName : String);
+// Return back end class. Exception if not found.
+Function  GetWriterClass(AName : String) : TFPDocWriterClass;
+// Return index of back end class.
+Function  FindWriterClass(AName : String) : Integer;
+// List of backend in name=descr form.
+Procedure EnumWriters(List : TStrings);
 
 
 implementation
 implementation
 
 
-uses SysUtils;
+
+{ ---------------------------------------------------------------------
+  Writer registration
+  ---------------------------------------------------------------------}
+  
+Type
+
+{ TWriterRecord }
+
+  TWriterRecord = Class(TObject)
+  Private
+    FClass : TFPDocWriterClass;
+    FName : String;
+    FDescription : String;
+  Public
+    Constructor Create (AClass : TFPDocWriterClass; Const AName,ADescr : String);
+  end;
+
+{ TWriterRecord }
+
+constructor TWriterRecord.Create(AClass: TFPDocWriterClass; const AName,
+  ADescr: String);
+begin
+  FClass:=AClass;
+  FName:=AName;
+  FDescription:=ADescr;
+end;
+
+Var
+  Writers : TStringList;
+
+Procedure InitWriterList;
+
+begin
+  Writers:=TStringList.Create;
+  Writers.Sorted:=True;
+end;
+
+Procedure DoneWriterList;
+
+Var
+  I : Integer;
+
+begin
+  For I:=Writers.Count-1 downto 0 do
+    Writers.Objects[i].Free;
+  FreeAndNil(Writers);
+end;
+
+procedure RegisterWriter(AClass : TFPDocWriterClass; Const AName, ADescr : String);
+begin
+  If Writers.IndexOf(AName)<>-1 then
+    Raise EFPDocWriterError.CreateFmt(SErralreadyRegistered,[ANAme]);
+  Writers.AddObject(AName,TWriterRecord.Create(AClass,AName,ADescr));
+end;
+
+function  FindWriterClass(AName : String) : Integer;
+
+begin
+  Result:=Writers.IndexOf(AName);
+end;
+
+function GetWriterClass(AName : String) : TFPDocWriterClass;
+
+Var
+  Index : Integer;
+
+begin
+  Index:=FindWriterClass(AName);
+  If Index=-1 then
+    Raise EFPDocWriterError.CreateFmt(SErrUnknownWriterClass,[ANAme]);
+  Result:=(Writers.Objects[Index] as TWriterRecord).FClass;
+end;
+
+// UnRegister backend
+
+Procedure UnRegisterWriter(Const AName : String);
+Var
+  Index : Integer;
+
+begin
+  Index:=Writers.IndexOf(AName);
+  If Index=-1 then
+    Raise EFPDocWriterError.CreateFmt(SErrUnknownWriterClass,[ANAme]);
+  Writers.Objects[Index].Free;
+  Writers.Delete(Index);
+end;
 
 
 
 
-constructor TFPDocWriter.Create(AEngine: TFPDocEngine);
+Procedure EnumWriters(List : TStrings);
+
+Var
+  I : Integer;
+
+begin
+  List.Clear;
+  For I:=0 to Writers.Count-1 do
+    With (Writers.Objects[I] as TWriterRecord) do
+      List.Add(FName+'='+FDescription);
+end;
+
+
+
+{ ---------------------------------------------------------------------
+  TFPDocWriter
+  ---------------------------------------------------------------------}
+{
+      fmtIPF:
+        begin
+          if Length(Engine.Output) = 0 then
+            WriteLn(SCmdLineOutputOptionMissing)
+          else
+            CreateIPFDocForPackage(Engine.Package, Engine);
+        end;
+
+
+}
+Constructor TFPDocWriter.Create(APackage: TPasPackage; AEngine: TFPDocEngine);
+
 begin
 begin
   inherited Create;
   inherited Create;
-  FEngine := AEngine;
+  FEngine  := AEngine;
+  FPackage := APackage;
   FTopics:=Tlist.Create;
   FTopics:=Tlist.Create;
 end;
 end;
 
 
@@ -170,6 +309,16 @@ begin
   Inherited;
   Inherited;
 end;
 end;
 
 
+function TFPDocWriter.InterpretOption(Const Cmd,Arg : String): Boolean;
+begin
+  Result:=False;
+end;
+
+Class procedure TFPDocWriter.Usage(List: TStrings);
+begin
+  // Do nothing.
+end;
+
 Function TFPDocWriter.FindTopicElement(Node : TDocNode): TTopicElement;
 Function TFPDocWriter.FindTopicElement(Node : TDocNode): TTopicElement;
 
 
 Var
 Var
@@ -186,10 +335,9 @@ begin
     end;
     end;
 end;
 end;
 
 
-
-// ===================================================================
-//   Generic documentation node conversion
-// ===================================================================
+{ ---------------------------------------------------------------------
+  Generic documentation node conversion
+  ---------------------------------------------------------------------}
 
 
 function IsContentNodeType(Node: TDOMNode): Boolean;
 function IsContentNodeType(Node: TDOMNode): Boolean;
 begin
 begin
@@ -813,12 +961,20 @@ begin
   Inherited;
   Inherited;
 end;
 end;
 
 
+
+initialization
+  InitWriterList;
+finalization
+  DoneWriterList;
 end.
 end.
 
 
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.3  2004-08-28 18:05:17  michael
+  Revision 1.4  2005-01-12 21:11:41  michael
+  + New structure for writers. Implemented TXT writer
+
+  Revision 1.3  2004/08/28 18:05:17  michael
   + Check for non-nil context
   + Check for non-nil context
 
 
   Revision 1.2  2004/06/06 10:53:02  michael
   Revision 1.2  2004/06/06 10:53:02  michael

+ 95 - 169
utils/fpdoc/fpdoc.pp

@@ -17,46 +17,46 @@
 program FPDoc;
 program FPDoc;
 
 
 uses
 uses
-  SysUtils, Classes, Gettext, DOM, XMLWrite,
-  dGlobals, PasTree, PParser, dw_LaTeX,dw_XML, dw_HTML,  dw_ipf, dwlinear;
-
-resourcestring
-  STitle = 'FPDoc - Free Pascal Documentation Tool';
-  SCopyright = '(c) 2000 - 2003 Areca Systems GmbH / Sebastian Guenther, [email protected]';
-  SCmdLineHelp = 'See documentation for usage.';
-  SCmdLineInvalidOption = 'Ignoring unknown option "%s"';
-  SCmdLineInvalidFormat = 'Invalid format "%s" specified';
-  SCmdLineOutputOptionMissing = 'Need an output filename, please specify one with --output=<filename>';
-  SWritingPages = 'Writing %d pages...';
-  SNeedPackageName = 'No package name specified. Please specify one using the --package option.';
-  SDone = 'Done.';
-
-type
-  TCmdLineAction = (actionHelp, actionConvert);
-  TOutputFormat = (fmtHTM, fmtHTML, fmtXHTML, fmtLaTeX, fmtXMLStruct, fmtIPF);
+  SysUtils, Classes, Gettext, DOM, XMLWrite, PasTree, PParser,
+  dGlobals, // GLobal definitions, constants.
+  dwriter,  // TFPDocWriter definition.
+  dwlinear, // Linear (abstract) writer
+  dw_LaTeX, // TLaTex writer
+  dw_XML,   // XML writer
+  dw_HTML,  // HTML writer
+  dw_ipf,   // IPF writer
+  dw_txt;   // TXT writer
 
 
 const
 const
-  CmdLineAction: TCmdLineAction = actionConvert;
-  OutputFormat: TOutputFormat = fmtHTML;
   OSTarget: String = {$I %FPCTARGETOS%};
   OSTarget: String = {$I %FPCTARGETOS%};
   CPUTarget: String = {$I %FPCTARGETCPU%};
   CPUTarget: String = {$I %FPCTARGETCPU%};
 
 
 var
 var
+  Backend : String;
+  BackendOptions : TStrings;
   InputFiles, DescrFiles: TStringList;
   InputFiles, DescrFiles: TStringList;
-  PackageName, DocLang, ContentFile, SearchPage: String;
+  PackageName, DocLang, ContentFile : String;
   Engine: TFPDocEngine;
   Engine: TFPDocEngine;
 
 
+Procedure Usage(AnExitCode : Byte);
+
+begin
+  Writeln(SCmdLineHelp);
+  Halt(AnExitCode);
+end;
 
 
 procedure InitOptions;
 procedure InitOptions;
 begin
 begin
   InputFiles := TStringList.Create;
   InputFiles := TStringList.Create;
   DescrFiles := TStringList.Create;
   DescrFiles := TStringList.Create;
+  BackendOptions := TStringList.Create;
   Engine := TFPDocEngine.Create;
   Engine := TFPDocEngine.Create;
 end;
 end;
 
 
 procedure FreeOptions;
 procedure FreeOptions;
 begin
 begin
   Engine.Free;
   Engine.Free;
+  BackendOptions.Free;
   DescrFiles.Free;
   DescrFiles.Free;
   InputFiles.Free;
   InputFiles.Free;
 end;
 end;
@@ -94,9 +94,10 @@ procedure ParseOption(const s: String);
 var
 var
   i: Integer;
   i: Integer;
   Cmd, Arg: String;
   Cmd, Arg: String;
+  
 begin
 begin
   if (s = '-h') or (s = '--help') then
   if (s = '-h') or (s = '--help') then
-    CmdLineAction := actionHelp
+    Usage(0)
   else if s = '--hide-protected' then
   else if s = '--hide-protected' then
     Engine.HideProtected := True
     Engine.HideProtected := True
   else if s = '--warn-no-node' then
   else if s = '--warn-no-node' then
@@ -104,40 +105,30 @@ begin
   else if s = '--show-private' then
   else if s = '--show-private' then
     Engine.HidePrivate := False
     Engine.HidePrivate := False
   else
   else
-  begin
+    begin
     i := Pos('=', s);
     i := Pos('=', s);
     if i > 0 then
     if i > 0 then
-    begin
+      begin
       Cmd := Copy(s, 1, i - 1);
       Cmd := Copy(s, 1, i - 1);
       Arg := Copy(s, i + 1, Length(s));
       Arg := Copy(s, i + 1, Length(s));
-    end else
-    begin
+      end
+    else
+      begin
       Cmd := s;
       Cmd := s;
       SetLength(Arg, 0);
       SetLength(Arg, 0);
-    end;
+      end;
     if Cmd = '--descr' then
     if Cmd = '--descr' then
       AddToFileList(DescrFiles, Arg)
       AddToFileList(DescrFiles, Arg)
     else if (Cmd = '-f') or (Cmd = '--format') then
     else if (Cmd = '-f') or (Cmd = '--format') then
-    begin
-      Arg := UpperCase(Arg);
-      if Arg = 'HTM' then
-        OutputFormat := fmtHTM
-      else if Arg = 'HTML' then
-        OutputFormat := fmtHTML
-      else if Arg = 'XHTML' then
-        OutputFormat := fmtXHTML
-      else if Arg = 'LATEX' then
-        OutputFormat := fmtLaTeX
-      else if Arg = 'IPF' then
-        OutputFormat := fmtIPF
-      else if Arg = 'XML-STRUCT' then
-        OutputFormat := fmtXMLStruct
+      begin
+      Arg:=UpperCase(Arg);
+      If FindWriterClass(Arg)=-1 then
+        WriteLn(StdErr, Format(SCmdLineInvalidFormat, [Arg]))
       else
       else
-        WriteLn(StdErr, Format(SCmdLineInvalidFormat, [Arg]));
-    end else if (Cmd = '-l') or (Cmd = '--lang') then
+        BackEnd:=Arg;
+      end
+    else if (Cmd = '-l') or (Cmd = '--lang') then
       DocLang := Arg
       DocLang := Arg
-    else if (Cmd = '--latex-highlight') then
-      LatexHighLight:=True
     else if (Cmd = '-i') or (Cmd = '--input') then
     else if (Cmd = '-i') or (Cmd = '--input') then
       AddToFileList(InputFiles, Arg)
       AddToFileList(InputFiles, Arg)
     else if (Cmd = '-o') or (Cmd = '--output') then
     else if (Cmd = '-o') or (Cmd = '--output') then
@@ -148,165 +139,100 @@ begin
       ReadContentFile(Arg)
       ReadContentFile(Arg)
     else if Cmd = '--package' then
     else if Cmd = '--package' then
       PackageName := Arg
       PackageName := Arg
-    else if Cmd = '--html-search' then
-      SearchPage := Arg
     else if Cmd = '--ostarget' then
     else if Cmd = '--ostarget' then
       OSTarget := Arg
       OSTarget := Arg
     else if Cmd = '--cputarget' then
     else if Cmd = '--cputarget' then
       CPUTarget := Arg
       CPUTarget := Arg
-    else if Cmd = '--latex-extension' then
-      TexExtension:=Arg
     else
     else
-      WriteLn(StdErr, Format(SCmdLineInvalidOption, [s]));
-  end;
+      begin
+      BackendOptions.Add(Cmd);
+      BackendOptions.Add(Arg);
+      end;
+    end;
 end;
 end;
 
 
 procedure ParseCommandLine;
 procedure ParseCommandLine;
+
 var
 var
   i: Integer;
   i: Integer;
+  
 begin
 begin
   for i := 1 to ParamCount do
   for i := 1 to ParamCount do
     ParseOption(ParamStr(i));
     ParseOption(ParamStr(i));
+  If (BackEnd='') then
+    BackEnd:='html';
+  if (PackageName='') then
+    begin
+    Writeln(SNeedPackageName);
+    Usage(1);
+    end;
 end;
 end;
 
 
+procedure CreateDocumentation;
 
 
 var
 var
   i: Integer;
   i: Integer;
-  Allocator: TFileAllocator;
-  HTMLWriter: THTMLWriter;
+  WriterClass : TFPDocWriterClass;
+  Writer : TFPDocWriter;
+  
+begin
+  for i := 0 to DescrFiles.Count - 1 do
+    Engine.AddDocFile(DescrFiles[i]);
+  Engine.SetPackageName(PackageName);
+  if Length(DocLang) > 0 then
+    TranslateDocStrings(DocLang);
+  for i := 0 to InputFiles.Count - 1 do
+    try
+      ParseSource(Engine, InputFiles[i], OSTarget, CPUTarget);
+    except
+      on e: EParserError do
+        WriteLn(StdErr, Format('%s(%d,%d): %s',
+          [e.Filename, e.Row, e.Column, e.Message]));
+    end;
+  WriterClass:=GetWriterClass(Backend);
+  Writer:=WriterClass.Create(Engine.Package,Engine);
+  With Writer do
+    Try
+      If BackendOptions.Count>0 then
+        for I:=0 to ((BackendOptions.Count-1) div 2) do
+          If not InterPretOption(BackendOptions[I*2],BackendOptions[I*2+1]) then
+            WriteLn(StdErr, Format(SCmdLineInvalidOption,[BackendOptions[I*2]+' '+BackendOptions[I*2+1]]));
+      WriteDoc;
+    Finally
+      Free;
+    end;
+  if Length(ContentFile) > 0 then
+    Engine.WriteContentFile(ContentFile);
+end;
+
+
+
 begin
 begin
 {$IFDEF Unix}
 {$IFDEF Unix}
   gettext.TranslateResourceStrings('/usr/local/share/locale/%s/LC_MESSAGES/fpdoc.mo');
   gettext.TranslateResourceStrings('/usr/local/share/locale/%s/LC_MESSAGES/fpdoc.mo');
 {$ELSE}
 {$ELSE}
   gettext.TranslateResourceStrings('intl/fpdoc.%s.mo');
   gettext.TranslateResourceStrings('intl/fpdoc.%s.mo');
 {$ENDIF}
 {$ENDIF}
-
   WriteLn(STitle);
   WriteLn(STitle);
   WriteLn(SCopyright);
   WriteLn(SCopyright);
   WriteLn;
   WriteLn;
-
   InitOptions;
   InitOptions;
-  ParseCommandLine;
-
-  if CmdLineAction = actionHelp then
-    WriteLn(SCmdLineHelp)
-  else
-  begin
-    if (PackageName='') then
-      begin
-      Writeln(SNeedPackageName);
-      Halt(1);
-      end;
-    // Action is to create documentation
-
-    // Read all description files
-    for i := 0 to DescrFiles.Count - 1 do
-      Engine.AddDocFile(DescrFiles[i]);
-
-    // Set the name of the package to be processed
-    Engine.SetPackageName(PackageName);
-
-    // Read all source files
-    for i := 0 to InputFiles.Count - 1 do
-      try
-        ParseSource(Engine, InputFiles[i], OSTarget, CPUTarget);
-      except
-        on e: EParserError do
-          WriteLn(StdErr, Format('%s(%d,%d): %s',
-            [e.Filename, e.Row, e.Column, e.Message]));
-      end;
-
-    // Translate internal documentation strings
-    if Length(DocLang) > 0 then
-      TranslateDocStrings(DocLang);
-
-    case OutputFormat of
-      fmtHTM:
-        begin
-          Allocator := TShortNameFileAllocator.Create('.htm');
-          try
-            HTMLWriter := THTMLWriter.Create(Engine, Allocator, Engine.Package);
-            try
-              HTMLWriter.SearchPage := SearchPage;
-              WriteLn(Format(SWritingPages, [HTMLWriter.PageCount]));
-              HTMLWriter.WriteHTMLPages;
-            finally
-              HTMLWriter.Free;
-            end;
-          finally
-            Allocator.Free;
-          end;
-        end;
-      fmtHTML:
-        begin
-          Allocator := TLongNameFileAllocator.Create('.html');
-          try
-            HTMLWriter := THTMLWriter.Create(Engine, Allocator, Engine.Package);
-            try
-              HTMLWriter.SearchPage := SearchPage;
-              WriteLn(Format(SWritingPages, [HTMLWriter.PageCount]));
-              HTMLWriter.WriteHTMLPages;
-            finally
-              HTMLWriter.Free;
-            end;
-          finally
-            Allocator.Free;
-          end;
-        end;
-{      fmtXHTML:
-        begin
-          Allocator := TLongNameFileAllocator.Create('.xml');
-          try
-            BeginXHTMLDocForPackage(Engine, XHTMLOptions, Allocator);
-            for i := 0 to InputFiles.Count - 1 do
-              CreateXHTMLDocFromModule(Engine, XHTMLOptions, Allocator,
-                ParseSource(Engine, InputFiles[i]));
-            EndXHTMLDocForPackage(Engine, XHTMLOptions, Allocator);
-          finally
-            Allocator.Free;
-          end;
-        end;}
-      fmtLaTeX:
-        begin
-          if Length(Engine.Output) = 0 then
-            WriteLn(SCmdLineOutputOptionMissing)
-          else
-            CreateLaTeXDocForPackage(Engine.Package, Engine);
-        end;
-      fmtIPF:
-        begin
-          if Length(Engine.Output) = 0 then
-            WriteLn(SCmdLineOutputOptionMissing)
-          else
-            CreateIPFDocForPackage(Engine.Package, Engine);
-        end;
-{      fmtXMLStruct:
-        for i := 0 to InputFiles.Count - 1 do
-        begin
-          XMLDoc := ModuleToXMLStruct(Module);
-          try
-           WriteXMLFile(XMLDoc, StdOut);
-          finally
-            XMLDoc.Free;
-          end;
-        end;}
-    end;
-
-    if Length(ContentFile) > 0 then
-      Engine.WriteContentFile(ContentFile);
-
-
+  Try
+    ParseCommandLine;
+    CreateDocumentation;
+    WriteLn(SDone);
+  Finally
+    FreeOptions;
   end;
   end;
-
-  FreeOptions;
-
-  WriteLn(SDone);
 end.
 end.
 
 
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.6  2005-01-09 15:59:50  michael
+  Revision 1.7  2005-01-12 21:11:41  michael
+  + New structure for writers. Implemented TXT writer
+
+  Revision 1.6  2005/01/09 15:59:50  michael
   + Split out latex writer to linear and latex writer
   + Split out latex writer to linear and latex writer
 
 
   Revision 1.5  2004/08/28 18:03:23  michael
   Revision 1.5  2004/08/28 18:03:23  michael