-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Huuuuuuuuuuge userland update and CLI improvement (#153)
ты пчела я пчеловод хуй пизда зубной налёт
- Loading branch information
Showing
24 changed files
with
429 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "common.h" | ||
|
||
typedef struct { | ||
char* original_string; | ||
int argc; | ||
char** argv; | ||
} command_parser_t; | ||
|
||
void command_parser_new(command_parser_t* parser, const char* _s); | ||
void command_parser_destroy(command_parser_t* parser); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "lib/command_parser.h" | ||
#include "mem/vmm.h" | ||
|
||
void command_parser_new(command_parser_t* parser, const char* _s) { | ||
if(!parser) { | ||
return; | ||
} | ||
|
||
parser->original_string = kcalloc(strlen(_s) + 1, 1); | ||
memcpy(parser->original_string, _s, strlen(_s)); | ||
|
||
parser->argc = 0; | ||
|
||
|
||
char* ptr = parser->original_string; | ||
// Count arguments | ||
while(*ptr++ == ' ') | ||
; | ||
while(*ptr++) { | ||
if(*ptr == ' ' || *ptr == 0) { | ||
if(parser->original_string != ptr - 1) { | ||
parser->argc++; | ||
} | ||
|
||
while(*ptr++ == ' ') | ||
; | ||
ptr--; | ||
} | ||
} | ||
|
||
|
||
parser->argv = kcalloc(parser->argc, sizeof(char*)); | ||
|
||
char* prev = parser->original_string; | ||
ptr = prev; | ||
|
||
size_t cur = 0; | ||
|
||
// Parse | ||
while(*ptr++ == ' ') | ||
; | ||
|
||
prev = ptr - 1; | ||
while(*ptr++) { | ||
if(*ptr == ' ' || *ptr == 0) { | ||
size_t len = ptr - prev; | ||
|
||
parser->argv[cur] = kcalloc(len + 1, 1); | ||
|
||
memcpy(parser->argv[cur], prev, len); | ||
|
||
cur++; | ||
|
||
while(*ptr++ == ' ') | ||
; | ||
|
||
prev = --ptr; | ||
} | ||
} | ||
} | ||
|
||
void command_parser_destroy(command_parser_t* parser) { | ||
kfree(parser->original_string); | ||
|
||
for(int i = 0; i < parser->argc; i++) { | ||
kfree(parser->argv[i]); | ||
} | ||
|
||
kfree(parser->argv); | ||
} | ||
|
Oops, something went wrong.