]> git.draconx.ca Git - gob-dx.git/blobdiff - src/util.c
Release 1.99.1
[gob-dx.git] / src / util.c
index acc112e0757ab42424ea10dd02612795128ff6ed..cc523ed529a4e0d7bbce4e62416adbcfa0d8a2bf 100644 (file)
@@ -21,6 +21,7 @@
  */
 
 #include "config.h"
+#include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <glib.h>
@@ -163,26 +164,36 @@ typedef struct _OurGtkType OurGtkType;
 struct _OurGtkType {
        gboolean simple;
        char *gtkname;
-       char *typename;
+       char *cast;
+       char *type_name;
+       char *type_pointer;
        int special;
 };
 const OurGtkType our_gtk_type_table[] = {
-       { TRUE, "NONE",         "void ", -1 },
-       { TRUE, "CHAR",         "gchar ", -1 },
-       { TRUE, "UCHAR",        "guchar ", -1 },
-       { TRUE, "BOOL",         "gboolean ", -1 },
-       { TRUE, "INT",          "gint ", -1 },
-       { TRUE, "UINT",         "guint ", -1 },
-       { TRUE, "LONG",         "glong ", -1 },
-       { TRUE, "ULONG",        "gulong ", -1 },
-       { TRUE, "FLOAT",        "gfloat ", -1 },
-       { TRUE, "DOUBLE",       "gdouble ", -1 },
-       { TRUE, "STRING",       /*"GtkString"*/"gchar *", -1 },
-       { TRUE, "ENUM",         /*"GtkEnum"*/"gint ", -1 },
-       { TRUE, "FLAGS",        /*"GtkFlags"*/"guint ", -1 },
-       { TRUE, "BOXED",        /*"GtkBoxed"*/"gpointer ", -1 },
-       { TRUE, "POINTER",      "gpointer ", -1 },
-       { TRUE, "OBJECT",       "GtkObject *", -1 },
+       { TRUE, "NONE",         "void ",        "void",         NULL,   -1 },
+       { TRUE, "CHAR",         "gchar ",       "gchar",        NULL,   -1 },
+       { TRUE, "UCHAR",        "guchar ",      "guchar",       NULL,   -1 },
+       { TRUE, "BOOLEAN",      "gboolean ",    "gboolean",     NULL,   -1 },
+       { TRUE, "INT",          "gint ",        "gint",         NULL,   -1 },
+       { TRUE, "UINT",         "guint ",       "guint",        NULL,   -1 },
+       { TRUE, "LONG",         "glong ",       "glong",        NULL,   -1 },
+       { TRUE, "ULONG",        "gulong ",      "gulong",       NULL,   -1 },
+       { TRUE, "ENUM",         /*"enum"*/"gint ", "gint",      NULL,   -1 },
+       { TRUE, "FLAGS",        /*"flags"*/"guint ", "guint",   NULL,   -1 },
+       { TRUE, "FLOAT",        "gfloat ",      "gfloat",       NULL,   -1 },
+       { TRUE, "DOUBLE",       "gdouble ",     "gdouble",      NULL,   -1 },
+       { TRUE, "STRING",       /*"string"*/"gchar *", "gchar", "*",    -1 },
+       { TRUE, "POINTER",      "gpointer ",    "gpointer",     NULL,   -1 },
+       { TRUE, "BOXED",        /*"boxed"*/"gpointer ", "gpointer", NULL, -1 },
+       { TRUE, "OBJECT",       "GObject *",    "GObject",      "*",    -1 },
+       { TRUE, "PARAM",        "GParamSpec *", "GParamSpec",   "*",    -1 },
+
+       /* FIXME: VALUE_ARRAY, CLOSURE, UNICHAR */
+       /* Note that those have some issues with g_value_ calls etc... so
+        * we can't just add them */
+
+       /* Do we need this??? */
+#if 0
        { FALSE, "SIGNAL",      /*"GtkSignal"*/"___twopointertype ",
                SPECIAL_2POINTER },
        { FALSE, "ARGS",        /*"GtkArgs"*/"___intpointertype ",
@@ -193,6 +204,7 @@ const OurGtkType our_gtk_type_table[] = {
                SPECIAL_2POINTER },
        { FALSE, "FOREIGN",     /*"GtkForeign"*/"___twopointertype ",
                SPECIAL_2POINTER },
+#endif
 
        { FALSE, NULL, NULL }
 };
@@ -215,20 +227,43 @@ init_type_hash(void)
 }
 
 const char *
-get_cast(char *type, gboolean simple_only)
+get_cast (const char *type, gboolean simple_only)
 {
        OurGtkType *gtype;
 
-       init_type_hash();
+       init_type_hash ();
 
-       gtype = g_hash_table_lookup(type_hash, type);
+       gtype = g_hash_table_lookup (type_hash, type);
 
-       if(!gtype ||
-          (simple_only &&
-           !gtype->simple))
+       if (gtype == NULL ||
+           (simple_only &&
+            ! gtype->simple))
                return NULL;
 
-       return gtype->typename;
+       return gtype->cast;
+}
+
+Type *
+get_tree_type (const char *type, gboolean simple_only)
+{
+       OurGtkType *gtype;
+       Node *node;
+
+       init_type_hash ();
+
+       gtype = g_hash_table_lookup (type_hash, type);
+
+       if (gtype == NULL ||
+           (simple_only &&
+            ! gtype->simple))
+               return NULL;
+
+       node = node_new (TYPE_NODE,
+                        "name", gtype->type_name,
+                        "pointer", gtype->type_pointer,
+                        NULL);
+
+       return (Type *)node;
 }
 
 static void
@@ -275,15 +310,3 @@ setup_special_array(Class *c, gboolean *special_array)
 
        return any_special;
 }
-
-/* get the id without the first underscore, but only if we're removing them */
-const char *
-get_real_id(const char *id)
-{
-       if( ! no_kill_underscores &&
-           id[0] == '_' &&
-           id[1] != '\0')
-               return &id[1];
-       else
-               return id;
-}