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(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(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(char *base, char *pre)
108 separns_replace_sep(base,&s1,&s2,'_');
110 s = g_strconcat(s1,"_",pre,"_",s2,NULL);
112 s = g_strconcat(pre,"_",s2,NULL);
122 /* here we will find out how inconsistent gtk really is :) */
123 /* the commented out types mean that these types don't actually
124 exist. so we "emulate them" with an equivalent */
125 typedef struct _OurGtkType OurGtkType;
132 const OurGtkType our_gtk_type_table[] = {
133 { TRUE, "NONE", "void ", -1 },
134 { TRUE, "CHAR", "gchar ", -1 },
135 { TRUE, "UCHAR", "guchar ", -1 },
136 { TRUE, "BOOL", "gboolean ", -1 },
137 { TRUE, "INT", "gint ", -1 },
138 { TRUE, "UINT", "guint ", -1 },
139 { TRUE, "LONG", "glong ", -1 },
140 { TRUE, "ULONG", "gulong ", -1 },
141 { TRUE, "FLOAT", "gfloat ", -1 },
142 { TRUE, "DOUBLE", "gdouble ", -1 },
143 { TRUE, "STRING", /*"GtkString"*/"gchar *", -1 },
144 { TRUE, "ENUM", /*"GtkEnum"*/"gint ", -1 },
145 { TRUE, "FLAGS", /*"GtkFlags"*/"guint ", -1 },
146 { TRUE, "BOXED", /*"GtkBoxed"*/"gpointer ", -1 },
147 { TRUE, "POINTER", "gpointer ", -1 },
148 { TRUE, "OBJECT", "GtkObject *", -1 },
149 { FALSE, "SIGNAL", /*"GtkSignal"*/"___twopointertype ",
151 { FALSE, "ARGS", /*"GtkArgs"*/"___intpointertype ",
152 SPECIAL_INT_POINTER },
153 { FALSE, "CALLBACK", /*"GtkCallback"*/"___threepointertype ",
155 { FALSE, "C_CALLBACK", /*"GtkCCallback"*/"___twopointertype ",
157 { FALSE, "FOREIGN", /*"GtkForeign"*/"___twopointertype ",
160 { FALSE, NULL, NULL }
163 static GHashTable *type_hash = NULL;
170 if(type_hash) return;
172 type_hash = g_hash_table_new(g_str_hash, g_str_equal);
174 for(i=0; our_gtk_type_table[i].gtkname; i++)
175 g_hash_table_insert(type_hash,
176 our_gtk_type_table[i].gtkname,
177 (gpointer)&our_gtk_type_table[i]);
181 get_cast(char *type, gboolean simple_only)
187 gtype = g_hash_table_lookup(type_hash, type);
194 return gtype->typename;
198 mask_special_array(char *type, gboolean *special_array, gboolean *any_special)
204 gtype = g_hash_table_lookup(type_hash, type);
206 if(gtype && gtype->special >= 0) {
207 special_array[gtype->special] = TRUE;
213 setup_special_array(Class *c, gboolean *special_array)
216 gboolean any_special = FALSE;
218 memset(special_array, 0, sizeof(gboolean)*SPECIAL_LAST);
220 for(li=c->nodes; li; li=g_list_next(li)) {
222 if(n->type == METHOD_NODE) {
223 Method *m = (Method *)n;
225 if(m->method != SIGNAL_LAST_METHOD &&
226 m->method != SIGNAL_FIRST_METHOD)
229 for(l=m->gtktypes; l; l=l->next)
230 mask_special_array(l->data, special_array,
232 } else if(n->type == ARGUMENT_NODE) {
233 Argument *a = (Argument *)n;
234 mask_special_array(a->gtktype, special_array,
242 /* get the id without the first underscore, but only if we're removing them */
244 get_real_id(char *id)
246 if(!no_kill_underscores &&