Permalink
Browse files

Allow file argument

  • Loading branch information...
1 parent 5d4bf52 commit 468f21940b354e2b4990d0d95a2ed44b177d5d22 Bjorn Reese committed with Feb 19, 2013
Showing with 17 additions and 7 deletions.
  1. +17 −7 test/parsing/yajl_test.c
View
@@ -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;
@@ -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;
}
}
@@ -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)) {
@@ -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

0 comments on commit 468f219

Please sign in to comment.