# HG changeset patch # User John Tsiombikas # Date 1464866737 -10800 # Node ID 75807c6b939b852a6e56a8136ee1d1d6463d4b07 initial commit diff -r 000000000000 -r 75807c6b939b Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Thu Jun 02 14:25:37 2016 +0300 @@ -0,0 +1,14 @@ +src = $(wildcard src/*.c) +obj = $(src:.c=.o) + +bin = test + +CFLAGS = -pedantic -Wall -g +LDFLAGS = -ljansson + +$(bin): $(obj) + $(CC) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) diff -r 000000000000 -r 75807c6b939b src/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.c Thu Jun 02 14:25:37 2016 +0300 @@ -0,0 +1,152 @@ +#include +#include +#include +#include +#include + +void proc_osg_node(const char *node_type, json_t *node, int level); +void proc_geometry(json_t *node, int level); +void proc_primitive(json_t *prim, int level); +json_t *find_node(json_t *node, const char *key); + +int main(int argc, char **argv) +{ + FILE *fp = stdin; + json_t *root, *osgnode; + json_error_t err; + + if(argc > 1) { + if(!(fp = fopen(argv[1], "r"))) { + fprintf(stderr, "failed to open osgjs file: %s: %s\n", argv[1], strerror(errno)); + return 1; + } + } + + if(!(root = json_loadf(fp, 0, &err))) { + fprintf(stderr, "json parsing error at %d:%d: %s\n", err.line, err.column, err.text); + return 1; + } + if(!json_is_object(root)) { + fprintf(stderr, "root node is not an object!\n"); + return 1; + } + if(!(osgnode = json_object_get(root, "osg.Node"))) { + fprintf(stderr, "root doesn't have an osg.Node field!\n"); + return 1; + } + proc_osg_node("osg.Node", osgnode, 0); + + json_decref(root); + return 0; +} + +void indent(int n) +{ + while(n--) { + putchar(' '); + } +} + +void proc_osg_node(const char *node_type, json_t *node, int level) +{ + json_t *children, *name_field; + const char *name = 0; + + if((name_field = json_object_get(node, "Name"))) { + if(json_is_string(name_field)) { + name = json_string_value(name_field); + } + } + + indent(level); + printf("%s: %s\n", node_type, name ? name : ""); + + if(strcmp(node_type, "osg.Geometry") == 0) { + proc_geometry(node, level); + } + + if((children = json_object_get(node, "Children")) && json_is_array(children)) { + int i, num = json_array_size(children); + + for(i=0; i