summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac16
-rw-r--r--src/core/Makefile.am1
-rw-r--r--src/core/core.c4
-rw-r--r--src/core/paths.c157
-rw-r--r--src/core/paths.h37
-rw-r--r--src/glibext/gbufferline.c2
-rw-r--r--src/glibext/linesegment.c3
-rw-r--r--src/gtkext/support.c72
-rw-r--r--src/gtkext/support.h6
-rw-r--r--src/gui/dialogs/about.c2
-rw-r--r--src/gui/dialogs/gotox.c2
-rw-r--r--src/gui/panels/bookmarks.c2
-rw-r--r--src/gui/panels/errors.c2
-rw-r--r--src/gui/panels/symbols.c2
-rw-r--r--src/gui/panels/welcome.c2
15 files changed, 223 insertions, 87 deletions
diff --git a/configure.ac b/configure.ac
index f1ac211..3bb72c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -154,14 +154,16 @@ fi
############################################################
AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [compile with debugging support [default=no]]),
- [enable_debug=yes], [enable_debug=no])
+ [], [enable_debug=no])
+
+AC_ARG_WITH(local-resources,
+ AS_HELP_STRING([--with-local-resources], [discard resources from local sources [default=yes]]),
+ [], [with_local_resources=yes])
#--- Small enumerations
CFLAGS="$CFLAGS -fshort-enums -D_LARGEFILE64_SOURCE"
-AC_SUBST(CFLAGS)
-
#--- Is debug mode needed ?
if test "x$enable_debug" = "xyes"; then
@@ -172,6 +174,14 @@ fi
AC_SUBST(DEBUG_CFLAGS)
+#--- Discard local sources when looking for resources ?
+
+if test "x$with_local_resources" = "xno"; then
+ CFLAGS="$CFLAGS -DDISCARD_LOCAL"
+fi
+
+AC_SUBST(CFLAGS)
+
#--- Compilation warnings
#-Wall -Wimplicit -Wreturn-type -Wunused -Wswitch -Wcomment -Wuninitialized -Wparentheses -Wpointer-arith -Wmissing-prototypes
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 4dcf6e7..89dd345 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -10,6 +10,7 @@ libcore_la_SOURCES = \
logs.h logs.c \
nproc.h nproc.c \
params.h params.c \
+ paths.h paths.c \
processors.h processors.c \
queue.h queue.c
diff --git a/src/core/core.c b/src/core/core.c
index bc1a9dc..3f0d244 100644
--- a/src/core/core.c
+++ b/src/core/core.c
@@ -44,7 +44,6 @@
#include "../common/io.h"
#include "../common/xdg.h"
#include "../glibext/linesegment.h"
-#include "../gtkext/support.h"
@@ -76,9 +75,6 @@ bool load_all_basic_components(void)
srand(time(NULL) + getpid());
- add_pixmap_directory(PIXMAPS_DIR);
- add_pixmap_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps");
-
cfgdir = get_xdg_config_dir("chrysalide" G_DIR_SEPARATOR_S "chrysalide");
result &= (ensure_path_exists(cfgdir) == 0);
free(cfgdir);
diff --git a/src/core/paths.c b/src/core/paths.c
new file mode 100644
index 0000000..13b9cbe
--- /dev/null
+++ b/src/core/paths.c
@@ -0,0 +1,157 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * paths.c - récupération de fichiers secondaires
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "paths.h"
+
+
+#include <glib.h>
+#include <malloc.h>
+#include <stdio.h>
+#include <unistd.h>
+
+
+#include <config.h>
+
+
+
+/* Trouve le chemin d'accès complet à un fichier donné. */
+static char *find_file_in_directory(const char *, const char *);
+
+
+
+/******************************************************************************
+* *
+* Paramètres : dirname = répertoire de travail à fouiller. *
+* filename = nom de fichier seul comme indice. *
+* *
+* Description : Trouve le chemin d'accès complet à un fichier donné. *
+* *
+* Retour : Chemin trouvé à libérer de la mémoire ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static char *find_file_in_directory(const char *dirname, const char *filename)
+{
+ char *result; /* Trouvaille à renvoyer */
+ int ret; /* Bilan du test de présence */
+
+ asprintf(&result, "%s%s%s", dirname, G_DIR_SEPARATOR_S, filename);
+
+ ret = access(result, F_OK);
+
+ if (ret != 0)
+ {
+ free(result);
+ result = NULL;
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : filename = nom de fichier seul comme indice. *
+* *
+* Description : Trouve le chemin d'accès complet à un fichier d'image. *
+* *
+* Retour : Chemin trouvé à libérer de la mémoire ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *find_pixmap_file(const char *filename)
+{
+ char *result; /* Trouvaille à renvoyer */
+
+ /**
+ * On privilégie si possible les sources fraiches.
+ */
+
+#ifndef DISCARD_LOCAL
+
+ result = find_file_in_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps", filename);
+
+#else
+
+ result = NULL;
+
+#endif
+
+ if (result == NULL)
+ result = find_file_in_directory(PIXMAPS_DIR, filename);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : pgname = nom du greffon concerné. *
+* filename = nom de fichier seul comme indice. *
+* *
+* Description : Trouve le chemin d'accès complet à un fichier de greffon. *
+* *
+* Retour : Chemin trouvé à libérer de la mémoire ou NULL. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+char *find_plugin_file(const char *pgname, const char *filename)
+{
+ char *result; /* Trouvaille à renvoyer */
+#ifndef DISCARD_LOCAL
+ char *dirname; /* Répertoire à cibler */
+#endif
+
+ /**
+ * On privilégie si possible les sources fraiches.
+ */
+
+#ifndef DISCARD_LOCAL
+
+ asprintf(&dirname, "%s%splugins%s%s%s%s",
+ PACKAGE_SOURCE_DIR, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S, pgname, G_DIR_SEPARATOR_S, filename);
+
+ result = find_file_in_directory(dirname, filename);
+
+ free(dirname);
+
+#else
+
+ result = NULL;
+
+#endif
+
+ if (result == NULL)
+ result = find_file_in_directory(PLUGINS_DIR, filename);
+
+ return result;
+
+}
diff --git a/src/core/paths.h b/src/core/paths.h
new file mode 100644
index 0000000..c16a278
--- /dev/null
+++ b/src/core/paths.h
@@ -0,0 +1,37 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * paths.h - prototypes pour la récupération de fichiers secondaires
+ *
+ * Copyright (C) 2018 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * Chrysalide 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Chrysalide 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _CORE_PATHS_H
+#define _CORE_PATHS_H
+
+
+
+/* Trouve le chemin d'accès complet à un fichier d'image. */
+char *find_pixmap_file(const char *);
+
+/* Trouve le chemin d'accès complet à un fichier de greffon. */
+char *find_plugin_file(const char *, const char *);
+
+
+
+#endif /* _CORE_PATHS_H */
diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c
index 7c49163..95af21a 100644
--- a/src/glibext/gbufferline.c
+++ b/src/glibext/gbufferline.c
@@ -32,7 +32,7 @@
#include "chrysamarshal.h"
#include "linecolumn.h"
#include "../common/extstr.h"
-#include "../gtkext/support.h"
+#include "../core/paths.h"
diff --git a/src/glibext/linesegment.c b/src/glibext/linesegment.c
index 7f1afa4..373d744 100644
--- a/src/glibext/linesegment.c
+++ b/src/glibext/linesegment.c
@@ -30,11 +30,12 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
+#include <gtk/gtk.h>
#include "../common/extstr.h"
#include "../common/fnv1a.h"
-#include "../gtkext/support.h"
+#include "../core/paths.h"
diff --git a/src/gtkext/support.c b/src/gtkext/support.c
index 645bce7..70e1f9a 100644
--- a/src/gtkext/support.c
+++ b/src/gtkext/support.c
@@ -25,71 +25,11 @@
#include "support.h"
-#include <glib.h>
-#include <string.h>
+#include <malloc.h>
+#include "../core/paths.h"
-/* Liste des répertoires contenant des images */
-static GList *pixmaps_directories = NULL;
-
-
-
-/******************************************************************************
-* *
-* Paramètres : directory = nouveau répertoire à parcourir. *
-* *
-* Description : Ajoute un répertoire à la liste des répertoires d'images. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void add_pixmap_directory(const char *directory)
-{
- pixmaps_directories = g_list_prepend(pixmaps_directories,
- strdup(directory));
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : filename = nom de fichier seul comme indice. *
-* *
-* Description : Trouve le chemin d'accès complet à un fichier donné. *
-* *
-* Retour : Chemin trouvé à libérer de la mémoire ou NULL. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-gchar *find_pixmap_file(const char *filename)
-{
- gchar *result; /* Trouvaille à renvoyer */
- GList *iter; /* Boucle de parcours */
-
- result = NULL;
-
- for (iter = pixmaps_directories; iter != NULL && result == NULL; iter = iter->next)
- {
- result = g_strdup_printf("%s%s%s", (gchar *)iter->data,
- G_DIR_SEPARATOR_S, filename);
-
- if (!g_file_test(result, G_FILE_TEST_EXISTS))
- {
- g_free(result);
- result = NULL;
- }
-
- }
-
- return result;
-
-}
/******************************************************************************
@@ -107,14 +47,14 @@ gchar *find_pixmap_file(const char *filename)
GtkWidget *get_image_from_file(const char *filename)
{
GtkWidget *result; /* Instance à retourner */
- gchar *fullname; /* Chemin d'accès complet */
+ char *fullname; /* Chemin d'accès complet */
fullname = find_pixmap_file(filename);
if (fullname != NULL)
{
result = gtk_image_new_from_file(fullname);
- g_free(fullname);
+ free(fullname);
gtk_widget_show(result);
@@ -141,14 +81,14 @@ GtkWidget *get_image_from_file(const char *filename)
GdkPixbuf *get_pixbuf_from_file(const char *filename)
{
GdkPixbuf *result; /* Instance à retourner */
- gchar *fullname; /* Chemin d'accès complet */
+ char *fullname; /* Chemin d'accès complet */
fullname = find_pixmap_file(filename);
if (fullname != NULL)
{
result = gdk_pixbuf_new_from_file(fullname, NULL);
- g_free(fullname);
+ free(fullname);
}
else result = NULL;
diff --git a/src/gtkext/support.h b/src/gtkext/support.h
index 00a340c..0725f74 100644
--- a/src/gtkext/support.h
+++ b/src/gtkext/support.h
@@ -30,12 +30,6 @@
-/* Ajoute un répertoire à la liste des répertoires d'images. */
-void add_pixmap_directory(const char *);
-
-/* Trouve le chemin d'accès complet à un fichier donné. */
-gchar *find_pixmap_file(const char *);
-
/* Construit une image à partir d'un nom de fichier. */
GtkWidget *get_image_from_file(const char *);
diff --git a/src/gui/dialogs/about.c b/src/gui/dialogs/about.c
index 7e62269..0acba30 100644
--- a/src/gui/dialogs/about.c
+++ b/src/gui/dialogs/about.c
@@ -33,8 +33,8 @@
#include <i18n.h>
+#include "../../core/paths.h"
#include "../../gtkext/easygtk.h"
-#include "../../gtkext/support.h"
diff --git a/src/gui/dialogs/gotox.c b/src/gui/dialogs/gotox.c
index 7ae1244..d9a9979 100644
--- a/src/gui/dialogs/gotox.c
+++ b/src/gui/dialogs/gotox.c
@@ -31,10 +31,10 @@
#include <i18n.h>
+#include "../../core/paths.h"
#include "../../format/format.h"
#include "../../format/symiter.h"
#include "../../gtkext/easygtk.h"
-#include "../../gtkext/support.h"
diff --git a/src/gui/panels/bookmarks.c b/src/gui/panels/bookmarks.c
index 104e519..fd8af25 100644
--- a/src/gui/panels/bookmarks.c
+++ b/src/gui/panels/bookmarks.c
@@ -41,12 +41,12 @@
#include "../../common/cpp.h"
#include "../../common/extstr.h"
#include "../../core/params.h"
+#include "../../core/paths.h"
#include "../../core/queue.h"
#include "../../glibext/chrysamarshal.h"
#include "../../glibext/signal.h"
#include "../../gtkext/easygtk.h"
#include "../../gtkext/gtkdockable-int.h"
-#include "../../gtkext/support.h"
diff --git a/src/gui/panels/errors.c b/src/gui/panels/errors.c
index 161d1ab..5873ad5 100644
--- a/src/gui/panels/errors.c
+++ b/src/gui/panels/errors.c
@@ -37,10 +37,10 @@
#include "updating-int.h"
#include "../core/global.h"
#include "../../core/global.h"
+#include "../../core/paths.h"
#include "../../core/queue.h"
#include "../../format/format.h"
#include "../../glibext/signal.h"
-#include "../../gtkext/support.h"
diff --git a/src/gui/panels/symbols.c b/src/gui/panels/symbols.c
index fab82a9..94605b3 100644
--- a/src/gui/panels/symbols.c
+++ b/src/gui/panels/symbols.c
@@ -40,11 +40,11 @@
#include "updating-int.h"
#include "../core/global.h"
#include "../../common/extstr.h"
+#include "../../core/paths.h"
#include "../../core/queue.h"
#include "../../format/format.h"
#include "../../format/symiter.h"
#include "../../gtkext/easygtk.h"
-#include "../../gtkext/support.h"
#include "../../gtkext/tmgt.h"
diff --git a/src/gui/panels/welcome.c b/src/gui/panels/welcome.c
index eeff152..fc4b314 100644
--- a/src/gui/panels/welcome.c
+++ b/src/gui/panels/welcome.c
@@ -44,7 +44,7 @@
#include "../../common/shuffle.h"
#include "../../core/global.h"
#include "../../core/params.h"
-#include "../../gtkext/support.h"
+#include "../../core/paths.h"