Skip to content

Commit

Permalink
Allow file argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjorn Reese authored and lloyd committed Feb 15, 2014
1 parent 5d4bf52 commit 468f219
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions test/parsing/yajl_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ int
main(int argc, char ** argv)
{
yajl_handle hand;
const char * fileName;
const char * fileName = NULL;
static unsigned char * fileData = NULL;
FILE *file;
size_t bufSize = BUF_SIZE;
yajl_status stat;
size_t rd;
Expand Down Expand Up @@ -220,9 +221,8 @@ main(int argc, char ** argv)
} else if (!strcmp("-p", argv[i])) {
yajl_config(hand, yajl_allow_partial_values, 1);
} else {
fprintf(stderr, "invalid command line option: '%s'\n",
argv[i]);
usage(argv[0]);
fileName = argv[i];
break;
}
}

Expand All @@ -236,10 +236,16 @@ main(int argc, char ** argv)
exit(2);
}

fileName = argv[argc-1];

if (fileName)
{
file = fopen(fileName, "r");
}
else
{
file = stdin;
}
for (;;) {
rd = fread((void *) fileData, 1, bufSize, stdin);
rd = fread((void *) fileData, 1, bufSize, file);

if (rd == 0) {
if (!feof(stdin)) {
Expand All @@ -265,6 +271,10 @@ main(int argc, char ** argv)
yajl_free(hand);
free(fileData);

if (fileName)
{
fclose(file);
}
/* finally, print out some memory statistics */

/* (lth) only print leaks here, as allocations and frees may vary depending
Expand Down

0 comments on commit 468f219

Please sign in to comment.