* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include <assert.h>
#include <string.h>
#include <fnmatch.h>
-#include <ctype.h>
+
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
#ifndef FALSE
#define FALSE (0)
return glob_hash_node;
}
+#ifdef NOT_USED_IN_GIO
+
static void
_xdg_glob_hash_node_dump (XdgGlobHashNode *glob_hash_node,
int depth)
_xdg_glob_hash_node_dump (glob_hash_node->next, depth);
}
+#endif
+
static XdgGlobHashNode *
_xdg_glob_hash_insert_ucs4 (XdgGlobHashNode *glob_hash_node,
xdg_unichar_t *text,
const MimeWeight *aa = (const MimeWeight *)a;
const MimeWeight *bb = (const MimeWeight *)b;
- return aa->weight - bb->weight;
+ return bb->weight - aa->weight;
}
#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
return lower;
}
+static int
+filter_out_dupes (MimeWeight mimes[], int n_mimes)
+{
+ int last;
+ int i, j;
+
+ last = n_mimes;
+
+ for (i = 0; i < last; i++)
+ {
+ j = i + 1;
+ while (j < last)
+ {
+ if (strcmp (mimes[i].mime, mimes[j].mime) == 0)
+ {
+ mimes[i].weight = MAX (mimes[i].weight, mimes[j].weight);
+ last--;
+ mimes[j].mime = mimes[last].mime;
+ mimes[j].weight = mimes[last].weight;
+ }
+ else
+ j++;
+ }
+ }
+
+ return last;
+}
+
int
_xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash,
const char *file_name,
int n_mimes = 10;
int len;
char *lower_case;
- int try_lower_case;
/* First, check the literals */
len = strlen (file_name);
n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, lower_case, len, FALSE,
mimes, n_mimes);
- if (n == 0)
- n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, TRUE,
- mimes, n_mimes);
+ if (n < 2)
+ n += _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, TRUE,
+ mimes + n, n_mimes - n);
- if (n == 0)
+ if (n < 2)
{
for (list = glob_hash->full_list; list && n < n_mime_types; list = list->next)
{
}
free (lower_case);
+ n = filter_out_dupes (mimes, n);
+
qsort (mimes, n, sizeof (MimeWeight), compare_mime_weight);
if (n_mime_types < n)
}
}
+#ifdef NOT_USED_IN_GIO
+
void
_xdg_glob_hash_dump (XdgGlobHash *glob_hash)
{
}
}
+#endif
void
_xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash,