Stuff
git-svn-id: https://spexeah.com:8443/svn/Asuro@259 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
		
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								lib/libpsystem.a
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lib/libpsystem.a
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -23,6 +23,8 @@ function stringNew(size : uint32) : pchar; | |||||||
| function stringSize(str : pchar) : uint32; | function stringSize(str : pchar) : uint32; | ||||||
| function stringConcat(str1, str2 : pchar) : pchar; | function stringConcat(str1, str2 : pchar) : pchar; | ||||||
| function stringContains(str : pchar; sub : pchar) : boolean; | function stringContains(str : pchar; sub : pchar) : boolean; | ||||||
|  | function stringToInt(str : pchar) : uint32; | ||||||
|  | function intToString(i : uint32) : pchar; | ||||||
|  |  | ||||||
| implementation | implementation | ||||||
|  |  | ||||||
| @@ -122,4 +124,30 @@ begin | |||||||
|     stringContains:= false;     |     stringContains:= false;     | ||||||
| end; | 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. | end. | ||||||
							
								
								
									
										131
									
								
								src/terminal.pas
									
									
									
									
									
								
							
							
						
						
									
										131
									
								
								src/terminal.pas
									
									
									
									
									
								
							| @@ -15,7 +15,8 @@ uses | |||||||
|     console, |     console, | ||||||
|     keyboard, |     keyboard, | ||||||
|     util, |     util, | ||||||
|     lmemorymanager; |     lmemorymanager, | ||||||
|  |     strings; | ||||||
|  |  | ||||||
| type | type | ||||||
|     PParamList = ^TParamList; |     PParamList = ^TParamList; | ||||||
| @@ -50,6 +51,21 @@ function getParams(buf : TCommandBuffer) : PParamList; | |||||||
|  |  | ||||||
| implementation | 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; | function getParams(buf : TCommandBuffer) : PParamList; | ||||||
| var | var | ||||||
|     start, finish : uint32; |     start, finish : uint32; | ||||||
| @@ -86,6 +102,36 @@ begin | |||||||
|     getParams:= root; |     getParams:= root; | ||||||
| end; | 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); | procedure testParams(params : PParamList); | ||||||
| begin | begin | ||||||
|     while params^.Param <> nil do begin |     while params^.Param <> nil do begin | ||||||
| @@ -133,6 +179,15 @@ begin | |||||||
|     end; |     end; | ||||||
| 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); | procedure registerCommand(command : pchar; method : TCommandMethod; description : pchar); | ||||||
| var | var | ||||||
|     index : uint32; |     index : uint32; | ||||||
| @@ -146,68 +201,47 @@ begin | |||||||
|     Commands[index].description:= description; |     Commands[index].description:= description; | ||||||
| end; | 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; | procedure process_command; | ||||||
| var | var | ||||||
|     fallthrough : boolean; |     fallthrough : boolean; | ||||||
|     params : PParamList; |     params : PParamList; | ||||||
|     i : uint32; |     i : uint32; | ||||||
|     next : PParamList; |     next : PParamList; | ||||||
|  |     uppera, upperb : pchar; | ||||||
|  |  | ||||||
| begin | begin | ||||||
|  |     { Start a new line. } | ||||||
|     console.writecharln(' '); |     console.writecharln(' '); | ||||||
|  |  | ||||||
|  |     { Enable fallthrough/Unrecognized command } | ||||||
|     fallthrough:= true; |     fallthrough:= true; | ||||||
|     upper; |      | ||||||
|     for i:=0 to 65534 do begin |     { Get all params and check params[0] (the command) to see if it's registered } | ||||||
|         if Commands[i].registered then begin |     params:= getParams(buffer); | ||||||
|             if isCommand(Commands[i].command) then begin |     if params^.param <> nil then begin | ||||||
|                 params:= getParams(buffer); |         uppera:= stringToUpper(params^.param); | ||||||
|                 Commands[i].method(params); |         for i:=0 to 65534 do begin | ||||||
|                 params:= params; |             if Commands[i].registered then begin | ||||||
|                 next:= params^.next; |                 upperb:= stringToUpper(Commands[i].command); | ||||||
|                 while params^.next <> nil do begin |                 if stringEquals(uppera, upperb) then begin | ||||||
|                     if params^.param <> nil then kfree(void(params^.param)); |                     Commands[i].method(params); | ||||||
|                     kfree(void(params)); |                     fallthrough:= false; | ||||||
|                     params:= next; |  | ||||||
|                     next:= params^.next; |  | ||||||
|                 end; |                 end; | ||||||
|                 fallthrough:= false; |                 kfree(void(upperb)); | ||||||
|             end; |             end;    | ||||||
|         end;    |         end; | ||||||
|  |         kfree(void(uppera)); | ||||||
|     end; |     end; | ||||||
|  |  | ||||||
|  |     { Free the params } | ||||||
|  |     freeParams(params); | ||||||
|  |  | ||||||
|  |     { Display message if command is unknown AKA fallthrough is active } | ||||||
|     if fallthrough then begin |     if fallthrough then begin | ||||||
|         console.writestringln('Unknown Command.'); |         console.writestringln('Unknown Command.'); | ||||||
|     end; |     end; | ||||||
|  |  | ||||||
|  |     { Reset the terminal ready for the next command } | ||||||
|     console.writestring('Asuro#> '); |     console.writestring('Asuro#> '); | ||||||
|     bIndex:= 0; |     bIndex:= 0; | ||||||
|     memset(uint32(@buffer[0]), 0, 1024); |     memset(uint32(@buffer[0]), 0, 1024); | ||||||
| @@ -243,6 +277,7 @@ begin | |||||||
|     registerCommand('HELP', @help, 'Lists all registered commands and their description.'); |     registerCommand('HELP', @help, 'Lists all registered commands and their description.'); | ||||||
|     registerCommand('ECHO', @echo, 'Echo''s text to the terminal.'); |     registerCommand('ECHO', @echo, 'Echo''s text to the terminal.'); | ||||||
|     registerCommand('TESTPARAMS', @testParams, 'Tests param parsing.'); |     registerCommand('TESTPARAMS', @testParams, 'Tests param parsing.'); | ||||||
|  |     registerCommand('TEST', @test, 'Command for testing.') | ||||||
| end; | end; | ||||||
|  |  | ||||||
| procedure run; | procedure run; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 kieron
					kieron