summaryrefslogtreecommitdiff
path: root/lib/ephy-node-db.c
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@igalia.com>2016-03-21 23:13:34 -0500
committerMichael Catanzaro <mcatanzaro@igalia.com>2016-03-21 23:55:15 -0500
commitc5d5bd28f071b3734b0f07af7e802f902263d6f0 (patch)
tree32a2bf0127ac7732e4afa4dd65da6c81b17585ee /lib/ephy-node-db.c
parent17c9805c3b7901d17666c71a2163de980eb5c774 (diff)
downloadepiphany-uncrustify.tar.gz
Uncrustifyuncrustify
For a better future. Apologies when your 'git blame' resolves to this. I'm actually really impressed how well uncrustify works. This required only a little one-time manual work to avoid extra space in 'else {'. This breaks function prototype alignment, but we should get rid of most of those anyway. We decided to start aligning function parameters, like other GNOME applications. It looks nicer this way, and I couldn't teach uncrustify the previous Epiphany style.
Diffstat (limited to 'lib/ephy-node-db.c')
-rw-r--r--lib/ephy-node-db.c512
1 files changed, 246 insertions, 266 deletions
diff --git a/lib/ephy-node-db.c b/lib/ephy-node-db.c
index 11a0c1271..7847724cf 100644
--- a/lib/ephy-node-db.c
+++ b/lib/ephy-node-db.c
@@ -32,99 +32,95 @@
/* FIXME I want to find a better way to deal with "root" nodes */
#define RESERVED_IDS 30
-enum
-{
- PROP_0,
- PROP_NAME,
- PROP_IMMUTABLE,
- LAST_PROP
+enum {
+ PROP_0,
+ PROP_NAME,
+ PROP_IMMUTABLE,
+ LAST_PROP
};
static GParamSpec *obj_properties[LAST_PROP];
-struct _EphyNodeDb
-{
- GObject parent_instance;
+struct _EphyNodeDb {
+ GObject parent_instance;
- char *name;
- gboolean immutable;
+ char *name;
+ gboolean immutable;
- guint id_factory;
+ guint id_factory;
- GPtrArray *id_to_node;
+ GPtrArray *id_to_node;
};
G_DEFINE_TYPE (EphyNodeDb, ephy_node_db, G_TYPE_OBJECT)
static void
-ephy_node_db_get_property (GObject *object,
- guint prop_id,
- GValue *value,
+ephy_node_db_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
GParamSpec *pspec)
{
- EphyNodeDb *db = EPHY_NODE_DB (object);
-
- switch (prop_id)
- {
- case PROP_NAME:
- g_value_set_string (value, db->name);
- break;
- case PROP_IMMUTABLE:
- g_value_set_boolean (value, ephy_node_db_is_immutable (db));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ EphyNodeDb *db = EPHY_NODE_DB (object);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ g_value_set_string (value, db->name);
+ break;
+ case PROP_IMMUTABLE:
+ g_value_set_boolean (value, ephy_node_db_is_immutable (db));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
-ephy_node_db_set_property (GObject *object,
- guint prop_id,
+ephy_node_db_set_property (GObject *object,
+ guint prop_id,
const GValue *value,
- GParamSpec *pspec)
+ GParamSpec *pspec)
{
- EphyNodeDb *db = EPHY_NODE_DB (object);
-
- switch (prop_id)
- {
- case PROP_NAME:
- db->name = g_value_dup_string (value);
- break;
- case PROP_IMMUTABLE:
- ephy_node_db_set_immutable (db, g_value_get_boolean (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ EphyNodeDb *db = EPHY_NODE_DB (object);
+
+ switch (prop_id) {
+ case PROP_NAME:
+ db->name = g_value_dup_string (value);
+ break;
+ case PROP_IMMUTABLE:
+ ephy_node_db_set_immutable (db, g_value_get_boolean (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
}
static void
ephy_node_db_free_func (EphyNode *node)
{
- if (node)
- ephy_node_unref (node);
+ if (node)
+ ephy_node_unref (node);
}
static void
ephy_node_db_init (EphyNodeDb *db)
{
- /* id to node */
- db->id_to_node = g_ptr_array_new_with_free_func ((GDestroyNotify)ephy_node_db_free_func);
+ /* id to node */
+ db->id_to_node = g_ptr_array_new_with_free_func ((GDestroyNotify)ephy_node_db_free_func);
- /* id factory */
- db->id_factory = RESERVED_IDS;
+ /* id factory */
+ db->id_factory = RESERVED_IDS;
}
static void
ephy_node_db_finalize (GObject *object)
{
- EphyNodeDb *db = EPHY_NODE_DB (object);
+ EphyNodeDb *db = EPHY_NODE_DB (object);
- g_ptr_array_free (db->id_to_node, TRUE);
+ g_ptr_array_free (db->id_to_node, TRUE);
- g_free (db->name);
+ g_free (db->name);
- G_OBJECT_CLASS (ephy_node_db_parent_class)->finalize (object);
+ G_OBJECT_CLASS (ephy_node_db_parent_class)->finalize (object);
}
/**
@@ -138,24 +134,24 @@ ephy_node_db_finalize (GObject *object)
EphyNodeDb *
ephy_node_db_new (const char *name)
{
- EphyNodeDb *db;
+ EphyNodeDb *db;
- db = EPHY_NODE_DB (g_object_new (EPHY_TYPE_NODE_DB,
- "name", name,
- NULL));
+ db = EPHY_NODE_DB (g_object_new (EPHY_TYPE_NODE_DB,
+ "name", name,
+ NULL));
- return db;
+ return db;
}
static inline EphyNode *
node_from_id_real (EphyNodeDb *db, guint id)
{
- EphyNode *ret = NULL;
+ EphyNode *ret = NULL;
- if (id < db->id_to_node->len)
- ret = g_ptr_array_index (db->id_to_node, id);
+ if (id < db->id_to_node->len)
+ ret = g_ptr_array_index (db->id_to_node, id);
- return ret;
+ return ret;
}
/**
@@ -167,7 +163,7 @@ node_from_id_real (EphyNodeDb *db, guint id)
const char *
ephy_node_db_get_name (EphyNodeDb *db)
{
- return db->name;
+ return db->name;
}
/**
@@ -179,7 +175,7 @@ ephy_node_db_get_name (EphyNodeDb *db)
gboolean
ephy_node_db_is_immutable (EphyNodeDb *db)
{
- return db->immutable;
+ return db->immutable;
}
/**
@@ -193,9 +189,9 @@ ephy_node_db_is_immutable (EphyNodeDb *db)
void
ephy_node_db_set_immutable (EphyNodeDb *db, gboolean immutable)
{
- db->immutable = immutable;
+ db->immutable = immutable;
- g_object_notify_by_pspec (G_OBJECT (db), obj_properties[PROP_IMMUTABLE]);
+ g_object_notify_by_pspec (G_OBJECT (db), obj_properties[PROP_IMMUTABLE]);
}
/**
@@ -210,48 +206,47 @@ ephy_node_db_set_immutable (EphyNodeDb *db, gboolean immutable)
EphyNode *
ephy_node_db_get_node_from_id (EphyNodeDb *db, guint id)
{
- EphyNode *ret = NULL;
+ EphyNode *ret = NULL;
- ret = node_from_id_real (db, id);
+ ret = node_from_id_real (db, id);
- return ret;
+ return ret;
}
guint
_ephy_node_db_new_id (EphyNodeDb *db)
{
- guint ret;
+ guint ret;
- while (node_from_id_real (db, db->id_factory) != NULL)
- {
- db->id_factory++;
- }
+ while (node_from_id_real (db, db->id_factory) != NULL) {
+ db->id_factory++;
+ }
- ret = db->id_factory;
+ ret = db->id_factory;
- return ret;
+ return ret;
}
void
_ephy_node_db_add_id (EphyNodeDb *db,
- guint id,
- EphyNode *node)
+ guint id,
+ EphyNode *node)
{
- /* resize array if needed */
- if (id >= db->id_to_node->len)
- g_ptr_array_set_size (db->id_to_node, id + 1);
+ /* resize array if needed */
+ if (id >= db->id_to_node->len)
+ g_ptr_array_set_size (db->id_to_node, id + 1);
- g_ptr_array_index (db->id_to_node, id) = node;
+ g_ptr_array_index (db->id_to_node, id) = node;
}
void
_ephy_node_db_remove_id (EphyNodeDb *db,
- guint id)
+ guint id)
{
- g_ptr_array_index (db->id_to_node, id) = NULL;
+ g_ptr_array_index (db->id_to_node, id) = NULL;
- /* reset id factory so we use the freed node id */
- db->id_factory = RESERVED_IDS;
+ /* reset id factory so we use the freed node id */
+ db->id_factory = RESERVED_IDS;
}
/**
@@ -272,176 +267,163 @@ _ephy_node_db_remove_id (EphyNodeDb *db,
* Return value: %TRUE if successful
**/
gboolean
-ephy_node_db_load_from_file (EphyNodeDb *db,
- const char *xml_file,
- const xmlChar *xml_root,
- const xmlChar *xml_version)
+ephy_node_db_load_from_file (EphyNodeDb *db,
+ const char *xml_file,
+ const xmlChar *xml_root,
+ const xmlChar *xml_version)
{
- xmlTextReaderPtr reader;
- gboolean success = TRUE;
- gboolean was_immutable;
- int ret;
+ xmlTextReaderPtr reader;
+ gboolean success = TRUE;
+ gboolean was_immutable;
+ int ret;
- LOG ("ephy_node_db_load_from_file %s", xml_file);
+ LOG ("ephy_node_db_load_from_file %s", xml_file);
- START_PROFILER ("loading node db")
+ START_PROFILER ("loading node db")
- if (g_file_test (xml_file, G_FILE_TEST_EXISTS) == FALSE)
- {
- return FALSE;
- }
+ if (g_file_test (xml_file, G_FILE_TEST_EXISTS) == FALSE) {
+ return FALSE;
+ }
- reader = xmlNewTextReaderFilename (xml_file);
- if (reader == NULL)
- {
- return FALSE;
- }
+ reader = xmlNewTextReaderFilename (xml_file);
+ if (reader == NULL) {
+ return FALSE;
+ }
- was_immutable = db->immutable;
- db->immutable = FALSE;
+ was_immutable = db->immutable;
+ db->immutable = FALSE;
- ret = xmlTextReaderRead (reader);
- while (ret == 1)
- {
- const xmlChar *name;
- xmlReaderTypes type;
- gboolean skip = FALSE;
+ ret = xmlTextReaderRead (reader);
+ while (ret == 1) {
+ const xmlChar *name;
+ xmlReaderTypes type;
+ gboolean skip = FALSE;
- name = xmlTextReaderConstName (reader);
- type = xmlTextReaderNodeType (reader);
+ name = xmlTextReaderConstName (reader);
+ type = xmlTextReaderNodeType (reader);
- if (xmlStrEqual (name, (const xmlChar *)"node")
- && type == XML_READER_TYPE_ELEMENT)
- {
- xmlNodePtr subtree;
+ if (xmlStrEqual (name, (const xmlChar *)"node")
+ && type == XML_READER_TYPE_ELEMENT) {
+ xmlNodePtr subtree;
- /* grow the subtree and load the node from it */
- subtree = xmlTextReaderExpand (reader);
+ /* grow the subtree and load the node from it */
+ subtree = xmlTextReaderExpand (reader);
- if (subtree != NULL)
- {
- ephy_node_new_from_xml (db, subtree);
- }
+ if (subtree != NULL) {
+ ephy_node_new_from_xml (db, subtree);
+ }
- skip = TRUE;
- }
- else if (xmlStrEqual (name, xml_root)
- && type == XML_READER_TYPE_ELEMENT)
- {
- xmlChar *version;
+ skip = TRUE;
+ } else if (xmlStrEqual (name, xml_root)
+ && type == XML_READER_TYPE_ELEMENT) {
+ xmlChar *version;
- /* check version info */
- version = xmlTextReaderGetAttribute (reader, (const xmlChar *)"version");
- if (xmlStrEqual (version, xml_version) == FALSE)
- {
- success = FALSE;
- xmlFree (version);
+ /* check version info */
+ version = xmlTextReaderGetAttribute (reader, (const xmlChar *)"version");
+ if (xmlStrEqual (version, xml_version) == FALSE) {
+ success = FALSE;
+ xmlFree (version);
- break;
- }
+ break;
+ }
- xmlFree (version);
- }
+ xmlFree (version);
+ }
- /* next one, please */
- ret = skip ? xmlTextReaderNext (reader)
- : xmlTextReaderRead (reader);
- }
+ /* next one, please */
+ ret = skip ? xmlTextReaderNext (reader)
+ : xmlTextReaderRead (reader);
+ }
- xmlFreeTextReader (reader);
+ xmlFreeTextReader (reader);
- db->immutable = was_immutable;
+ db->immutable = was_immutable;
- STOP_PROFILER ("loading node db")
+ STOP_PROFILER ("loading node db")
- return (success && ret == 0);
+ return (success && ret == 0);
}
static int
-ephy_node_db_write_to_xml_valist (EphyNodeDb *db,
- xmlBuffer *buffer,
- const xmlChar *root,
- const xmlChar *version,
- const xmlChar *comment,
- EphyNode *first_node,
- va_list argptr)
+ephy_node_db_write_to_xml_valist (EphyNodeDb *db,
+ xmlBuffer *buffer,
+ const xmlChar *root,
+ const xmlChar *version,
+ const xmlChar *comment,
+ EphyNode *first_node,
+ va_list argptr)
{
- xmlTextWriterPtr writer;
- EphyNode *node;
- int ret;
+ xmlTextWriterPtr writer;
+ EphyNode *node;
+ int ret;
- START_PROFILER ("Saving node db")
+ START_PROFILER ("Saving node db")
- /* FIXME: do we want to turn compression on ? */
- writer = xmlNewTextWriterMemory (buffer, 0);
- if (writer == NULL)
- {
- return -1;
- }
+ /* FIXME: do we want to turn compression on ? */
+ writer = xmlNewTextWriterMemory (buffer, 0);
+ if (writer == NULL) {
+ return -1;
+ }
- ret = xmlTextWriterSetIndent (writer, 1);
- if (ret < 0) goto out;
+ ret = xmlTextWriterSetIndent (writer, 1);
+ if (ret < 0) goto out;
- ret = xmlTextWriterSetIndentString (writer, (const xmlChar *)" ");
- if (ret < 0) goto out;
+ ret = xmlTextWriterSetIndentString (writer, (const xmlChar *)" ");
+ if (ret < 0) goto out;
- ret = xmlTextWriterStartDocument (writer, "1.0", NULL, NULL);
- if (ret < 0) goto out;
+ ret = xmlTextWriterStartDocument (writer, "1.0", NULL, NULL);
+ if (ret < 0) goto out;
- ret = xmlTextWriterStartElement (writer, root);
- if (ret < 0) goto out;
+ ret = xmlTextWriterStartElement (writer, root);
+ if (ret < 0) goto out;
- ret = xmlTextWriterWriteAttribute (writer, (const xmlChar *)"version", version);
- if (ret < 0) goto out;
+ ret = xmlTextWriterWriteAttribute (writer, (const xmlChar *)"version", version);
+ if (ret < 0) goto out;
- if (comment != NULL)
- {
- ret = xmlTextWriterWriteComment (writer, comment);
- if (ret < 0) goto out;
- }
+ if (comment != NULL) {
+ ret = xmlTextWriterWriteComment (writer, comment);
+ if (ret < 0) goto out;
+ }
- node = first_node;
- while (node != NULL)
- {
- GPtrArray *children;
- EphyNodeFilterFunc filter;
- gpointer user_data;
- guint i;
+ node = first_node;
+ while (node != NULL) {
+ GPtrArray *children;
+ EphyNodeFilterFunc filter;
+ gpointer user_data;
+ guint i;
- filter = va_arg (argptr, EphyNodeFilterFunc);
- user_data = va_arg (argptr, gpointer);
+ filter = va_arg (argptr, EphyNodeFilterFunc);
+ user_data = va_arg (argptr, gpointer);
- children = ephy_node_get_children (node);
- for (i = 0; i < children->len; i++)
- {
- EphyNode *kid;
+ children = ephy_node_get_children (node);
+ for (i = 0; i < children->len; i++) {
+ EphyNode *kid;
- kid = g_ptr_array_index (children, i);
+ kid = g_ptr_array_index (children, i);
- if (!filter || filter (kid, user_data))
- {
- ret = ephy_node_write_to_xml (kid, writer);
- if (ret < 0) break;
- }
- }
- if (ret < 0) break;
+ if (!filter || filter (kid, user_data)) {
+ ret = ephy_node_write_to_xml (kid, writer);
+ if (ret < 0) break;
+ }
+ }
+ if (ret < 0) break;
- node = va_arg (argptr, EphyNode *);
- }
- if (ret < 0) goto out;
+ node = va_arg (argptr, EphyNode *);
+ }
+ if (ret < 0) goto out;
- ret = xmlTextWriterEndElement (writer); /* root */
- if (ret < 0) goto out;
+ ret = xmlTextWriterEndElement (writer); /* root */
+ if (ret < 0) goto out;
- ret = xmlTextWriterEndDocument (writer);
- if (ret < 0) goto out;
+ ret = xmlTextWriterEndDocument (writer);
+ if (ret < 0) goto out;
-out:
- xmlFreeTextWriter (writer);
+ out:
+ xmlFreeTextWriter (writer);
- STOP_PROFILER ("Saving node db")
+ STOP_PROFILER ("Saving node db")
- return ret >= 0 ? 0 : -1;
+ return ret >= 0 ? 0 : -1;
}
/**
@@ -453,7 +435,7 @@ out:
* @comment: a comment to place directly inside the @root element of @filename
* @node: The first node of data to write
* @Varargs: number of exceptions, list of their #EphyNodes, and more such
- * sequences, followed by %NULL
+ * sequences, followed by %NULL
*
* Writes @db's data to an XML file for storage. The data can be retrieved in
* the future using ephy_node_db_load_from_file().
@@ -479,68 +461,66 @@ out:
**/
int
ephy_node_db_write_to_xml_safe (EphyNodeDb *db,
- const xmlChar *filename,
- const xmlChar *root,
- const xmlChar *version,
- const xmlChar *comment,
- EphyNode *node, ...)
+ const xmlChar *filename,
+ const xmlChar *root,
+ const xmlChar *version,
+ const xmlChar *comment,
+ EphyNode *node, ...)
{
- va_list argptr;
- xmlBuffer *buffer;
- GError *error = NULL;
- int ret = 0;
+ va_list argptr;
+ xmlBuffer *buffer;
+ GError *error = NULL;
+ int ret = 0;
- LOG ("Saving node db to %s", filename);
+ LOG ("Saving node db to %s", filename);
- va_start (argptr, node);
+ va_start (argptr, node);
- buffer = xmlBufferCreate ();
- ret = ephy_node_db_write_to_xml_valist
- (db, buffer, root, version, comment, node, argptr);
+ buffer = xmlBufferCreate ();
+ ret = ephy_node_db_write_to_xml_valist
+ (db, buffer, root, version, comment, node, argptr);
- va_end (argptr);
+ va_end (argptr);
- if (ret < 0)
- {
- g_warning ("Failed to write XML data");
- goto failed;
- }
+ if (ret < 0) {
+ g_warning ("Failed to write XML data");
+ goto failed;
+ }
- if (g_file_set_contents ((const char *)filename, (const char *)buffer->content, buffer->use, &error) == FALSE)
- {
- g_warning ("Error saving EphyNodeDB as XML: %s", error->message);
- g_error_free (error);
- ret = -1;
- }
+ if (g_file_set_contents ((const char *)filename, (const char *)buffer->content, buffer->use, &error) == FALSE) {
+ g_warning ("Error saving EphyNodeDB as XML: %s", error->message);
+ g_error_free (error);
+ ret = -1;
+ }
-failed:
- xmlBufferFree (buffer);
+ failed:
+ xmlBufferFree (buffer);
- return ret;
+ return ret;
}
static void
ephy_node_db_class_init (EphyNodeDbClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = ephy_node_db_finalize;
- object_class->set_property = ephy_node_db_set_property;
- object_class->get_property = ephy_node_db_get_property;
-
- obj_properties[PROP_NAME] =
- g_param_spec_string ("name",
- "Name",
- "Name",
- NULL,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
-
- obj_properties[PROP_IMMUTABLE] =
- g_param_spec_boolean ("immutable",
- "Immutable",
- "Immutable",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ephy_node_db_finalize;
+ object_class->set_property = ephy_node_db_set_property;
+ object_class->get_property = ephy_node_db_get_property;
+
+ obj_properties[PROP_NAME] =
+ g_param_spec_string ("name",
+ "Name",
+ "Name",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
+
+ obj_properties[PROP_IMMUTABLE] =
+ g_param_spec_boolean ("immutable",
+ "Immutable",
+ "Immutable",
+ FALSE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
}