2 * Copyright (C) 1999 the Free Software Foundation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
38 char *filename = NULL;
47 extern GList *include_files;
50 static char *funcbase;
51 static char *pfuncbase;
52 static char *macrobase;
54 static char *macrotype;
55 static char *typebase;
56 static char *ptypebase;
58 static int signals = 0; /* number of signals */
59 static int arguments = 0; /* number of named arguments */
60 static int overrides = 0; /* number of override methods */
61 static int privates = 0; /* number of private data members */
62 static int protecteds = 0; /* number of protected methods */
64 static gboolean made_aliases = FALSE; /* if we made any shorthand aliases
65 and need the REALLY UGLY HACK to
72 gboolean no_touch_headers = FALSE;
73 gboolean for_cpp = FALSE;
74 gboolean exit_on_warn = FALSE;
75 gboolean exit_on_error = TRUE;
76 gboolean got_error = FALSE;
77 gboolean always_private_header = FALSE;
78 gboolean no_private_header = FALSE;
81 print_error(int is_warn, char *error,int line)
91 fprintf(stderr,"%s:%d: %s %s\n",filename,line,w,error);
93 fprintf(stderr,"%s: %s %s\n",filename,w,error);
94 if((!is_warn || exit_on_warn) && exit_on_error)
99 remove_sep(char *base)
102 char *s = g_strdup(base);
103 while((p=strchr(s,':')))
109 replace_sep(char *base, char r)
112 char *s = g_strdup(base);
113 while((p=strchr(s,':')))
123 /*separate the namespace part and then replace rest of
126 separns_replace_sep(char *base, char **ns, char **name, char r)
129 char *s = g_strdup(base);
131 if((p=strchr(s,':')) && p!=s) {
138 while((p=strchr(s,':')))
141 *name = g_strdup(s+1);
147 /* make a macro with some prefix before the name but after
150 make_pre_macro(char *base, char *pre)
155 separns_replace_sep(base,&s1,&s2,'_');
157 s = g_strconcat(s1,"_",pre,"_",s2,NULL);
159 s = g_strconcat(pre,"_",s2,NULL);
172 filebase = replace_sep(((Class *)class)->otype,'-');
175 funcbase = replace_sep(((Class *)class)->otype,'_');
178 pfuncbase = replace_sep(((Class *)class)->ptype,'_');
179 g_strdown(pfuncbase);
181 macrobase = replace_sep(((Class *)class)->otype,'_');
184 macrois = make_pre_macro(((Class *)class)->otype,"IS");
185 macrotype = make_pre_macro(((Class *)class)->otype,"TYPE");
187 typebase = remove_sep(((Class *)class)->otype);
189 ptypebase = remove_sep(((Class *)class)->ptype);
193 print_type(FILE *fp, Type *t, gboolean postfix_to_stars)
199 s = remove_sep(t->name);
200 out_printf(fp,"%s ",s);
204 if(postfix_to_stars) {
206 /*XXX: this is ugly perhaps we can do this whole postfix thing
207 in a nicer way, we just count the number of '[' s and from
208 that we deduce the number of dimensions, so that we can print
210 for(p=t->postfix; p && *p; p++)
211 if(*p == '[') extra++;
214 for(i=0;i<(t->stars+extra);i++)
219 print_method(FILE *fp, char *typeprefix, char *nameprefix,
220 char *namepostfix,char *postfix, Method *m,
221 gboolean no_funcbase)
225 out_printf(fp,"%s",typeprefix);
226 print_type(fp,m->mtype,TRUE);
228 out_printf(fp,"%s%s%s(",
229 nameprefix,m->id,namepostfix);
231 out_printf(fp,"%s%s_%s%s(",
232 nameprefix,funcbase,m->id,namepostfix);
235 for(li=m->args;li;li=g_list_next(li)) {
236 FuncArg *arg = li->data;
237 print_type(fp,arg->atype,FALSE);
239 out_printf(fp,"%s%s, ",arg->name,
241 arg->atype->postfix:"");
243 out_printf(fp,"%s%s",arg->name,
245 arg->atype->postfix:"");
248 out_printf(fp,", ...");
250 out_printf(fp,"void");
252 out_printf(fp,")%s",postfix);
257 make_method_pointers(Class *c)
261 out_printf(out,"\n");
262 for(li=c->nodes;li;li=g_list_next(li)) {
263 Node *node = li->data;
264 if(node->type == METHOD_NODE) {
265 Method *m = (Method *)node;
267 if(m->method == INIT_METHOD ||
268 m->method == CLASS_INIT_METHOD ||
269 m->method == OVERRIDE_METHOD)
272 /* in C++ mode don't alias new */
273 if(for_cpp && strcmp(m->id,"new")==0)
276 print_method(out,"static ","(* ",") ","",m,TRUE);
277 out_printf(out," = %s_%s;\n",funcbase,m->id);
282 out_printf(out,"\n");
286 add_bad_hack_to_avoid_unused_warnings(Class *c)
290 /* if we haven't had any methods, just return */
294 out_printf(out,"\n\n/*REALLY BAD HACK\n"
295 " This is to avoid unused warnings if you don't call\n"
296 " some method. I need to find a better way to do\n"
298 out_printf(out,"static void\n"
299 "__%s_really_bad_hack_to_avoid_warnings(void)\n"
301 for(li=c->nodes;li;li=g_list_next(li)) {
302 Node *node = li->data;
303 if(node->type == METHOD_NODE) {
304 Method *m = (Method *)node;
306 if(m->method == INIT_METHOD ||
307 m->method == CLASS_INIT_METHOD ||
308 m->method == OVERRIDE_METHOD)
311 /* in C++ mode we don't alias new */
312 if(for_cpp && strcmp(m->id,"new")==0)
315 out_printf(out,"\t((void (*)(void))%s)();\n",m->id);
318 out_printf(out, "\t__%s_really_bad_hack_to_avoid_warnings();\n",
320 out_printf(out,"}\n\n");
324 put_variable(Variable *v, FILE *fp)
327 print_type(fp,v->vtype,FALSE);
328 out_printf(fp,"%s%s;",v->id,
330 v->vtype->postfix:"");
331 if(v->scope == PROTECTED_SCOPE)
332 out_printf(fp," /* protected */");
337 put_vs_method(Method *m)
339 if(m->method != SIGNAL_LAST_METHOD &&
340 m->method != SIGNAL_FIRST_METHOD &&
341 m->method != VIRTUAL_METHOD)
344 print_method(outh,"\t","(* ",") ",";\n",m,TRUE);
348 put_pub_method(Method *m)
350 if(m->scope != PUBLIC_SCOPE)
353 print_method(outh,"","\t","\t",";\n",m,FALSE);
357 put_prot_method(Method *m)
359 if(m->scope != PROTECTED_SCOPE)
363 print_method(outph,"","\t","\t",";\n",m,FALSE);
365 print_method(out,"","\t","\t",";\n",m,FALSE);
369 put_priv_method_prot(Method *m)
371 if(m->method == SIGNAL_LAST_METHOD ||
372 m->method == SIGNAL_FIRST_METHOD ||
373 m->method == VIRTUAL_METHOD) {
375 print_method(out,"static ","_real_"," ",";\n",m,FALSE);
378 if(m->scope == PRIVATE_SCOPE ||
379 m->method == INIT_METHOD ||
380 m->method == CLASS_INIT_METHOD ||
381 (m->method == OVERRIDE_METHOD &&
383 print_method(out,"static ",""," ",";\n",m,FALSE);
387 make_func_arg(char *typename, int is_class, char *name)
394 tn = g_strconcat(typename,":Class",NULL);
396 tn = g_strdup(typename);
398 type = new_type(1,tn,NULL);
399 node = new_funcarg((Type *)type,name,NULL);
400 return g_list_prepend(NULL, node);
404 make_inits(Class *cl)
406 int got_class_init = FALSE;
407 int got_init = FALSE;
410 for(li=cl->nodes;li;li=g_list_next(li)) {
412 if(n->type == METHOD_NODE) {
413 Method *m = (Method *)n;
414 if(m->method == INIT_METHOD) {
416 print_error(FALSE,"init defined more then once",m->line_no);
418 } else if(m->method == CLASS_INIT_METHOD) {
420 print_error(FALSE,"class_init defined more then once",m->line_no);
421 got_class_init = TRUE;
425 if(!got_class_init) {
426 node = new_method(NO_SCOPE, CLASS_INIT_METHOD,
427 (Type *)new_type(0,g_strdup("void"),NULL),
428 NULL,NULL,g_strdup("class_init"),
429 make_func_arg(cl->otype,TRUE,g_strdup("c")),
430 NULL, NULL,0,0,FALSE);
431 cl->nodes = g_list_prepend(cl->nodes,node);
434 node = new_method(NO_SCOPE, INIT_METHOD,
435 (Type *)new_type(0,g_strdup("void"),NULL),
436 NULL,NULL,g_strdup("init"),
437 make_func_arg(cl->otype,FALSE,g_strdup("o")),
438 NULL, NULL,0,0,FALSE);
439 cl->nodes = g_list_prepend(cl->nodes,node);
444 make_destroy(Class *cl)
446 int got_destroy = FALSE;
449 for(li=cl->nodes;li;li=g_list_next(li)) {
451 if(n->type == METHOD_NODE) {
452 Method *m = (Method *)n;
453 if(m->method == OVERRIDE_METHOD &&
454 strcmp(m->id,"destroy")==0) {
455 if(strcmp(m->otype,"Gtk:Object")==0) {
459 print_error(FALSE,"destroy method override "
460 "of class other then Gtk:Object",
468 node = new_method(NO_SCOPE, OVERRIDE_METHOD,
469 (Type *)new_type(0,g_strdup("void"),NULL),
470 g_strdup("Gtk:Object"),
471 NULL,g_strdup("destroy"),
472 make_func_arg("Gtk:Object",FALSE,g_strdup("o")),
474 g_strdup("PARENT_HANDLER (o);\n"),
476 cl->nodes = g_list_append(cl->nodes,node);
481 /* here we will find out how inconsistent gtk really is :) */
482 /* the commented out types mean that these types don't actually
483 exist. so we "emulate them" with an equivalent */
487 } our_gtk_type_table[] = {
490 { "UCHAR", "guchar" },
491 { "BOOL", "gboolean" },
495 { "ULONG", "gulong" },
496 { "FLOAT", "gfloat" },
497 { "DOUBLE", "gdouble" },
498 { "STRING", /*"GtkString"*/"gchar *" },
499 { "ENUM", /*"GtkEnum"*/"gint" },
500 { "FLAGS", /*"GtkFlags"*/"guint" },
501 { "BOXED", /*"GtkBoxed"*/"gpointer" },
502 { "POINTER", "gpointer" },
503 { "OBJECT", "GtkObject *" },
504 { "SIGNAL", /*"GtkSignal"*/"__twopointertype" },
505 { "ARGS", /*"GtkArgs"*/"__twopointertype" },
506 { "CALLBACK", /*"GtkCallback"*/"__threepointertype" },
507 { "C_CALLBACK", /*"GtkCCallback"*/"__twopointertype" },
508 { "FOREIGN", /*"GtkForeign"*/"__twopointertype" },
517 for(i=0;our_gtk_type_table[i].gtkname;i++) {
518 if(strcmp(our_gtk_type_table[i].gtkname,type)==0) {
519 return our_gtk_type_table[i].typename;
526 /* hash of method -> name of signal prototype */
527 static GHashTable *marsh = NULL;
529 /* list of methods with different signal prototypes,
530 we check this list if we can use a signal prototype of a
531 previous signal method, there are only uniques here */
532 static GList *eq_signal_methods = NULL;
534 /* compare a list of strings */
536 is_list_equal(GList *a, GList *b)
538 for(;a && b; a=a->next, b=b->next) {
539 if(strcmp(a->data,b->data)!=0) {
543 /* the the lists were different length */
550 find_same_type_signal(Method *m)
553 for(li=eq_signal_methods;li;li=li->next) {
554 Method *mm = li->data;
555 if(is_list_equal(mm->gtktypes,m->gtktypes))
562 print_signal_marsal_args(Method *m)
564 if(strcmp(m->gtktypes->next->data,"NONE")!=0) {
567 for(i=0,li=m->gtktypes->next;li;
568 i++,li=g_list_next(li)) {
570 out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])",
573 out_printf(out, ",\n\t\t(%s)"
574 "GTK_VALUE_%s(args[%d])",
580 out_printf(out, ",\n\t\tfunc_data);\n}\n\n");
585 add_signal_prots(Method *m)
592 if(m->method != SIGNAL_LAST_METHOD &&
593 m->method != SIGNAL_FIRST_METHOD)
597 marsh = g_hash_table_new(NULL,NULL);
599 if(strcmp(m->gtktypes->data,"NONE")==0 &&
600 strcmp(m->gtktypes->next->data,"NONE")==0)
603 /* if we already did a signal prototype just use that */
604 mm = find_same_type_signal(m);
606 s = g_hash_table_lookup(marsh,mm);
607 g_hash_table_insert(marsh,m,s);
611 s = g_strdup_printf("__Sig%d",sig++);
613 g_hash_table_insert(marsh,m,s);
614 eq_signal_methods = g_list_prepend(eq_signal_methods,m);
616 /* we know that we'll know all the gtktypes (so get_cast can't fail) */
617 out_printf(out,"\ntypedef %s (*%s) (%s *, ",
618 get_cast(m->gtktypes->data),s, typebase);
620 for(li=m->gtktypes->next;li;li=g_list_next(li))
621 out_printf(out,"%s, ",get_cast(li->data));
622 out_printf(out,"gpointer);\n");
624 out_printf(out,"\nstatic void\n"
625 "marshal_%s (GtkObject * object,\n"
626 "\tGtkSignalFunc func,\n"
627 "\tgpointer func_data,\n"
631 if(strcmp(m->gtktypes->data,"NONE")==0) {
632 out_printf(out, "\t%s rfunc;\n\n"
633 "\trfunc = (%s)func;\n\n"
634 "\t(*rfunc)((%s *)object",s,s,typebase);
636 out_printf(out, "\t%s rfunc;\n\t",s);
637 print_type(out,m->mtype,TRUE);
638 out_printf(out, " *retval;\n\n"
639 "\trfunc = (%s)func;\n\n"
640 "\tretval = GTK_RETLOC_%s(args[%d]);\n\n"
641 "\t*retval = (*rfunc)((%s *)object",
642 s,(char *)m->gtktypes->data,
643 g_list_length(m->gtktypes)-1,typebase);
645 print_signal_marsal_args(m);
653 out_printf(out,"\n");
655 out_printf(out,"enum {\n");
656 for(li=c->nodes;li;li=g_list_next(li)) {
658 if(n->type == METHOD_NODE) {
659 Method *m = (Method *)n;
660 if(m->method == SIGNAL_LAST_METHOD ||
661 m->method == SIGNAL_FIRST_METHOD) {
662 char *s = g_strdup(m->id);
664 out_printf(out,"\t%s_SIGNAL,\n",s);
669 out_printf(out,"\tLAST_SIGNAL\n};\n\n");
672 out_printf(out,"enum {\n\tARG_0,\n");
673 for(li=c->nodes;li;li=g_list_next(li)) {
675 if(n->type == ARGUMENT_NODE) {
676 Argument *a = (Argument *)n;
677 char *s = g_strdup(a->name);
679 out_printf(out,"\tARG_%s,\n",s);
683 out_printf(out, "};\n\n");
688 "static guint object_signals[LAST_SIGNAL] = {0};\n\n");
690 out_printf(out, "static %sClass *parent_class = NULL;\n\n",ptypebase);
696 out_printf(out, "guint\n"
697 "%s_get_type (void)\n"
699 "\tstatic guint type = 0;\n\n"
701 "\t\tstatic const GtkTypeInfo info = {\n"
703 "\t\t\tsizeof (%s),\n"
704 "\t\t\tsizeof (%sClass),\n"
705 "\t\t\t(GtkClassInitFunc) %s_class_init,\n"
706 "\t\t\t(GtkObjectInitFunc) %s_init,\n"
707 "\t\t\t/* reserved_1 */ NULL,\n"
708 "\t\t\t/* reserved_2 */ NULL,\n"
709 "\t\t\t(GtkClassInitFunc) NULL,\n"
711 "\t\ttype = gtk_type_unique (%s_get_type(), &info);\n"
715 funcbase,typebase,typebase,typebase,
716 funcbase,funcbase,pfuncbase);
720 add_overrides(Class *c, char *oname, gboolean did_gtk_obj)
726 done = g_hash_table_new(g_str_hash,g_str_equal);
728 s = g_strdup("GtkObject"); /* This was already done */
729 g_hash_table_insert(done,s,s);
731 for(li=c->nodes;li;li=g_list_next(li)) {
734 Method *m = (Method *)n;
735 if(n->type != METHOD_NODE ||
736 m->method != OVERRIDE_METHOD)
739 s = remove_sep(m->otype);
741 if(g_hash_table_lookup(done,s)) {
745 g_hash_table_insert(done,s,s);
747 f = replace_sep(m->otype,'_');
750 out_printf(out,"\t%sClass *%s_class = (%sClass *)%s;\n",
755 g_hash_table_foreach(done,(GHFunc)g_free,NULL);
756 g_hash_table_destroy(done);
760 add_signals(Class *c)
764 out_printf(out,"\n");
765 for(li=c->nodes;li;li=g_list_next(li)) {
771 Method *m = (Method *)n;
772 if(n->type != METHOD_NODE ||
773 (m->method != SIGNAL_FIRST_METHOD &&
774 m->method != SIGNAL_LAST_METHOD))
778 if(m->method == SIGNAL_FIRST_METHOD)
783 if(g_hash_table_lookup(marsh,m))
784 mar = g_strconcat("marshal_",
785 (char *)g_hash_table_lookup(marsh,m),
788 mar = g_strdup("gtk_signal_default_marshaller");
790 is_none = (strcmp(m->gtktypes->next->data,"NONE")==0);
792 sig = g_strdup(m->id);
794 out_printf(out,"\tobject_signals[%s_SIGNAL] =\n"
795 "\t\tgtk_signal_new (\"%s\",\n"
796 "\t\t\tGTK_RUN_%s,\n"
797 "\t\t\tgtk_object_class->type,\n"
798 "\t\t\tGTK_SIGNAL_OFFSET (%sClass, %s),\n"
800 "\t\t\tGTK_TYPE_%s, %d",
803 typebase,m->id,mar,(char *)m->gtktypes->data,
804 is_none?0:g_list_length(m->gtktypes->next));
810 for(l=m->gtktypes->next;l;l=g_list_next(l))
811 out_printf(out,",\n\t\t\tGTK_TYPE_%s",
815 out_printf(out,");\n");
817 out_printf(out,"\tgtk_object_class_add_signals (gtk_object_class,\n"
818 "\t\tobject_signals, LAST_SIGNAL);\n\n");
822 set_def_handlers(Class *c, char *oname)
826 out_printf(out,"\n");
827 for(li=c->nodes;li;li=g_list_next(li)) {
829 Method *m = (Method *)n;
830 if(n->type != METHOD_NODE ||
831 (m->method != SIGNAL_FIRST_METHOD &&
832 m->method != SIGNAL_LAST_METHOD &&
833 m->method != VIRTUAL_METHOD &&
834 m->method != OVERRIDE_METHOD))
838 if(m->method == OVERRIDE_METHOD) {
840 s = replace_sep(m->otype,'_');
843 out_printf(out,"\t%s_class->%s = %s_%s;\n",
844 s,m->id,funcbase,m->id);
846 out_printf(out,"\t%s_class->%s = NULL;\n",
850 out_printf(out,"\t%s->%s = _real_%s_%s;\n",
851 oname,m->id,funcbase,m->id);
853 out_printf(out,"\t%s->%s = NULL;\n",
860 make_arguments(Class *c)
864 out_printf(out,"\n");
865 for(li=c->nodes;li;li=g_list_next(li)) {
871 if(n->type != ARGUMENT_NODE)
877 flags = g_string_new("GTK_ARG_READWRITE");
879 flags = g_string_new("GTK_ARG_READABLE");
881 flags = g_string_new("GTK_ARG_WRITABLE");
883 for(l=a->flags;l;l=g_list_next(l))
884 g_string_sprintfa(flags," | GTK_ARG_%s",(char *)l->data);
886 s = g_strdup(a->name);
888 out_printf(out,"\tgtk_object_add_arg_type(\"%s::%s\",\n"
892 typebase,a->name,a->gtktype,flags->str,s);
894 g_string_free(flags,TRUE);
898 "\n\tgtk_object_class->set_arg = __object_set_arg;\n"
899 "\tgtk_object_class->get_arg = __object_get_arg;\n");
906 for(li=c->nodes;li;li=g_list_next(li)) {
909 if(n->type != METHOD_NODE)
912 if(m->method == INIT_METHOD) {
914 out_addline_infile(out,m->line_no);
915 print_method(out,"static ","\n"," ","\n",m,FALSE);
917 out_addline_outfile(out);
918 out_printf(out,"{\n");
920 out_printf(out,"\t%s->_priv = "
921 "g_new0 (%sPrivate,1);\n",
922 ((FuncArg *)m->args->data)->name,
925 } else if(m->method == CLASS_INIT_METHOD) {
927 out_addline_infile(out,m->line_no);
928 print_method(out,"static ","\n"," ","\n",m,FALSE);
930 out_addline_outfile(out);
931 out_printf(out,"{\n");
936 "gtk_object_class = "
937 "(GtkObjectClass*) %s;\n",
938 ((FuncArg *)m->args->data)->name);
942 ((FuncArg *)m->args->data)->name,
943 (signals>0 || arguments>0));
945 out_printf(out,"\n\tparent_class = ");
947 out_printf(out,"(%sClass *)",ptypebase);
948 out_printf(out,"gtk_type_class (%s_get_type ());\n",
954 set_def_handlers(c, ((FuncArg *)m->args->data)->name);
963 out_printf(out," {\n");
964 out_addline_infile(out,m->ccode_line);
965 out_printf(out,"%s\n",m->cbuf);
966 out_addline_outfile(out);
967 out_printf(out," }\n");
969 out_printf(out,"return;\n");
971 out_printf(out,"}\n");
976 add_getset_arg(Class *c, int is_set)
979 out_printf(out,"\nstatic void\n"
980 "__object_%s_arg (GtkObject *object,\n"
985 "\tself = %s (object);\n\n"
986 "\tswitch (arg_id) {\n",
987 is_set?"set":"get",typebase,macrobase);
989 for(li=c->nodes;li;li=g_list_next(li)) {
995 if(n->type != ARGUMENT_NODE)
1000 line_no = a->set_line;
1003 line_no = a->get_line;
1007 s = g_strdup(a->name);
1009 out_printf(out,"\tcase ARG_%s:\n"
1010 "#define ARG (GTK_VALUE_%s(*arg))\n"
1014 out_addline_infile(out,line_no);
1015 out_printf(out,"%s\n",cbuf);
1016 out_addline_outfile(out);
1017 out_printf(out,"\t\t}\n\t\tbreak;\n"
1020 out_printf(out,"\tdefault:\n\t\tbreak;\n\t}\n}\n");
1024 print_checks(Method *m, FuncArg *fa)
1028 is_void = (strcmp(m->mtype->name,"void")==0 &&
1029 m->mtype->stars == 0);
1031 for(li=fa->checks;li;li=g_list_next(li)) {
1032 Check *ch = li->data;
1035 out_printf(out,"\tg_return_if_fail (");
1037 out_printf(out,"\tg_return_val_if_fail (");
1038 switch(ch->chtype) {
1040 out_printf(out,"%s != NULL",fa->name);
1043 s = make_pre_macro(fa->atype->name,"IS");
1044 out_printf(out,"%s (%s)",s,fa->name);
1048 out_printf(out,"%s < %s",fa->name,ch->number);
1051 out_printf(out,"%s > %s",fa->name,ch->number);
1054 out_printf(out,"%s <= %s",fa->name,ch->number);
1057 out_printf(out,"%s >= %s",fa->name,ch->number);
1060 out_printf(out,"%s == %s",fa->name,ch->number);
1063 out_printf(out,"%s != %s",fa->name,ch->number);
1067 out_printf(out,");\n");
1069 out_printf(out,", (");
1070 print_type(out,m->mtype,TRUE);
1071 out_printf(out,")%s);\n",
1072 m->onerror?m->onerror:"0");
1078 print_preconditions(Method *m)
1082 for(li=m->args;li;li=g_list_next(li)) {
1083 FuncArg *fa = li->data;
1089 /* put in code if it's needed */
1091 put_in_gen_code(Method *m)
1093 /* now we only have the freeing of the private structure */
1095 m->method == OVERRIDE_METHOD &&
1096 strcmp(m->id,"destroy")==0) {
1097 out_printf(out,"\tg_free (%s (%s)->_priv);\n"
1098 "\t%s (%s)->_priv = NULL;\n",
1100 ((FuncArg *)m->args->data)->name,
1102 ((FuncArg *)m->args->data)->name);
1108 print_method_body(Method *m, int pre)
1110 out_printf(out,"{\n");
1112 print_preconditions(m);
1115 /* Note: the trailing }'s are on one line, this is so
1116 that we get the no return warning correctly and point to
1117 the correct line in the .gob file, yes this is slightly
1118 ugly in the .c file, but that is not supposed to be
1119 human readable anyway. */
1121 out_printf(out,"{\n");
1122 out_addline_infile(out,m->ccode_line);
1123 out_printf(out,"\t%s}",m->cbuf);
1126 out_printf(out,"}\n");
1129 out_addline_outfile(out);
1133 put_signal_args(Method *m)
1137 for(ali = m->gtktypes->next,li=m->args->next;
1139 li=li->next, ali=ali->next) {
1140 FuncArg *fa = li->data;
1141 const char *cast = get_cast(ali->data);
1142 /* we should have already proved before that
1143 the we know all the types */
1146 out_printf(out,",\n\t\t(%s)%s",cast,
1152 put_method(Method *m)
1156 is_void = (strcmp(m->mtype->name,"void")==0 &&
1157 m->mtype->stars == 0);
1158 out_printf(out,"\n");
1160 case REGULAR_METHOD:
1161 out_addline_infile(out,m->line_no);
1162 if(m->scope == PRIVATE_SCOPE)
1163 print_method(out,"static ","\n"," ","\n",m,FALSE);
1164 else /* PUBLIC, PROTECTED */
1165 print_method(out,"","\n"," ","\n",m,FALSE);
1166 print_method_body(m,TRUE);
1168 case SIGNAL_FIRST_METHOD:
1169 case SIGNAL_LAST_METHOD:
1170 out_addline_infile(out,m->line_no);
1171 if(m->scope == PRIVATE_SCOPE)
1172 print_method(out,"static ","\n"," ","\n",m,FALSE);
1174 print_method(out,"","\n"," ","\n",m,FALSE);
1175 out_addline_outfile(out);
1176 out_printf(out,"{\n");
1177 s = g_strdup(m->id);
1179 if(strcmp(m->mtype->name,"void")==0 &&
1180 m->mtype->stars==0) {
1181 print_preconditions(m);
1182 if(((FuncArg *)m->args->data)->name)
1183 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (%s),\n"
1184 "\t\tobject_signals[%s_SIGNAL]",
1185 ((FuncArg *)m->args->data)->name,s);
1187 out_printf(out,");\n}\n");
1189 out_printf(out,"\t");
1190 print_type(out,m->mtype,TRUE);
1191 out_printf(out,"return_val;\n");
1192 print_preconditions(m);
1193 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (%s),\n"
1194 "\t\tobject_signals[%s_SIGNAL]",
1195 ((FuncArg *)m->args->data)->name,s);
1197 out_printf(out,",\n\t\t&return_val);\n"
1198 "\treturn return_val;\n}\n");
1203 out_addline_infile(out,m->line_no);
1204 print_method(out,"static ","\n_real_"," ","\n",m,FALSE);
1205 print_method_body(m,FALSE);
1207 case VIRTUAL_METHOD:
1208 out_addline_infile(out,m->line_no);
1209 if(m->scope==PRIVATE_SCOPE)
1210 print_method(out,"static ","\n"," ","\n",m,FALSE);
1212 print_method(out,"","\n"," ","\n",m,FALSE);
1213 out_addline_outfile(out);
1214 out_printf(out,"{\n"
1215 "\t%sClass *klass;\n",typebase);
1216 print_preconditions(m);
1217 out_printf(out,"\tklass = %s_CLASS(GTK_OBJECT(%s)->klass);\n\n"
1218 "\tif(klass->%s)\n",
1219 macrobase, ((FuncArg *)m->args->data)->name, m->id);
1220 if(strcmp(m->mtype->name,"void")==0 &&
1221 m->mtype->stars==0) {
1223 out_printf(out,"\t\t(*klass->%s)(%s",m->id,
1224 ((FuncArg *)m->args->data)->name);
1225 for(li=m->args->next;li;li=g_list_next(li)) {
1226 FuncArg *fa = li->data;
1227 out_printf(out,",%s",fa->name);
1229 out_printf(out,");\n}\n");
1232 out_printf(out,"\t\treturn (*klass->%s)(%s",m->id,
1233 ((FuncArg *)m->args->data)->name);
1234 for(li=m->args->next;li;li=g_list_next(li)) {
1235 FuncArg *fa = li->data;
1236 out_printf(out,",%s",fa->name);
1238 out_printf(out,");\n"
1241 print_type(out,m->mtype,TRUE);
1242 out_printf(out,")(%s);\n}\n",
1243 m->onerror?m->onerror:"0");
1248 out_addline_infile(out,m->line_no);
1249 print_method(out,"static ","\n_real_"," ","\n",m,FALSE);
1250 print_method_body(m,FALSE);
1252 case OVERRIDE_METHOD:
1255 out_addline_infile(out,m->line_no);
1256 print_method(out,"static ","\n"," ","\n",m,FALSE);
1257 s = replace_sep(m->otype,'_');
1260 out_printf(out,"#define PARENT_HANDLER(args...) \\\n"
1261 "\t{ if(%s_CLASS(parent_class)->%s) \\\n"
1262 "\t\t(* %s_CLASS(parent_class)->%s)(##args); }\n",
1265 out_printf(out,"#define PARENT_HANDLER(args...) \\\n"
1266 "\t((%s_CLASS(parent_class)->%s)? \\\n"
1267 "\t\t(* %s_CLASS(parent_class)->%s)(##args): \\\n"
1270 out_printf(out,"(");
1271 print_type(out,m->mtype,TRUE);
1272 out_printf(out,")%s))\n",
1273 m->onerror?m->onerror:"0");
1276 print_method_body(m,TRUE);
1277 out_printf(out,"#undef PARENT_HANDLER\n");
1285 check_duplicate(Class *c, Node *node, char *id, int line_no)
1288 for(l=c->nodes;l;l=g_list_next(l)) {
1293 if(n->type == METHOD_NODE) {
1294 Method *m = (Method *)n;
1296 nline_no = m->line_no;
1297 } else if(n->type == VARIABLE_NODE) {
1298 Variable *v = (Variable *)n;
1300 nline_no = v->line_no;
1304 line_no>=nline_no ||
1305 strcmp(nid,id)!=0 ||
1306 n->type != node->type)
1308 s = g_strdup_printf("symbol '%s' redefined, "
1309 "first defined on line %d",
1311 print_error(FALSE,s,nline_no);
1316 check_duplicate_symbols(Class *c)
1319 for(l=c->nodes;l;l=g_list_next(l)) {
1321 if(n->type == METHOD_NODE) {
1322 Method *m = (Method *)n;
1323 check_duplicate(c,n,m->id,m->line_no);
1324 } else if(n->type == VARIABLE_NODE) {
1325 Variable *v = (Variable *)n;
1326 check_duplicate(c,n,v->id,v->line_no);
1332 check_bad_symbols(Class *c)
1335 for(l=c->nodes;l;l=g_list_next(l)) {
1337 if(n->type == METHOD_NODE) {
1338 Method *m = (Method *)n;
1339 if((m->method == SIGNAL_LAST_METHOD ||
1340 m->method == SIGNAL_FIRST_METHOD ||
1341 m->method == VIRTUAL_METHOD) &&
1342 strcmp(m->id,"__parent__")==0) {
1344 s = g_strdup_printf("'%s' not allowed as an "
1345 "identifier of signal "
1346 "or virtual methods",
1348 print_error(FALSE,s,m->line_no);
1351 } else if(n->type == VARIABLE_NODE) {
1352 Variable *v = (Variable *)n;
1353 if(strcmp(v->id,"_priv")==0 ||
1354 strcmp(v->id,"__parent__")==0) {
1356 s = g_strdup_printf("'%s' not allowed as a data "
1357 "member name",v->id);
1358 print_error(FALSE,s,v->line_no);
1367 check_duplicate_named(Class *c,Node *node,char *id, int line_no)
1370 for(l=c->nodes;l;l=g_list_next(l)) {
1375 if(n->type == METHOD_NODE) {
1376 Method *m = (Method *)n;
1377 if(m->method == SIGNAL_LAST_METHOD ||
1378 m->method == SIGNAL_FIRST_METHOD) {
1380 nline_no = m->line_no;
1383 } else if(n->type == ARGUMENT_NODE) {
1384 Argument *a = (Argument *)n;
1386 nline_no = a->line_no;
1390 line_no>=nline_no ||
1393 s = g_strdup_printf("named symbol (argument or signal) '%s' "
1394 "redefined, first defined on line %d",
1396 print_error(FALSE,s,nline_no);
1401 check_duplicate_signals_args(Class *c)
1404 for(l=c->nodes;l;l=g_list_next(l)) {
1406 if(n->type == METHOD_NODE) {
1407 Method *m = (Method *)n;
1408 if(m->method == SIGNAL_LAST_METHOD ||
1409 m->method == SIGNAL_FIRST_METHOD)
1410 check_duplicate_named(c,n,m->id,m->line_no);
1411 } else if(n->type == ARGUMENT_NODE) {
1412 Argument *a = (Argument *)n;
1413 check_duplicate_named(c,n,a->name,a->line_no);
1419 check_public_new(Class *c)
1422 for(l=c->nodes;l;l=g_list_next(l)) {
1424 if(n->type == METHOD_NODE) {
1425 Method *m = (Method *)n;
1426 if((strcmp(m->id,"new")==0) &&
1427 (m->method != REGULAR_METHOD ||
1428 m->scope != PUBLIC_SCOPE))
1430 "'new' should be a regular\n"
1438 check_vararg(Class *c)
1441 for(l=c->nodes;l;l=g_list_next(l)) {
1443 if(n->type == METHOD_NODE) {
1444 Method *m = (Method *)n;
1447 if(m->method == OVERRIDE_METHOD ||
1448 m->method == SIGNAL_LAST_METHOD ||
1449 m->method == SIGNAL_FIRST_METHOD ||
1450 m->method == VIRTUAL_METHOD) {
1452 "signals, overrides and virtuals, "
1453 "can't have variable argument "
1462 check_firstarg(Class *c)
1465 for(l=c->nodes;l;l=g_list_next(l)) {
1467 if(n->type == METHOD_NODE) {
1468 Method *m = (Method *)n;
1471 if(m->method == OVERRIDE_METHOD ||
1472 m->method == SIGNAL_LAST_METHOD ||
1473 m->method == SIGNAL_FIRST_METHOD ||
1474 m->method == VIRTUAL_METHOD) {
1476 "signals, overrides and virtuals, "
1477 "can't have no arguments",
1485 check_nonvoidempty(Class *c)
1488 for(l=c->nodes;l;l=g_list_next(l)) {
1490 if(n->type == METHOD_NODE) {
1491 Method *m = (Method *)n;
1492 if(m->method != REGULAR_METHOD)
1494 if(!(strcmp(m->mtype->name,"void")==0 &&
1495 m->mtype->stars == 0) &&
1498 "non-void empty method found, "
1499 "regular non-void function should "
1502 /* add a body here, so that the user will also
1503 get a warning from gcc, and so that it will
1504 at least point him to the prototype of the
1505 function in the .gob file */
1506 m->cbuf = g_strdup("/*empty*/");
1507 m->ccode_line = m->line_no;
1514 check_signal_args(Class *c)
1517 for(l=c->nodes;l;l=g_list_next(l)) {
1519 if(n->type == METHOD_NODE) {
1520 Method *m = (Method *)n;
1522 if(m->method != SIGNAL_LAST_METHOD &&
1523 m->method != SIGNAL_FIRST_METHOD)
1526 for(l=m->gtktypes;l;l=l->next) {
1528 if(get_cast(l->data))
1530 s = g_strdup_printf("Unknown GTK+ type '%s' "
1531 "among signal types",
1533 print_error(FALSE, s, m->line_no);
1541 count_signals(Class *c)
1545 for(l=c->nodes;l;l=g_list_next(l)) {
1547 if(n->type == METHOD_NODE) {
1548 Method *m = (Method *)n;
1549 if(m->method == SIGNAL_LAST_METHOD ||
1550 m->method == SIGNAL_FIRST_METHOD)
1558 count_arguments(Class *c)
1563 for(li=c->nodes;li;li=g_list_next(li)) {
1565 if(n->type == ARGUMENT_NODE)
1572 count_overrides(Class *c)
1576 for(l=c->nodes;l;l=g_list_next(l)) {
1578 if(n->type == METHOD_NODE) {
1579 Method *m = (Method *)n;
1580 if(m->method == OVERRIDE_METHOD)
1588 count_privates(Class *c)
1592 for(l=c->nodes;l;l=g_list_next(l)) {
1594 if(n->type == VARIABLE_NODE) {
1595 Variable *v = (Variable *)n;
1596 if(v->scope == PRIVATE_SCOPE)
1604 count_protecteds(Class *c)
1608 for(l=c->nodes;l;l=g_list_next(l)) {
1610 if(n->type == METHOD_NODE) {
1611 Method *m = (Method *)n;
1612 if(m->scope == PROTECTED_SCOPE)
1623 char *outfile,*outfileh,*outfileph;
1626 outfile = g_strconcat(filebase,".c",NULL);
1628 outfile = g_strconcat(filebase,".cc",NULL);
1629 if(no_touch_headers)
1630 outfileh = g_strconcat("#gob#",filebase,".h#gob#",NULL);
1632 outfileh = g_strconcat(filebase,".h",NULL);
1634 if((privates>0 || protecteds>0 || always_private_header) &&
1636 outfileph = g_strconcat(filebase,"-private.h",NULL);
1641 out = fopen(outfile,"w");
1643 g_error("Cannot open outfile: %s",outfile);
1645 outh = fopen(outfileh,"w");
1647 g_error("Cannot open outfile: %s",outfileh);
1650 outph = fopen(outfileph,"w");
1652 g_error("Cannot open outfile: %s",outfileh);
1658 generate_outfiles(void)
1663 gboolean found_header;
1666 out_printf(outh,"/* Generated by GOB (v%s)"
1667 " (do not edit directly) */\n\n",VERSION);
1669 out_printf(outph,"/* Generated by GOB (v%s)"
1670 " (do not edit directly) */\n\n",VERSION);
1671 out_printf(out,"/* Generated by GOB (v%s) on %s"
1672 " (do not edit directly) */\n\n",VERSION,ctime(&curtime));
1674 p = replace_sep(((Class *)class)->otype,'_');
1676 out_printf(outh,"#ifndef __%s_H__\n#define __%s_H__\n\n"
1677 "#include <gtk/gtk.h>\n\n",p,p);
1679 out_printf(outph,"#ifndef __%s_PRIVATE_H__\n"
1680 "#define __%s_PRIVATE_H__\n\n"
1681 "#include \"%s.h\"\n\n",p,p,filebase);
1685 out_printf(outh,"#ifdef __cplusplus\n"
1687 "#endif /* __cplusplus */\n\n");
1689 out_printf(outph,"#ifdef __cplusplus\n"
1691 "#endif /* __cplusplus */\n\n");
1694 p = g_strconcat(filebase,".h",NULL);
1695 found_header = TRUE;
1696 if(!g_list_find_custom(include_files,p,(GCompareFunc)strcmp)) {
1697 out_printf(out,"#include \"%s.h\"\n\n",filebase);
1698 found_header = FALSE;
1702 /* if we are creating a private header see if it was included */
1704 p = g_strconcat(filebase,"-private.h",NULL);
1705 if(!g_list_find_custom(include_files,p,(GCompareFunc)strcmp)) {
1706 out_printf(out,"#include \"%s-private.h\"\n\n",
1710 "Implicit private header include "
1712 "\tsource file, while public "
1713 "header is at a custom location, "
1715 "\texplicitly include "
1716 "the private header below the "
1722 for(li=nodes;li;li=g_list_next(li)) {
1723 Node *node = li->data;
1724 if(node->type == CCODE_NODE) {
1725 CCode *cc = (CCode *)node;
1729 out_printf(fp,"\n");
1732 out_printf(fp,"\n");
1733 out_addline_infile(fp,cc->line_no);
1735 out_printf(fp,"%s\n",cc->cbuf);
1737 out_addline_outfile(fp);
1738 } else if(node->type == CLASS_NODE) {
1739 Class *c = (Class *)class;
1742 out_printf(out,"/* utility types we may need */\n");
1743 out_printf(out,"typedef struct { "
1744 "gpointer a; gpointer b; "
1745 "} __twopointertype;\n");
1746 out_printf(out,"typedef struct { "
1747 "gpointer a; gpointer b; "
1749 "} __threepointertype;\n");
1751 out_printf(outh,"\n#define %s\t"
1752 "(%s_get_type())\n",
1753 macrotype,funcbase);
1754 out_printf(outh,"#define %s(obj)\t"
1755 "GTK_CHECK_CAST((obj),%s_get_type(),%s)\n",
1756 macrobase,funcbase,typebase);
1757 out_printf(outh,"#define %s_CLASS(klass)\t"
1758 "GTK_CHECK_CLASS_CAST((klass),%s_get_type(),%sClass)\n",
1759 macrobase,funcbase,typebase);
1760 out_printf(outh,"#define %s(obj)\t"
1761 "GTK_CHECK_TYPE((obj), %s_get_type ())\n\n",
1765 out_printf(outh,"\ntypedef struct _%sPrivate %sPrivate;\n",typebase,typebase);
1767 out_printf(outh,"\ntypedef struct _%s %s;\n",typebase,typebase);
1768 out_printf(outh,"struct _%s {\n\t%s __parent__;\n",
1769 typebase,ptypebase);
1770 for(l=c->nodes;l;l=g_list_next(l)) {
1772 Variable *v = (Variable *)n;
1773 if(n->type == VARIABLE_NODE &&
1774 v->scope == PUBLIC_SCOPE)
1775 put_variable((Variable *)n,outh);
1777 /* put protecteds always AFTER publics */
1778 for(l=c->nodes;l;l=g_list_next(l)) {
1780 Variable *v = (Variable *)n;
1781 if(n->type == VARIABLE_NODE &&
1782 v->scope == PROTECTED_SCOPE)
1783 put_variable((Variable *)n,outh);
1786 out_printf(outh,"\t%sPrivate *_priv;\n",typebase);
1787 out_printf(outh,"};\n");
1792 /* if we are to stick this into the private
1793 header, if not stick it directly into the
1800 out_printf(outfp,"struct _%sPrivate {\n",
1802 for(l=c->nodes;l;l=l->next) {
1804 Variable *v = (Variable *)n;
1805 if(n->type == VARIABLE_NODE &&
1806 v->scope == PRIVATE_SCOPE) {
1807 out_addline_infile(outfp,v->line_no);
1808 put_variable(v,outfp);
1811 out_addline_outfile(outfp);
1812 out_printf(outfp,"};\n");
1815 out_printf(outh,"\ntypedef struct _%sClass %sClass;\n",
1818 "struct _%sClass {\n\t%sClass __parent__;\n",
1819 typebase,ptypebase);
1820 for(l=c->nodes;l;l=g_list_next(l)) {
1822 if(n->type == METHOD_NODE)
1823 put_vs_method((Method *)n);
1825 out_printf(outh,"};\n\n");
1827 out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
1830 out_printf(out,"static void __object_set_arg "
1831 "(GtkObject *object, GtkArg *arg, "
1833 "static void __object_get_arg "
1834 "(GtkObject *object, GtkArg *arg, "
1835 "guint arg_id);\n");
1838 out_printf(out,"/* here are local prototypes */\n");
1839 for(l=c->nodes;l;l=g_list_next(l)) {
1841 if(n->type == METHOD_NODE) {
1842 put_pub_method((Method *)n);
1843 put_prot_method((Method *)n);
1844 put_priv_method_prot((Method *)n);
1849 for(l=c->nodes;l;l=g_list_next(l)) {
1851 if(n->type == METHOD_NODE)
1852 add_signal_prots((Method *)n);
1860 make_method_pointers(c);
1862 out_printf(out,"#define GET_NEW (gtk_type_new(%s_get_type()))\n",
1868 add_getset_arg(c, TRUE);
1869 add_getset_arg(c, FALSE);
1872 for(l=c->nodes;l;l=g_list_next(l)) {
1874 if(n->type == METHOD_NODE) {
1875 put_method((Method *)n);
1879 out_printf(out,"#undef GET_NEW\n");
1881 add_bad_hack_to_avoid_unused_warnings(c);
1883 g_assert_not_reached();
1887 out_printf(outh,"\n#ifdef __cplusplus\n"
1889 "#endif /* __cplusplus */\n");
1890 out_printf(outh,"\n#endif");
1893 out_printf(outph,"\n#ifdef __cplusplus\n"
1895 "#endif /* __cplusplus */\n");
1896 out_printf(outph,"\n#endif");
1902 usage(poptContext optCon, int exitcode, char *error, char *addl)
1904 poptPrintUsage(optCon, stderr, 0);
1905 if (error) fprintf(stderr, "%s: %s", error, addl);
1913 fprintf(stderr,"Gob version %s\n\n",VERSION);
1914 fprintf(stderr,"Options:\n"
1915 "\t--help,-h,-? Display this help\n"
1916 "\t--version Display version\n"
1917 "\t--exit-on-warn,-w Exit with an error on warnings\n"
1918 "\t--no-exit-on-warn Don't exit on warnings [default]\n"
1919 "\t--for-cpp Create C++ files\n"
1920 "\t--no-touch-headers Don't touch headers unless they "
1922 "\t--always-private-header Always create a private header "
1924 "\t even if it would be empty\n"
1925 "\t--no-private-header Don't create a private header, "
1927 "\t structure and protected "
1928 "prototypes inside c file\n");
1932 parse_options(int argc, char *argv[])
1935 int got_file = FALSE;
1936 int no_opts = FALSE;
1940 for(i=1;i<argc;i++) {
1941 if(no_opts || argv[i][0]!='-') {
1944 fprintf(stderr,"Specify only one file!\n");
1950 } else if(strcmp(argv[i],"--help")==0) {
1953 } else if(strcmp(argv[i],"--version")==0) {
1954 fprintf(stderr,"Gob version %s\n",VERSION);
1956 } else if(strcmp(argv[i],"--exit-on-warn")==0) {
1957 exit_on_warn = TRUE;
1958 } else if(strcmp(argv[i],"--no-exit-on-warn")==0) {
1959 exit_on_warn = FALSE;
1960 } else if(strcmp(argv[i],"--for-cpp")==0) {
1962 } else if(strcmp(argv[i],"--no-touch-headers")==0) {
1963 no_touch_headers = TRUE;
1964 } else if(strcmp(argv[i],"--always-private-header")==0) {
1965 no_private_header = FALSE;
1966 always_private_header = TRUE;
1967 } else if(strcmp(argv[i],"--no-private-header")==0) {
1968 always_private_header = FALSE;
1969 no_private_header = TRUE;
1970 } else if(strcmp(argv[i],"--")==0) {
1971 /*further arguments are files*/
1973 } else if(strncmp(argv[i],"--",2)==0) {
1974 /*unknown long option*/
1975 fprintf(stderr,"Unknown option '%s'!\n",argv[i]);
1979 /*by now we know we have a string starting with
1980 - which is a short option string*/
1981 char *p = argv[i]+1;
1982 for(p=argv[i]+1;*p;p++) {
1993 "Unknown option '%c'!\n",*p);
2002 /* this is a somewhat ugly hack, but it appears to work */
2004 compare_and_move_header(void)
2006 char *hfnew = g_strconcat("#gob#",filebase,".h#gob#",NULL);
2007 char *hf = g_strconcat(filebase,".h",NULL);
2009 if(stat(hf,&s)==0) {
2011 s = g_strdup_printf("cmp '%s' '%s' > /dev/null",hf,hfnew);
2013 if(unlink(hfnew)!=0)
2014 print_error(FALSE,"Can't remove new header file",0);
2022 print_error(FALSE,"Can't remove old header file",0);
2024 if(rename(hfnew,hf)!=0)
2025 print_error(FALSE,"Can't rename new header file",0);
2031 main(int argc, char *argv[])
2037 struct poptOption optionsTable[] = {
2038 { "exit-on-warn", 'w', 0, &exit_on_warn, 0,
2039 "exit on warnings" },
2041 { NULL, 0, 0, NULL, 0 }
2044 optCon = poptGetContext(NULL, argc, argv, optionsTable, 0);
2045 poptSetOtherOptionHelp(optCon, "[OPTIONS]* [filename]");
2047 while ((c = poptGetNextOpt(optCon)) >= 0)
2050 filename = poptGetArg(optCon);
2051 if(!(poptPeekArg(optCon) == NULL))
2052 usage(optCon, 1, "Specify only one file",
2053 ".e.g., filename.gob");
2056 /* an error occurred during option processing */
2057 fprintf(stderr, "%s: %s\n",
2058 poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
2064 parse_options(argc,argv);
2067 yyin = fopen(filename,"r");
2069 fprintf(stderr,"Error: can't open file '%s'\n",
2078 g_error("Parsing errors, quitting");
2080 print_error(FALSE," no class defined",0);
2083 exit_on_error = FALSE;
2085 signals = count_signals((Class *)class);
2086 arguments = count_arguments((Class *)class);
2087 overrides = count_overrides((Class *)class);
2088 privates = count_privates((Class *)class);
2089 protecteds = count_protecteds((Class *)class);
2092 make_inits((Class *)class);
2094 make_destroy((Class *)class);
2095 check_bad_symbols((Class *)class);
2096 check_duplicate_symbols((Class *)class);
2097 check_duplicate_signals_args((Class *)class);
2098 check_public_new((Class *)class);
2099 check_vararg((Class *)class);
2100 check_firstarg((Class *)class);
2101 check_nonvoidempty((Class *)class);
2102 check_signal_args((Class *)class);
2104 exit_on_error = TRUE;
2111 generate_outfiles();
2116 if(no_touch_headers)
2117 compare_and_move_header();
2120 poptFreeContext(optCon);