| 1 | Unit CmdLineParameterUnit;
|
|---|
| 2 |
|
|---|
| 3 | // NewView - a new OS/2 Help Viewer
|
|---|
| 4 | // Copyright 2006 Ronald Brill (rbri at rbri dot de)
|
|---|
| 5 | // This software is released under the GNU Public License - see readme.txt
|
|---|
| 6 |
|
|---|
| 7 | // Helper functions to address the command line parameters newview
|
|---|
| 8 | // is started with
|
|---|
| 9 |
|
|---|
| 10 | Interface
|
|---|
| 11 |
|
|---|
| 12 | uses
|
|---|
| 13 | Os2Def,
|
|---|
| 14 | BseTib,
|
|---|
| 15 | BseDos,
|
|---|
| 16 | SysUtils,
|
|---|
| 17 | Classes,
|
|---|
| 18 | PMWIN,
|
|---|
| 19 | StringUtilsUnit,
|
|---|
| 20 | DebugUnit;
|
|---|
| 21 |
|
|---|
| 22 | CONST
|
|---|
| 23 | SUCCESS = 0;
|
|---|
| 24 | ERROR_UNMATCHED_QUOTE = -1;
|
|---|
| 25 |
|
|---|
| 26 | TYPE EParsingFailed=CLASS(Exception);
|
|---|
| 27 |
|
|---|
| 28 | TYPE
|
|---|
| 29 | TWindowPosition = record
|
|---|
| 30 | left: longint;
|
|---|
| 31 | bottom: longint;
|
|---|
| 32 | width: longint;
|
|---|
| 33 | height: longint;
|
|---|
| 34 | end;
|
|---|
| 35 | TYPE
|
|---|
| 36 | TCmdLineParameters = class
|
|---|
| 37 | private
|
|---|
| 38 | commandLine : String;
|
|---|
| 39 | showUsageFlag : boolean;
|
|---|
| 40 | searchFlag : boolean;
|
|---|
| 41 | globalSearchFlag : boolean;
|
|---|
| 42 | language : string;
|
|---|
| 43 | helpManagerFlag : boolean;
|
|---|
| 44 | helpManagerWindow : integer;
|
|---|
| 45 | windowPositionFlag: boolean;
|
|---|
| 46 | windowPosition: TWindowPosition;
|
|---|
| 47 | ownerWindow : integer;
|
|---|
| 48 | windowTitle : string;
|
|---|
| 49 | fileNames : string;
|
|---|
| 50 | fileNamesRaw : string;
|
|---|
| 51 | searchText : string;
|
|---|
| 52 |
|
|---|
| 53 | // FUNCTION ReadNextPart(const aParseString : String; const aSetOfDelimiterChars : TSetOfChars): String;
|
|---|
| 54 | FUNCTION handleSwitchWithValue(const aSwitchString : String; const aSwitch : String; var aValue : String) : Boolean;
|
|---|
| 55 | PROCEDURE parseSwitch(aSwitchString : String);
|
|---|
| 56 | PROPERTY getFileNames : string read fileNames;
|
|---|
| 57 | PROPERTY getSearchText : string read searchText;
|
|---|
| 58 |
|
|---|
| 59 | public
|
|---|
| 60 | PROPERTY getCommandLine : String read commandLine;
|
|---|
| 61 | PROPERTY getShowUsageFlag : boolean read showUsageFlag;
|
|---|
| 62 | PROPERTY getSearchFlag : boolean read searchFlag;
|
|---|
| 63 | PROPERTY getGlobalSearchFlag : boolean read globalSearchFlag;
|
|---|
| 64 | PROPERTY getLanguage : string read language;
|
|---|
| 65 | PROPERTY getHelpManagerFlag : boolean read helpManagerFlag;
|
|---|
| 66 | FUNCTION setHelpManagerFlag(aNewValue : boolean) : boolean;
|
|---|
| 67 | PROPERTY getHelpManagerWindow : integer read helpManagerWindow;
|
|---|
| 68 | PROPERTY getWindowPositionFlag : boolean read windowPositionFlag;
|
|---|
| 69 | PROPERTY getWindowPosition : TWindowPosition read windowPosition;
|
|---|
| 70 | PROPERTY getOwnerWindow : integer read ownerWindow;
|
|---|
| 71 | PROPERTY getWindowTitle : string read windowTitle;
|
|---|
| 72 | PROPERTY getFileNamesRaw : string read fileNamesRaw;
|
|---|
| 73 |
|
|---|
| 74 | PROCEDURE writeDetailsTo(aStrings : TStrings);
|
|---|
| 75 | PROCEDURE parseCmdLine(aCmdLineString : String);
|
|---|
| 76 |
|
|---|
| 77 | FUNCTION getInterpretedFileNames: String;
|
|---|
| 78 | FUNCTION getInterpretedSearchText: String;
|
|---|
| 79 | end;
|
|---|
| 80 |
|
|---|
| 81 | FUNCTION getOwnHelpFileName: String;
|
|---|
| 82 |
|
|---|
| 83 | // returns a string containing the whole
|
|---|
| 84 | // command line parametes
|
|---|
| 85 | FUNCTION nativeOS2GetCmdLineParameter : String;
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 | Implementation
|
|---|
| 89 | uses
|
|---|
| 90 | ACLFileUtility;
|
|---|
| 91 |
|
|---|
| 92 | PROCEDURE TCmdLineParameters.writeDetailsTo(aStrings : TStrings);
|
|---|
| 93 | var
|
|---|
| 94 | tmpWindowPosition : TWindowPosition;
|
|---|
| 95 | begin
|
|---|
| 96 | aStrings.Add('''' + getCommandLine + '''');
|
|---|
| 97 | aStrings.Add('parsed infos:');
|
|---|
| 98 |
|
|---|
| 99 | aStrings.Add('getShowUsageFlag: ' + boolToStr(getShowUsageFlag));
|
|---|
| 100 | aStrings.Add('getSearchFlag: ' + boolToStr(getSearchFlag));
|
|---|
| 101 | aStrings.Add('getSearchText: ' + getSearchText);
|
|---|
| 102 | aStrings.Add('getGlobalSearchFlag: ' + boolToStr(getGlobalSearchFlag));
|
|---|
| 103 | aStrings.Add('getLanguage: ' + getLanguage);
|
|---|
| 104 | aStrings.Add('getHelpManagerFlag: ' + boolToStr(getHelpManagerFlag));
|
|---|
| 105 | aStrings.Add('getHelpManagerFlag: ' + boolToStr(getHelpManagerFlag));
|
|---|
| 106 | aStrings.Add('getHelpManagerWindow: ' + intToStr(getHelpManagerWindow));
|
|---|
| 107 | aStrings.Add('getWindowPositionFlag: ' + boolToStr(getWindowPositionFlag));
|
|---|
| 108 | aStrings.Add('getFileNames: ' + getFileNames);
|
|---|
| 109 | aStrings.Add('getInterpretedSearchText: ' + getInterpretedSearchText);
|
|---|
| 110 | aStrings.Add('getInterpretedFileNames: ' + getInterpretedFileNames);
|
|---|
| 111 |
|
|---|
| 112 | tmpWindowPosition := getWindowPosition;
|
|---|
| 113 | aStrings.Add('getWindowPosition: '
|
|---|
| 114 | + intToStr(tmpWindowPosition.left) + ', '
|
|---|
| 115 | + intToStr(tmpWindowPosition.bottom) + ', '
|
|---|
| 116 | + intToStr(tmpWindowPosition.width) + ', '
|
|---|
| 117 | + intToStr(tmpWindowPosition.height)
|
|---|
| 118 | );
|
|---|
| 119 | aStrings.Add('getOwnerWindow: ' + intToStr(getOwnerWindow));
|
|---|
| 120 | aStrings.Add('getWindowTitle: ' + getWindowTitle);
|
|---|
| 121 | end;
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | Function TCmdLineParameters.getInterpretedFileNames: String;
|
|---|
| 125 | var
|
|---|
| 126 | tmpOwnHelpFileName : String;
|
|---|
| 127 | begin
|
|---|
| 128 | result := getFileNames;
|
|---|
| 129 |
|
|---|
| 130 | if getGlobalSearchFlag
|
|---|
| 131 | AND (getSearchText = '')
|
|---|
| 132 | then
|
|---|
| 133 | begin
|
|---|
| 134 | result := '';
|
|---|
| 135 | exit;
|
|---|
| 136 | end;
|
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 | tmpOwnHelpFileName := FindDefaultLanguageHelpFile('NewView');
|
|---|
| 140 | if (result = '') AND
|
|---|
| 141 | FileExists(tmpOwnHelpFileName)
|
|---|
| 142 | then
|
|---|
| 143 | result := tmpOwnHelpFileName;
|
|---|
| 144 | end;
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 | Function TCmdLineParameters.getInterpretedSearchText: String;
|
|---|
| 148 | begin
|
|---|
| 149 | result := getSearchText;
|
|---|
| 150 |
|
|---|
| 151 | if getGlobalSearchFlag
|
|---|
| 152 | AND (result = '')
|
|---|
| 153 | then
|
|---|
| 154 | result := getFileNamesRaw;
|
|---|
| 155 |
|
|---|
| 156 | if not getGlobalSearchFlag
|
|---|
| 157 | AND (not getSearchFlag)
|
|---|
| 158 | then
|
|---|
| 159 | begin
|
|---|
| 160 | result := StrTrim(result);
|
|---|
| 161 | result := StrTrimChars(result, ['"']);
|
|---|
| 162 | end;
|
|---|
| 163 |
|
|---|
| 164 | end;
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 | Function TCmdLineParameters.setHelpManagerFlag(aNewValue : boolean) : boolean;
|
|---|
| 168 | begin
|
|---|
| 169 | helpManagerFlag := aNewValue;
|
|---|
| 170 | result := helpManagerFlag;
|
|---|
| 171 | end;
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 | Procedure TCmdLineParameters.parseCmdLine(aCmdLineString : String);
|
|---|
| 175 | var
|
|---|
| 176 | tmpState : (WHITESPACE, QUOTE, SWITCH, FILENAME, TEXT);
|
|---|
| 177 | tmpCurrentParsePosition : integer;
|
|---|
| 178 | tmpQuoted : boolean;
|
|---|
| 179 | tmpCurrentChar : char;
|
|---|
| 180 | tmpWhitespace : String;
|
|---|
| 181 | tmpQuote : String;
|
|---|
| 182 | tmpSwitch : String;
|
|---|
| 183 | begin
|
|---|
| 184 | LogEvent(LogStartup, 'ParseCommandLine: "' + aCmdLineString + '"');
|
|---|
| 185 |
|
|---|
| 186 | // store the original string for debugging
|
|---|
| 187 | commandLine := aCmdLineString;
|
|---|
| 188 |
|
|---|
| 189 | // reset the whole object
|
|---|
| 190 | showUsageFlag := false;
|
|---|
| 191 | searchFlag := false;
|
|---|
| 192 | globalSearchFlag := false;
|
|---|
| 193 | language := '';
|
|---|
| 194 | helpManagerFlag := false;
|
|---|
| 195 | helpManagerWindow := 0;
|
|---|
| 196 | windowPositionFlag := false;
|
|---|
| 197 | ownerWindow := 0;
|
|---|
| 198 | windowTitle := '';
|
|---|
| 199 | searchText := '';
|
|---|
| 200 | fileNames := '';
|
|---|
| 201 | fileNamesRaw := '';
|
|---|
| 202 |
|
|---|
| 203 | try
|
|---|
| 204 | // start parsing
|
|---|
| 205 | tmpState := WHITESPACE;
|
|---|
| 206 | tmpWhitespace := '';
|
|---|
| 207 | tmpSwitch := '';
|
|---|
| 208 | tmpQuote := '';
|
|---|
| 209 | tmpQuoted := false;
|
|---|
| 210 | tmpCurrentParsePosition := 1;
|
|---|
| 211 | while tmpCurrentParsePosition <= length(aCmdLineString) do
|
|---|
| 212 | begin
|
|---|
| 213 | tmpCurrentChar := aCmdLineString[tmpCurrentParsePosition];
|
|---|
| 214 |
|
|---|
| 215 | Case tmpCurrentChar of
|
|---|
| 216 | ' ' :
|
|---|
| 217 | begin
|
|---|
| 218 | Case tmpState of
|
|---|
| 219 |
|
|---|
| 220 | WHITESPACE :
|
|---|
| 221 | begin
|
|---|
| 222 | tmpWhitespace := tmpWhitespace + tmpCurrentChar;
|
|---|
| 223 | end;
|
|---|
| 224 |
|
|---|
| 225 | QUOTE :
|
|---|
| 226 | begin
|
|---|
| 227 | tmpQuote := tmpQuote + tmpCurrentChar;
|
|---|
| 228 | end;
|
|---|
| 229 |
|
|---|
| 230 | SWITCH :
|
|---|
| 231 | begin
|
|---|
| 232 | if tmpQuoted then
|
|---|
| 233 | begin
|
|---|
| 234 | tmpSwitch := tmpSwitch + tmpCurrentChar;
|
|---|
| 235 | end
|
|---|
| 236 | else
|
|---|
| 237 | begin
|
|---|
| 238 | parseSwitch(tmpSwitch);
|
|---|
| 239 | tmpState := WHITESPACE;
|
|---|
| 240 | tmpWhitespace := tmpCurrentChar;
|
|---|
| 241 | end
|
|---|
| 242 | end;
|
|---|
| 243 |
|
|---|
| 244 | FILENAME :
|
|---|
| 245 | begin
|
|---|
| 246 | if tmpQuoted then
|
|---|
| 247 | begin
|
|---|
| 248 | fileNames := fileNames + tmpCurrentChar;
|
|---|
| 249 | fileNamesRaw := fileNamesRaw + tmpCurrentChar;
|
|---|
| 250 | end
|
|---|
| 251 | else
|
|---|
| 252 | begin
|
|---|
| 253 | tmpState := WHITESPACE;
|
|---|
| 254 | tmpWhitespace := tmpCurrentChar;
|
|---|
| 255 | end
|
|---|
| 256 | end;
|
|---|
| 257 |
|
|---|
| 258 | TEXT :
|
|---|
| 259 | begin
|
|---|
| 260 | if tmpQuoted then
|
|---|
| 261 | begin
|
|---|
| 262 | searchText := searchText + tmpCurrentChar;
|
|---|
| 263 | end
|
|---|
| 264 | else
|
|---|
| 265 | begin
|
|---|
| 266 | tmpState := WHITESPACE;
|
|---|
| 267 | tmpWhitespace := tmpCurrentChar;
|
|---|
| 268 | end
|
|---|
| 269 | end;
|
|---|
| 270 | end;
|
|---|
| 271 | end;
|
|---|
| 272 |
|
|---|
| 273 | '/', '-' :
|
|---|
| 274 | begin
|
|---|
| 275 | Case tmpState of
|
|---|
| 276 | WHITESPACE :
|
|---|
| 277 | begin
|
|---|
| 278 | tmpState := SWITCH;
|
|---|
| 279 | tmpSwitch := '';
|
|---|
| 280 | end;
|
|---|
| 281 |
|
|---|
| 282 | QUOTE :
|
|---|
| 283 | begin
|
|---|
| 284 | tmpState := SWITCH;
|
|---|
| 285 | tmpSwitch := '';
|
|---|
| 286 | end;
|
|---|
| 287 |
|
|---|
| 288 | SWITCH :
|
|---|
| 289 | begin
|
|---|
| 290 | parseSwitch(tmpSwitch);
|
|---|
| 291 | tmpSwitch := '';
|
|---|
| 292 | end;
|
|---|
| 293 |
|
|---|
| 294 | FILENAME :
|
|---|
| 295 | begin
|
|---|
| 296 | fileNames := fileNames + tmpCurrentChar;
|
|---|
| 297 | fileNamesRaw := fileNamesRaw + tmpCurrentChar;
|
|---|
| 298 | end;
|
|---|
| 299 |
|
|---|
| 300 | TEXT :
|
|---|
| 301 | begin
|
|---|
| 302 | searchText := searchText + tmpCurrentChar;
|
|---|
| 303 | end;
|
|---|
| 304 | end;
|
|---|
| 305 | end;
|
|---|
| 306 |
|
|---|
| 307 | '"' :
|
|---|
| 308 | begin
|
|---|
| 309 | if tmpQuoted then
|
|---|
| 310 | begin
|
|---|
| 311 | tmpQuoted := false;
|
|---|
| 312 | Case tmpState of
|
|---|
| 313 | FILENAME :
|
|---|
| 314 | begin
|
|---|
| 315 | fileNamesRaw := fileNamesRaw + tmpCurrentChar;
|
|---|
| 316 | end;
|
|---|
| 317 | end;
|
|---|
| 318 | end
|
|---|
| 319 | else
|
|---|
| 320 | begin
|
|---|
| 321 | Case tmpState of
|
|---|
| 322 | WHITESPACE :
|
|---|
| 323 | begin
|
|---|
| 324 | tmpState := QUOTE;
|
|---|
| 325 | tmpQuote := tmpCurrentChar;
|
|---|
| 326 | end;
|
|---|
| 327 | FILENAME :
|
|---|
| 328 | begin
|
|---|
| 329 | fileNamesRaw := fileNamesRaw + tmpCurrentChar;
|
|---|
| 330 | end;
|
|---|
| 331 | end;
|
|---|
| 332 | tmpQuoted := true;
|
|---|
| 333 | end;
|
|---|
| 334 | end;
|
|---|
| 335 |
|
|---|
| 336 | // any other char
|
|---|
| 337 | else
|
|---|
| 338 | begin
|
|---|
| 339 | Case tmpState of
|
|---|
| 340 |
|
|---|
| 341 | WHITESPACE :
|
|---|
| 342 | begin
|
|---|
| 343 | if length(fileNames) > 0 then
|
|---|
| 344 | begin
|
|---|
| 345 | tmpState := TEXT;
|
|---|
| 346 | searchText := searchText + tmpWhitespace + tmpCurrentChar;
|
|---|
| 347 | end
|
|---|
| 348 | else
|
|---|
| 349 | begin
|
|---|
| 350 | tmpState := FILENAME;
|
|---|
| 351 | fileNames := fileNames + tmpCurrentChar;
|
|---|
| 352 | fileNamesRaw := fileNamesRaw + tmpCurrentChar;
|
|---|
| 353 | end;
|
|---|
| 354 | end;
|
|---|
| 355 |
|
|---|
| 356 | QUOTE :
|
|---|
| 357 | begin
|
|---|
| 358 | if length(fileNames) > 0 then
|
|---|
| 359 | begin
|
|---|
| 360 | tmpState := TEXT;
|
|---|
| 361 | searchText := searchText + tmpWhitespace + tmpCurrentChar;
|
|---|
| 362 | end
|
|---|
| 363 | else
|
|---|
| 364 | begin
|
|---|
| 365 | tmpState := FILENAME;
|
|---|
| 366 | fileNames := fileNames + tmpCurrentChar;
|
|---|
| 367 | fileNamesRaw := fileNamesRaw + tmpQuote + tmpCurrentChar;
|
|---|
| 368 | end;
|
|---|
| 369 | end;
|
|---|
| 370 |
|
|---|
| 371 | SWITCH :
|
|---|
| 372 | begin
|
|---|
| 373 | tmpSwitch := tmpSwitch + tmpCurrentChar;
|
|---|
| 374 | end;
|
|---|
| 375 |
|
|---|
| 376 | FILENAME :
|
|---|
| 377 | begin
|
|---|
| 378 | fileNames := fileNames + tmpCurrentChar;
|
|---|
| 379 | fileNamesRaw := fileNamesRaw + tmpCurrentChar;
|
|---|
| 380 | end;
|
|---|
| 381 |
|
|---|
| 382 | TEXT :
|
|---|
| 383 | begin
|
|---|
| 384 | searchText := searchText + tmpCurrentChar;
|
|---|
| 385 | end;
|
|---|
| 386 | end;
|
|---|
| 387 | end;
|
|---|
| 388 | end;
|
|---|
| 389 | inc(tmpCurrentParsePosition);
|
|---|
| 390 | end;
|
|---|
| 391 |
|
|---|
| 392 | // ok all chars are processed, but maybe we have something to do
|
|---|
| 393 | Case tmpState of
|
|---|
| 394 | SWITCH :
|
|---|
| 395 | begin
|
|---|
| 396 | parseSwitch(tmpSwitch);
|
|---|
| 397 | end;
|
|---|
| 398 | end;
|
|---|
| 399 |
|
|---|
| 400 |
|
|---|
| 401 | // TODO remove interpreted
|
|---|
| 402 |
|
|---|
| 403 | except
|
|---|
| 404 | on e:EParsingFailed do
|
|---|
| 405 | begin
|
|---|
| 406 | showUsageFlag := true;
|
|---|
| 407 | end;
|
|---|
| 408 | end;
|
|---|
| 409 |
|
|---|
| 410 | // remove leading blanks from search text
|
|---|
| 411 | searchText := StrTrim(searchText);
|
|---|
| 412 |
|
|---|
| 413 | LogEvent(LogStartup, 'Parameters parsed');
|
|---|
| 414 | LogEvent(LogStartup, ' Filename(s): "' + fileNames + '"');
|
|---|
| 415 | LogEvent(LogStartup, ' Search Text: "' + searchText + '"');
|
|---|
| 416 | end;
|
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 | {
|
|---|
| 420 | FUNCTION TCmdLineParameters.ReadNextPart(const aParseString : String; const aSetOfDelimiterChars : TSetOfChars): String;
|
|---|
| 421 | VAR
|
|---|
| 422 | i : integer;
|
|---|
| 423 | tmpChar : char;
|
|---|
| 424 | BEGIN
|
|---|
| 425 | result := '';
|
|---|
| 426 | for i:= currentParsePosition to length(aParseString) do
|
|---|
| 427 | begin
|
|---|
| 428 | tmpChar := aParseString[i];
|
|---|
| 429 | if tmpChar in aSetOfDelimiterChars then
|
|---|
| 430 | begin
|
|---|
| 431 | i := length(aParseString); // stop parsing
|
|---|
| 432 | end
|
|---|
| 433 | else
|
|---|
| 434 | begin
|
|---|
| 435 | result := result + tmpChar;
|
|---|
| 436 | end;
|
|---|
| 437 | end;
|
|---|
| 438 | END;
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 |
|
|---|
| 442 | Function TCmdLineParameters.handleSwitchWithValue(const aSwitchString : String; const aSwitch : String; var aValue : String) : Boolean;
|
|---|
| 443 | var
|
|---|
| 444 | tmpText : String;
|
|---|
| 445 | tmpValueStartPos : integer;
|
|---|
| 446 | tmpSwitchLength : integer;
|
|---|
| 447 | begin
|
|---|
| 448 | tmpSwitchLength := Length(aSwitch);
|
|---|
| 449 | tmpText := copy(aSwitchString, 1, tmpSwitchLength);
|
|---|
| 450 | tmpText := lowercase(tmpText);
|
|---|
| 451 |
|
|---|
| 452 | if (lowercase(aSwitch) = tmpText) then
|
|---|
| 453 | begin
|
|---|
| 454 | tmpValueStartPos := tmpSwitchLength;
|
|---|
| 455 | inc(tmpValueStartPos);
|
|---|
| 456 | if aSwitchString[tmpValueStartPos] = ':' then
|
|---|
| 457 | begin
|
|---|
| 458 | inc(tmpValueStartPos);
|
|---|
| 459 | end;
|
|---|
| 460 |
|
|---|
| 461 | aValue := copy(aSwitchString, tmpValueStartPos, Length(aSwitchString) - tmpValueStartPos+ 1);
|
|---|
| 462 | result := true;
|
|---|
| 463 | exit;
|
|---|
| 464 | end;
|
|---|
| 465 | result := false;
|
|---|
| 466 | end;
|
|---|
| 467 |
|
|---|
| 468 |
|
|---|
| 469 | Function ParseWindowPositionPart(const aPart: String; const aScreenDimension: longint): longint;
|
|---|
| 470 | Var
|
|---|
| 471 | tmpPart : String;
|
|---|
| 472 | Begin
|
|---|
| 473 | if aPart = '' then
|
|---|
| 474 | raise EParsingFailed.Create('Missing position element');
|
|---|
| 475 |
|
|---|
| 476 | if StrEndsWithIgnoringCase(aPart, 'P') then
|
|---|
| 477 | begin
|
|---|
| 478 | tmpPart := copy(aPart, 1, length(aPart)-1);
|
|---|
| 479 | if tmpPart = '' then
|
|---|
| 480 | raise EParsingFailed.Create('Missing position element');
|
|---|
| 481 |
|
|---|
| 482 | Result := StrToInt(tmpPart);
|
|---|
| 483 | if Result < 0 then
|
|---|
| 484 | Result := 0;
|
|---|
| 485 | if Result > 100 then
|
|---|
| 486 | Result := 100;
|
|---|
| 487 | Result := Round(Result / 100 * aScreenDimension);
|
|---|
| 488 | end
|
|---|
| 489 | else
|
|---|
| 490 | begin
|
|---|
| 491 | Result := StrToInt(aPart);
|
|---|
| 492 | end;
|
|---|
| 493 | end;
|
|---|
| 494 |
|
|---|
| 495 | Function ParseWindowPosition(const aParamValue: String): TWindowPosition;
|
|---|
| 496 | Var
|
|---|
| 497 | tmpParts : TStringList;
|
|---|
| 498 | Begin
|
|---|
| 499 | tmpParts := TStringList.Create;
|
|---|
| 500 | StrExtractStrings(tmpParts, aParamValue, [','], '\');
|
|---|
| 501 |
|
|---|
| 502 | result.Left := ParseWindowPositionPart(tmpParts[0], WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN));
|
|---|
| 503 | result.Bottom := ParseWindowPositionPart(tmpParts[1], WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN));
|
|---|
| 504 |
|
|---|
| 505 | result.Width := ParseWindowPositionPart(tmpParts[2], WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN));
|
|---|
| 506 | if result.Width < 50 then
|
|---|
| 507 | result.Width := 50;
|
|---|
| 508 |
|
|---|
| 509 | result.Height := ParseWindowPositionPart(tmpParts[3], WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN));
|
|---|
| 510 | if result.Height < 50 then
|
|---|
| 511 | result.Height := 50;
|
|---|
| 512 |
|
|---|
| 513 | tmpParts.Destroy;
|
|---|
| 514 | end;
|
|---|
| 515 |
|
|---|
| 516 |
|
|---|
| 517 | Procedure TCmdLineParameters.parseSwitch(aSwitchString : String);
|
|---|
| 518 | var
|
|---|
| 519 | tmpCurrentChar : char;
|
|---|
| 520 | tmpText : String;
|
|---|
| 521 | tmpValue : String;
|
|---|
| 522 | begin
|
|---|
| 523 | // lang
|
|---|
| 524 | if handleSwitchWithValue(aSwitchString, 'lang', tmpValue) then
|
|---|
| 525 | begin
|
|---|
| 526 | language := tmpValue;
|
|---|
| 527 | exit;
|
|---|
| 528 | end;
|
|---|
| 529 |
|
|---|
| 530 | // title
|
|---|
| 531 | if handleSwitchWithValue(aSwitchString, 'title', tmpValue) then
|
|---|
| 532 | begin
|
|---|
| 533 | windowTitle := tmpValue;
|
|---|
| 534 | exit;
|
|---|
| 535 | end;
|
|---|
| 536 |
|
|---|
| 537 | // HM
|
|---|
| 538 | if handleSwitchWithValue(aSwitchString, 'hm', tmpValue) then
|
|---|
| 539 | begin
|
|---|
| 540 | try
|
|---|
| 541 | helpManagerWindow := StrToInt(tmpValue);
|
|---|
| 542 | helpManagerFlag := true;
|
|---|
| 543 | except
|
|---|
| 544 | on e:Exception do
|
|---|
| 545 | begin
|
|---|
| 546 | showUsageFlag := true;
|
|---|
| 547 | end;
|
|---|
| 548 | end;
|
|---|
| 549 | exit;
|
|---|
| 550 | end;
|
|---|
| 551 |
|
|---|
| 552 | // owner
|
|---|
| 553 | if handleSwitchWithValue(aSwitchString, 'owner', tmpValue) then
|
|---|
| 554 | begin
|
|---|
| 555 | try
|
|---|
| 556 | ownerWindow := StrToInt(tmpValue);
|
|---|
| 557 | except
|
|---|
| 558 | on e:Exception do
|
|---|
| 559 | begin
|
|---|
| 560 | showUsageFlag := true;
|
|---|
| 561 | end;
|
|---|
| 562 | end;
|
|---|
| 563 | exit;
|
|---|
| 564 | end;
|
|---|
| 565 |
|
|---|
| 566 | // pos
|
|---|
| 567 | if handleSwitchWithValue(aSwitchString, 'pos', tmpValue) then
|
|---|
| 568 | begin
|
|---|
| 569 | windowPosition := ParseWindowPosition(tmpValue);
|
|---|
| 570 | windowPositionFlag := true;
|
|---|
| 571 | exit;
|
|---|
| 572 | end;
|
|---|
| 573 |
|
|---|
| 574 | // check the next char
|
|---|
| 575 | // TODO check for other invalid chars
|
|---|
| 576 | tmpCurrentChar := aSwitchString[1];
|
|---|
| 577 | Case tmpCurrentChar of
|
|---|
| 578 | 'h', 'H', '?' :
|
|---|
| 579 | begin
|
|---|
| 580 | showUsageFlag := true;
|
|---|
| 581 |
|
|---|
| 582 | // check for 'help'
|
|---|
| 583 | // tmpText := copy(aCmdLineString, 2, 3);
|
|---|
| 584 | // tmpText := lowercase(tmpText);
|
|---|
| 585 |
|
|---|
| 586 | // if ('elp' = tmpText) then
|
|---|
| 587 | // begin
|
|---|
| 588 | // end;
|
|---|
| 589 | end;
|
|---|
| 590 |
|
|---|
| 591 | 's', 'S' :
|
|---|
| 592 | begin
|
|---|
| 593 | searchFlag := true;
|
|---|
| 594 | end;
|
|---|
| 595 |
|
|---|
| 596 | 'g', 'G' :
|
|---|
| 597 | begin
|
|---|
| 598 | globalSearchFlag := true;
|
|---|
| 599 | end;
|
|---|
| 600 |
|
|---|
| 601 | else
|
|---|
| 602 | begin
|
|---|
| 603 | raise EParsingFailed.Create('Unsupported switch');
|
|---|
| 604 | end;
|
|---|
| 605 | end;
|
|---|
| 606 | end;
|
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 | FUNCTION getOwnHelpFileName: String;
|
|---|
| 610 | begin
|
|---|
| 611 | result := FindDefaultLanguageHelpFile('NewView');
|
|---|
| 612 | end;
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 | FUNCTION nativeOS2GetCmdLineParameter : STRING;
|
|---|
| 616 | VAR
|
|---|
| 617 | tmpPtib : PTIB; // thread information block
|
|---|
| 618 | tmpPpib : PPIB; // process information block
|
|---|
| 619 | tmpCmd : PCHAR;
|
|---|
| 620 | tmpResult : PCHAR;
|
|---|
| 621 |
|
|---|
| 622 | BEGIN
|
|---|
| 623 | // ask the system
|
|---|
| 624 | DosGetInfoBlocks(tmpPtib, tmpPpib);
|
|---|
| 625 | tmpCmd := tmpPpib^.pib_pchcmd;
|
|---|
| 626 | // the fist element (null terminated) is the
|
|---|
| 627 | // called command itself
|
|---|
| 628 | // skip to the next null terminated string
|
|---|
| 629 | // these are the parameters
|
|---|
| 630 | tmpResult := tmpCmd + StrLen(tmpCmd) + 1;
|
|---|
| 631 | result := StrPas(tmpResult);
|
|---|
| 632 | END;
|
|---|
| 633 | END.
|
|---|