Beispiel #1
0
/** dump ast node to file at indent level */
static int genbind_ast_dump(FILE *dfile, struct genbind_node *node, int indent)
{
        const char *SPACES="                                                                               ";
        char *txt;
        int *val;

        while (node != NULL) {
                fprintf(dfile, "%.*s%s", indent, SPACES,
                        genbind_node_type_to_str(node->type));

                txt = genbind_node_gettext(node);
                if (txt == NULL) {
                        val = genbind_node_getint(node);
                        if (val == NULL) {
                                fprintf(dfile, "\n");
                                genbind_ast_dump(dfile,
                                                 genbind_node_getnode(node),
                                                 indent + 2);
                        } else {
                                fprintf(dfile, ": %d\n", *val);
                        }
                } else {
                        fprintf(dfile, ": \"%.*s\"\n", 75 - indent, txt);
                }
                node = node->l;
        }
        return 0;
}
Beispiel #2
0
int genbind_ast_dump(struct genbind_node *node, int indent)
{
	const char *SPACES="                                                                               ";
	char *txt;

	while (node != NULL) {
		printf("%.*s%s", indent, SPACES,  genbind_node_type_to_str(node->type));

		txt = genbind_node_gettext(node);
		if (txt == NULL) {
			printf("\n");
			genbind_ast_dump(genbind_node_getnode(node), indent + 2);
		} else {
			printf(": \"%.*s\"\n", 75 - indent, txt);
		}
		node = node->l;
	}
	return 0;
}
Beispiel #3
0
/* exported interface documented in nsgenbind-ast.h */
int genbind_dump_ast(struct genbind_node *node)
{
        FILE *dumpf;

        /* only dump AST to file if required */
        if (!options->debug) {
                return 0;
        }

        dumpf = genb_fopen("binding-ast", "w");
        if (dumpf == NULL) {
                return 2;
        }

        genbind_ast_dump(dumpf, node, 0);

        fclose(dumpf);

        return 0;
}
Beispiel #4
0
int main(int argc, char **argv)
{
	int res;
	struct genbind_node *genbind_root;

	options = process_cmdline(argc, argv);
	if (options == NULL) {
		return 1; /* bad commandline */
	}

	if (options->verbose && 
	    (options->outfilename == NULL)) {
		fprintf(stderr, 
			"Error: output to stdout with verbose logging would fail\n");
		return 2;
	}

	if (options->depfilename != NULL &&
	    options->outfilename == NULL) {
		fprintf(stderr,
			"Error: output to stdout with dep generation would fail\n");
		return 3;
	}

	if (options->depfilename != NULL &&
	    options->infilename == NULL) {
		fprintf(stderr,
			"Error: input from stdin with dep generation would fail\n");
		return 3;
	}

	if (options->depfilename != NULL) {
		options->depfilehandle = fopen(options->depfilename, "w");
		if (options->depfilehandle == NULL) {
			fprintf(stderr,
				"Error: unable to open dep file\n");
			return 4;
		}
		fprintf(options->depfilehandle,
			"%s %s :", options->depfilename,
			options->outfilename);
	}

	res = genbind_parsefile(options->infilename, &genbind_root);
	if (res != 0) {
		fprintf(stderr, "Error: parse failed with code %d\n", res);
		return res;
	}

	if (options->verbose) {
		genbind_ast_dump(genbind_root, 0);
	}

	res = jsapi_libdom_output(options->outfilename, 
				  options->hdrfilename, 
				  genbind_root);
	if (res != 0) {
		fprintf(stderr, "Error: output failed with code %d\n", res);
		if (options->outfilename != NULL) {
			unlink(options->outfilename);
		}
		if (options->hdrfilename != NULL) {
			unlink(options->hdrfilename);
		} 
		return res;
	}

	if (options->depfilehandle != NULL) {
		fputc('\n', options->depfilehandle);
		fclose(options->depfilehandle);
	}

	return 0;
}