gimp/app/file/file-utils.c

594 lines
16 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
* Copyright (C) 1997 Josh MacDonald
*
* file-utils.c
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
added app/display/ and app/plug-in/. Empty for now except for the types 2001-08-17 Michael Natterer <mitch@gimp.org> * configure.in: added app/display/ and app/plug-in/. Empty for now except for the types files. * app/Makefile.am * app/appenums.h * app/apptypes.h: removed. * app/display/Makefile.am * app/display/display-types.h * app/plug-in/Makefile.am * app/plug-in/plug-in-types.h * app/gui/Makefile.am * app/gui/gui-types.h * app/pdb/Makefile.am * app/pdb/pdb-types.h: new files for typedefs. * app/appenv.h: added MessageHandlerType and StackTraceMode here. * app/undo_types.h: moved undo struct typedefs here. * app/tools/tools-types.h * app/core/core-types.h: added some enums and Tattoo here (renamed to GimpTattoo). * app/gdisplay.h: temp_hack: #include "display/display-types.h" * app/gimphelp.c: s/gtk_idle_add/g_idle_add/ * app/gimprc.c: don't use "gimprc" in token handlers but the passed "val1p" and "val2p". * app/image_map.[ch]: cleanup in preparation of making a GObject out of it. * app/base/pixel-region.[ch]: no need to pass the PixelRegionIterator around as void pointer. * app/core/gimp.[ch] * app/core/gimpcontext.[ch] * app/core/gimptoolinfo.[ch] * app/tools/tool_manager.c * app/widgets/gimpdnd.c: added the standard_tool_info to the Gimp object. * app/batch.c * app/file-open.c * app/file-save.c * app/file-utils.c * app/interface.c * app/main.c * app/path.[ch] * app/pathP.h * app/plug_in.h * app/core/gimpdrawable.[ch] * app/core/gimpimage-mask.c * app/core/gimpimage.[ch] * app/core/gimplayer.c * app/gui/color-area.c * app/gui/color-notebook.c * app/gui/colormap-dialog.c * app/gui/dialogs-commands.c * app/gui/dialogs-constructors.c * app/gui/error-console-dialog.c * app/gui/gradient-editor.c * app/gui/gradient-select.c * app/gui/indicator-area.c * app/gui/info-dialog.c * app/gui/palette-editor.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/session.c * app/gui/splash.c * app/gui/view-commands.c * app/tools/gimpinktool-blob.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpdockbook.c * app/widgets/gimppreview.c * app/xcf/xcf-load.c * app/xcf/xcf-save.c * app/xcf/xcf.c: changed accordingly: s/Tattoo/GimpTattoo/, include the new types files, include <glib-object.h> instead of >gtk/gtk.h>. Bad hacks to get rid of SELECTION_OFF and friends in core/ (will be replaced ba a signal soon). * tools/pdbgen/Makefile.am: changed list of headers scanned for enums accordingly. * app/pdb/procedural_db.c * tools/pdbgen/app.pl * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb: same fixes as above, added hacks to ensure that all foo-types.h files are included before all other gimp internal includes, include "pdb-types.h" unconditionally. * tools/pdbgen/enums.pl * app/pdb/*_cmds.c: regenerated.
2001-08-17 22:27:31 +08:00
#include <glib-object.h>
#include "libgimpmath/gimpmath.h"
#include "core/core-types.h"
new directory app/base/ 2001-05-15 Michael Natterer <mitch@gimp.org> * configure.in: new directory app/base/ * app/Makefile.am * app/boundary.[ch] * app/brush_scale.[ch] * app/gimpchecks.h * app/gimplut.[ch] * app/pixel_processor.[ch] * app/pixel_region.[ch] * app/pixel_surround.[ch] * app/temp_buf.[ch] * app/tile.[ch] * app/tile_cache.[ch] * app/tile_manager.[ch] * app/tile_manager_pvt.h * app/tile_pvt.h * app/tile_swap.[ch]: moved to base/ * app/base/Makefile.am * app/base/base-types.h * app/base/*: new directory for the sub-object pixel maniplation and storage stuff. Does not include Gtk+ or anything outside base/. Did some cleanup in all files. * app/appenums.h * app/apptypes.h * app/core/gimpimage.h: removed types which are now in base/base-types.h. * app/base/base-config.[ch] * app/gimprc.[ch]: put the config variables for base/ to their own file so base/ doesn not have to include gimprc.h (does not yet work, i.e. the variables are un-configurable right now) * app/main.c: set a log handler for "Gimp-Base". * app/paint-funcs/Makefile.am * app/paint-funcs/paint-funcs.[ch]: removed the color hash which maps RGB to color indices because it's a totally standalone system which has nothing to do with the paint-funcs and introduced a GimpImage dependency. paint-funcs/ should be considered on the same sub-object (glib-only) level as base/, only in a different directory. * app/core/Makefile.am * app/core/gimpimage-colorhash.[ch]: put the color hash here. * app/gimage.c: don't invalidate the color hash here... * app/core/gimpimage.c: ... but in the colormap_changed() default inplementation. Initialize the hash in class_init(). * tools/pdbgen/Makefile.am: scan app/base/base-types.h for enums. * tools/pdbgen/enums.pl: regenerated. * app/[lots] * app/core/[of] * app/gui/[files] * app/pdb/[all] * app/tools/[over] * app/widgets/[the] * tools/pdbgen/pdb/[place]: changed #includes accordingly. And use base_config->value instead of the stuff from gimprc.h.
2001-05-15 19:25:25 +08:00
#include "base/temp-buf.h"
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
#include "core/gimp.h"
#include "core/gimpimage.h"
app/Makefile.am removed... 2001-11-30 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/plug_in.[ch]: removed... * app/plug-in/Makefile.am * app/plug-in/plug-in-types.h * app/plug-in/plug-in.[ch]: ...and added here. * app/appenv.h: removed StackTraceMode and MessageHandlerType... * libgimpbase/gimpbasetypes.h: ...and added them here. * tools/pdbgen/Makefile.am: don't scan "app/apptypes.h" for enums. * tools/pdbgen/enumcode.pl: added a general check to prevent enums which are defined in libgimp* from being written to "libgimp/gimpenums.c". * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: regenerated. * app/core/core-types.h: include "pdb/pdb-types.h" so including "core/core-types.h" gets the whole core type space. * app/core/gimp.[ch]: added a "stack_trace_mode" parameter to the constructor and store it in the Gimp struct because the value is also passed to plug-ins and nobody should include "appenv.h". * app/gimprc.[ch]: pass the alternate_system_gimprc and alternate_gimprc filenames from the command line to gimprc_prase() so we don't need to include "appenv.h". * app/batch.[ch]: pass the "batch_cmds" as parameter, don't include "append.h". * app/app_procs.c: pass more parameters around. * app/devices.c * app/errors.c * app/gimphelp.c * app/main.c * app/core/gimpgradient.c * app/display/gimpdisplay.c * app/display/gimpdisplayshell.c * app/file/file-open.c * app/file/file-save.c * app/file/file-utils.c * app/gui/commands.c * app/gui/error-console-dialog.c * app/gui/file-dialog-utils.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/paths-dialog.c * app/gui/user-install-dialog.c * app/tools/gimpbezierselecttool.c * app/tools/xinput_airbrush.c * app/xcf/xcf.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/message.pdb * tools/pdbgen/pdb/plug_in.pdb: changed accordingly: - changed "plug-in.h" include where needed. - don't call gimp_fatal_error() directly, it's called via the log handler when calling g_error(). - don't incude "errors.h" except from main.c. - changed stack_trace and message_handler enum names. - get "stack_trace_mode" from Gimp. - removed many inclusions of "appenv.h". * app/pdb/fileops_cmds.c * app/pdb/help_cmds.c * app/pdb/message_cmds.c * app/pdb/plug_in_cmds.c * app/pdb/procedural_db.c: regenerated.
2001-12-01 08:14:14 +08:00
#include "pdb/procedural_db.h"
#include "plug-in/plug-in.h"
#include "plug-in/plug-in-proc-def.h"
generate app/file/Makefile 2001-10-25 Michael Natterer <mitch@gimp.org> * configure.in: generate app/file/Makefile * app/Makefile.am * app/file-open.[ch] * app/file-save.[ch] * app/file-utils.[ch]: removed... * app/file/Makefile.am * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: ...and added here. * app/gui/file-commands.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * tools/pdbgen/pdb/fileops.pdb: changed includes accordingly. * app/app_procs.[ch]: removed app_exit_finish() and app_exit_finish_done() from the public API, call gtk_main() here, pass "no_data" to gimp_new() and "restore_session" to gui_restore(). * app/main.c: removed global variable "double_speed", don't call gtk_main() in main.c. Added some missing log domains. * app/appenv.h: removed "double_speed". * app/core/gimp.[ch]: added "gboolean no_data" property which must be passed to gimp_new(). * app/display/gimpdisplay-foreach.[ch]: added gdisplays_set_busy() and gdisplays_unset_busy(). * app/gui/about-dialog.c: don't include "appenv.h", declare "double_speed" extern. * app/gui/brush-select.[ch] * app/gui/gradient-select.[ch] * app/gui/palette-select.[ch] * app/gui/pattern-select.[ch]: made the list of dialogs and the global selection dialogs private. Added functions which get a dialog by PDB callback_name. Pass a "Gimp" and the callback_name to the constructors. Don't include "app_procs.h" for "the_gimp" and "appenv.h" for "no_data" any more. Use the passed "Gimp" instead and look at gimp->no_data. * app/gui/toolbox.[ch]: pass a "Gimp" to the constructor. * app/gui/gui.[ch]: use the new gdisplays_[un]set_busy() functions, use the passed "Gimp" all over the place, don't include "appenv.h" and "app_procs.h". gui_really_quit_dialog() takes a "quit_func" callback now and calls it instead of calling app_exit_finish() (which is now private) directly. * app/gui/convert-dialog.c * app/gui/dialogs-constructors.c * app/gui/palette-import-dialog.c * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/pattern_select.pdb: changed accordingly. * app/pdb/brush_select_cmds.c * app/pdb/fileops_cmds.c * app/pdb/gradient_select_cmds.c * app/pdb/pattern_select_cmds.c: regenerated. 2001-10-25 Michael Natterer <mitch@gimp.org> * POTFILES.in: app/file-*.c -> app/file/file-*.c
2001-10-25 21:30:01 +08:00
app/Makefile.am removed... 2001-11-30 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/plug_in.[ch]: removed... * app/plug-in/Makefile.am * app/plug-in/plug-in-types.h * app/plug-in/plug-in.[ch]: ...and added here. * app/appenv.h: removed StackTraceMode and MessageHandlerType... * libgimpbase/gimpbasetypes.h: ...and added them here. * tools/pdbgen/Makefile.am: don't scan "app/apptypes.h" for enums. * tools/pdbgen/enumcode.pl: added a general check to prevent enums which are defined in libgimp* from being written to "libgimp/gimpenums.c". * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: regenerated. * app/core/core-types.h: include "pdb/pdb-types.h" so including "core/core-types.h" gets the whole core type space. * app/core/gimp.[ch]: added a "stack_trace_mode" parameter to the constructor and store it in the Gimp struct because the value is also passed to plug-ins and nobody should include "appenv.h". * app/gimprc.[ch]: pass the alternate_system_gimprc and alternate_gimprc filenames from the command line to gimprc_prase() so we don't need to include "appenv.h". * app/batch.[ch]: pass the "batch_cmds" as parameter, don't include "append.h". * app/app_procs.c: pass more parameters around. * app/devices.c * app/errors.c * app/gimphelp.c * app/main.c * app/core/gimpgradient.c * app/display/gimpdisplay.c * app/display/gimpdisplayshell.c * app/file/file-open.c * app/file/file-save.c * app/file/file-utils.c * app/gui/commands.c * app/gui/error-console-dialog.c * app/gui/file-dialog-utils.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/paths-dialog.c * app/gui/user-install-dialog.c * app/tools/gimpbezierselecttool.c * app/tools/xinput_airbrush.c * app/xcf/xcf.c * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/message.pdb * tools/pdbgen/pdb/plug_in.pdb: changed accordingly: - changed "plug-in.h" include where needed. - don't call gimp_fatal_error() directly, it's called via the log handler when calling g_error(). - don't incude "errors.h" except from main.c. - changed stack_trace and message_handler enum names. - get "stack_trace_mode" from Gimp. - removed many inclusions of "appenv.h". * app/pdb/fileops_cmds.c * app/pdb/help_cmds.c * app/pdb/message_cmds.c * app/pdb/plug_in_cmds.c * app/pdb/procedural_db.c: regenerated.
2001-12-01 08:14:14 +08:00
#include "file-utils.h"
#include "gimp-intl.h"
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
/* local function prototypes */
static PlugInProcDef * file_proc_find_by_prefix (GSList *procs,
const gchar *uri,
gboolean skip_magic);
static PlugInProcDef * file_proc_find_by_extension (GSList *procs,
const gchar *uri,
gboolean skip_magic);
static PlugInProcDef * file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic);
static void file_convert_string (gchar *instr,
gchar *outmem,
gint maxmem,
gint *nmem);
static gint file_check_single_magic (gchar *offset,
gchar *type,
gchar *value,
gint headsize,
guchar *file_head,
FILE *ifp);
static gint file_check_magic_list (GSList *magics_list,
gint headsize,
guchar *head,
FILE *ifp);
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
/* public functions */
gchar *
file_utils_filename_to_uri (GSList *procs,
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
const gchar *filename,
GError **error)
{
gchar *absolute;
gchar *uri;
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
g_return_val_if_fail (procs != NULL, NULL);
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
g_return_val_if_fail (filename != NULL, NULL);
/* check for prefixes like http or ftp */
if (file_proc_find_by_prefix (procs, filename, FALSE))
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
{
if (g_utf8_validate (filename, -1, NULL))
{
return g_strdup (filename);
}
else
{
libgimpwidgets/gimpquerybox.c configure the labels in the message dialog 2003-11-14 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpquerybox.c * app/widgets/gimpwidgets-utils.c: configure the labels in the message dialog and the query boxes to do automatic word wrapping to be HIG compliant. * app/app_procs.c * app/batch.c * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-path.c * app/config/gimpconfig-utils.c * app/config/gimpconfigwriter.c * app/config/gimpscanner.c * app/core/gimpbrush.c * app/core/gimpbrushgenerated.c * app/core/gimpbrushpipe.c * app/core/gimpdatafactory.c * app/core/gimpgradient.c * app/core/gimpimage-merge.c * app/core/gimpimage.c * app/core/gimpimagefile.c * app/core/gimplayer-floating-sel.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimpselection.c * app/display/gimpdisplayshell.c * app/file/file-utils.c * app/gui/brush-select.c * app/gui/dialogs-commands.c * app/gui/drawable-commands.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-select.c * app/gui/gui.c * app/gui/image-commands.c * app/gui/layers-commands.c * app/gui/palette-select.c * app/gui/palettes-commands.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/select-commands.c * app/gui/stroke-dialog.c * app/gui/tool-options-menu.c * app/gui/vectors-commands.c * app/gui/view-commands.c * app/plug-in/plug-in-message.c * app/plug-in/plug-in.c * app/plug-in/plug-ins.c * app/text/gimptextlayer-xcf.c * app/text/gimptextlayer.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimptransformtool.c * app/vectors/gimpvectors-export.c * app/widgets/gimpdatafactoryview.c * app/widgets/gimphelp.c * app/widgets/gimptemplateview.c * app/widgets/gimptooloptionseditor.c * app/xcf/xcf.c * tools/pdbgen/pdb/image.pdb: removed explicit newlines from messages. Reduced number of translatable strings by making many file error messages the same. Quote single words and filenames with 'foo', not "foo". Replaced some more "drawable" by "layer". General message cleanup and consistency check. * app/pdb/image_cmds.c: regenerated.
2003-11-14 23:33:40 +08:00
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
_("Invalid character sequence in URI"));
return NULL;
}
}
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
if (! g_path_is_absolute (filename))
{
gchar *current;
current = g_get_current_dir ();
absolute = g_build_filename (current, filename, NULL);
g_free (current);
}
else
{
absolute = g_strdup (filename);
}
uri = g_filename_to_uri (absolute, NULL, error);
g_free (absolute);
return uri;
}
PlugInProcDef *
file_utils_find_proc (GSList *procs,
const gchar *uri)
{
PlugInProcDef *file_proc;
GSList *all_procs = procs;
gchar *filename;
g_return_val_if_fail (procs != NULL, NULL);
g_return_val_if_fail (uri != NULL, NULL);
/* First, check magicless prefixes/suffixes */
file_proc = file_proc_find_by_name (all_procs, uri, TRUE);
if (file_proc)
return file_proc;
filename = g_filename_from_uri (uri, NULL, NULL);
/* Then look for magics */
if (filename)
{
PlugInProcDef *size_matched_proc = NULL;
FILE *ifp = NULL;
gint head_size = -2;
gint size_match_count = 0;
gint match_val;
guchar head[256];
while (procs)
{
file_proc = procs->data;
procs = procs->next;
if (file_proc->magics_list)
{
if (head_size == -2)
{
head_size = 0;
if ((ifp = fopen (filename, "rb")) != NULL)
head_size = fread ((gchar *) head, 1, sizeof (head), ifp);
}
if (head_size >= 4)
{
match_val = file_check_magic_list (file_proc->magics_list,
head_size, head, ifp);
if (match_val == 2) /* size match ? */
{ /* Use it only if no other magic matches */
size_match_count++;
size_matched_proc = file_proc;
}
else if (match_val)
{
fclose (ifp);
g_free (filename);
return file_proc;
}
}
}
}
if (ifp)
fclose (ifp);
g_free (filename);
if (size_match_count == 1)
return size_matched_proc;
}
/* As a last ditch, try matching by name */
return file_proc_find_by_name (all_procs, uri, FALSE);
}
gchar *
file_utils_uri_to_utf8_basename (const gchar *uri)
{
gchar *filename;
gchar *basename;
g_assert (uri != NULL);
g_return_val_if_fail (uri != NULL, NULL);
filename = file_utils_uri_to_utf8_filename (uri);
if (strstr (filename, G_DIR_SEPARATOR_S))
{
basename = g_path_get_basename (filename);
g_free (filename);
return basename;
}
else if (strstr (filename, "://"))
{
basename = strrchr (uri, '/');
basename = g_strdup (basename + 1);
g_free (filename);
return basename;
}
return filename;
}
gchar *
file_utils_uri_to_utf8_filename (const gchar *uri)
{
g_return_val_if_fail (uri != NULL, NULL);
if (! strncmp (uri, "file:", strlen ("file:")))
{
gchar *filename;
filename = g_filename_from_uri (uri, NULL, NULL);
if (filename)
{
gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
g_free (filename);
return utf8;
}
}
return g_strdup (uri);
}
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
/* private functions */
static PlugInProcDef *
file_proc_find_by_prefix (GSList *procs,
const gchar *uri,
gboolean skip_magic)
{
GSList *p;
for (p = procs; p; p = g_slist_next (p))
{
PlugInProcDef *proc = p->data;
GSList *prefixes;
if (skip_magic && proc->magics_list)
continue;
for (prefixes = proc->prefixes_list;
prefixes;
prefixes = g_slist_next (prefixes))
{
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
if (strncmp (uri, prefixes->data, strlen (prefixes->data)) == 0)
return proc;
}
}
return NULL;
}
static PlugInProcDef *
file_proc_find_by_extension (GSList *procs,
const gchar *uri,
gboolean skip_magic)
{
GSList *p;
gchar *ext;
ext = strrchr (uri, '.');
if (ext)
ext++;
for (p = procs; p; p = g_slist_next (p))
{
PlugInProcDef *proc = p->data;
GSList *extensions;
for (extensions = proc->extensions_list;
ext && extensions;
extensions = g_slist_next (extensions))
{
gchar *p1 = ext;
gchar *p2 = (gchar *) extensions->data;
if (skip_magic && proc->magics_list)
continue;
while (*p1 && *p2)
{
if (g_ascii_tolower (*p1) != g_ascii_tolower (*p2))
break;
p1++;
p2++;
}
if (!(*p1) && !(*p2))
return proc;
}
}
return NULL;
}
static PlugInProcDef *
file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic)
{
PlugInProcDef *proc;
proc = file_proc_find_by_prefix (procs, uri, skip_magic);
if (! proc)
proc = file_proc_find_by_extension (procs, uri, skip_magic);
return proc;
}
static void
file_convert_string (gchar *instr,
gchar *outmem,
gint maxmem,
gint *nmem)
{
/* Convert a string in C-notation to array of char */
guchar *uin = (guchar *) instr;
guchar *uout = (guchar *) outmem;
guchar tmp[5], *tmpptr;
guint k;
while ((*uin != '\0') && ((((gchar *) uout) - outmem) < maxmem))
{
if (*uin != '\\') /* Not an escaped character ? */
{
*(uout++) = *(uin++);
continue;
}
if (*(++uin) == '\0')
{
*(uout++) = '\\';
break;
}
switch (*uin)
{
case '0': case '1': case '2': case '3': /* octal */
for (tmpptr = tmp; (tmpptr-tmp) <= 3;)
{
*(tmpptr++) = *(uin++);
if ( (*uin == '\0') || (!g_ascii_isdigit (*uin))
|| (*uin == '8') || (*uin == '9'))
break;
}
*tmpptr = '\0';
sscanf ((gchar *) tmp, "%o", &k);
*(uout++) = k;
break;
case 'a': *(uout++) = '\a'; uin++; break;
case 'b': *(uout++) = '\b'; uin++; break;
case 't': *(uout++) = '\t'; uin++; break;
case 'n': *(uout++) = '\n'; uin++; break;
case 'v': *(uout++) = '\v'; uin++; break;
case 'f': *(uout++) = '\f'; uin++; break;
case 'r': *(uout++) = '\r'; uin++; break;
default : *(uout++) = *(uin++); break;
}
}
*nmem = ((gchar *) uout) - outmem;
}
static gint
file_check_single_magic (gchar *offset,
gchar *type,
gchar *value,
gint headsize,
guchar *file_head,
FILE *ifp)
{
/* Return values are 0: no match, 1: magic match, 2: size match */
glong offs;
gulong num_testval, num_operatorval;
gulong fileval;
gint numbytes, k, c = 0, found = 0;
gchar *num_operator_ptr, num_operator, num_test;
guchar mem_testval[256];
/* Check offset */
if (sscanf (offset, "%ld", &offs) != 1) return (0);
if (offs < 0) return (0);
/* Check type of test */
num_operator_ptr = NULL;
num_operator = '\0';
num_test = '=';
if (strncmp (type, "byte", 4) == 0)
{
numbytes = 1;
num_operator_ptr = type+4;
}
else if (strncmp (type, "short", 5) == 0)
{
numbytes = 2;
num_operator_ptr = type+5;
}
else if (strncmp (type, "long", 4) == 0)
{
numbytes = 4;
num_operator_ptr = type+4;
}
else if (strncmp (type, "size", 4) == 0)
{
numbytes = 5;
}
else if (strcmp (type, "string") == 0)
{
numbytes = 0;
}
else return (0);
/* Check numerical operator value if present */
if (num_operator_ptr && (*num_operator_ptr == '&'))
{
if (g_ascii_isdigit (num_operator_ptr[1]))
{
if (num_operator_ptr[1] != '0') /* decimal */
sscanf (num_operator_ptr+1, "%lu", &num_operatorval);
else if (num_operator_ptr[2] == 'x') /* hexadecimal */
sscanf (num_operator_ptr+3, "%lx", &num_operatorval);
else /* octal */
sscanf (num_operator_ptr+2, "%lo", &num_operatorval);
num_operator = *num_operator_ptr;
}
}
if (numbytes > 0) /* Numerical test ? */
{
/* Check test value */
if ((value[0] == '=') || (value[0] == '>') || (value[0] == '<'))
{
num_test = value[0];
value++;
}
if (!g_ascii_isdigit (value[0])) return (0);
/*
* to anybody reading this: is strtol's parsing behaviour
* (e.g. "0x" prefix) broken on some systems or why do we
* do the base detection ourselves?
* */
if (value[0] != '0') /* decimal */
num_testval = strtol(value, NULL, 10);
else if (value[1] == 'x') /* hexadecimal */
num_testval = (unsigned long)strtoul(value+2, NULL, 16);
else /* octal */
num_testval = strtol(value+1, NULL, 8);
fileval = 0;
if (numbytes == 5) /* Check for file size ? */
{
struct stat buf;
if (fstat (fileno (ifp), &buf) < 0) return (0);
fileval = buf.st_size;
}
else if (offs + numbytes <= headsize) /* We have it in memory ? */
{
for (k = 0; k < numbytes; k++)
fileval = (fileval << 8) | (long)file_head[offs+k];
}
else /* Read it from file */
{
if (fseek (ifp, offs, SEEK_SET) < 0) return (0);
for (k = 0; k < numbytes; k++)
fileval = (fileval << 8) | (c = getc (ifp));
if (c == EOF) return (0);
}
if (num_operator == '&')
fileval &= num_operatorval;
if (num_test == '<')
found = (fileval < num_testval);
else if (num_test == '>')
found = (fileval > num_testval);
else
found = (fileval == num_testval);
if (found && (numbytes == 5)) found = 2;
}
else if (numbytes == 0) /* String test */
{
file_convert_string ((char *)value, (char *)mem_testval,
sizeof (mem_testval), &numbytes);
if (numbytes <= 0) return (0);
if (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) return (0);
found = 1;
for (k = 0; found && (k < numbytes); k++)
{
c = getc (ifp);
found = (c != EOF) && (c == (int)mem_testval[k]);
}
}
}
return found;
}
Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. 2002-04-14 Michael Natterer <mitch@gimp.org> Use UTF-8 encoded escaped URIs for GimpImage and GimpImageFile. * app/file/file-open.[ch] * app/file/file-save.[ch] * app/file/file-utils.[ch]: port everything to using URIs, removed file_open_absolute_filename() and added file_utils_filename_to_uri() instead. * app/core/gimpimage.[ch]: added gimp_image_[get|set]_uri() which works like the old gimp_image_[get|set]_filename(). Changed gimp_image_[get|set]_filename() to call uri conversion functions. * app/app_procs.c: removed lots of code and use the new uri functions to open images passed on the command line. * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c: changed accordingly. * app/nav_window.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/info-window.c * app/gui/palette-import-dialog.c * app/tools/gimpbycolorselecttool.c * app/widgets/gimpcontainerview-utils.c: s/gimp_image_get_filename()/gimp_image_get_uri()/g. Need to add a utility function which returns the basename in unescaped UTF-8. * app/gui/file-commands.c * app/widgets/gimpdocumentview.c: use "uri", not "filename" as variable name where appropriate. * app/gui/menus.c: some broken code for the "Open Recent" items, will be fixed soon... * app/widgets/gimpdnd.c: evil (!!!) hackery to convert dropped filenames to uris. * tools/pdbgen/pdb/fileops.pdb: changed accordingly. Clarified the meaning of the "raw_filename" parameter. * tools/pdbgen/pdb/message.pdb: use g_message("%s", message), *not* g_message(message). * app/pdb/fileops_cmds.c * app/pdb/message_cmds.c * libgimp/gimpfileops_pdb.c: regenerated.
2002-04-14 22:38:55 +08:00
/*
* Return values are 0: no match, 1: magic match, 2: size match
*/
static gint
file_check_magic_list (GSList *magics_list,
gint headsize,
guchar *head,
FILE *ifp)
{
gchar *offset;
gchar *type;
gchar *value;
gint and = 0;
gint found = 0;
gint match_val;
while (magics_list)
{
if ((offset = (gchar *)magics_list->data) == NULL) break;
if ((magics_list = magics_list->next) == NULL) break;
if ((type = (gchar *)magics_list->data) == NULL) break;
if ((magics_list = magics_list->next) == NULL) break;
if ((value = (gchar *)magics_list->data) == NULL) break;
magics_list = magics_list->next;
match_val = file_check_single_magic (offset, type, value,
headsize, head, ifp);
if (and)
found = found && match_val;
else
found = match_val;
and = (strchr (offset, '&') != NULL);
if ((!and) && found)
return match_val;
}
return 0;
}