From 2752c839ed8406bb3284e8d50a46e91a3b237c72 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 28 Sep 2015 10:21:55 +0200 Subject: [PATCH] Simplified command line parameter handling --- UApp.pas | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/UApp.pas b/UApp.pas index e78da4a..0d5cb3b 100644 --- a/UApp.pas +++ b/UApp.pas @@ -58,6 +58,12 @@ type implementation +{Some trickery to have clean command line option checks} +{$MACRO ON} +{$define OPT_COMMANDFILE:='c', 'commandfile'} +{$define OPT_SIMPLE:='s', 'simple'} +{$define OPT_LOGFILE:='f', 'logfile'} + { TLogFilterApplication } procedure TLogFilterApplication.DoRun; @@ -66,17 +72,17 @@ var line: String; fg, bg: Byte; begin - if HasOption('h', 'help') or (not HasOption('c', 'commandfile') and not - HasOption('s', 'simple')) then + if HasOption('h', 'help') or (not HasOption(OPT_COMMANDFILE) and not + HasOption(OPT_SIMPLE)) then begin WriteHelp; Terminate; Exit; end; - if HasOption('c', 'commandfile') then + if HasOption(OPT_COMMANDFILE) then begin - FCommandFileName := GetOptionValue('c', 'commandfile'); + FCommandFileName := GetOptionValue(OPT_COMMANDFILE); if not FileExists(FCommandFileName) then begin @@ -100,9 +106,9 @@ begin CloseFile(commandFile); end; //commandfile processing - if HasOption('s', 'simple') then + if HasOption(OPT_SIMPLE) then begin - FCurrentLineFilter := TLineFilter.Create(GetOptionValue('s', 'simple')); + FCurrentLineFilter := TLineFilter.Create(GetOptionValue(OPT_SIMPLE)); FLineFilters.Add(FCurrentLineFilter); if HasOption('fg') then @@ -118,8 +124,8 @@ begin FCurrentLineFilter.Filters.Add(THighlightFilter.Create('.*', fg, bg, 0)); end; //Simple Mode - if HasOption('f', 'logfile') then - FLogFileName := GetOptionValue('f', 'logfile'); + if HasOption(OPT_LOGFILE) then + FLogFileName := GetOptionValue(OPT_LOGFILE); if not FileExists(FLogFileName) then begin