Ignore:
Timestamp:
Aug 1, 2006, 8:51:54 PM (19 years ago)
Author:
RBRi
Message:

refactoring for cmd line parameters handling finished

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/NewView/StartupUnit.pas

    r18 r25  
    1515  ACLString,
    1616  GlobalFilelistUnit,
    17   SharedMemoryUnit;
     17  SharedMemoryUnit,
     18  CmdLineParameterUnit;
    1819
    1920const
    2021  OWN_HELP_MARKER = '[NVHELP]';
    2122
    22 type
    23   TWindowPosition = record
    24     Left: longint;
    25     Bottom: longint;
    26     Width: longint;
    27     Height: longint;
    28   end;
    29 
    30   TCommandLineParameters = record
    31     ShowUsageFlag: boolean; // *
    32     TopicParam: string; // *
    33     FilenamesParam: TAString;
    34     SearchText: string;
    35     SearchFlag: boolean;
    36     GlobalSearchText: string; // *
    37     GlobalSearchFlag: boolean; // *
    38     OwnerWindow: HWND;
    39     HelpManagerWindow: HWND;
    40     IsHelpManager: boolean;
    41     WindowTitle: string;
    42     Position: TWindowPosition;
    43     SetPosition: boolean;
    44     Language: string;
    45   end;
    46   // * posted to re-used windows
    47 
    48 Procedure ParseCommandLineParameters;
    4923
    5024function AccessSharedMemory: TSuballocatedSharedMemory;
     
    6741
    6842var
    69   Parameters: TCommandLineParameters;
     43  CmdLineParameters: TCmdLineParameters;
    7044  SharedMemory: TSubAllocatedSharedMemory;
    7145  GlobalFilelist: TGlobalFilelist;
     
    7448
    7549uses
    76   //Forms,
    77   Dos, SysUtils, PMWin,
    78   ACLUtility, ACLStringUtility, ACLFileUtility, AStringUtilityUnit, ACLProfile,
     50  Dos,
     51  SysUtils,
     52  PMWin,
     53  ACLUtility,
     54  ACLStringUtility,
     55  ACLFileUtility,
     56  AStringUtilityUnit,
     57  ACLProfile,
    7958  HelpManagerUnit;
    8059
     
    251230end;
    252231
    253 // Parse command line parameters newview was launched with.
    254 // Store them into the Parameters. variables for later processing.
    255 Procedure ParseCommandLineParameters;
    256 var
    257   ParamIndex: longint;
    258   Param: string;
    259   ParamValue: string;
    260 begin
    261   ProfileEvent( 'ParseCommandLineParameters started' );
    262 
    263   Parameters.FilenamesParam := TAString.Create;
    264   Parameters.TopicParam := '';
    265   Parameters.ShowUsageFlag := false;
    266   Parameters.GlobalSearchFlag := false;
    267   Parameters.SearchFlag := false;
    268   Parameters.OwnerWindow := 0;
    269   Parameters.IsHelpManager := false;
    270   Parameters.HelpManagerWindow := 0;
    271   Parameters.WindowTitle := '';
    272   Parameters.SetPosition := false;
    273   Parameters.Language := '';
    274 
    275   for ParamIndex := 1 to ParamCount do
    276   begin
    277     Param := ParamStr( ParamIndex );
    278     if    MatchFlagParam( Param, '?' )
    279        or MatchFlagParam( Param, 'H' )
    280        or MatchFlagParam( Param, 'HELP' ) then
    281     begin
    282       Parameters.ShowUsageFlag := true
    283     end
    284     else if MatchValueParam( Param, 'LANG', Parameters.Language ) then
    285     begin
    286     end
    287     else if MatchValueParam( Param, 'G', Parameters.GlobalSearchText ) then
    288     begin
    289       Parameters.GlobalSearchFlag := true;
    290     end
    291     else if MatchValueParam( Param, 'S', Parameters.SearchText ) then
    292     begin
    293       Parameters.SearchFlag := true;
    294     end
    295     else if MatchValueParam( Param, 'HM', ParamValue ) then
    296     begin
    297       try
    298         Parameters.HelpManagerWindow := StrToInt( ParamValue );
    299         Parameters.IsHelpManager := true;
    300       except
    301         // ignore invalid window value
    302       end;
    303     end
    304     else if MatchValueParam( Param, 'OWNER', ParamValue ) then
    305     begin
    306       Parameters.OwnerWindow := StrToInt( ParamValue );
    307     end
    308     else if MatchValueParam( Param, 'TITLE', ParamValue ) then
    309     begin
    310       Parameters.WindowTitle := ParamValue;
    311     end
    312     else if MatchFlagParam( Param, 'PROFILE' ) then
    313     begin
    314       StartProfile( GetLogFilesDir + 'newview.prf' );
    315     end
    316     else if MatchValueParam( Param, 'POS', ParamValue ) then
    317     begin
    318       // set window position/size
    319       if ExtractPositionSpec( ParamValue,
    320                               Parameters.Position ) then
    321       begin
    322         Parameters.SetPosition := true;
    323       end
    324       else
    325       begin
    326         // invalid...
    327         Parameters.ShowUsageFlag := true;
    328       end;
    329     end
    330     else
    331     begin
    332       if Parameters.FilenamesParam.Length = 0 then
    333       begin
    334         // filename(s)
    335         AString_ParamStr( ParamIndex, Parameters.FilenamesParam );
    336       end
    337       else
    338       begin
    339         // search (topic) parameter... append all remaining thingies
    340         if Parameters.TopicParam <> '' then
    341         begin
    342           Parameters.TopicParam := Parameters.TopicParam + ' ';
    343         end;
    344         Parameters.TopicParam := Parameters.TopicParam + Param;
    345       end;
    346     end;
    347   end;
    348 
    349   ProfileEvent( 'Parameters parsed' );
    350   ProfileEvent( '  Filenames: '
    351                 + Parameters.FilenamesParam.AsString );
    352   ProfileEvent( '  Topic: '
    353                 + Parameters.TopicParam );
    354 
    355   // params will be acted on later...
    356   ProfileEvent( '...done' );
    357 
    358 end;
    359232
    360233// If another instance already has the files open
     
    371244  Result := NULLHANDLE;
    372245
    373   if Parameters.FilenamesParam.Length = 0 then
     246  if length(CmdLineParameters.getFileNames) = 0 then
    374247    // not loading files; nothing to check
    375248    exit;
     
    378251  Filenames := TStringList.Create;
    379252
    380   AStringToList( Parameters.FilenamesParam, FileItems, '+' );
     253  StringToList(cmdLineParameters.getFileNames, FileItems, '+' );
    381254  TranslateIPFEnvironmentVars( FileItems, FileNames );
    382255
     
    446319function Startup: boolean;
    447320var
     321  tmpCmdLine: String;
     322  tmpSplittedCmdLine : TStringList;
     323  tmpRc : Integer;
     324
    448325  ExistingWindow: HWND;
    449326begin
     
    455332
    456333  // parse parameters into Parameters object
    457   ParseCommandLineParameters;
     334  tmpCmdLine := nativeOS2GetCmdLineParameter;
     335  tmpSplittedCmdLine := TStringList.Create;
     336  tmpRc := splitCmdLineParameter(tmpCmdLine, tmpSplittedCmdLine);
     337
     338  CmdLineParameters := TCmdLineParameters.Create;
     339  CmdLineParameters.parseCmdLine(tmpSplittedCmdLine);
     340
     341  tmpSplittedCmdLine.Destroy;
    458342
    459343  ExistingWindow := FindExistingWindow;
     
    466350    // destroy global list - nobody else will
    467351    GlobalFilelist.Destroy;
    468     Parameters.FilenamesParam.Destroy;
     352    // TODO rbri maybe we need the next line
     353    // Parameters.FilenamesParam.Destroy;
    469354
    470355    WinSetFocus( HWND_DESKTOP, ExistingWindow );
    471356
    472     if Parameters.TopicParam <> '' then
     357    if CmdLineParameters.getTopics <> '' then
    473358    begin
    474359      PostNewViewTextMessage( ExistingWindow,
    475360                              NHM_SEARCH,
    476                               Parameters.TopicParam );
    477     end;
    478 
    479     if Parameters.GlobalSearchFlag then
     361                              CmdLineParameters.getTopics);
     362    end;
     363
     364    if CmdLineParameters.getGlobalSearchTextFlag then
    480365    begin
    481366      PostNewViewTextMessage( ExistingWindow,
    482367                              NHM_GLOBAL_SEARCH,
    483                               Parameters.GlobalSearchText );
    484     end;
    485 
    486     if Parameters.ShowUsageFlag then
     368                              CmdLineParameters.getGlobalSearchText );
     369    end;
     370
     371    if CmdLineParameters.getShowUsageFlag then
    487372    begin
    488373      WinPostMsg( ExistingWindow,
     
    492377    end;
    493378
    494     if Parameters.IsHelpManager then
     379    if CmdLineParameters.getHelpManagerFlag then
    495380    begin
    496381      // tell the new help manager instance to talk to the
    497382      // other viewer
    498       WinPostMsg( Parameters.HelpManagerWindow,
     383      WinPostMsg( CmdLineParameters.getHelpManagerWindow,
    499384               NHM_VIEWER_READY,
    500385               ExistingWindow,
Note: See TracChangeset for help on using the changeset viewer.