+static void
+print_enum (EnumDef *enode)
+{
+ GList *li;
+ char *funcprefix;
+ char *type;
+ char *str;
+
+ funcprefix = replace_sep (enode->etype, '_');
+ gob_strdown (funcprefix);
+ out_printf (out, "static const GEnumValue _%s_values[] = {\n",
+ funcprefix);
+ type = remove_sep (enode->etype);
+
+ out_printf (outh, "\ntypedef enum {\n");
+
+ for (li = enode->values; li != NULL; li = li->next) {
+ EnumValue *value = li->data;
+ char *p;
+ char *sname = gob_strdown (g_strdup (value->name));
+
+ while ((p = strchr (sname, '_')) != NULL)
+ *p = '-';
+
+ out_printf (outh, "\t%s_%s", enode->prefix, value->name);
+ if (value->value != NULL)
+ out_printf (outh, " = %s", value->value);
+ if (li->next != NULL)
+ out_printf (outh, ",\n");
+ else
+ out_printf (outh, "\n");
+
+ out_printf (out, "\t{ %s_%s, \"%s_%s\", \"%s\" },\n",
+ enode->prefix, value->name,
+ enode->prefix, value->name,
+ sname);
+
+ g_free (sname);
+ }
+
+ out_printf (out, "\t{ 0, NULL, NULL }\n};\n\n");
+
+ out_printf (outh, "} %s;\n", type);
+
+ str = make_pre_macro (enode->etype, "TYPE");
+ out_printf (outh, "#define %s ", str);
+ g_free (str);
+
+ out_printf (outh, "%s_get_type()\n", funcprefix);
+ out_printf (outh, "GType %s_get_type (void);\n\n", funcprefix);
+
+ out_printf (out,
+ "GType\n%s_get_type (void)\n"
+ "{\n"
+ "\tstatic GType type = 0;\n"
+ "\tif ___GOB_UNLIKELY(type == 0)\n"
+ "\t\ttype = g_enum_register_static (\"%s\", _%s_values);\n"
+ "\treturn type;\n"
+ "}\n\n",
+ funcprefix, type, funcprefix);
+
+ g_free (funcprefix);
+ g_free (type);
+}
+
+static void
+print_flags (Flags *fnode)
+{
+ GList *li;
+ char *funcprefix;
+ char *type;
+ char *str;
+ int i;
+
+ funcprefix = replace_sep (fnode->ftype, '_');
+ gob_strdown (funcprefix);
+ out_printf (out, "static const GFlagsValue _%s_values[] = {\n",
+ funcprefix);
+ type = remove_sep (fnode->ftype);
+
+ out_printf (outh, "\ntypedef enum {\n");
+
+ for (i = 0, li = fnode->values; li != NULL; i++, li = li->next) {
+ const char *name = li->data;
+ char *p;
+ char *sname = gob_strdown (g_strdup (name));
+
+ while ((p = strchr (sname, '_')) != NULL)
+ *p = '-';
+
+ out_printf (outh, "\t%s_%s = 1<<%d",
+ fnode->prefix, name, i);
+ if (li->next != NULL)
+ out_printf (outh, ",\n");
+ else
+ out_printf (outh, "\n");
+
+ out_printf (out, "\t{ %s_%s, \"%s_%s\", \"%s\" },\n",
+ fnode->prefix, name,
+ fnode->prefix, name,
+ sname);
+
+ g_free (sname);
+ }
+
+ out_printf (out, "\t{ 0, NULL, NULL }\n};\n\n");
+
+ out_printf (outh, "} %s;\n", type);
+
+ str = make_pre_macro (fnode->ftype, "TYPE");
+ out_printf (outh, "#define %s ", str);
+ g_free (str);
+
+ out_printf (outh, "%s_get_type()\n", funcprefix);
+ out_printf (outh, "GType %s_get_type (void);\n\n", funcprefix);
+
+ out_printf (out,
+ "GType\n%s_get_type (void)\n"
+ "{\n"
+ "\tstatic GType type = 0;\n"
+ "\tif ___GOB_UNLIKELY(type == 0)\n"
+ "\t\ttype = g_flags_register_static (\"%s\", _%s_values);\n"
+ "\treturn type;\n"
+ "}\n\n",
+ funcprefix, type, funcprefix);
+
+ g_free (funcprefix);
+ g_free (type);
+}
+
+static void
+print_error (Error *enode)
+{
+ GList *li;
+ char *funcprefix;
+ char *type;
+ char *str;
+
+ funcprefix = replace_sep (enode->etype, '_');
+ gob_strdown (funcprefix);
+ out_printf (out, "static const GEnumValue _%s_values[] = {\n",
+ funcprefix);
+ type = remove_sep (enode->etype);
+
+ out_printf (outh, "\ntypedef enum {\n");
+
+ for (li = enode->values; li != NULL; li = li->next) {
+ const char *name = li->data;
+ char *p;
+ char *sname = gob_strdown (g_strdup (name));
+
+ while ((p = strchr (sname, '_')) != NULL)
+ *p = '-';
+
+ out_printf (outh, "\t%s_%s", enode->prefix, name);
+ if (li->next != NULL)
+ out_printf (outh, ",\n");
+ else
+ out_printf (outh, "\n");
+
+ out_printf (out, "\t{ %s_%s, \"%s_%s\", \"%s\" },\n",
+ enode->prefix, name,
+ enode->prefix, name,
+ sname);
+
+ g_free (sname);
+ }
+
+ out_printf (out, "\t{ 0, NULL, NULL }\n};\n\n");
+
+ out_printf (outh, "} %s;\n", type);
+
+ str = make_pre_macro (enode->etype, "TYPE");
+ out_printf (outh, "#define %s ", str);
+ g_free (str);
+
+ out_printf (outh, "%s_get_type ()\n", funcprefix);
+ out_printf (outh, "GType %s_get_type (void);\n\n", funcprefix);
+
+ out_printf (out,
+ "GType\n%s_get_type (void)\n"
+ "{\n"
+ "\tstatic GType type = 0;\n"
+ "\tif ___GOB_UNLIKELY(type == 0)\n"
+ "\t\ttype = g_enum_register_static (\"%s\", _%s_values);\n"
+ "\treturn type;\n"
+ "}\n\n",
+ funcprefix, type, funcprefix);
+
+ out_printf (outh, "#define %s %s_quark ()\n", enode->prefix, funcprefix);
+ out_printf (outh, "GQuark %s_quark (void);\n\n", funcprefix);
+
+ str = replace_sep (enode->etype, '-');
+ gob_strdown (str);
+
+ out_printf (out,
+ "GQuark\n%s_quark (void)\n"
+ "{\n"
+ "\tstatic GQuark q = 0;\n"
+ "\tif (q == 0)\n"
+ "\t\tq = g_quark_from_static_string (\"%s\");\n"
+ "\treturn q;\n"
+ "}\n\n",
+ funcprefix, str);
+
+ g_free (str);
+
+ g_free (funcprefix);
+ g_free (type);
+}
+