Coding style cleanup

This commit is contained in:
Michael Natterer 2009-10-17 20:37:13 +02:00
parent 7ce6757ad0
commit b77592ffb2
1 changed files with 80 additions and 67 deletions

View File

@ -27,7 +27,6 @@
#include "libgimpbase/gimpbase.h" #include "libgimpbase/gimpbase.h"
#include "libgimpmath/gimpmath.h" #include "libgimpmath/gimpmath.h"
#include "libgimpconfig/gimpconfig.h"
#include "core-types.h" #include "core-types.h"
@ -43,47 +42,48 @@
typedef struct typedef struct
{ {
const gchar *locale; const gchar *locale;
GString *buf; GString *buf;
gboolean locale_matches; gboolean locale_matches;
} GimpTagsInstaller; } GimpTagsInstaller;
static void gimp_tags_installer_load_start_element (GMarkupParseContext *context,
const gchar *element_name, static void gimp_tags_installer_load_start_element (GMarkupParseContext *context,
const gchar **attribute_names, const gchar *element_name,
const gchar **attribute_values, const gchar **attribute_names,
gpointer user_data, const gchar **attribute_values,
GError **error); gpointer user_data,
static void gimp_tags_installer_load_end_element (GMarkupParseContext *context, GError **error);
const gchar *element_name, static void gimp_tags_installer_load_end_element (GMarkupParseContext *context,
gpointer user_data, const gchar *element_name,
GError **error); gpointer user_data,
static void gimp_tags_installer_load_text (GMarkupParseContext *context, GError **error);
const gchar *text, static void gimp_tags_installer_load_text (GMarkupParseContext *context,
gsize text_len, const gchar *text,
gpointer user_data, gsize text_len,
GError **error); gpointer user_data,
static const gchar* attribute_name_to_value (const gchar **attribute_names, GError **error);
const gchar **attribute_values, static const gchar* attribute_name_to_value (const gchar **attribute_names,
const gchar *name); const gchar **attribute_values,
const gchar *name);
gboolean gboolean
gimp_tags_user_install (void) gimp_tags_user_install (void)
{ {
gchar *filename; gchar *filename;
GError *error; GMarkupParser markup_parser;
GMarkupParser markup_parser; GimpXmlParser *xml_parser;
GimpXmlParser *xml_parser; const char *tags_locale;
const char *tags_locale; GimpTagsInstaller tags_installer = { 0, };
GimpTagsInstaller tags_installer = { 0, }; GError *error = NULL;
gboolean result = TRUE; gboolean result = TRUE;
/* This is a special string to specify the language identifier to /* This is a special string to specify the language identifier to
look for in the gimp-tags-default.xml file. Please translate the * look for in the gimp-tags-default.xml file. Please translate the
C in it according to the name of the po file used for * C in it according to the name of the po file used for
gimp-tags-default.xml. E.g. lithuanian for the translation, * gimp-tags-default.xml. E.g. lithuanian for the translation,
that would be "tags-locale:lt". * that would be "tags-locale:lt".
*/ */
tags_locale = _("tags-locale:C"); tags_locale = _("tags-locale:C");
@ -100,22 +100,26 @@ gimp_tags_user_install (void)
} }
tags_installer.buf = g_string_new (NULL); tags_installer.buf = g_string_new (NULL);
g_string_append (tags_installer.buf, "<?xml version='1.0' encoding='UTF-8'?>\n"); g_string_append (tags_installer.buf, "<?xml version='1.0' encoding='UTF-8'?>\n");
g_string_append (tags_installer.buf, "<tags>\n"); g_string_append (tags_installer.buf, "<tags>\n");
filename = g_build_filename (gimp_data_directory (), "tags", filename = g_build_filename (gimp_data_directory (), "tags",
"gimp-tags-default.xml", NULL); "gimp-tags-default.xml", NULL);
error = NULL;
markup_parser.start_element = gimp_tags_installer_load_start_element; markup_parser.start_element = gimp_tags_installer_load_start_element;
markup_parser.end_element = gimp_tags_installer_load_end_element; markup_parser.end_element = gimp_tags_installer_load_end_element;
markup_parser.text = gimp_tags_installer_load_text; markup_parser.text = gimp_tags_installer_load_text;
markup_parser.passthrough = NULL; markup_parser.passthrough = NULL;
markup_parser.error = NULL; markup_parser.error = NULL;
xml_parser = gimp_xml_parser_new (&markup_parser, &tags_installer); xml_parser = gimp_xml_parser_new (&markup_parser, &tags_installer);
result = gimp_xml_parser_parse_file (xml_parser, filename, &error); result = gimp_xml_parser_parse_file (xml_parser, filename, &error);
g_free (filename); g_free (filename);
gimp_xml_parser_free (xml_parser); gimp_xml_parser_free (xml_parser);
if (! result) if (! result)
{ {
g_string_free (tags_installer.buf, TRUE); g_string_free (tags_installer.buf, TRUE);
@ -125,10 +129,13 @@ gimp_tags_user_install (void)
g_string_append (tags_installer.buf, "\n</tags>\n"); g_string_append (tags_installer.buf, "\n</tags>\n");
filename = g_build_filename (gimp_directory (), GIMP_TAGS_FILE, NULL); filename = g_build_filename (gimp_directory (), GIMP_TAGS_FILE, NULL);
error = NULL;
result = g_file_set_contents (filename, tags_installer.buf->str, tags_installer.buf->len, &error); result = g_file_set_contents (filename, tags_installer.buf->str,
tags_installer.buf->len, &error);
g_free (filename); g_free (filename);
g_string_free (tags_installer.buf, TRUE); g_string_free (tags_installer.buf, TRUE);
if (! result) if (! result)
{ {
g_warning ("Error while creating tags.xml: %s\n", error->message); g_warning ("Error while creating tags.xml: %s\n", error->message);
@ -140,18 +147,19 @@ gimp_tags_user_install (void)
} }
static void static void
gimp_tags_installer_load_start_element (GMarkupParseContext *context, gimp_tags_installer_load_start_element (GMarkupParseContext *context,
const gchar *element_name, const gchar *element_name,
const gchar **attribute_names, const gchar **attribute_names,
const gchar **attribute_values, const gchar **attribute_values,
gpointer user_data, gpointer user_data,
GError **error) GError **error)
{ {
GimpTagsInstaller *tags_installer = (GimpTagsInstaller*) user_data; GimpTagsInstaller *tags_installer = user_data;
if (! strcmp (element_name, "resource")) if (! strcmp (element_name, "resource"))
{ {
g_string_append_printf (tags_installer->buf, "\n <resource"); g_string_append_printf (tags_installer->buf, "\n <resource");
while (*attribute_names) while (*attribute_names)
{ {
g_string_append_printf (tags_installer->buf, " %s=\"%s\"", g_string_append_printf (tags_installer->buf, " %s=\"%s\"",
@ -160,31 +168,36 @@ gimp_tags_installer_load_start_element (GMarkupParseContext *context,
attribute_names++; attribute_names++;
attribute_values++; attribute_values++;
} }
g_string_append_printf (tags_installer->buf, ">\n"); g_string_append_printf (tags_installer->buf, ">\n");
} }
else if (! strcmp (element_name, "thetag")) else if (! strcmp (element_name, "thetag"))
{ {
const char *current_locale; const char *current_locale;
current_locale = attribute_name_to_value (attribute_names, attribute_values, "xml:lang"); current_locale = attribute_name_to_value (attribute_names, attribute_values,
"xml:lang");
if (current_locale && tags_installer->locale) if (current_locale && tags_installer->locale)
{ {
tags_installer->locale_matches = !strcmp (current_locale, tags_installer->locale); tags_installer->locale_matches = ! strcmp (current_locale,
tags_installer->locale);
} }
else else
{ {
tags_installer->locale_matches = (current_locale == tags_installer->locale); tags_installer->locale_matches = (current_locale ==
tags_installer->locale);
} }
} }
} }
static void static void
gimp_tags_installer_load_end_element (GMarkupParseContext *context, gimp_tags_installer_load_end_element (GMarkupParseContext *context,
const gchar *element_name, const gchar *element_name,
gpointer user_data, gpointer user_data,
GError **error) GError **error)
{ {
GimpTagsInstaller *tags_installer = (GimpTagsInstaller*) user_data; GimpTagsInstaller *tags_installer = user_data;
if (strcmp (element_name, "resource") == 0) if (strcmp (element_name, "resource") == 0)
{ {
@ -193,13 +206,13 @@ gimp_tags_installer_load_end_element (GMarkupParseContext *context,
} }
static void static void
gimp_tags_installer_load_text (GMarkupParseContext *context, gimp_tags_installer_load_text (GMarkupParseContext *context,
const gchar *text, const gchar *text,
gsize text_len, gsize text_len,
gpointer user_data, gpointer user_data,
GError **error) GError **error)
{ {
GimpTagsInstaller *tags_installer = (GimpTagsInstaller*) user_data; GimpTagsInstaller *tags_installer = user_data;
const gchar *current_element; const gchar *current_element;
gchar *tag_string; gchar *tag_string;
@ -210,15 +223,16 @@ gimp_tags_installer_load_text (GMarkupParseContext *context,
strcmp (current_element, "thetag") == 0) strcmp (current_element, "thetag") == 0)
{ {
tag_string = g_markup_escape_text (text, text_len); tag_string = g_markup_escape_text (text, text_len);
g_string_append_printf (tags_installer->buf, " <tag>%s</tag>\n", tag_string); g_string_append_printf (tags_installer->buf, " <tag>%s</tag>\n",
tag_string);
g_free (tag_string); g_free (tag_string);
} }
} }
static const gchar* static const gchar *
attribute_name_to_value (const gchar **attribute_names, attribute_name_to_value (const gchar **attribute_names,
const gchar **attribute_values, const gchar **attribute_values,
const gchar *name) const gchar *name)
{ {
while (*attribute_names) while (*attribute_names)
{ {
@ -233,4 +247,3 @@ attribute_name_to_value (const gchar **attribute_names,
return NULL; return NULL;
} }