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
|
||||
AM_ENABLE_SHARED
|
||||
AM_PROG_LIBTOOL
|
||||
AC_FUNC_ALLOCA
|
||||
AC_C___ATTRIBUTE__
|
||||
|
||||
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)
|
||||
{
|
||||
Efreet_Mime_Glob *g;
|
||||
char *s, *sl;
|
||||
const char *ext, *mime;
|
||||
|
||||
Efreet_Mime_Glob *g;
|
||||
char *s, *sl, *p;
|
||||
const char *ext, *mime;
|
||||
|
||||
/*
|
||||
* Check in the extension hash for the type
|
||||
*/
|
||||
sl = alloca(strlen(file) + 1);
|
||||
strcpy(sl, file);
|
||||
for (s = sl; *s; s++) *s = tolower(*s);
|
||||
ext = strchr(sl,'.');
|
||||
while(ext)
|
||||
ext = strchr(file, '.');
|
||||
sl = alloca(strlen(ext) + 1);
|
||||
for (s = ext, p = sl; *s; s++, p++) *p = tolower(*s);
|
||||
*p = 0;
|
||||
p = sl;
|
||||
while (p)
|
||||
{
|
||||
++ext;
|
||||
|
||||
if (ext && (mime = ecore_hash_get(wild, ext)))
|
||||
return mime;
|
||||
|
||||
ext = strchr(ext,'.');
|
||||
p++;
|
||||
if (p && (mime = ecore_hash_get(wild, p))) return mime;
|
||||
p = strchr(p, '.');
|
||||
}
|
||||
|
||||
/*
|
||||
* Fallback to the other globs if not found
|
||||
*/
|
||||
ecore_list_first_goto(globs);
|
||||
while ((g = ecore_list_next(globs)))
|
||||
{
|
||||
/*
|
||||
* Fallback to the other globs if not found
|
||||
*/
|
||||
ecore_list_first_goto(globs);
|
||||
while ((g = ecore_list_next(globs)))
|
||||
{
|
||||
if (efreet_mime_glob_match(file, g->glob))
|
||||
return g->mime;
|
||||
}
|
||||
|
||||
s = strdup(file);
|
||||
ecore_list_first_goto(globs);
|
||||
while ((g = ecore_list_next(globs)))
|
||||
{
|
||||
if (efreet_mime_glob_case_match(s, g->glob))
|
||||
return g->mime;
|
||||
}
|
||||
FREE(s);
|
||||
|
||||
return NULL;
|
||||
return g->mime;
|
||||
}
|
||||
|
||||
ext = alloca(strlen(file) + 1);
|
||||
for (s = file, p = ext; *s; s++, p++) *p = tolower(*s);
|
||||
*p = 0;
|
||||
ecore_list_first_goto(globs);
|
||||
while ((g = ecore_list_next(globs)))
|
||||
{
|
||||
if (efreet_mime_glob_case_match(ext, g->glob))
|
||||
return g->mime;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1196,18 +1194,14 @@ efreet_mime_magic_entry_free(void *data)
|
|||
static int
|
||||
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;
|
||||
|
||||
if (glob[0] == '\0')
|
||||
{
|
||||
if (str[0] == '\0') return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!fnmatch(glob, str, 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 glob: Glob to match str to
|
||||
* @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
|
||||
efreet_mime_glob_case_match(char *str, const char *glob)
|
||||
{
|
||||
const char *p;
|
||||
char *tglob, *tp;
|
||||
|
||||
if (glob[0] == '\0')
|
||||
{
|
||||
if (str[0] == '\0') return 1;
|
||||
const char *p;
|
||||
char *tglob, *tp;
|
||||
|
||||
if (!str || !glob) return 0;
|
||||
if (glob[0] == 0)
|
||||
{
|
||||
if (str[0] == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (tp = str; *tp != '\0'; tp++) *tp = tolower(*tp);
|
||||
|
||||
tglob = NEW(1, strlen(glob) + 1);
|
||||
for (tp = tglob, p = glob; *p != 0; p++, tp++) *tp = tolower(*p);
|
||||
*tp = 0;
|
||||
|
||||
if (!fnmatch(str, p, 0)) return 1;
|
||||
|
||||
IF_FREE(tglob);
|
||||
|
||||
return 0;
|
||||
}
|
||||
tglob = alloca(strlen(glob) + 1);
|
||||
for (tp = tglob, p = glob; *p; p++, tp++) *tp = tolower(*p);
|
||||
*tp = 0;
|
||||
if (!fnmatch(str, tglob, 0)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -24,11 +25,14 @@
|
|||
#include <fnmatch.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_File.h>
|
||||
#include <Ecore_Str.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "efreet_xml.h"
|
||||
#include "efreet_ini.h"
|
||||
|
||||
|
|
Loading…
Reference in New Issue