Browse Source

+ added main loop for file reading

master
Alex 'AdUser' Z 13 years ago
parent
commit
d4d17668d7
  1. 18
      src/json2torrent.c

18
src/json2torrent.c

@ -15,6 +15,8 @@ FILE *out;
struct yajl_handle_t *handle = NULL; struct yajl_handle_t *handle = NULL;
struct yajl_gen_t *gen = NULL; struct yajl_gen_t *gen = NULL;
#define BUF_SIZE (64 * 1024)
static int static int
write_integer(void *ctx, long long l) write_integer(void *ctx, long long l)
{ {
@ -70,6 +72,8 @@ check_yajl_error(struct yajl_handle_t *handle, unsigned char *buf, size_t read)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
static unsigned char buf[BUF_SIZE];
size_t read = 0;
/* FILE */ in = stdin; /* FILE */ in = stdin;
/* FILE */ out = stdout; /* FILE */ out = stdout;
@ -81,7 +85,19 @@ main(int argc, char **argv)
yajl_config(handle, yajl_allow_comments, 1); yajl_config(handle, yajl_allow_comments, 1);
yajl_config(handle, yajl_dont_validate_strings, 1); yajl_config(handle, yajl_dont_validate_strings, 1);
/* some work here */ while ((read = fread(buf, 1, (BUF_SIZE - 1), in)) != 0)
{
buf[read] = '\0';
if (yajl_parse(handle, buf, read) != yajl_status_ok)
{
check_yajl_error(handle, buf, read);
break;
}
}
if (yajl_complete_parse(handle) != yajl_status_ok)
check_yajl_error(handle, buf, read);
yajl_free(handle); yajl_free(handle);

Loading…
Cancel
Save