[gspell/wip/untie-libxml: 3/5] cont.
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/untie-libxml: 3/5] cont.
- Date: Thu, 10 Dec 2015 18:09:30 +0000 (UTC)
commit d355a1dcb77fe3b4b8a0abd9f13ed56f974da6f3
Author: Sébastien Wilmet <swilmet gnome org>
Date: Thu Dec 10 18:51:41 2015 +0100
cont.
gspell/gspell-language.c | 146 +++++++++++++++++++++++++++-------------------
1 files changed, 86 insertions(+), 60 deletions(-)
---
diff --git a/gspell/gspell-language.c b/gspell/gspell-language.c
index f66d18d..65ad73d 100644
--- a/gspell/gspell-language.c
+++ b/gspell/gspell-language.c
@@ -19,7 +19,7 @@
* along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#include "gtkhtml-spell-language.h"
+#include "gspell-language.h"
#include <string.h>
#include <glib/gi18n-lib.h>
@@ -28,7 +28,8 @@
#define ISO_639_DOMAIN "iso_639"
#define ISO_3166_DOMAIN "iso_3166"
-struct _GspellLanguage {
+struct _GspellLanguage
+{
gchar *code;
gchar *name;
gchar *ckey;
@@ -37,8 +38,6 @@ struct _GspellLanguage {
static GHashTable *iso_639_table = NULL;
static GHashTable *iso_3166_table = NULL;
-#ifdef HAVE_ISO_CODES
-
#define ISOCODESLOCALEDIR ISO_CODES_PREFIX "/share/locale"
#ifdef G_OS_WIN32
@@ -50,20 +49,20 @@ static HMODULE hmodule;
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
- DWORD fdwReason,
- LPVOID lpvReserved);
+ DWORD fdwReason,
+ LPVOID lpvReserved);
BOOL WINAPI
DllMain (HINSTANCE hinstDLL,
- DWORD fdwReason,
- LPVOID lpvReserved)
+ DWORD fdwReason,
+ LPVOID lpvReserved)
{
switch (fdwReason)
- {
- case DLL_PROCESS_ATTACH:
- hmodule = hinstDLL;
- break;
- }
+ {
+ case DLL_PROCESS_ATTACH:
+ hmodule = hinstDLL;
+ break;
+ }
return TRUE;
}
@@ -72,20 +71,23 @@ static gchar *
_get_iso_codes_prefix (void)
{
static gchar retval[1000];
- static gint beenhere = 0;
+ static gboolean beenhere = FALSE;
gchar *temp_dir = 0;
if (beenhere)
+ {
return retval;
+ }
- if (!(temp_dir = g_win32_get_package_installation_directory_of_module ((gpointer) hmodule))) {
+ if (!(temp_dir = g_win32_get_package_installation_directory_of_module ((gpointer) hmodule)))
+ {
strcpy (retval, ISO_CODES_PREFIX);
return retval;
}
strcpy (retval, temp_dir);
g_free (temp_dir);
- beenhere = 1;
+ beenhere = TRUE;
return retval;
}
@@ -93,14 +95,16 @@ static gchar *
_get_isocodeslocaledir (void)
{
static gchar retval[1000];
- static gint beenhere = 0;
+ static gboolean beenhere = FALSE;
if (beenhere)
+ {
return retval;
+ }
strcpy (retval, _get_iso_codes_prefix ());
strcat (retval, "\\share\\locale");
- beenhere = 1;
+ beenhere = TRUE;
return retval;
}
@@ -110,15 +114,15 @@ _get_isocodeslocaledir (void)
#undef ISOCODESLOCALEDIR
#define ISOCODESLOCALEDIR _get_isocodeslocaledir ()
-#endif
+#endif /* G_OS_WIN32 */
static void
-iso_639_start_element (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer data,
- GError **error)
+iso_639_start_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer data,
+ GError **error)
{
GHashTable *hash_table = data;
const gchar *iso_639_1_code = NULL;
@@ -128,32 +132,44 @@ iso_639_start_element (GMarkupParseContext *context,
gint ii;
if (strcmp (element_name, "iso_639_entry") != 0)
+ {
return;
+ }
- for (ii = 0; attribute_names[ii] != NULL; ii++) {
+ for (ii = 0; attribute_names[ii] != NULL; ii++)
+ {
if (strcmp (attribute_names[ii], "name") == 0)
+ {
name = attribute_values[ii];
+ }
else if (strcmp (attribute_names[ii], "iso_639_1_code") == 0)
+ {
iso_639_1_code = attribute_values[ii];
+ }
else if (strcmp (attribute_names[ii], "iso_639_2T_code") == 0)
+ {
iso_639_2_code = attribute_values[ii];
+ }
}
code = (iso_639_1_code != NULL) ? iso_639_1_code : iso_639_2_code;
- if (code != NULL && *code != '\0' && name != NULL && *name != '\0')
- g_hash_table_insert (
- hash_table, g_strdup (code),
- g_strdup (dgettext (ISO_639_DOMAIN, name)));
+ if (code != NULL && *code != '\0' &&
+ name != NULL && *name != '\0')
+ {
+ g_hash_table_insert (hash_table,
+ g_strdup (code),
+ g_strdup (dgettext (ISO_639_DOMAIN, name)));
+ }
}
static void
-iso_3166_start_element (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer data,
- GError **error)
+iso_3166_start_element (GMarkupParseContext *context,
+ const gchar *element_name,
+ const gchar **attribute_names,
+ const gchar **attribute_values,
+ gpointer data,
+ GError **error)
{
GHashTable *hash_table = data;
const gchar *name = NULL;
@@ -161,73 +177,83 @@ iso_3166_start_element (GMarkupParseContext *context,
gint ii;
if (strcmp (element_name, "iso_3166_entry") != 0)
+ {
return;
+ }
- for (ii = 0; attribute_names[ii] != NULL; ii++) {
+ for (ii = 0; attribute_names[ii] != NULL; ii++)
+ {
if (strcmp (attribute_names[ii], "name") == 0)
+ {
name = attribute_values[ii];
+ }
else if (strcmp (attribute_names[ii], "alpha_2_code") == 0)
+ {
code = attribute_values[ii];
+ }
}
- if (code != NULL && *code != '\0' && name != NULL && *name != '\0')
- g_hash_table_insert (
- hash_table, g_ascii_strdown (code, -1),
- g_strdup (dgettext (ISO_3166_DOMAIN, name)));
+ if (code != NULL && *code != '\0' &&
+ name != NULL && *name != '\0')
+ {
+ g_hash_table_insert (hash_table,
+ g_ascii_strdown (code, -1),
+ g_strdup (dgettext (ISO_3166_DOMAIN, name)));
+ }
}
-static GMarkupParser iso_639_parser = {
+static GMarkupParser iso_639_parser =
+{
iso_639_start_element,
NULL, NULL, NULL, NULL
};
-static GMarkupParser iso_3166_parser = {
+static GMarkupParser iso_3166_parser =
+{
iso_3166_start_element,
NULL, NULL, NULL, NULL
};
static void
iso_codes_parse (const GMarkupParser *parser,
- const gchar *basename,
- GHashTable *hash_table)
+ const gchar *basename,
+ GHashTable *hash_table)
{
GMappedFile *mapped_file;
gchar *filename;
GError *error = NULL;
- filename = g_build_filename (
- ISO_CODES_PREFIX, "share", "xml",
- "iso-codes", basename, NULL);
+ filename = g_build_filename (ISO_CODES_PREFIX,
+ "share",
+ "xml",
+ "iso-codes",
+ basename,
+ NULL);
+
mapped_file = g_mapped_file_new (filename, FALSE, &error);
g_free (filename);
- if (mapped_file != NULL) {
+ if (mapped_file != NULL)
+ {
GMarkupParseContext *context;
const gchar *contents;
gsize length;
- context = g_markup_parse_context_new (
- parser, 0, hash_table, NULL);
+ context = g_markup_parse_context_new (parser, 0, hash_table, NULL);
contents = g_mapped_file_get_contents (mapped_file);
length = g_mapped_file_get_length (mapped_file);
- g_markup_parse_context_parse (
- context, contents, length, &error);
+ g_markup_parse_context_parse (context, contents, length, &error);
g_markup_parse_context_free (context);
-#if GLIB_CHECK_VERSION(2,21,3)
g_mapped_file_unref (mapped_file);
-#else
- g_mapped_file_free (mapped_file);
-#endif
}
- if (error != NULL) {
+ if (error != NULL)
+ {
g_warning ("%s: %s", basename, error->message);
g_error_free (error);
}
}
-#endif /* HAVE_ISO_CODES */
-
static void
spell_language_dict_describe_cb (const gchar * const language_code,
const gchar * const provider_name,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]