|
|
@ -137,22 +137,22 @@ f2b_cmd_create(const char *line) { |
|
|
|
|
|
|
|
|
|
|
|
assert(line != NULL); |
|
|
|
assert(line != NULL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (isspace(*line)) line++; |
|
|
|
|
|
|
|
if (strlen(line) <= 0) |
|
|
|
|
|
|
|
return NULL; /* empty string */ |
|
|
|
|
|
|
|
|
|
|
|
if ((cmd = calloc(1, sizeof(f2b_cmd_t))) == NULL) |
|
|
|
if ((cmd = calloc(1, sizeof(f2b_cmd_t))) == NULL) |
|
|
|
return NULL; |
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
|
|
if (f2b_buf_alloc(&cmd->data, strlen(line))) { |
|
|
|
|
|
|
|
if (f2b_cmd_parse(cmd, line)) |
|
|
|
if (f2b_cmd_parse(cmd, line)) |
|
|
|
return cmd; |
|
|
|
return cmd; |
|
|
|
free(cmd); |
|
|
|
free(cmd); |
|
|
|
cmd = NULL; |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cmd; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|
f2b_cmd_destroy(f2b_cmd_t *cmd) { |
|
|
|
f2b_cmd_destroy(f2b_cmd_t *cmd) { |
|
|
|
|
|
|
|
if (!cmd) return; |
|
|
|
f2b_buf_free(&cmd->data); |
|
|
|
f2b_buf_free(&cmd->data); |
|
|
|
free(cmd); |
|
|
|
free(cmd); |
|
|
|
} |
|
|
|
} |
|
|
@ -168,6 +168,9 @@ f2b_cmd_parse(f2b_cmd_t *cmd, const char *src) { |
|
|
|
while (isblank(*src)) |
|
|
|
while (isblank(*src)) |
|
|
|
src++; |
|
|
|
src++; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (strlen(src) == 0) |
|
|
|
|
|
|
|
return false; /* empty string */ |
|
|
|
|
|
|
|
|
|
|
|
f2b_buf_alloc(&cmd->data, strlen(src) + 1); |
|
|
|
f2b_buf_alloc(&cmd->data, strlen(src) + 1); |
|
|
|
f2b_buf_append(&cmd->data, src, 0); |
|
|
|
f2b_buf_append(&cmd->data, src, 0); |
|
|
|
|
|
|
|
|
|
|
@ -234,6 +237,7 @@ f2b_cmd_parse(f2b_cmd_t *cmd, const char *src) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
cmd->type = CMD_UNKNOWN; |
|
|
|
cmd->type = CMD_UNKNOWN; |
|
|
|
|
|
|
|
memset(cmd->args, 0x0, sizeof(cmd->args)); |
|
|
|
f2b_buf_free(&cmd->data); |
|
|
|
f2b_buf_free(&cmd->data); |
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|