diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d972a4d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +lib/ +*.lps diff --git a/UApp.pas b/UApp.pas index 3640c54..acaeca7 100644 --- a/UApp.pas +++ b/UApp.pas @@ -250,6 +250,8 @@ begin Writeln(' specifies the filename with filter commands'); Writeln(' -f --logfile='); Writeln(' specifies the logfile to be parsed'); + Writeln(' --html='); + Writeln(' outputs filtered results in a formatted HTML file'); Writeln(' -h --help'); Writeln(' show this help screen'); end; diff --git a/UWriter.pas b/UWriter.pas index c59b850..0ad47c7 100644 --- a/UWriter.pas +++ b/UWriter.pas @@ -5,7 +5,7 @@ unit UWriter; interface uses - Classes, SysUtils, UFilter, crt, fgl; + Classes, SysUtils, UFilter, crt, fgl, htmlelements; type TWriter = class @@ -38,6 +38,18 @@ type implementation +const + htmlColors: array[0..15] of String[6] = ( + '000000', '000066', '003300', '0099CC', '990000', '990033', '663300', + 'CCCCCC', '666666', '66CCFF', '66FF66', '99FFCC', 'FF8080', 'FF80B2', + 'FFFF00', 'FFFFFF' + ); + cssColors: array[0..15] of String = ( + 'Black', 'Blue', 'Green', 'Cyan', 'Red', 'Magenta', 'Brown', 'LightGray', + 'DarkGray', 'LightBlue', 'LightGreen', 'LightCyan', 'LightRed', + 'LightMagenta', 'Yellow', 'White' + ); + { THTMLWriter } procedure THTMLWriter.WriteLine(AContent: String); @@ -50,20 +62,50 @@ constructor THTMLWriter.Create(AFileName: String); begin FFileStream := TFileStream.Create(AFileName, fmCreate); WriteLine(''); - WriteLine(''); + WriteLine(''); end; destructor THTMLWriter.Destroy; begin - WriteLine(''); + WriteLine(''); WriteLine(''); FFileStream.Free; inherited Destroy; end; procedure THTMLWriter.WriteContent(AContent: String; AHighlights: THighlights); +var + matchPos, offset, lastPos: Integer; + highlight: THighlight; + htmlContent, style: String; begin + lastPos := 1; + htmlContent := ''; + for highlight in AHighlights do + begin + matchPos := highlight.Start; + offset := highlight.Length; + htmlContent := htmlContent + EscapeHTML(Copy(AContent, lastPos, + matchPos - lastPos)); + + style := ''; + if highlight.FGColor < 16 then + style := 'color: ' + cssColors[highlight.FGColor] + ';'; + if highlight.BGColor < 15 then + style := style + 'background-color: ' + cssColors[highlight.BGColor] + ';'; + + if style <> '' then + htmlContent := htmlContent + ''; + htmlContent := htmlContent + EscapeHTML(Copy(AContent, matchPos, offset)); + if style <> '' then + htmlContent := htmlContent + ''; + lastPos := matchPos + offset; + end; + + htmlContent := htmlContent + EscapeHTML(Copy(AContent, lastPos, Length(AContent))); + + WriteLine(htmlContent + '
'); end; { TConsoleWriter }