X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obcl%2Fobcl.c;h=a4b58eec2e9cc0f87bc5fdb889b42a9e6e8a0b06;hb=f8c712f53470fd651dbbc785f71045645cbcd8ed;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hpb=d0e9015651aa960cf8cb58a5ab08da79e6aeb51b;p=chaz%2Fopenbox diff --git a/obcl/obcl.c b/obcl/obcl.c index e69de29b..a4b58eec 100644 --- a/obcl/obcl.c +++ b/obcl/obcl.c @@ -0,0 +1,84 @@ +#include "obcl.h" + +void cl_tree_free(GList *tree) +{ + CLNode *tmp; + + if (!tree) return; + + for (; tree; tree = tree->next) { + tmp = (CLNode*)tree->data; + switch(tmp->type) { + case CL_ID: + case CL_STR: + g_free(tmp->u.str); + break; + case CL_LIST: + case CL_BLOCK: + case CL_LISTBLOCK: + g_free(tmp->u.lb.id); + cl_tree_free(tmp->u.lb.list); + cl_tree_free(tmp->u.lb.block); + break; + default: + break; + } + g_free(tmp); + } + g_list_free(tree); +} + +GList *cl_parse(gchar *file) +{ + FILE *fh = fopen(file, "r"); + GList *ret = NULL; + + if (fh) { + ret = cl_parse_fh(fh); + fclose(fh); + } else { + perror(file); + } + + return ret; +} + +void cl_tree_print(GList *tree, int depth) +{ + CLNode *tmp; + int tmpd = depth; + + for (; tree; tree = tree->next) { + tmp = (CLNode*)tree->data; + + while (tmpd-- > 0) + printf(" "); + tmpd = depth; + + switch(tmp->type) { + case CL_ID: + printf("--ID-- %s\n", tmp->u.str); + break; + case CL_STR: + printf("--STR-- %s\n", tmp->u.str); + break; + case CL_NUM: + printf("--NUM-- %.2f\n", tmp->u.num); + break; + case CL_LIST: + printf("--LIST-- %s\n", tmp->u.lb.id); + cl_tree_print(tmp->u.lb.list, depth+2); + break; + case CL_BLOCK: + printf("--BLOCK-- %s\n", tmp->u.lb.id); + cl_tree_print(tmp->u.lb.block, depth+2); + break; + case CL_LISTBLOCK: + printf("--LISTBLOCK-- %s\n", tmp->u.lb.id); + cl_tree_print(tmp->u.lb.list, depth+2); + printf("\n"); + cl_tree_print(tmp->u.lb.block, depth+2); + break; + } + } +}