Kouhei Sutou
kous****@users*****
2006年 11月 27日 (月) 11:02:57 JST
Index: tomoe/lib/tomoe-char.c diff -u tomoe/lib/tomoe-char.c:1.46 tomoe/lib/tomoe-char.c:1.47 --- tomoe/lib/tomoe-char.c:1.46 Sun Nov 26 16:30:37 2006 +++ tomoe/lib/tomoe-char.c Mon Nov 27 11:02:57 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.46 2006/11/26 07:30:37 kous Exp $ + * $Id: tomoe-char.c,v 1.47 2006/11/27 02:02:57 kous Exp $ */ #include <stdlib.h> @@ -264,7 +264,7 @@ tomoe_char_has_meta_data (TomoeChar *chr) { TomoeCharPrivate *priv; - g_return_if_fail (chr); + g_return_val_if_fail (chr, FALSE); priv = TOMOE_CHAR_GET_PRIVATE (chr); return g_hash_table_size (priv->meta) > 0; Index: tomoe/lib/tomoe-dict.c diff -u tomoe/lib/tomoe-dict.c:1.85 tomoe/lib/tomoe-dict.c:1.86 --- tomoe/lib/tomoe-dict.c:1.85 Mon Nov 27 10:57:04 2006 +++ tomoe/lib/tomoe-dict.c Mon Nov 27 11:02:57 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.85 2006/11/27 01:57:04 makeinu Exp $ + * $Id: tomoe-dict.c,v 1.86 2006/11/27 02:02:57 kous Exp $ */ #include <stdio.h> @@ -764,45 +764,6 @@ return TRUE; } -static gboolean -_write_writing (TomoeChar *chr, FILE *f) -{ - TomoeWriting *writing = tomoe_char_get_writing (chr); - GList *stroke_list = (GList*) tomoe_writing_get_strokes (writing); - gchar buf[256]; - - if (!stroke_list) return TRUE; - - g_snprintf (buf, G_N_ELEMENTS (buf), " <strokelist>\n"); - if (fwrite (buf, strlen (buf), 1, f) < 1) return FALSE; - - for (; stroke_list; stroke_list = g_list_next (stroke_list)) { - GList *point_list = stroke_list->data; - - if (!point_list) continue; - - g_snprintf (buf, G_N_ELEMENTS (buf), " <s>"); - if (fwrite (buf, strlen (buf), 1, f) < 1) return FALSE; - - for (; point_list; point_list = g_list_next (point_list)) { - TomoePoint *p = point_list->data; - - if (!p) continue; - - g_snprintf (buf, G_N_ELEMENTS (buf), "(%d %d) ", p->x, p->y); - if (fwrite (buf, strlen (buf), 1, f) < 1) return FALSE; - } - - g_snprintf (buf, G_N_ELEMENTS (buf), "</s>\n"); - if (fwrite (buf, strlen (buf), 1, f) < 1) return FALSE; - } - - g_snprintf (buf, G_N_ELEMENTS (buf), " </strokelist>\n"); - if (fwrite (buf, strlen (buf), 1, f) < 1) return FALSE; - - return TRUE; -} - static void _write_meta_datum (gpointer key, gpointer value, gpointer user_data) { @@ -833,6 +794,7 @@ { gchar *head; const gchar *foot = " </character>\n"; + gchar *output; g_return_val_if_fail (TOMOE_IS_CHAR (chr), FALSE); @@ -852,8 +814,16 @@ if (!_write_readings (chr, f)) return FALSE; /* writing */ - if (tomoe_char_get_writing (chr)) - if (!_write_writing (chr, f)) return FALSE; + if (tomoe_char_get_writing (chr)) { + gboolean failed; + + output = tomoe_writing_to_xml (tomoe_char_get_writing (chr)); + if (!output) return FALSE; + + failed = fwrite (output, strlen (output), 1, f) < 1; + g_free (output); + if (failed) return FALSE; + } /* meta */ if (tomoe_char_has_meta_data (chr)) Index: tomoe/lib/tomoe-writing.c diff -u tomoe/lib/tomoe-writing.c:1.7 tomoe/lib/tomoe-writing.c:1.8 --- tomoe/lib/tomoe-writing.c:1.7 Fri Nov 24 15:39:24 2006 +++ tomoe/lib/tomoe-writing.c Mon Nov 27 11:02:57 2006 @@ -18,7 +18,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-writing.c,v 1.7 2006/11/24 06:39:24 ikezoe Exp $ + * $Id: tomoe-writing.c,v 1.8 2006/11/27 02:02:57 kous Exp $ */ #include <stdlib.h> @@ -173,6 +173,43 @@ return TOMOE_WRITING_GET_PRIVATE(writing)->stroke_first; } +gchar * +tomoe_writing_to_xml (TomoeWriting *writing) +{ + TomoeWritingPrivate *priv; + GList *stroke_list; + GString *output; + + g_return_val_if_fail (TOMOE_IS_WRITING (writing), NULL); + + priv = TOMOE_WRITING_GET_PRIVATE(writing); + if (!priv->stroke_first) return NULL; + + output = g_string_new (" <strokelist>\n"); + for (stroke_list = priv->stroke_first; + stroke_list; + stroke_list = g_list_next (stroke_list)) { + GList *point_list = stroke_list->data; + + if (!point_list) continue; + g_string_append (output, " <s>"); + + for (; point_list; point_list = g_list_next (point_list)) { + TomoePoint *p = point_list->data; + + if (!p) continue; + + g_string_append_printf (output, "(%d %d) ", p->x, p->y); + } + + g_string_append (output, "</s>\n"); + } + + g_string_append (output, " </strokelist>\n"); + + return g_string_free (output, FALSE); +} + TomoePoint * tomoe_point_new (gint x, gint y) { Index: tomoe/lib/tomoe-writing.h diff -u tomoe/lib/tomoe-writing.h:1.5 tomoe/lib/tomoe-writing.h:1.6 --- tomoe/lib/tomoe-writing.h:1.5 Fri Nov 24 15:22:36 2006 +++ tomoe/lib/tomoe-writing.h Mon Nov 27 11:02:57 2006 @@ -18,7 +18,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-writing.h,v 1.5 2006/11/24 06:22:36 ikezoe Exp $ + * $Id: tomoe-writing.h,v 1.6 2006/11/27 02:02:57 kous Exp $ */ /** @file tomoe-handwrite.h @@ -77,6 +77,8 @@ const GList *tomoe_writing_get_strokes (TomoeWriting *writing); +gchar *tomoe_writing_to_xml (TomoeWriting *writing); + GType tomoe_point_get_type (void) G_GNUC_CONST; TomoePoint *tomoe_point_new (gint x, gint y);