Changeset 25
- Timestamp:
- Aug 1, 2006, 8:51:54 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Library/ACLStringUtility.pas
r17 r25 284 284 Function BoolToStr( const b: boolean ): string; 285 285 286 // Return true if param matches the form287 // /Flag:value288 // dash (-) can be used instead of slash (/)289 // colon can be omitted290 function MatchValueParam( const Param: string;291 const Flag: string;292 var Value: string ): boolean;293 294 // Return true if param matches the form295 // /Flag296 // dash (-) can be used instead of slash (/)297 function MatchFlagParam( const Param: string;298 const Flag: string ): boolean;299 286 300 287 Implementation … … 1448 1435 end; 1449 1436 1450 // Return true if param matches the form1451 // /Flag:value1452 // dash (-) can be used instead of slash (/)1453 // colon can be omitted1454 function MatchValueParam( const Param: string;1455 const Flag: string;1456 var Value: string ): boolean;1457 begin1458 Result := false;1459 1460 if Param = '' then1461 exit;1462 1463 if ( Param[ 1 ] <> '/' )1464 and ( Param[ 1 ] <> '-' ) then1465 exit;1466 1467 if not StringsSame( Copy( Param, 2, Length( Flag ) ),1468 Flag ) then1469 exit;1470 1471 Result := true;1472 1473 Value := StrRightFrom( Param, 2 + Length( Flag ) );1474 if Value <> '' then1475 if Value[ 1 ] = ':' then1476 Delete( Value, 1, 1 );1477 end;1478 1479 // Return true if param matches the form1480 // /Flag1481 // dash (-) can be used instead of slash (/)1482 function MatchFlagParam( const Param: string;1483 const Flag: string ): boolean;1484 begin1485 Result := false;1486 1487 if Param = '' then1488 exit;1489 1490 if ( Param[ 1 ] <> '/' )1491 and ( Param[ 1 ] <> '-' ) then1492 exit;1493 1494 Result := StringsSame( StrRightFrom( Param, 2 ),1495 Flag );1496 end;1497 1498 1437 Initialization 1499 1438 InitHexDigitMap; -
trunk/NewView/CmdLineParameterUnit.pas
r23 r25 47 47 ownerWindow : integer; 48 48 windowTitle : string; 49 fileName : string; 50 topic : string; 51 { 52 TopicParam: string; 53 FilenamesParam: TAString; 54 } 49 fileNames : string; 50 topics : string; 55 51 56 52 public … … 62 58 FUNCTION getLanguage : string; 63 59 FUNCTION getHelpManagerFlag : boolean; 60 FUNCTION setHelpManagerFlag(aNewValue : boolean) : boolean; 64 61 FUNCTION getHelpManagerWindow : integer; 65 62 FUNCTION getWindowPositionFlag : boolean; … … 67 64 FUNCTION getOwnerWindow : integer; 68 65 FUNCTION getWindowTitle : string; 69 FUNCTION getFileName : string;70 FUNCTION getTopic : string;66 FUNCTION getFileNames : string; 67 FUNCTION getTopics : string; 71 68 PROCEDURE parseCmdLine(aSplittedCmdLine : TStringList); 72 69 end; … … 78 75 // returns a string containing the whole 79 76 // command line parametes 80 FUNCTION splitCmdLineParameter(aCmdLineString : String; var aR C : Integer) : TStringList;77 FUNCTION splitCmdLineParameter(aCmdLineString : String; var aResult : TStringList) : integer; 81 78 82 79 // Return true if param matches the form … … 145 142 146 143 144 FUNCTION TCmdLineParameters.setHelpManagerFlag(aNewValue : boolean) : boolean; 145 begin 146 helpManagerFlag := aNewValue; 147 result := helpManagerFlag; 148 end; 149 150 147 151 FUNCTION TCmdLineParameters.getHelpManagerWindow : integer; 148 152 begin … … 175 179 176 180 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; 186 190 end; 187 191 … … 193 197 tmpParameterValue : string; 194 198 begin 199 ProfileEvent( 'ParseCommandLineParameters started' ); 200 195 201 // reset the whole object 196 202 showUsageFlag := false; … … 207 213 windowTitle := ''; 208 214 209 filename := '';210 topic := '';215 filenames := ''; 216 topics := ''; 211 217 212 218 // start parsing … … 273 279 else 274 280 begin 275 if length(filename ) = 0 then281 if length(filenames) = 0 then 276 282 begin 277 283 // filename 278 fileName := tmpParameter;284 fileNames := tmpParameter; 279 285 end 280 286 else 281 287 begin 282 288 // search (topic) parameter... append all remaining thingies 283 if topic <> '' then289 if topics <> '' then 284 290 begin 285 topic := topic+ ' ';291 topics := topics + ' '; 286 292 end; 287 topic := topic+ tmpParameter;293 topics := topics + tmpParameter; 288 294 end; 289 295 end; 290 296 end; 297 298 ProfileEvent('Parameters parsed'); 299 ProfileEvent(' Filename(s): ' + fileNames); 300 ProfileEvent(' Topic(s): ' + topics); 301 ProfileEvent( '...done' ); 291 302 end; 292 303 … … 307 318 308 319 309 FUNCTION splitCmdLineParameter(aCmdLineString : String; var aR C : Integer) : TStringList;320 FUNCTION splitCmdLineParameter(aCmdLineString : String; var aResult : TStringList) : integer; 310 321 CONST 311 322 STATE_BEFORE = 0; … … 319 330 tmpState : INTEGER; 320 331 tmpCurrentCommand : String; 321 tmpResult : TStringList;322 332 323 333 BEGIN 324 aRC := SUCCESS; 325 tmpResult := TStringList.Create; 334 result := SUCCESS; 335 aResult.Clear; 336 326 337 tmpState := 0; 327 338 tmpCurrentCommand := ''; … … 337 348 STATE_INSIDE : 338 349 begin 339 tmpResult.add(tmpCurrentCommand);350 aResult.add(tmpCurrentCommand); 340 351 tmpCurrentCommand := ''; 341 352 tmpState := STATE_BEFORE; … … 343 354 STATE_INSIDE_QUOTED_START_QUOTE : 344 355 begin 345 tmpResult.add(tmpCurrentCommand);356 aResult.add(tmpCurrentCommand); 346 357 tmpCurrentCommand := ''; 347 358 tmpState := STATE_BEFORE; … … 409 420 STATE_INSIDE : 410 421 begin 411 tmpResult.add(tmpCurrentCommand);422 aResult.add(tmpCurrentCommand); 412 423 end; 413 424 STATE_INSIDE_QUOTED_START_QUOTE : 414 425 begin 415 tmpResult.add(tmpCurrentCommand);426 aResult.add(tmpCurrentCommand); 416 427 end; 417 428 ELSE 418 429 begin 419 aRC:= ERROR_UNMATCHED_QUOTE;420 tmpResult.add(tmpCurrentCommand);430 result := ERROR_UNMATCHED_QUOTE; 431 aResult.add(tmpCurrentCommand); 421 432 end; 422 433 end; 423 splitCmdLineParameter:= tmpResult;424 434 END; 425 435 … … 509 519 end; 510 520 521 511 522 END. -
trunk/NewView/MainForm.pas
r18 r25 16 16 // library 17 17 ACLString, SharedMemoryUnit, ACLLanguageUnit, GenericThread, 18 CmdLineParameterUnit, 19 18 20 // custom components 19 21 SplitBar, Outline2, RichTextView, Coolbar2, … … 862 864 T: TTopic; 863 865 ResourceIDs: TList; 864 Level: longint;865 866 ImageOffsets: TList; 866 867 ImageOffset: longint; … … 1900 1901 TotalTopics: longint; 1901 1902 TotalTopicIndex: longint; 1902 1903 Topic: TTopic;1904 1903 begin 1905 1904 PrintSingle := nil; … … 2218 2217 var 2219 2218 i: integer; 2219 tmpCmdLine: String; 2220 tmpSplittedCmdLine : TStringList; 2221 tmpRc : Integer; 2222 tmpWindowPosition : TWindowPosition; 2220 2223 Begin 2221 2224 with InformationForm.InformationMemo do 2222 2225 begin 2226 tmpCmdLine := nativeOS2GetCmdLineParameter; 2227 tmpSplittedCmdLine := TStringList.Create; 2228 2223 2229 Lines.Clear; 2224 Lines.Add( ParameterCountLabel2225 + IntToStr( ParamCount ));2226 for i := 1 to ParamCountdo2230 Lines.Add(ParameterCountLabel +IntToStr(tmpSplittedCmdLine.count)); 2231 tmpRc := splitCmdLineParameter(tmpCmdLine, tmpSplittedCmdLine); 2232 for i := 0 to tmpSplittedCmdLine.Count -1 do 2227 2233 Lines.Add( ' ' 2228 2234 + IntToStr( i ) 2229 2235 + ' [' 2230 + ParamStr( i )2236 + tmpSplittedCmdLine[i] 2231 2237 + ']' ); 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 2232 2264 end; 2233 2265 … … 2350 2382 FileIndex: longint; 2351 2383 HelpFile: THelpFile; 2352 Dummy: TNode;2353 2384 Begin 2354 2385 EnableControls; … … 2357 2388 begin 2358 2389 // not really feasible to load contents here, as we rely 2359 // on it for many things 2390 // on it for many things 2360 2391 ContentsOutline.Focus; 2361 2392 end; … … 3619 3650 Settings.MRUList.Destroy; 3620 3651 3621 Parameters.FilenamesParam.Destroy; 3652 // TODO rbri maybe we have to do this 3653 // Parameters.FilenamesParam.Destroy; 3622 3654 3623 3655 if g_CurrentLanguageFile <> nil then … … 3763 3795 3764 3796 Procedure TMainForm.MainFormOnCreate (Sender: TObject); 3797 var 3798 tmpCmdLine: String; 3799 tmpSplittedCmdLine : TStringList; 3800 tmpRc : Integer; 3765 3801 Begin 3766 3802 ProfileEvent( 'MainFormOnCreate' ); … … 3774 3810 GlobalFilelist := TGlobalFilelist.Create; 3775 3811 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; 3778 3819 RegisterForLanguages( OnLanguageEvent ); 3779 3820 … … 3849 3890 ProfileEvent( 'Loading language' ); 3850 3891 3851 if Parameters.Language <> '' then3852 LoadAutoLanguage( 'newview', Parameters.Language )3892 if CmdLineParameters.getLanguage <> '' then 3893 LoadAutoLanguage( 'newview', CmdLineParameters.getLanguage ) 3853 3894 else 3854 3895 LoadDefaultLanguage( 'newview' ); … … 3881 3922 ProfileEvent( 'OnCreate done' ); 3882 3923 3883 if Parameters.SetPositionthen3924 if CmdLineParameters.getWindowPositionFlag then 3884 3925 begin 3885 3926 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, 3890 3931 false ); 3891 3932 end; … … 3973 4014 Procedure TMainForm.ClearHelpManager; 3974 4015 Begin 3975 if not Parameters.IsHelpManagerthen4016 if not CmdLineParameters.getHelpManagerFlag then 3976 4017 exit; 3977 4018 … … 3979 4020 PostHelpManagerMessage( NHM_FORGET_VIEWER, 0, 0 ); 3980 4021 3981 Parameters.IsHelpManager := false;4022 CmdLineParameters.setHelpManagerFlag(false); 3982 4023 3983 4024 HelpManagerWindows.Clear; … … 3990 4031 ProfileEvent( 'MainFormOnShow' ); 3991 4032 3992 if Parameters.OwnerWindow <> NULLHANDLE then4033 if CmdLineParameters.getOwnerWindow <> NULLHANDLE then 3993 4034 begin 3994 4035 ProfileEvent( 'Setting owner: ' 3995 + IntToStr( Parameters.OwnerWindow ) );4036 + IntToStr( CmdLineParameters.getOwnerWindow ) ); 3996 4037 WinSetOwner( Frame.Handle, 3997 Parameters.OwnerWindow );3998 3999 end; 4000 4001 if Parameters.IsHelpManagerthen4038 CmdLineParameters.getOwnerWindow ); 4039 4040 end; 4041 4042 if CmdLineParameters.getHelpManagerFlag then 4002 4043 begin 4003 4044 ProfileEvent( ' Help Manager Title: ' … … 4104 4145 ProfileEvent( 'WMOpened: SetLayout' ); 4105 4146 4106 if Parameters.IsHelpManagerthen4147 if CmdLineParameters.getHelpManagerFlag then 4107 4148 FShowLeftPanel := Settings.ShowLeftPanel_Help 4108 4149 else … … 4123 4164 Update; 4124 4165 4125 if not Parameters.IsHelpManagerthen4166 if not CmdLineParameters.getHelpManagerFlag then 4126 4167 begin 4127 4168 ProfileEvent( 'Check environment vars' ); 4128 4169 CheckEnvironmentVars; 4129 4170 4130 if Parameters.ShowUsageFlag then4171 if CmdLineParameters.getShowUsageFlag then 4131 4172 begin 4132 4173 ProfileEvent( 'Showing usage' ); … … 4136 4177 end; 4137 4178 4138 HelpManagerWindows.Add( pointer( Parameters.HelpManagerWindow ) );4139 4140 if Parameters.FilenamesParam.Length> 0 then4179 HelpManagerWindows.Add( pointer( CmdLineParameters.getHelpManagerWindow ) ); 4180 4181 if length(CmdLineParameters.getFileNames) > 0 then 4141 4182 begin 4142 4183 // open specified files 4143 4184 Filenames := TStringList.Create; 4144 4185 4145 AStringToList( Parameters.FilenamesParam, Filenames, '+' ); 4186 // TODO rbri remove type conversion 4187 StringToList(cmdLineParameters.getFileNames, Filenames, '+' ); 4146 4188 4147 4189 ProfileEvent( 'Call OpenFiles' ); 4148 4190 4149 4191 OpenFirstTopic := true; 4150 if ( Parameters.TopicParam<> '' )4151 or Parameters.SearchFlag then4192 if ( CmdLineParameters.getTopics <> '' ) 4193 or CmdLineParameters.getSearchTextFlag then 4152 4194 // if we're going to search, don't open first topic 4153 4195 OpenFirstTopic := false; 4154 4196 4155 if Parameters.IsHelpManagerthen4197 if CmdLineParameters.getHelpManagerFlag then 4156 4198 // don't open first topic if we're online help 4157 4199 // in case we are wanting to show a specific topic … … 4160 4202 4161 4203 OpenFiles( Filenames, 4162 Parameters.WindowTitle,4204 CmdLineParameters.getWindowTitle, 4163 4205 OpenFirstTopic ); 4164 4206 4165 4207 Filenames.Destroy; 4166 4208 4167 if Parameters.TopicParam<> '' then4209 if CmdLineParameters.getTopics <> '' then 4168 4210 begin 4169 4211 // search in contents only! 4170 4212 ProfileEvent( 'Do startup topic search' ); 4171 4213 4172 StartupTopicSearch( Parameters.TopicParam);4214 StartupTopicSearch( CmdLineParameters.getTopics ); 4173 4215 end 4174 else if Parameters.SearchFlag then4216 else if CmdLineParameters.getSearchTextFlag then 4175 4217 begin 4176 4218 // search in specified files … … 4178 4220 DisplaySearch; 4179 4221 4180 SearchFor( Parameters.SearchText );4222 SearchFor( CmdLineParameters.getSearchText ); 4181 4223 end; 4182 4224 end; 4183 4225 4184 if Parameters.GlobalSearchFlag then4226 if CmdLineParameters.getGlobalSearchTextFlag then 4185 4227 begin 4186 4228 // 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 ) then4229 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 4193 4235 begin 4194 4236 // user hasn't requested any particular file … … 4213 4255 ProfileEvent( 'Open finished' ); 4214 4256 4215 if Parameters.IsHelpManagerthen4257 if CmdLineParameters.getHelpManagerFlag then 4216 4258 begin 4217 4259 // Tell helpmanager(s) our window handle … … 4757 4799 begin 4758 4800 SearchResultsListBox.Items.Add( NoSearchMatchesMsg 4759 + ': ' 4801 + ': ' 4760 4802 + SearchText ); 4761 4803 RefreshWindows( Windows ); // update to remove old highlights … … 6663 6705 FirstContentsNode ); 6664 6706 6665 if Parameters.IsHelpManagerthen6707 if CmdLineParameters.getHelpManagerFlag then 6666 6708 ShowLeftPanel := Settings.ShowLeftPanel_Help 6667 6709 else -
trunk/NewView/NewViewTests.pas
r23 r25 96 96 writeln('CmdLineParameterUnit Tests ''' + nativeOS2GetCmdLineParameter + ''''); 97 97 98 tmpResult := splitCmdLineParameter('', tmpRC); 98 tmpResult := TStringList.Create; 99 tmpRC := splitCmdLineParameter('', tmpResult); 99 100 assertEqualsInt('CmdLine split empy string', 0, tmpRC); 100 101 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); 103 106 assertEqualsInt('CmdLine split single string', 0, tmpRC); 104 107 assertEqualsInt('CmdLine split single string', 1, tmpResult.Count); 105 108 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); 108 113 assertEqualsInt('CmdLine split single string with leading blank', 0, tmpRC); 109 114 assertEqualsInt('CmdLine split single string with leading blank', 1, tmpResult.Count); 110 115 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); 113 120 assertEqualsInt('CmdLine split empy string', 0, tmpRC); 114 121 assertEqualsInt('CmdLine split many strings', 3, tmpResult.Count); … … 116 123 assertEqualsString('CmdLine split many strings', 'def', tmpResult[1]); 117 124 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); 120 129 assertEqualsInt('CmdLine split quoted (1)', 0, tmpRC); 121 130 assertEqualsInt('CmdLine split quoted (1)', 1, tmpResult.Count); 122 131 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); 125 136 assertEqualsInt('CmdLine split quoted (2)', 0, tmpRC); 126 137 assertEqualsInt('CmdLine split quoted (2)', 1, tmpResult.Count); 127 138 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); 130 143 assertEqualsInt('CmdLine split quoted (3)', 0, tmpRC); 131 144 assertEqualsInt('CmdLine split quoted (3)', 1, tmpResult.Count); 132 145 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); 135 150 assertEqualsInt('CmdLine split quoted (4)', 0, tmpRC); 136 151 assertEqualsInt('CmdLine split quoted (4)', 1, tmpResult.Count); 137 152 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); 140 157 assertEqualsInt('CmdLine split quoted (5)', 0, tmpRC); 141 158 assertEqualsInt('CmdLine split quoted (5)', 2, tmpResult.Count); 142 159 assertEqualsString('CmdLine split quoted (5)', 'ababc"def', tmpResult[0]); 143 160 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); 146 165 assertEqualsInt('CmdLine split quoted (6)', -1, tmpRC); 147 166 assertEqualsInt('CmdLine split quoted (6)', 2, tmpResult.Count); 148 167 assertEqualsString('CmdLine split quoted (6)', 'ababc"def', tmpResult[0]); 149 168 assertEqualsString('CmdLine split quoted (6)', 'ghi', tmpResult[1]); 169 tmpResult.Destroy; 150 170 151 171 // parser Tests … … 510 530 tmpCmdLineParameters := TCmdLineParameters.Create; 511 531 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 514 535 END; 515 536 -
trunk/NewView/StartupUnit.pas
r18 r25 15 15 ACLString, 16 16 GlobalFilelistUnit, 17 SharedMemoryUnit; 17 SharedMemoryUnit, 18 CmdLineParameterUnit; 18 19 19 20 const 20 21 OWN_HELP_MARKER = '[NVHELP]'; 21 22 22 type23 TWindowPosition = record24 Left: longint;25 Bottom: longint;26 Width: longint;27 Height: longint;28 end;29 30 TCommandLineParameters = record31 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 windows47 48 Procedure ParseCommandLineParameters;49 23 50 24 function AccessSharedMemory: TSuballocatedSharedMemory; … … 67 41 68 42 var 69 Parameters: TCommandLineParameters;43 CmdLineParameters: TCmdLineParameters; 70 44 SharedMemory: TSubAllocatedSharedMemory; 71 45 GlobalFilelist: TGlobalFilelist; … … 74 48 75 49 uses 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, 79 58 HelpManagerUnit; 80 59 … … 251 230 end; 252 231 253 // Parse command line parameters newview was launched with.254 // Store them into the Parameters. variables for later processing.255 Procedure ParseCommandLineParameters;256 var257 ParamIndex: longint;258 Param: string;259 ParamValue: string;260 begin261 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 do276 begin277 Param := ParamStr( ParamIndex );278 if MatchFlagParam( Param, '?' )279 or MatchFlagParam( Param, 'H' )280 or MatchFlagParam( Param, 'HELP' ) then281 begin282 Parameters.ShowUsageFlag := true283 end284 else if MatchValueParam( Param, 'LANG', Parameters.Language ) then285 begin286 end287 else if MatchValueParam( Param, 'G', Parameters.GlobalSearchText ) then288 begin289 Parameters.GlobalSearchFlag := true;290 end291 else if MatchValueParam( Param, 'S', Parameters.SearchText ) then292 begin293 Parameters.SearchFlag := true;294 end295 else if MatchValueParam( Param, 'HM', ParamValue ) then296 begin297 try298 Parameters.HelpManagerWindow := StrToInt( ParamValue );299 Parameters.IsHelpManager := true;300 except301 // ignore invalid window value302 end;303 end304 else if MatchValueParam( Param, 'OWNER', ParamValue ) then305 begin306 Parameters.OwnerWindow := StrToInt( ParamValue );307 end308 else if MatchValueParam( Param, 'TITLE', ParamValue ) then309 begin310 Parameters.WindowTitle := ParamValue;311 end312 else if MatchFlagParam( Param, 'PROFILE' ) then313 begin314 StartProfile( GetLogFilesDir + 'newview.prf' );315 end316 else if MatchValueParam( Param, 'POS', ParamValue ) then317 begin318 // set window position/size319 if ExtractPositionSpec( ParamValue,320 Parameters.Position ) then321 begin322 Parameters.SetPosition := true;323 end324 else325 begin326 // invalid...327 Parameters.ShowUsageFlag := true;328 end;329 end330 else331 begin332 if Parameters.FilenamesParam.Length = 0 then333 begin334 // filename(s)335 AString_ParamStr( ParamIndex, Parameters.FilenamesParam );336 end337 else338 begin339 // search (topic) parameter... append all remaining thingies340 if Parameters.TopicParam <> '' then341 begin342 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;359 232 360 233 // If another instance already has the files open … … 371 244 Result := NULLHANDLE; 372 245 373 if Parameters.FilenamesParam.Length= 0 then246 if length(CmdLineParameters.getFileNames) = 0 then 374 247 // not loading files; nothing to check 375 248 exit; … … 378 251 Filenames := TStringList.Create; 379 252 380 AStringToList( Parameters.FilenamesParam, FileItems, '+' );253 StringToList(cmdLineParameters.getFileNames, FileItems, '+' ); 381 254 TranslateIPFEnvironmentVars( FileItems, FileNames ); 382 255 … … 446 319 function Startup: boolean; 447 320 var 321 tmpCmdLine: String; 322 tmpSplittedCmdLine : TStringList; 323 tmpRc : Integer; 324 448 325 ExistingWindow: HWND; 449 326 begin … … 455 332 456 333 // 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; 458 342 459 343 ExistingWindow := FindExistingWindow; … … 466 350 // destroy global list - nobody else will 467 351 GlobalFilelist.Destroy; 468 Parameters.FilenamesParam.Destroy; 352 // TODO rbri maybe we need the next line 353 // Parameters.FilenamesParam.Destroy; 469 354 470 355 WinSetFocus( HWND_DESKTOP, ExistingWindow ); 471 356 472 if Parameters.TopicParam<> '' then357 if CmdLineParameters.getTopics <> '' then 473 358 begin 474 359 PostNewViewTextMessage( ExistingWindow, 475 360 NHM_SEARCH, 476 Parameters.TopicParam);477 end; 478 479 if Parameters.GlobalSearchFlag then361 CmdLineParameters.getTopics); 362 end; 363 364 if CmdLineParameters.getGlobalSearchTextFlag then 480 365 begin 481 366 PostNewViewTextMessage( ExistingWindow, 482 367 NHM_GLOBAL_SEARCH, 483 Parameters.GlobalSearchText );484 end; 485 486 if Parameters.ShowUsageFlag then368 CmdLineParameters.getGlobalSearchText ); 369 end; 370 371 if CmdLineParameters.getShowUsageFlag then 487 372 begin 488 373 WinPostMsg( ExistingWindow, … … 492 377 end; 493 378 494 if Parameters.IsHelpManagerthen379 if CmdLineParameters.getHelpManagerFlag then 495 380 begin 496 381 // tell the new help manager instance to talk to the 497 382 // other viewer 498 WinPostMsg( Parameters.HelpManagerWindow,383 WinPostMsg( CmdLineParameters.getHelpManagerWindow, 499 384 NHM_VIEWER_READY, 500 385 ExistingWindow,
Note:
See TracChangeset
for help on using the changeset viewer.