diff --git a/Library/targp.c b/Library/targp.c new file mode 100644 index 0000000..6a40017 --- /dev/null +++ b/Library/targp.c @@ -0,0 +1,30 @@ +#include + +#include +#include + +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; +} diff --git a/include/targp.h b/include/targp.h new file mode 100644 index 0000000..eba8407 --- /dev/null +++ b/include/targp.h @@ -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__