Commit 000d3a56 authored by Alexander Larsson's avatar Alexander Larsson
Browse files

2009-10-02 Alexander Larsson <alexl@redhat.com>

	Based on patch from David Faure <faure@kde.org>

	* shared-mime-info-spec.xml: Define new case-sensitive attribute, and
	change the text from the two-step glob match to a single glob match,
	that is either case sensitive or case insensitive. Add flags field to
	globs2 file, define the "cs" flag.

	* freedesktop.org.xml.in:
	Make core, *.c and *.C case sensitive  (Closes: #22634)

	* update-mime-database.c:
	Process case-sensitive flag, write it out in globs2 and mime.cache

	* tests/list:
	Mark as expected success the previously problematic
	case sensitive issues.
parent 400a511c
2009-10-02 Alexander Larsson <alexl@redhat.com>
Based on patch from David Faure <faure@kde.org>
* shared-mime-info-spec.xml: Define new case-sensitive attribute, and
change the text from the two-step glob match to a single glob match,
that is either case sensitive or case insensitive. Add flags field to
globs2 file, define the "cs" flag.
* freedesktop.org.xml.in:
Make core, *.c and *.C case sensitive (Closes: #22634)
* update-mime-database.c:
Process case-sensitive flag, write it out in globs2 and mime.cache
* tests/list:
Mark as expected success the previously problematic
case sensitive issues.
2009-09-30 Bastien Nocera <hadess@hadess.net>
* freedesktop.org.xml.in: Fix "make check" problem for MRML.
......
......@@ -26,6 +26,7 @@
<!ELEMENT glob EMPTY>
<!ATTLIST glob pattern CDATA #REQUIRED>
<!ATTLIST glob weight CDATA #IMPLIED>
<!ATTLIST glob case-sensitive CDATA #IMPLIED>
<!ELEMENT magic (match)+>
<!ATTLIST magic priority CDATA #IMPLIED>
......@@ -1268,7 +1269,7 @@ command to generate the output files.
<match type="string" value="Core\001" offset="0"/>
<match type="string" value="Core\002" offset="0"/>
</magic>
<glob pattern="core"/>
<glob pattern="core" case-sensitive="true"/>
</mime-type>
<mime-type type="application/x-cpio">
<_comment>CPIO archive</_comment>
......@@ -4306,7 +4307,7 @@ command to generate the output files.
<glob pattern="*.cpp"/>
<glob pattern="*.cxx"/>
<glob pattern="*.cc"/>
<glob pattern="*.C"/>
<glob pattern="*.C" case-sensitive="true"/>
<glob pattern="*.c++"/>
</mime-type>
<mime-type type="text/x-changelog">
......@@ -4345,7 +4346,7 @@ command to generate the output files.
<_comment>C source code</_comment>
<sub-class-of type="text/plain"/>
<alias type="text/x-c"/>
<glob pattern="*.c"/>
<glob pattern="*.c" case-sensitive="true"/>
<magic priority="30">
<match type="string" value="/*" offset="0"/>
<match type="string" value="//" offset="0"/>
......
......@@ -456,6 +456,7 @@ For example:
...
55:text/x-diff:*.patch
50:text/x-diff:*.diff
50:text/x-c++src:*.C:cs
...
]]></programlisting>
</para>
......@@ -474,9 +475,9 @@ text/x-diff:*.diff
]]></programlisting>
</para>
<para>
Applications MUST first try a case-sensitive match, then try again with the
filename converted to lower-case if that fails.
This is so that <filename>main.C</filename> will be seen as a C++ file,
Applications MUST match globs case-insensitively, except when the case-sensitive attribute
is set to true.
This is so that e.g. <filename>main.C</filename> will be seen as a C++ file,
but <filename>IMAGE.GIF</filename> will still use the *.gif pattern.
</para>
<para>
......@@ -531,6 +532,16 @@ Group's package, which MUST be required by all applications using this
specification. Since each application will then only be providing information
about its own types, conflicts should be rare.
</para>
<para>
The fourth field ("cs" in the first globs2 example) contains a list of comma-separated flags.
The flags currently defined are: cs (for case-sensitive). Implementations should ignore
unknown flags.
</para>
<para>
Implementations should also ignore further fields, so that the syntax of the globs2 file
can be extended in the future. Example: "50:text/x-c++src:*.C:cs,newflag:newfeature:somethingelse"
should currently be parsed as "50:text/x-c++src:*.C:cs".
</para>
</sect2>
<sect2>
<title>The magic files</title>
......@@ -683,8 +694,8 @@ mmappable format:
</para>
<programlisting>
Header:
2 CARD16 MAJOR_VERSION 1
2 CARD16 MINOR_VERSION 1
2 CARD16 MAJOR_VERSION 1
2 CARD16 MINOR_VERSION 2
4 CARD32 ALIAS_LIST_OFFSET
4 CARD32 PARENT_LIST_OFFSET
4 CARD32 LITERAL_LIST_OFFSET
......@@ -722,7 +733,10 @@ LiteralList:
LiteralEntry:
4 CARD32 LITERAL_OFFSET
4 CARD32 MIME_TYPE_OFFSET
4 CARD32 WEIGHT
4 CARD32 WEIGHT in lower 8 bits
FLAGS in rest:
0x100 = case-sensitive
GlobList:
4 CARD32 N_GLOBS
......@@ -731,7 +745,9 @@ GlobList:
GlobEntry:
4 CARD32 GLOB_OFFSET
4 CARD32 MIME_TYPE_OFFSET
4 CARD32 WEIGHT
4 CARD32 WEIGHT in lower 8 bits
FLAGS in rest:
0x100 = case-sensitive
ReverseSuffixTree:
4 CARD32 N_ROOTS
......@@ -745,7 +761,9 @@ ReverseSuffixTreeNode:
ReverseSuffixTreeLeafNode:
4 CARD32 0
4 CARD32 MIME_TYPE_OFFSET
4 CARD32 WEIGHT
4 CARD32 WEIGHT in lower 8 bits
FLAGS in rest:
0x100 = case-sensitive
MagicList:
4 CARD32 N_MATCHES
......
......@@ -206,7 +206,7 @@ googleearth.kml application/vnd.google-earth.kml+xml ox
test.gnd application/gnunet-directory
text.ps application/postscript
text.ps.gz application/x-gzpostscript ox
text.PS.gz application/x-gzpostscript xxx
text.PS.gz application/x-gzpostscript oxo
test.cmake text/x-cmake ox
bluerect.mdi image/vnd.ms-modi
Stallman_Richard_-_The_GNU_Manifesto.fb2 application/x-fictionbook+xml
......
......@@ -94,6 +94,7 @@ struct _Glob {
char *pattern;
Type *type;
gboolean noglob;
gboolean case_sensitive;
};
struct _Magic {
......@@ -307,6 +308,24 @@ static int get_weight(xmlNode *node)
return get_int_attribute (node, "weight");
}
/* Return the value of a false/true attribute, which defaults to false.
* Returns 0 or 1.
*/
static gboolean get_boolean_attribute(xmlNode *node, const char* name)
{
char *attr;
attr = my_xmlGetNsProp(node, name, NULL);
if (attr)
{
if (strcmp (attr, "true") == 0)
{
return TRUE;
}
xmlFree(attr);
}
return FALSE;
}
/* Process a <root-XML> element by adding a rule to namespace_hash */
static void add_namespace(Type *type, const char *namespaceURI,
const char *localName, GError **error)
......@@ -363,8 +382,10 @@ static gboolean process_freedesktop_node(Type *type, xmlNode *field,
{
gchar *pattern;
gint weight;
gboolean case_sensitive;
weight = get_weight(field);
case_sensitive = get_boolean_attribute(field, "case-sensitive");
if (weight == -1)
{
......@@ -382,6 +403,7 @@ static gboolean process_freedesktop_node(Type *type, xmlNode *field,
glob->pattern = g_strdup (pattern);
glob->type = type;
glob->weight = weight;
glob->case_sensitive = case_sensitive;
list = g_list_append (list, glob);
g_hash_table_insert(globs_hash, g_strdup (glob->pattern), list);
xmlFree(pattern);
......@@ -406,6 +428,7 @@ static gboolean process_freedesktop_node(Type *type, xmlNode *field,
glob->type = type;
glob->weight = 0;
glob->noglob = TRUE;
glob->case_sensitive = FALSE;
list = g_list_append (list, glob);
g_hash_table_insert(globs_hash, g_strdup (glob->pattern), list);
copy_to_xml = TRUE;
......@@ -847,6 +870,7 @@ static void write_out_glob2(GList *globs, FILE *stream)
GList *list;
Glob *glob;
Type *type;
gboolean need_flags;
for (list = globs ; list; list = list->next) {
glob = (Glob *)list->data;
......@@ -855,9 +879,22 @@ static void write_out_glob2(GList *globs, FILE *stream)
g_warning("* Glob patterns can't contain literal newlines "
"(%s in type %s/%s)\n", glob->pattern,
type->media, type->subtype);
else
else
{
need_flags = FALSE;
if (glob->case_sensitive)
need_flags = TRUE;
if (need_flags) {
g_fprintf(stream, "%d:%s/%s:%s%s\n",
glob->weight, type->media, type->subtype, glob->pattern,
glob->case_sensitive ? ":cs" : "");
}
/* Always write the line without the flags, for older parsers */
g_fprintf(stream, "%d:%s/%s:%s\n",
glob->weight, type->media, type->subtype, glob->pattern);
glob->weight, type->media, type->subtype, glob->pattern);
}
}
}
......@@ -2141,7 +2178,7 @@ write_card32 (FILE *cache, guint32 n)
}
#define MAJOR_VERSION 1
#define MINOR_VERSION 1
#define MINOR_VERSION 2
static gboolean
write_header (FILE *cache,
......@@ -2298,6 +2335,17 @@ get_type_value (gpointer data,
return result;
}
static guint32
get_glob_weight_and_flags (Glob *glob)
{
guint32 res;
res = glob->weight & 0xff;
if (glob->case_sensitive)
res |= 0x100;
return res;
}
static gchar **
get_glob_list_value (gpointer data,
gchar *key)
......@@ -2320,7 +2368,7 @@ get_glob_list_value (gpointer data,
result[i++] = g_strdup (glob->pattern);
result[i++] = g_strdup_printf ("%s/%s", type->media, type->subtype);
result[i++] = g_strdup_printf ("%d", glob->weight);
result[i++] = g_strdup_printf ("%ud", get_glob_weight_and_flags (glob));
}
return result;
}
......@@ -2501,6 +2549,7 @@ struct _SuffixEntry
gunichar character;
gchar *mimetype;
gint weight;
guint32 flags;
GList *children;
guint size;
guint depth;
......@@ -2509,7 +2558,8 @@ struct _SuffixEntry
static GList *
insert_suffix (gunichar *suffix,
gchar *mimetype,
gint weight,
gint weight,
guint32 flags,
GList *suffixes)
{
GList *l;
......@@ -2568,12 +2618,13 @@ insert_suffix (gunichar *suffix,
s2->character = 0;
s2->mimetype = mimetype;
s2->weight = weight;
s2->flags = flags;
s2->children = NULL;
s->children = g_list_insert_before (s->children, l2, s2);
}
}
}
else
s->children = insert_suffix (suffix + 1, mimetype, weight, s->children);
s->children = insert_suffix (suffix + 1, mimetype, weight, flags, s->children);
return suffixes;
}
......@@ -2605,6 +2656,7 @@ build_suffixes (gpointer key,
Glob *glob;
Type *type;
glong len;
guint32 flags;
if (is_simple_glob (pattern))
{
......@@ -2623,7 +2675,10 @@ build_suffixes (gpointer key,
type = glob->type;
mimetype = g_strdup_printf ("%s/%s", type->media, type->subtype);
*suffixes = insert_suffix (suffix, mimetype, glob->weight, *suffixes);
flags = 0;
if (glob->case_sensitive)
flags |= 0x100;
*suffixes = insert_suffix (suffix, mimetype, glob->weight, flags, *suffixes);
}
g_free (suffix);
......@@ -2691,7 +2746,7 @@ write_suffix_entries (FILE *cache,
if (!write_card32 (cache, offset))
return FALSE;
if (!write_card32 (cache, entry->weight))
if (!write_card32 (cache, (entry->weight & 0xff) | entry->flags))
return FALSE;
}
else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment