Kouhei Sutou
kous****@users*****
2006年 11月 22日 (水) 15:39:44 JST
Index: tomoe/lib/tomoe-char.c diff -u tomoe/lib/tomoe-char.c:1.42 tomoe/lib/tomoe-char.c:1.43 --- tomoe/lib/tomoe-char.c:1.42 Wed Nov 22 15:19:19 2006 +++ tomoe/lib/tomoe-char.c Wed Nov 22 15:39:44 2006 @@ -18,7 +18,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-char.c,v 1.42 2006/11/22 06:19:19 makeinu Exp $ + * $Id: tomoe-char.c,v 1.43 2006/11/22 06:39:44 kous Exp $ */ #include <stdlib.h> @@ -36,7 +36,7 @@ { char *charCode; TomoeWriting *writing; - GPtrArray *readings; + GList *readings; GHashTable *meta; }; @@ -72,9 +72,9 @@ } static void -tomoe_char_init (TomoeChar *t_char) +tomoe_char_init (TomoeChar *chr) { - TomoeCharPrivate *priv = TOMOE_CHAR_GET_PRIVATE (t_char); + TomoeCharPrivate *priv = TOMOE_CHAR_GET_PRIVATE (chr); priv->charCode = NULL; priv->writing = NULL; priv->meta = g_hash_table_new_full(g_str_hash, g_str_equal, @@ -99,8 +99,10 @@ g_object_unref (G_OBJECT (priv->writing)); if (priv->meta) g_hash_table_destroy (priv->meta); - if (priv->readings) - TOMOE_PTR_ARRAY_FREE_ALL (priv->readings, g_free); + if (priv->readings) { + g_list_foreach (priv->readings, (GFunc)g_free, NULL); + g_list_free (priv->readings); + } priv->charCode = NULL; priv->writing = NULL; @@ -115,11 +117,11 @@ const GValue *value, GParamSpec *pspec) { - TomoeChar *t_char; + TomoeChar *chr; TomoeCharPrivate *priv; - t_char = TOMOE_CHAR(object); - priv = TOMOE_CHAR_GET_PRIVATE (t_char); + chr = TOMOE_CHAR(object); + priv = TOMOE_CHAR_GET_PRIVATE (chr); switch (prop_id) { default: @@ -134,11 +136,11 @@ GValue *value, GParamSpec *pspec) { - TomoeChar *t_char; + TomoeChar *chr; TomoeCharPrivate *priv; - t_char = TOMOE_CHAR (object); - priv = TOMOE_CHAR_GET_PRIVATE (t_char); + chr = TOMOE_CHAR (object); + priv = TOMOE_CHAR_GET_PRIVATE (chr); switch (prop_id) { default: @@ -148,95 +150,71 @@ } const char* -tomoe_char_get_code (const TomoeChar* t_char) +tomoe_char_get_code (const TomoeChar* chr) { TomoeCharPrivate *priv; - g_return_val_if_fail (TOMOE_IS_CHAR (t_char), NULL); + g_return_val_if_fail (TOMOE_IS_CHAR (chr), NULL); - priv = TOMOE_CHAR_GET_PRIVATE (t_char); + priv = TOMOE_CHAR_GET_PRIVATE (chr); return priv->charCode; } void -tomoe_char_set_code (TomoeChar* t_char, const char* code) +tomoe_char_set_code (TomoeChar* chr, const char* code) { TomoeCharPrivate *priv; - g_return_if_fail (TOMOE_IS_CHAR (t_char)); + g_return_if_fail (TOMOE_IS_CHAR (chr)); - priv = TOMOE_CHAR_GET_PRIVATE (t_char); + priv = TOMOE_CHAR_GET_PRIVATE (chr); g_free (priv->charCode); priv->charCode = code ? g_strdup (code) : NULL; } -static void -_copy_reading_func (gpointer data, gpointer user_data) -{ - GPtrArray *new = (GPtrArray *) user_data; - const gchar *reading = (const gchar*) data; - - g_ptr_array_add (new, g_strdup (reading)); -} - -#warning FIXME! this interface is too bad. We need TomoeCharReading object? -GPtrArray* -tomoe_char_get_readings (TomoeChar* t_char) +const GList * +tomoe_char_get_readings (TomoeChar* chr) { TomoeCharPrivate *priv; - GPtrArray *readings; - g_return_val_if_fail (TOMOE_IS_CHAR (t_char), NULL); + g_return_val_if_fail (TOMOE_IS_CHAR (chr), NULL); - priv = TOMOE_CHAR_GET_PRIVATE (t_char); - - readings = g_ptr_array_new (); - if (priv->readings) { - g_ptr_array_foreach (priv->readings, _copy_reading_func, readings); - } - return readings; + priv = TOMOE_CHAR_GET_PRIVATE (chr); + return priv->readings; } void -tomoe_char_set_readings (TomoeChar* t_char, GPtrArray* readings) +tomoe_char_add_reading (TomoeChar* chr, const gchar *reading) { TomoeCharPrivate *priv; - g_return_if_fail (TOMOE_IS_CHAR (t_char)); - - priv = TOMOE_CHAR_GET_PRIVATE (t_char); + g_return_if_fail (TOMOE_IS_CHAR (chr)); - if (priv->readings) { - TOMOE_PTR_ARRAY_FREE_ALL (priv->readings, g_free); - priv->readings = NULL; - } + priv = TOMOE_CHAR_GET_PRIVATE (chr); - priv->readings = g_ptr_array_new (); - if (readings) { - g_ptr_array_foreach (readings, _copy_reading_func, priv->readings); - } + priv->readings = g_list_prepend(priv->readings, g_strdup(reading)); } TomoeWriting* -tomoe_char_get_writing (TomoeChar* t_char) +tomoe_char_get_writing (TomoeChar* chr) { TomoeCharPrivate *priv; - g_return_val_if_fail (TOMOE_IS_CHAR (t_char), NULL); + g_return_val_if_fail (TOMOE_IS_CHAR (chr), NULL); - priv = TOMOE_CHAR_GET_PRIVATE (t_char); + priv = TOMOE_CHAR_GET_PRIVATE (chr); return priv->writing; } void -tomoe_char_set_writing (TomoeChar* t_char, TomoeWriting* writing) +tomoe_char_set_writing (TomoeChar* chr, TomoeWriting* writing) { TomoeCharPrivate *priv; - g_return_if_fail (TOMOE_IS_CHAR (t_char)); + g_return_if_fail (TOMOE_IS_CHAR (chr)); - priv = TOMOE_CHAR_GET_PRIVATE (t_char); + priv = TOMOE_CHAR_GET_PRIVATE (chr); if (priv->writing) g_object_unref (G_OBJECT (priv->writing)); Index: tomoe/lib/tomoe-char.h diff -u tomoe/lib/tomoe-char.h:1.40 tomoe/lib/tomoe-char.h:1.41 --- tomoe/lib/tomoe-char.h:1.40 Wed Nov 22 15:19:19 2006 +++ tomoe/lib/tomoe-char.h Wed Nov 22 15:39:44 2006 @@ -18,7 +18,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-char.h,v 1.40 2006/11/22 06:19:19 makeinu Exp $ + * $Id: tomoe-char.h,v 1.41 2006/11/22 06:39:44 kous Exp $ */ /** @file tomoe-char.h @@ -63,12 +63,12 @@ */ TomoeChar *tomoe_char_new (void); -const char *tomoe_char_get_code (const TomoeChar *t_char); -void tomoe_char_set_code (TomoeChar *t_char, - const char *code); -GPtrArray *tomoe_char_get_readings (TomoeChar *t_char); -void tomoe_char_set_readings (TomoeChar *t_char, - GPtrArray *readings); +const gchar *tomoe_char_get_code (const TomoeChar *chr); +void tomoe_char_set_code (TomoeChar *chr, + const gchar *code); +const GList *tomoe_char_get_readings (TomoeChar *chr); +void tomoe_char_add_reading (TomoeChar *chr, + const gchar *reading); TomoeWriting *tomoe_char_get_writing (TomoeChar *t_char); void tomoe_char_set_writing (TomoeChar *t_char, TomoeWriting *writing); Index: tomoe/lib/tomoe-dict.c diff -u tomoe/lib/tomoe-dict.c:1.66 tomoe/lib/tomoe-dict.c:1.67 --- tomoe/lib/tomoe-dict.c:1.66 Wed Nov 22 15:19:19 2006 +++ tomoe/lib/tomoe-dict.c Wed Nov 22 15:39:44 2006 @@ -21,7 +21,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-dict.c,v 1.66 2006/11/22 06:19:19 makeinu Exp $ + * $Id: tomoe-dict.c,v 1.67 2006/11/22 06:39:44 kous Exp $ */ #include <stdio.h> @@ -318,7 +318,6 @@ for (i = 0; i < num; i++) { xmlNodePtr charNode = xmlNewChild (root, NULL, BAD_CAST "character", NULL); TomoeChar* chr = (TomoeChar*)g_ptr_array_index (priv->letters, i); - GPtrArray *readings = tomoe_char_get_readings (chr); TomoeWriting* writing = tomoe_char_get_writing (chr); const char* code = tomoe_char_get_code (chr); xmlNewChild (charNode, NULL, BAD_CAST "literal", BAD_CAST code); @@ -340,16 +339,24 @@ xmlNewChild (strokelistNode, NULL, BAD_CAST "s", BAD_CAST buf); } } - if (readings->len) { - guint readings_num = readings->len; - xmlNodePtr readingsNode = xmlNewChild (charNode, NULL, BAD_CAST "readings", NULL); - for (k = 0; k < readings_num; k++) - xmlNewChild (readingsNode, NULL, BAD_CAST "r", g_ptr_array_index (readings, k)); + + { + const GList *readings, *reading; + + readings = tomoe_char_get_readings (chr); + if (readings) { + xmlNodePtr readingsNode; + readingsNode = xmlNewChild (charNode, NULL, + BAD_CAST "readings", NULL); + for (reading = readings; reading; reading = reading->next) { + xmlNewChild (readingsNode, NULL, BAD_CAST "r", + reading->data); + } + } } + tomoe_char_meta_data_foreach (chr, tomoe_dict_append_meta_data, charNode); - - TOMOE_PTR_ARRAY_FREE_ALL (readings, g_free); } xmlSaveFormatFileEnc(priv->filename, doc, "UTF-8", 1); @@ -485,31 +492,11 @@ { TomoeChar *chr = data; TomoeDictSearchContext *context = user_data; - guint reading_num, i; - gboolean find = FALSE; - GPtrArray *readings; - - readings = tomoe_char_get_readings (chr); - - /* check for available reading data */ - if (!readings->len) { - TOMOE_PTR_ARRAY_FREE_ALL (readings, g_free); - return; - } - reading_num = readings->len; - for (i = 0; i < reading_num; i++) { - const char* r = (const char*) g_ptr_array_index (readings, i); - if (0 == strcmp (r, context->reading)) { - find = TRUE; - break; - } - } - if (find) + if (g_list_find_custom ((GList *)tomoe_char_get_readings (chr), + context->reading, (GCompareFunc)strcmp)) context->results = g_list_prepend (context->results, tomoe_candidate_new (chr)); - - TOMOE_PTR_ARRAY_FREE_ALL (readings, g_free); } GList * @@ -534,10 +521,8 @@ xmlNodePtr child; for (child = node->children; child; child = child->next) { if (child->type == XML_ELEMENT_NODE) { - GPtrArray *readings = tomoe_char_get_readings (chr); - g_ptr_array_add (readings, strdup ((const char*)child->children->content)); - tomoe_char_set_readings (chr, readings); - TOMOE_PTR_ARRAY_FREE_ALL (readings, g_free); + tomoe_char_add_reading (chr, + (const gchar *)child->children->content); } } }