grim/gplate

197c6e92dcdd
Parents 909d3cc49f66
Children 4464c1a04980
Default tags are working again
renamed fall_through tags to default tags.
Check passes with 100% now
--- a/gplate/gplate-errors.h Sun Feb 10 10:57:11 2008 -0600
+++ b/gplate/gplate-errors.h Sun Feb 10 22:14:32 2008 -0600
@@ -27,20 +27,18 @@
GPLATE_ERROR_TYPE_IS_NOT_DESCENDANT = 100,
GPLATE_ERROR_TYPE_IS_ABSTRACT,
- GPLATE_ERROR_TAG_EXISTS = 210,
- GPLATE_ERROR_TAG_FALL_THROUGH_EXISTS,
- GPLATE_ERROR_TAG_NO_PREFIX_HAVE_SUFFIX = 220,
- GPLATE_ERROR_TAG_HAVE_PREFIX_NO_SUFFIX,
+ GPLATE_ERROR_TEMPLATE_FILE_DOES_NOT_EXIST = 200,
- GPLATE_ERROR_TEMPLATE_FILE_DOES_NOT_EXIST = 300,
-
- GPLATE_ERROR_LIBRARY_FUNCTION_NAME_EXISTS = 400,
+ GPLATE_ERROR_LIBRARY_FUNCTION_NAME_EXISTS = 300,
GPLATE_ERROR_LIBRARY_FUNCTION_NAME_NOT_FOUND,
GPLATE_ERROR_LIBRARY_FUNCTION_BOUND,
GPLATE_ERROR_LIBRARY_FUNCTION_NOT_BOUND,
GPLATE_ERROR_LIBRARY_FUNCTION_NOT_BOUND_TO_TAG,
- GPLATE_ERROR_LIBRARY_TAG_EXISTS = 450,
+ GPLATE_ERROR_LIBRARY_TAG_EXISTS = 350,
GPLATE_ERROR_LIBRARY_TAG_NOT_FOUND,
+ GPLATE_ERROR_LIBRARY_TAG_NO_PREFIX_HAVE_SUFFIX,
+ GPLATE_ERROR_LIBRARY_TAG_HAVE_PREFIX_NO_SUFFIX,
+ GPLATE_ERROR_LIBRARY_DEFAULT_TAG_REGISTERED = 360,
GPLATE_ERROR_UNKNOWN = 1 << 31,
} GPlateErrors;
--- a/gplate/gplate-library.c Sun Feb 10 10:57:11 2008 -0600
+++ b/gplate/gplate-library.c Sun Feb 10 22:14:32 2008 -0600
@@ -43,6 +43,7 @@
*****************************************************************************/
static GHashTable *functions = NULL;
static GHashTable *tags = NULL;
+static GType default_tag = G_TYPE_INVALID;
/******************************************************************************
* GPlateFunctionData API
@@ -66,7 +67,7 @@
* GPlateTagData API
*****************************************************************************/
static GPlateTagData *
-gplate_tag_data_new(GType tag) {
+gplate_tag_data_new(GType tag, GError **error) {
GPlateTagData *data = NULL;
GPlateTagClass *klass = NULL;
const gchar *prefix = NULL, *suffix = NULL;
@@ -75,6 +76,47 @@
prefix = gplate_tag_class_get_prefix(klass);
suffix = gplate_tag_class_get_suffix(klass);
+ if(!prefix && suffix) {
+ if(error) {
+ *error =
+ g_error_new(GPLATE_DOMAIN,
+ GPLATE_ERROR_LIBRARY_TAG_NO_PREFIX_HAVE_SUFFIX,
+ "tag '%s' does not have a prefix, but has a "
+ "suffix.",
+ g_type_name(tag));
+ }
+
+ return NULL;
+ } else if(prefix && !suffix) {
+ if(error) {
+ *error =
+ g_error_new(GPLATE_DOMAIN,
+ GPLATE_ERROR_LIBRARY_TAG_HAVE_PREFIX_NO_SUFFIX,
+ "tag '%s' has a prefix, but does not have a "
+ "suffix.",
+ g_type_name(tag));
+ }
+
+ return NULL;
+ }
+
+ if(!prefix && !suffix) {
+ if(default_tag != G_TYPE_INVALID) {
+ if(error) {
+ *error =
+ g_error_new(GPLATE_DOMAIN,
+ GPLATE_ERROR_LIBRARY_DEFAULT_TAG_REGISTERED,
+ "A default tag named '%s' has already been "
+ "registered.",
+ g_type_name(default_tag));
+ }
+
+ return NULL;
+ } else {
+ default_tag = tag;
+ }
+ }
+
data = g_new(GPlateTagData, 1);
data->tag = tag;
@@ -250,7 +292,9 @@
return FALSE;
}
- data = gplate_tag_data_new(tag);
+ data = gplate_tag_data_new(tag, error);
+ if(!data)
+ return FALSE;
g_hash_table_insert(tags, GSIZE_TO_POINTER(data->tag), data);
@@ -542,6 +586,22 @@
return TRUE;
}
+/**
+ * gplate_library_get_default_tag:
+ *
+ * Gets the default tag if one has been registered.
+ *
+ * A default tag is one that does not have a prefix or a suffix. It is used
+ * when no other tags match.
+ *
+ * Return Value: The default tag if one has been registered, otherwise
+ * #G_TYPE_INVALID.
+ */
+GType
+gplate_library_get_default_tag(void) {
+ return default_tag;
+}
+
/******************************************************************************
* For each stuff
*****************************************************************************/
--- a/gplate/gplate-library.h Sun Feb 10 10:57:11 2008 -0600
+++ b/gplate/gplate-library.h Sun Feb 10 22:14:32 2008 -0600
@@ -43,6 +43,7 @@
GType gplate_library_lookup_function_for_tag(const gchar *name, GType tag, GError **error);
gboolean gplate_library_lookup_tag(GType tag, gchar **prefix, gchar **suffix, GError **error);
+GType gplate_library_get_default_tag(void);
void gplate_library_tags_foreach(GPlateLibraryTagsForeachFunc func, gpointer data);
G_END_DECLS
--- a/gplate/gplate-template.c Sun Feb 10 10:57:11 2008 -0600
+++ b/gplate/gplate-template.c Sun Feb 10 22:14:32 2008 -0600
@@ -40,8 +40,6 @@
* Structs
*****************************************************************************/
typedef struct {
- GType fall_through;
-
gchar *pattern;
GPlateVariable *vars;
@@ -151,7 +149,6 @@
static GType
gplate_template_find_tag(GPlateTemplate *tplate, const gchar *contents) {
- GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(tplate);
GPlateTemplateFindTagData d;
d.contents = contents;
@@ -159,7 +156,10 @@
gplate_library_tags_foreach(gplate_template_find_tag_helper, &d);
- return (d.type == G_TYPE_INVALID) ? priv->fall_through : d.type;
+ if(d.type == G_TYPE_INVALID)
+ d.type = gplate_library_get_default_tag();
+
+ return d.type;
}
static GList *
@@ -192,7 +192,7 @@
type = gplate_template_find_tag(tplate, matches[i]);
if(!gplate_library_lookup_tag(type, &prefix, &suffix, error))
- break;
+ continue;
if(!prefix && !suffix) {
/* it's a fall through tag */
@@ -291,8 +291,6 @@
gplate_template_init(GTypeInstance *self, gpointer klass) {
GPlateTemplatePrivate *priv = GPLATE_TEMPLATE_GET_PRIVATE(self);
- priv->fall_through = G_TYPE_INVALID;
-
priv->pattern = NULL;
priv->vars = gplate_dictionary_variable_new("dict");