summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2013-01-02 16:55:45 +0000
committerVincent Sanders <vince@kyllikki.org>2013-01-02 16:55:45 +0000
commit3b19d1d1ad88ba63ae821b2aedd4005466ed52fa (patch)
tree5a167270b6c2a2627e2b53113519e433ffb63279 /src
parent841ecdf404e166945f5cc6cd320ca15dfb93b57c (diff)
downloadnsgenbind-3b19d1d1ad88ba63ae821b2aedd4005466ed52fa.tar.gz
nsgenbind-3b19d1d1ad88ba63ae821b2aedd4005466ed52fa.tar.bz2
Add epilogue output
Add header guard generation
Diffstat (limited to 'src')
-rw-r--r--src/jsapi-libdom.c65
-rw-r--r--src/jsapi-libdom.h2
-rw-r--r--src/nsgenbind-ast.h2
3 files changed, 69 insertions, 0 deletions
diff --git a/src/jsapi-libdom.c b/src/jsapi-libdom.c
index 4fbe67b..39225ea 100644
--- a/src/jsapi-libdom.c
+++ b/src/jsapi-libdom.c
@@ -11,6 +11,7 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <ctype.h>
#include "options.h"
#include "nsgenbind-ast.h"
@@ -68,6 +69,15 @@ static int webidl_preamble_cb(struct genbind_node *node, void *ctx)
return 0;
}
+static int webidl_epilogue_cb(struct genbind_node *node, void *ctx)
+{
+ struct binding *binding = ctx;
+
+ fprintf(binding->outfile, "%s", genbind_node_gettext(node));
+
+ return 0;
+}
+
static int webidl_hdrcomments_cb(struct genbind_node *node, void *ctx)
{
@@ -597,6 +607,42 @@ output_preamble(struct binding *binding)
fprintf(binding->outfile,"\n\n");
+ if (binding->hdrfile) {
+ binding->outfile = binding->hdrfile;
+
+ fprintf(binding->outfile,
+ "#ifndef _%s_\n"
+ "#define _%s_\n\n",
+ binding->hdrguard,
+ binding->hdrguard);
+
+ binding->outfile = binding->srcfile;
+ }
+
+
+ return 0;
+}
+
+static int
+output_epilogue(struct binding *binding)
+{
+ genbind_node_for_each_type(binding->gb_ast,
+ GENBIND_NODE_TYPE_EPILOGUE,
+ webidl_epilogue_cb,
+ binding);
+
+ fprintf(binding->outfile,"\n\n");
+
+ if (binding->hdrfile) {
+ binding->outfile = binding->hdrfile;
+
+ fprintf(binding->outfile,
+ "\n\n#endif /* _%s_ */\n",
+ binding->hdrguard);
+
+ binding->outfile = binding->srcfile;
+ }
+
return 0;
}
@@ -679,6 +725,7 @@ binding_new(char *outfilename,
struct genbind_node *interface_node;
FILE *outfile = NULL; /* output source file */
FILE *hdrfile = NULL; /* output header file */
+ char *hdrguard = NULL;
struct webidl_node *webidl_ast = NULL;
int res;
@@ -730,6 +777,9 @@ binding_new(char *outfilename,
/* output header file if required */
if (hdrfilename != NULL) {
+ int guardlen;
+ int pos;
+
hdrfile = fopen(hdrfilename, "w");
if (hdrfile == NULL) {
fprintf(stderr, "Error opening header output %s: %s\n",
@@ -738,6 +788,15 @@ binding_new(char *outfilename,
fclose(outfile);
return NULL;
}
+ guardlen = strlen(hdrfilename);
+ hdrguard = calloc(1, guardlen + 1);
+ for (pos = 0; pos < guardlen; pos++) {
+ if (isalpha(hdrfilename[pos])) {
+ hdrguard[pos] = toupper(hdrfilename[pos]);
+ } else {
+ hdrguard[pos] = '_';
+ }
+ }
}
nb = calloc(1, sizeof(struct binding));
@@ -749,6 +808,7 @@ binding_new(char *outfilename,
nb->outfile = outfile;
nb->srcfile = outfile;
nb->hdrfile = hdrfile;
+ nb->hdrguard = hdrguard;
nb->has_private = binding_has_private(binding_list);
nb->has_global = binding_has_global(nb);
nb->binding_list = binding_list;
@@ -849,6 +909,11 @@ jsapi_libdom_output(char *outfilename,
return 150;
}
+ res = output_epilogue(binding);
+ if (res) {
+ return 160;
+ }
+
fclose(binding->outfile);
return 0;
diff --git a/src/jsapi-libdom.h b/src/jsapi-libdom.h
index bdc941d..a263efa 100644
--- a/src/jsapi-libdom.h
+++ b/src/jsapi-libdom.h
@@ -24,6 +24,8 @@ struct binding {
struct genbind_node *finalise; /* binding api finalise node or NULL */
struct genbind_node *mark; /* binding api mark node or NULL */
+ const char *hdrguard; /* header file guard name */
+
FILE *outfile ; /* file handle output should be written to,
* allows reuse of callback routines to output
* to headers and source files
diff --git a/src/nsgenbind-ast.h b/src/nsgenbind-ast.h
index 6368519..4e2ffee 100644
--- a/src/nsgenbind-ast.h
+++ b/src/nsgenbind-ast.h
@@ -20,6 +20,8 @@ enum genbind_node_type {
GENBIND_NODE_TYPE_HDRCOMMENT,
GENBIND_NODE_TYPE_STRING,
GENBIND_NODE_TYPE_PREAMBLE,
+ GENBIND_NODE_TYPE_PROLOGUE,
+ GENBIND_NODE_TYPE_EPILOGUE,
GENBIND_NODE_TYPE_BINDING,
GENBIND_NODE_TYPE_BINDING_PRIVATE,
GENBIND_NODE_TYPE_BINDING_INTERNAL,