summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Untz <vuntz@gnome.org>2008-04-26 17:51:30 +0000
committerVincent Untz <vuntz@gnome.org>2008-04-26 17:51:30 +0000
commit3425eaf5d0e55c4e1c853f6af6e846c7763ba48a (patch)
tree6e8a743e9412d4cf3fe489a553b9af5e1e5720a8
parent834fdc1f65043704962dcf26b9aa5194338eec91 (diff)
check that the Comment does not look like the Name of the GenericName
2008-04-26 Vincent Untz <vuntz@gnome.org> * src/validate.c: (handle_comment_key): check that the Comment does not look like the Name of the GenericName (validate_keys_for_current_group): instead of storing only the information that a group contain a key, also link to the content of the key. Also report the error of multiple keys with the same name the first time we have a key (instead of the second time). Plug a small leak.
-rw-r--r--ChangeLog10
-rw-r--r--src/validate.c59
2 files changed, 61 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 6e17f6f..e36bc57 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2008-04-26 Vincent Untz <vuntz@gnome.org>
+ * src/validate.c: (handle_comment_key): check that the Comment does not
+ look like the Name of the GenericName
+ (validate_keys_for_current_group): instead of storing only the
+ information that a group contain a key, also link to the content of the
+ key. Also report the error of multiple keys with the same name the
+ first time we have a key (instead of the second time).
+ Plug a small leak.
+
+2008-04-26 Vincent Untz <vuntz@gnome.org>
+
* src/validate.c: make a few more structure static, change the way we
store data about the know catgories so that we have more information
(like dependencies)
diff --git a/src/validate.c b/src/validate.c
index 8d3da29..d1fd959 100644
--- a/src/validate.c
+++ b/src/validate.c
@@ -803,13 +803,42 @@ handle_version_key (kf_validator *kf,
/* + Tooltip for the entry, for example "View sites on the Internet", should
* not be redundant with Name or GenericName.
- * FIXME
+ * Checked.
*/
static gboolean
handle_comment_key (kf_validator *kf,
const char *locale_key,
const char *value)
{
+ char *locale_compare_key;
+ kf_keyvalue *keyvalue;
+
+ locale_compare_key = g_strdup_printf ("Name%s",
+ locale_key + strlen ("Comment"));
+ keyvalue = g_hash_table_lookup (kf->current_keys, locale_compare_key);
+ g_free (locale_compare_key);
+
+ if (keyvalue && g_ascii_strcasecmp (value, keyvalue->value) == 0) {
+ print_warning (kf, "value \"%s\" for key \"%s\" in group \"%s\" "
+ "looks redundant with value \"%s\" of key \"%s\"\n",
+ value, locale_key, kf->current_group,
+ keyvalue->value, keyvalue->key);
+ return FALSE;
+ }
+
+ locale_compare_key = g_strdup_printf ("GenericName%s",
+ locale_key + strlen ("Comment"));
+ keyvalue = g_hash_table_lookup (kf->current_keys, locale_compare_key);
+ g_free (locale_compare_key);
+
+ if (keyvalue && g_ascii_strcasecmp (value, keyvalue->value) == 0) {
+ print_warning (kf, "value \"%s\" for key \"%s\" in group \"%s\" "
+ "looks redundant with value \"%s\" of key \"%s\"\n",
+ value, locale_key, kf->current_group,
+ keyvalue->value, keyvalue->key);
+ return FALSE;
+ }
+
return TRUE;
}
@@ -1691,10 +1720,12 @@ validate_keys_for_current_group (kf_validator *kf)
{
gboolean desktop_group;
gboolean retval;
+ GHashTable *duplicated_keys_hash;
char *key;
char *locale;
GSList *keys;
GSList *sl;
+ gpointer hashvalue;
retval = TRUE;
@@ -1708,6 +1739,8 @@ validate_keys_for_current_group (kf_validator *kf)
kf->current_keys = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, NULL);
+ duplicated_keys_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
+ NULL, NULL);
/* we need two passes: some checks are looking if another key exists in the
* group */
@@ -1715,13 +1748,23 @@ validate_keys_for_current_group (kf_validator *kf)
kf_keyvalue *keyvalue;
keyvalue = (kf_keyvalue *) sl->data;
- g_hash_table_insert (kf->current_keys, keyvalue->key, GINT_TO_POINTER (1));
+ g_hash_table_insert (kf->current_keys, keyvalue->key, keyvalue);
+
+ /* we could display the error about duplicate keys here, but it's better
+ * to display it with the first occurence of this key */
+ hashvalue = g_hash_table_lookup (duplicated_keys_hash, keyvalue->key);
+ if (!hashvalue)
+ g_hash_table_insert (duplicated_keys_hash, keyvalue->key,
+ GINT_TO_POINTER (1));
+ else {
+ g_hash_table_replace (duplicated_keys_hash, keyvalue->key,
+ GINT_TO_POINTER (GPOINTER_TO_INT (hashvalue) + 1));
+ }
}
for (sl = keys; sl != NULL; sl = sl->next) {
kf_keyvalue *keyvalue;
gboolean skip_desktop_check;
- gpointer hashvalue;
keyvalue = (kf_keyvalue *) sl->data;
@@ -1740,14 +1783,12 @@ validate_keys_for_current_group (kf_validator *kf)
g_assert (key != NULL);
- hashvalue = g_hash_table_lookup (kf->current_keys, keyvalue->key);
- if (GPOINTER_TO_INT (hashvalue) != 1) {
+ hashvalue = g_hash_table_lookup (duplicated_keys_hash, keyvalue->key);
+ if (GPOINTER_TO_INT (hashvalue) > 1) {
+ g_hash_table_remove (duplicated_keys_hash, keyvalue->key);
print_fatal (kf, "file contains multiple keys named \"%s\" in "
"group \"%s\"\n", keyvalue->key, kf->current_group);
retval = FALSE;
- } else {
- g_hash_table_replace (kf->current_keys, keyvalue->key,
- GINT_TO_POINTER (2));
}
if (desktop_group && !skip_desktop_check) {
@@ -1762,6 +1803,8 @@ validate_keys_for_current_group (kf_validator *kf)
locale = NULL;
}
+ g_slist_free (keys);
+ g_hash_table_destroy (duplicated_keys_hash);
g_hash_table_destroy (kf->current_keys);
kf->current_keys = NULL;