mirror of https://github.com/GNOME/gimp.git
alow negative offsets in magics and interpret them as relative to the end
2007-03-17 Michael Natterer <mitch@gimp.org> * app/file/file-utils.c (file_check_single_magic): alow negative offsets in magics and interpret them as relative to the end of the file. (file_utils_find_proc) (file_check_magic_list): some cleanup. * plug-ins/common/tga.c (query): register the magic string "TRUEVISION-XFILE.\0" 18 bytes before the end of the file. This way, "new style" TGA files are detected regardless of their filename. "old style" TGA files still need the right extension to be treated as TGA. Added "vda", "icb" and "vst" to the list of extensions. Fixes bug #133798. svn path=/trunk/; revision=22138
This commit is contained in:
parent
24a8095025
commit
0845a11c55
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2007-03-17 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* app/file/file-utils.c (file_check_single_magic): alow negative
|
||||
offsets in magics and interpret them as relative to the end of the
|
||||
file.
|
||||
|
||||
(file_utils_find_proc)
|
||||
(file_check_magic_list): some cleanup.
|
||||
|
||||
* plug-ins/common/tga.c (query): register the magic string
|
||||
"TRUEVISION-XFILE.\0" 18 bytes before the end of the file.
|
||||
This way, "new style" TGA files are detected regardless of
|
||||
their filename. "old style" TGA files still need the right
|
||||
extension to be treated as TGA. Added "vda", "icb" and "vst"
|
||||
to the list of extensions. Fixes bug #133798.
|
||||
|
||||
2007-03-17 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
Make the height of the previews in data editors configurable.
|
||||
|
|
|
@ -276,7 +276,6 @@ file_utils_find_proc (GSList *procs,
|
|||
FILE *ifp = NULL;
|
||||
gint head_size = -2;
|
||||
gint size_match_count = 0;
|
||||
FileMatchType match_val;
|
||||
guchar head[256];
|
||||
|
||||
while (procs)
|
||||
|
@ -305,16 +304,19 @@ file_utils_find_proc (GSList *procs,
|
|||
|
||||
if (head_size >= 4)
|
||||
{
|
||||
FileMatchType match_val;
|
||||
|
||||
match_val = file_check_magic_list (file_proc->magics_list,
|
||||
head, head_size,
|
||||
ifp);
|
||||
|
||||
if (match_val == 2) /* size match ? */
|
||||
{ /* Use it only if no other magic matches */
|
||||
if (match_val == FILE_MATCH_SIZE)
|
||||
{
|
||||
/* Use it only if no other magic matches */
|
||||
size_match_count++;
|
||||
size_matched_proc = file_proc;
|
||||
}
|
||||
else if (match_val)
|
||||
else if (match_val != FILE_MATCH_NONE)
|
||||
{
|
||||
fclose (ifp);
|
||||
g_free (filename);
|
||||
|
@ -817,9 +819,6 @@ file_check_single_magic (const gchar *offset,
|
|||
if (sscanf (offset, "%ld", &offs) != 1)
|
||||
return FILE_MATCH_NONE;
|
||||
|
||||
if (offs < 0)
|
||||
return FILE_MATCH_NONE;
|
||||
|
||||
/* Check type of test */
|
||||
num_operator_ptr = NULL;
|
||||
num_operator = '\0';
|
||||
|
@ -895,16 +894,17 @@ file_check_single_magic (const gchar *offset,
|
|||
|
||||
fileval = buf.st_size;
|
||||
}
|
||||
else if (offs + numbytes <= headsize) /* We have it in memory ? */
|
||||
else if (offs > 0 &&
|
||||
(offs + numbytes <= headsize)) /* We have it in memory ? */
|
||||
{
|
||||
for (k = 0; k < numbytes; k++)
|
||||
fileval = (fileval << 8) | (glong) file_head[offs+k];
|
||||
fileval = (fileval << 8) | (glong) file_head[offs + k];
|
||||
}
|
||||
else /* Read it from file */
|
||||
{
|
||||
gint c = 0;
|
||||
|
||||
if (fseek (ifp, offs, SEEK_SET) < 0)
|
||||
if (fseek (ifp, offs, (offs > 0) ? SEEK_SET : SEEK_END) < 0)
|
||||
return FILE_MATCH_NONE;
|
||||
|
||||
for (k = 0; k < numbytes; k++)
|
||||
|
@ -938,13 +938,14 @@ file_check_single_magic (const gchar *offset,
|
|||
if (numbytes <= 0)
|
||||
return FILE_MATCH_NONE;
|
||||
|
||||
if (offs + numbytes <= headsize) /* We have it in memory ? */
|
||||
if (offs > 0 &&
|
||||
(offs + numbytes <= headsize)) /* We have it in memory ? */
|
||||
{
|
||||
found = (memcmp (mem_testval, file_head + offs, numbytes) == 0);
|
||||
}
|
||||
else /* Read it from file */
|
||||
{
|
||||
if (fseek (ifp, offs, SEEK_SET) < 0)
|
||||
if (fseek (ifp, offs, (offs > 0) ? SEEK_SET : SEEK_END) < 0)
|
||||
return FILE_MATCH_NONE;
|
||||
|
||||
found = FILE_MATCH_MAGIC;
|
||||
|
@ -972,7 +973,7 @@ file_check_magic_list (GSList *magics_list,
|
|||
const gchar *type;
|
||||
const gchar *value;
|
||||
gboolean and = FALSE;
|
||||
FileMatchType found = FILE_MATCH_NONE;
|
||||
gboolean found = FALSE;
|
||||
FileMatchType match_val;
|
||||
|
||||
while (magics_list)
|
||||
|
@ -989,13 +990,13 @@ file_check_magic_list (GSList *magics_list,
|
|||
head, headsize,
|
||||
ifp);
|
||||
if (and)
|
||||
found = found && match_val;
|
||||
found = found && (match_val != FILE_MATCH_NONE);
|
||||
else
|
||||
found = match_val;
|
||||
found = (match_val != FILE_MATCH_NONE);
|
||||
|
||||
and = (strchr (offset, '&') != NULL);
|
||||
|
||||
if ((! and) && found)
|
||||
if (! and && found)
|
||||
return match_val;
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,10 @@ query (void)
|
|||
load_args, load_return_vals);
|
||||
|
||||
gimp_register_file_handler_mime (LOAD_PROC, "image/x-tga");
|
||||
gimp_register_load_handler (LOAD_PROC, "tga", "");
|
||||
gimp_register_magic_load_handler (LOAD_PROC,
|
||||
"tga,vda,icb,vst",
|
||||
"",
|
||||
"-18&,string,TRUEVISION-XFILE.,-1,byte,0");
|
||||
|
||||
gimp_install_procedure (SAVE_PROC,
|
||||
"saves files in the Targa file format",
|
||||
|
|
Loading…
Reference in New Issue