From d0633ccb833c7bcde4830f3e1859915fd2212a6d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 28 Sep 2015 09:54:03 +0200 Subject: [PATCH] * Added simple filter support --- UApp.pas | 63 ++++++++++++++++++++++++++++++++++++++--------------- UFilter.pas | 10 +++++++++ 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/UApp.pas b/UApp.pas index ed6a060..e78da4a 100644 --- a/UApp.pas +++ b/UApp.pas @@ -64,36 +64,59 @@ procedure TLogFilterApplication.DoRun; var commandFile: TextFile; line: String; + fg, bg: Byte; begin - if HasOption('h', 'help') or not HasOption('c', 'commandfile') then + if HasOption('h', 'help') or (not HasOption('c', 'commandfile') and not + HasOption('s', 'simple')) then begin WriteHelp; Terminate; Exit; end; - FCommandFileName := GetOptionValue('c', 'commandfile'); - - if not FileExists(FCommandFileName) then + if HasOption('c', 'commandfile') then begin - Writeln('Commandfile not found: ', FCommandFileName); - ExitCode := 1; - Terminate; - Exit; - end; + FCommandFileName := GetOptionValue('c', 'commandfile'); - AssignFile(commandFile, FCommandFileName); - Reset(commandFile); + if not FileExists(FCommandFileName) then + begin + Writeln('Commandfile not found: ', FCommandFileName); + ExitCode := 1; + Terminate; + Exit; + end; - // Parse command file first - while not EOF(commandFile) do + AssignFile(commandFile, FCommandFileName); + Reset(commandFile); + + // Parse command file first + while not EOF(commandFile) do + begin + Readln(commandFile, line); + if FCommandMatcher.Exec(line) then + ProcessCommand(FCommandMatcher.Match[1], FCommandMatcher.Match[3]); + end; + + CloseFile(commandFile); + end; //commandfile processing + + if HasOption('s', 'simple') then begin - Readln(commandFile, line); - if FCommandMatcher.Exec(line) then - ProcessCommand(FCommandMatcher.Match[1], FCommandMatcher.Match[3]); - end; + FCurrentLineFilter := TLineFilter.Create(GetOptionValue('s', 'simple')); + FLineFilters.Add(FCurrentLineFilter); - CloseFile(commandFile); + if HasOption('fg') then + fg := StrToIntDef(GetOptionValue('fg'), $FF) + else + fg := LightBlue; + + if HasOption('bg') then + bg := StrToIntDef(GetOptionValue('bg'), $FF) + else + bg := $FF; + + FCurrentLineFilter.Filters.Add(THighlightFilter.Create('.*', fg, bg, 0)); + end; //Simple Mode if HasOption('f', 'logfile') then FLogFileName := GetOptionValue('f', 'logfile'); @@ -379,12 +402,16 @@ begin Writeln('Options:'); Writeln(' -c --commandfile='); Writeln(' specifies the filename with filter commands'); + Writeln(' -s --simple='); + Writeln(' Applies a simple filter and highlights the (full) match.'); Writeln(' -f --logfile='); Writeln(' specifies the logfile to be parsed'); Writeln(' -p --poll'); Writeln(' keep the log file open and wait for data'); Writeln(' --html='); Writeln(' outputs filtered results in a formatted HTML file'); + Writeln(' --fg= --bg='); + Writeln(' Sets the highlight color for the simple matcher (-s)'); Writeln(' -h --help'); Writeln(' show this help screen'); end; diff --git a/UFilter.pas b/UFilter.pas index ee8e8e8..92aca98 100644 --- a/UFilter.pas +++ b/UFilter.pas @@ -37,6 +37,7 @@ type BGColor: Byte; Group: Byte; constructor Create(AString: String); + constructor Create(AExpression: String; AFG, ABG, AGroup: Byte); destructor Destroy; override; class var FilterExpression: TRegExpr; @@ -104,6 +105,15 @@ begin Expression := TRegExpr.Create(AString); end; +constructor THighlightFilter.Create(AExpression: String; AFG, ABG, AGroup: Byte + ); +begin + FGColor := AFG; + BGColor := ABG; + Group := AGroup; + Expression := TRegExpr.Create(AExpression); +end; + destructor THighlightFilter.Destroy; begin Expression.Free;