#include "argparser.h" #include #include #include #include void argparser_parse(char **buf, int max, char *str) { // Clear buf array for (int i = 0; i < max; ++i) buf[i] = NULL; int argc = 0; char c; for (int i = 0; (c = str[i]) != '\0'; ++i) { // Strings in quotes if (c == '"') { int start = i + 1; do ++i; while (str[i] != '\0' && str[i] != '"'); buf[argc++] = str + start; if (str[i] == '\0') break; else str[i] = '\0'; } // String without quotes else if (!isspace(str[i])) { int start = i; while (str[i] != '\0' && !isspace(str[i])) i += 1; buf[argc++] = str + start; if (str[i] == '\0') break; else str[i] = '\0'; } if (argc >= max) break; } }