summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-12-19 11:00:21 +0100
committerErich Eckner <git@eckner.net>2016-12-19 11:00:21 +0100
commite75d61df84dc920f5e460cf56127b51e777559ca (patch)
tree8dcf33fdaaaa8bcd55097de79ec01ee959a08d8c
parenta02f8fb3d44b8273740d5b6ef482bdc469ebdf2e (diff)
downloadAnalyzer-e75d61df84dc920f5e460cf56127b51e777559ca.tar.xz
bissl was gemacht
-rw-r--r--analyzer.lpr134
-rw-r--r--analyzer.lps31
2 files changed, 133 insertions, 32 deletions
diff --git a/analyzer.lpr b/analyzer.lpr
index 02dfd2a..348518c 100644
--- a/analyzer.lpr
+++ b/analyzer.lpr
@@ -6,72 +6,146 @@ uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
- Classes, SysUtils, CustApp
+ classes, sysUtils, custApp
{ you can add units after this };
type
+ tOption = (oHelp, oInput);
+
{ TAnalyzer }
- TAnalyzer = class(TCustomApplication)
+ tAnalyzer = class(tCustomApplication)
protected
- procedure DoRun; override;
+ options: array of tOption;
+ oValues: array of string;
+ procedure doRun; override;
+ procedure parseOptions;
+ procedure illegalOption(i: longint);
public
- constructor Create(TheOwner: TComponent); override;
- destructor Destroy; override;
- procedure WriteHelp; virtual;
+ constructor create(theOwner: tComponent); override;
+ destructor destroy; override;
+ procedure writeHelp; virtual;
end;
+const
+ shortOptions: array[tOption] of char =
+ ('h','i');
+ longOptions: array[tOption] of string = (
+ 'help',
+ 'input'
+ );
+ optionValue: array[tOption] of byte = ( // bit 0: kann Wert haben; bit 1: muss Wert haben
+ 0,
+ 3
+ );
+
{ TAnalyzer }
-procedure TAnalyzer.DoRun;
+procedure tAnalyzer.doRun;
var
- ErrorMsg: String;
+ errorMsg: string;
begin
// quick check parameters
- ErrorMsg:=CheckOptions('h', 'help');
- if ErrorMsg<>'' then begin
- ShowException(Exception.Create(ErrorMsg));
- Terminate;
- Exit;
+ errorMsg:=checkOptions('hi:', 'help input:');
+ if errorMsg<>'' then begin
+ showException(Exception.Create(ErrorMsg));
+ halt(1);
end;
// parse parameters
- if HasOption('h', 'help') then begin
- WriteHelp;
- Terminate;
- Exit;
+ if hasOption('h', 'help') then begin
+ writeHelp;
+ terminate;
+ exit;
+ end;
+
+ if not hasOption('i','input') then begin
+ writeln('error: required option ''-i'' not given');
+ writeHelp;
+ halt(1);
end;
{ add your program here }
+ writeln(''''+getOptionValue('i','input')+'''');
+
// stop program loop
- Terminate;
+ terminate;
+end;
+
+procedure tAnalyzer.parseOptions;
+var
+ i: longint;
+ s,t: string;
+ o: tOption;
+ v,gefunden: boolean;
+begin
+ setlength(options,0);
+ setlength(oValues,0);
+ i:=1;
+ while i<=paramcount do begin
+ s:=paramstr(i);
+ if copy(s,1,1)<>'-' then
+ illegalOption(i);
+ delete(s,1,1);
+ gefunden:=false;
+ if copy(s,1,1)='-' then begin // long option
+ delete(s,1,1);
+ if pos('=',s)>0 then begin
+ t:=copy(s,pos('=',s)+1,length(s));
+ s:=copy(s,1,pos('=',s)-1);
+ v:=true;
+ end
+ else begin
+ t:='';
+ v:=false;
+ end;
+ for o:=low(longOptions) to high(longOptions) do
+ if (longOptions[o]<>'') and (longOptions[o]=s) and ((not v) or odd(optionValue[o])) then begin
+ gefunden:=true;
+ break;
+ end;
+ end;
+
+ if not gefunden then
+ illegalOption(i);
+
+ inc(i);
+ end;
+end;
+
+procedure tAnalyzer.illegalOption(i: longint);
+begin
+ writeln('Illegal option at position '+inttostr(i)+': '''+paramstr(i)+'''');
+ writeHelp;
+ halt(1);
end;
-constructor TAnalyzer.Create(TheOwner: TComponent);
+constructor tAnalyzer.create(theOwner: tComponent);
begin
- inherited Create(TheOwner);
- StopOnException:=True;
+ inherited create(theOwner);
+ parseOptions;
+ stopOnException:=true;
end;
-destructor TAnalyzer.Destroy;
+destructor tAnalyzer.destroy;
begin
- inherited Destroy;
+ inherited destroy;
end;
-procedure TAnalyzer.WriteHelp;
+procedure tAnalyzer.writeHelp;
begin
{ add your help code here }
- writeln('Usage: ', ExeName, ' -h');
+ writeln('usage: ', exeName, ' -h');
end;
var
- Application: TAnalyzer;
+ application: tAnalyzer;
begin
- Application:=TAnalyzer.Create(nil);
- Application.Title:='Analyzer';
- Application.Run;
- Application.Free;
+ application:=tAnalyzer.create(nil);
+ application.title:='analyzer';
+ application.run;
+ application.free;
end.
diff --git a/analyzer.lps b/analyzer.lps
index be061c4..2f4a0df 100644
--- a/analyzer.lps
+++ b/analyzer.lps
@@ -3,15 +3,42 @@
<ProjectSession>
<Version Value="9"/>
<BuildModes Active="Default"/>
- <Units Count="1">
+ <Units Count="2">
<Unit0>
<Filename Value="analyzer.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
+ <TopLine Value="23"/>
+ <CursorPos Y="52"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit0>
+ <Unit1>
+ <Filename Value="/usr/lib/fpc/src/packages/fcl-base/src/custapp.pp"/>
+ <UnitName Value="CustApp"/>
+ <EditorIndex Value="-1"/>
+ <TopLine Value="348"/>
+ <CursorPos X="44" Y="351"/>
+ <UsageCount Value="10"/>
+ </Unit1>
</Units>
- <JumpHistory HistoryIndex="-1"/>
+ <JumpHistory Count="4" HistoryIndex="3">
+ <Position1>
+ <Filename Value="analyzer.lpr"/>
+ <Caret Line="51" Column="50" TopLine="29"/>
+ </Position1>
+ <Position2>
+ <Filename Value="analyzer.lpr"/>
+ <Caret Line="52" Column="15" TopLine="30"/>
+ </Position2>
+ <Position3>
+ <Filename Value="analyzer.lpr"/>
+ <Caret Line="53" Column="39" TopLine="30"/>
+ </Position3>
+ <Position4>
+ <Filename Value="analyzer.lpr"/>
+ <Caret Line="52" Column="38" TopLine="30"/>
+ </Position4>
+ </JumpHistory>
</ProjectSession>
</CONFIG>