diff --git a/jsoncat.c b/jsoncat.c index 77fbab6..bda444d 100644 --- a/jsoncat.c +++ b/jsoncat.c @@ -64,16 +64,10 @@ void json_print(json_object *j, int depth) { } } -int main() { +void process(FILE *f) { json_object *j = NULL; - while ((j = json_parse(stdin, j)) != NULL) { - json_object *g = json_hash_get(j, "type"); - if (g != NULL && g->type == JSON_STRING && strcmp(g->string, "Feature") == 0) { - json_print(j, 0); - printf("\n"); - } - + while ((j = json_parse(f, j)) != NULL) { if (j->parent == NULL) { json_print(j, 0); printf("\n"); @@ -81,3 +75,20 @@ int main() { } } } + +int main(int argc, char **argv) { + if (argc == 1) { + process(stdin); + } else { + int i; + for (i = 1; i < argc; i++) { + FILE *f = fopen(argv[i], "r"); + if (f == NULL) { + perror(argv[i]); + exit(EXIT_FAILURE); + } + process(f); + fclose(f); + } + } +}