Changeset 25


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

refactoring for cmd line parameters handling finished

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Library/ACLStringUtility.pas

    r17 r25  
    284284Function BoolToStr( const b: boolean ): string;
    285285
    286 // Return true if param matches the form
    287 // /Flag:value
    288 // dash (-) can be used instead of slash (/)
    289 // colon can be omitted
    290 function MatchValueParam( const Param: string;
    291                           const Flag: string;
    292                           var Value: string ): boolean;
    293 
    294 // Return true if param matches the form
    295 // /Flag
    296 // dash (-) can be used instead of slash (/)
    297 function MatchFlagParam( const Param: string;
    298                          const Flag: string ): boolean;
    299286
    300287Implementation
     
    14481435end;
    14491436
    1450 // Return true if param matches the form
    1451 // /Flag:value
    1452 // dash (-) can be used instead of slash (/)
    1453 // colon can be omitted
    1454 function MatchValueParam( const Param: string;
    1455                           const Flag: string;
    1456                           var Value: string ): boolean;
    1457 begin
    1458   Result := false;
    1459 
    1460   if Param = '' then
    1461     exit;
    1462 
    1463   if     ( Param[ 1 ] <> '/' )
    1464      and ( Param[ 1 ] <> '-' ) then
    1465     exit;
    1466 
    1467   if not StringsSame( Copy( Param, 2, Length( Flag ) ),
    1468                       Flag ) then
    1469     exit;
    1470 
    1471   Result := true;
    1472 
    1473   Value := StrRightFrom( Param, 2 + Length( Flag ) );
    1474   if Value <> '' then
    1475     if Value[ 1 ] = ':' then
    1476       Delete( Value, 1, 1 );
    1477 end;
    1478 
    1479 // Return true if param matches the form
    1480 // /Flag
    1481 // dash (-) can be used instead of slash (/)
    1482 function MatchFlagParam( const Param: string;
    1483                          const Flag: string ): boolean;
    1484 begin
    1485   Result := false;
    1486 
    1487   if Param = '' then
    1488     exit;
    1489 
    1490   if     ( Param[ 1 ] <> '/' )
    1491      and ( Param[ 1 ] <> '-' ) then
    1492     exit;
    1493 
    1494   Result := StringsSame( StrRightFrom( Param, 2 ),
    1495                          Flag );
    1496 end;
    1497 
    14981437Initialization
    14991438  InitHexDigitMap;
  • trunk/NewView/CmdLineParameterUnit.pas

    r23 r25  
    4747       ownerWindow : integer;
    4848       windowTitle : string;
    49        fileName : string;
    50        topic : string;
    51     {
    52     TopicParam: string;
    53     FilenamesParam: TAString;
    54     }
     49       fileNames : string;
     50       topics : string;
    5551
    5652     public
     
    6258       FUNCTION getLanguage : string;
    6359       FUNCTION getHelpManagerFlag : boolean;
     60       FUNCTION setHelpManagerFlag(aNewValue : boolean) : boolean;
    6461       FUNCTION getHelpManagerWindow : integer;
    6562       FUNCTION getWindowPositionFlag : boolean;
     
    6764       FUNCTION getOwnerWindow : integer;
    6865       FUNCTION getWindowTitle : string;
    69        FUNCTION getFileName : string;
    70        FUNCTION getTopic : string;
     66       FUNCTION getFileNames : string;
     67       FUNCTION getTopics : string;
    7168       PROCEDURE parseCmdLine(aSplittedCmdLine : TStringList);
    7269  end;
     
    7875 // returns a string containing the whole
    7976 // command line parametes
    80  FUNCTION splitCmdLineParameter(aCmdLineString : String; var aRC : Integer) : TStringList;
     77 FUNCTION splitCmdLineParameter(aCmdLineString : String; var aResult : TStringList) : integer;
    8178
    8279 // Return true if param matches the form
     
    145142
    146143
     144  FUNCTION TCmdLineParameters.setHelpManagerFlag(aNewValue : boolean) : boolean;
     145  begin
     146       helpManagerFlag := aNewValue;
     147       result := helpManagerFlag;
     148  end;
     149
     150
    147151  FUNCTION TCmdLineParameters.getHelpManagerWindow : integer;
    148152  begin
     
    175179
    176180
    177   FUNCTION TCmdLineParameters.getFileName : string;
    178   begin
    179        result := fileName;
    180   end;
    181 
    182 
    183   FUNCTION TCmdLineParameters.getTopic : string;
    184   begin
    185        result := topic;
     181  FUNCTION TCmdLineParameters.getFileNames : string;
     182  begin
     183       result := fileNames;
     184  end;
     185
     186
     187  FUNCTION TCmdLineParameters.getTopics : string;
     188  begin
     189       result := topics;
    186190  end;
    187191
     
    193197      tmpParameterValue : string;
    194198  begin
     199      ProfileEvent( 'ParseCommandLineParameters started' );
     200
    195201      // reset the whole object
    196202      showUsageFlag := false;
     
    207213      windowTitle := '';
    208214
    209       filename := '';
    210       topic := '';
     215      filenames := '';
     216      topics := '';
    211217
    212218      // start parsing
     
    273279          else
    274280          begin
    275                if length(filename) = 0 then
     281               if length(filenames) = 0 then
    276282               begin
    277283                   // filename
    278                    fileName := tmpParameter;
     284                   fileNames := tmpParameter;
    279285               end
    280286               else
    281287               begin
    282288                   // search (topic) parameter... append all remaining thingies
    283                    if topic <> '' then
     289                   if topics <> '' then
    284290                   begin
    285                        topic := topic + ' ';
     291                       topics := topics + ' ';
    286292                   end;
    287                    topic := topic + tmpParameter;
     293                   topics := topics + tmpParameter;
    288294               end;
    289295          end;
    290296      end;
     297
     298      ProfileEvent('Parameters parsed');
     299      ProfileEvent('  Filename(s): ' + fileNames);
     300      ProfileEvent('  Topic(s): ' + topics);
     301      ProfileEvent( '...done' );
    291302  end;
    292303
     
    307318
    308319
    309 FUNCTION splitCmdLineParameter(aCmdLineString : String; var aRC : Integer) : TStringList;
     320FUNCTION splitCmdLineParameter(aCmdLineString : String; var aResult : TStringList) : integer;
    310321 CONST
    311322     STATE_BEFORE = 0;
     
    319330     tmpState : INTEGER;
    320331     tmpCurrentCommand : String;
    321      tmpResult : TStringList;
    322332
    323333  BEGIN
    324      aRC := SUCCESS;
    325      tmpResult := TStringList.Create;
     334     result := SUCCESS;
     335     aResult.Clear;
     336
    326337     tmpState := 0;
    327338     tmpCurrentCommand := '';
     
    337348               STATE_INSIDE :
    338349                 begin
    339                     tmpResult.add(tmpCurrentCommand);
     350                    aResult.add(tmpCurrentCommand);
    340351                    tmpCurrentCommand := '';
    341352                    tmpState := STATE_BEFORE;
     
    343354               STATE_INSIDE_QUOTED_START_QUOTE :
    344355                 begin
    345                     tmpResult.add(tmpCurrentCommand);
     356                    aResult.add(tmpCurrentCommand);
    346357                    tmpCurrentCommand := '';
    347358                    tmpState := STATE_BEFORE;
     
    409420     STATE_INSIDE :
    410421       begin
    411           tmpResult.add(tmpCurrentCommand);
     422          aResult.add(tmpCurrentCommand);
    412423       end;
    413424     STATE_INSIDE_QUOTED_START_QUOTE :
    414425       begin
    415           tmpResult.add(tmpCurrentCommand);
     426          aResult.add(tmpCurrentCommand);
    416427       end;
    417428     ELSE
    418429       begin
    419           aRC := ERROR_UNMATCHED_QUOTE;
    420           tmpResult.add(tmpCurrentCommand);
     430          result := ERROR_UNMATCHED_QUOTE;
     431          aResult.add(tmpCurrentCommand);
    421432       end;
    422433     end;
    423      splitCmdLineParameter:= tmpResult;
    424434  END;
    425435
     
    509519end;
    510520
     521
    511522END.
  • trunk/NewView/MainForm.pas

    r18 r25  
    1616// library
    1717  ACLString, SharedMemoryUnit, ACLLanguageUnit, GenericThread,
     18  CmdLineParameterUnit,
     19
    1820// custom components
    1921  SplitBar, Outline2, RichTextView, Coolbar2,
     
    862864  T: TTopic;
    863865  ResourceIDs: TList;
    864   Level: longint;
    865866  ImageOffsets: TList;
    866867  ImageOffset: longint;
     
    19001901  TotalTopics: longint;
    19011902  TotalTopicIndex: longint;
    1902 
    1903   Topic: TTopic;
    19041903begin
    19051904  PrintSingle := nil;
     
    22182217var
    22192218  i: integer;
     2219  tmpCmdLine: String;
     2220  tmpSplittedCmdLine : TStringList;
     2221  tmpRc : Integer;
     2222  tmpWindowPosition : TWindowPosition;
    22202223Begin
    22212224  with InformationForm.InformationMemo do
    22222225  begin
     2226    tmpCmdLine := nativeOS2GetCmdLineParameter;
     2227    tmpSplittedCmdLine := TStringList.Create;
     2228
    22232229    Lines.Clear;
    2224     Lines.Add( ParameterCountLabel
    2225                + IntToStr( ParamCount ) );
    2226     for i := 1 to ParamCount do
     2230    Lines.Add(ParameterCountLabel +IntToStr(tmpSplittedCmdLine.count));
     2231    tmpRc := splitCmdLineParameter(tmpCmdLine, tmpSplittedCmdLine);
     2232    for i := 0 to tmpSplittedCmdLine.Count -1 do
    22272233      Lines.Add( ' '
    22282234                 + IntToStr( i )
    22292235                 + ' ['
    2230                  + ParamStr( i )
     2236                 + tmpSplittedCmdLine[i]
    22312237                 + ']' );
     2238
     2239    tmpSplittedCmdLine.Destroy;
     2240    Lines.Add('');
     2241    Lines.Add('parsed infos:');
     2242    Lines.Add('getShowUsageFlag: ' + boolToStr(CmdLineParameters.getShowUsageFlag));
     2243    Lines.Add('getSearchTextFlag: ' + boolToStr(CmdLineParameters.getSearchTextFlag));
     2244    Lines.Add('getSearchText: ' + CmdLineParameters.getSearchText);
     2245    Lines.Add('getGlobalSearchTextFlag: ' + boolToStr(CmdLineParameters.getGlobalSearchTextFlag));
     2246    Lines.Add('getGlobalSearchText: ' + CmdLineParameters.getGlobalSearchText);
     2247    Lines.Add('getLanguage: ' + CmdLineParameters.getLanguage);
     2248    Lines.Add('getHelpManagerFlag: ' + boolToStr(CmdLineParameters.getHelpManagerFlag));
     2249    Lines.Add('getHelpManagerFlag: ' + boolToStr(CmdLineParameters.getHelpManagerFlag));
     2250    Lines.Add('getHelpManagerWindow: ' + intToStr(CmdLineParameters.getHelpManagerWindow));
     2251    Lines.Add('getWindowPositionFlag: ' + boolToStr(CmdLineParameters.getWindowPositionFlag));
     2252
     2253    tmpWindowPosition := CmdLineParameters.getWindowPosition;
     2254    Lines.Add('getWindowPosition: ');
     2255    Lines.Add('    left:   ' + intToStr(tmpWindowPosition.left));
     2256    Lines.Add('    bottom: ' + intToStr(tmpWindowPosition.bottom));
     2257    Lines.Add('    width: ' + intToStr(tmpWindowPosition.width));
     2258    Lines.Add('    height: ' + intToStr(tmpWindowPosition.height));
     2259    Lines.Add('getOwnerWindow: ' + intToStr(CmdLineParameters.getOwnerWindow));
     2260    Lines.Add('getWindowTitle: ' + CmdLineParameters.getWindowTitle);
     2261    Lines.Add('getFileNames: ' + CmdLineParameters.getFileNames);
     2262    Lines.Add('getTopics: ' + CmdLineParameters.getTopics);
     2263
    22322264  end;
    22332265
     
    23502382  FileIndex: longint;
    23512383  HelpFile: THelpFile;
    2352   Dummy: TNode;
    23532384Begin
    23542385  EnableControls;
     
    23572388    begin
    23582389      // not really feasible to load contents here, as we rely
    2359       // on it for many things 
     2390      // on it for many things
    23602391      ContentsOutline.Focus;
    23612392    end;
     
    36193650  Settings.MRUList.Destroy;
    36203651
    3621   Parameters.FilenamesParam.Destroy;
     3652  // TODO rbri maybe we have to do this
     3653  // Parameters.FilenamesParam.Destroy;
    36223654
    36233655  if g_CurrentLanguageFile <> nil then
     
    37633795
    37643796Procedure TMainForm.MainFormOnCreate (Sender: TObject);
     3797var
     3798  tmpCmdLine: String;
     3799  tmpSplittedCmdLine : TStringList;
     3800  tmpRc : Integer;
    37653801Begin
    37663802  ProfileEvent( 'MainFormOnCreate' );
     
    37743810  GlobalFilelist := TGlobalFilelist.Create;
    37753811
    3776   ParseCommandLineParameters;
    3777 
     3812  // parse parameters into Parameters object
     3813  tmpCmdLine := nativeOS2GetCmdLineParameter;
     3814  tmpSplittedCmdLine := TStringList.Create;
     3815  tmpRc := splitCmdLineParameter(tmpCmdLine, tmpSplittedCmdLine);
     3816  CmdLineParameters := TCmdLineParameters.Create;
     3817  CmdLineParameters.parseCmdLine(tmpSplittedCmdLine);
     3818  tmpSplittedCmdLine.destroy;
    37783819  RegisterForLanguages( OnLanguageEvent );
    37793820
     
    38493890  ProfileEvent( 'Loading language' );
    38503891
    3851   if Parameters.Language <> '' then
    3852     LoadAutoLanguage( 'newview', Parameters.Language )
     3892  if CmdLineParameters.getLanguage <> '' then
     3893    LoadAutoLanguage( 'newview', CmdLineParameters.getLanguage )
    38533894  else
    38543895    LoadDefaultLanguage( 'newview' );
     
    38813922  ProfileEvent( 'OnCreate done' );
    38823923
    3883   if Parameters.SetPosition then
     3924  if CmdLineParameters.getWindowPositionFlag then
    38843925  begin
    38853926    SmartSetWindowPos( self,
    3886                        Parameters.Position.Left,
    3887                        Parameters.Position.Bottom,
    3888                        Parameters.Position.Width,
    3889                        Parameters.Position.Height,
     3927                       CmdLineParameters.getWindowPosition.Left,
     3928                       CmdLineParameters.getWindowPosition.Bottom,
     3929                       CmdLineParameters.getWindowPosition.Width,
     3930                       CmdLineParameters.getWindowPosition.Height,
    38903931                       false );
    38913932  end;
     
    39734014Procedure TMainForm.ClearHelpManager;
    39744015Begin
    3975   if not Parameters.IsHelpManager then
     4016  if not CmdLineParameters.getHelpManagerFlag then
    39764017    exit;
    39774018
     
    39794020  PostHelpManagerMessage( NHM_FORGET_VIEWER, 0, 0 );
    39804021
    3981   Parameters.IsHelpManager := false;
     4022  CmdLineParameters.setHelpManagerFlag(false);
    39824023
    39834024  HelpManagerWindows.Clear;
     
    39904031  ProfileEvent( 'MainFormOnShow' );
    39914032
    3992   if Parameters.OwnerWindow <> NULLHANDLE then
     4033  if CmdLineParameters.getOwnerWindow <> NULLHANDLE then
    39934034  begin
    39944035    ProfileEvent( 'Setting owner: '
    3995                   + IntToStr( Parameters.OwnerWindow ) );
     4036                  + IntToStr( CmdLineParameters.getOwnerWindow ) );
    39964037    WinSetOwner( Frame.Handle,
    3997                  Parameters.OwnerWindow );
    3998 
    3999   end;
    4000 
    4001   if Parameters.IsHelpManager then
     4038                 CmdLineParameters.getOwnerWindow );
     4039
     4040  end;
     4041
     4042  if CmdLineParameters.getHelpManagerFlag then
    40024043  begin
    40034044    ProfileEvent( '  Help Manager Title: '
     
    41044145  ProfileEvent( 'WMOpened: SetLayout' );
    41054146
    4106   if Parameters.IsHelpManager then
     4147  if CmdLineParameters.getHelpManagerFlag then
    41074148    FShowLeftPanel := Settings.ShowLeftPanel_Help
    41084149  else
     
    41234164  Update;
    41244165
    4125   if not Parameters.IsHelpManager then
     4166  if not CmdLineParameters.getHelpManagerFlag then
    41264167  begin
    41274168    ProfileEvent( 'Check environment vars' );
    41284169    CheckEnvironmentVars;
    41294170
    4130     if Parameters.ShowUsageFlag then
     4171    if CmdLineParameters.getShowUsageFlag then
    41314172    begin
    41324173      ProfileEvent( 'Showing usage' );
     
    41364177  end;
    41374178
    4138   HelpManagerWindows.Add( pointer( Parameters.HelpManagerWindow ) );
    4139 
    4140   if Parameters.FilenamesParam.Length > 0 then
     4179  HelpManagerWindows.Add( pointer( CmdLineParameters.getHelpManagerWindow ) );
     4180
     4181  if length(CmdLineParameters.getFileNames) > 0 then
    41414182  begin
    41424183    // open specified files
    41434184    Filenames := TStringList.Create;
    41444185
    4145     AStringToList( Parameters.FilenamesParam, Filenames, '+' );
     4186    // TODO rbri remove type conversion
     4187    StringToList(cmdLineParameters.getFileNames, Filenames, '+' );
    41464188
    41474189    ProfileEvent( 'Call OpenFiles' );
    41484190
    41494191    OpenFirstTopic := true;
    4150     if    ( Parameters.TopicParam <> '' )
    4151        or Parameters.SearchFlag then
     4192    if    ( CmdLineParameters.getTopics <> '' )
     4193       or CmdLineParameters.getSearchTextFlag then
    41524194      // if we're going to search, don't open first topic
    41534195      OpenFirstTopic := false;
    41544196
    4155     if Parameters.IsHelpManager then
     4197    if CmdLineParameters.getHelpManagerFlag then
    41564198      // don't open first topic if we're online help
    41574199      // in case we are wanting to show a specific topic
     
    41604202
    41614203    OpenFiles( Filenames,
    4162                Parameters.WindowTitle,
     4204               CmdLineParameters.getWindowTitle,
    41634205               OpenFirstTopic );
    41644206
    41654207    Filenames.Destroy;
    41664208
    4167     if Parameters.TopicParam <> '' then
     4209    if CmdLineParameters.getTopics <> '' then
    41684210    begin
    41694211      // search in contents only!
    41704212      ProfileEvent( 'Do startup topic search' );
    41714213
    4172       StartupTopicSearch( Parameters.TopicParam );
     4214      StartupTopicSearch( CmdLineParameters.getTopics );
    41734215    end
    4174     else if Parameters.SearchFlag then
     4216    else if CmdLineParameters.getSearchTextFlag then
    41754217    begin
    41764218      // search in specified files
     
    41784220      DisplaySearch;
    41794221
    4180       SearchFor( Parameters.SearchText );
     4222      SearchFor( CmdLineParameters.getSearchText );
    41814223    end;
    41824224  end;
    41834225
    4184   if Parameters.GlobalSearchFlag then
     4226  if CmdLineParameters.getGlobalSearchTextFlag then
    41854227  begin
    41864228    // Global search
    4187     ProfileEvent( 'Do global search: ' + Parameters.GlobalSearchText );
    4188     DoGlobalSearch( Parameters.GlobalSearchText );
    4189   end;
    4190 
    4191   if     ( Parameters.FilenamesParam.Length = 0 )
    4192      and ( not Parameters.GlobalSearchFlag ) then
     4229    ProfileEvent( 'Do global search: ' + CmdLineParameters.getGlobalSearchText );
     4230    DoGlobalSearch( CmdLineParameters.getGlobalSearchText );
     4231  end;
     4232
     4233  if     ( length(CmdLineParameters.getFileNames) = 0 )
     4234     and ( not CmdLineParameters.getGlobalSearchTextFlag ) then
    41934235  begin
    41944236    // user hasn't requested any particular file
     
    42134255  ProfileEvent( 'Open finished' );
    42144256
    4215   if Parameters.IsHelpManager then
     4257  if CmdLineParameters.getHelpManagerFlag then
    42164258  begin
    42174259    // Tell helpmanager(s) our window handle
     
    47574799  begin
    47584800    SearchResultsListBox.Items.Add(   NoSearchMatchesMsg
    4759                                     + ': ' 
     4801                                    + ': '
    47604802                                    + SearchText );
    47614803    RefreshWindows( Windows ); // update to remove old highlights
     
    66636705                FirstContentsNode );
    66646706
    6665   if Parameters.IsHelpManager then
     6707  if CmdLineParameters.getHelpManagerFlag then
    66666708    ShowLeftPanel := Settings.ShowLeftPanel_Help
    66676709  else
  • trunk/NewView/NewViewTests.pas

    r23 r25  
    9696     writeln('CmdLineParameterUnit Tests ''' + nativeOS2GetCmdLineParameter + '''');
    9797
    98      tmpResult := splitCmdLineParameter('', tmpRC);
     98     tmpResult := TStringList.Create;
     99     tmpRC := splitCmdLineParameter('', tmpResult);
    99100     assertEqualsInt('CmdLine split empy string', 0, tmpRC);
    100101     assertEqualsInt('CmdLine split empy string', 0, tmpResult.Count);
    101 
    102      tmpResult := splitCmdLineParameter('abc', tmpRC);
     102     tmpResult.Destroy;
     103
     104     tmpResult := TStringList.Create;
     105     tmpRC := splitCmdLineParameter('abc', tmpResult);
    103106     assertEqualsInt('CmdLine split single string', 0, tmpRC);
    104107     assertEqualsInt('CmdLine split single string', 1, tmpResult.Count);
    105108     assertEqualsString('CmdLine split single string', 'abc', tmpResult[0]);
    106 
    107      tmpResult := splitCmdLineParameter(' abc', tmpRC);
     109     tmpResult.Destroy;
     110
     111     tmpResult := TStringList.Create;
     112     tmpRC := splitCmdLineParameter(' abc', tmpResult);
    108113     assertEqualsInt('CmdLine split single string with leading blank', 0, tmpRC);
    109114     assertEqualsInt('CmdLine split single string with leading blank', 1, tmpResult.Count);
    110115     assertEqualsString('CmdLine split single string with leading blankCmdLine split many strings', 'abc', tmpResult[0]);
    111 
    112      tmpResult := splitCmdLineParameter('abc def ghi', tmpRC);
     116     tmpResult.Destroy;
     117
     118     tmpResult := TStringList.Create;
     119     tmpRC := splitCmdLineParameter('abc def ghi', tmpResult);
    113120     assertEqualsInt('CmdLine split empy string', 0, tmpRC);
    114121     assertEqualsInt('CmdLine split many strings', 3, tmpResult.Count);
     
    116123     assertEqualsString('CmdLine split many strings', 'def', tmpResult[1]);
    117124     assertEqualsString('CmdLine split many strings', 'ghi', tmpResult[2]);
    118 
    119      tmpResult := splitCmdLineParameter('"abc def"', tmpRC);
     125     tmpResult.Destroy;
     126
     127     tmpResult := TStringList.Create;
     128     tmpRC := splitCmdLineParameter('"abc def"', tmpResult);
    120129     assertEqualsInt('CmdLine split quoted (1)', 0, tmpRC);
    121130     assertEqualsInt('CmdLine split quoted (1)', 1, tmpResult.Count);
    122131     assertEqualsString('CmdLine split quoted (1)', 'abc def', tmpResult[0]);
    123 
    124      tmpResult := splitCmdLineParameter('ab"abc def"', tmpRC);
     132     tmpResult.Destroy;
     133
     134     tmpResult := TStringList.Create;
     135     tmpRC := splitCmdLineParameter('ab"abc def"', tmpResult);
    125136     assertEqualsInt('CmdLine split quoted (2)', 0, tmpRC);
    126137     assertEqualsInt('CmdLine split quoted (2)', 1, tmpResult.Count);
    127138     assertEqualsString('CmdLine split quoted (2)', 'ababc def', tmpResult[0]);
    128 
    129      tmpResult := splitCmdLineParameter('ab"""abc def"', tmpRC);
     139     tmpResult.Destroy;
     140
     141     tmpResult := TStringList.Create;
     142     tmpRC := splitCmdLineParameter('ab"""abc def"', tmpResult);
    130143     assertEqualsInt('CmdLine split quoted (3)', 0, tmpRC);
    131144     assertEqualsInt('CmdLine split quoted (3)', 1, tmpResult.Count);
    132145     assertEqualsString('CmdLine split quoted (3)', 'ab"abc def', tmpResult[0]);
    133 
    134      tmpResult := splitCmdLineParameter('ab"abc""def"', tmpRC);
     146     tmpResult.Destroy;
     147
     148     tmpResult := TStringList.Create;
     149     tmpRC := splitCmdLineParameter('ab"abc""def"', tmpResult);
    135150     assertEqualsInt('CmdLine split quoted (4)', 0, tmpRC);
    136151     assertEqualsInt('CmdLine split quoted (4)', 1, tmpResult.Count);
    137152     assertEqualsString('CmdLine split quoted (4)', 'ababc"def', tmpResult[0]);
    138 
    139      tmpResult := splitCmdLineParameter('ab"abc""def" "ghi"', tmpRC);
     153     tmpResult.Destroy;
     154
     155     tmpResult := TStringList.Create;
     156     tmpRC := splitCmdLineParameter('ab"abc""def" "ghi"', tmpResult);
    140157     assertEqualsInt('CmdLine split quoted (5)', 0, tmpRC);
    141158     assertEqualsInt('CmdLine split quoted (5)', 2, tmpResult.Count);
    142159     assertEqualsString('CmdLine split quoted (5)', 'ababc"def', tmpResult[0]);
    143160     assertEqualsString('CmdLine split quoted (5)', 'ghi', tmpResult[1]);
    144 
    145      tmpResult := splitCmdLineParameter('ab"abc""def" "ghi', tmpRC);
     161     tmpResult.Destroy;
     162
     163     tmpResult := TStringList.Create;
     164     tmpRC := splitCmdLineParameter('ab"abc""def" "ghi', tmpResult);
    146165     assertEqualsInt('CmdLine split quoted (6)', -1, tmpRC);
    147166     assertEqualsInt('CmdLine split quoted (6)', 2, tmpResult.Count);
    148167     assertEqualsString('CmdLine split quoted (6)', 'ababc"def', tmpResult[0]);
    149168     assertEqualsString('CmdLine split quoted (6)', 'ghi', tmpResult[1]);
     169     tmpResult.Destroy;
    150170
    151171     // parser Tests
     
    510530     tmpCmdLineParameters := TCmdLineParameters.Create;
    511531     tmpCmdLineParameters.parseCmdLine(tmpParams);
    512      assertEqualsString('parseCmdLine [getFileName](70)', 'ab c', tmpCmdLineParameters.getFileName);
    513      assertEqualsString('parseCmdLine [getTopic](70)', 'topi1 topi2', tmpCmdLineParameters.getTopic);
     532     assertEqualsString('parseCmdLine [getFileName](70)', 'ab c', tmpCmdLineParameters.getFileNames);
     533     assertEqualsString('parseCmdLine [getTopic](70)', 'topi1 topi2', tmpCmdLineParameters.getTopics);
     534
    514535END;
    515536
  • 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.