Ignore:
Timestamp:
Feb 12, 2007, 9:35:45 PM (19 years ago)
Author:
RBRi
Message:

improved debug switch handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/NewView/CmdLineParameterUnit.pas

    r69 r76  
    2121
    2222 CONST
    23      SUCCESS = 0;
    24      ERROR_UNMATCHED_QUOTE = -1;
     23   ENV_DEBUG = 'NEWVIEW_DEBUG';
     24
    2525
    2626 TYPE EParsingFailed=CLASS(Exception);
     
    5151       searchText : string;
    5252
    53 //       FUNCTION ReadNextPart(const aParseString : String; const aSetOfDelimiterChars : TSetOfChars): String;
    5453       FUNCTION handleSwitchWithValue(const aSwitchString : String; const aSwitch : String; var aValue : String) : Boolean;
    5554       PROCEDURE parseSwitch(aSwitchString : String);
     
    8887Implementation
    8988uses
     89  DOS,
    9090  ACLFileUtility;
    9191
     
    160160      result := StrTrimChars(result, ['"']);
    161161    end;
    162 
    163162  end;
    164163
     
    181180    tmpSwitch : String;
    182181  begin
    183      LogEvent(LogStartup, 'ParseCommandLine: "' + aCmdLineString + '"');
    184 
    185      // store the original string for debugging
    186      commandLine := aCmdLineString;
    187 
    188      // reset the whole object
    189      showUsageFlag := false;
    190      searchFlag := false;
    191      globalSearchFlag := false;
    192      language := '';
    193      helpManagerFlag := false;
    194      helpManagerWindow := 0;
    195      windowPositionFlag := false;
    196      ownerWindow := 0;
    197      windowTitle := '';
    198      searchText := '';
    199      fileNames := '';
    200      fileNamesRaw := '';
    201 
    202      try
    203        // start parsing
    204        tmpState := WHITESPACE;
    205        tmpWhitespace := '';
    206        tmpSwitch := '';
    207        tmpQuote := '';
    208        tmpQuoted := false;
    209        tmpCurrentParsePosition := 1;
    210        while tmpCurrentParsePosition <= length(aCmdLineString) do
    211        begin
    212          tmpCurrentChar := aCmdLineString[tmpCurrentParsePosition];
    213 
    214          Case tmpCurrentChar of
    215            ' ' :
    216            begin
    217              Case tmpState of
    218 
    219                WHITESPACE :
    220                begin
    221                  tmpWhitespace := tmpWhitespace + tmpCurrentChar;
    222                end;
    223 
    224                QUOTE :
    225                begin
    226                  tmpQuote := tmpQuote + tmpCurrentChar;
    227                end;
    228 
    229                SWITCH :
    230                begin
    231                  if tmpQuoted then
    232                  begin
    233                    tmpSwitch := tmpSwitch + tmpCurrentChar;
    234                  end
    235                  else
    236                  begin
    237                    parseSwitch(tmpSwitch);
    238                    tmpState := WHITESPACE;
    239                    tmpWhitespace := tmpCurrentChar;
    240                  end
    241                end;
    242 
    243                FILENAME :
    244                begin
    245                  if tmpQuoted then
    246                  begin
    247                    fileNames := fileNames + tmpCurrentChar;
    248                    fileNamesRaw := fileNamesRaw + tmpCurrentChar;
    249                  end
    250                  else
    251                  begin
    252                    tmpState := WHITESPACE;
    253                    tmpWhitespace := tmpCurrentChar;
    254                  end
    255                end;
    256 
    257                TEXT :
    258                begin
    259                  if tmpQuoted then
    260                  begin
    261                    searchText := searchText + tmpCurrentChar;
    262                  end
    263                  else
    264                  begin
    265                    tmpState := WHITESPACE;
    266                    tmpWhitespace := tmpCurrentChar;
    267                  end
    268                end;
    269              end;
    270            end;
    271 
    272            '/', '-' :
    273            begin
    274              Case tmpState of
    275                WHITESPACE :
    276                begin
    277                  tmpState := SWITCH;
    278                  tmpSwitch := '';
    279                end;
    280 
    281                QUOTE :
    282                begin
    283                  tmpState := SWITCH;
    284                  tmpSwitch := '';
    285                end;
    286 
    287                SWITCH :
    288                begin
    289                  parseSwitch(tmpSwitch);
    290                  tmpSwitch := '';
    291                end;
    292 
    293                FILENAME :
    294                begin
    295                  fileNames := fileNames + tmpCurrentChar;
    296                  fileNamesRaw := fileNamesRaw + tmpCurrentChar;
    297                end;
    298 
    299                TEXT :
    300                begin
    301                  searchText := searchText + tmpCurrentChar;
    302                end;
    303              end;
    304            end;
    305 
    306            '"' :
    307            begin
    308              if tmpQuoted then
    309              begin
    310                tmpQuoted := false;
    311                Case tmpState of
    312                  FILENAME :
    313                  begin
    314                    fileNamesRaw := fileNamesRaw + tmpCurrentChar;
    315                  end;
    316                end;
    317              end
    318              else
    319              begin
    320                Case tmpState of
    321                  WHITESPACE :
    322                  begin
    323                    tmpState := QUOTE;
    324                    tmpQuote := tmpCurrentChar;
    325                  end;
    326                  FILENAME :
    327                  begin
    328                    fileNamesRaw := fileNamesRaw + tmpCurrentChar;
    329                  end;
    330                end;
    331                tmpQuoted := true;
    332              end;
    333            end;
    334 
    335            // any other char
    336            else
    337            begin
    338              Case tmpState of
    339 
    340                WHITESPACE :
    341                begin
    342                  if length(fileNames) > 0 then
    343                  begin
    344                    tmpState := TEXT;
    345                    searchText := searchText + tmpWhitespace + tmpCurrentChar;
    346                  end
    347                  else
    348                  begin
    349                    tmpState := FILENAME;
    350                    fileNames := fileNames + tmpCurrentChar;
    351                    fileNamesRaw := fileNamesRaw + tmpCurrentChar;
    352                  end;
    353                end;
    354 
    355                QUOTE :
    356                begin
    357                  if length(fileNames) > 0 then
    358                  begin
    359                    tmpState := TEXT;
    360                    searchText := searchText + tmpWhitespace + tmpCurrentChar;
    361                  end
    362                  else
    363                  begin
    364                    tmpState := FILENAME;
    365                    fileNames := fileNames + tmpCurrentChar;
    366                    fileNamesRaw := fileNamesRaw + tmpQuote + tmpCurrentChar;
    367                  end;
    368                end;
    369 
    370                SWITCH :
    371                begin
    372                  tmpSwitch := tmpSwitch + tmpCurrentChar;
    373                end;
    374 
    375                FILENAME :
    376                begin
    377                  fileNames := fileNames + tmpCurrentChar;
    378                  fileNamesRaw := fileNamesRaw + tmpCurrentChar;
    379                end;
    380 
    381                TEXT :
    382                begin
    383                  searchText := searchText + tmpCurrentChar;
    384                end;
    385              end;
    386            end;
     182    // first adjust logging
     183    if GetEnv(ENV_DEBUG) = '' then
     184    begin
     185      // TODO set boolean
     186    end
     187    else
     188    begin
     189      SetLogAspects(GetEnv(ENV_DEBUG));
     190    end;
     191
     192    LogEvent(LogStartup, 'ParseCommandLine: "' + aCmdLineString + '"');
     193
     194    // store the original string for debugging
     195    commandLine := aCmdLineString;
     196
     197    // reset the whole object
     198    showUsageFlag := false;
     199    searchFlag := false;
     200    globalSearchFlag := false;
     201    language := '';
     202    helpManagerFlag := false;
     203    helpManagerWindow := 0;
     204    windowPositionFlag := false;
     205    ownerWindow := 0;
     206    windowTitle := '';
     207    searchText := '';
     208    fileNames := '';
     209    fileNamesRaw := '';
     210
     211    try
     212      // start parsing
     213      tmpState := WHITESPACE;
     214      tmpWhitespace := '';
     215      tmpSwitch := '';
     216      tmpQuote := '';
     217      tmpQuoted := false;
     218      tmpCurrentParsePosition := 1;
     219      while tmpCurrentParsePosition <= length(aCmdLineString) do
     220      begin
     221        tmpCurrentChar := aCmdLineString[tmpCurrentParsePosition];
     222
     223        Case tmpCurrentChar of
     224          ' ' :
     225          begin
     226            Case tmpState of
     227
     228              WHITESPACE :
     229              begin
     230                tmpWhitespace := tmpWhitespace + tmpCurrentChar;
     231              end;
     232
     233              QUOTE :
     234              begin
     235                tmpQuote := tmpQuote + tmpCurrentChar;
     236              end;
     237
     238              SWITCH :
     239              begin
     240                if tmpQuoted then
     241                begin
     242                  tmpSwitch := tmpSwitch + tmpCurrentChar;
     243                end
     244                else
     245                begin
     246                  parseSwitch(tmpSwitch);
     247                  tmpState := WHITESPACE;
     248                  tmpWhitespace := tmpCurrentChar;
     249                end
     250              end;
     251
     252              FILENAME :
     253              begin
     254                if tmpQuoted then
     255                begin
     256                  fileNames := fileNames + tmpCurrentChar;
     257                  fileNamesRaw := fileNamesRaw + tmpCurrentChar;
     258                end
     259                else
     260                begin
     261                  tmpState := WHITESPACE;
     262                  tmpWhitespace := tmpCurrentChar;
     263                end
     264              end;
     265
     266              TEXT :
     267              begin
     268                if tmpQuoted then
     269                begin
     270                  searchText := searchText + tmpCurrentChar;
     271                end
     272                else
     273                begin
     274                  tmpState := WHITESPACE;
     275                  tmpWhitespace := tmpCurrentChar;
     276                end
     277              end;
     278            end;
     279          end;
     280
     281          '/', '-' :
     282          begin
     283            Case tmpState of
     284              WHITESPACE :
     285              begin
     286                tmpState := SWITCH;
     287                tmpSwitch := '';
     288              end;
     289
     290              QUOTE :
     291              begin
     292                tmpState := SWITCH;
     293                tmpSwitch := '';
     294              end;
     295
     296              SWITCH :
     297              begin
     298                parseSwitch(tmpSwitch);
     299                tmpSwitch := '';
     300              end;
     301
     302              FILENAME :
     303              begin
     304                fileNames := fileNames + tmpCurrentChar;
     305                fileNamesRaw := fileNamesRaw + tmpCurrentChar;
     306              end;
     307
     308              TEXT :
     309              begin
     310                searchText := searchText + tmpCurrentChar;
     311              end;
     312            end;
     313          end;
     314
     315          '"' :
     316          begin
     317            if tmpQuoted then
     318            begin
     319              tmpQuoted := false;
     320              Case tmpState of
     321                FILENAME :
     322                begin
     323                  fileNamesRaw := fileNamesRaw + tmpCurrentChar;
     324                end;
     325              end;
     326            end
     327            else
     328            begin
     329              Case tmpState of
     330                WHITESPACE :
     331                begin
     332                  tmpState := QUOTE;
     333                  tmpQuote := tmpCurrentChar;
     334                end;
     335                FILENAME :
     336                begin
     337                  fileNamesRaw := fileNamesRaw + tmpCurrentChar;
     338                end;
     339              end;
     340              tmpQuoted := true;
     341            end;
     342          end;
     343
     344          // any other char
     345          else
     346          begin
     347            Case tmpState of
     348
     349              WHITESPACE :
     350              begin
     351                if length(fileNames) > 0 then
     352                begin
     353                  tmpState := TEXT;
     354                  searchText := searchText + tmpWhitespace + tmpCurrentChar;
     355                end
     356                else
     357                begin
     358                  tmpState := FILENAME;
     359                  fileNames := fileNames + tmpCurrentChar;
     360                  fileNamesRaw := fileNamesRaw + tmpCurrentChar;
     361                end;
     362              end;
     363
     364              QUOTE :
     365              begin
     366                if length(fileNames) > 0 then
     367                begin
     368                  tmpState := TEXT;
     369                  searchText := searchText + tmpWhitespace + tmpCurrentChar;
     370                end
     371                else
     372                begin
     373                  tmpState := FILENAME;
     374                  fileNames := fileNames + tmpCurrentChar;
     375                  fileNamesRaw := fileNamesRaw + tmpQuote + tmpCurrentChar;
     376                end;
     377              end;
     378
     379              SWITCH :
     380              begin
     381                tmpSwitch := tmpSwitch + tmpCurrentChar;
     382              end;
     383
     384              FILENAME :
     385              begin
     386                fileNames := fileNames + tmpCurrentChar;
     387                fileNamesRaw := fileNamesRaw + tmpCurrentChar;
     388              end;
     389
     390              TEXT :
     391              begin
     392                searchText := searchText + tmpCurrentChar;
     393              end;
     394            end;
     395          end;
    387396        end;
    388397        inc(tmpCurrentParsePosition);
     
    395404          parseSwitch(tmpSwitch);
    396405        end;
    397      end;
    398 
    399 
    400      // TODO remove interpreted
    401 
     406      end;
     407      // TODO remove interpreted
    402408    except
    403409        on e:EParsingFailed do
     
    414420    LogEvent(LogStartup, '  Search Text: "' + searchText + '"');
    415421  end;
    416 
    417 
    418 {
    419   FUNCTION TCmdLineParameters.ReadNextPart(const aParseString : String; const aSetOfDelimiterChars : TSetOfChars): String;
    420   VAR
    421     i : integer;
    422     tmpChar : char;
    423   BEGIN
    424     result := '';
    425     for i:= currentParsePosition to length(aParseString) do
    426     begin
    427       tmpChar := aParseString[i];
    428       if tmpChar in aSetOfDelimiterChars then
    429       begin
    430         i := length(aParseString); // stop parsing
    431       end
    432       else
    433       begin
    434         result := result + tmpChar;
    435       end;
    436     end;
    437   END;
    438 }
    439422
    440423
     
    517500  var
    518501    tmpCurrentChar : char;
    519     tmpText : String;
    520502    tmpValue : String;
    521503  begin
     
    578560        begin
    579561          showUsageFlag := true;
    580 
    581           // check for 'help'
    582 //          tmpText := copy(aCmdLineString, 2, 3);
    583 //          tmpText := lowercase(tmpText);
    584 
    585 //          if ('elp' = tmpText) then
    586 //          begin
    587 //          end;
    588562        end;
    589563
Note: See TracChangeset for help on using the changeset viewer.