diff options
| author | bozo.kopic <bozo@kopic.xyz> | 2021-12-22 03:31:04 +0100 |
|---|---|---|
| committer | bozo.kopic <bozo@kopic.xyz> | 2021-12-22 03:31:04 +0100 |
| commit | 7dedbce91b8cb6cfbb1571f2c6dccb968d93351d (patch) | |
| tree | 68670b3ff3f2b913fdf79bcbd881dc64de678fb7 /src_c/main.c | |
| parent | 3b22a7aee8644b26da7babfc9ea83b9cb8c7289c (diff) | |
WIP c implementation
Diffstat (limited to 'src_c/main.c')
| -rw-r--r-- | src_c/main.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src_c/main.c b/src_c/main.c new file mode 100644 index 0000000..9cc71ed --- /dev/null +++ b/src_c/main.c @@ -0,0 +1,57 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "common.h" + + +static int read_stdin(opcut_str_t *json) { + size_t json_data_size = 0; + json->data = NULL; + json->len = 0; + + while (!(json->len < json_data_size)) { + char *old_json_data = json->data; + json_data_size += 4096; + json->data = realloc(json->data, json_data_size); + if (!json->data) { + free(old_json_data); + return OPCUT_ERROR; + } + json->len += + fread(json->data + json->len, 1, json_data_size - json->len, stdin); + } + + return OPCUT_SUCCESS; +} + + +int main(int argc, char **argv) { + char *method = NULL; + for (size_t i = 1; i < argc - 1; ++i) { + if (strcmp("--method", argv[i]) == 0) + method = argv[++i]; + } + + opcut_str_t json; + if (!read_stdin(&json)) + return OPCUT_ERROR; + + opcut_params_t params; + if (!opcut_params_init(¶ms, &json)) { + free(json.data); + return OPCUT_ERROR; + } + + opcut_result_t result = {.params = ¶ms, + .used = NULL, + .used_len = 0, + .unused = NULL, + .unused_len = 0}; + + size_t res = opcut_result_write(&result, stdout); + + opcut_params_destroy(¶ms); + free(json.data); + + return res; +} |
