summaryrefslogtreecommitdiff
path: root/src/nsgenbind.c
diff options
context:
space:
mode:
authorVincent Sanders <vincent.sanders@collabora.co.uk>2012-10-23 17:43:09 +0100
committerVincent Sanders <vincent.sanders@collabora.co.uk>2012-10-23 17:43:09 +0100
commitb00346cd08b55d25e427cfabafbaa66e09a8444b (patch)
treee3b6477843762d86698b70fd27fec28b52fc22db /src/nsgenbind.c
parent0c61abc9f71a128c5045738af3489aac743986bd (diff)
downloadnsgenbind-b00346cd08b55d25e427cfabafbaa66e09a8444b.tar.gz
nsgenbind-b00346cd08b55d25e427cfabafbaa66e09a8444b.tar.bz2
The name of teh tool is nsgenbind correct this everywhere
Diffstat (limited to 'src/nsgenbind.c')
-rw-r--r--src/nsgenbind.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/src/nsgenbind.c b/src/nsgenbind.c
new file mode 100644
index 0000000..14854ad
--- /dev/null
+++ b/src/nsgenbind.c
@@ -0,0 +1,108 @@
+/* binding generator main and command line parsing
+ *
+ * This file is part of nsgenbind.
+ * Licensed under the MIT License,
+ * http://www.opensource.org/licenses/mit-license.php
+ * Copyright 2012 Vincent Sanders <vince@netsurf-browser.org>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <errno.h>
+
+#include "nsgenbind-ast.h"
+#include "jsapi-libdom.h"
+#include "options.h"
+
+struct options *options;
+
+static struct options* process_cmdline(int argc, char **argv)
+{
+ int opt;
+
+ options = calloc(1,sizeof(struct options));
+ if (options == NULL) {
+ fprintf(stderr, "Allocation error\n");
+ return NULL;
+ }
+
+ while ((opt = getopt(argc, argv, "vdI:o:")) != -1) {
+ switch (opt) {
+ case 'I':
+ options->idlpath = strdup(optarg);
+ break;
+
+ case 'o':
+ options->outfilename = strdup(optarg);
+ break;
+
+ case 'v':
+ options->verbose = true;
+ break;
+
+ case 'd':
+ options->debug = true;
+ break;
+
+ default: /* '?' */
+ fprintf(stderr,
+ "Usage: %s [-I idlpath] [-o filename] inputfile\n",
+ argv[0]);
+ free(options);
+ return NULL;
+
+ }
+ }
+
+ if (optind >= argc) {
+ fprintf(stderr, "Error: expected input filename\n");
+ free(options);
+ return NULL;
+ }
+
+ options->infilename = strdup(argv[optind]);
+
+ return options;
+
+}
+
+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;
+ }
+
+ 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, genbind_root);
+ if (res != 0) {
+ fprintf(stderr, "Error: output failed with code %d\n", res);
+ unlink(options->outfilename);
+ return res;
+ }
+
+ return 0;
+}