Handle named files, not just standard input

This commit is contained in:
Eric Fischer 2014-02-05 22:00:52 -08:00
parent 264abd48de
commit 7641459278

View File

@ -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);
}
}
}