forked from enlightenment/efl
and for the picky - there's less copies for tolowoer. i also saw some BAD BAD
leaks. bad! alloc pointer but not freeing them! also fixed up #include of alloca.h if needed. SVN revision: 31260
This commit is contained in:
parent
07032e8edf
commit
6b0688752a
|
@ -11,6 +11,7 @@ AC_HEADER_STDC
|
||||||
AC_C_CONST
|
AC_C_CONST
|
||||||
AM_ENABLE_SHARED
|
AM_ENABLE_SHARED
|
||||||
AM_PROG_LIBTOOL
|
AM_PROG_LIBTOOL
|
||||||
|
AC_FUNC_ALLOCA
|
||||||
AC_C___ATTRIBUTE__
|
AC_C___ATTRIBUTE__
|
||||||
|
|
||||||
dnl Set PACKAGE_DATA_DIR in config.h.
|
dnl Set PACKAGE_DATA_DIR in config.h.
|
||||||
|
|
|
@ -257,47 +257,45 @@ const char *efreet_mime_magic_type_get(const char *file)
|
||||||
*/
|
*/
|
||||||
const char *efreet_mime_globs_type_get(const char *file)
|
const char *efreet_mime_globs_type_get(const char *file)
|
||||||
{
|
{
|
||||||
Efreet_Mime_Glob *g;
|
Efreet_Mime_Glob *g;
|
||||||
char *s, *sl;
|
char *s, *sl, *p;
|
||||||
const char *ext, *mime;
|
const char *ext, *mime;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check in the extension hash for the type
|
* Check in the extension hash for the type
|
||||||
*/
|
*/
|
||||||
sl = alloca(strlen(file) + 1);
|
ext = strchr(file, '.');
|
||||||
strcpy(sl, file);
|
sl = alloca(strlen(ext) + 1);
|
||||||
for (s = sl; *s; s++) *s = tolower(*s);
|
for (s = ext, p = sl; *s; s++, p++) *p = tolower(*s);
|
||||||
ext = strchr(sl,'.');
|
*p = 0;
|
||||||
while(ext)
|
p = sl;
|
||||||
|
while (p)
|
||||||
{
|
{
|
||||||
++ext;
|
p++;
|
||||||
|
if (p && (mime = ecore_hash_get(wild, p))) return mime;
|
||||||
if (ext && (mime = ecore_hash_get(wild, ext)))
|
p = strchr(p, '.');
|
||||||
return mime;
|
|
||||||
|
|
||||||
ext = strchr(ext,'.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fallback to the other globs if not found
|
* Fallback to the other globs if not found
|
||||||
*/
|
*/
|
||||||
ecore_list_first_goto(globs);
|
ecore_list_first_goto(globs);
|
||||||
while ((g = ecore_list_next(globs)))
|
while ((g = ecore_list_next(globs)))
|
||||||
{
|
{
|
||||||
if (efreet_mime_glob_match(file, g->glob))
|
if (efreet_mime_glob_match(file, g->glob))
|
||||||
return g->mime;
|
return g->mime;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = strdup(file);
|
ext = alloca(strlen(file) + 1);
|
||||||
ecore_list_first_goto(globs);
|
for (s = file, p = ext; *s; s++, p++) *p = tolower(*s);
|
||||||
while ((g = ecore_list_next(globs)))
|
*p = 0;
|
||||||
{
|
ecore_list_first_goto(globs);
|
||||||
if (efreet_mime_glob_case_match(s, g->glob))
|
while ((g = ecore_list_next(globs)))
|
||||||
return g->mime;
|
{
|
||||||
}
|
if (efreet_mime_glob_case_match(ext, g->glob))
|
||||||
FREE(s);
|
return g->mime;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1196,18 +1194,14 @@ efreet_mime_magic_entry_free(void *data)
|
||||||
static int
|
static int
|
||||||
efreet_mime_glob_match(const char *str, const char *glob)
|
efreet_mime_glob_match(const char *str, const char *glob)
|
||||||
{
|
{
|
||||||
if (!str || !glob)
|
if (!str || !glob) return 0;
|
||||||
|
if (glob[0] == 0)
|
||||||
|
{
|
||||||
|
if (str[0] == 0) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
if (glob[0] == '\0')
|
if (!fnmatch(glob, str, 0)) return 1;
|
||||||
{
|
return 0;
|
||||||
if (str[0] == '\0') return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fnmatch(glob, str, 0)) return 1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1215,30 +1209,24 @@ efreet_mime_glob_match(const char *str, const char *glob)
|
||||||
* @param str: String (filename) to match
|
* @param str: String (filename) to match
|
||||||
* @param glob: Glob to match str to
|
* @param glob: Glob to match str to
|
||||||
* @return Returns 1 on success, 0 on failure
|
* @return Returns 1 on success, 0 on failure
|
||||||
* @brief Compares str to glob, case insensitive
|
* @brief Compares str to glob, case insensitive (expects str already in lower case)
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
efreet_mime_glob_case_match(char *str, const char *glob)
|
efreet_mime_glob_case_match(char *str, const char *glob)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
char *tglob, *tp;
|
char *tglob, *tp;
|
||||||
|
|
||||||
if (glob[0] == '\0')
|
if (!str || !glob) return 0;
|
||||||
{
|
if (glob[0] == 0)
|
||||||
if (str[0] == '\0') return 1;
|
{
|
||||||
|
if (str[0] == 0) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
tglob = alloca(strlen(glob) + 1);
|
||||||
for (tp = str; *tp != '\0'; tp++) *tp = tolower(*tp);
|
for (tp = tglob, p = glob; *p; p++, tp++) *tp = tolower(*p);
|
||||||
|
*tp = 0;
|
||||||
tglob = NEW(1, strlen(glob) + 1);
|
if (!fnmatch(str, tglob, 0)) return 1;
|
||||||
for (tp = tglob, p = glob; *p != 0; p++, tp++) *tp = tolower(*p);
|
return 0;
|
||||||
*tp = 0;
|
|
||||||
|
|
||||||
if (!fnmatch(str, p, 0)) return 1;
|
|
||||||
|
|
||||||
IF_FREE(tglob);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -24,11 +25,14 @@
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_ALLOCA_H
|
||||||
|
#include <alloca.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <Ecore.h>
|
#include <Ecore.h>
|
||||||
#include <Ecore_File.h>
|
#include <Ecore_File.h>
|
||||||
#include <Ecore_Str.h>
|
#include <Ecore_Str.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
#include "efreet_xml.h"
|
#include "efreet_xml.h"
|
||||||
#include "efreet_ini.h"
|
#include "efreet_ini.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue