[POS-commit] r159 - in libglade: . patches
Johan Dahlin
jdahlin at async.com.br
Tue Mar 22 11:00:47 BRT 2005
Author: jdahlin
Date: 2005-03-22 11:00:47 -0300 (Tue, 22 Mar 2005)
New Revision: 159
Added:
libglade/patches/
libglade/patches/GMarkup.patch
Modified:
libglade/glade-parser.c
Log:
Apply GMarkup patch
Modified: libglade/glade-parser.c
===================================================================
--- libglade/glade-parser.c 2005-03-22 14:00:25 UTC (rev 158)
+++ libglade/glade-parser.c 2005-03-22 14:00:47 UTC (rev 159)
@@ -34,7 +34,7 @@
# define dgettext(Domain, String) (String)
#endif
-#include <libxml/parser.h>
+#include <glib/gmarkup.h>
#include "glade-parser.h"
#include "glade-private.h"
@@ -153,18 +153,20 @@
}
static GladeWidgetInfo *
-create_widget_info(GladeInterface *interface, const xmlChar **attrs)
+create_widget_info(GladeInterface *interface,
+ const gchar **names,
+ const gchar **values)
{
GladeWidgetInfo *info = g_new0(GladeWidgetInfo, 1);
int i;
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "class"))
- info->classname = alloc_string(interface, attrs[i+1]);
- else if (!strcmp(attrs[i], "id"))
- info->name = alloc_string(interface, attrs[i+1]);
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "class"))
+ info->classname = alloc_string(interface, values[i]);
+ else if (!strcmp(names[i], "id"))
+ info->name = alloc_string(interface, values[i]);
else
- g_warning("unknown attribute `%s' for <widget>.", attrs[i]);
+ g_warning("unknown attribute `%s' for <widget>.", names[i]);
}
if (info->classname == NULL || info->name == NULL)
g_warning("<widget> element missing required attributes!");
@@ -259,22 +261,24 @@
}
static inline void
-handle_atk_action(GladeParseState *state, const xmlChar **attrs)
+handle_atk_action(GladeParseState *state,
+ const gchar **names,
+ const gchar **values)
{
gint i;
GladeAtkActionInfo info = { NULL };
flush_properties(state);
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "action_name"))
- info.action_name = alloc_string(state->interface, attrs[i+1]);
- else if (!strcmp(attrs[i], "description"))
- info.description = alloc_string(state->interface,
- dgettext(state->domain, attrs[i+1]));
- else
- g_warning("unknown attribute `%s' for <action>.", attrs[i]);
- }
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "action_name"))
+ info.action_name = alloc_string(state->interface, values[i]);
+ else if (!strcmp(names[i], "description"))
+ info.description = alloc_string(state->interface,
+ dgettext(state->domain, values[i]));
+ else
+ g_warning("unknown attribute `%s' for <action>.", names[i]);
+ }
if (info.action_name == NULL) {
g_warning("required <atkaction> attribute 'action_name' missing!!!");
return;
@@ -286,20 +290,22 @@
}
static inline void
-handle_atk_relation(GladeParseState *state, const xmlChar **attrs)
+handle_atk_relation(GladeParseState *state,
+ const gchar **names,
+ const gchar **values)
{
gint i;
GladeAtkRelationInfo info = { NULL };
flush_properties(state);
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "target"))
- info.target = alloc_string(state->interface, attrs[i+1]);
- else if (!strcmp(attrs[i], "type"))
- info.type = alloc_string(state->interface, attrs[i+1]);
- else
- g_warning("unknown attribute `%s' for <signal>.", attrs[i]);
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "target"))
+ info.target = alloc_string(state->interface, values[i]);
+ else if (!strcmp(names[i], "type"))
+ info.type = alloc_string(state->interface, values[i]);
+ else
+ g_warning("unknown attribute `%s' for <signal>.", names[i]);
}
if (info.target == NULL || info.type == NULL) {
g_warning("required <atkrelation> attributes ('target' and/or 'type') missing!!!");
@@ -312,7 +318,9 @@
}
static inline void
-handle_signal(GladeParseState *state, const xmlChar **attrs)
+handle_signal(GladeParseState *state,
+ const gchar **names,
+ const gchar **values)
{
GladeSignalInfo info = { NULL };
gint i;
@@ -320,19 +328,19 @@
flush_properties(state);
info.after = FALSE;
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "name"))
- info.name = alloc_string(state->interface, attrs[i+1]);
- else if (!strcmp(attrs[i], "handler"))
- info.handler = alloc_string(state->interface, attrs[i+1]);
- else if (!strcmp(attrs[i], "after"))
- info.after = attrs[i+1][0] == 'y';
- else if (!strcmp(attrs[i], "object"))
- info.object = alloc_string(state->interface, attrs[i+1]);
- else if (!strcmp(attrs[i], "last_modification_time"))
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "name"))
+ info.name = alloc_string(state->interface, values[i]);
+ else if (!strcmp(names[i], "handler"))
+ info.handler = alloc_string(state->interface, values[i]);
+ else if (!strcmp(names[i], "after"))
+ info.after = values[i][0] == 'y';
+ else if (!strcmp(names[i], "object"))
+ info.object = alloc_string(state->interface, values[i]);
+ else if (!strcmp(names[i], "last_modification_time"))
/* Do nothing. */;
else
- g_warning("unknown attribute `%s' for <signal>.", attrs[i]);
+ g_warning("unknown attribute `%s' for <signal>.", names[i]);
}
if (info.name == NULL || info.handler == NULL) {
g_warning("required <signal> attributes missing!!!");
@@ -345,7 +353,9 @@
}
static inline void
-handle_accel(GladeParseState *state, const xmlChar **attrs)
+handle_accel(GladeParseState *state,
+ const gchar **names,
+ const gchar **values)
{
GladeAccelInfo info = { 0 };
gint i;
@@ -355,11 +365,11 @@
flush_actions(state);
flush_relations(state);
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "key"))
- info.key = gdk_keyval_from_name(attrs[i+1]);
- else if (!strcmp(attrs[i], "modifiers")) {
- const xmlChar *pos = attrs[i+1];
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "key"))
+ info.key = gdk_keyval_from_name(values[i]);
+ else if (!strcmp(names[i], "modifiers")) {
+ const gchar *pos = values[i];
info.modifiers = 0;
while (pos[0])
@@ -411,10 +421,10 @@
pos++;
} else
pos++;
- } else if (!strcmp(attrs[i], "signal"))
- info.signal = alloc_string(state->interface, attrs[i+1]);
+ } else if (!strcmp(names[i], "signal"))
+ info.signal = alloc_string(state->interface, values[i]);
else
- g_warning("unknown attribute `%s' for <accelerator>.", attrs[i]);
+ g_warning("unknown attribute `%s' for <accelerator>.", names[i]);
}
if (info.key == 0 || info.signal == NULL) {
g_warning("required <accelerator> attributes missing!!!");
@@ -427,7 +437,9 @@
}
static inline void
-handle_child(GladeParseState *state, const xmlChar **attrs)
+handle_child(GladeParseState *state,
+ const gchar **names,
+ const gchar **values)
{
GladeChildInfo *info;
gint i;
@@ -448,11 +460,11 @@
info->n_properties = 0;
info->child = NULL;
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "internal-child"))
- info->internal_child = alloc_string(state->interface, attrs[i+1]);
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "internal-child"))
+ info->internal_child = alloc_string(state->interface, values[i]);
else
- g_warning("unknown attribute `%s' for <child>.", attrs[i]);
+ g_warning("unknown attribute `%s' for <child>.", names[i]);
}
}
@@ -496,9 +508,13 @@
}
static void
-glade_parser_start_element(GladeParseState *state,
- const xmlChar *name, const xmlChar **attrs)
-{
+glade_parser_start_element (GMarkupParseContext *context,
+ const gchar *name,
+ const gchar **names,
+ const gchar **values,
+ GladeParseState *state,
+ GError **error)
+{
int i;
GLADE_NOTE(PARSER, g_message("<%s> in state %s",
@@ -510,13 +526,13 @@
state->state = PARSER_GLADE_INTERFACE;
#if 0
/* check for correct XML namespace */
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "xmlns") &&
- !strcmp(attrs[i+1], "...")) {
- g_warning("bad XML namespace `%s'.", attrs[i+1]);
+ for (i = 0; names && names[i] != NULL; i ++) {
+ if (!strcmp(names[i], "xmlns") &&
+ !strcmp(values[i], "...")) {
+ g_warning("bad XML namespace `%s'.", values[i]);
} else
g_warning("unknown attribute `%s' for <glade-interface>",
- attrs[i]);
+ names[i]);
}
#endif
} else {
@@ -528,8 +544,8 @@
break;
case PARSER_GLADE_INTERFACE:
if (!strcmp(name, "requires")) {
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "lib")) {
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "lib")) {
GladeInterface *iface = state->interface;
/* add to the list of requirements for this module */
@@ -537,10 +553,10 @@
iface->requires = g_renew(gchar *, iface->requires,
iface->n_requires);
iface->requires[iface->n_requires-1] =
- alloc_string(iface, attrs[i+1]);
+ alloc_string(iface, values[i]);
} else
g_warning("unknown attribute `%s' for <requires>.",
- attrs[i]);
+ names[i]);
}
state->state = PARSER_REQUIRES;
} else if (!strcmp(name, "widget")) {
@@ -549,7 +565,7 @@
iface->n_toplevels++;
iface->toplevels = g_renew(GladeWidgetInfo *, iface->toplevels,
iface->n_toplevels);
- state->widget = create_widget_info(iface, attrs);
+ state->widget = create_widget_info(iface, names, values);
iface->toplevels[iface->n_toplevels-1] = state->widget;
state->widget_depth++;
@@ -582,22 +598,20 @@
state->prop_type != PROP_WIDGET)
g_warning("non widget properties defined here (oh no!)");
state->translate_prop = FALSE;
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "name"))
- state->prop_name = alloc_propname(state->interface,
- attrs[i+1]);
- else if (!strcmp(attrs[i], "translatable"))
- state->translate_prop = !strcmp(attrs[i+1], "yes");
- else if (!strcmp(attrs[i], "context"))
- state->context_prop = !strcmp(attrs[i+1], "yes");
- else if (!strcmp(attrs[i], "agent"))
- bad_agent = strcmp(attrs[i], "libglade") != 0;
- else if (!strcmp(attrs[i], "comments"))
- /* Do nothing. */;
- else
- g_warning("unknown attribute `%s' for <property>.",
- attrs[i]);
- }
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "name"))
+ state->prop_name = alloc_propname(state->interface, values[i]);
+ else if (!strcmp(names[i], "translatable"))
+ state->translate_prop = !strcmp(values[i], "yes");
+ else if (!strcmp(names[i], "context"))
+ state->context_prop = !strcmp(values[i], "yes");
+ else if (!strcmp(names[i], "agent"))
+ bad_agent = strcmp(names[i], "libglade") != 0;
+ else if (!strcmp(names[i], "comments"))
+ /* Do nothing. */;
+ else
+ g_warning("unknown attribute `%s' for <property>.", names[i]);
+ }
if (bad_agent) {
/* ignore the property ... */
state->prev_state = state->state;
@@ -610,17 +624,17 @@
} else if (!strcmp(name, "accessibility")) {
flush_properties(state);
- if (attrs != NULL && attrs[0] != NULL)
+ if (names != NULL && names[0] != NULL)
g_warning("<accessibility> element should have no attributes");
state->state = PARSER_WIDGET_ATK;
} else if (!strcmp(name, "signal")) {
- handle_signal(state, attrs);
+ handle_signal(state, names, values);
state->state = PARSER_WIDGET_SIGNAL;
} else if (!strcmp(name, "accelerator")) {
- handle_accel(state, attrs);
+ handle_accel(state, names, values);
state->state = PARSER_WIDGET_ACCEL;
} else if (!strcmp(name, "child")) {
- handle_child(state, attrs);
+ handle_child(state, names, values);
state->state = PARSER_WIDGET_CHILD;
} else {
g_warning("Unexpected element <%s> inside <widget>.", name);
@@ -642,26 +656,26 @@
g_warning("non atk properties defined here (oh no!)");
state->prop_type = PROP_ATK;
state->translate_prop = FALSE;
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "name"))
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "name"))
state->prop_name = alloc_propname(state->interface,
- attrs[i+1]);
- else if (!strcmp(attrs[i], "translatable"))
- state->translate_prop = !strcmp(attrs[i+1], "yes");
- else if (!strcmp(attrs[i], "context"))
- state->context_prop = !strcmp(attrs[i+1], "yes");
- else if (!strcmp(attrs[i], "comments"))
+ values[i]);
+ else if (!strcmp(names[i], "translatable"))
+ state->translate_prop = !strcmp(values[i], "yes");
+ else if (!strcmp(names[i], "context"))
+ state->context_prop = !strcmp(values[i], "yes");
+ else if (!strcmp(names[i], "comments"))
/* Do nothing. */;
else
g_warning("unknown attribute `%s' for <atkproperty>.",
- attrs[i]);
+ names[i]);
}
state->state = PARSER_WIDGET_ATK_PROPERTY;
} else if (!strcmp(name, "atkaction")) {
- handle_atk_action(state, attrs);
+ handle_atk_action(state, names, values);
state->state = PARSER_WIDGET_ATK_ACTION;
} else if (!strcmp(name, "atkrelation")) {
- handle_atk_relation(state, attrs);
+ handle_atk_relation(state, names, values);
state->state = PARSER_WIDGET_ATK_RELATION;
} else {
g_warning("Unexpected element <%s> inside <accessibility>.", name);
@@ -694,13 +708,13 @@
break;
case PARSER_WIDGET_AFTER_ATK:
if (!strcmp(name, "signal")) {
- handle_signal(state, attrs);
+ handle_signal(state, names, values);
state->state = PARSER_WIDGET_SIGNAL;
} else if (!strcmp(name, "accelerator")) {
- handle_accel(state, attrs);
+ handle_accel(state, names, values);
state->state = PARSER_WIDGET_ACCEL;
} else if (!strcmp(name, "child")) {
- handle_child(state, attrs);
+ handle_child(state, names, values);
state->state = PARSER_WIDGET_CHILD;
} else {
g_warning("Unexpected element <%s> inside <widget>.", name);
@@ -717,10 +731,10 @@
break;
case PARSER_WIDGET_AFTER_SIGNAL:
if (!strcmp(name, "accelerator")) {
- handle_accel(state, attrs);
+ handle_accel(state, names, values);
state->state = PARSER_WIDGET_ACCEL;
} else if (!strcmp(name, "child")) {
- handle_child(state, attrs);
+ handle_child(state, names, values);
state->state = PARSER_WIDGET_CHILD;
} else {
g_warning("Unexpected element <%s> inside <widget>.", name);
@@ -737,7 +751,7 @@
break;
case PARSER_WIDGET_AFTER_ACCEL:
if (!strcmp(name, "child")) {
- handle_child(state, attrs);
+ handle_child(state, names, values);
state->state = PARSER_WIDGET_CHILD;
} else {
g_warning("Unexpected element <%s> inside <widget>.", name);
@@ -754,7 +768,7 @@
if (info->child)
g_warning("widget pointer already set!! not good");
- state->widget = create_widget_info(state->interface, attrs);
+ state->widget = create_widget_info(state->interface, names, values);
info->child = state->widget;
info->child->parent = parent;
@@ -795,21 +809,21 @@
state->prop_type != PROP_CHILD)
g_warning("non child properties defined here (oh no!)");
state->translate_prop = FALSE;
- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
- if (!strcmp(attrs[i], "name"))
+ for (i = 0; names && names[i] != NULL; i++) {
+ if (!strcmp(names[i], "name"))
state->prop_name = alloc_propname(state->interface,
- attrs[i+1]);
- else if (!strcmp(attrs[i], "translatable"))
- state->translate_prop = !strcmp(attrs[i+1], "yes");
- else if (!strcmp(attrs[i], "context"))
- state->context_prop = !strcmp(attrs[i+1], "yes");
- else if (!strcmp(attrs[i], "agent"))
- bad_agent = strcmp(attrs[i], "libglade") != 0;
- else if (!strcmp(attrs[i], "comments"))
+ values[i]);
+ else if (!strcmp(names[i], "translatable"))
+ state->translate_prop = !strcmp(values[i], "yes");
+ else if (!strcmp(names[i], "context"))
+ state->context_prop = !strcmp(values[i], "yes");
+ else if (!strcmp(names[i], "agent"))
+ bad_agent = strcmp(values[i], "libglade") != 0;
+ else if (!strcmp(names[i], "comments"))
/* Do nothing. */;
else
g_warning("unknown attribute `%s' for <property>.",
- attrs[i]);
+ names[i]);
}
if (bad_agent) {
/* ignore the property ... */
@@ -866,7 +880,10 @@
}
static void
-glade_parser_end_element(GladeParseState *state, const xmlChar *name)
+glade_parser_end_element(GMarkupParseContext *context,
+ const gchar *name,
+ GladeParseState *state,
+ GError **error)
{
GladeProperty prop;
@@ -1049,7 +1066,11 @@
}
static void
-glade_parser_characters(GladeParseState *state, const xmlChar *chars, int len)
+glade_parser_text(GMarkupParseContext *context,
+ const gchar *chars,
+ gsize len,
+ GladeParseState *state,
+ GError **error)
{
switch (state->state) {
case PARSER_WIDGET_PROPERTY:
@@ -1063,67 +1084,20 @@
}
}
-static xmlEntityPtr
-glade_parser_get_entity(GladeParseState *state, const xmlChar *name)
-{
- return xmlGetPredefinedEntity(name);
-}
-
static void
-glade_parser_warning(GladeParseState *state, const char *msg, ...)
+glade_parser_error(GMarkupParseContext *context,
+ GError *error,
+ GladeParseState *state)
{
- va_list args;
-
- va_start(args, msg);
- g_logv("XML", G_LOG_LEVEL_WARNING, msg, args);
- va_end(args);
+ g_log("GMarkup", G_LOG_LEVEL_CRITICAL, error->message);
}
-
-static void
-glade_parser_error(GladeParseState *state, const char *msg, ...)
-{
- va_list args;
-
- va_start(args, msg);
- g_logv("XML", G_LOG_LEVEL_CRITICAL, msg, args);
- va_end(args);
-}
-
-static void
-glade_parser_fatal_error(GladeParseState *state, const char *msg, ...)
-{
- va_list args;
-
- va_start(args, msg);
- g_logv("XML", G_LOG_LEVEL_ERROR, msg, args);
- va_end(args);
-}
-
-static xmlSAXHandler glade_parser = {
- (internalSubsetSAXFunc)NULL, /* internalSubset */
- (isStandaloneSAXFunc)NULL, /* isStandalone */
- (hasInternalSubsetSAXFunc)NULL, /* hasInternalSubset */
- (hasExternalSubsetSAXFunc)NULL, /* hasExternalSubset */
- (resolveEntitySAXFunc)NULL, /* resolveEntity */
- (getEntitySAXFunc)glade_parser_get_entity, /* getEntity */
- (entityDeclSAXFunc)NULL, /* entityDecl */
- (notationDeclSAXFunc)NULL, /* notationDecl */
- (attributeDeclSAXFunc)NULL, /* attributeDecl */
- (elementDeclSAXFunc)NULL, /* elementDecl */
- (unparsedEntityDeclSAXFunc)NULL, /* unparsedEntityDecl */
- (setDocumentLocatorSAXFunc)NULL, /* setDocumentLocator */
- (startDocumentSAXFunc)glade_parser_start_document, /* startDocument */
- (endDocumentSAXFunc)glade_parser_end_document, /* endDocument */
- (startElementSAXFunc)glade_parser_start_element, /* startElement */
- (endElementSAXFunc)glade_parser_end_element, /* endElement */
- (referenceSAXFunc)NULL, /* reference */
- (charactersSAXFunc)glade_parser_characters, /* characters */
- (ignorableWhitespaceSAXFunc)NULL, /* ignorableWhitespace */
- (processingInstructionSAXFunc)NULL, /* processingInstruction */
- (commentSAXFunc)NULL, /* comment */
- (warningSAXFunc)glade_parser_warning, /* warning */
- (errorSAXFunc)glade_parser_error, /* error */
- (fatalErrorSAXFunc)glade_parser_fatal_error, /* fatalError */
+
+static GMarkupParser glade_parser = {
+ (void*)glade_parser_start_element, /* startElement */
+ (void*)glade_parser_end_element, /* endElement */
+ (void*)glade_parser_text, /* characters */
+ 0, /* get_entity?? */
+ (void*)glade_parser_error, /* error */
};
static void
@@ -1195,7 +1169,10 @@
glade_parser_parse_file(const gchar *file, const gchar *domain)
{
GladeParseState state = { 0 };
-
+ GMarkupParseContext *context;
+ gchar *buffer;
+ gsize len;
+
if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) {
g_warning("could not find glade file '%s'", file);
return NULL;
@@ -1207,12 +1184,17 @@
else
state.domain = textdomain(NULL);
- if (xmlSAXUserParseFile(&glade_parser, &state, file) < 0) {
- g_warning("document not well formed");
- if (state.interface)
- glade_interface_destroy (state.interface);
- return NULL;
+
+ context = g_markup_parse_context_new(&glade_parser, 0, &state, NULL);
+
+ if (g_file_get_contents(file, &buffer, &len, NULL)) {
+ glade_parser_start_document(&state);
+ g_markup_parse_context_parse(context, buffer, len, NULL);
+ glade_parser_end_document(&state);
}
+
+ g_markup_parse_context_free (context);
+
if (state.state != PARSER_FINISH) {
g_warning("did not finish in PARSER_FINISH state");
if (state.interface)
@@ -1241,6 +1223,7 @@
glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
{
GladeParseState state = { 0 };
+ GMarkupParseContext *context;
state.interface = NULL;
if (domain)
@@ -1248,12 +1231,14 @@
else
state.domain = textdomain(NULL);
- if (xmlSAXUserParseMemory(&glade_parser, &state, buffer, len) < 0) {
- g_warning("document not well formed!");
- if (state.interface)
- glade_interface_destroy (state.interface);
- return NULL;
- }
+ context = g_markup_parse_context_new(&glade_parser, 0, &state, NULL);
+
+ glade_parser_start_document(&state);
+ g_markup_parse_context_parse(context, buffer, len, NULL);
+ glade_parser_end_document(&state);
+
+ g_markup_parse_context_free(context);
+
if (state.state != PARSER_FINISH) {
g_warning("did not finish in PARSER_FINISH state!");
if (state.interface)
@@ -1263,6 +1248,7 @@
return state.interface;
}
+#if 0
static void
dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent)
{
@@ -1381,6 +1367,7 @@
for (j = 0; j < indent; j++)
xmlNodeAddContent(widget, " ");
}
+#endif
/**
* glade_interface_dump
@@ -1393,6 +1380,7 @@
void
glade_interface_dump(GladeInterface *interface, const gchar *filename)
{
+#if 0
xmlDoc *doc;
xmlNode *root;
gint i;
@@ -1426,6 +1414,7 @@
xmlSaveFileEnc(filename, doc, "UTF-8");
xmlFreeDoc(doc);
+#endif
}
#if 0
@@ -1433,7 +1422,7 @@
main(int argc, char **argv) {
gtk_init(&argc, &argv);
if (argc > 1) {
- GladeInterface *interface = glade_parser_parse_file(argv[1]);
+ GladeInterface *interface = glade_parser_parse_file(argv[1], NULL);
g_message("output: %p", interface);
if (interface) {
glade_interface_dump(interface, "/dev/stdout");
Added: libglade/patches/GMarkup.patch
===================================================================
--- libglade/patches/GMarkup.patch 2005-03-22 14:00:25 UTC (rev 158)
+++ libglade/patches/GMarkup.patch 2005-03-22 14:00:47 UTC (rev 159)
@@ -0,0 +1,679 @@
+Index: glade/glade-parser.c
+===================================================================
+RCS file: /cvs/gnome/libglade/glade/glade-parser.c,v
+retrieving revision 1.32
+diff -u -r1.32 glade-parser.c
+--- glade/glade-parser.c 11 Nov 2004 08:46:29 -0000 1.32
++++ glade/glade-parser.c 28 Feb 2005 19:46:25 -0000
+@@ -34,7 +34,7 @@
+ # define dgettext(Domain, String) (String)
+ #endif
+
+-#include <libxml/parser.h>
++#include <glib/gmarkup.h>
+
+ #include "glade-parser.h"
+ #include "glade-private.h"
+@@ -153,18 +153,20 @@
+ }
+
+ static GladeWidgetInfo *
+-create_widget_info(GladeInterface *interface, const xmlChar **attrs)
++create_widget_info(GladeInterface *interface,
++ const gchar **names,
++ const gchar **values)
+ {
+ GladeWidgetInfo *info = g_new0(GladeWidgetInfo, 1);
+ int i;
+
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "class"))
+- info->classname = alloc_string(interface, attrs[i+1]);
+- else if (!strcmp(attrs[i], "id"))
+- info->name = alloc_string(interface, attrs[i+1]);
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "class"))
++ info->classname = alloc_string(interface, values[i]);
++ else if (!strcmp(names[i], "id"))
++ info->name = alloc_string(interface, values[i]);
+ else
+- g_warning("unknown attribute `%s' for <widget>.", attrs[i]);
++ g_warning("unknown attribute `%s' for <widget>.", names[i]);
+ }
+ if (info->classname == NULL || info->name == NULL)
+ g_warning("<widget> element missing required attributes!");
+@@ -259,22 +261,24 @@
+ }
+
+ static inline void
+-handle_atk_action(GladeParseState *state, const xmlChar **attrs)
++handle_atk_action(GladeParseState *state,
++ const gchar **names,
++ const gchar **values)
+ {
+ gint i;
+ GladeAtkActionInfo info = { NULL };
+
+ flush_properties(state);
+
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "action_name"))
+- info.action_name = alloc_string(state->interface, attrs[i+1]);
+- else if (!strcmp(attrs[i], "description"))
+- info.description = alloc_string(state->interface,
+- dgettext(state->domain, attrs[i+1]));
+- else
+- g_warning("unknown attribute `%s' for <action>.", attrs[i]);
+- }
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "action_name"))
++ info.action_name = alloc_string(state->interface, values[i]);
++ else if (!strcmp(names[i], "description"))
++ info.description = alloc_string(state->interface,
++ dgettext(state->domain, values[i]));
++ else
++ g_warning("unknown attribute `%s' for <action>.", names[i]);
++ }
+ if (info.action_name == NULL) {
+ g_warning("required <atkaction> attribute 'action_name' missing!!!");
+ return;
+@@ -286,20 +290,22 @@
+ }
+
+ static inline void
+-handle_atk_relation(GladeParseState *state, const xmlChar **attrs)
++handle_atk_relation(GladeParseState *state,
++ const gchar **names,
++ const gchar **values)
+ {
+ gint i;
+ GladeAtkRelationInfo info = { NULL };
+
+ flush_properties(state);
+
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "target"))
+- info.target = alloc_string(state->interface, attrs[i+1]);
+- else if (!strcmp(attrs[i], "type"))
+- info.type = alloc_string(state->interface, attrs[i+1]);
+- else
+- g_warning("unknown attribute `%s' for <signal>.", attrs[i]);
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "target"))
++ info.target = alloc_string(state->interface, values[i]);
++ else if (!strcmp(names[i], "type"))
++ info.type = alloc_string(state->interface, values[i]);
++ else
++ g_warning("unknown attribute `%s' for <signal>.", names[i]);
+ }
+ if (info.target == NULL || info.type == NULL) {
+ g_warning("required <atkrelation> attributes ('target' and/or 'type') missing!!!");
+@@ -312,7 +318,9 @@
+ }
+
+ static inline void
+-handle_signal(GladeParseState *state, const xmlChar **attrs)
++handle_signal(GladeParseState *state,
++ const gchar **names,
++ const gchar **values)
+ {
+ GladeSignalInfo info = { NULL };
+ gint i;
+@@ -320,19 +328,19 @@
+ flush_properties(state);
+
+ info.after = FALSE;
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "name"))
+- info.name = alloc_string(state->interface, attrs[i+1]);
+- else if (!strcmp(attrs[i], "handler"))
+- info.handler = alloc_string(state->interface, attrs[i+1]);
+- else if (!strcmp(attrs[i], "after"))
+- info.after = attrs[i+1][0] == 'y';
+- else if (!strcmp(attrs[i], "object"))
+- info.object = alloc_string(state->interface, attrs[i+1]);
+- else if (!strcmp(attrs[i], "last_modification_time"))
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "name"))
++ info.name = alloc_string(state->interface, values[i]);
++ else if (!strcmp(names[i], "handler"))
++ info.handler = alloc_string(state->interface, values[i]);
++ else if (!strcmp(names[i], "after"))
++ info.after = values[i][0] == 'y';
++ else if (!strcmp(names[i], "object"))
++ info.object = alloc_string(state->interface, values[i]);
++ else if (!strcmp(names[i], "last_modification_time"))
+ /* Do nothing. */;
+ else
+- g_warning("unknown attribute `%s' for <signal>.", attrs[i]);
++ g_warning("unknown attribute `%s' for <signal>.", names[i]);
+ }
+ if (info.name == NULL || info.handler == NULL) {
+ g_warning("required <signal> attributes missing!!!");
+@@ -345,7 +353,9 @@
+ }
+
+ static inline void
+-handle_accel(GladeParseState *state, const xmlChar **attrs)
++handle_accel(GladeParseState *state,
++ const gchar **names,
++ const gchar **values)
+ {
+ GladeAccelInfo info = { 0 };
+ gint i;
+@@ -355,11 +365,11 @@
+ flush_actions(state);
+ flush_relations(state);
+
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "key"))
+- info.key = gdk_keyval_from_name(attrs[i+1]);
+- else if (!strcmp(attrs[i], "modifiers")) {
+- const xmlChar *pos = attrs[i+1];
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "key"))
++ info.key = gdk_keyval_from_name(values[i]);
++ else if (!strcmp(names[i], "modifiers")) {
++ const gchar *pos = values[i];
+
+ info.modifiers = 0;
+ while (pos[0])
+@@ -411,10 +421,10 @@
+ pos++;
+ } else
+ pos++;
+- } else if (!strcmp(attrs[i], "signal"))
+- info.signal = alloc_string(state->interface, attrs[i+1]);
++ } else if (!strcmp(names[i], "signal"))
++ info.signal = alloc_string(state->interface, values[i]);
+ else
+- g_warning("unknown attribute `%s' for <accelerator>.", attrs[i]);
++ g_warning("unknown attribute `%s' for <accelerator>.", names[i]);
+ }
+ if (info.key == 0 || info.signal == NULL) {
+ g_warning("required <accelerator> attributes missing!!!");
+@@ -427,7 +437,9 @@
+ }
+
+ static inline void
+-handle_child(GladeParseState *state, const xmlChar **attrs)
++handle_child(GladeParseState *state,
++ const gchar **names,
++ const gchar **values)
+ {
+ GladeChildInfo *info;
+ gint i;
+@@ -448,11 +460,11 @@
+ info->n_properties = 0;
+ info->child = NULL;
+
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "internal-child"))
+- info->internal_child = alloc_string(state->interface, attrs[i+1]);
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "internal-child"))
++ info->internal_child = alloc_string(state->interface, values[i]);
+ else
+- g_warning("unknown attribute `%s' for <child>.", attrs[i]);
++ g_warning("unknown attribute `%s' for <child>.", names[i]);
+ }
+ }
+
+@@ -496,9 +508,13 @@
+ }
+
+ static void
+-glade_parser_start_element(GladeParseState *state,
+- const xmlChar *name, const xmlChar **attrs)
+-{
++glade_parser_start_element (GMarkupParseContext *context,
++ const gchar *name,
++ const gchar **names,
++ const gchar **values,
++ GladeParseState *state,
++ GError **error)
++{
+ int i;
+
+ GLADE_NOTE(PARSER, g_message("<%s> in state %s",
+@@ -510,13 +526,13 @@
+ state->state = PARSER_GLADE_INTERFACE;
+ #if 0
+ /* check for correct XML namespace */
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "xmlns") &&
+- !strcmp(attrs[i+1], "...")) {
+- g_warning("bad XML namespace `%s'.", attrs[i+1]);
++ for (i = 0; names && names[i] != NULL; i ++) {
++ if (!strcmp(names[i], "xmlns") &&
++ !strcmp(values[i], "...")) {
++ g_warning("bad XML namespace `%s'.", values[i]);
+ } else
+ g_warning("unknown attribute `%s' for <glade-interface>",
+- attrs[i]);
++ names[i]);
+ }
+ #endif
+ } else {
+@@ -528,8 +544,8 @@
+ break;
+ case PARSER_GLADE_INTERFACE:
+ if (!strcmp(name, "requires")) {
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "lib")) {
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "lib")) {
+ GladeInterface *iface = state->interface;
+
+ /* add to the list of requirements for this module */
+@@ -537,10 +553,10 @@
+ iface->requires = g_renew(gchar *, iface->requires,
+ iface->n_requires);
+ iface->requires[iface->n_requires-1] =
+- alloc_string(iface, attrs[i+1]);
++ alloc_string(iface, values[i]);
+ } else
+ g_warning("unknown attribute `%s' for <requires>.",
+- attrs[i]);
++ names[i]);
+ }
+ state->state = PARSER_REQUIRES;
+ } else if (!strcmp(name, "widget")) {
+@@ -549,7 +565,7 @@
+ iface->n_toplevels++;
+ iface->toplevels = g_renew(GladeWidgetInfo *, iface->toplevels,
+ iface->n_toplevels);
+- state->widget = create_widget_info(iface, attrs);
++ state->widget = create_widget_info(iface, names, values);
+ iface->toplevels[iface->n_toplevels-1] = state->widget;
+
+ state->widget_depth++;
+@@ -582,22 +598,20 @@
+ state->prop_type != PROP_WIDGET)
+ g_warning("non widget properties defined here (oh no!)");
+ state->translate_prop = FALSE;
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "name"))
+- state->prop_name = alloc_propname(state->interface,
+- attrs[i+1]);
+- else if (!strcmp(attrs[i], "translatable"))
+- state->translate_prop = !strcmp(attrs[i+1], "yes");
+- else if (!strcmp(attrs[i], "context"))
+- state->context_prop = !strcmp(attrs[i+1], "yes");
+- else if (!strcmp(attrs[i], "agent"))
+- bad_agent = strcmp(attrs[i], "libglade") != 0;
+- else if (!strcmp(attrs[i], "comments"))
+- /* Do nothing. */;
+- else
+- g_warning("unknown attribute `%s' for <property>.",
+- attrs[i]);
+- }
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "name"))
++ state->prop_name = alloc_propname(state->interface, values[i]);
++ else if (!strcmp(names[i], "translatable"))
++ state->translate_prop = !strcmp(values[i], "yes");
++ else if (!strcmp(names[i], "context"))
++ state->context_prop = !strcmp(values[i], "yes");
++ else if (!strcmp(names[i], "agent"))
++ bad_agent = strcmp(names[i], "libglade") != 0;
++ else if (!strcmp(names[i], "comments"))
++ /* Do nothing. */;
++ else
++ g_warning("unknown attribute `%s' for <property>.", names[i]);
++ }
+ if (bad_agent) {
+ /* ignore the property ... */
+ state->prev_state = state->state;
+@@ -610,17 +624,17 @@
+ } else if (!strcmp(name, "accessibility")) {
+ flush_properties(state);
+
+- if (attrs != NULL && attrs[0] != NULL)
++ if (names != NULL && names[0] != NULL)
+ g_warning("<accessibility> element should have no attributes");
+ state->state = PARSER_WIDGET_ATK;
+ } else if (!strcmp(name, "signal")) {
+- handle_signal(state, attrs);
++ handle_signal(state, names, values);
+ state->state = PARSER_WIDGET_SIGNAL;
+ } else if (!strcmp(name, "accelerator")) {
+- handle_accel(state, attrs);
++ handle_accel(state, names, values);
+ state->state = PARSER_WIDGET_ACCEL;
+ } else if (!strcmp(name, "child")) {
+- handle_child(state, attrs);
++ handle_child(state, names, values);
+ state->state = PARSER_WIDGET_CHILD;
+ } else {
+ g_warning("Unexpected element <%s> inside <widget>.", name);
+@@ -642,26 +656,26 @@
+ g_warning("non atk properties defined here (oh no!)");
+ state->prop_type = PROP_ATK;
+ state->translate_prop = FALSE;
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "name"))
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "name"))
+ state->prop_name = alloc_propname(state->interface,
+- attrs[i+1]);
+- else if (!strcmp(attrs[i], "translatable"))
+- state->translate_prop = !strcmp(attrs[i+1], "yes");
+- else if (!strcmp(attrs[i], "context"))
+- state->context_prop = !strcmp(attrs[i+1], "yes");
+- else if (!strcmp(attrs[i], "comments"))
++ values[i]);
++ else if (!strcmp(names[i], "translatable"))
++ state->translate_prop = !strcmp(values[i], "yes");
++ else if (!strcmp(names[i], "context"))
++ state->context_prop = !strcmp(values[i], "yes");
++ else if (!strcmp(names[i], "comments"))
+ /* Do nothing. */;
+ else
+ g_warning("unknown attribute `%s' for <atkproperty>.",
+- attrs[i]);
++ names[i]);
+ }
+ state->state = PARSER_WIDGET_ATK_PROPERTY;
+ } else if (!strcmp(name, "atkaction")) {
+- handle_atk_action(state, attrs);
++ handle_atk_action(state, names, values);
+ state->state = PARSER_WIDGET_ATK_ACTION;
+ } else if (!strcmp(name, "atkrelation")) {
+- handle_atk_relation(state, attrs);
++ handle_atk_relation(state, names, values);
+ state->state = PARSER_WIDGET_ATK_RELATION;
+ } else {
+ g_warning("Unexpected element <%s> inside <accessibility>.", name);
+@@ -694,13 +708,13 @@
+ break;
+ case PARSER_WIDGET_AFTER_ATK:
+ if (!strcmp(name, "signal")) {
+- handle_signal(state, attrs);
++ handle_signal(state, names, values);
+ state->state = PARSER_WIDGET_SIGNAL;
+ } else if (!strcmp(name, "accelerator")) {
+- handle_accel(state, attrs);
++ handle_accel(state, names, values);
+ state->state = PARSER_WIDGET_ACCEL;
+ } else if (!strcmp(name, "child")) {
+- handle_child(state, attrs);
++ handle_child(state, names, values);
+ state->state = PARSER_WIDGET_CHILD;
+ } else {
+ g_warning("Unexpected element <%s> inside <widget>.", name);
+@@ -717,10 +731,10 @@
+ break;
+ case PARSER_WIDGET_AFTER_SIGNAL:
+ if (!strcmp(name, "accelerator")) {
+- handle_accel(state, attrs);
++ handle_accel(state, names, values);
+ state->state = PARSER_WIDGET_ACCEL;
+ } else if (!strcmp(name, "child")) {
+- handle_child(state, attrs);
++ handle_child(state, names, values);
+ state->state = PARSER_WIDGET_CHILD;
+ } else {
+ g_warning("Unexpected element <%s> inside <widget>.", name);
+@@ -737,7 +751,7 @@
+ break;
+ case PARSER_WIDGET_AFTER_ACCEL:
+ if (!strcmp(name, "child")) {
+- handle_child(state, attrs);
++ handle_child(state, names, values);
+ state->state = PARSER_WIDGET_CHILD;
+ } else {
+ g_warning("Unexpected element <%s> inside <widget>.", name);
+@@ -754,7 +768,7 @@
+ if (info->child)
+ g_warning("widget pointer already set!! not good");
+
+- state->widget = create_widget_info(state->interface, attrs);
++ state->widget = create_widget_info(state->interface, names, values);
+ info->child = state->widget;
+ info->child->parent = parent;
+
+@@ -795,21 +809,21 @@
+ state->prop_type != PROP_CHILD)
+ g_warning("non child properties defined here (oh no!)");
+ state->translate_prop = FALSE;
+- for (i = 0; attrs && attrs[i] != NULL; i += 2) {
+- if (!strcmp(attrs[i], "name"))
++ for (i = 0; names && names[i] != NULL; i++) {
++ if (!strcmp(names[i], "name"))
+ state->prop_name = alloc_propname(state->interface,
+- attrs[i+1]);
+- else if (!strcmp(attrs[i], "translatable"))
+- state->translate_prop = !strcmp(attrs[i+1], "yes");
+- else if (!strcmp(attrs[i], "context"))
+- state->context_prop = !strcmp(attrs[i+1], "yes");
+- else if (!strcmp(attrs[i], "agent"))
+- bad_agent = strcmp(attrs[i], "libglade") != 0;
+- else if (!strcmp(attrs[i], "comments"))
++ values[i]);
++ else if (!strcmp(names[i], "translatable"))
++ state->translate_prop = !strcmp(values[i], "yes");
++ else if (!strcmp(names[i], "context"))
++ state->context_prop = !strcmp(values[i], "yes");
++ else if (!strcmp(names[i], "agent"))
++ bad_agent = strcmp(values[i], "libglade") != 0;
++ else if (!strcmp(names[i], "comments"))
+ /* Do nothing. */;
+ else
+ g_warning("unknown attribute `%s' for <property>.",
+- attrs[i]);
++ names[i]);
+ }
+ if (bad_agent) {
+ /* ignore the property ... */
+@@ -866,7 +880,10 @@
+ }
+
+ static void
+-glade_parser_end_element(GladeParseState *state, const xmlChar *name)
++glade_parser_end_element(GMarkupParseContext *context,
++ const gchar *name,
++ GladeParseState *state,
++ GError **error)
+ {
+ GladeProperty prop;
+
+@@ -1049,7 +1066,11 @@
+ }
+
+ static void
+-glade_parser_characters(GladeParseState *state, const xmlChar *chars, int len)
++glade_parser_text(GMarkupParseContext *context,
++ const gchar *chars,
++ gsize len,
++ GladeParseState *state,
++ GError **error)
+ {
+ switch (state->state) {
+ case PARSER_WIDGET_PROPERTY:
+@@ -1063,67 +1084,20 @@
+ }
+ }
+
+-static xmlEntityPtr
+-glade_parser_get_entity(GladeParseState *state, const xmlChar *name)
+-{
+- return xmlGetPredefinedEntity(name);
+-}
+-
+ static void
+-glade_parser_warning(GladeParseState *state, const char *msg, ...)
+-{
+- va_list args;
+-
+- va_start(args, msg);
+- g_logv("XML", G_LOG_LEVEL_WARNING, msg, args);
+- va_end(args);
+-}
+-
+-static void
+-glade_parser_error(GladeParseState *state, const char *msg, ...)
+-{
+- va_list args;
+-
+- va_start(args, msg);
+- g_logv("XML", G_LOG_LEVEL_CRITICAL, msg, args);
+- va_end(args);
+-}
+-
+-static void
+-glade_parser_fatal_error(GladeParseState *state, const char *msg, ...)
+-{
+- va_list args;
+-
+- va_start(args, msg);
+- g_logv("XML", G_LOG_LEVEL_ERROR, msg, args);
+- va_end(args);
+-}
+-
+-static xmlSAXHandler glade_parser = {
+- (internalSubsetSAXFunc)NULL, /* internalSubset */
+- (isStandaloneSAXFunc)NULL, /* isStandalone */
+- (hasInternalSubsetSAXFunc)NULL, /* hasInternalSubset */
+- (hasExternalSubsetSAXFunc)NULL, /* hasExternalSubset */
+- (resolveEntitySAXFunc)NULL, /* resolveEntity */
+- (getEntitySAXFunc)glade_parser_get_entity, /* getEntity */
+- (entityDeclSAXFunc)NULL, /* entityDecl */
+- (notationDeclSAXFunc)NULL, /* notationDecl */
+- (attributeDeclSAXFunc)NULL, /* attributeDecl */
+- (elementDeclSAXFunc)NULL, /* elementDecl */
+- (unparsedEntityDeclSAXFunc)NULL, /* unparsedEntityDecl */
+- (setDocumentLocatorSAXFunc)NULL, /* setDocumentLocator */
+- (startDocumentSAXFunc)glade_parser_start_document, /* startDocument */
+- (endDocumentSAXFunc)glade_parser_end_document, /* endDocument */
+- (startElementSAXFunc)glade_parser_start_element, /* startElement */
+- (endElementSAXFunc)glade_parser_end_element, /* endElement */
+- (referenceSAXFunc)NULL, /* reference */
+- (charactersSAXFunc)glade_parser_characters, /* characters */
+- (ignorableWhitespaceSAXFunc)NULL, /* ignorableWhitespace */
+- (processingInstructionSAXFunc)NULL, /* processingInstruction */
+- (commentSAXFunc)NULL, /* comment */
+- (warningSAXFunc)glade_parser_warning, /* warning */
+- (errorSAXFunc)glade_parser_error, /* error */
+- (fatalErrorSAXFunc)glade_parser_fatal_error, /* fatalError */
++glade_parser_error(GMarkupParseContext *context,
++ GError *error,
++ GladeParseState *state)
++{
++ g_log("GMarkup", G_LOG_LEVEL_CRITICAL, error->message);
++}
++
++static GMarkupParser glade_parser = {
++ (void*)glade_parser_start_element, /* startElement */
++ (void*)glade_parser_end_element, /* endElement */
++ (void*)glade_parser_text, /* characters */
++ 0, /* get_entity?? */
++ (void*)glade_parser_error, /* error */
+ };
+
+ static void
+@@ -1195,7 +1169,10 @@
+ glade_parser_parse_file(const gchar *file, const gchar *domain)
+ {
+ GladeParseState state = { 0 };
+-
++ GMarkupParseContext *context;
++ gchar *buffer;
++ gsize len;
++
+ if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) {
+ g_warning("could not find glade file '%s'", file);
+ return NULL;
+@@ -1207,12 +1184,17 @@
+ else
+ state.domain = textdomain(NULL);
+
+- if (xmlSAXUserParseFile(&glade_parser, &state, file) < 0) {
+- g_warning("document not well formed");
+- if (state.interface)
+- glade_interface_destroy (state.interface);
+- return NULL;
++
++ context = g_markup_parse_context_new(&glade_parser, 0, &state, NULL);
++
++ if (g_file_get_contents(file, &buffer, &len, NULL)) {
++ glade_parser_start_document(&state);
++ g_markup_parse_context_parse(context, buffer, len, NULL);
++ glade_parser_end_document(&state);
+ }
++
++ g_markup_parse_context_free (context);
++
+ if (state.state != PARSER_FINISH) {
+ g_warning("did not finish in PARSER_FINISH state");
+ if (state.interface)
+@@ -1241,6 +1223,7 @@
+ glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
+ {
+ GladeParseState state = { 0 };
++ GMarkupParseContext *context;
+
+ state.interface = NULL;
+ if (domain)
+@@ -1248,12 +1231,14 @@
+ else
+ state.domain = textdomain(NULL);
+
+- if (xmlSAXUserParseMemory(&glade_parser, &state, buffer, len) < 0) {
+- g_warning("document not well formed!");
+- if (state.interface)
+- glade_interface_destroy (state.interface);
+- return NULL;
+- }
++ context = g_markup_parse_context_new(&glade_parser, 0, &state, NULL);
++
++ glade_parser_start_document(&state);
++ g_markup_parse_context_parse(context, buffer, len, NULL);
++ glade_parser_end_document(&state);
++
++ g_markup_parse_context_free(context);
++
+ if (state.state != PARSER_FINISH) {
+ g_warning("did not finish in PARSER_FINISH state!");
+ if (state.interface)
+@@ -1263,6 +1248,7 @@
+ return state.interface;
+ }
+
++#if 0
+ static void
+ dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent)
+ {
+@@ -1381,6 +1367,7 @@
+ for (j = 0; j < indent; j++)
+ xmlNodeAddContent(widget, " ");
+ }
++#endif
+
+ /**
+ * glade_interface_dump
+@@ -1393,6 +1380,7 @@
+ void
+ glade_interface_dump(GladeInterface *interface, const gchar *filename)
+ {
++#if 0
+ xmlDoc *doc;
+ xmlNode *root;
+ gint i;
+@@ -1426,6 +1414,7 @@
+
+ xmlSaveFileEnc(filename, doc, "UTF-8");
+ xmlFreeDoc(doc);
++#endif
+ }
+
+ #if 0
+@@ -1433,7 +1422,7 @@
+ main(int argc, char **argv) {
+ gtk_init(&argc, &argv);
+ if (argc > 1) {
+- GladeInterface *interface = glade_parser_parse_file(argv[1]);
++ GladeInterface *interface = glade_parser_parse_file(argv[1], NULL);
+ g_message("output: %p", interface);
+ if (interface) {
+ glade_interface_dump(interface, "/dev/stdout");
More information about the POS-commit
mailing list