reduce code duplication
authorTommi Komulainen <tommi.komulainen@iki.fi>
Wed, 15 Oct 2008 22:08:40 +0000 (22:08 +0000)
committerTommi Komulainen <tko@src.gnome.org>
Wed, 15 Oct 2008 22:08:40 +0000 (22:08 +0000)
2008-10-15  Tommi Komulainen  <tommi.komulainen@iki.fi>

* tools/generate.c (write_type_name, write_type_info,
write_type_info, write_object_info, write_object_info,
write_interface_info, write_error_domain_info): reduce code
duplication

svn path=/trunk/; revision=718

ChangeLog
tools/generate.c

index 2b7aa02654c48d11ca42b60126ca9d2a8c456094..8b4a6877864361397cf27aa78e12d0aad6c6b8c1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-10-15  Tommi Komulainen  <tommi.komulainen@iki.fi>
+
+       * tools/generate.c (write_type_name, write_type_info,
+       write_type_info, write_object_info, write_object_info,
+       write_interface_info, write_error_domain_info): reduce code
+       duplication
+
 2008-10-15  Tommi Komulainen  <tommi.komulainen@iki.fi>
 
        Bug 556174 – parse types for lists etc.
index fb80138db868b5cc4459a9569d96abc2b2990685..7493f657fa7b17af6c99eb95b29635157cf7c29c 100644 (file)
@@ -175,6 +175,17 @@ write_type_name (const gchar *namespace,
   xml_printf (file, "%s", g_base_info_get_name (info));
 }
 
+static void
+write_type_name_attribute (const gchar *namespace,
+                          GIBaseInfo  *info,
+                          const char  *attr_name,
+                          Xml         *file)
+{
+  xml_printf (file, " %s=\"", attr_name);
+  write_type_name (namespace, info, file);
+  xml_printf (file, "\"");
+}
+
 static void
 write_type_info (const gchar *namespace,
                 GITypeInfo  *info, 
@@ -230,9 +241,7 @@ write_type_info (const gchar *namespace,
     {
       GIBaseInfo *iface = g_type_info_get_interface (info);
       xml_start_element (file, "type");
-      xml_printf (file, " name=\"");
-      write_type_name (namespace, iface, file);
-      xml_printf (file, "\"");
+      write_type_name_attribute (namespace, iface, "name", file);
       xml_end_element (file, "type");
       g_base_info_unref (iface);
     }
@@ -289,9 +298,7 @@ write_type_info (const gchar *namespace,
            {
              GIErrorDomainInfo *ed = g_type_info_get_error_domain (info, i);
              xml_start_element (file, "type");
-             xml_printf (file, " name=\"");
-             write_type_name (namespace, (GIBaseInfo *)ed, file);
-             xml_printf (file, "\"");
+             write_type_name_attribute (namespace, (GIBaseInfo *)ed, "name", file);
              xml_end_element (file, "type");
              g_base_info_unref ((GIBaseInfo *)ed);
            }
@@ -881,9 +888,7 @@ write_object_info (const gchar  *namespace,
   pnode = g_object_info_get_parent (info);
   if (pnode)
     {
-      xml_printf (file, " parent=\"");
-      write_type_name (namespace, (GIBaseInfo *)pnode, file);
-      xml_printf (file, "\""  );
+      write_type_name_attribute (namespace, (GIBaseInfo *)pnode, "parent", file);
       g_base_info_unref ((GIBaseInfo *)pnode);
     }
 
@@ -899,9 +904,7 @@ write_object_info (const gchar  *namespace,
        {
          GIInterfaceInfo *imp = g_object_info_get_interface (info, i);
           xml_start_element (file, "implements");
-         xml_printf (file, " name=\"");
-         write_type_name (namespace, (GIBaseInfo*)imp, file);
-         xml_printf (file,"\"");
+         write_type_name_attribute (namespace, (GIBaseInfo *)imp, "name", file);
           xml_end_element (file, "implements");
          g_base_info_unref ((GIBaseInfo*)imp);
        }
@@ -987,8 +990,7 @@ write_interface_info (const gchar     *namespace,
             xml_start_element (file, "interface");
          else
             xml_start_element (file, "object");
-          xml_printf (file, " name=\"");
-         write_type_name (namespace, req, file);
+         write_type_name_attribute (namespace, req, "name", file);
           xml_end_element_unchecked (file);
          g_base_info_unref (req);
        }
@@ -1045,9 +1047,9 @@ write_error_domain_info (const gchar       *namespace,
   quark = g_error_domain_info_get_quark (info);
   enum_ = (GIBaseInfo *)g_error_domain_info_get_codes (info);
   xml_start_element (file, "errordomain");
-  xml_printf (file, " name=\"%s\" get-quark=\"%s\" codes=\"",
+  xml_printf (file, " name=\"%s\" get-quark=\"%s\"",
               name, quark);
-  write_type_name (namespace, enum_, file);
+  write_type_name_attribute (namespace, enum_, "codes", file);
   xml_end_element (file, "errordomain");
   g_base_info_unref (enum_);
 }