2 * Copyright (C) 1999-2000 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,
27 #include "treefuncs.h"
33 print_error(gboolean is_warn, char *error, int line)
43 fprintf(stderr, "%s:%d: %s %s\n", filename, line, w, error);
45 fprintf(stderr, "%s: %s %s\n", filename, w, error);
46 if((!is_warn || exit_on_warn) && exit_on_error)
51 remove_sep(char *base)
54 char *s = g_strdup(base);
55 while((p=strchr(s,':')))
61 replace_sep(char *base, char r)
64 char *s = g_strdup(base);
65 while((p=strchr(s,':')))
75 /*separate the namespace part and then replace rest of
78 separns_replace_sep(char *base, char **ns, char **name, char r)
81 char *s = g_strdup(base);
83 if((p=strchr(s,':')) && p!=s) {
90 while((p=strchr(s,':')))
93 *name = g_strdup(s+1);
99 /* make a macro with some prefix before the name but after
102 make_pre_macro(char *base, char *pre)
107 separns_replace_sep(base,&s1,&s2,'_');
109 s = g_strconcat(s1,"_",pre,"_",s2,NULL);
111 s = g_strconcat(pre,"_",s2,NULL);
121 /* here we will find out how inconsistent gtk really is :) */
122 /* the commented out types mean that these types don't actually
123 exist. so we "emulate them" with an equivalent */
124 typedef struct _OurGtkType OurGtkType;
131 const OurGtkType our_gtk_type_table[] = {
132 { TRUE, "NONE", "void ", -1 },
133 { TRUE, "CHAR", "gchar ", -1 },
134 { TRUE, "UCHAR", "guchar ", -1 },
135 { TRUE, "BOOL", "gboolean ", -1 },
136 { TRUE, "INT", "gint ", -1 },
137 { TRUE, "UINT", "guint ", -1 },
138 { TRUE, "LONG", "glong ", -1 },
139 { TRUE, "ULONG", "gulong ", -1 },
140 { TRUE, "FLOAT", "gfloat ", -1 },
141 { TRUE, "DOUBLE", "gdouble ", -1 },
142 { TRUE, "STRING", /*"GtkString"*/"gchar *", -1 },
143 { TRUE, "ENUM", /*"GtkEnum"*/"gint ", -1 },
144 { TRUE, "FLAGS", /*"GtkFlags"*/"guint ", -1 },
145 { TRUE, "BOXED", /*"GtkBoxed"*/"gpointer ", -1 },
146 { TRUE, "POINTER", "gpointer ", -1 },
147 { TRUE, "OBJECT", "GtkObject *", -1 },
148 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
150 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
151 SPECIAL_INT_POINTER },
152 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
154 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
156 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
159 { FALSE, NULL, NULL }
162 static GHashTable *type_hash = NULL;
169 if(type_hash) return;
171 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
173 for(i=0; our_gtk_type_table[i].gtkname; i++)
174 g_hash_table_insert(type_hash,
175 our_gtk_type_table[i].gtkname,
176 (gpointer)&our_gtk_type_table[i]);
180 get_cast(char *type, gboolean simple_only)
186 gtype = g_hash_table_lookup(type_hash, type);
193 return gtype->typename;
197 mask_special_array(char *type, gboolean *special_array, gboolean *any_special)
203 gtype = g_hash_table_lookup(type_hash, type);
205 if(gtype && gtype->special >= 0) {
206 special_array[gtype->special] = TRUE;
212 setup_special_array(Class *c, gboolean *special_array)
215 gboolean any_special = FALSE;
217 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
219 for(li=c->nodes; li; li=g_list_next(li)) {
221 if(n->type == METHOD_NODE) {
222 Method *m = (Method *)n;
224 if(m->method != SIGNAL_LAST_METHOD &&
225 m->method != SIGNAL_FIRST_METHOD)
228 for(l=m->gtktypes; l; l=l->next)
229 mask_special_array(l->data, special_array,
231 } else if(n->type == ARGUMENT_NODE) {
232 Argument *a = (Argument *)n;
233 mask_special_array(a->gtktype, special_array,