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,
28 #include "treefuncs.h"
34 error_print(int type, int line, const char *error)
47 g_assert_not_reached();
50 fprintf(stderr, "%s:%d: %s %s\n", filename, line, w, error);
52 fprintf(stderr, "%s: %s %s\n", filename, w, error);
55 (type == GOB_WARN && exit_on_warn)))
60 error_printf(int type, int line, const char *error, ...)
66 s = g_strdup_vprintf(error, ap);
69 error_print(type, line, s);
75 remove_sep(const char *base)
78 char *s = g_strdup(base);
79 while((p = strchr(s, ':')))
85 replace_sep(const char *base, char r)
88 char *s = g_strdup(base);
89 while((p=strchr(s,':')))
99 /*separate the namespace part and then replace rest of
102 separns_replace_sep(const char *base, char **ns, char **name, char r)
105 char *s = g_strdup(base);
107 if((p=strchr(s,':')) && p!=s) {
114 while((p=strchr(s,':')))
117 *name = g_strdup(s+1);
123 /* make a macro with some prefix before the name but after
126 make_pre_macro(const char *base, const char *pre)
132 if(strchr(base, ' ')) {
134 v = g_strsplit(base, " ", 0);
135 for(i = 0; v[i] != NULL; i++) {
136 if(*v[i] && strcmp(v[i], "const") != 0) {
143 separns_replace_sep(base, &ns, &name, '_');
145 s = g_strconcat(ns, "_", pre, "_", name,NULL);
147 s = g_strconcat(pre, "_", name, NULL);
159 /* here we will find out how inconsistent gtk really is :) */
160 /* the commented out types mean that these types don't actually
161 exist. so we "emulate them" with an equivalent */
162 typedef struct _OurGtkType OurGtkType;
169 const OurGtkType our_gtk_type_table[] = {
170 { TRUE, "NONE", "void ", -1 },
171 { TRUE, "CHAR", "gchar ", -1 },
172 { TRUE, "UCHAR", "guchar ", -1 },
173 { TRUE, "BOOL", "gboolean ", -1 },
174 { TRUE, "INT", "gint ", -1 },
175 { TRUE, "UINT", "guint ", -1 },
176 { TRUE, "LONG", "glong ", -1 },
177 { TRUE, "ULONG", "gulong ", -1 },
178 { TRUE, "FLOAT", "gfloat ", -1 },
179 { TRUE, "DOUBLE", "gdouble ", -1 },
180 { TRUE, "STRING", /*"GtkString"*/"gchar *", -1 },
181 { TRUE, "ENUM", /*"GtkEnum"*/"gint ", -1 },
182 { TRUE, "FLAGS", /*"GtkFlags"*/"guint ", -1 },
183 { TRUE, "BOXED", /*"GtkBoxed"*/"gpointer ", -1 },
184 { TRUE, "POINTER", "gpointer ", -1 },
185 { TRUE, "OBJECT", "GtkObject *", -1 },
186 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
188 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
189 SPECIAL_INT_POINTER },
190 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
192 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
194 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
197 { FALSE, NULL, NULL }
200 static GHashTable *type_hash = NULL;
207 if(type_hash) return;
209 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
211 for(i=0; our_gtk_type_table[i].gtkname; i++)
212 g_hash_table_insert(type_hash,
213 our_gtk_type_table[i].gtkname,
214 (gpointer)&our_gtk_type_table[i]);
218 get_cast(char *type, gboolean simple_only)
224 gtype = g_hash_table_lookup(type_hash, type);
231 return gtype->typename;
235 mask_special_array(char *type, gboolean *special_array, gboolean *any_special)
241 gtype = g_hash_table_lookup(type_hash, type);
243 if(gtype && gtype->special >= 0) {
244 special_array[gtype->special] = TRUE;
250 setup_special_array(Class *c, gboolean *special_array)
253 gboolean any_special = FALSE;
255 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
257 for(li=c->nodes; li; li=g_list_next(li)) {
259 if(n->type == METHOD_NODE) {
260 Method *m = (Method *)n;
262 if(m->method != SIGNAL_LAST_METHOD &&
263 m->method != SIGNAL_FIRST_METHOD)
266 for(l=m->gtktypes; l; l=l->next)
267 mask_special_array(l->data, special_array,
269 } else if(n->type == ARGUMENT_NODE) {
270 Argument *a = (Argument *)n;
271 mask_special_array(a->gtktype, special_array,
279 /* get the id without the first underscore, but only if we're removing them */
281 get_real_id(const char *id)
283 if( ! no_kill_underscores &&