[Xfce4-commits] <squeeze:master> Cleanup parser.c (partially) and parser.h

Stephan Arts noreply at xfce.org
Tue Oct 4 22:28:01 CEST 2011


Updating branch refs/heads/master
         to c0753b8c94ef67874956aae32241ccd5443d6b4e (commit)
       from b91a87c5add8c9267d6ae00057a7b77aafd2cb7c (commit)

commit c0753b8c94ef67874956aae32241ccd5443d6b4e
Author: Stephan Arts <stephan at xfce.org>
Date:   Tue Oct 4 22:27:40 2011 +0200

    Cleanup parser.c (partially) and parser.h

 libsqueeze/parser.c |  255 +++++++++++++++++++++++++++------------------------
 libsqueeze/parser.h |   96 +++++++++++++-------
 2 files changed, 200 insertions(+), 151 deletions(-)

diff --git a/libsqueeze/parser.c b/libsqueeze/parser.c
index c9586a2..84672d9 100644
--- a/libsqueeze/parser.c
+++ b/libsqueeze/parser.c
@@ -1,17 +1,17 @@
 /*
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or 
- *  (at your option) any later version.
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or 
+ *    (at your option) any later version.
  *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU Library General Public License for more details.
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
+ *    GNU Library General Public License for more details.
  *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 #include <config.h>
@@ -32,9 +32,9 @@ G_DEFINE_ABSTRACT_TYPE(LSQParser, lsq_parser, G_TYPE_OBJECT);
 
 struct _LSQTypeStorageGroup
 {
-  guint size_of;
-  guint n_types;
-  GType *types;
+    guint size_of;
+    guint n_types;
+    GType *types;
 };
 typedef struct _LSQTypeStorageGroup LSQTypeStorageGroup;
 static LSQTypeStorageGroup *storage_groups = NULL;
@@ -43,170 +43,189 @@ static guint storage_group_count = 0;
 static void
 lsq_storage_group_add(GType type, guint size_of)
 {
-  guint i;
-  LSQTypeStorageGroup *_storage_groups;
-  GType *_types;
+    guint i;
+    LSQTypeStorageGroup *_storage_groups;
+    GType *_types;
 
-  for (i = 0; i < storage_group_count; ++i)
-  {
-    if (storage_groups[i].size_of <= size_of)
-      break;
-  }
+    for (i = 0; i < storage_group_count; ++i)
+    {
+        if (storage_groups[i].size_of <= size_of)
+        {
+            break;
+        }
+    }
 
-  g_return_if_fail(i <= storage_group_count);
+    g_return_if_fail(i <= storage_group_count);
 
-  if (i == storage_group_count ||
-      storage_groups[i].size_of < size_of)
-  {
-    _storage_groups = g_new0(LSQTypeStorageGroup, storage_group_count+1);
+    if (i == storage_group_count ||
+            storage_groups[i].size_of < size_of)
+    {
+        _storage_groups = g_new0(LSQTypeStorageGroup, storage_group_count+1);
 
-    memcpy(_storage_groups, storage_groups, sizeof(LSQTypeStorageGroup) * i);
-    memcpy(_storage_groups + i + 1, storage_groups + i, sizeof(LSQTypeStorageGroup) * (storage_group_count - i));
+        memcpy(_storage_groups, storage_groups, sizeof(LSQTypeStorageGroup) * i);
+        memcpy(_storage_groups + i + 1, storage_groups + i, sizeof(LSQTypeStorageGroup) * (storage_group_count - i));
 
-    g_free(storage_groups);
-    storage_groups = _storage_groups;
-    ++storage_group_count;
+        g_free(storage_groups);
+        storage_groups = _storage_groups;
+        ++storage_group_count;
 
-    storage_groups[i].size_of = size_of;
-    storage_groups[i].n_types = 0;
-    storage_groups[i].types = NULL;
-  }
+        storage_groups[i].size_of = size_of;
+        storage_groups[i].n_types = 0;
+        storage_groups[i].types = NULL;
+    }
 
-  _types = g_new(GType, storage_groups[i].n_types+1);
+    _types = g_new(GType, storage_groups[i].n_types+1);
 
-  memcpy(_types, storage_groups[i].types, sizeof(GType) * storage_groups[i].n_types);
+    memcpy(_types, storage_groups[i].types, sizeof(GType) * storage_groups[i].n_types);
 
-  g_free(storage_groups[i].types);
-  storage_groups[i].types = _types;
-  _types[storage_groups[i].n_types] = type;
-  ++storage_groups[i].n_types;
+    g_free(storage_groups[i].types);
+    storage_groups[i].types = _types;
+    _types[storage_groups[i].n_types] = type;
+    ++storage_groups[i].n_types;
 }
 
 static gboolean
-lsq_storage_group_has_type(LSQTypeStorageGroup *storage_group, GType type)
+lsq_storage_group_has_type (
+        LSQTypeStorageGroup *storage_group,
+        GType type )
 {
-  guint i;
-  for (i = 0; i < storage_group->n_types; ++i)
-  {
-    if (storage_group->types[i] == type)
-      return TRUE;
-  }
-  return FALSE;
+    guint i;
+    for (i = 0; i < storage_group->n_types; ++i)
+    {
+        if (storage_group->types[i] == type)
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 static void
-lsq_parser_init(LSQParser *self)
+lsq_parser_init ( LSQParser *self )
 {
 }
 
 static void
-lsq_parser_class_init(LSQParserClass *klass)
+lsq_parser_class_init ( LSQParserClass *klass )
 {
-  klass->get_context = NULL;
-
-  lsq_storage_group_add(G_TYPE_CHAR, sizeof(gchar));
-  lsq_storage_group_add(G_TYPE_DOUBLE, sizeof(gdouble));
-  lsq_storage_group_add(G_TYPE_FLOAT, sizeof(gfloat));
-  lsq_storage_group_add(G_TYPE_INT, sizeof(gint));
-  lsq_storage_group_add(G_TYPE_INT64, sizeof(gint64));
-  lsq_storage_group_add(G_TYPE_LONG, sizeof(glong));
-  lsq_storage_group_add(G_TYPE_STRING, sizeof(gchar*));
-  lsq_storage_group_add(G_TYPE_UINT, sizeof(guint));
-  lsq_storage_group_add(G_TYPE_UINT64, sizeof(guint64));
-  lsq_storage_group_add(G_TYPE_ULONG, sizeof(gulong));
+    klass->get_context = NULL;
+
+    lsq_storage_group_add(G_TYPE_CHAR, sizeof(gchar));
+    lsq_storage_group_add(G_TYPE_DOUBLE, sizeof(gdouble));
+    lsq_storage_group_add(G_TYPE_FLOAT, sizeof(gfloat));
+    lsq_storage_group_add(G_TYPE_INT, sizeof(gint));
+    lsq_storage_group_add(G_TYPE_INT64, sizeof(gint64));
+    lsq_storage_group_add(G_TYPE_LONG, sizeof(glong));
+    lsq_storage_group_add(G_TYPE_STRING, sizeof(gchar*));
+    lsq_storage_group_add(G_TYPE_UINT, sizeof(guint));
+    lsq_storage_group_add(G_TYPE_UINT64, sizeof(guint64));
+    lsq_storage_group_add(G_TYPE_ULONG, sizeof(gulong));
 }
 
 LSQParserContext*
-lsq_parser_get_context(LSQParser *self, LSQArchive *archive)
+lsq_parser_get_context (
+        LSQParser *self,
+        LSQArchive *archive )
 {
-	LSQParserClass *klass = LSQ_PARSER_GET_CLASS(self);
+    LSQParserClass *klass = LSQ_PARSER_GET_CLASS(self);
 
-	g_return_val_if_fail(klass->get_context, NULL);
+    g_return_val_if_fail(klass->get_context, NULL);
 
-	return klass->get_context(self, archive);
+    return klass->get_context(self, archive);
 }
 
 void
-lsq_parser_parse(LSQParser *self, LSQParserContext *ctx)
+lsq_parser_parse (
+        LSQParser *self,
+        LSQParserContext *ctx )
 {
-	LSQParserClass *klass = LSQ_PARSER_GET_CLASS(self);
+    LSQParserClass *klass = LSQ_PARSER_GET_CLASS(self);
 
-	g_return_if_fail(klass->parse);
+    g_return_if_fail(klass->parse);
 
-	klass->parse(self, ctx);
+    klass->parse(self, ctx);
 }
 
 guint
-lsq_parser_n_properties(LSQParser *parser)
+lsq_parser_n_properties ( LSQParser *parser )
 {
-  return parser->n_properties;
+    return parser->n_properties;
 }
 
 GType
-lsq_parser_get_property_type(LSQParser *parser, guint nr)
+lsq_parser_get_property_type (
+        LSQParser *parser,
+        guint nr )
 {
-  g_return_val_if_fail(nr < parser->n_properties, G_TYPE_NONE);
-  return parser->property_types[nr];
+    g_return_val_if_fail(nr < parser->n_properties, G_TYPE_NONE);
+    return parser->property_types[nr];
 }
 
 guint
-lsq_parser_get_property_offset(LSQParser *parser, guint nr)
+lsq_parser_get_property_offset (
+        LSQParser *parser,
+        guint nr )
 {
-  g_return_val_if_fail(nr < parser->n_properties, 0);
-  return parser->property_offset[nr];
+    g_return_val_if_fail(nr < parser->n_properties, 0);
+    return parser->property_offset[nr];
 }
 
 void
-lsq_parser_set_property_type(LSQParser *parser, guint nr, GType type)
+lsq_parser_set_property_type (
+        LSQParser *parser,
+        guint nr,
+        GType type )
 {
-  guint i, j;
-  guint size_of, offset = 0;
+    guint i, j;
+    guint size_of, offset = 0;
 
-  if(nr >= parser->n_properties)
-  {
-    GType *new_list = g_new(GType, nr+1);
-    for(i=0; i < parser->n_properties; ++i)
-    {
-      new_list[i] = parser->property_types[i];
-    }
-    while(i<nr)
+    if(nr >= parser->n_properties)
     {
-      new_list[i++] = G_TYPE_NONE;
+        GType *new_list = g_new(GType, nr+1);
+        for(i=0; i < parser->n_properties; ++i)
+        {
+            new_list[i] = parser->property_types[i];
+        }
+        while(i<nr)
+        {
+            new_list[i++] = G_TYPE_NONE;
+        }
+        g_free(parser->property_types);
+        parser->property_types = new_list;
+        parser->n_properties = nr+1;
+
+        g_free(parser->property_offset);
+        parser->property_offset = g_new(guint, nr+1);
     }
-    g_free(parser->property_types);
-    parser->property_types = new_list;
-    parser->n_properties = nr+1;
-
-    g_free(parser->property_offset);
-    parser->property_offset = g_new(guint, nr+1);
-  }
 
-  parser->property_types[nr] = type;
+    parser->property_types[nr] = type;
 
-  for (i = 0; i < storage_group_count; ++i)
-  {
-    size_of = storage_groups[i].size_of;
-    for (j = 0; j < parser->n_properties; ++j)
+    for (i = 0; i < storage_group_count; ++i)
     {
-      if (lsq_storage_group_has_type(&storage_groups[i], parser->property_types[j]))
-      {
-	guint align = offset % size_of;
-	if (align)
-	  offset += size_of - align;
-
-	/* Store the offset as count of block sized size_of */
-	parser->property_offset[j] = offset / size_of;
-	offset += size_of;
-      }
+        size_of = storage_groups[i].size_of;
+        for (j = 0; j < parser->n_properties; ++j)
+        {
+            if (lsq_storage_group_has_type(&storage_groups[i], parser->property_types[j]))
+            {
+                guint align = offset % size_of;
+                if ( 0 != align )
+                {
+                    offset += size_of - align;
+                }
+
+                /* Store the offset as count of block sized size_of */
+                parser->property_offset[j] = offset / size_of;
+                offset += size_of;
+            }
+        }
     }
-  }
 
-  parser->properties_size = offset;
+    parser->properties_size = offset;
 }
 
 guint
-lsq_parser_get_properties_size(LSQParser *parser)
+lsq_parser_get_properties_size ( LSQParser *parser )
 {
-  return parser->properties_size;
+    return parser->properties_size;
 }
 
diff --git a/libsqueeze/parser.h b/libsqueeze/parser.h
index 33c8d38..b3c0301 100644
--- a/libsqueeze/parser.h
+++ b/libsqueeze/parser.h
@@ -20,28 +20,28 @@ G_BEGIN_DECLS
 
 #define LSQ_TYPE_PARSER lsq_parser_get_type()
 
-#define LSQ_PARSER(obj) (			   \
-		G_TYPE_CHECK_INSTANCE_CAST ((obj),  \
-			LSQ_TYPE_PARSER,				  \
-			LSQParser))
+#define LSQ_PARSER(obj) (               \
+        G_TYPE_CHECK_INSTANCE_CAST ((obj),  \
+            LSQ_TYPE_PARSER,                  \
+            LSQParser))
 
-#define LSQ_IS_PARSER(obj) (			\
-		G_TYPE_CHECK_INSTANCE_TYPE ((obj),  \
-			LSQ_TYPE_PARSER))
+#define LSQ_IS_PARSER(obj) (            \
+        G_TYPE_CHECK_INSTANCE_TYPE ((obj),  \
+            LSQ_TYPE_PARSER))
 
-#define LSQ_PARSER_CLASS(class) (	  \
-		G_TYPE_CHECK_CLASS_CAST ((class),  \
-			LSQ_TYPE_PARSER,				 \
-			LSQParserClass))
+#define LSQ_PARSER_CLASS(class) (      \
+        G_TYPE_CHECK_CLASS_CAST ((class),  \
+            LSQ_TYPE_PARSER,                 \
+            LSQParserClass))
 
 #define LSQ_IS_PARSER_CLASS(class) (   \
-		G_TYPE_CHECK_CLASS_TYPE ((class),  \
-			LSQ_TYPE_PARSER))
+        G_TYPE_CHECK_CLASS_TYPE ((class),  \
+            LSQ_TYPE_PARSER))
 
-#define LSQ_PARSER_GET_CLASS(obj) (	\
-		G_TYPE_INSTANCE_GET_CLASS ((obj),  \
-			LSQ_TYPE_PARSER,				 \
-	  LSQParserClass))
+#define LSQ_PARSER_GET_CLASS(obj) (    \
+        G_TYPE_INSTANCE_GET_CLASS ((obj),  \
+            LSQ_TYPE_PARSER,                 \
+            LSQParserClass))
 
 
 #if 0
@@ -50,12 +50,12 @@ typedef struct _LSQParser LSQParser;
 
 struct _LSQParser
 {
-	GObject parent;
+    GObject parent;
 
-  guint n_properties;
-  GType *property_types;
-  guint *property_offset;
-  guint properties_size;
+    guint n_properties;
+    GType *property_types;
+    guint *property_offset;
+    guint properties_size;
 };
 
 
@@ -63,24 +63,54 @@ typedef struct _LSQParserClass LSQParserClass;
 
 struct _LSQParserClass
 {
-	GObjectClass parent;
+    GObjectClass parent;
 
-	LSQParserContext*(*get_context)(LSQParser *, LSQArchive *);
-  void(*parse)(LSQParser *, LSQParserContext *);
+    LSQParserContext*
+    (*get_context)(
+            LSQParser *,
+            LSQArchive * );
+
+    void
+    (*parse)(
+            LSQParser *,
+            LSQParserContext *);
 };
 
 
-GType		   lsq_parser_get_type(void);
+GType
+lsq_parser_get_type ( void );
+
+LSQParserContext*
+lsq_parser_get_context (
+        LSQParser *,
+        LSQArchive * );
+
+void
+lsq_parser_parse (
+        LSQParser *,
+        LSQParserContext * );
+
+guint
+lsq_parser_n_properties ( LSQParser * );
+
+GType
+lsq_parser_get_property_type (
+        LSQParser *,
+        guint );
 
-LSQParserContext* lsq_parser_get_context(LSQParser *, LSQArchive *);
+void
+lsq_parser_set_property_type (
+        LSQParser *,
+        guint,
+        GType );
 
-void              lsq_parser_parse(LSQParser *, LSQParserContext *);
+guint
+lsq_parser_get_property_offset (
+        LSQParser *,
+        guint );
 
-guint             lsq_parser_n_properties(LSQParser *);
-GType             lsq_parser_get_property_type(LSQParser *, guint);
-void              lsq_parser_set_property_type(LSQParser *, guint, GType);
-guint		  lsq_parser_get_property_offset(LSQParser *, guint);
-guint		  lsq_parser_get_properties_size(LSQParser *);
+guint
+lsq_parser_get_properties_size ( LSQParser * );
 
 G_END_DECLS
 


More information about the Xfce4-commits mailing list