2 * Copyright (C) 1999-2000 the Free Software Foundation.
3 * Copyright (C) 2000 Eazel, Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
29 #include "treefuncs.h"
35 error_print(int type, int line, const char *error)
48 g_assert_not_reached();
51 fprintf(stderr, "%s:%d: %s %s\n", filename, line, w, error);
53 fprintf(stderr, "%s: %s %s\n", filename, w, error);
56 (type == GOB_WARN && exit_on_warn)))
61 error_printf(int type, int line, const char *error, ...)
67 s = g_strdup_vprintf(error, ap);
70 error_print(type, line, s);
76 remove_sep(const char *base)
79 char *s = g_strdup(base);
80 while((p = strchr(s, ':')))
86 replace_sep(const char *base, char r)
89 char *s = g_strdup(base);
90 while((p=strchr(s,':')))
100 /*separate the namespace part and then replace rest of
103 separns_replace_sep(const char *base, char **ns, char **name, char r)
106 char *s = g_strdup(base);
108 if((p=strchr(s,':')) && p!=s) {
115 while((p=strchr(s,':')))
118 *name = g_strdup(s+1);
124 /* make a macro with some prefix before the name but after
127 make_pre_macro(const char *base, const char *pre)
133 if(strchr(base, ' ')) {
135 v = g_strsplit(base, " ", 0);
136 for(i = 0; v[i] != NULL; i++) {
137 if(*v[i] && strcmp(v[i], "const") != 0) {
144 separns_replace_sep(base, &ns, &name, '_');
146 s = g_strconcat(ns, "_", pre, "_", name,NULL);
148 s = g_strconcat(pre, "_", name, NULL);
160 /* here we will find out how inconsistent gtk really is :) */
161 /* the commented out types mean that these types don't actually
162 exist. so we "emulate them" with an equivalent */
163 typedef struct _OurGtkType OurGtkType;
170 const OurGtkType our_gtk_type_table[] = {
171 { TRUE, "NONE", "void ", -1 },
172 { TRUE, "CHAR", "gchar ", -1 },
173 { TRUE, "UCHAR", "guchar ", -1 },
174 { TRUE, "BOOL", "gboolean ", -1 },
175 { TRUE, "INT", "gint ", -1 },
176 { TRUE, "UINT", "guint ", -1 },
177 { TRUE, "LONG", "glong ", -1 },
178 { TRUE, "ULONG", "gulong ", -1 },
179 { TRUE, "FLOAT", "gfloat ", -1 },
180 { TRUE, "DOUBLE", "gdouble ", -1 },
181 { TRUE, "STRING", /*"GtkString"*/"gchar *", -1 },
182 { TRUE, "ENUM", /*"GtkEnum"*/"gint ", -1 },
183 { TRUE, "FLAGS", /*"GtkFlags"*/"guint ", -1 },
184 { TRUE, "BOXED", /*"GtkBoxed"*/"gpointer ", -1 },
185 { TRUE, "POINTER", "gpointer ", -1 },
186 { TRUE, "OBJECT", "GtkObject *", -1 },
187 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
189 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
190 SPECIAL_INT_POINTER },
191 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
193 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
195 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
198 { FALSE, NULL, NULL }
201 static GHashTable *type_hash = NULL;
208 if(type_hash) return;
210 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
212 for(i=0; our_gtk_type_table[i].gtkname; i++)
213 g_hash_table_insert(type_hash,
214 our_gtk_type_table[i].gtkname,
215 (gpointer)&our_gtk_type_table[i]);
219 get_cast(const char *type, gboolean simple_only)
225 gtype = g_hash_table_lookup(type_hash, type);
232 return gtype->typename;
236 mask_special_array(char *type, gboolean *special_array, gboolean *any_special)
242 gtype = g_hash_table_lookup(type_hash, type);
244 if(gtype && gtype->special >= 0) {
245 special_array[gtype->special] = TRUE;
251 setup_special_array(Class *c, gboolean *special_array)
254 gboolean any_special = FALSE;
256 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
258 for(li=c->nodes; li; li=g_list_next(li)) {
260 if(n->type == METHOD_NODE) {
261 Method *m = (Method *)n;
263 if(m->method != SIGNAL_LAST_METHOD &&
264 m->method != SIGNAL_FIRST_METHOD)
267 for(l=m->gtktypes; l; l=l->next)
268 mask_special_array(l->data, special_array,
270 } else if(n->type == ARGUMENT_NODE) {
271 Argument *a = (Argument *)n;
272 mask_special_array(a->gtktype, special_array,
280 /* get the id without the first underscore, but only if we're removing them */
282 get_real_id(const char *id)
284 if( ! no_kill_underscores &&