index 60e72b4f1f712390a0fabfe00d5b3c4b8a9c65ec..93f030194db1e09cd09780573f2ddf3865ea8aff 100644 (file)
-(* Copyright (C) DooM 2D:Forever Developers
+(* Copyright (C) Doom 2D: Forever Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * the Free Software Foundation, version 3 of the License ONLY.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
type
TBindArgLessCB = procedure ();
TBindToggleCB = procedure (arg: Integer); // -1: no arg
type
TBindArgLessCB = procedure ();
TBindToggleCB = procedure (arg: Integer); // -1: no arg
+ TBindStringCB = procedure (s: AnsiString);
PHolmesCommand = ^THolmesCommand;
THolmesCommand = record
public
PHolmesCommand = ^THolmesCommand;
THolmesCommand = record
public
- type TType = (TArgLess, TToggle);
+ type TType = (TArgLess, TToggle, TString);
public
name: AnsiString;
public
name: AnsiString;
function cmdName (): AnsiString;
end;
function cmdName (): AnsiString;
end;
- TCmdHash = specialize THashBase<AnsiString, PHolmesCommand>;
+ TCmdHash = specialize THashBase<AnsiString, PHolmesCommand, THashKeyStr>;
// ////////////////////////////////////////////////////////////////////////// //
// ////////////////////////////////////////////////////////////////////////// //
procedure THolmesCommand.execute (pr: TTextParser);
var
a: Integer = -1;
procedure THolmesCommand.execute (pr: TTextParser);
var
a: Integer = -1;
+ s: AnsiString = '';
begin
if not assigned(cb) then exit;
begin
if not assigned(cb) then exit;
- if (ctype = TType.TToggle) then
- begin
- if pr.skipBlanks() then
- begin
- if pr.eatId('true') or pr.eatId('tan') or pr.eatId('yes') then a := 1
- else if pr.eatId('false') or pr.eatId('ona') or pr.eatId('no') then a := 0
- else begin conwritefln('%s: invalid argument', [name]); exit; end;
- end;
- end;
- if pr.skipBlanks() then begin conwritefln('%s: too many arguments', [name]); exit; end;
case ctype of
case ctype of
- TType.TArgLess: TBindArgLessCB(cb)();
- TType.TToggle: TBindToggleCB(cb)(a);
+ TType.TToggle:
+ begin
+ if (pr.tokType <> pr.TTEOF) then
+ begin
+ if pr.eatId('true') or pr.eatId('tan') or pr.eatId('yes') then a := 1
+ else if pr.eatId('false') or pr.eatId('ona') or pr.eatId('no') then a := 0
+ else begin conwritefln('%s: invalid argument', [name]); exit; end;
+ if (pr.tokType <> pr.TTEOF) then begin conwritefln('%s: too many arguments', [name]); exit; end;
+ end;
+ TBindToggleCB(cb)(a);
+ end;
+ TType.TArgLess:
+ begin
+ if (pr.tokType <> pr.TTEOF) then begin conwritefln('%s: too many arguments', [name]); exit; end;
+ TBindArgLessCB(cb)();
+ end;
+ TType.TString:
+ begin
+ if (pr.tokType <> pr.TTEOF) then
+ begin
+ if (pr.tokType = pr.TTStr) then s := pr.expectStr(false) else s := pr.expectId;
+ if (pr.tokType <> pr.TTEOF) then begin conwritefln('%s: too many arguments', [name]); exit; end;
+ end
+ else
+ begin
+ conwritefln('%s: string argument expected', [name]);
+ exit;
+ end;
+ TBindStringCB(cb)(s);
+ end;
else assert(false);
end;
end;
// ////////////////////////////////////////////////////////////////////////// //
else assert(false);
end;
end;
// ////////////////////////////////////////////////////////////////////////// //
-function ansistrEquCB (constref a, b: AnsiString): Boolean; begin result := (a = b); end;
-function ansistrHashCB (constref a: AnsiString): LongWord; begin if (Length(a) > 0) then result := fnvHash(PChar(a)^, Length(a)) else result := 0; end;
-
function hashNewCommand (): TCmdHash;
begin
function hashNewCommand (): TCmdHash;
begin
- result := TCmdHash.Create(ansistrHashCB, ansistrEquCB);
+ result := TCmdHash.Create();
end;
end;
end;
end;
+// ////////////////////////////////////////////////////////////////////////// //
procedure cmdAdd (const aname: AnsiString; cb: TBindArgLessCB; const ahelp: AnsiString; const asection: AnsiString); overload;
var
cmd: PHolmesCommand;
procedure cmdAdd (const aname: AnsiString; cb: TBindArgLessCB; const ahelp: AnsiString; const asection: AnsiString); overload;
var
cmd: PHolmesCommand;
end;
end;
+procedure cmdAdd (const aname: AnsiString; cb: TBindStringCB; const ahelp: AnsiString; const asection: AnsiString); overload;
+var
+ cmd: PHolmesCommand;
+begin
+ if (Length(aname) = 0) or not assigned(cb) then exit;
+ cmd := cmdNewInternal(aname, ahelp, asection);
+ cmd.cb := Pointer(@cb);
+ cmd.ctype := cmd.TType.TString;
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
function getCommandHelp (const aname: AnsiString): AnsiString;
var
cmd: PHolmesCommand = nil;
function getCommandHelp (const aname: AnsiString): AnsiString;
var
cmd: PHolmesCommand = nil;
end;
end;
-function keybindExecute (var ev: THKeyEvent): Boolean;
+function keybindExecute (var ev: TFUIEvent): Boolean;
var
f: Integer;
begin
var
f: Integer;
begin
end;
end;
-function msbindExecute (var ev: THMouseEvent): Boolean;
+function msbindExecute (var ev: TFUIEvent): Boolean;
var
f: Integer;
begin
var
f: Integer;
begin