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

📄 uparameterstostate.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 3 页
字号:
                                        [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.LoadGUIProject(Ini);         //load the project

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

   //create editor of the texts
   EditTexts := TDocumentationTextOptionWrapper.Create;
   try
     EditTexts.LoadIniOptions(Ini);        //load from project file
   finally
    EditTexts.Free;                        //free the editor
   end;
 finally
  Ini.Free;                                //close the project file
 end;
end;


{Generates the documentation of the specified or most recently used kind.
~param Mode the kind of documentation to generate,
            '' for the most recently kind
~result whether the documentation could be generated successfully }
function TJADDParameterOptions.SetModeAndGenerate(const Mode: String): Boolean;
         //the names of the kinds of documentation to be generated
const    GenerationModes: array[TDocGenerationKind] of String =
                          ('Source', 'UserDoc', 'GUIHelp');
begin
 if Mode <> '' then                          //kind specified?
  begin
   FGenerationKind := High(GenerationModes);   //search the kind by its name
   while (FGenerationKind > Low(GenerationModes)) and
         (CompareText(GenerationModes[FGenerationKind], Mode) <> 0) do
    Dec(FGenerationKind);
   //not a name of a mode?
   if CompareText(GenerationModes[FGenerationKind], Mode) <> 0 then
    raise EParameterException.CreateFmt('Mode of generation of documentation is unknown: "%s"!',
                                        [Mode]);
  end;

 Result := DoGenerate;                       //generate the documentation
end;





{Will be called for each parsed parameter of the program.
~param Parameter  the kind of the parameter
~param SingleChar the single character used for the option, if the long option
                  has be used it will be #0
~param Value      the value of the parameter of the parameter, '' if none
                  specified
~param HasValue   whether a parameter has been specified for the option
~result whether the function should be called for the next parameter or parsing
        them should be aborted
~exception EParameterException when the parameter or its value is invalid }
function TJADDParameterOptions.ParamFunc(Parameter: TParameter;
                                         SingleChar: Char;
                                         const Value: String;
                                         HasValue: Boolean): Boolean;
begin
 Result := True;                    //assume everthing's find
 case Parameter of                  //handle the parameter
   //output the simple help
   pHelp:                   begin
                             ShowParametersHelp('');
                             Result := False;
//                             FAbort := True;
                            end;
   //load a project file with the list of Pascal files to be
   //parsed
   pSourceProject:          begin
                             Assert(HasValue);
                             Result := LoadSourceProjectFile(Value);
                            end;
   //load or create a new project based on its executable file
   pExecutable:             begin
                             Assert(HasValue);
                             Result := HandleExecutable(Value);
                            end;
   //load previously parsed data from a file
   pLoadParsedData:         begin
                             Assert(HasValue);
                             LoadParsedData(Value);
                            end;
   //keep the data and generate documentation again about it
//   pReuseData:

   //select the generator to generate the documentation
   pGenerator:              begin
                             Assert(HasValue);
                             if not FJADDState.Generate.
                                              ChangeGeneratorByName(Value) then
                              raise EParameterException.CreateFmt('Generator class is unknown: "%s"!',
                                                                  [Value]);
                            end;
   //set the directory to generate the documentation to
   pDocumentationPath:      begin
                             Assert(HasValue);
                             //set path for the documentation
                             FJADDState.Generate.DestPath := Value;
                            end;
   //the the name of the file to generate the documentation into,
   //same as ~[link pGenerationOption] with "FileName=Value", not
   //all generators support this option, so it will be ignored
   pDocumentationFileName:  begin
                             Assert(HasValue);
                             //if generator has an option to set the file name
                             if FJADDState.Generate.GeneratorHasFileName then
                              //set name of the file for the documentation
                              FJADDState.Generate.FileName := Value;
                            end;

   //sets an option of a generator, the parameter consists of
   //a "Name=Value" pair with "Name" being the name of the option
   //to be set and "Value" its new value
   pGenerationOption:       begin
                             Assert(HasValue);
                             Assert(not (pos('=', Value) in [0, 1]));
                             //set the option
                             FJADDState.Generate.SetOneOption(Copy(Value, 1,
                                                         pos('=', Value) - 1),
                                                    Copy(Value,
                                                         pos('=', Value) + 1,
                                                         High(Length(Value))));
                            end;
   //sets the localized version of a text to be used in the
   //documentation, the parameter consists of a "Name=Value" pair
   //with "Name" being the name of the text to be localized and
   //"Value" its new value
   pLocalize:               begin
                             Assert(HasValue);
                             Assert(not (pos('=', Value) in [0, 1]));
                             SetLocalizationOption(Value);    //set the option
                            end;
   //loads the localized versions of the texts to be used in the
   //documentation from a file
   pLoadLocalization:       begin
                             Assert(HasValue);
                             //file does not exist?
                             if not FileExists(Value) then
                              if SingleChar = 'L' then     //short option used?
                               //try to set it as a language
                               SetLocalizationOption('Language=' + Value)
                              else
                               raise EParameterException.CreateFmt('File to load localized texts from not found: "%s"!',
                                                                   [Value])
                             else
                              //try to load as file
                              SetLocalizationOption('LanguageFile=' + Value)
                            end;
   //(re-)set the localized versions of the texts to be used in
   //the documentation to the value of a language whose values
   //are pre-defined in the program (currently only English and
   //German)
   pUseLanguage:            begin
                             Assert(HasValue);
                             //set the language as option
                             SetLocalizationOption('Language=' + Value);
                            end;

   //adds a file with (additional) user documentation to the
   //internal list so it can be included in the documentation
   //being generated
   pUserDocumentation:      begin
                             Assert(HasValue);
                             //if not already in it, add the file
                             if FJADDState.FilesOfUserDocumentation.
                                                       IndexOf(Value) = -1 then
                              FJADDState.FilesOfUserDocumentation.Add(Value);
                            end;
   //clears the list of files with (additional) user
   //documentation so no user documentation in included unless
   //new files are added afterwards
   pClearUserDocumentation: begin
                             Assert(not HasValue);
                             FJADDState.FilesOfUserDocumentation.Clear;
                            end;
   //changes a part of the filter for the messages of the
   //generator when generating the documentation, only the not
   //filtered messages are written in the command line version
   pGeneratorFilter:        begin
                             Assert(HasValue);
                             //filter to edit available?
                             if assigned(FFilter) and
                                not ChangeFilter(Value) then
                              raise EParameterException.CreateFmt('Invalid value to change the filter on messages of generator: "%s"!',
                                     [Value]);
                            end;
   //clears the filter so all messages of the generator when
   //generating the documentation will be written in the command
   //line version, unless the filter is changed afterwards
   pClearGeneratorFilter:   begin
                             Assert(not HasValue);
                             //filter to edit available?
                             if assigned(FFilter) then
                              FFilter.ClearFilter;        //clear it completely
                            end;
   //sets the kind of messages and information to output in the
   //command line version
   pVerboseModes:           begin
                             SetVerboseMode(Value, SingleChar = #0, True);
                            end;
   //sets the kind of messages and information not to output in
   //the command line version
   pNonVerboseModes:        begin
                             SetVerboseMode(Value, SingleChar = #0, False);
                            end;
   //sets whether the progress while parsing or generating should
   //be shown in the command line version
   pShowProgress:           begin
                             FShowProgress := (SingleChar <> #0) or
                                              not HasValue;
                             if not FShowProgress then
                              if not StringToBoolean(Value, FShowProgress) then
                               raise EParameterException.CreateFmt('Invalid boolean value to set whether the progress should be shown: "%s"!',
                                      [Value]);
                            end;
   //sets that the progress while parsing or generating should
   //not be shown in the command line version
   pHideProgress:           FShowProgress := False;
   //sets that the documentation should automatically be
   //generated in the GUI version
//                   pAutomaticGeneration,

   //adds a log file of a GUI to the internal list so
   //documentation as a help on it can be generated
   pGUILogFile:             begin
                             Assert(HasValue);
                             //if not already in it, add the file
                             if FJADDState.GUIHelpLogFiles.IndexOf(Value) =
                                -1 then
                              FJADDState.GUIHelpLogFiles.Add(Value);
                            end;
   //clears the list of logs files about GUIs so it can be filled
   //anew
   pClearGUILogFiles:       begin
                             Assert(not HasValue);
                             FJADDState.FilesOfUserDocumentation.Clear;
                            end;
   //loads a project file of documentation to be generated as a
   //help on a GUI, this means the list of log files of GUIs and
   //the content of the main index
   pLoadGUIHelpProject:     begin
                             Assert(HasValue);
                             LoadGUIHelpProjectFile(Value);
                            end;

   //generates the documentation with the currently set values,
   //in the command line version automatically implied as last
   //parameter, the kind of the documentation can be selected
   //with an optional parameter, if it is not specified the most recently used
   //kind will be used (default is documentation about source
   //code), if the generator does not support the selected kind
   //the program will exit with an error message
   pGenerate:               Result := SetModeAndGenerate(Value);
 else
  assert(False);
 end;
end;





{Handles all parameters of the program.
~result whether all parameters have been handled and wasn't aborted (in that
        case either an error occured or the help was requested) }
function TJADDParameterOptions.HandleAllParameters: Boolean;
begin
 try
   Result := ReadParameters;             //read all parameters
 except
   on E: EParameterException do           //in case of a faulty parameter
    begin
     ShowParametersHelp(E.Message);         //show the help message
     Result := False;                       //parameter not correct
    end;
   else
    raise;                                //error not handled
 end;
end;


end.

⌨️ 快捷键说明

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