diff options
author | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-06-23 12:26:49 +0100 |
---|---|---|
committer | Stephen Dolan <mu@netsoc.tcd.ie> | 2013-06-23 12:26:49 +0100 |
commit | 8c2e228c74b99b800bb0169bb873e7d7db0f3f63 (patch) | |
tree | d584ebf3d1027d9bbad3e229fb74b5776aa784fe /jv_file.c | |
parent | 8630fb02bbb3c52409a4aaf682109e57a6642296 (diff) | |
download | jq-8c2e228c74b99b800bb0169bb873e7d7db0f3f63.tar.gz |
Fix the jv_parser interface.
Diffstat (limited to 'jv_file.c')
-rw-r--r-- | jv_file.c | 11 |
1 files changed, 5 insertions, 6 deletions
@@ -4,11 +4,10 @@ #include <stdlib.h> #include <string.h> #include "jv.h" -#include "jv_parse.h" jv jv_load_file(const char* filename, int raw) { FILE* file = fopen(filename, "r"); - struct jv_parser parser; + struct jv_parser* parser; jv data; if (!file) { return jv_invalid_with_msg(jv_string_fmt("Could not open %s: %s", @@ -19,7 +18,7 @@ jv jv_load_file(const char* filename, int raw) { data = jv_string(""); } else { data = jv_array(); - jv_parser_init(&parser); + parser = jv_parser_new(); } while (!feof(file) && !ferror(file)) { char buf[4096]; @@ -27,15 +26,15 @@ jv jv_load_file(const char* filename, int raw) { if (raw) { data = jv_string_concat(data, jv_string_sized(buf, (int)n)); } else { - jv_parser_set_buf(&parser, buf, n, !feof(file)); + jv_parser_set_buf(parser, buf, n, !feof(file)); jv value; - while (jv_is_valid((value = jv_parser_next(&parser)))) + while (jv_is_valid((value = jv_parser_next(parser)))) data = jv_array_append(data, value); jv_free(value); } } if (!raw) - jv_parser_free(&parser); + jv_parser_free(parser); int badread = ferror(file); fclose(file); if (badread) { |