#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
#include <sys/stat.h>
#include "tree.h"
extern GList *include_files;
+extern GHashTable *gtk_doc_hash;
+
char *filebase;
static char *funcbase;
static char *pfuncbase;
FILE *out = NULL;
FILE *outh = NULL;
FILE *outph = NULL;
+FILE *devnull = NULL;
gboolean no_touch_headers = FALSE;
gboolean for_cpp = FALSE;
gboolean always_private_header = FALSE;
gboolean no_private_header = FALSE;
gboolean no_extern_c = FALSE;
+gboolean no_write = FALSE;
static void
make_bases(void)
{
- filebase = replace_sep(((Class *)class)->otype,'-');
+ filebase = replace_sep(((Class *)class)->otype, '-');
g_strdown(filebase);
- funcbase = replace_sep(((Class *)class)->otype,'_');
+ funcbase = replace_sep(((Class *)class)->otype, '_');
g_strdown(funcbase);
- pfuncbase = replace_sep(((Class *)class)->ptype,'_');
+ pfuncbase = replace_sep(((Class *)class)->ptype, '_');
g_strdown(pfuncbase);
- macrobase = replace_sep(((Class *)class)->otype,'_');
+ macrobase = replace_sep(((Class *)class)->otype, '_');
g_strup(macrobase);
- macrois = make_pre_macro(((Class *)class)->otype,"IS");
- macrotype = make_pre_macro(((Class *)class)->otype,"TYPE");
+ macrois = make_pre_macro(((Class *)class)->otype, "IS");
+ macrotype = make_pre_macro(((Class *)class)->otype, "TYPE");
typebase = remove_sep(((Class *)class)->otype);
}
g_string_append_c(gs,' ');
- for(i=0;i<(t->stars+extra);i++)
- g_string_append_c(gs,'*');
+ for(i=0; i<(t->stars+extra); i++)
+ g_string_append_c(gs, '*');
s = gs->str;
- g_string_free(gs,FALSE);
+ g_string_free(gs, FALSE);
return s;
}
+static char *
+get_gtk_doc(char *id)
+{
+ char *val, *s;
+
+ if(!gtk_doc_hash)
+ return NULL;
+
+ val = g_hash_table_lookup(gtk_doc_hash, id);
+ if(val)
+ return g_strdup_printf("/**\n * %s_%s:\n%s **/\n",
+ funcbase, id, val);
+ s = g_strconcat(funcbase, "_", id, NULL);
+ val = g_hash_table_lookup(gtk_doc_hash, s);
+ g_free(s);
+ if(val)
+ return g_strdup_printf("/**\n * %s_%s:\n%s **/\n",
+ funcbase, id, val);
+ return NULL;
+}
+
static void
print_type(FILE *fp, Type *t, gboolean postfix_to_stars)
{
char *s;
- s = get_type(t,postfix_to_stars);
- out_printf(fp,"%s",s);
+ s = get_type(t, postfix_to_stars);
+ out_printf(fp, "%s", s);
g_free(s);
}
static void
print_method(FILE *fp, char *typeprefix, char *nameprefix,
- char *namepostfix,char *postfix, Method *m,
+ char *subnameprefix,
+ char *namepostfix, char *postfix, Method *m,
+ gboolean one_arg_per_line,
gboolean no_funcbase)
{
GList *li;
- out_printf(fp,"%s",typeprefix);
- print_type(fp,m->mtype,TRUE);
+ out_printf(fp, "%s", typeprefix);
+ print_type(fp, m->mtype, TRUE);
if(no_funcbase)
- out_printf(fp,"%s%s%s(",
- nameprefix,m->id,namepostfix);
+ out_printf(fp, "%s%s%s%s(",
+ nameprefix, subnameprefix, m->id, namepostfix);
else
- out_printf(fp,"%s%s_%s%s(",
- nameprefix,funcbase,m->id,namepostfix);
+ out_printf(fp,"%s%s_%s%s%s(",
+ nameprefix, funcbase, subnameprefix, m->id,
+ namepostfix);
if(m->args) {
- for(li=m->args;li;li=g_list_next(li)) {
+ for(li=m->args; li; li=g_list_next(li)) {
FuncArg *arg = li->data;
- print_type(fp,arg->atype,FALSE);
+ print_type(fp, arg->atype, FALSE);
if(li->next)
- out_printf(fp,"%s%s, ",arg->name,
+ out_printf(fp, "%s%s,%s", arg->name,
arg->atype->postfix?
- arg->atype->postfix:"");
+ arg->atype->postfix:"",
+ one_arg_per_line?"\n\t\t\t\t\t":" ");
else
- out_printf(fp,"%s%s",arg->name,
+ out_printf(fp, "%s%s", arg->name,
arg->atype->postfix?
arg->atype->postfix:"");
}
if(m->vararg)
- out_printf(fp,", ...");
+ out_printf(fp, ",%s...",
+ one_arg_per_line?"\n\t\t\t\t\t":" ");
} else {
- out_printf(fp,"void");
+ out_printf(fp, "void");
}
- out_printf(fp,")%s",postfix);
+ out_printf(fp, ")%s", postfix);
}
{
GList *li;
- for(li=c->nodes;li;li=g_list_next(li)) {
+ for(li=c->nodes; li; li=g_list_next(li)) {
Node *node = li->data;
if(node->type == METHOD_NODE) {
Method *m = (Method *)node;
continue;
/* in C++ mode don't alias new */
- if(for_cpp && strcmp(m->id,"new")==0)
+ if(for_cpp && strcmp(m->id, "new")==0)
continue;
- print_method(out,"static ","(* ",") ","",m,TRUE);
- out_printf(out," = %s_%s;\n",funcbase,m->id);
+ print_method(out, "static ", "(* ", "", ") ", "",
+ m, FALSE, TRUE);
+ out_printf(out, " = %s_%s;\n", funcbase, m->id);
made_aliases = TRUE;
}
m->method != VIRTUAL_METHOD)
return;
- print_method(outh,"\t","(* ",") ",";\n",m,TRUE);
+ /* if a signal mark it as such */
+ if(m->method != VIRTUAL_METHOD)
+ print_method(outh,"\t/*signal*/","(* ","",") ",";\n",m,
+ FALSE,TRUE);
+ else
+ print_method(outh,"\t","(* ","",") ",";\n",m,FALSE,TRUE);
}
static void
if(m->scope != PUBLIC_SCOPE)
return;
- print_method(outh,"","\t","\t",";\n",m,FALSE);
+ print_method(outh,"","\t","","\t",";\n",m,TRUE,FALSE);
}
+/* I'm starting not to like this idea */
+#if 0
+static void
+put_signal_connect(Method *m)
+{
+ if(m->method != SIGNAL_LAST_METHOD &&
+ m->method != SIGNAL_FIRST_METHOD)
+ return;
+
+ out_printf(outh, "guint \t%s_%s__connect_full\t(%s *object,\n"
+ "\t\t\t\t\tconst char *name,\n"
+ "\t\t\t\t\tGtkSignalFunc func,\n"
+ "\t\t\t\t\tGtkCallbackMarshal marshal,\n"
+ "\t\t\t\t\tgpointer data,\n"
+ "\t\t\t\t\tGtkDestroyNotify destroy_func,\n"
+ "\t\t\t\t\tgboolean object_signal,\n"
+ "\t\t\t\t\tgboolean after);\n",
+ funcbase, m->id, typebase);
+
+ out_printf(outh, "#define %s_%s__connect(object,name,func,data) "
+ "%s_%s__connect_full((object),(name),(func),NULL,"
+ "(data),NULL,FALSE,FALSE)\n",
+ funcbase, m->id, funcbase, m->id);
+ out_printf(outh, "#define %s_%s__connect_after(object,name,func,data) "
+ "%s__connect_%s_full((object),(name),(func),NULL,"
+ "(data),NULL,FALSE,TRUE)\n",
+ funcbase, m->id, funcbase, m->id);
+
+ out_printf(outh, "guint \t%s_%s__connect_while_alive\t(%s *object,\n"
+ "\t\t\t\t\tconst char *name,\n"
+ "\t\t\t\t\tGtkSignalFunc func,\n"
+ "\t\t\t\t\tgpointer data,\n"
+ "\t\t\t\t\tGtkObject *alive_object);\n\n",
+ funcbase, m->id, typebase);
+}
+#endif
+
+
static void
put_prot_method(Method *m)
{
return;
if(outph)
- print_method(outph,"","\t","\t",";\n",m,FALSE);
+ print_method(outph,"","\t","","\t",";\n",m,FALSE,FALSE);
else
- print_method(out,"","\t","\t",";\n",m,FALSE);
+ print_method(out,"","\t","","\t",";\n",m,FALSE,FALSE);
}
static void
m->method == SIGNAL_FIRST_METHOD ||
m->method == VIRTUAL_METHOD) {
if(m->cbuf)
- print_method(out,"static ","___real_"," ",";\n",m,FALSE);
+ print_method(out,
+ "static ", "___real_", "", " ", ";\n",
+ m, FALSE, FALSE);
}
if(m->scope == PRIVATE_SCOPE ||
m->method == CLASS_INIT_METHOD ||
(m->method == OVERRIDE_METHOD &&
m->cbuf))
- print_method(out,"static ",""," ",
- no_gnu?";\n":" ___NO_UNUSED_WARNING;\n"
- ,m,FALSE);
+ print_method(out, "static ", "", "", " ",
+ no_gnu?";\n":" G_GNUC_UNUSED;\n",
+ m, FALSE, FALSE);
}
static GList *
}
if(!got_class_init) {
node = new_method(NO_SCOPE, CLASS_INIT_METHOD,
- (Type *)new_type(0,g_strdup("void"),NULL),
- NULL,NULL,g_strdup("class_init"),
- make_func_arg(cl->otype,TRUE,g_strdup("c")),
- NULL, NULL,0,0,FALSE);
+ (Type *)new_type(0, g_strdup("void"),NULL),
+ NULL, NULL, NULL, g_strdup("class_init"),
+ make_func_arg(cl->otype, TRUE, g_strdup("c")),
+ NULL, NULL, 0, 0, FALSE);
cl->nodes = g_list_prepend(cl->nodes,node);
}
if(!got_init) {
node = new_method(NO_SCOPE, INIT_METHOD,
- (Type *)new_type(0,g_strdup("void"),NULL),
- NULL,NULL,g_strdup("init"),
- make_func_arg(cl->otype,FALSE,g_strdup("o")),
- NULL, NULL,0,0,FALSE);
+ (Type *)new_type(0, g_strdup("void"),NULL),
+ NULL, NULL, NULL, g_strdup("init"),
+ make_func_arg(cl->otype, FALSE, g_strdup("o")),
+ NULL, NULL, 0, 0, FALSE);
cl->nodes = g_list_prepend(cl->nodes,node);
}
}
if(n->type == METHOD_NODE) {
Method *m = (Method *)n;
if(m->method == OVERRIDE_METHOD &&
- strcmp(m->id,"finalize")==0) {
- if(strcmp(m->otype,"Gtk:Object")==0) {
+ strcmp(m->id, "finalize")==0) {
+ if(strcmp(m->otype, "Gtk:Object")==0) {
got_finalize = TRUE;
break;
- } else {
- print_error(FALSE,"finalize method override "
- "of class other then Gtk:Object",
- m->line_no);
}
-
+ print_error(FALSE,"finalize method override "
+ "of class other then Gtk:Object",
+ m->line_no);
}
}
}
node = new_method(NO_SCOPE, OVERRIDE_METHOD,
(Type *)new_type(0,g_strdup("void"),NULL),
g_strdup("Gtk:Object"),
- NULL,g_strdup("finalize"),
+ NULL, NULL, g_strdup("finalize"),
make_func_arg("Gtk:Object",FALSE,g_strdup("o")),
NULL,
g_strdup("PARENT_HANDLER (o);\n"),
out_printf(out,"\tLAST_SIGNAL\n};\n\n");
}
if(arguments>0) {
- out_printf(out,"enum {\n\tARG_0,\n");
+ out_printf(out,"enum {\n\tARG_0");
for(li=c->nodes;li;li=g_list_next(li)) {
Node *n = li->data;
if(n->type == ARGUMENT_NODE) {
Argument *a = (Argument *)n;
char *s = g_strdup(a->name);
g_strup(s);
- out_printf(out,"\tARG_%s,\n",s);
+ out_printf(out,",\n\tARG_%s",s);
g_free(s);
}
}
- out_printf(out, "};\n\n");
+ out_printf(out, "\n};\n\n");
}
if(signals>0)
GHashTable *done;
char *s;
- done = g_hash_table_new(g_str_hash,g_str_equal);
+ done = g_hash_table_new(g_str_hash, g_str_equal);
if(did_gtk_obj) {
s = g_strdup("GtkObject"); /* This was already done */
- g_hash_table_insert(done,s,s);
+ g_hash_table_insert(done, s, s);
}
- for(li=c->nodes;li;li=g_list_next(li)) {
+ for(li=c->nodes; li; li=g_list_next(li)) {
Node *n = li->data;
char *f;
Method *m = (Method *)n;
g_hash_table_destroy(done);
}
+static char *
+make_run_signal_flags(Method *m, gboolean last)
+{
+ GList *li;
+ GString *gs;
+ char *flags[] = {
+ "FIRST",
+ "LAST",
+ "BOTH",
+ "NO_RECURSE",
+ "ACTION",
+ "NO_HOOKS",
+ NULL
+ };
+
+ gs = g_string_new(NULL);
+
+ if(last)
+ g_string_assign(gs, "GTK_RUN_LAST");
+ else
+ g_string_assign(gs, "GTK_RUN_FIRST");
+
+ if(m->scope == PUBLIC_SCOPE)
+ g_string_append(gs, " | GTK_RUN_ACTION");
+
+ for(li = m->flags; li; li = li->next) {
+ char *flag = li->data;
+ int i;
+ for(i=0;flags[i];i++) {
+ if(strcmp(flags[i],flag)==0)
+ break;
+ }
+ /* if we haven't found it in our list */
+ if(!flags[i]) {
+ char *s;
+ s = g_strdup_printf("Unknown flag '%s' used, "
+ "perhaps it was misspelled",
+ flag);
+ print_error(TRUE, s, m->line_no);
+ g_free(s);
+ }
+ g_string_sprintfa(gs, " | GTK_RUN_%s",flag);
+ }
+
+ {
+ char *ret = gs->str;
+ g_string_free(gs, FALSE);
+ return ret;
+ }
+}
+
+
static void
add_signals(Class *c)
{
out_printf(out,"\n");
for(li=c->nodes;li;li=g_list_next(li)) {
Node *n = li->data;
- char *mar;
- char *sig;
- int is_none;
- int last = FALSE;
+ char *mar, *sig, *flags;
+ gboolean is_none, last = FALSE;
Method *m = (Method *)n;
+
if(n->type != METHOD_NODE ||
(m->method != SIGNAL_FIRST_METHOD &&
m->method != SIGNAL_LAST_METHOD))
continue;
-
if(m->method == SIGNAL_FIRST_METHOD)
last = FALSE;
else
last = TRUE;
- if(g_hash_table_lookup(marsh,m))
+ if(g_hash_table_lookup(marsh, m))
mar = g_strconcat("___marshal_",
(char *)g_hash_table_lookup(marsh,m),
NULL);
else
mar = g_strdup("gtk_signal_default_marshaller");
- is_none = (strcmp(m->gtktypes->next->data,"NONE")==0);
+ is_none = (strcmp(m->gtktypes->next->data, "NONE")==0);
sig = g_strdup(m->id);
g_strup(sig);
+ flags = make_run_signal_flags(m, last);
out_printf(out,"\tobject_signals[%s_SIGNAL] =\n"
"\t\tgtk_signal_new (\"%s\",\n"
- "\t\t\tGTK_RUN_%s,\n"
+ "\t\t\%s,\n"
"\t\t\tgtk_object_class->type,\n"
"\t\t\tGTK_SIGNAL_OFFSET (%sClass, %s),\n"
"\t\t\t%s,\n"
"\t\t\tGTK_TYPE_%s, %d",
sig,m->id,
- last?"LAST":"FIRST",
+ flags,
typebase,m->id,mar,(char *)m->gtktypes->data,
is_none?0:g_list_length(m->gtktypes->next));
g_free(mar);
g_free(sig);
+ g_free(flags);
if(!is_none) {
GList *l;
if(m->method == INIT_METHOD) {
if(m->line_no>0)
out_addline_infile(out,m->line_no);
- print_method(out,"static ","\n"," ","\n",m,FALSE);
+ print_method(out, "static ", "\n", "", " ", "\n",
+ m, FALSE, FALSE);
if(m->line_no>0)
out_addline_outfile(out);
out_printf(out,"{\n");
}
} else if(m->method == CLASS_INIT_METHOD) {
if(m->line_no>0)
- out_addline_infile(out,m->line_no);
- print_method(out,"static ","\n"," ","\n",m,FALSE);
+ out_addline_infile(out, m->line_no);
+ print_method(out, "static ", "\n", "", " ", "\n",
+ m, FALSE, FALSE);
if(m->line_no>0)
out_addline_outfile(out);
out_printf(out,"{\n");
static void
put_method(Method *m)
{
- char *s,*args;
+ char *s,*args,*doc;
gboolean is_void;
is_void = (strcmp(m->mtype->name,"void")==0 &&
m->mtype->stars == 0);
out_printf(out,"\n");
+ doc = get_gtk_doc(m->id);
+ if(doc) {
+ out_printf(out, "%s", doc);
+ g_free(doc);
+ }
switch(m->method) {
case REGULAR_METHOD:
if(m->line_no>0)
out_addline_infile(out,m->line_no);
if(m->scope == PRIVATE_SCOPE)
- print_method(out,"static ","\n"," ","\n",m,FALSE);
+ print_method(out,"static ","\n",""," ","\n",
+ m,FALSE,FALSE);
else /* PUBLIC, PROTECTED */
- print_method(out,"","\n"," ","\n",m,FALSE);
+ print_method(out, "", "\n", "", " ", "\n",
+ m, FALSE, FALSE);
print_method_body(m,TRUE);
break;
case SIGNAL_FIRST_METHOD:
if(m->line_no>0)
out_addline_infile(out,m->line_no);
if(m->scope == PRIVATE_SCOPE)
- print_method(out,"static ","\n"," ","\n",m,FALSE);
- else
- print_method(out,"","\n"," ","\n",m,FALSE);
+ print_method(out,"static ","\n",""," ","\n",
+ m,FALSE,FALSE);
+ else /* PUBLIC, PROTECTED */
+ print_method(out,"","\n",""," ","\n",m,FALSE,FALSE);
out_addline_outfile(out);
out_printf(out,"{\n");
s = g_strdup(m->id);
break;
if(m->line_no>0)
out_addline_infile(out,m->line_no);
- print_method(out,"static ","\n___real_"," ","\n",m,FALSE);
+ print_method(out,"static ","\n___real_",""," ","\n",
+ m,FALSE,FALSE);
print_method_body(m,FALSE);
break;
case VIRTUAL_METHOD:
if(m->line_no>0)
out_addline_infile(out,m->line_no);
if(m->scope==PRIVATE_SCOPE)
- print_method(out,"static ","\n"," ","\n",m,FALSE);
- else
- print_method(out,"","\n"," ","\n",m,FALSE);
+ print_method(out,"static ","\n",""," ","\n",
+ m,FALSE,FALSE);
+ else /* PUBLIC, PROTECTED */
+ print_method(out,"","\n",""," ","\n",m,FALSE,FALSE);
out_addline_outfile(out);
out_printf(out,"{\n"
"\t%sClass *klass;\n",typebase);
break;
if(m->line_no>0)
out_addline_infile(out,m->line_no);
- print_method(out,"static ","\n___real_"," ","\n",m,FALSE);
+ print_method(out,"static ","\n___real_",""," ","\n",
+ m,FALSE,FALSE);
print_method_body(m,FALSE);
break;
case OVERRIDE_METHOD:
break;
if(m->line_no>0)
out_addline_infile(out,m->line_no);
- print_method(out,"static ","\n"," ","\n",m,FALSE);
+ print_method(out,"static ","\n",""," ","\n",
+ m,FALSE,FALSE);
s = replace_sep(m->otype,'_');
g_strup(s);
args = get_arg_names_for_macro(m);
outfileph = NULL;
- out = fopen(outfile,"w");
- if(!out) {
- g_error("Cannot open outfile: %s",outfile);
- }
- outh = fopen(outfileh,"w");
- if(!outh) {
- g_error("Cannot open outfile: %s",outfileh);
- }
- if(outfileph) {
- outph = fopen(outfileph,"w");
- if(!outph) {
+ if(no_write) {
+ devnull = fopen("/dev/null","w");
+ if(!devnull) {
+ g_error("Cannot open null device",NULL);
+ }
+ out = devnull;
+ outh = devnull;
+ if(outfileph)
+ outph = devnull;
+ } else {
+ out = fopen(outfile,"w");
+ if(!out) {
+ g_error("Cannot open outfile: %s",outfile);
+ }
+ outh = fopen(outfileh,"w");
+ if(!outh) {
g_error("Cannot open outfile: %s",outfileh);
}
+ if(outfileph) {
+ outph = fopen(outfileph,"w");
+ if(!outph) {
+ g_error("Cannot open outfile: %s",outfileh);
+ }
+ }
}
}
fp = outh;
out_printf(fp,"\n");
break;
+ case AT_CCODE:
+ /* AT code is printed exactly like normal 'all'
+ code but is printed before */
+ case A_CCODE:
+ if(outph) {
+ out_printf(outph,"\n");
+ out_printf(outph,"%s\n",cc->cbuf);
+ out_addline_infile(outph,cc->line_no);
+ out_addline_outfile(outph);
+ }
+ out_printf(outh,"\n");
+ out_printf(outh,"%s\n",cc->cbuf);
+ fp = out;
+ out_printf(fp,"\n");
+ out_addline_infile(fp,cc->line_no);
+ break;
default:
case C_CCODE:
fp = out;
}
out_printf(fp,"%s\n",cc->cbuf);
if(cc->cctype == C_CCODE ||
+ cc->cctype == A_CCODE ||
+ cc->cctype == AT_CCODE ||
cc->cctype == PH_CCODE)
out_addline_outfile(fp);
}
{
GList *l;
char *s;
+ gboolean printed_private = FALSE;
out_printf(out,"/* utility types we may need */\n");
out_printf(out,"typedef struct { "
"gpointer c; "
"} ___threepointertype;\n");
- out_printf(outh,"\n#define %s\t"
+ out_printf(outh, "\n/*\n"
+ " * Type checking and casting macros\n"
+ " */\n");
+ out_printf(outh,"#define %s\t"
"(%s_get_type())\n",
macrotype,funcbase);
out_printf(outh,"#define %s(obj)\t"
"GTK_CHECK_TYPE((obj), %s_get_type ())\n\n",
macrois,funcbase);
- /* argument wrapping macros */
- if(arguments>0 && !no_gnu) {
- out_printf(outh,"\n#ifdef __GNUC__\n");
- put_argument_gnu_wrappers(c);
- out_printf(outh,"#else /* __GNUC__ */\n");
- put_argument_nongnu_wrappers(c);
- out_printf(outh,"#endif /* __GNUC__ */\n\n");
- } else if(arguments>0 && no_gnu) {
- put_argument_nongnu_wrappers(c);
- }
+ out_printf(out, "\n/* self casting macros */\n");
+ out_printf(out, "#define SELF(x) %s(x)\n", macrobase);
+ out_printf(out, "#define IS_SELF(x) %s(x)\n", macrois);
+ out_printf(out, "#define SELF_CLASS(x) %s_CLASS(x)\n\n", macrobase);
- if(privates>0)
- out_printf(outh,"\ntypedef struct _%sPrivate %sPrivate;\n",typebase,typebase);
+ if(privates>0) {
+ out_printf(outh, "\n/* Private structure type */\n");
+ out_printf(outh,"typedef struct _%sPrivate %sPrivate;\n",
+ typebase,typebase);
+ }
+ out_printf(outh, "\n/*\n"
+ " * Main object structure\n"
+ " */\n");
s = replace_sep(c->otype,'_');
g_strup(s);
out_printf(outh,"#ifndef __TYPEDEF_%s__\n"
out_printf(outh,"struct _%s {\n\t%s __parent__;\n",
typebase,ptypebase);
for(l=c->nodes;l;l=g_list_next(l)) {
+ static gboolean printed_public = FALSE;
Node *n = l->data;
Variable *v = (Variable *)n;
if(n->type == VARIABLE_NODE &&
- v->scope == PUBLIC_SCOPE)
+ v->scope == PUBLIC_SCOPE) {
+ if(!printed_public) {
+ out_printf(outh,"\t/*< public >*/\n");
+ printed_public = TRUE;
+ }
put_variable((Variable *)n,outh);
+ }
}
/* put protecteds always AFTER publics */
for(l=c->nodes;l;l=g_list_next(l)) {
Node *n = l->data;
Variable *v = (Variable *)n;
if(n->type == VARIABLE_NODE &&
- v->scope == PROTECTED_SCOPE)
+ v->scope == PROTECTED_SCOPE) {
+ if(!printed_private) {
+ out_printf(outh,"\t/*< private >*/\n");
+ printed_private = TRUE;
+ }
put_variable((Variable *)n,outh);
+ }
}
- if(privates>0)
+ if(privates>0) {
+ if(!printed_private)
+ out_printf(outh,"\t/*< private >*/\n");
out_printf(outh,"\t%sPrivate *_priv;\n",typebase);
+ }
out_printf(outh,"};\n");
if(privates>0) {
out_printf(outfp,"};\n");
}
- out_printf(outh,"\ntypedef struct _%sClass %sClass;\n",
+ out_printf(outh, "\n/*\n"
+ " * Class definition\n"
+ " */\n");
+ out_printf(outh,"typedef struct _%sClass %sClass;\n",
typebase,typebase);
out_printf(outh,
"struct _%sClass {\n\t%sClass __parent__;\n",
}
out_printf(outh,"};\n\n");
- out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
-
out_printf(out,"/* here are local prototypes */\n");
- if(!no_gnu) {
- out_printf(out,"#ifdef __GNUC__\n"
- "#define ___NO_UNUSED_WARNING "
- "__attribute__ ((__unused__))\n"
- "#else /* __GNUC__ */\n"
- "#define ___NO_UNUSED_WARNING\n"
- "#endif /* __GNUC__ */\n");
- }
if(arguments>0) {
out_printf(out,"static void ___object_set_arg "
"(GtkObject *object, GtkArg *arg, "
"guint arg_id);\n");
}
+ out_printf(outh, "\n/*\n"
+ " * Public methods\n"
+ " */\n");
+
+ out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
for(l=c->nodes;l;l=g_list_next(l)) {
Node *n = l->data;
if(n->type == METHOD_NODE) {
}
}
+/* this idea is less and less apealing to me */
+#if 0
+ if(!no_signal_connect) {
+ if(signals>0) {
+ out_printf(outh, "\n/*\n"
+ " * Signal connection methods\n"
+ " */\n");
+ }
+
+ for(l=c->nodes;l;l=g_list_next(l)) {
+ Node *n = l->data;
+ if(n->type == METHOD_NODE)
+ put_signal_connect((Method *)n);
+ }
+ }
+#endif
+
+
+ /* argument wrapping macros */
+ if(arguments>0 && !no_gnu) {
+ out_printf(outh, "\n/*\n"
+ " * Argument wrapping macros\n"
+ " */\n");
+ out_printf(outh,"#ifdef __GNUC__\n");
+ put_argument_gnu_wrappers(c);
+ out_printf(outh,"#else /* __GNUC__ */\n");
+ put_argument_nongnu_wrappers(c);
+ out_printf(outh,"#endif /* __GNUC__ */\n\n");
+ } else if(arguments>0 && no_gnu) {
+ out_printf(outh, "\n/*\n"
+ " * Argument wrapping macros\n"
+ " */\n");
+ put_argument_nongnu_wrappers(c);
+ }
+
if(signals>0) {
for(l=c->nodes;l;l=g_list_next(l)) {
Node *n = l->data;
}
}
- if(!no_gnu)
- out_printf(out,"#undef ___NO_UNUSED_WARNING\n");
-
add_enums(c);
add_get_type();
int major=0,minor=0,pl=0;
sscanf(VERSION,"%d.%d.%d",&major,&minor,&pl);
- out_printf(out,"#define GOB_VERSION_MAJOR %d\n", major);
- out_printf(out,"#define GOB_VERSION_MINOR %d\n", minor);
- out_printf(out,"#define GOB_VERSION_PATCHLEVEL %d\n\n", pl);
+ out_printf(out, "#define GOB_VERSION_MAJOR %d\n", major);
+ out_printf(out, "#define GOB_VERSION_MINOR %d\n", minor);
+ out_printf(out, "#define GOB_VERSION_PATCHLEVEL %d\n\n", pl);
}
static void
}
}
+static void
+print_all_top(void)
+{
+ GList *li;
+
+ /* print the AT_CCODE blocks */
+ for(li=nodes;li;li=g_list_next(li)) {
+ Node *node = li->data;
+ if(node->type == CCODE_NODE) {
+ CCode *cc = (CCode *)node;
+ if(cc->cctype==AT_CCODE)
+ print_ccode_block((CCode *)node);
+ }
+ }
+}
+
static void
print_header_top(void)
{
print_file_comments();
+ print_all_top();
+
print_header_top();
print_header_prefixes();
print_version_macros();
-
+
print_includes();
for(li=nodes;li;li=g_list_next(li)) {
"\t--no-private-header Don't create a private header, "
"put private\n"
"\t structure and protected "
- "prototypes inside c file\n");
+ "prototypes inside c file\n"
+ "\t--no-write,-n Don't write output files, just "
+ "check syntax\n");
}
static void
if(no_opts || argv[i][0]!='-') {
/*must be a file*/
if(got_file) {
- fprintf(stderr,"Specify only one file!\n");
+ fprintf(stderr, "Specify only one file!\n");
print_help();
exit(1);
}
print_help();
exit(0);
} else if(strcmp(argv[i],"--version")==0) {
- fprintf(stderr,"Gob version %s\n",VERSION);
+ fprintf(stderr, "Gob version %s\n", VERSION);
exit(0);
- } else if(strcmp(argv[i],"--exit-on-warn")==0) {
+ } else if(strcmp(argv[i], "--exit-on-warn")==0) {
exit_on_warn = TRUE;
- } else if(strcmp(argv[i],"--no-exit-on-warn")==0) {
+ } else if(strcmp(argv[i], "--no-exit-on-warn")==0) {
exit_on_warn = FALSE;
- } else if(strcmp(argv[i],"--for-cpp")==0) {
+ } else if(strcmp(argv[i], "--for-cpp")==0) {
for_cpp = TRUE;
- } else if(strcmp(argv[i],"--no-touch-headers")==0) {
+ } else if(strcmp(argv[i], "--no-touch-headers")==0) {
no_touch_headers = TRUE;
- } else if(strcmp(argv[i],"--always-private-header")==0) {
+ } else if(strcmp(argv[i], "--always-private-header")==0) {
no_private_header = FALSE;
always_private_header = TRUE;
- } else if(strcmp(argv[i],"--no-private-header")==0) {
+ } else if(strcmp(argv[i], "--no-private-header")==0) {
always_private_header = FALSE;
no_private_header = TRUE;
- } else if(strcmp(argv[i],"--no-gnu")==0) {
+ } else if(strcmp(argv[i], "--no-gnu")==0) {
no_gnu = TRUE;
- } else if(strcmp(argv[i],"--no-extern-c")==0) {
+ } else if(strcmp(argv[i], "--no-extern-c")==0) {
no_extern_c = TRUE;
- } else if(strcmp(argv[i],"--")==0) {
+ } else if(strcmp(argv[i], "--no-write")==0) {
+ no_write = TRUE;
+ } else if(strcmp(argv[i], "--")==0) {
/*further arguments are files*/
no_opts = TRUE;
- } else if(strncmp(argv[i],"--",2)==0) {
+ } else if(strncmp(argv[i], "--",2)==0) {
/*unknown long option*/
- fprintf(stderr,"Unknown option '%s'!\n",argv[i]);
+ fprintf(stderr, "Unknown option '%s'!\n", argv[i]);
print_help();
exit(1);
} else {
/*by now we know we have a string starting with
- which is a short option string*/
char *p = argv[i]+1;
- for(p=argv[i]+1;*p;p++) {
+ for(p=argv[i]+1; *p; p++) {
switch(*p) {
case 'w':
exit_on_warn=TRUE;
break;
+ case 'n':
+ no_write = TRUE;
+ break;
case 'h':
case '?':
print_help();
exit(0);
default:
fprintf(stderr,
- "Unknown option '%c'!\n",*p);
+ "Unknown option '%c'!\n", *p);
print_help();
exit(1);
}
static void
compare_and_move_header(void)
{
- char *hfnew = g_strconcat("#gob#",filebase,".h#gob#",NULL);
- char *hf = g_strconcat(filebase,".h",NULL);
+ char *hfnew = g_strconcat("#gob#", filebase, ".h#gob#", NULL);
+ char *hf = g_strconcat(filebase, ".h", NULL);
struct stat s;
if(stat(hf,&s)==0) {
char *s;
- s = g_strdup_printf("cmp '%s' '%s' > /dev/null",hf,hfnew);
+ s = g_strdup_printf("cmp '%s' '%s' > /dev/null", hf, hfnew);
if(system(s)==0) {
if(unlink(hfnew)!=0)
- print_error(FALSE,"Can't remove new header file",0);
+ print_error(FALSE,
+ "Can't remove new header file", 0);
g_free(hfnew);
g_free(hf);
g_free(s);
}
g_free(s);
if(unlink(hf)!=0)
- print_error(FALSE,"Can't remove old header file",0);
+ print_error(FALSE, "Can't remove old header file", 0);
}
if(rename(hfnew,hf)!=0)
- print_error(FALSE,"Can't rename new header file",0);
+ print_error(FALSE, "Can't rename new header file", 0);
g_free(hfnew);
g_free(hf);
}
int
main(int argc, char *argv[])
{
- parse_options(argc,argv);
+ parse_options(argc, argv);
if(filename) {
- yyin = fopen(filename,"r");
+ yyin = fopen(filename, "r");
if(!yyin) {
- fprintf(stderr,"Error: can't open file '%s'\n",
+ fprintf(stderr, "Error: can't open file '%s'\n",
filename);
exit(1);
}
if(yyparse()!=0)
g_error("Parsing errors, quitting");
if(!class)
- print_error(FALSE," no class defined",0);
+ print_error(FALSE, " no class defined", 0);
exit_on_error = FALSE;
generate_outfiles();
- fclose(out);
- fclose(outh);
+ if(devnull)
+ fclose(devnull);
+ else {
+ fclose(out);
+ fclose(outh);
+ if(outph)
+ fclose(outph);
+ }
- if(no_touch_headers)
+ if(no_touch_headers && !no_write)
compare_and_move_header();
return 0;