From 6cef75a6df920f13a42b0ab17e2539aacc5e79e5 Mon Sep 17 00:00:00 2001 From: Vasily_Makarov Date: Wed, 8 Feb 2012 19:31:40 +0400 Subject: SAE: Removing dependencies of ibus --- saedit/Makefile | 21 ++-- saedit/config.c | 2 +- saedit/config.h | 1 - saedit/icon.svg | 118 +++++---------------- saedit/interface.ui | 5 + saedit/main.c | 4 +- saedit/sae.c | 5 +- saedit/sae.h | 1 - saedit/xml.c | 296 +++++++++++++++++++++++++++++++++++++++++++++++++++- saedit/xml.h | 29 +++-- 10 files changed, 361 insertions(+), 121 deletions(-) diff --git a/saedit/Makefile b/saedit/Makefile index d5a7bdc..a45c3c1 100644 --- a/saedit/Makefile +++ b/saedit/Makefile @@ -8,28 +8,23 @@ endif LDFLAGS += -export-dynamic -GTK_CFLAGS = `pkg-config --cflags gtk+-3.0 gtksourceview-3.0` -IBUS_CFLAGS = `pkg-config --cflags ibus-1.0` +CFLAGS += `pkg-config --cflags gtk+-3.0 gtksourceview-3.0` -GTK_LDFLAGS = `pkg-config --libs gtk+-3.0 gtksourceview-3.0` -IBUS_LDFLAGS = `pkg-config --libs ibus-1.0` - -IBUS_FLAGS = ${IBUS_CFLAGS} ${IBUS_LDFLAGS} -GTK_FLAGS = ${GTK_CFLAGS} ${GTK_LDFLAGS} +LDFLAGS += `pkg-config --libs gtk+-3.0 gtksourceview-3.0` OUTPUT = saedit all:clean main.o search.o config.o xml.o sae.o compile compile: main.o search.o config.o xml.o - gcc ${CFLAGS} ${GTK_FLAGS} ${IBUS_FLAGS} ${LDFLAGS} -o '${OUTPUT}' main.o search.o config.o xml.o sae.o + gcc ${CFLAGS} ${LDFLAGS} -o '${OUTPUT}' main.o search.o config.o xml.o sae.o main.o: main.c main.h search.h config.h common.h xml.h - gcc ${CFLAGS} ${GTK_CFLAGS} ${IBUS_CFLAGS} -c -o main.o main.c + gcc ${CFLAGS}-c -o main.o main.c search.o: search.c search.h common.h - gcc ${CFLAGS} ${GTK_CFLAGS} -c -o search.o search.c + gcc ${CFLAGS} -c -o search.o search.c xml.o: xml.c xml.h common.h - gcc ${CFLAGS} ${IBUS_FLAGS} -c -o xml.o xml.c + gcc ${CFLAGS} -c -o xml.o xml.c config.o: config.c config.h common.h - gcc ${CFLAGS} ${GTK_CFLAGS} ${IBUS_FLAGS} -c -o config.o config.c + gcc ${CFLAGS} -c -o config.o config.c sae.o: sae.c sae.h common.h - gcc ${CFLAGS} ${GTK_CFLAGS} ${IBUS_CFLAGS} -c -o sae.o sae.c + gcc ${CFLAGS} -c -o sae.o sae.c clean: rm -rfv '${OUTPUT}' *.o *.o~ *~ diff --git a/saedit/config.c b/saedit/config.c index 51d554d..cdc0ffd 100644 --- a/saedit/config.c +++ b/saedit/config.c @@ -20,7 +20,7 @@ void config_options_load_from_file(Options *options, gchar *data_folder) { options->sprites = NULL; - XMLNode *node = ibus_xml_parse_file(file); + XMLNode *node = xml_parse_file(file); if (node != NULL) { GList *list = node->sub_nodes; diff --git a/saedit/config.h b/saedit/config.h index 99f3da3..0fb0ac7 100644 --- a/saedit/config.h +++ b/saedit/config.h @@ -13,7 +13,6 @@ #define CONFIG_H #include -#include #include #include #include diff --git a/saedit/icon.svg b/saedit/icon.svg index c3dbf5e..6a3bf35 100644 --- a/saedit/icon.svg +++ b/saedit/icon.svg @@ -585,9 +585,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="1.4142136" - inkscape:cx="11.719468" - inkscape:cy="151.53998" + inkscape:zoom="1" + inkscape:cx="-79.999984" + inkscape:cy="276.83172" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" @@ -617,103 +617,37 @@ style="font-size:40px;font-style:normal;font-variant:normal;font-weight:500;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Charter" id="text3080" /> + id="g3107" + transform="matrix(5.7032977,0,0,5.7032977,-463.19349,-3989.5514)" + style="fill:#800000"> + transform="translate(-0.55621842,0.00758253)" + id="text3086" + style="font-size:40px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;fill:#800000;fill-opacity:1;stroke:none;font-family:Cantarell;-inkscape-font-specification:Sans"> - - - - - + inkscape:connector-curvature="0" + id="path3105" + style="fill:#800000;font-family:Sans;-inkscape-font-specification:Sans" + d="m 110.87616,841.71545 0,3.39844 c -1.01564,-0.52081 -2.07033,-0.91144 -3.16406,-1.17187 -1.09377,-0.2604 -2.22658,-0.39061 -3.39844,-0.39063 -1.78386,2e-5 -3.12501,0.27346 -4.02344,0.82031 -0.885421,0.5469 -1.328129,1.36721 -1.328123,2.46094 -6e-6,0.83335 0.319004,1.4909 0.957031,1.97266 0.638012,0.46876 1.920562,0.91798 3.847652,1.34765 l 1.23047,0.27344 c 2.55207,0.54689 4.36197,1.32163 5.42969,2.32422 1.08071,0.98959 1.62108,2.37631 1.62109,4.16016 -1e-5,2.03125 -0.80731,3.63932 -2.42187,4.82422 -1.60158,1.18489 -3.80861,1.77734 -6.62109,1.77734 -1.17189,0 -2.39584,-0.11719 -3.671879,-0.35156 -1.263026,-0.22136 -2.59766,-0.5599 -4.003906,-1.01563 l 0,-3.71094 c 1.328121,0.69011 2.636714,1.21094 3.925781,1.5625 1.289054,0.33855 2.565094,0.50782 3.828124,0.50782 1.6927,0 2.99478,-0.28646 3.90625,-0.85938 0.91144,-0.58593 1.36717,-1.40624 1.36719,-2.46094 -2e-5,-0.97655 -0.33205,-1.72525 -0.9961,-2.24609 -0.65105,-0.52082 -2.08985,-1.02213 -4.3164,-1.50391 l -1.25,-0.29296 c -2.22657,-0.46874 -3.834642,-1.18489 -4.82422,-2.14844 -0.989586,-0.97655 -1.484378,-2.31119 -1.484375,-4.00391 -3e-6,-2.05727 0.729163,-3.64581 2.1875,-4.76562 1.458327,-1.11977 3.528635,-1.67967 6.210935,-1.67969 1.32812,2e-5 2.57811,0.0977 3.75,0.29297 1.17186,0.19533 2.25259,0.4883 3.24219,0.8789" /> - - - - + id="text3090" + style="font-size:40px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;fill:#800000;fill-opacity:1;stroke:none;font-family:Cantarell;-inkscape-font-specification:Sans"> - - - - + id="path3102" + style="fill:#800000;font-family:Sans;-inkscape-font-specification:Sans" + d="m 97.149544,871.06958 c -2.903657,10e-6 -4.915374,0.33204 -6.035156,0.99609 -1.119799,0.66408 -1.679694,1.79689 -1.679688,3.39844 -6e-6,1.27605 0.41666,2.29167 1.25,3.04688 0.846346,0.74219 1.992178,1.11328 3.4375,1.11328 1.992175,0 3.587225,-0.70312 4.785156,-2.10938 1.210924,-1.41926 1.816394,-3.30077 1.816404,-5.64453 l 0,-0.80078 -3.574216,0 m 7.167966,-1.48437 0,12.48046 -3.59375,0 0,-3.32031 c -0.820326,1.32813 -1.842461,2.3112 -3.066404,2.94922 -1.223971,0.625 -2.721365,0.9375 -4.492187,0.9375 -2.239591,0 -4.023443,-0.625 -5.351563,-1.875 -1.315107,-1.26302 -1.972658,-2.94921 -1.972656,-5.05859 -2e-6,-2.46093 0.820309,-4.3164 2.460938,-5.56641 1.653639,-1.24999 4.114574,-1.87499 7.382812,-1.875 l 5.03906,0 0,-0.35156 c -1e-5,-1.65363 -0.54689,-2.92967 -1.640622,-3.82813 -1.080744,-0.91144 -2.60418,-1.36717 -4.570313,-1.36718 -1.25001,1e-5 -2.467457,0.14975 -3.652344,0.44921 -1.184902,0.2995 -2.324224,0.74872 -3.417968,1.34766 l 0,-3.32031 c 1.315098,-0.50779 2.591139,-0.8854 3.828125,-1.13281 1.23697,-0.2604 2.441395,-0.39061 3.613281,-0.39063 3.164048,2e-5 5.527331,0.82033 7.089841,2.46094 1.56248,1.64064 2.34373,4.12762 2.34375,7.46094" + inkscape:connector-curvature="0" /> - - - - - + id="text3094" + style="font-size:40px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;fill:#800000;fill-opacity:1;stroke:none;font-family:Cantarell;-inkscape-font-specification:Sans" + transform="translate(0,796.36209)"> + id="path3099" + style="fill:#800000;font-family:Sans;-inkscape-font-specification:Sans" + d="m 121.47542,73.044228 0,1.757812 -16.52344,0 c 0.15624,2.473966 0.89843,4.361985 2.22656,5.664063 1.34114,1.289065 3.20312,1.933596 5.58594,1.933593 1.38019,3e-6 2.71483,-0.169268 4.00391,-0.507812 1.30206,-0.338538 2.59112,-0.84635 3.86718,-1.523438 l 0,3.398438 c -1.28908,0.546875 -2.61069,0.963542 -3.96484,1.25 -1.35418,0.286458 -2.72788,0.429687 -4.12109,0.429687 -3.4896,0 -6.25652,-1.015624 -8.30078,-3.046875 -2.03126,-2.031245 -3.04688,-4.778638 -3.04688,-8.242187 0,-3.580715 0.96354,-6.419254 2.89063,-8.515625 1.94009,-2.109354 4.55077,-3.16404 7.83203,-3.164063 2.94269,2.3e-5 5.26691,0.950543 6.97265,2.851563 1.71873,1.888038 2.57811,4.45965 2.57813,7.714844 m -3.59375,-1.054688 c -0.0261,-1.966131 -0.57945,-3.53514 -1.66016,-4.707031 -1.06772,-1.171856 -2.48699,-1.757793 -4.25781,-1.757813 -2.00522,2e-5 -3.61329,0.566425 -4.82422,1.699219 -1.19792,1.132829 -1.88803,2.72788 -2.07031,4.785156 l 12.8125,-0.01953" + inkscape:connector-curvature="0" /> diff --git a/saedit/interface.ui b/saedit/interface.ui index db4b883..7c1ba9d 100644 --- a/saedit/interface.ui +++ b/saedit/interface.ui @@ -418,6 +418,7 @@ Reid Yaro <reidyaro@gmail.com> True False Clientdata folder + 24 @@ -447,6 +448,7 @@ Reid Yaro <reidyaro@gmail.com> True False XML source file + 24 @@ -537,6 +539,7 @@ Reid Yaro <reidyaro@gmail.com> True False Imagesets + 24 @@ -567,6 +570,7 @@ Reid Yaro <reidyaro@gmail.com> True False Actions + 24 @@ -597,6 +601,7 @@ Reid Yaro <reidyaro@gmail.com> True False Directions + 24 diff --git a/saedit/main.c b/saedit/main.c index b6ef4e9..44cd48c 100644 --- a/saedit/main.c +++ b/saedit/main.c @@ -514,7 +514,7 @@ void load_options() { void parse_xml_text(gchar *text, SAEInfo *sae_info) { free_lists(sae_info); - XMLNode *_root_node = ibus_xml_parse_buffer(text); + XMLNode *_root_node = xml_parse_buffer(text); sae_info->root = _root_node; if (_root_node == NULL) { show_wrong_source_buffer_dialog(); @@ -529,7 +529,7 @@ void parse_xml_text(gchar *text, SAEInfo *sae_info) { file_attr = g_strjoin(NULL, paths->sprites, file_attr, NULL); gchar *buf; if (g_file_get_contents(file_attr, &buf, NULL, NULL)) - _root_node->sub_nodes = g_list_concat(_root_node->sub_nodes, ibus_xml_parse_buffer(buf)->sub_nodes); + _root_node->sub_nodes = g_list_concat(_root_node->sub_nodes, xml_parse_buffer(buf)->sub_nodes); } if (list->next != NULL) list = g_list_find_custom(list->next, "include", xml_node_compare_with_name_func); diff --git a/saedit/sae.c b/saedit/sae.c index bb57bd5..472901e 100644 --- a/saedit/sae.c +++ b/saedit/sae.c @@ -127,9 +127,6 @@ gboolean set_up_animation_by_direction(SAEInfo *sae_info, const gchar *direction } if (sae_info->animation == NULL) return FALSE; - /*if (count > 1) { - g_list_last(sae_info->animation)->next = g_list_first(sae_info->animation); - g_list_first(sae_info->animation)->prev = g_list_last(sae_info->animation); - }*/ + return TRUE; } diff --git a/saedit/sae.h b/saedit/sae.h index 12d10e6..830e64b 100644 --- a/saedit/sae.h +++ b/saedit/sae.h @@ -13,7 +13,6 @@ #define SAE_H #include -#include #include "common.h" #include "xml.h" diff --git a/saedit/xml.c b/saedit/xml.c index 715a208..d7b697e 100644 --- a/saedit/xml.c +++ b/saedit/xml.c @@ -11,7 +11,7 @@ #include "xml.h" -gchar **xml_attr_new(const gchar *name, const gchar *value) { +gchar** xml_attr_new(const gchar *name, const gchar *value) { gchar **attr = g_new0(gchar*, 2); attr[0] = g_strdup(name); attr[1] = g_strdup(value); @@ -41,3 +41,297 @@ gint xml_node_compare_with_attr_func(const XMLNode *node, const gchar **attr) { return g_strcmp0(attr[1], xml_node_get_attr_value(node, attr[0])); } + +static GMarkupParser parser; + +void +xml_free (XMLNode *node) +{ + g_free (node->name); + + g_free (node->text); + + g_strfreev (node->attributes); + + g_list_foreach (node->sub_nodes, (GFunc) xml_free, NULL); + g_list_free (node->sub_nodes); + + g_slice_free (XMLNode, node); +} + +static void +_start_root_element_cb (GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) +{ + XMLNode **node = (XMLNode **) user_data; + g_assert (node != NULL); + + XMLNode *p = g_slice_new0 (XMLNode); + + + p->name = g_strdup (element_name); + + GArray *attributes = g_array_new (TRUE, TRUE, sizeof (gchar *)); + while (*attribute_names != NULL && *attribute_values != NULL) { + gchar *p; + p = g_strdup (*attribute_names++); + g_array_append_val (attributes, p); + p = g_strdup (*attribute_values++); + g_array_append_val (attributes, p); + } + + p->attributes = (gchar **) g_array_free (attributes, FALSE); + + g_markup_parse_context_push (context, &parser, p); + *node = p; +} + + +static void +_start_element_cb (GMarkupParseContext *context, + const gchar *element_name, + const gchar **attribute_names, + const gchar **attribute_values, + gpointer user_data, + GError **error) +{ + XMLNode *node = (XMLNode *) user_data; + + if (node->text) { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, " "); + return; + } + + XMLNode *p = g_slice_new0 (XMLNode); + + node->sub_nodes = g_list_append (node->sub_nodes, p); + g_markup_parse_context_push (context, &parser, p); + + p->name = g_strdup (element_name); + + GArray *attributes = g_array_new (TRUE, TRUE, sizeof (gchar *)); + while (*attribute_names != NULL && *attribute_values != NULL) { + gchar *p; + p = g_strdup (*attribute_names++); + g_array_append_val (attributes, p); + p = g_strdup (*attribute_values++); + g_array_append_val (attributes, p); + } + + p->attributes = (gchar **)g_array_free (attributes, FALSE); +} + +static void +_end_element_cb (GMarkupParseContext *context, + const gchar *element_name, + gpointer user_data, + GError **error) +{ + XMLNode *p = (XMLNode *) g_markup_parse_context_pop (context); + + if (p->text && p->sub_nodes) { + g_warning ("Error"); + } + + if (p->text == NULL && p->sub_nodes == NULL) { + p->text = g_strdup (""); + } +} + +static gboolean +_is_space (const gchar *text, + gsize text_len) +{ + gsize i = 0; + + for (i = 0; text[i] != '\0' && i < text_len; i++) { + switch (text[i]) { + case '\t': + case ' ': + case '\n': + case '\r': + continue; + default: + return FALSE; + } + } + + return TRUE; +} + +static void +_text_cb (GMarkupParseContext *context, + const gchar *text, + gsize text_len, + gpointer user_data, + GError **error) +{ + XMLNode *p = (XMLNode *)user_data; + + if (_is_space (text, text_len)) { + return; + } + + if (p->sub_nodes || p->text) { + g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT, " "); + return; + } + + p->text = g_strndup (text, text_len); +} + +static GMarkupParser parser = { + _start_element_cb, + _end_element_cb, + _text_cb, + 0, + 0, +}; + +XMLNode * +xml_parse_file (const gchar *filename) +{ + gboolean retval = FALSE; + GError *error = NULL; + FILE *pf = fopen (filename, "r"); + + if (pf == NULL) { + return NULL; + } + + GMarkupParseContext *context; + XMLNode *node; + + const static GMarkupParser root_parser = { + _start_root_element_cb, + _end_element_cb, + _text_cb, + 0, + 0, + }; + + do { + context = g_markup_parse_context_new (&root_parser, 0, &node, 0); + + while (!feof (pf)) { + gchar buf[1024]; + gssize len = 0; + + len = fread (buf, 1, sizeof (buf), pf); + retval = g_markup_parse_context_parse (context, buf, len, &error); + + if (!retval) + break; + } + fclose (pf); + + if (!retval) + break; + + retval = g_markup_parse_context_end_parse (context, &error); + if (!retval) + break; + + g_markup_parse_context_free (context); + + return node; + } while (0); + + g_warning ("Parse %s failed: %s", filename, error->message); + g_error_free (error); + g_markup_parse_context_free (context); + return NULL; +} + +XMLNode * +xml_parse_buffer (const gchar *buffer) +{ + gboolean retval; + GError *error = NULL; + + GMarkupParseContext *context; + XMLNode *node; + + const static GMarkupParser root_parser = { + _start_root_element_cb, + _end_element_cb, + _text_cb, + 0, + 0, + }; + + context = g_markup_parse_context_new (&root_parser, 0, &node, 0); + + do { + retval = g_markup_parse_context_parse (context, buffer, strlen (buffer), &error); + if (!retval) + break; + + retval = g_markup_parse_context_end_parse (context, &error); + if (!retval) + break; + g_markup_parse_context_free (context); + return node; + } while (0); + + g_warning ("Parse buffer failed: %s", error->message); + g_error_free (error); + g_markup_parse_context_free (context); + return NULL; +} + + +static void +output_indent (int level, GString *output) +{ + gint i; + for (i = 0; i < level; i++) { + g_string_append (output, " "); + } +} + +static void +xml_output_indent (const XMLNode *node, int level, GString *output) +{ + gchar **attrs; + + output_indent (level, output); + g_string_append_printf (output, "<%s", node->name); + + attrs = node->attributes; + + while (attrs != NULL && *attrs != NULL) { + g_string_append_printf (output, " %s", *(attrs++)); + g_string_append_printf (output, "=\"%s\"", *(attrs++)); + } + + if (node->sub_nodes != NULL){ + g_string_append (output, ">\n"); + GList *sub_node; + + for (sub_node = node->sub_nodes; sub_node != NULL; sub_node = sub_node->next) { + xml_output_indent (sub_node->data, level + 1, output); + } + output_indent (level, output); + g_string_append_printf (output, "\n",node->name); + } + else if (node->text != NULL) { + gchar *text = g_markup_escape_text (node->text, -1); + g_string_append_printf (output, ">%s\n", text, node->name); + g_free (text); + } + else { + g_string_append (output, "/>\n"); + } +} + +void +xml_output (const XMLNode *node, GString *output) +{ + xml_output_indent (node, 0, output); +} + diff --git a/saedit/xml.h b/saedit/xml.h index cf76795..4030d72 100644 --- a/saedit/xml.h +++ b/saedit/xml.h @@ -11,14 +11,31 @@ #ifndef XML_H #define XML_H +#include #include -#include #include "common.h" -gchar **xml_attr_new(const gchar *name, const gchar *value); -gchar *xml_node_get_attr_value(const XMLNode *node, const gchar *attr_name); -gint xml_node_compare_with_name_func(gconstpointer a, gconstpointer b); -gint xml_node_compare_with_action_node_by_imageset_name_func(gconstpointer a, gconstpointer b); -gint xml_node_compare_with_attr_func(const XMLNode *node, const gchar **attr); +typedef struct { + gchar *name; + gchar *text; + gchar **attributes; + GList *sub_nodes; +} XMLNode; + + +XMLNode *xml_parse_file (const gchar *name); + +XMLNode *xml_parse_buffer (const gchar *buffer); + +void xml_free (XMLNode *node); + +void xml_output (const XMLNode *node, + GString *output); + +gchar **xml_attr_new(const gchar *name, const gchar *value); +gchar *xml_node_get_attr_value(const XMLNode *node, const gchar *attr_name); +gint xml_node_compare_with_name_func(gconstpointer a, gconstpointer b); +gint xml_node_compare_with_action_node_by_imageset_name_func(gconstpointer a, gconstpointer b); +gint xml_node_compare_with_attr_func(const XMLNode *node, const gchar **attr); #endif -- cgit v1.2.3-70-g09d2