Index: update-mime-database.c =================================================================== RCS file: /cvs/mime/shared-mime-info/update-mime-database.c,v retrieving revision 1.30 diff -u -p -r1.30 update-mime-database.c --- update-mime-database.c 13 Oct 2003 09:43:38 -0000 1.30 +++ update-mime-database.c 11 Sep 2004 06:27:48 -0000 @@ -94,6 +94,9 @@ static GHashTable *globs_hash = NULL; /* 'magic' nodes */ static GPtrArray *magic_array = NULL; +/* Maps MIME type names to superclass names */ +static GHashTable *subclass_hash = NULL; + /* Static prototypes */ static Magic *magic_new(xmlNode *node, Type *type, GError **error); @@ -245,6 +248,17 @@ static void add_namespace(Type *type, co type); } +static void +insert_subclass (gchar *type, gchar *parent) +{ + GSList *list, *nlist; + + list = g_hash_table_lookup (subclass_hash, type); + nlist = g_slist_append (list, g_strdup (parent)); + if (list == NULL) + g_hash_table_insert(subclass_hash, g_strdup (type), nlist); +} + /* 'field' was found in the definition of 'type' and has the freedesktop.org * namespace. If it's a known field, process it and return TRUE, else * return FALSE to add it to the output XML document. @@ -297,10 +311,23 @@ static gboolean process_freedesktop_node gboolean valid; other_type = xmlGetNsProp(field, "type", NULL); valid = other_type && strchr(other_type, '/'); - xmlFree(other_type); if (valid) - return FALSE; /* Copy through */ + { + char *typename; + typename = g_strdup_printf("%s/%s", + type->media, + type->subtype); + insert_subclass(typename, other_type); + if (strcmp(field->name, "alias") == 0) + insert_subclass(other_type, typename); + g_free(typename); + xmlFree(other_type); + + return FALSE; /* Copy through */ + } + + xmlFree(other_type); g_set_error(error, MIME_ERROR, 0, _("Incorrect or missing 'type' attribute " "in <%s>"), field->name); @@ -1310,6 +1337,27 @@ static void write_namespaces(FILE *strea g_ptr_array_free(lines, TRUE); } +static void write_subclass(gpointer key, gpointer value, gpointer data) +{ + GSList *list = value; + FILE *stream = data; + GSList *l; + char *line; + + for (l = list; l; l = l->next) + { + line = g_strconcat (key, ":", l->data, "\n", NULL); + fwrite(line, 1, strlen(line), stream); + g_free (line); + } +} + +/* Write all the collected subclass information to 'subclasses' */ +static void write_subclasses(FILE *stream) +{ + g_hash_table_foreach(subclass_hash, write_subclass, stream); +} + /* Issue a warning if 'path' won't be found by applications */ static void check_in_path_xdg_data(const char *mime_path) { @@ -1371,6 +1419,15 @@ out: g_free(path); } +static void +free_string_list (gpointer data) +{ + GSList *list = data; + + g_slist_foreach (list, g_free, NULL); + g_slist_free (list); +} + int main(int argc, char **argv) { char *mime_dir = NULL; @@ -1442,7 +1499,9 @@ int main(int argc, char **argv) namespace_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); magic_array = g_ptr_array_new(); - + subclass_hash = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, free_string_list); + scan_source_dir(package_dir); g_free(package_dir); @@ -1494,7 +1553,7 @@ int main(int argc, char **argv) atomic_update(magic_path); g_free(magic_path); } - + { FILE *stream; char *ns_path; @@ -1510,12 +1569,30 @@ int main(int argc, char **argv) atomic_update(ns_path); g_free(ns_path); } + + { + FILE *stream; + char *path; + + path = g_strconcat(mime_dir, "/subclasses.new", NULL); + stream = fopen(path, "wb"); + if (!stream) + g_error("Failed to open '%s' for writing\n", + path); + + write_subclasses(stream); + + atomic_update(path); + g_free(path); + } + g_ptr_array_free(magic_array, TRUE); g_hash_table_destroy(types); g_hash_table_destroy(globs_hash); g_hash_table_destroy(namespace_hash); + g_hash_table_destroy(subclass_hash); g_print("***\n"); Index: shared-mime-info-spec.xml =================================================================== RCS file: /cvs/mime/shared-mime-info/shared-mime-info-spec.xml,v retrieving revision 1.53 diff -u -p -r1.53 shared-mime-info-spec.xml --- shared-mime-info-spec.xml 11 May 2004 10:33:33 -0000 1.53 +++ shared-mime-info-spec.xml 11 Sep 2004 06:27:48 -0000 @@ -165,6 +165,9 @@ The files created by update-mim <MIME>/magic (contains a mapping from file contents to MIME types) +<MIME>/subclasses (contains a mapping from MIME types to types they inherit from or alias with) + + <MIME>/XMLnamespaces (contains a mapping from XML (namespaceURI, localName) pairs to MIME types)