X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_holmes_cmd.inc;h=63b0ae55a83587d0e1118b97633e2053ed3185d2;hb=2a25db0f5f685dcc316bbaa822bf7d455a0bdb85;hp=60e72b4f1f712390a0fabfe00d5b3c4b8a9c65ec;hpb=c16bfd4a6ac97b3ea5b3300a0e6eed93d44ace87;p=d2df-sdl.git diff --git a/src/game/g_holmes_cmd.inc b/src/game/g_holmes_cmd.inc index 60e72b4..63b0ae5 100644 --- a/src/game/g_holmes_cmd.inc +++ b/src/game/g_holmes_cmd.inc @@ -17,11 +17,12 @@ type TBindArgLessCB = procedure (); TBindToggleCB = procedure (arg: Integer); // -1: no arg + TBindStringCB = procedure (s: AnsiString); PHolmesCommand = ^THolmesCommand; THolmesCommand = record public - type TType = (TArgLess, TToggle); + type TType = (TArgLess, TToggle, TString); public name: AnsiString; @@ -69,21 +70,40 @@ end; procedure THolmesCommand.execute (pr: TTextParser); var a: Integer = -1; + s: AnsiString = ''; 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 - 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; @@ -135,6 +155,7 @@ begin end; +// ////////////////////////////////////////////////////////////////////////// // procedure cmdAdd (const aname: AnsiString; cb: TBindArgLessCB; const ahelp: AnsiString; const asection: AnsiString); overload; var cmd: PHolmesCommand; @@ -157,6 +178,18 @@ begin 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;