⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uparameterstostate.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{  JADD - Just Another DelphiDoc: Documentation from Delphi Source Code

Copyright (C) 2003-2008   Gerold Veith

This file is part of JADD - Just Another DelphiDoc.

DelphiDoc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.

DelphiDoc 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.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
}

unit UParametersToState;

{Contains the abstract class ~[link TJADDParameterOptions] to parse the
 parameters of this program and to set the internal state of this program,
 represented by an object of class ~[link TJADDState], according to the
 specified parameters. It has to be sub-classed to implement the actual parsing
 of source code and generation of documentation and to handle special needs for
 the different versions of this program (GUI and command line).
}

interface

uses IniFiles,
     UMakeDoc,
     UJADDState,
     UGenerationMessages,
     UCommandParameters;


type


   { * * *  ***  * * *  ***   TJADDParameterOptions   ***  * * *  ***  * * *  }

  //what topics the program can be verbose about
  TVerboseAbout = (
                   //the messages generated while parsing
                   vaParsing,
                   //the list of unknown identifiers/types
                   vaUnknownIdentifiers,
                   //the messages generated while creating the documentation
                   vaGeneration);

  //what topics the program can be verbose about
  TVerboseAbouts = set of TVerboseAbout;



  {Handles all parametes of the program that can be given at the command line.
  }
  TJADDParameterOptions = class(TParameterOptions)
  private
    //the state of the program that is to be modified by the parameters
    FJADDState: TJADDState;

    //whether the program supports reading files from standard Input (only CL)
    FSupportsStdInput: Boolean;

    //filter on messages generated while generating documentation;
    //may be nil; only a reference, won't be freed!
    FFilter: TMessageFilter;

    //whether the handling of the parameters should be aborted
//    FAbort: Boolean;


    //what topics the program should be verbose about (only CL)
    FVerboseOutput: TVerboseAbouts;
    //show the progress while parsing source and generating documentation
    //(only CL)
    FShowProgress: Boolean;


    //the kind of documentation that should be generated by the generator
    FGenerationKind: TDocGenerationKind;


  protected
    //Loads a project file and parses the source code files listed in it.
    function LoadSourceProjectFile(FileName: String): Boolean;
    //Tries to select the source code of an executable and parses it.
    function HandleExecutable(FileName: String): Boolean;
    //Loads already parsed data from a file.
    procedure LoadParsedData(FileName: String);
    //Sets a text in the documentation to be generated to the specified value.
    procedure SetLocalizationOption(const NameValue: String);
    //Changes the filter on messages generated by the generator.
    function ChangeFilter(Value: String): Boolean;
    //Sets what topics the program should be verbose about.
    procedure SetVerboseMode(const Modes: String;
                             LongModes, DefaultEnable: Boolean);
    //Loads a file with a list of GUI log files to generate a help about.
    procedure LoadGUIHelpProjectFile(FileName: String);
    //Generates the documentation of the specified or most recently used kind.
    function SetModeAndGenerate(const Mode: String): Boolean;



    {Parses the selected files with source code.
    ~result whether the selected files were successfully parsed  }
    function DoParse: Boolean; virtual; abstract;
    {Generates the documentation with the current settings.
    ~result whether the documentation was successfully generated }
    function DoGenerate: Boolean; virtual; abstract;

    //Will be called for each parsed parameter of the program.
    function ParamFunc(Parameter: TParameter; SingleChar: Char;
                       const Value: String; HasValue: Boolean): Boolean;
                                                                      override;
  public
    //Create the object to process the parameters of the program.
    constructor Create;


    //Handles all parameters of the program.
    function HandleAllParameters: Boolean;




    property VerboseOutput: TVerboseAbouts read FVerboseOutput
                                           write FVerboseOutput;
    property ShowProgress: Boolean read FShowProgress write FShowProgress;

    property GenerationKind: TDocGenerationKind read FGenerationKind;



    property JADDState: TJADDState read FJADDState write FJADDState;

    property SupportsStdInput: Boolean read FSupportsStdInput
                                       write FSupportsStdInput;
    property Filter: TMessageFilter read FFilter write FFilter;
  end;



















//Reads a project file of the data to parse from (standard) input.
function ReadStdInProject: TCustomIniFile;




implementation

uses SysUtils, Classes,
{$IFDEF VER120}
     FileCtrl,
{$ENDIF}
{$IFNDEF LINUX}
     Windows, Forms, Controls, Dialogs, Registry, ShellApi, ShlObj,
{$ELSE}
     QDialogs,
{$ENDIF}
     General,
     UFilePaths,
     UOptions,
     UDocumentationTexts,
     USaveParsed;






{Reads a project file of the data to parse from (standard) input. It is
 terminated either by EoF or by "[-]" on a line.
~result an ini file object containing all read options }
function ReadStdInProject: TCustomIniFile;
var      Line     :String;          //each line
         Section  :String;          //the current section
         i        :Integer;         //index of a character in the line
begin
 Result := TMemIniFile.Create('');  //create the internal ini file object
 try
   if not Eof then                  //text on stdin available?
    begin
     Section := '';                   //no section defined so far
     repeat                           //until Eof or Section = '-'
       ReadLn(Line);                  //read a line
       if Line <> '' then             //line not empty?
        if Line[1] = '[' then           //is a section?
         begin
          i := pos(']', Line);
          if i = 0 then                 //extract name of the section
           Section := copy(Line, 2, high(length(Line)))
          else
           Section := copy(Line, 2, i - 2);
         end
        else
         if Section <> '' then          //section defined?
          begin
           i := pos('=', Line);
           if i > 1 then                  //is a ini line?
            //save the ini line
            Result.WriteString(Section, copy(Line, 1, i - 1),
                               copy(Line, i + 1, high(length(Line))));
          end;

     //until all text read, or the "end of ini section" read ("[-]")
     until Eof or (Section = '-');

    end; //if not Eof

 except                       //in case of an error
   Result.Free;                //free the ini object again
   raise;                      //and handle the error
 end;
end;












   { * * *  ***  * * *  ***   TJADDParameterOptions   ***  * * *  ***  * * *  }



{Create the object to process the parameters of the program. }
constructor TJADDParameterOptions.Create;
begin
 inherited Create;                         //create the object

 ShowProgress := True;                     //by default show progress
 //by default be verbose on all topics
 FVerboseOutput := [Low(TVerboseAbout)..High(TVerboseAbout)];
end;







{Loads a project file and parses the source code files listed in it.
~param FileName the name of the project file to load
~result whether the source code files could be parsed }
function TJADDParameterOptions.LoadSourceProjectFile(FileName:
                                                              String): Boolean;
var      Ini                  :TCustomIniFile;  //the project ini file to load
         //to edit the language texts
         EditTexts            :TDocumentationTextOptionWrapper;
begin
 //Input should be used and is supported?
 if (FileName = '-') and SupportsStdInput then
  Ini := ReadStdInProject                    //create ini from stdin
 else
  begin
   if not FileExists(FileName) then
    FileName := FileName + '.' + DDPDefaultExtension;
   if not FileExists(FileName) then
    raise EParameterException.CreateFmt('Source project file "%s" not found!',
                                        [FileName]);

{$IFNDEF LINUX}
   if ExtractFilePath(FileName) = '' then    //always use local files
    FileName := '.' + PathDelimiter + FileName;
{$ENDIF}

   Ini := TIniFile.Create(FileName);         //open the ini file
  end;
 try
   FJADDState.LoadProject(Ini);            //load the project

   //load options from the project file
   FJADDState.Generate.InitAllOptions(Ini, nil);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -