A ton of updates that aparently don't work... will look into this more tomorrow, now, must sleep
--- a/gplate/Makefile.am Tue Feb 19 03:26:49 2008 -0600
+++ b/gplate/Makefile.am Tue Feb 19 05:05:32 2008 -0600
@@ -21,6 +21,7 @@
@@ -40,6 +41,7 @@
--- a/gplate/gplate-errors.h Tue Feb 19 03:26:49 2008 -0600
+++ b/gplate/gplate-errors.h Tue Feb 19 05:05:32 2008 -0600
@@ -27,7 +27,7 @@
GPLATE_ERROR_TYPE_IS_NOT_DESCENDANT = 100,
GPLATE_ERROR_TYPE_IS_ABSTRACT,
- GPLATE_ERROR_TEMPLATE_FILE_DOES_NOT_EXIST = 200,
+ GPLATE_ERROR_UTIL_FILE_DOES_NOT_EXIST = 200, GPLATE_ERROR_LIBRARY_FUNCTION_NAME_EXISTS = 300,
GPLATE_ERROR_LIBRARY_FUNCTION_NAME_NOT_FOUND,
@@ -49,4 +49,4 @@
+#endif /* GPLATE_ERRORS_H */ --- a/gplate/gplate-include-function.c Tue Feb 19 03:26:49 2008 -0600
+++ b/gplate/gplate-include-function.c Tue Feb 19 05:05:32 2008 -0600
@@ -23,11 +23,25 @@
#include <gplate/gplate-include-function.h>
#include <gplate/gplate-collection.h>
+#include <gplate/gplate-util.h> #include <gplate/gplate-variable.h>
/******************************************************************************
*****************************************************************************/
+gplate_include_function_common(GPlateTemplate *tplate, const gchar *filename) { + gchar *contents = NULL; + if(gplate_util_read_file(filename, &contents, NULL, NULL)) { + GList *tokens = gplate_template_tokenize(tplate, contents, NULL); + gplate_template_insert_tags(tplate, tokens); gplate_include_function_evaluate(GPlateFunction *function,
@@ -35,14 +49,13 @@
regex = g_regex_new("\"(.+)\"", 0, 0, NULL);
if(g_regex_match(regex, contents, 0, &info)) {
gchar *file = g_match_info_fetch(info, 1);
- ret = gplate_template_render_file(tplate, file, NULL);
+ gplate_include_function_common(tplate, file); @@ -53,17 +66,18 @@
if(GPLATE_IS_VARIABLE(variable)) {
- const gchar *value = gplate_variable_get_value(variable);
+ const gchar *file = gplate_variable_get_value(variable); - ret = gplate_template_render_file(tplate, value, NULL);
+ gplate_include_function_common(tplate, file); g_object_unref(G_OBJECT(variable));
+ /* we always return an empty string since we just add our tags to the /******************************************************************************
--- a/gplate/gplate-template.c Tue Feb 19 03:26:49 2008 -0600
+++ b/gplate/gplate-template.c Tue Feb 19 05:05:32 2008 -0600
@@ -26,6 +26,7 @@
#include <gplate/gplate-dictionary-variable.h>
#include <gplate/gplate-errors.h>
#include <gplate/gplate-library.h>
+#include <gplate/gplate-util.h> @@ -356,6 +357,44 @@
+gplate_template_real_insert_tags(GPlateTemplate *tplate, GList *tags) { + GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate); + /* check if our current node is valid */ + if(!priv->current_token) { + /* check if we have a list of tokens */ + /* no existing tokens, set it to tags and exit */ + /* we have tokens, but we've read the last one, move back to the + priv->tokens = g_list_concat(priv->tokens, tags); + /* we have a valid node selected, save it's next node */ + tmp = priv->current_token->next; + /* now mangle current and the first node in tags to shove tags in */ + priv->current_token->next = tags; + tags->prev = priv->current_token; + /* if the original next node is valid, we need to put them back into + GList *last = g_list_last(tags); /******************************************************************************
*****************************************************************************/
@@ -392,6 +431,8 @@
klass->previous_tag = gplate_template_real_previous_tag;
klass->nth_tag = gplate_template_real_nth_tag;
klass->nth_previous_tag = gplate_template_real_nth_previous_tag;
+ klass->insert_tags = gplate_template_real_insert_tags; @@ -629,19 +670,7 @@
g_return_val_if_fail(GPLATE_IS_TEMPLATE(tplate), NULL);
g_return_val_if_fail(filename, NULL);
- if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
- g_error_new(GPLATE_DOMAIN,
- GPLATE_ERROR_TEMPLATE_FILE_DOES_NOT_EXIST,
- "File '%s' does not exist.\n",
- if(!g_file_get_contents(filename, &contents, NULL, error))
+ if(!gplate_util_read_file(filename, &contents, NULL, error)) ret = gplate_template_render(tplate, contents, error);
@@ -807,3 +836,22 @@
+ * gplate_template_insert_tags: + * @tplate: The #GPlateTemplate. + * @tags: A #GList of #GPlateTag's to insert. + * Inserts @tags after the current tag in @tplate's stack. +gplate_template_insert_tags(GPlateTemplate *tplate, GList *tags) { + GPlateTemplateClass *klass = NULL; + g_return_if_fail(GPLATE_IS_TEMPLATE(tplate)); + g_return_if_fail(tags); + klass = GPLATE_TEMPLATE_GET_CLASS(tplate); + if(klass && klass->insert_tags) + klass->insert_tags(tplate, tags); --- a/gplate/gplate-template.h Tue Feb 19 03:26:49 2008 -0600
+++ b/gplate/gplate-template.h Tue Feb 19 05:05:32 2008 -0600
@@ -56,6 +56,8 @@
GPlateTag *(*previous_tag)(GPlateTemplate *tplate);
GPlateTag *(*nth_tag)(GPlateTemplate *tplate, guint nth);
GPlateTag *(*nth_previous_tag)(GPlateTemplate *tplate, guint nth);
+ void (*insert_tags)(GPlateTemplate *tplate, GList *tags); void (*_gplate_reserved1)(void);
void (*_gplate_reserved2)(void);
@@ -82,6 +84,8 @@
GPlateTag *gplate_template_nth_tag(GPlateTemplate *tplate, guint nth);
GPlateTag *gplate_template_nth_previous_tag(GPlateTemplate *tplate, guint nth);
+void gplate_template_insert_tags(GPlateTemplate *tplate, GList *tags); #endif /* GPLATE_TEMPLATE_H */
--- a/tests/Makefile.am Tue Feb 19 03:26:49 2008 -0600
+++ b/tests/Makefile.am Tue Feb 19 05:05:32 2008 -0600
@@ -23,6 +23,7 @@
--- a/tests/templates/Makefile.am Tue Feb 19 03:26:49 2008 -0600
+++ b/tests/templates/Makefile.am Tue Feb 19 05:05:32 2008 -0600
@@ -1,4 +1,4 @@
--- a/tests/templates/include1.gplate Tue Feb 19 03:26:49 2008 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,4 +0,0 @@
-{% include "include2.gplate" %}
--- a/tests/templates/include2.gplate Tue Feb 19 03:26:49 2008 -0600
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-inside the included file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/templates/simple-include.gplate Tue Feb 19 05:05:32 2008 -0600
@@ -0,0 +1,1 @@
+inside the included file --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/templates/simple.gplate Tue Feb 19 05:05:32 2008 -0600
@@ -0,0 +1,4 @@
+{% include "templates/simple-include.gplate" %} --- a/tests/test.c Tue Feb 19 03:26:49 2008 -0600
+++ b/tests/test.c Tue Feb 19 05:05:32 2008 -0600
@@ -31,6 +31,8 @@
srunner_add_suite(sr, syntax_suite());
srunner_add_suite(sr, variable_suite());
+ srunner_add_suite(sr, include_suite()); srunner_run_all(sr, CK_NORMAL);
nfail = srunner_ntests_failed(sr);
--- a/tests/test.h Tue Feb 19 03:26:49 2008 -0600
+++ b/tests/test.h Tue Feb 19 05:05:32 2008 -0600
@@ -9,6 +9,7 @@
Suite *syntax_suite(void);
Suite *variable_suite(void);
+Suite *include_suite(void);