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,
39 char *filename = NULL;
48 extern GList *include_files;
50 extern GHashTable *gtk_doc_hash;
53 static char *funcbase;
54 static char *pfuncbase;
55 static char *macrobase;
57 static char *macrotype;
58 static char *typebase;
59 static char *ptypebase;
61 static int signals = 0; /* number of signals */
62 static int arguments = 0; /* number of named arguments */
63 static int overrides = 0; /* number of override methods */
64 static int privates = 0; /* number of private data members */
65 static int protecteds = 0; /* number of protected methods */
67 static gboolean made_aliases = FALSE; /* if we made any shorthand aliases
68 and need the REALLY UGLY HACK to
75 gboolean no_touch_headers = FALSE;
76 gboolean for_cpp = FALSE;
77 gboolean no_gnu = FALSE;
78 gboolean exit_on_warn = FALSE;
79 gboolean exit_on_error = TRUE;
80 gboolean got_error = FALSE;
81 gboolean always_private_header = FALSE;
82 gboolean no_private_header = FALSE;
83 gboolean no_extern_c = FALSE;
88 filebase = replace_sep(((Class *)class)->otype,'-');
91 funcbase = replace_sep(((Class *)class)->otype,'_');
94 pfuncbase = replace_sep(((Class *)class)->ptype,'_');
97 macrobase = replace_sep(((Class *)class)->otype,'_');
100 macrois = make_pre_macro(((Class *)class)->otype,"IS");
101 macrotype = make_pre_macro(((Class *)class)->otype,"TYPE");
103 typebase = remove_sep(((Class *)class)->otype);
105 ptypebase = remove_sep(((Class *)class)->ptype);
109 get_type(Type *t, gboolean postfix_to_stars)
116 s = remove_sep(t->name);
117 gs = g_string_new(s);
122 if(postfix_to_stars) {
124 /*XXX: this is ugly perhaps we can do this whole postfix thing
125 in a nicer way, we just count the number of '[' s and from
126 that we deduce the number of dimensions, so that we can print
128 for(p=t->postfix; p && *p; p++)
129 if(*p == '[') extra++;
131 g_string_append_c(gs,' ');
133 for(i=0;i<(t->stars+extra);i++)
134 g_string_append_c(gs,'*');
137 g_string_free(gs,FALSE);
142 get_gtk_doc(char *id)
149 val = g_hash_table_lookup(gtk_doc_hash, id);
151 return g_strdup_printf("/**\n * %s_%s:\n%s **/\n",
153 s = g_strconcat(funcbase, "_", id, NULL);
154 val = g_hash_table_lookup(gtk_doc_hash, s);
157 return g_strdup_printf("/**\n * %s_%s:\n%s **/\n",
163 print_type(FILE *fp, Type *t, gboolean postfix_to_stars)
167 s = get_type(t,postfix_to_stars);
168 out_printf(fp,"%s",s);
174 print_method(FILE *fp, char *typeprefix, char *nameprefix,
176 char *namepostfix, char *postfix, Method *m,
177 gboolean one_arg_per_line,
178 gboolean no_funcbase)
182 out_printf(fp,"%s",typeprefix);
183 print_type(fp,m->mtype,TRUE);
185 out_printf(fp,"%s%s%s%s(",
186 nameprefix,subnameprefix,m->id,namepostfix);
188 out_printf(fp,"%s%s_%s%s%s(",
189 nameprefix,funcbase,subnameprefix,m->id,
193 for(li=m->args;li;li=g_list_next(li)) {
194 FuncArg *arg = li->data;
195 print_type(fp,arg->atype,FALSE);
197 out_printf(fp,"%s%s,%s",arg->name,
199 arg->atype->postfix:"",
200 one_arg_per_line?"\n\t\t\t\t\t":" ");
202 out_printf(fp,"%s%s",arg->name,
204 arg->atype->postfix:"");
207 out_printf(fp,",%s...",
208 one_arg_per_line?"\n\t\t\t\t\t":" ");
210 out_printf(fp,"void");
212 out_printf(fp,")%s",postfix);
217 make_method_gnu_aliases(Class *c)
221 for(li=c->nodes;li;li=g_list_next(li)) {
222 Node *node = li->data;
223 if(node->type == METHOD_NODE) {
224 Method *m = (Method *)node;
226 if(m->method == INIT_METHOD ||
227 m->method == CLASS_INIT_METHOD ||
228 m->method == OVERRIDE_METHOD)
231 /* in C++ mode don't alias new */
232 if(for_cpp && strcmp(m->id, "new")==0)
235 out_printf(out, "static const typeof(&%s_%s) %s "
236 "__attribute__ ((__unused__)) "
237 "= %s_%s;\n", funcbase, m->id, m->id,
239 out_printf(out, "#define %s(args...) "
240 "%s_%s(##args)\n", m->id, funcbase, m->id);
246 make_method_nongnu_aliases(Class *c)
250 for(li=c->nodes;li;li=g_list_next(li)) {
251 Node *node = li->data;
252 if(node->type == METHOD_NODE) {
253 Method *m = (Method *)node;
255 if(m->method == INIT_METHOD ||
256 m->method == CLASS_INIT_METHOD ||
257 m->method == OVERRIDE_METHOD)
260 /* in C++ mode don't alias new */
261 if(for_cpp && strcmp(m->id,"new")==0)
264 print_method(out,"static ","(* ","",") ","",m,FALSE,TRUE);
265 out_printf(out," = %s_%s;\n",funcbase,m->id);
273 add_bad_hack_to_avoid_unused_warnings(Class *c)
277 /* if we haven't had any methods, just return */
282 out_printf(out,"\n\n#ifndef __GNUC__\n");
284 "/*REALLY BAD HACK\n"
285 " This is to avoid unused warnings if you don't call\n"
286 " some method. I need to find a better way to do\n"
287 " this, not needed in GCC since we use some gcc\n"
288 " extentions to make saner, faster code */\n"
290 "___%s_really_bad_hack_to_avoid_warnings(void)\n"
292 for(li=c->nodes;li;li=g_list_next(li)) {
293 Node *node = li->data;
294 if(node->type == METHOD_NODE) {
295 Method *m = (Method *)node;
297 if(m->method == INIT_METHOD ||
298 m->method == CLASS_INIT_METHOD ||
299 m->method == OVERRIDE_METHOD)
302 /* in C++ mode we don't alias new */
303 if(for_cpp && strcmp(m->id,"new")==0)
306 out_printf(out,"\t((void (*)(void))%s)();\n",m->id);
309 out_printf(out, "\t___%s_really_bad_hack_to_avoid_warnings();\n",
312 out_printf(out,"}\n#endif /* __GNUC__ */\n\n");
314 out_printf(out,"}\n\n");
318 put_variable(Variable *v, FILE *fp)
321 print_type(fp,v->vtype,FALSE);
322 out_printf(fp,"%s%s;",v->id,
324 v->vtype->postfix:"");
325 if(v->scope == PROTECTED_SCOPE)
326 out_printf(fp," /* protected */");
331 put_vs_method(Method *m)
333 if(m->method != SIGNAL_LAST_METHOD &&
334 m->method != SIGNAL_FIRST_METHOD &&
335 m->method != VIRTUAL_METHOD)
338 /* if a signal mark it as such */
339 if(m->method != VIRTUAL_METHOD)
340 print_method(outh,"\t/*signal*/","(* ","",") ",";\n",m,
343 print_method(outh,"\t","(* ","",") ",";\n",m,FALSE,TRUE);
347 put_pub_method(Method *m)
349 if(m->scope != PUBLIC_SCOPE)
352 print_method(outh,"","\t","","\t",";\n",m,TRUE,FALSE);
355 /* I'm starting not to like this idea */
358 put_signal_connect(Method *m)
360 if(m->method != SIGNAL_LAST_METHOD &&
361 m->method != SIGNAL_FIRST_METHOD)
364 out_printf(outh, "guint \t%s_%s__connect_full\t(%s *object,\n"
365 "\t\t\t\t\tconst char *name,\n"
366 "\t\t\t\t\tGtkSignalFunc func,\n"
367 "\t\t\t\t\tGtkCallbackMarshal marshal,\n"
368 "\t\t\t\t\tgpointer data,\n"
369 "\t\t\t\t\tGtkDestroyNotify destroy_func,\n"
370 "\t\t\t\t\tgboolean object_signal,\n"
371 "\t\t\t\t\tgboolean after);\n",
372 funcbase, m->id, typebase);
374 out_printf(outh, "#define %s_%s__connect(object,name,func,data) "
375 "%s_%s__connect_full((object),(name),(func),NULL,"
376 "(data),NULL,FALSE,FALSE)\n",
377 funcbase, m->id, funcbase, m->id);
378 out_printf(outh, "#define %s_%s__connect_after(object,name,func,data) "
379 "%s__connect_%s_full((object),(name),(func),NULL,"
380 "(data),NULL,FALSE,TRUE)\n",
381 funcbase, m->id, funcbase, m->id);
383 out_printf(outh, "guint \t%s_%s__connect_while_alive\t(%s *object,\n"
384 "\t\t\t\t\tconst char *name,\n"
385 "\t\t\t\t\tGtkSignalFunc func,\n"
386 "\t\t\t\t\tgpointer data,\n"
387 "\t\t\t\t\tGtkObject *alive_object);\n\n",
388 funcbase, m->id, typebase);
394 put_prot_method(Method *m)
396 if(m->scope != PROTECTED_SCOPE)
400 print_method(outph,"","\t","","\t",";\n",m,FALSE,FALSE);
402 print_method(out,"","\t","","\t",";\n",m,FALSE,FALSE);
406 put_priv_method_prot(Method *m)
408 if(m->method == SIGNAL_LAST_METHOD ||
409 m->method == SIGNAL_FIRST_METHOD ||
410 m->method == VIRTUAL_METHOD) {
413 "static ", "___real_", "", " ", ";\n",
417 if(m->scope == PRIVATE_SCOPE ||
418 m->method == INIT_METHOD ||
419 m->method == CLASS_INIT_METHOD ||
420 (m->method == OVERRIDE_METHOD &&
422 print_method(out, "static ", "", "", " ",
423 no_gnu?";\n":" G_GNUC_UNUSED;\n",
428 make_func_arg(char *typename, int is_class, char *name)
435 tn = g_strconcat(typename,":Class",NULL);
437 tn = g_strdup(typename);
439 type = new_type(1,tn,NULL);
440 node = new_funcarg((Type *)type,name,NULL);
441 return g_list_prepend(NULL, node);
445 make_inits(Class *cl)
447 int got_class_init = FALSE;
448 int got_init = FALSE;
451 for(li=cl->nodes;li;li=g_list_next(li)) {
453 if(n->type == METHOD_NODE) {
454 Method *m = (Method *)n;
455 if(m->method == INIT_METHOD) {
457 print_error(FALSE,"init defined more then once",m->line_no);
459 } else if(m->method == CLASS_INIT_METHOD) {
461 print_error(FALSE,"class_init defined more then once",m->line_no);
462 got_class_init = TRUE;
466 if(!got_class_init) {
467 node = new_method(NO_SCOPE, CLASS_INIT_METHOD,
468 (Type *)new_type(0,g_strdup("void"),NULL),
469 NULL,NULL,g_strdup("class_init"),
470 make_func_arg(cl->otype,TRUE,g_strdup("c")),
471 NULL, NULL,0,0,FALSE);
472 cl->nodes = g_list_prepend(cl->nodes,node);
475 node = new_method(NO_SCOPE, INIT_METHOD,
476 (Type *)new_type(0,g_strdup("void"),NULL),
477 NULL,NULL,g_strdup("init"),
478 make_func_arg(cl->otype,FALSE,g_strdup("o")),
479 NULL, NULL,0,0,FALSE);
480 cl->nodes = g_list_prepend(cl->nodes,node);
485 make_finalize(Class *cl)
487 int got_finalize = FALSE;
490 for(li=cl->nodes;li;li=g_list_next(li)) {
492 if(n->type == METHOD_NODE) {
493 Method *m = (Method *)n;
494 if(m->method == OVERRIDE_METHOD &&
495 strcmp(m->id,"finalize")==0) {
496 if(strcmp(m->otype,"Gtk:Object")==0) {
500 print_error(FALSE,"finalize method override "
501 "of class other then Gtk:Object",
509 node = new_method(NO_SCOPE, OVERRIDE_METHOD,
510 (Type *)new_type(0,g_strdup("void"),NULL),
511 g_strdup("Gtk:Object"),
512 NULL,g_strdup("finalize"),
513 make_func_arg("Gtk:Object",FALSE,g_strdup("o")),
515 g_strdup("PARENT_HANDLER (o);\n"),
517 cl->nodes = g_list_append(cl->nodes,node);
523 /* hash of method -> name of signal prototype */
524 static GHashTable *marsh = NULL;
526 /* list of methods with different signal prototypes,
527 we check this list if we can use a signal prototype of a
528 previous signal method, there are only uniques here */
529 static GList *eq_signal_methods = NULL;
531 /* compare a list of strings */
533 is_list_equal(GList *a, GList *b)
535 for(;a && b; a=a->next, b=b->next) {
536 if(strcmp(a->data,b->data)!=0) {
540 /* the the lists were different length */
547 find_same_type_signal(Method *m)
550 for(li=eq_signal_methods;li;li=li->next) {
551 Method *mm = li->data;
552 if(is_list_equal(mm->gtktypes,m->gtktypes))
559 print_signal_marsal_args(Method *m)
561 if(strcmp(m->gtktypes->next->data,"NONE")!=0) {
564 for(i=0,li=m->gtktypes->next;li;
565 i++,li=g_list_next(li)) {
567 out_printf(out, ",\n\t\tGTK_VALUE_%s(args[%d])",
570 out_printf(out, ",\n\t\t(%s)"
571 "GTK_VALUE_%s(args[%d])",
572 get_cast(li->data,FALSE),
577 out_printf(out, ",\n\t\tfunc_data);\n}\n\n");
582 add_signal_prots(Method *m)
589 if(m->method != SIGNAL_LAST_METHOD &&
590 m->method != SIGNAL_FIRST_METHOD)
594 marsh = g_hash_table_new(NULL,NULL);
596 if(strcmp(m->gtktypes->data,"NONE")==0 &&
597 strcmp(m->gtktypes->next->data,"NONE")==0)
600 /* if we already did a signal prototype just use that */
601 mm = find_same_type_signal(m);
603 s = g_hash_table_lookup(marsh,mm);
604 g_hash_table_insert(marsh,m,s);
608 s = g_strdup_printf("Sig%d",sig++);
610 g_hash_table_insert(marsh,m,s);
611 eq_signal_methods = g_list_prepend(eq_signal_methods,m);
613 /* we know that we'll know all the gtktypes (so get_cast can't fail) */
614 out_printf(out,"\ntypedef %s (*___%s) (%s *, ",
615 get_cast(m->gtktypes->data,FALSE),s, typebase);
617 for(li=m->gtktypes->next;li;li=g_list_next(li))
618 out_printf(out,"%s, ",get_cast(li->data,FALSE));
619 out_printf(out,"gpointer);\n");
621 out_printf(out,"\nstatic void\n"
622 "___marshal_%s (GtkObject * object,\n"
623 "\tGtkSignalFunc func,\n"
624 "\tgpointer func_data,\n"
628 if(strcmp(m->gtktypes->data,"NONE")==0) {
629 out_printf(out, "\t___%s rfunc;\n\n"
630 "\trfunc = (___%s)func;\n\n"
631 "\t(*rfunc)((%s *)object",s,s,typebase);
633 out_printf(out, "\t___%s rfunc;\n\t",s);
634 print_type(out,m->mtype,TRUE);
635 out_printf(out, " *retval;\n\n"
636 "\trfunc = (___%s)func;\n\n"
637 "\tretval = GTK_RETLOC_%s(args[%d]);\n\n"
638 "\t*retval = (*rfunc)((%s *)object",
639 s,(char *)m->gtktypes->data,
640 g_list_length(m->gtktypes)-1,typebase);
642 print_signal_marsal_args(m);
650 out_printf(out,"\n");
652 out_printf(out,"enum {\n");
653 for(li=c->nodes;li;li=g_list_next(li)) {
655 if(n->type == METHOD_NODE) {
656 Method *m = (Method *)n;
657 if(m->method == SIGNAL_LAST_METHOD ||
658 m->method == SIGNAL_FIRST_METHOD) {
659 char *s = g_strdup(m->id);
661 out_printf(out,"\t%s_SIGNAL,\n",s);
666 out_printf(out,"\tLAST_SIGNAL\n};\n\n");
669 out_printf(out,"enum {\n\tARG_0,\n");
670 for(li=c->nodes;li;li=g_list_next(li)) {
672 if(n->type == ARGUMENT_NODE) {
673 Argument *a = (Argument *)n;
674 char *s = g_strdup(a->name);
676 out_printf(out,"\tARG_%s,\n",s);
680 out_printf(out, "};\n\n");
685 "static guint object_signals[LAST_SIGNAL] = {0};\n\n");
687 out_printf(out, "static %sClass *parent_class = NULL;\n\n",ptypebase);
693 out_printf(out, "guint\n"
694 "%s_get_type (void)\n"
696 "\tstatic guint type = 0;\n\n"
698 "\t\tstatic const GtkTypeInfo info = {\n"
700 "\t\t\tsizeof (%s),\n"
701 "\t\t\tsizeof (%sClass),\n"
702 "\t\t\t(GtkClassInitFunc) %s_class_init,\n"
703 "\t\t\t(GtkObjectInitFunc) %s_init,\n"
704 "\t\t\t/* reserved_1 */ NULL,\n"
705 "\t\t\t/* reserved_2 */ NULL,\n"
706 "\t\t\t(GtkClassInitFunc) NULL,\n"
708 "\t\ttype = gtk_type_unique (%s_get_type(), &info);\n"
712 funcbase,typebase,typebase,typebase,
713 funcbase,funcbase,pfuncbase);
717 add_overrides(Class *c, char *oname, gboolean did_gtk_obj)
723 done = g_hash_table_new(g_str_hash, g_str_equal);
725 s = g_strdup("GtkObject"); /* This was already done */
726 g_hash_table_insert(done, s, s);
728 for(li=c->nodes; li; li=g_list_next(li)) {
731 Method *m = (Method *)n;
732 if(n->type != METHOD_NODE ||
733 m->method != OVERRIDE_METHOD)
736 s = remove_sep(m->otype);
738 if(g_hash_table_lookup(done,s)) {
742 g_hash_table_insert(done,s,s);
744 f = replace_sep(m->otype,'_');
747 out_printf(out,"\t%sClass *%s_class = (%sClass *)%s;\n",
752 g_hash_table_foreach(done,(GHFunc)g_free,NULL);
753 g_hash_table_destroy(done);
757 add_signals(Class *c)
761 out_printf(out,"\n");
762 for(li=c->nodes;li;li=g_list_next(li)) {
768 Method *m = (Method *)n;
769 if(n->type != METHOD_NODE ||
770 (m->method != SIGNAL_FIRST_METHOD &&
771 m->method != SIGNAL_LAST_METHOD))
775 if(m->method == SIGNAL_FIRST_METHOD)
780 if(g_hash_table_lookup(marsh,m))
781 mar = g_strconcat("___marshal_",
782 (char *)g_hash_table_lookup(marsh,m),
785 mar = g_strdup("gtk_signal_default_marshaller");
787 is_none = (strcmp(m->gtktypes->next->data,"NONE")==0);
789 sig = g_strdup(m->id);
791 out_printf(out,"\tobject_signals[%s_SIGNAL] =\n"
792 "\t\tgtk_signal_new (\"%s\",\n"
793 "\t\t\tGTK_RUN_%s,\n"
794 "\t\t\tgtk_object_class->type,\n"
795 "\t\t\tGTK_SIGNAL_OFFSET (%sClass, %s),\n"
797 "\t\t\tGTK_TYPE_%s, %d",
800 typebase,m->id,mar,(char *)m->gtktypes->data,
801 is_none?0:g_list_length(m->gtktypes->next));
807 for(l=m->gtktypes->next;l;l=g_list_next(l))
808 out_printf(out,",\n\t\t\tGTK_TYPE_%s",
812 out_printf(out,");\n");
814 out_printf(out,"\tgtk_object_class_add_signals (gtk_object_class,\n"
815 "\t\tobject_signals, LAST_SIGNAL);\n\n");
819 set_def_handlers(Class *c, char *oname)
823 out_printf(out,"\n");
824 for(li=c->nodes;li;li=g_list_next(li)) {
826 Method *m = (Method *)n;
827 if(n->type != METHOD_NODE ||
828 (m->method != SIGNAL_FIRST_METHOD &&
829 m->method != SIGNAL_LAST_METHOD &&
830 m->method != VIRTUAL_METHOD &&
831 m->method != OVERRIDE_METHOD))
835 if(m->method == OVERRIDE_METHOD) {
837 s = replace_sep(m->otype,'_');
840 out_printf(out,"\t%s_class->%s = %s_%s;\n",
841 s,m->id,funcbase,m->id);
843 out_printf(out,"\t%s_class->%s = NULL;\n",
847 out_printf(out,"\t%s->%s = ___real_%s_%s;\n",
848 oname,m->id,funcbase,m->id);
850 out_printf(out,"\t%s->%s = NULL;\n",
857 make_arguments(Class *c)
868 out_printf(out,"\n");
869 for(li=c->nodes;li;li=g_list_next(li)) {
875 if(n->type != ARGUMENT_NODE)
881 flags = g_string_new("GTK_ARG_READWRITE");
883 flags = g_string_new("GTK_ARG_READABLE");
885 flags = g_string_new("GTK_ARG_WRITABLE");
887 for(l=a->flags;l;l=g_list_next(l)) {
888 char *flag = l->data;
890 if(strcmp(flag,"READWRITE")==0 ||
891 strcmp(flag,"READABLE")==0 ||
892 strcmp(flag,"WRITABLE")==0) {
893 print_error(TRUE,"READWRITE, READABLE and "
894 "WRITABLE argument flags are "
895 "set automatically",a->line_no);
898 for(i=0;argflags[i];i++) {
899 if(strcmp(argflags[i],flag)==0)
902 /* if we haven't found it in our list */
905 s = g_strdup_printf("Unknown flag '%s' used, "
906 "perhaps it was misspelled",
908 print_error(TRUE,s,a->line_no);
911 g_string_sprintfa(flags, " | GTK_ARG_%s",flag);
914 s = g_strdup(a->name);
916 out_printf(out,"\tgtk_object_add_arg_type(\"%s::%s\",\n"
920 typebase,a->name,a->gtktype,flags->str,s);
922 g_string_free(flags,TRUE);
926 "\n\tgtk_object_class->set_arg = ___object_set_arg;\n"
927 "\tgtk_object_class->get_arg = ___object_get_arg;\n");
934 for(li=c->nodes;li;li=g_list_next(li)) {
937 if(n->type != METHOD_NODE)
940 if(m->method == INIT_METHOD) {
942 out_addline_infile(out,m->line_no);
943 print_method(out, "static ", "\n", "", " ", "\n",
946 out_addline_outfile(out);
947 out_printf(out,"{\n");
949 out_printf(out,"\t%s->_priv = "
950 "g_new0 (%sPrivate,1);\n",
951 ((FuncArg *)m->args->data)->name,
954 } else if(m->method == CLASS_INIT_METHOD) {
956 out_addline_infile(out, m->line_no);
957 print_method(out, "static ", "\n", "", " ", "\n",
960 out_addline_outfile(out);
961 out_printf(out,"{\n");
966 "gtk_object_class = "
967 "(GtkObjectClass*) %s;\n",
968 ((FuncArg *)m->args->data)->name);
972 ((FuncArg *)m->args->data)->name,
973 (signals>0 || arguments>0));
975 out_printf(out,"\n\tparent_class = ");
977 out_printf(out,"(%sClass *)",ptypebase);
978 out_printf(out,"gtk_type_class (%s_get_type ());\n",
984 set_def_handlers(c, ((FuncArg *)m->args->data)->name);
993 out_printf(out," {\n");
994 out_addline_infile(out,m->ccode_line);
995 out_printf(out,"%s\n",m->cbuf);
996 out_addline_outfile(out);
997 out_printf(out," }\n");
999 out_printf(out,"return;\n");
1001 out_printf(out,"}\n");
1006 add_getset_arg(Class *c, int is_set)
1009 out_printf(out,"\nstatic void\n"
1010 "___object_%s_arg (GtkObject *object,\n"
1015 "\tself = %s (object);\n\n"
1016 "\tswitch (arg_id) {\n",
1017 is_set?"set":"get",typebase,macrobase);
1019 for(li=c->nodes;li;li=g_list_next(li)) {
1025 if(n->type != ARGUMENT_NODE)
1030 line_no = a->set_line;
1033 line_no = a->get_line;
1037 s = g_strdup(a->name);
1039 out_printf(out,"\tcase ARG_%s:\n"
1040 "#define ARG (GTK_VALUE_%s(*arg))\n"
1044 out_addline_infile(out,line_no);
1045 out_printf(out,"%s\n",cbuf);
1046 out_addline_outfile(out);
1047 out_printf(out,"\t\t}\n\t\tbreak;\n"
1050 out_printf(out,"\tdefault:\n\t\tbreak;\n\t}\n}\n");
1054 print_checks(Method *m, FuncArg *fa)
1058 gboolean checked_null = FALSE;
1059 is_void = (strcmp(m->mtype->name,"void")==0 &&
1060 m->mtype->stars == 0);
1062 for(li=fa->checks;li;li=g_list_next(li)) {
1063 Check *ch = li->data;
1065 /* point to the method prot in .gob for failed checks */
1067 out_addline_infile(out,m->line_no);
1069 out_printf(out,"\tg_return_if_fail (");
1071 out_printf(out,"\tg_return_val_if_fail (");
1072 switch(ch->chtype) {
1074 out_printf(out,"%s != NULL",fa->name);
1075 checked_null = TRUE;
1078 s = make_pre_macro(fa->atype->name,"IS");
1080 out_printf(out,"%s (%s)",s,fa->name);
1082 /* if not check null, null may be valid */
1083 out_printf(out,"!(%s) || %s (%s)",fa->name,s,
1088 out_printf(out,"%s < %s",fa->name,ch->number);
1091 out_printf(out,"%s > %s",fa->name,ch->number);
1094 out_printf(out,"%s <= %s",fa->name,ch->number);
1097 out_printf(out,"%s >= %s",fa->name,ch->number);
1100 out_printf(out,"%s == %s",fa->name,ch->number);
1103 out_printf(out,"%s != %s",fa->name,ch->number);
1107 out_printf(out,");\n");
1109 out_printf(out,", (");
1110 print_type(out,m->mtype,TRUE);
1111 out_printf(out,")%s);\n",
1112 m->onerror?m->onerror:"0");
1118 print_preconditions(Method *m)
1122 for(li=m->args;li;li=g_list_next(li)) {
1123 FuncArg *fa = li->data;
1128 out_addline_outfile(out);
1131 /* put in code if it's needed */
1133 put_in_gen_code(Method *m)
1135 /* now we only have the freeing of the private structure */
1137 m->method == OVERRIDE_METHOD &&
1138 strcmp(m->id,"finalize")==0) {
1139 out_printf(out,"\tg_free (%s (%s)->_priv);\n"
1140 "\t%s (%s)->_priv = NULL;\n",
1142 ((FuncArg *)m->args->data)->name,
1144 ((FuncArg *)m->args->data)->name);
1149 print_method_body(Method *m, int pre)
1151 out_printf(out,"{\n");
1153 print_preconditions(m);
1157 /* Note: the trailing }'s are on one line, this is so
1158 that we get the no return warning correctly and point to
1159 the correct line in the .gob file, yes this is slightly
1160 ugly in the .c file, but that is not supposed to be
1161 human readable anyway. */
1163 out_printf(out,"{\n");
1165 out_addline_infile(out,m->ccode_line);
1166 out_printf(out,"\t%s}",m->cbuf);
1169 out_printf(out,"}\n");
1172 out_addline_outfile(out);
1176 put_signal_args(Method *m)
1180 for(ali = m->gtktypes->next,li=m->args->next;
1182 li=li->next, ali=ali->next) {
1183 FuncArg *fa = li->data;
1184 const char *cast = get_cast(ali->data,FALSE);
1185 /* we should have already proved before that
1186 the we know all the types */
1189 out_printf(out,",\n\t\t(%s)%s",cast,
1195 get_arg_names_for_macro(Method *m)
1199 GString *gs = g_string_new("");
1201 for(li=m->args;li;li=g_list_next(li)) {
1202 FuncArg *arg = li->data;
1203 g_string_sprintfa(gs, "%s___%s", p, arg->name);
1207 g_string_free(gs,FALSE);
1212 put_method(Method *m)
1216 is_void = (strcmp(m->mtype->name,"void")==0 &&
1217 m->mtype->stars == 0);
1218 out_printf(out,"\n");
1219 doc = get_gtk_doc(m->id);
1221 out_printf(out, "%s", doc);
1225 case REGULAR_METHOD:
1227 out_addline_infile(out,m->line_no);
1228 if(m->scope == PRIVATE_SCOPE)
1229 print_method(out,"static ","\n",""," ","\n",
1231 else /* PUBLIC, PROTECTED */
1232 print_method(out, "", "\n", "", " ", "\n",
1234 print_method_body(m,TRUE);
1236 case SIGNAL_FIRST_METHOD:
1237 case SIGNAL_LAST_METHOD:
1239 out_addline_infile(out,m->line_no);
1240 if(m->scope == PRIVATE_SCOPE)
1241 print_method(out,"static ","\n",""," ","\n",
1243 else /* PUBLIC, PROTECTED */
1244 print_method(out,"","\n",""," ","\n",m,FALSE,FALSE);
1245 out_addline_outfile(out);
1246 out_printf(out,"{\n");
1247 s = g_strdup(m->id);
1249 if(strcmp(m->mtype->name,"void")==0 &&
1250 m->mtype->stars==0) {
1251 print_preconditions(m);
1252 if(((FuncArg *)m->args->data)->name)
1253 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (%s),\n"
1254 "\t\tobject_signals[%s_SIGNAL]",
1255 ((FuncArg *)m->args->data)->name,s);
1257 out_printf(out,");\n}\n");
1259 out_printf(out,"\t");
1260 print_type(out,m->mtype,TRUE);
1261 out_printf(out,"return_val;\n");
1262 print_preconditions(m);
1263 out_printf(out,"\tgtk_signal_emit (GTK_OBJECT (%s),\n"
1264 "\t\tobject_signals[%s_SIGNAL]",
1265 ((FuncArg *)m->args->data)->name,s);
1267 out_printf(out,",\n\t\t&return_val);\n"
1268 "\treturn return_val;\n}\n");
1274 out_addline_infile(out,m->line_no);
1275 print_method(out,"static ","\n___real_",""," ","\n",
1277 print_method_body(m,FALSE);
1279 case VIRTUAL_METHOD:
1281 out_addline_infile(out,m->line_no);
1282 if(m->scope==PRIVATE_SCOPE)
1283 print_method(out,"static ","\n",""," ","\n",
1285 else /* PUBLIC, PROTECTED */
1286 print_method(out,"","\n",""," ","\n",m,FALSE,FALSE);
1287 out_addline_outfile(out);
1288 out_printf(out,"{\n"
1289 "\t%sClass *klass;\n",typebase);
1290 print_preconditions(m);
1291 out_printf(out,"\tklass = %s_CLASS(GTK_OBJECT(%s)->klass);\n\n"
1292 "\tif(klass->%s)\n",
1293 macrobase, ((FuncArg *)m->args->data)->name, m->id);
1294 if(strcmp(m->mtype->name,"void")==0 &&
1295 m->mtype->stars==0) {
1297 out_printf(out,"\t\t(*klass->%s)(%s",m->id,
1298 ((FuncArg *)m->args->data)->name);
1299 for(li=m->args->next;li;li=g_list_next(li)) {
1300 FuncArg *fa = li->data;
1301 out_printf(out,",%s",fa->name);
1303 out_printf(out,");\n}\n");
1306 out_printf(out,"\t\treturn (*klass->%s)(%s",m->id,
1307 ((FuncArg *)m->args->data)->name);
1308 for(li=m->args->next;li;li=g_list_next(li)) {
1309 FuncArg *fa = li->data;
1310 out_printf(out,",%s",fa->name);
1312 out_printf(out,");\n"
1315 print_type(out,m->mtype,TRUE);
1316 out_printf(out,")(%s);\n}\n",
1317 m->onerror?m->onerror:"0");
1323 out_addline_infile(out,m->line_no);
1324 print_method(out,"static ","\n___real_",""," ","\n",
1326 print_method_body(m,FALSE);
1328 case OVERRIDE_METHOD:
1332 out_addline_infile(out,m->line_no);
1333 print_method(out,"static ","\n",""," ","\n",
1335 s = replace_sep(m->otype,'_');
1337 args = get_arg_names_for_macro(m);
1339 out_printf(out,"#define PARENT_HANDLER(%s) \\\n"
1340 "\t{ if(%s_CLASS(parent_class)->%s) \\\n"
1341 "\t\t(* %s_CLASS(parent_class)->%s)(%s); }\n",
1342 args,s,m->id,s,m->id,args);
1344 out_printf(out,"#define PARENT_HANDLER(%s) \\\n"
1345 "\t((%s_CLASS(parent_class)->%s)? \\\n"
1346 "\t\t(* %s_CLASS(parent_class)->%s)(%s): \\\n"
1348 args,s,m->id,s,m->id,args);
1349 out_printf(out,"(");
1350 print_type(out,m->mtype,TRUE);
1351 out_printf(out,")%s))\n",
1352 m->onerror?m->onerror:"0");
1356 print_method_body(m,TRUE);
1357 out_printf(out,"#undef PARENT_HANDLER\n");
1367 char *outfile,*outfileh,*outfileph;
1370 outfile = g_strconcat(filebase,".c",NULL);
1372 outfile = g_strconcat(filebase,".cc",NULL);
1373 if(no_touch_headers)
1374 outfileh = g_strconcat("#gob#",filebase,".h#gob#",NULL);
1376 outfileh = g_strconcat(filebase,".h",NULL);
1378 if((privates>0 || protecteds>0 || always_private_header) &&
1380 outfileph = g_strconcat(filebase,"-private.h",NULL);
1385 out = fopen(outfile,"w");
1387 g_error("Cannot open outfile: %s",outfile);
1389 outh = fopen(outfileh,"w");
1391 g_error("Cannot open outfile: %s",outfileh);
1394 outph = fopen(outfileph,"w");
1396 g_error("Cannot open outfile: %s",outfileh);
1402 put_argument_nongnu_wrappers(Class *c)
1409 for(li=c->nodes;li;li=g_list_next(li)) {
1411 Argument *a = (Argument *)n;
1414 if(n->type != ARGUMENT_NODE)
1416 s = g_strdup(a->name);
1419 cast = get_type(a->atype,TRUE);
1421 cast = g_strdup(get_cast(a->gtktype,TRUE));
1425 out_printf(outh, "#define %s_ARG_%s(arg) \t"
1426 "\"%s\",(%s)(arg)\n",
1427 macrobase, s, a->name, cast);
1429 out_printf(outh, "#define %s_GET_ARG_%s(arg)\t"
1430 "\"%s\",(%s*)(arg)\n",
1431 macrobase, s, a->name, cast);
1434 out_printf(outh, "#define %s_ARG_%s(arg) \t"
1436 macrobase, s, a->name);
1438 out_printf(outh, "#define %s_GET_ARG_%s(arg)\t"
1440 macrobase, s, a->name);
1448 put_argument_gnu_wrappers(Class *c)
1455 for(li=c->nodes;li;li=g_list_next(li)) {
1457 Argument *a = (Argument *)n;
1460 if(n->type != ARGUMENT_NODE)
1462 s = g_strdup(a->name);
1465 cast = get_type(a->atype,TRUE);
1467 cast = g_strdup(get_cast(a->gtktype,TRUE));
1470 out_printf(outh, "#define %s_ARG_%s(arg) \t"
1471 "\"%s\",({%sz = (arg); z;})\n",
1472 macrobase, s, a->name, cast);
1474 out_printf(outh, "#define %s_GET_ARG_%s(arg)\t"
1475 "\"%s\",({%s*z = (arg); z;})\n",
1476 macrobase, s, a->name, cast);
1479 out_printf(outh, "#define %s_ARG_%s(arg) \t"
1481 macrobase, s, a->name);
1483 out_printf(outh, "#define %s_GET_ARG_%s(arg)\t"
1485 macrobase, s, a->name);
1493 print_ccode_block(CCode *cc)
1496 switch(cc->cctype) {
1498 /* HT code is printed exactly like normal header
1499 code but is printed before */
1502 out_printf(fp,"\n");
1507 out_printf(fp,"\n");
1508 out_addline_infile(fp,cc->line_no);
1515 out_printf(fp,"\n");
1516 out_addline_infile(fp,cc->line_no);
1519 out_printf(fp,"%s\n",cc->cbuf);
1520 if(cc->cctype == C_CCODE ||
1521 cc->cctype == PH_CCODE)
1522 out_addline_outfile(fp);
1526 print_class_block(Class *c)
1531 out_printf(out,"/* utility types we may need */\n");
1532 out_printf(out,"typedef struct { "
1533 "gpointer a; gpointer b; "
1534 "} ___twopointertype;\n");
1535 out_printf(out,"typedef struct { "
1536 "gpointer a; gpointer b; "
1538 "} ___threepointertype;\n");
1540 out_printf(outh, "\n/*\n"
1541 " * Type checking and casting macros\n"
1543 out_printf(outh,"#define %s\t"
1544 "(%s_get_type())\n",
1545 macrotype,funcbase);
1546 out_printf(outh,"#define %s(obj)\t"
1547 "GTK_CHECK_CAST((obj),%s_get_type(),%s)\n",
1548 macrobase,funcbase,typebase);
1549 out_printf(outh,"#define %s_CLASS(klass)\t"
1550 "GTK_CHECK_CLASS_CAST((klass),%s_get_type(),%sClass)\n",
1551 macrobase,funcbase,typebase);
1552 out_printf(outh,"#define %s(obj)\t"
1553 "GTK_CHECK_TYPE((obj), %s_get_type ())\n\n",
1557 out_printf(outh, "\n/* Private structure type */\n");
1558 out_printf(outh,"typedef struct _%sPrivate %sPrivate;\n",
1562 out_printf(outh, "\n/*\n"
1563 " * Main object structure\n"
1565 s = replace_sep(c->otype,'_');
1567 out_printf(outh,"#ifndef __TYPEDEF_%s__\n"
1568 "#define __TYPEDEF_%s__\n",s,s);
1570 out_printf(outh,"typedef struct _%s %s;\n"
1571 "#endif\n",typebase,typebase);
1572 out_printf(outh,"struct _%s {\n\t%s __parent__;\n",
1573 typebase,ptypebase);
1574 for(l=c->nodes;l;l=g_list_next(l)) {
1576 Variable *v = (Variable *)n;
1577 if(n->type == VARIABLE_NODE &&
1578 v->scope == PUBLIC_SCOPE)
1579 put_variable((Variable *)n,outh);
1581 /* put protecteds always AFTER publics */
1582 for(l=c->nodes;l;l=g_list_next(l)) {
1584 Variable *v = (Variable *)n;
1585 if(n->type == VARIABLE_NODE &&
1586 v->scope == PROTECTED_SCOPE)
1587 put_variable((Variable *)n,outh);
1590 out_printf(outh,"\t%sPrivate *_priv;\n",typebase);
1591 out_printf(outh,"};\n");
1596 /* if we are to stick this into the private
1597 header, if not stick it directly into the
1604 out_printf(outfp,"struct _%sPrivate {\n",
1606 for(l=c->nodes;l;l=l->next) {
1608 Variable *v = (Variable *)n;
1609 if(n->type == VARIABLE_NODE &&
1610 v->scope == PRIVATE_SCOPE) {
1611 out_addline_infile(outfp,v->line_no);
1612 put_variable(v,outfp);
1615 out_addline_outfile(outfp);
1616 out_printf(outfp,"};\n");
1619 out_printf(outh, "\n/*\n"
1620 " * Class definition\n"
1622 out_printf(outh,"typedef struct _%sClass %sClass;\n",
1625 "struct _%sClass {\n\t%sClass __parent__;\n",
1626 typebase,ptypebase);
1627 for(l=c->nodes;l;l=g_list_next(l)) {
1629 if(n->type == METHOD_NODE)
1630 put_vs_method((Method *)n);
1632 out_printf(outh,"};\n\n");
1634 out_printf(out,"/* here are local prototypes */\n");
1636 out_printf(out,"static void ___object_set_arg "
1637 "(GtkObject *object, GtkArg *arg, "
1639 "static void ___object_get_arg "
1640 "(GtkObject *object, GtkArg *arg, "
1641 "guint arg_id);\n");
1644 out_printf(outh, "\n/*\n"
1645 " * Public methods\n"
1648 out_printf(outh,"guint\t%s_get_type\t(void);\n",funcbase);
1649 for(l=c->nodes;l;l=g_list_next(l)) {
1651 if(n->type == METHOD_NODE) {
1652 put_pub_method((Method *)n);
1653 put_prot_method((Method *)n);
1654 put_priv_method_prot((Method *)n);
1658 /* this idea is less and less apealing to me */
1660 if(!no_signal_connect) {
1662 out_printf(outh, "\n/*\n"
1663 " * Signal connection methods\n"
1667 for(l=c->nodes;l;l=g_list_next(l)) {
1669 if(n->type == METHOD_NODE)
1670 put_signal_connect((Method *)n);
1676 /* argument wrapping macros */
1677 if(arguments>0 && !no_gnu) {
1678 out_printf(outh, "\n/*\n"
1679 " * Argument wrapping macros\n"
1681 out_printf(outh,"#ifdef __GNUC__\n");
1682 put_argument_gnu_wrappers(c);
1683 out_printf(outh,"#else /* __GNUC__ */\n");
1684 put_argument_nongnu_wrappers(c);
1685 out_printf(outh,"#endif /* __GNUC__ */\n\n");
1686 } else if(arguments>0 && no_gnu) {
1687 out_printf(outh, "\n/*\n"
1688 " * Argument wrapping macros\n"
1690 put_argument_nongnu_wrappers(c);
1694 for(l=c->nodes;l;l=g_list_next(l)) {
1696 if(n->type == METHOD_NODE)
1697 add_signal_prots((Method *)n);
1706 make_method_nongnu_aliases(c);
1708 out_printf(out,"\n#ifdef __GNUC__\n");
1709 make_method_gnu_aliases(c);
1710 out_printf(out,"#else /* __GNUC__ */\n");
1711 make_method_nongnu_aliases(c);
1712 out_printf(out,"#endif /* __GNUC__ */\n\n");
1715 out_printf(out,"#define GET_NEW (gtk_type_new(%s_get_type()))\n",
1721 add_getset_arg(c, TRUE);
1722 add_getset_arg(c, FALSE);
1725 for(l=c->nodes;l;l=g_list_next(l)) {
1727 if(n->type == METHOD_NODE) {
1728 put_method((Method *)n);
1732 out_printf(out,"#undef GET_NEW\n");
1734 add_bad_hack_to_avoid_unused_warnings(c);
1738 print_version_macros(void)
1740 int major=0,minor=0,pl=0;
1741 sscanf(VERSION,"%d.%d.%d",&major,&minor,&pl);
1743 out_printf(out,"#define GOB_VERSION_MAJOR %d\n", major);
1744 out_printf(out,"#define GOB_VERSION_MINOR %d\n", minor);
1745 out_printf(out,"#define GOB_VERSION_PATCHLEVEL %d\n\n", pl);
1749 print_file_comments(void)
1753 out_printf(outh,"/* Generated by GOB (v%s)"
1754 " (do not edit directly) */\n\n",VERSION);
1756 out_printf(outph,"/* Generated by GOB (v%s)"
1757 " (do not edit directly) */\n\n",VERSION);
1758 out_printf(out,"/* Generated by GOB (v%s) on %s"
1759 " (do not edit directly) */\n\n",VERSION,ctime(&curtime));
1763 print_includes(void)
1765 gboolean found_header;
1768 p = g_strconcat(filebase,".h",NULL);
1769 found_header = TRUE;
1770 if(!g_list_find_custom(include_files,p,(GCompareFunc)strcmp)) {
1771 out_printf(out,"#include \"%s.h\"\n\n",filebase);
1772 found_header = FALSE;
1776 /* if we are creating a private header see if it was included */
1778 p = g_strconcat(filebase,"-private.h",NULL);
1779 if(!g_list_find_custom(include_files,p,(GCompareFunc)strcmp)) {
1780 out_printf(out,"#include \"%s-private.h\"\n\n",
1784 "Implicit private header include "
1786 "\tsource file, while public "
1787 "header is at a custom location, "
1789 "\texplicitly include "
1790 "the private header below the "
1798 print_header_prefixes(void)
1802 p = replace_sep(((Class *)class)->otype,'_');
1804 out_printf(outh,"#ifndef __%s_H__\n#define __%s_H__\n\n",p,p);
1806 out_printf(outph,"#ifndef __%s_PRIVATE_H__\n"
1807 "#define __%s_PRIVATE_H__\n\n"
1808 "#include \"%s.h\"\n\n",p,p,filebase);
1812 out_printf(outh,"#ifdef __cplusplus\n"
1814 "#endif /* __cplusplus */\n\n");
1816 out_printf(outph,"#ifdef __cplusplus\n"
1818 "#endif /* __cplusplus */\n\n");
1823 print_header_postfixes(void)
1826 out_printf(outh,"\n#ifdef __cplusplus\n"
1828 "#endif /* __cplusplus */\n");
1829 out_printf(outh,"\n#endif");
1832 out_printf(outph,"\n#ifdef __cplusplus\n"
1834 "#endif /* __cplusplus */\n");
1835 out_printf(outph,"\n#endif");
1840 print_header_top(void)
1844 /* mandatory include */
1845 out_printf(outh,"#include <gtk/gtk.h>\n\n");
1847 /* print the HT_CCODE blocks */
1848 for(li=nodes;li;li=g_list_next(li)) {
1849 Node *node = li->data;
1850 if(node->type == CCODE_NODE) {
1851 CCode *cc = (CCode *)node;
1852 if(cc->cctype==HT_CCODE)
1853 print_ccode_block((CCode *)node);
1859 generate_outfiles(void)
1863 print_file_comments();
1867 print_header_prefixes();
1869 print_version_macros();
1873 for(li=nodes;li;li=g_list_next(li)) {
1874 Node *node = li->data;
1875 if(node->type == CCODE_NODE) {
1876 CCode *cc = (CCode *)node;
1877 if(cc->cctype!=HT_CCODE)
1878 print_ccode_block((CCode *)node);
1879 } else if(node->type == CLASS_NODE) {
1880 print_class_block((Class *)node);
1882 g_assert_not_reached();
1885 print_header_postfixes();
1891 fprintf(stderr,"Gob version %s\n\n",VERSION);
1892 fprintf(stderr,"Options:\n"
1893 "\t--help,-h,-? Display this help\n"
1894 "\t--version Display version\n"
1895 "\t--exit-on-warn,-w Exit with an error on warnings\n"
1896 "\t--no-exit-on-warn Don't exit on warnings [default]\n"
1897 "\t--for-cpp Create C++ files\n"
1898 "\t--no-extern-c Never print extern \"C\" into the "
1900 "\t--no-gnu Never use GNU extentions\n"
1901 "\t--no-touch-headers Don't touch headers unless they "
1903 "\t--always-private-header Always create a private header "
1905 "\t even if it would be empty\n"
1906 "\t--no-private-header Don't create a private header, "
1908 "\t structure and protected "
1909 "prototypes inside c file\n");
1913 parse_options(int argc, char *argv[])
1916 int got_file = FALSE;
1917 int no_opts = FALSE;
1921 for(i=1;i<argc;i++) {
1922 if(no_opts || argv[i][0]!='-') {
1925 fprintf(stderr,"Specify only one file!\n");
1931 } else if(strcmp(argv[i],"--help")==0) {
1934 } else if(strcmp(argv[i],"--version")==0) {
1935 fprintf(stderr,"Gob version %s\n",VERSION);
1937 } else if(strcmp(argv[i],"--exit-on-warn")==0) {
1938 exit_on_warn = TRUE;
1939 } else if(strcmp(argv[i],"--no-exit-on-warn")==0) {
1940 exit_on_warn = FALSE;
1941 } else if(strcmp(argv[i],"--for-cpp")==0) {
1943 } else if(strcmp(argv[i],"--no-touch-headers")==0) {
1944 no_touch_headers = TRUE;
1945 } else if(strcmp(argv[i],"--always-private-header")==0) {
1946 no_private_header = FALSE;
1947 always_private_header = TRUE;
1948 } else if(strcmp(argv[i],"--no-private-header")==0) {
1949 always_private_header = FALSE;
1950 no_private_header = TRUE;
1951 } else if(strcmp(argv[i],"--no-gnu")==0) {
1953 } else if(strcmp(argv[i],"--no-extern-c")==0) {
1955 } else if(strcmp(argv[i],"--")==0) {
1956 /*further arguments are files*/
1958 } else if(strncmp(argv[i],"--",2)==0) {
1959 /*unknown long option*/
1960 fprintf(stderr,"Unknown option '%s'!\n",argv[i]);
1964 /*by now we know we have a string starting with
1965 - which is a short option string*/
1966 char *p = argv[i]+1;
1967 for(p=argv[i]+1;*p;p++) {
1978 "Unknown option '%c'!\n",*p);
1987 /* this is a somewhat ugly hack, but it appears to work */
1989 compare_and_move_header(void)
1991 char *hfnew = g_strconcat("#gob#",filebase,".h#gob#",NULL);
1992 char *hf = g_strconcat(filebase,".h",NULL);
1994 if(stat(hf,&s)==0) {
1996 s = g_strdup_printf("cmp '%s' '%s' > /dev/null",hf,hfnew);
1998 if(unlink(hfnew)!=0)
1999 print_error(FALSE,"Can't remove new header file",0);
2007 print_error(FALSE,"Can't remove old header file",0);
2009 if(rename(hfnew,hf)!=0)
2010 print_error(FALSE,"Can't rename new header file",0);
2016 main(int argc, char *argv[])
2018 parse_options(argc,argv);
2021 yyin = fopen(filename,"r");
2023 fprintf(stderr,"Error: can't open file '%s'\n",
2032 g_error("Parsing errors, quitting");
2034 print_error(FALSE," no class defined",0);
2037 exit_on_error = FALSE;
2039 signals = count_signals((Class *)class);
2040 arguments = count_arguments((Class *)class);
2041 overrides = count_overrides((Class *)class);
2042 privates = count_privates((Class *)class);
2043 protecteds = count_protecteds((Class *)class);
2046 make_inits((Class *)class);
2048 make_finalize((Class *)class);
2049 check_bad_symbols((Class *)class);
2050 check_duplicate_symbols((Class *)class);
2051 check_duplicate_signals_args((Class *)class);
2052 check_public_new((Class *)class);
2053 check_vararg((Class *)class);
2054 check_firstarg((Class *)class);
2055 check_nonvoidempty((Class *)class);
2056 check_signal_args((Class *)class);
2057 check_argument_types((Class *)class);
2059 exit_on_error = TRUE;
2066 generate_outfiles();
2071 if(no_touch_headers)
2072 compare_and_move_header();