mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Add an argument parser
This commit is contained in:
parent
7218575b48
commit
9718defcaa
30
Library/targp.c
Normal file
30
Library/targp.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <targp.h>
|
||||||
|
|
||||||
|
#include <memory.hpp>
|
||||||
|
#include <convert.h>
|
||||||
|
|
||||||
|
void targp_parse(const char *cmd, char **argv, int *argc)
|
||||||
|
{
|
||||||
|
const char delim[] = " ";
|
||||||
|
|
||||||
|
char *token = strtok((char *)cmd, delim);
|
||||||
|
while (token != NULL)
|
||||||
|
{
|
||||||
|
char *quote = strchr(token, '"');
|
||||||
|
if (quote != NULL)
|
||||||
|
{
|
||||||
|
memmove(quote, quote + 1, strlen(quote));
|
||||||
|
char *endQuote = strchr(quote, '"');
|
||||||
|
if (endQuote != NULL)
|
||||||
|
*endQuote = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
char *arg = (char *)kmalloc(strlen(token) + 1);
|
||||||
|
strcpy(arg, token);
|
||||||
|
|
||||||
|
argv[(*argc)++] = arg;
|
||||||
|
|
||||||
|
token = strtok(NULL, delim);
|
||||||
|
}
|
||||||
|
argv[(*argc)] = NULL;
|
||||||
|
}
|
15
include/targp.h
Normal file
15
include/targp.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef TinyArgumentParser_H__
|
||||||
|
#define TinyArgumentParser_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void targp_parse(const char *cmd, char **argv, int *argc);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // !TinyArgumentParser_H__
|
Loading…
x
Reference in New Issue
Block a user