Commit bbec1dc1 authored by Chema Celorio's avatar Chema Celorio Committed by Jose Maria Celorio

when saving a .xml file indent it as libxml did by calling SaveFormatFile

2001-07-23  Chema Celorio  <chema@celorio.com>

	* src/glade-xml-utils.c (glade_xml_doc_save): when saving a .xml file indent
	it as libxml did by calling SaveFormatFile and xmlKeepBlanksDefault.

	* src/glade-xml-utils.h: hide the libxml internals (remove headers from the
	.h file and into the .c file. Update all the code to not deal with libxml
	structs directly. Changed the while loops that generated libxml nodes to for
	loops. remove the skip_text macro and add glade_xml_node_is_comment so that
	we can test the node for a node we should ignore (in the for loops).
parent 550709b2
2001-07-23 Chema Celorio <chema@celorio.com>
* src/glade-xml-utils.c (glade_xml_doc_save): when saving a .xml file indent
it as libxml did by calling SaveFormatFile and xmlKeepBlanksDefault.
* src/glade-xml-utils.h: hide the libxml internals (remove headers from the
.h file and into the .c file. Update all the code to not deal with libxml
structs directly. Changed the while loops that generated libxml nodes to for
loops. remove the skip_text macro and add glade_xml_node_is_comment so that
we can test the node for a node we should ignore (in the for loops).
2001-07-22 Chema Celorio <chema@celorio.com>
* src/glade-utils.c (glade_util_path_is_writable): implement, new file.
......
......@@ -53,15 +53,13 @@ glade_catalog_load_names_from_node (GladeXmlContext *context, GladeXmlNode *node
list = NULL;
child = glade_xml_node_get_children (node);
while (child != NULL) {
skip_text (child);
for (; child != NULL; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify (child, GLADE_TAG_GLADE_WIDGET))
return NULL;
name = glade_xml_get_content (child);
if (name == NULL)
return NULL;
list = g_list_prepend (list, name);
child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
......@@ -74,11 +72,13 @@ glade_catalog_load_names_from_file (GladeCatalog *catalog, const gchar *file_nam
{
GladeXmlContext *context;
GladeXmlNode *root;
GladeXmlDoc *doc;
context = glade_xml_context_new_from_path (file_name, NULL, GLADE_TAG_CATALOG);
if (context == NULL)
return;
root = glade_xml_doc_get_root (context->doc);
doc = glade_xml_context_get_doc (context);
root = glade_xml_doc_get_root (doc);
catalog->names = glade_catalog_load_names_from_node (context, root);
glade_xml_context_free (context);
}
......
......@@ -154,15 +154,13 @@ glade_choice_list_new_from_node (GladeXmlNode *node)
list = NULL;
child = glade_xml_node_get_children (node);
while (child != NULL) {
skip_text (child);
for (; child != NULL; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify (child, GLADE_TAG_CHOICE))
return NULL;
choice = glade_choice_new_from_node (child);
if (choice == NULL)
return NULL;
list = g_list_prepend (list, choice);
child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
......
......@@ -172,10 +172,10 @@ glade_parameter_list_new_from_node (GList *list, GladeXmlNode *node)
child = glade_xml_node_get_children (node);
while (child != NULL) {
skip_text (child);
for (; child != NULL; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify (child, GLADE_TAG_PARAMETER))
return NULL;
parameter = glade_parameter_new_from_node (child);
if (parameter == NULL)
return NULL;
......@@ -187,11 +187,10 @@ glade_parameter_list_new_from_node (GList *list, GladeXmlNode *node)
if (findme) {
glade_parameter_free (findme->data);
findme->data = parameter;
child = glade_xml_node_next (child);
continue;
}
list = g_list_prepend (list, parameter);
child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
......
......@@ -500,14 +500,12 @@ glade_xml_read_list (GladeXmlNode *node, const gchar *list_tag, const gchar *ite
child = glade_xml_node_get_children (child);
while (child != NULL) {
skip_text (child);
for (; child != NULL; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify (child, item_tag))
return NULL;
item = glade_xml_get_content (child);
if (item != NULL)
list = g_list_prepend (list, item);
child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
......@@ -632,14 +630,12 @@ glade_property_class_list_new_from_node (GladeXmlNode *node, GladeWidgetClass *c
list = NULL;
child = glade_xml_node_get_children (node);
while (child != NULL) {
skip_text (child);
for (; child != NULL; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify (child, GLADE_TAG_PROPERTY))
return NULL;
property_class = glade_property_class_new_from_node (child, class);
if (property_class != NULL)
list = g_list_prepend (list, property_class);
child = glade_xml_node_next (child);
}
list = g_list_reverse (list);
......
......@@ -283,8 +283,9 @@ glade_widget_class_create_pixmap (GladeWidgetClass *class)
GladeWidgetClass *
glade_widget_class_new_from_name (const gchar *name)
{
GladeXmlContext *context;
GladeWidgetClass *class;
GladeXmlContext *context;
GladeXmlDoc *doc;
gchar *file_name;
file_name = g_strconcat (WIDGETS_DIR, "/", name, ".xml", NULL);
......@@ -292,7 +293,8 @@ glade_widget_class_new_from_name (const gchar *name)
context = glade_xml_context_new_from_path (file_name, NULL, GLADE_TAG_GLADE_WIDGET_CLASS);
if (context == NULL)
return NULL;
class = glade_widget_class_new_from_node (glade_xml_context_get_root (context));
doc = glade_xml_context_get_doc (context);
class = glade_widget_class_new_from_node (glade_xml_doc_get_root (doc));
glade_xml_context_free (context);
if (!glade_widget_class_create_pixmap (class))
......
......@@ -14,6 +14,37 @@
#include "glade-xml-utils.h"
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/xmlmemory.h>
struct _GladeXmlNode
{
xmlNodePtr node;
};
struct _GladeXmlDoc
{
xmlDoc doc;
};
struct _GladeXmlContext {
GladeXmlDoc *doc;
xmlNsPtr ns;
};
/* This is used inside for loops so that we skip xml comments <!-- i am a comment ->
* also to skip whitespace bettween nodes
*/
#define skip_text(node) if ((strcmp ( ((xmlNodePtr)node)->name, "text") == 0) ||\
(strcmp ( ((xmlNodePtr)node)->name, "comment") == 0)) { \
node = (GladeXmlNode *)((xmlNodePtr)node)->next; continue ; };
#define skip_text_libxml(node) if ((strcmp ( ((xmlNodePtr)node)->name, "text") == 0) ||\
(strcmp ( ((xmlNodePtr)node)->name, "comment") == 0)) { \
node = ((xmlNodePtr)node)->next; continue ; };
/*
* Set a string value for a node either carried as an attibute or as
* the content of a child.
......@@ -455,20 +486,25 @@ glade_xml_utils_hash_write (GladeXmlContext *context, GHashTable *hash, const gc
}
#endif
/* --------------------------- Parse Context ----------------------------*/
GladeXmlContext *
glade_xml_context_new (GladeXmlDoc *doc,
xmlNsPtr ns)
glade_xml_context_new_real (GladeXmlDoc *doc, xmlNsPtr ns)
{
GladeXmlContext *context = g_new0 (GladeXmlContext, 1);
context->doc = doc;
context->ns = ns;
return context;
}
GladeXmlContext *
glade_xml_context_new (GladeXmlDoc *doc, const gchar *name_space)
{
/* We are not using the namespace now */
return glade_xml_context_new_real (doc, NULL);
}
void
glade_xml_context_destroy (GladeXmlContext *context)
{
......@@ -518,7 +554,7 @@ glade_xml_context_new_from_path (const gchar *full_path,
return FALSE;
}
context = glade_xml_context_new ((GladeXmlDoc *)doc, name_space);
context = glade_xml_context_new_real ((GladeXmlDoc *)doc, name_space);
return context;
}
......@@ -562,31 +598,45 @@ glade_xml_node_new (GladeXmlContext *context, const gchar *name)
return (GladeXmlNode *) xmlNewDocNode ((xmlDocPtr) context->doc, context->ns, name, NULL);
}
GladeXmlNode *
glade_xml_context_get_root (GladeXmlContext *context)
GladeXmlDoc *
glade_xml_context_get_doc (GladeXmlContext *context)
{
xmlNodePtr node;
node = ((xmlDocPtr)(context->doc))->children;
return context->doc;
}
return (GladeXmlNode *)node;
static gboolean
glade_libxml_node_is_comment (xmlNodePtr node) {
if (node == NULL)
return FALSE;
if ((strcmp ( node->name, "text") == 0) ||
(strcmp ( node->name, "comment") == 0))
return TRUE;
return FALSE;
}
GladeXmlNode *
glade_xml_node_get_children (GladeXmlNode *node_in)
{
xmlNodePtr node = (xmlNodePtr) node_in;
xmlNodePtr children;
return (GladeXmlNode *)node->children;
children = node->children;
while (glade_libxml_node_is_comment (children))
children = children->next;
return (GladeXmlNode *)children;
}
GladeXmlNode *
glade_xml_node_next (GladeXmlNode *node_in)
{
xmlNodePtr node = (xmlNodePtr) node_in;
return (GladeXmlNode *)node->next;
node = node->next;
while (glade_libxml_node_is_comment (node))
node = node->next;
return (GladeXmlNode *)node;
}
const gchar *
......@@ -621,7 +671,8 @@ glade_xml_doc_save (GladeXmlDoc *doc_in, const gchar *full_path)
{
xmlDocPtr doc = (xmlDocPtr) doc_in;
return xmlSaveFile (full_path, doc);
xmlKeepBlanksDefault (0);
return xmlSaveFormatFile (full_path, doc, 1);
}
void
......
......@@ -4,13 +4,6 @@
#ifndef __GLADE_XML_UTILS_H__
#define __GLADE_XML_UTILS_H__
#include <libxml/tree.h>
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
#include <libxml/xmlmemory.h>
#include "glade-node.h"
G_BEGIN_DECLS
#define GLADE_XML_CONTEXT(c) ((GladeXmlContext *)c)
......@@ -20,31 +13,6 @@ typedef struct _GladeXmlContext GladeXmlContext;
typedef struct _GladeXmlNode GladeXmlNode;
typedef struct _GladeXmlDoc GladeXmlDoc;
struct _GladeXmlNode
{
xmlNode node;
};
struct _GladeXmlDoc
{
xmlDoc doc;
};
struct _GladeXmlContext {
GladeXmlDoc *doc;
xmlNsPtr ns;
};
/* This is used inside for loops so that we skip xml comments <!-- i am a comment ->
* also to skip whitespace bettween nodes
*/
#define skip_text(node) if ((strcmp ( ((xmlNodePtr)node)->name, "text") == 0) ||\
(strcmp ( ((xmlNodePtr)node)->name, "comment") == 0)) { \
node = (GladeXmlNode *)((xmlNodePtr)node)->next; continue ; };
#define skip_text_libxml(node) if ((strcmp ( ((xmlNodePtr)node)->name, "text") == 0) ||\
(strcmp ( ((xmlNodePtr)node)->name, "comment") == 0)) { \
node = ((xmlNodePtr)node)->next; continue ; };
gchar * glade_xml_get_content (GladeXmlNode * node); /* Get the content of the node */
void glade_xml_set_content (GladeXmlNode *node_in, const gchar *content);
......@@ -72,13 +40,14 @@ gboolean glade_xml_property_get_boolean (GladeXmlNode *node_in, const char *name
void glade_xml_node_set_property_string (GladeXmlNode *node_in, const gchar *name, const gchar *string);
/* Parse Context */
GladeXmlContext * glade_xml_context_new (GladeXmlDoc *doc, xmlNsPtr name_space);
GladeXmlContext * glade_xml_context_new (GladeXmlDoc *doc, const gchar *name_space);
void glade_xml_context_destroy (GladeXmlContext *context);
void glade_xml_context_free (GladeXmlContext *context);
GladeXmlContext * glade_xml_context_new_from_path (const gchar *full_path,
const gchar *nspace,
const gchar *root_name);
GladeXmlNode * glade_xml_context_get_root (GladeXmlContext *context);
GladeXmlDoc * glade_xml_context_get_doc (GladeXmlContext *context);
void glade_xml_append_child (GladeXmlNode * node, GladeXmlNode * child);
......@@ -97,6 +66,7 @@ GladeXmlNode * glade_xml_node_next (GladeXmlNode *node_in);
const gchar * glade_xml_node_get_name (GladeXmlNode *node_in);
/* Document Operatons */
GladeXmlNode * glade_xml_doc_get_root (GladeXmlDoc *doc);
GladeXmlDoc * glade_xml_doc_new (void);
......@@ -104,6 +74,10 @@ void glade_xml_doc_set_root (GladeXmlDoc *doc, GladeXmlNode *node);
gint glade_xml_doc_save (GladeXmlDoc *doc_in, const gchar *full_path);
void glade_xml_doc_free (GladeXmlDoc *doc_in);
G_END_DECLS
#endif /* __GLADE_XML_UTILS_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment