Browse Source

* f2b_cmd_{create,destroy}()

master
Alex 'AdUser' Z 3 years ago
parent
commit
d44aee855f
  1. 26
      src/commands.c
  2. 14
      src/commands.h

26
src/commands.c

@ -116,6 +116,32 @@ f2b_cmd_help() {
return help;
}
f2b_cmd_t *
f2b_cmd_create(const char *line) {
f2b_cmd_t *cmd = NULL;
assert(line != NULL);
if ((cmd = calloc(1, sizeof(f2b_cmd_t))) == NULL)
return NULL;
if (f2b_buf_alloc(&cmd->data, strlen(line))) {
if (f2b_cmd_parse(cmd, line))
return cmd;
free(cmd);
cmd = NULL;
}
return cmd;
}
void
f2b_cmd_destroy(f2b_cmd_t *cmd) {
f2b_buf_free(&cmd->data);
free(cmd);
}
bool
f2b_cmd_parse(f2b_cmd_t *cmd, const char *src) {
char *p = NULL;

14
src/commands.h

@ -51,6 +51,20 @@ typedef struct f2b_cmd_t {
const char *
f2b_cmd_help();
/**
* @brief Creates new struct from user input
* @param line User input string
* @returns pointer to newly allocated struct or NULL on malloc()/parse error
*/
f2b_cmd_t *
f2b_cmd_create(const char *line);
/**
* @brief Frees memory
*/
void
f2b_cmd_destroy(f2b_cmd_t *cmd);
/**
* @brief Try to parse user input
* @param cmd pointer to preallocated f2b_cmd_t struct

Loading…
Cancel
Save