#include "parser.h" #include "../lib/malloc/malloc.h" #include "../lib/cstr/cstr.h" #include "../lib/sys/write.h" char **__new_argv(char *exp); void __free_argv(char **argv); expression_list_t *new_expression_from_line(char *line) { u64 n = cstr_split(line, '|'); char *current = line; char *next = 0; expression_list_t *head = 0; expression_list_t *expression = 0; for (; n > 0; --n) { next = (char*)next_split(current); strip_cstr(current, ' '); if (!expression) { expression = malloc(sizeof(expression_list_t)); head = expression; } else { expression->next = malloc(sizeof(expression_list_t)); expression = expression->next; } expression->call = current; expression->next = 0; current = next; } return head; } void free_expression(expression_list_t *expression) { expression_list_t *next; while (expression) { next = expression->next; free(expression); expression = next; } } char **new_argv(char *exp) { u64 n = cstr_split(exp, ' '); char **argv = malloc(sizeof(char*) * (n + 1)); u64 i = 0; char *current = exp; char *next; argv[n] = 0; for (; n > 0; --n) { next = (char*)next_split(current); strip_cstr(current, ' '); if (cstr_length(current)) argv[i++] = current; current = next; } return argv; } void free_argv(char **argv) { free(argv); }