forked from enlightenment/efl
- formatting
- simplify a couple routines - make the magic loading not loop infinitly on big endian SVN revision: 30544
This commit is contained in:
parent
e8a13809f9
commit
5406ab673f
|
@ -17,9 +17,9 @@ static Ecore_List *monitors = NULL; /* contains Efreet_Mime_Monitor structs */
|
||||||
*/
|
*/
|
||||||
static enum
|
static enum
|
||||||
{
|
{
|
||||||
BIG = 0,
|
EFREET_ENDIAN_BIG = 0,
|
||||||
LITTLE = 1
|
EFREET_ENDIAN_LITTLE = 1
|
||||||
} efreet_mime_endianess = BIG;
|
} efreet_mime_endianess = EFREET_ENDIAN_BIG;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -103,8 +103,6 @@ static void efreet_mime_monitor_free(void *data);
|
||||||
int
|
int
|
||||||
efreet_mime_init(void)
|
efreet_mime_init(void)
|
||||||
{
|
{
|
||||||
Efreet_Mime_Monitor *mm = NULL;
|
|
||||||
|
|
||||||
if (!ecore_init())
|
if (!ecore_init())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -122,14 +120,6 @@ efreet_mime_init(void)
|
||||||
if (!efreet_mime_init_files())
|
if (!efreet_mime_init_files())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Can be used to debug monitors*/
|
|
||||||
if (monitors)
|
|
||||||
{
|
|
||||||
ecore_list_goto_first(monitors);
|
|
||||||
while ((mm = ecore_list_next(monitors)))
|
|
||||||
printf("Watching: %s\n", mm->file);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,8 +158,8 @@ efreet_mime_get(const char *file, int methods)
|
||||||
|
|
||||||
if (methods & EFREET_MIME_FLAG_MAGIC)
|
if (methods & EFREET_MIME_FLAG_MAGIC)
|
||||||
{
|
{
|
||||||
if ((type = efreet_mime_magic_check_priority(file, 0, 80)))
|
if ((type = efreet_mime_magic_check_priority(file, 0, 80)))
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((methods & EFREET_MIME_FLAG_GLOB)
|
if ((methods & EFREET_MIME_FLAG_GLOB)
|
||||||
|
@ -302,17 +292,14 @@ efreet_mime_load_globs(Ecore_List *datadirs, const char *datahome)
|
||||||
globs = ecore_list_new();
|
globs = ecore_list_new();
|
||||||
ecore_list_set_free_cb(globs, efreet_mime_glob_free);
|
ecore_list_set_free_cb(globs, efreet_mime_glob_free);
|
||||||
|
|
||||||
|
datadir = datahome
|
||||||
ecore_list_goto_first(datadirs);
|
ecore_list_goto_first(datadirs);
|
||||||
while ((datadir = ecore_list_next(datadirs)))
|
while (datadir)
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "%s/mime/globs", datadir);
|
snprintf(buf, sizeof(buf), "%s/mime/globs", datadir);
|
||||||
efreet_mime_shared_mimeinfo_globs_load(buf);
|
efreet_mime_shared_mimeinfo_globs_load(buf);
|
||||||
}
|
|
||||||
|
|
||||||
if (datahome && (datahome[0] != '\0'))
|
datadir = ecore_list_next(datadirs);
|
||||||
{
|
|
||||||
snprintf(buf, sizeof(buf), "%s/mime/globs", datahome);
|
|
||||||
efreet_mime_shared_mimeinfo_globs_load(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -339,17 +326,14 @@ efreet_mime_load_magics(Ecore_List *datadirs, const char *datahome)
|
||||||
magics = ecore_list_new();
|
magics = ecore_list_new();
|
||||||
ecore_list_set_free_cb(magics, efreet_mime_magic_free);
|
ecore_list_set_free_cb(magics, efreet_mime_magic_free);
|
||||||
|
|
||||||
|
datadir = datahome;
|
||||||
ecore_list_goto_first(datadirs);
|
ecore_list_goto_first(datadirs);
|
||||||
while ((datadir = ecore_list_next(datadirs)))
|
while (datadir)
|
||||||
{
|
{
|
||||||
snprintf(buf, sizeof(buf), "%s/mime/magic", datadir);
|
snprintf(buf, sizeof(buf), "%s/mime/magic", datadir);
|
||||||
efreet_mime_shared_mimeinfo_magic_load(buf);
|
efreet_mime_shared_mimeinfo_magic_load(buf);
|
||||||
}
|
|
||||||
|
|
||||||
if (datahome && (datahome[0] != '\0'))
|
datadir = ecore_list_next(datadirs);
|
||||||
{
|
|
||||||
snprintf(buf, sizeof(buf), "%s/mime/magic", datahome);
|
|
||||||
efreet_mime_shared_mimeinfo_magic_load(buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +383,7 @@ efreet_mime_init_files(void)
|
||||||
{
|
{
|
||||||
Ecore_List *datadirs = NULL;
|
Ecore_List *datadirs = NULL;
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
const char *datahome = NULL, *datadir = NULL;
|
const char *datahome, *datadir = NULL;
|
||||||
|
|
||||||
if (!(datahome = efreet_data_home_get()))
|
if (!(datahome = efreet_data_home_get()))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -409,21 +393,18 @@ efreet_mime_init_files(void)
|
||||||
|
|
||||||
/* Add our file monitors */
|
/* Add our file monitors */
|
||||||
/* We watch the directories so we can watch for new files? */
|
/* We watch the directories so we can watch for new files? */
|
||||||
|
datadir = datahome;
|
||||||
ecore_list_goto_first(datadirs);
|
ecore_list_goto_first(datadirs);
|
||||||
while ((datadir = ecore_list_next(datadirs)))
|
while (datadir)
|
||||||
{
|
{
|
||||||
snprintf(buf,PATH_MAX,"%s/mime", datadir);
|
snprintf(buf, PATH_MAX, "%s/mime", datadir);
|
||||||
efreet_mime_monitor_add(buf);
|
efreet_mime_monitor_add(buf);
|
||||||
|
|
||||||
|
datadir = ecore_list_next(datadirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf,PATH_MAX,"%s/mime", datahome);
|
|
||||||
efreet_mime_monitor_add(buf);
|
|
||||||
|
|
||||||
efreet_mime_monitor_add("/etc/mime.types");
|
efreet_mime_monitor_add("/etc/mime.types");
|
||||||
|
|
||||||
/*
|
/* Load our mime information */
|
||||||
* Load our mime information
|
|
||||||
*/
|
|
||||||
efreet_mime_load_globs(datadirs, datahome);
|
efreet_mime_load_globs(datadirs, datahome);
|
||||||
efreet_mime_load_magics(datadirs, datahome);
|
efreet_mime_load_magics(datadirs, datahome);
|
||||||
|
|
||||||
|
@ -691,14 +672,12 @@ efreet_mime_shared_mimeinfo_globs_load(const char *file)
|
||||||
static int
|
static int
|
||||||
efreet_mime_count_digits(int in)
|
efreet_mime_count_digits(int in)
|
||||||
{
|
{
|
||||||
int i = 1, j = in;
|
int i = 1, j = in;
|
||||||
|
|
||||||
if (j < 10)
|
if (j < 10) return 1;
|
||||||
return 1;
|
while ((j /= 10) > 0) ++i;
|
||||||
|
|
||||||
while ((j /= 10) > 0) ++i;
|
return i;
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -756,12 +735,14 @@ efreet_mime_shared_mimeinfo_magic_load(const char *file)
|
||||||
|
|
||||||
/* Check for magic string. Will also move us to first section */
|
/* Check for magic string. Will also move us to first section */
|
||||||
if (fread(buf, 1, 12, f))
|
if (fread(buf, 1, 12, f))
|
||||||
if (memcmp(buf, "MIME-Magic\0\n", 12)) return;
|
{
|
||||||
|
if (memcmp(buf, "MIME-Magic\0\n", 12)) return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Begin reading in sections and mime data */
|
/* Begin reading in sections and mime data */
|
||||||
while ((bytes_read = fread(buf, 1, sizeof(buf), f)))
|
while ((bytes_read = fread(buf, 1, sizeof(buf), f)))
|
||||||
{
|
{
|
||||||
for (i=0; i < bytes_read;)
|
for (i = 0; i < bytes_read;)
|
||||||
{
|
{
|
||||||
if (buf[i] == '[')
|
if (buf[i] == '[')
|
||||||
{
|
{
|
||||||
|
@ -826,7 +807,12 @@ efreet_mime_shared_mimeinfo_magic_load(const char *file)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VALUE:
|
case VALUE:
|
||||||
entry->value_len = ntohs(buf[i + 1] << 8 | (short)(buf[i]));
|
|
||||||
|
if (efreet_mime_endianess == EFREET_ENDIAN_LITTLE)
|
||||||
|
entry->value_len = ntohs(buf[i + 1] << 8 | (short)(buf[i]));
|
||||||
|
else
|
||||||
|
entry->value_len = ntohs((short)(buf[i + 1]) | buf[i] << 8);
|
||||||
|
|
||||||
i += 2;
|
i += 2;
|
||||||
|
|
||||||
entry->value = NEW(1, entry->value_len);
|
entry->value = NEW(1, entry->value_len);
|
||||||
|
@ -856,7 +842,7 @@ efreet_mime_shared_mimeinfo_magic_load(const char *file)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (efreet_mime_endianess == LITTLE)
|
if (efreet_mime_endianess == EFREET_ENDIAN_LITTLE)
|
||||||
{
|
{
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < entry->value_len; j += entry->word_size)
|
for (j = 0; j < entry->value_len; j += entry->word_size)
|
||||||
|
@ -1000,20 +986,21 @@ efreet_mime_magic_check_priority(const char *file,
|
||||||
{
|
{
|
||||||
if ((level < e->indent) && !match)
|
if ((level < e->indent) && !match)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((level >= e->indent) && !match)
|
if ((level >= e->indent) && !match)
|
||||||
level = e->indent;
|
level = e->indent;
|
||||||
|
|
||||||
else if ((level > e->indent) && match)
|
else if ((level > e->indent) && match)
|
||||||
{
|
{
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
if (last_mime)
|
if (last_mime) return last_mime;
|
||||||
return last_mime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (offset = e->offset; offset < e->offset+e->range_len; ++offset)
|
for (offset = e->offset; offset < e->offset+e->range_len; ++offset)
|
||||||
{
|
{
|
||||||
if (((offset+e->value_len) > bytes_read) &&
|
if (((offset+e->value_len) > bytes_read) &&
|
||||||
(fseek(f, offset, SEEK_SET) == -1))
|
(fseek(f, offset, SEEK_SET) == -1))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
match = 1;
|
match = 1;
|
||||||
|
@ -1025,7 +1012,6 @@ efreet_mime_magic_check_priority(const char *file,
|
||||||
c = buf[offset + i];
|
c = buf[offset + i];
|
||||||
|
|
||||||
v = e->value[i];
|
v = e->value[i];
|
||||||
|
|
||||||
if (e->mask)
|
if (e->mask)
|
||||||
v &= e->mask[i];
|
v &= e->mask[i];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue