token_list_t *init_token_list(int max_tokens, int max_token_size) { int i; token_list_t *list = parse_alloc(sizeof(token_list_t)); //bzero if (list == 0) return 0; list->max_tokens = max_tokens; list->tokens = (char **) parse_alloc(sizeof(char*) * max_tokens); list->max_token_size = max_token_size; for(i=0; i < max_tokens; i++) { TK[i] = (char *) parse_alloc(max_token_size); if (TK[i] == 0) { destroy_token_list(list); return 0; } } list->token_index = 0; list->max_line_length = 512; return list; }
/** * Simplify the command and call one of the sub parser functions * * @param cmd Raw command string. This parameter is mutated. This * parameter cannot be NULL. * @param cmd_len Length in bytes of the command string. * @return Program status. */ static status_t parse_command(char* cmd, int cmd_len) { assert(cmd != NULL); int ws_cursor = 0; if (cmd[0] == '\0' || cmd[0] == '\n' || cmd[0] == '\r') return SUCCESS; // remove whitespace from command for (int i = 0; i < cmd_len; ++i) { switch (cmd[i]) { case ' ': case '\n': case '\r': case '\t': break; default: cmd[ws_cursor++] = cmd[i]; } } status_t status; // We have 2 commands: alloc and free. if (strstr(cmd, "alloc") != NULL) status = parse_alloc(cmd); else if (strstr(cmd, "free") != NULL) status = parse_free(cmd); else return parse_error(cmd); if (status != SUCCESS) return status; // Output free blocks buddy_dump(); return SUCCESS; }