mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 18:35:41 +02:00
Add the whole-tree reader
This commit is contained in:
@@ -122,7 +122,7 @@ void process_callback(FILE *f, char *fname) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process(FILE *f, char *fname) {
|
void process_incremental(FILE *f, char *fname) {
|
||||||
json_pull *jp = json_begin_file(f);
|
json_pull *jp = json_begin_file(f);
|
||||||
json_object *j;
|
json_object *j;
|
||||||
|
|
||||||
@@ -139,9 +139,29 @@ void process(FILE *f, char *fname) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void process_tree(FILE *f, char *fname) {
|
||||||
|
json_pull *jp = json_begin_file(f);
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
json_object *j = json_read_tree(jp);
|
||||||
|
|
||||||
|
if (j == NULL) {
|
||||||
|
if (jp->error != NULL) {
|
||||||
|
fprintf(stderr, "%s: %d: %s\n", fname, jp->line, jp->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_print(j, 0);
|
||||||
|
json_free(j);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
process(stdin, "standard input");
|
process_tree(stdin, "standard input");
|
||||||
} else {
|
} else {
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
@@ -150,7 +170,7 @@ int main(int argc, char **argv) {
|
|||||||
perror(argv[i]);
|
perror(argv[i]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
process(f, argv[i]);
|
process_tree(f, argv[i]);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
@@ -55,6 +55,10 @@ json_pull *json_begin_string(char *s) {
|
|||||||
return json_begin(read_string, peek_string, s);
|
return json_begin(read_string, peek_string, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void json_end(json_pull *p) {
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
static int read_wrap(json_pull *j) {
|
static int read_wrap(json_pull *j) {
|
||||||
int c = j->read(j);
|
int c = j->read(j);
|
||||||
|
|
||||||
@@ -475,6 +479,18 @@ json_object *json_read(json_pull *j) {
|
|||||||
return json_read_with_separators(j, NULL, NULL);
|
return json_read_with_separators(j, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
json_object *json_read_tree(json_pull *p) {
|
||||||
|
json_object *j;
|
||||||
|
|
||||||
|
while ((j = json_read(p)) != NULL) {
|
||||||
|
if (j->parent == NULL) {
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void json_free(json_object *o) {
|
void json_free(json_object *o) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user