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 print_error(gboolean is_warn, char *error, int line)
44 fprintf(stderr, "%s:%d: %s %s\n", filename, line, w, error);
46 fprintf(stderr, "%s: %s %s\n", filename, w, error);
47 if((!is_warn || exit_on_warn) && exit_on_error)
52 remove_sep(char *base)
55 char *s = g_strdup(base);
56 while((p = strchr(s, ':')))
62 replace_sep(const char *base, char r)
65 char *s = g_strdup(base);
66 while((p=strchr(s,':')))
76 /*separate the namespace part and then replace rest of
79 separns_replace_sep(const char *base, char **ns, char **name, char r)
82 char *s = g_strdup(base);
84 if((p=strchr(s,':')) && p!=s) {
91 while((p=strchr(s,':')))
94 *name = g_strdup(s+1);
100 /* make a macro with some prefix before the name but after
103 make_pre_macro(const char *base, const char *pre)
109 if(strchr(base, ' ')) {
111 v = g_strsplit(base, " ", 0);
112 for(i = 0; v[i] != NULL; i++) {
113 if(*v[i] && strcmp(v[i], "const") != 0) {
120 separns_replace_sep(base, &ns, &name, '_');
122 s = g_strconcat(ns, "_", pre, "_", name,NULL);
124 s = g_strconcat(pre, "_", name, NULL);
136 /* here we will find out how inconsistent gtk really is :) */
137 /* the commented out types mean that these types don't actually
138 exist. so we "emulate them" with an equivalent */
139 typedef struct _OurGtkType OurGtkType;
146 const OurGtkType our_gtk_type_table[] = {
147 { TRUE, "NONE", "void ", -1 },
148 { TRUE, "CHAR", "gchar ", -1 },
149 { TRUE, "UCHAR", "guchar ", -1 },
150 { TRUE, "BOOL", "gboolean ", -1 },
151 { TRUE, "INT", "gint ", -1 },
152 { TRUE, "UINT", "guint ", -1 },
153 { TRUE, "LONG", "glong ", -1 },
154 { TRUE, "ULONG", "gulong ", -1 },
155 { TRUE, "FLOAT", "gfloat ", -1 },
156 { TRUE, "DOUBLE", "gdouble ", -1 },
157 { TRUE, "STRING", /*"GtkString"*/"gchar *", -1 },
158 { TRUE, "ENUM", /*"GtkEnum"*/"gint ", -1 },
159 { TRUE, "FLAGS", /*"GtkFlags"*/"guint ", -1 },
160 { TRUE, "BOXED", /*"GtkBoxed"*/"gpointer ", -1 },
161 { TRUE, "POINTER", "gpointer ", -1 },
162 { TRUE, "OBJECT", "GtkObject *", -1 },
163 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
165 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
166 SPECIAL_INT_POINTER },
167 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
169 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
171 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
174 { FALSE, NULL, NULL }
177 static GHashTable *type_hash = NULL;
184 if(type_hash) return;
186 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
188 for(i=0; our_gtk_type_table[i].gtkname; i++)
189 g_hash_table_insert(type_hash,
190 our_gtk_type_table[i].gtkname,
191 (gpointer)&our_gtk_type_table[i]);
195 get_cast(char *type, gboolean simple_only)
201 gtype = g_hash_table_lookup(type_hash, type);
208 return gtype->typename;
212 mask_special_array(char *type, gboolean *special_array, gboolean *any_special)
218 gtype = g_hash_table_lookup(type_hash, type);
220 if(gtype && gtype->special >= 0) {
221 special_array[gtype->special] = TRUE;
227 setup_special_array(Class *c, gboolean *special_array)
230 gboolean any_special = FALSE;
232 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
234 for(li=c->nodes; li; li=g_list_next(li)) {
236 if(n->type == METHOD_NODE) {
237 Method *m = (Method *)n;
239 if(m->method != SIGNAL_LAST_METHOD &&
240 m->method != SIGNAL_FIRST_METHOD)
243 for(l=m->gtktypes; l; l=l->next)
244 mask_special_array(l->data, special_array,
246 } else if(n->type == ARGUMENT_NODE) {
247 Argument *a = (Argument *)n;
248 mask_special_array(a->gtktype, special_array,
256 /* get the id without the first underscore, but only if we're removing them */
258 get_real_id(char *id)
260 if(!no_kill_underscores &&