summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjorn Reese <breese@sourceforge.net>2013-02-19 13:41:26 +0100
committerLloyd Hilaiel <lloyd@hilaiel.com>2014-02-15 10:47:00 +0100
commit468f21940b354e2b4990d0d95a2ed44b177d5d22 (patch)
tree98f00bc1664b785b80c3ef5fb9131bdacd3b65aa
parent5d4bf5250180cec3f12d192023870ea74a19013b (diff)
downloadyajl-468f21940b354e2b4990d0d95a2ed44b177d5d22.tar.gz
Allow file argument
-rw-r--r--test/parsing/yajl_test.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/test/parsing/yajl_test.c b/test/parsing/yajl_test.c
index e876c90..c50755b 100644
--- a/test/parsing/yajl_test.c
+++ b/test/parsing/yajl_test.c
@@ -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