diff --git a/Asuro.iso b/Asuro.iso index 5afe4496..49533de2 100644 Binary files a/Asuro.iso and b/Asuro.iso differ diff --git a/iso/boot/asuro.bin b/iso/boot/asuro.bin index fb8c698b..ad5bbfd1 100755 Binary files a/iso/boot/asuro.bin and b/iso/boot/asuro.bin differ diff --git a/lib/libpconsole.a b/lib/libpconsole.a index b68395f4..bf710698 100644 Binary files a/lib/libpconsole.a and b/lib/libpconsole.a differ diff --git a/lib/libpmultiboot.a b/lib/libpmultiboot.a index ea5a9e6a..f4ef9c3e 100644 Binary files a/lib/libpmultiboot.a and b/lib/libpmultiboot.a differ diff --git a/lib/libpsystem.a b/lib/libpsystem.a index 0860571d..de826d0d 100644 Binary files a/lib/libpsystem.a and b/lib/libpsystem.a differ diff --git a/src/strings.pas b/src/strings.pas index 7f1be8ff..f7da64ec 100644 --- a/src/strings.pas +++ b/src/strings.pas @@ -23,6 +23,8 @@ function stringNew(size : uint32) : pchar; function stringSize(str : pchar) : uint32; function stringConcat(str1, str2 : pchar) : pchar; function stringContains(str : pchar; sub : pchar) : boolean; +function stringToInt(str : pchar) : uint32; +function intToString(i : uint32) : pchar; implementation @@ -122,4 +124,30 @@ begin stringContains:= false; end; +function stringToInt(str : pchar) : uint32; +var + i : uint32; + x : uint32; + v : uint32; + r : uint32; + +begin + stringToInt:= 0; + x:= 1; + r:= 0; + for i:=stringSize(str)-1 downto 0 do begin + v:= byte(str[i]) - 48; + if (v >= 0) and (v <= 9) then begin + r:= r + (v * x); + end; + x:= x * 10; + end; + stringToInt:= r; +end; + +function intToString(i : uint32) : pchar; +begin + intToString:= ' '; +end; + end. \ No newline at end of file diff --git a/src/terminal.pas b/src/terminal.pas index 0de1edc3..336615ae 100644 --- a/src/terminal.pas +++ b/src/terminal.pas @@ -15,7 +15,8 @@ uses console, keyboard, util, - lmemorymanager; + lmemorymanager, + strings; type PParamList = ^TParamList; @@ -50,6 +51,21 @@ function getParams(buf : TCommandBuffer) : PParamList; implementation +function paramCount(params : PParamList) : uint32; +var + current : PParamList; + i : uint32; + +begin + current:= params; + i:= 0; + while current^.param <> nil do begin + inc(i); + current:= current^.next; + end; + paramCount:= i-1; +end; + function getParams(buf : TCommandBuffer) : PParamList; var start, finish : uint32; @@ -86,6 +102,36 @@ begin getParams:= root; end; +function getParam(index : uint32; params : PParamList) : pchar; +var + result : pchar; + search : PParamList; + +begin + result:= nil; + search:= params; + for i:=0 to index do begin + search:= search^.next; + end; + result:= search^.param; +end; + +procedure freeParams(params : PParamList); +var + p : PParamList; + next : PParamList; + +begin + p:= params; + next:= p^.next; + while p^.next <> nil do begin + if p^.param <> nil then kfree(void(p^.param)); + kfree(void(p)); + p:= next; + next:= p^.next; + end; +end; + procedure testParams(params : PParamList); begin while params^.Param <> nil do begin @@ -133,6 +179,15 @@ begin end; end; +procedure test(params : PParamList); +begin + if paramCount(params) > 0 then begin + console.writeintln(stringToInt(params^.next^.param)); + end else begin + console.writestringln('Invalid number of params'); + end; +end; + procedure registerCommand(command : pchar; method : TCommandMethod; description : pchar); var index : uint32; @@ -146,68 +201,47 @@ begin Commands[index].description:= description; end; -procedure upper; -var - i : uint32; - -begin - for i:=0 to bIndex do begin - if char(buffer[i]) = ' ' then exit; - if (buffer[i] >= 97) and (buffer[i] <= 122) then begin - buffer[i]:= buffer[i] - 32; - end; - end; -end; - -function isCommand(command : pchar) : boolean; -var - i : uint32; - -begin - isCommand:= true; - for i:=0 to bIndex do begin - if char(buffer[i]) = ' ' then begin - if i = 0 then isCommand:= false; - exit; - end; - if char(buffer[i]) <> char(command[i]) then begin - isCommand:= false; - exit; - end; - end; -end; - procedure process_command; var fallthrough : boolean; params : PParamList; i : uint32; next : PParamList; + uppera, upperb : pchar; begin + { Start a new line. } console.writecharln(' '); + + { Enable fallthrough/Unrecognized command } fallthrough:= true; - upper; - for i:=0 to 65534 do begin - if Commands[i].registered then begin - if isCommand(Commands[i].command) then begin - params:= getParams(buffer); - Commands[i].method(params); - params:= params; - next:= params^.next; - while params^.next <> nil do begin - if params^.param <> nil then kfree(void(params^.param)); - kfree(void(params)); - params:= next; - next:= params^.next; + + { Get all params and check params[0] (the command) to see if it's registered } + params:= getParams(buffer); + if params^.param <> nil then begin + uppera:= stringToUpper(params^.param); + for i:=0 to 65534 do begin + if Commands[i].registered then begin + upperb:= stringToUpper(Commands[i].command); + if stringEquals(uppera, upperb) then begin + Commands[i].method(params); + fallthrough:= false; end; - fallthrough:= false; - end; - end; + kfree(void(upperb)); + end; + end; + kfree(void(uppera)); end; + + { Free the params } + freeParams(params); + + { Display message if command is unknown AKA fallthrough is active } if fallthrough then begin console.writestringln('Unknown Command.'); end; + + { Reset the terminal ready for the next command } console.writestring('Asuro#> '); bIndex:= 0; memset(uint32(@buffer[0]), 0, 1024); @@ -243,6 +277,7 @@ begin registerCommand('HELP', @help, 'Lists all registered commands and their description.'); registerCommand('ECHO', @echo, 'Echo''s text to the terminal.'); registerCommand('TESTPARAMS', @testParams, 'Tests param parsing.'); + registerCommand('TEST', @test, 'Command for testing.') end; procedure run;