diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 88 |
1 files changed, 74 insertions, 14 deletions
@@ -31,10 +31,11 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <gtk/gtk.h> +#ifdef INCLUDE_GTK_SUPPORT +# include <gtk/gtk.h> +#endif -#include <config.h> #include <i18n.h> @@ -50,9 +51,11 @@ #include "core/paths.h" #include "core/queue.h" #include "glibext/delayed.h" -#include "gui/editor.h" -#include "gui/core/core.h" -#include "gui/core/global.h" +#ifdef INCLUDE_GTK_SUPPORT +# include "gui/editor.h" +# include "gui/core/core.h" +# include "gui/core/global.h" +#endif #include "plugins/pglist.h" @@ -63,9 +66,13 @@ static void show_chrysalide_help(const char *); /* Affiche des indications sur la version courante du programme. */ static void show_chrysalide_version(void); +#ifdef INCLUDE_GTK_SUPPORT + /* Recharge le dernier projet ouvert s'il existe. */ static gboolean load_last_project(GGenConfig *); +#endif + /* Ouvre les éventuels fichiers fournis au démarrage. */ static int open_binaries(char **, int); @@ -186,16 +193,20 @@ int main(int argc, char **argv) bool show_help; /* Affichage de l'aide ? */ bool show_version; /* Affichage de la version ? */ LogMessageType verbosity; /* Niveau de filtre de message */ +#ifdef INCLUDE_GTK_SUPPORT bool batch_mode; /* Exécution sans GUI ? */ +#endif bool save; /* Sauvegarde du cache ? */ char *prj_filename; /* Chemin vers un projet */ int index; /* Indice d'argument */ int ret; /* Bilan d'un appel */ char *edir; /* Répertoire de base effectif */ bool status; /* Bilan d'opérations */ +#ifdef INCLUDE_GTK_SUPPORT GtkWidget *editor; /* Fenêtre graphique */ GGenConfig *config; /* Configuration globale */ bool welcome; /* Affichage de la bienvenue ? */ +#endif char resolved[PATH_MAX]; /* Résolution de nom de fichier*/ GStudyProject *project; /* Nouveau projet courant */ @@ -225,7 +236,9 @@ int main(int argc, char **argv) show_version = false; verbosity = LMT_INFO; +#ifdef INCLUDE_GTK_SUPPORT batch_mode = false; +#endif save = false; prj_filename = NULL; @@ -249,7 +262,9 @@ int main(int argc, char **argv) break; case 'b': +#ifdef INCLUDE_GTK_SUPPORT batch_mode = true; +#endif break; case 's': @@ -294,11 +309,15 @@ int main(int argc, char **argv) /* Initialisation de GTK */ g_set_prgname("Chrysalide"); +#ifdef INCLUDE_GTK_SUPPORT gtk_init(&argc, &argv); +#endif /* Initialisation du programme */ +#ifdef INCLUDE_GTK_SUPPORT if (batch_mode) +#endif set_batch_mode(); set_log_verbosity(verbosity); @@ -308,6 +327,8 @@ int main(int argc, char **argv) /* Création de l'interface */ +#ifdef INCLUDE_GTK_SUPPORT + if (!batch_mode) { editor = create_editor(); @@ -330,8 +351,12 @@ int main(int argc, char **argv) else editor = NULL; +#endif + init_all_plugins(true); +#ifdef INCLUDE_GTK_SUPPORT + config = get_main_configuration(); if (!batch_mode) @@ -340,6 +365,8 @@ int main(int argc, char **argv) if (!status) goto exit_complete_gui; } +#endif + /* Lancement du serveur local */ status = ensure_internal_connections_setup(); @@ -354,6 +381,8 @@ int main(int argc, char **argv) /* Charge le dernier projet ? */ +#ifdef INCLUDE_GTK_SUPPORT + if (batch_mode) welcome = true; else @@ -363,6 +392,9 @@ int main(int argc, char **argv) g_idle_add((GSourceFunc)load_last_project, config); else + +#endif + { if (prj_filename != NULL) { @@ -382,7 +414,11 @@ int main(int argc, char **argv) if (ret == 0) { +#ifdef INCLUDE_GTK_SUPPORT project = g_study_project_open(prj_filename, !batch_mode); +#else + project = g_study_project_open(prj_filename, false); +#endif if (project == NULL) goto bad_project; } @@ -410,7 +446,12 @@ int main(int argc, char **argv) result = open_binaries(argv + optind, argc - optind); +#ifdef INCLUDE_GTK_SUPPORT + if (batch_mode) + +#endif + { wait_for_all_global_works(); @@ -422,22 +463,28 @@ int main(int argc, char **argv) } +#ifdef INCLUDE_GTK_SUPPORT + else gtk_main(); +#endif + set_current_project(NULL); bad_project: no_internal_server: +#ifdef INCLUDE_GTK_SUPPORT exit_complete_gui: +#endif #ifdef TRACK_GOBJECT_LEAKS remember_gtypes_for_leaks(); #endif - exit_all_plugins(); +#ifdef INCLUDE_GTK_SUPPORT if (!batch_mode) unload_all_gui_components(); @@ -449,12 +496,16 @@ int main(int argc, char **argv) failed_to_load_editor: +#endif + unload_all_core_components(true); #ifdef TRACK_GOBJECT_LEAKS dump_remaining_gtypes(); #endif + exit_all_plugins(); + done: return result; @@ -462,6 +513,9 @@ int main(int argc, char **argv) } +#ifdef INCLUDE_GTK_SUPPORT + + /****************************************************************************** * * * Paramètres : cfg = configuration globale sur laquelle s'appuyer. * @@ -492,6 +546,9 @@ static gboolean load_last_project(GGenConfig *cfg) } +#endif + + /****************************************************************************** * * * Paramètres : files = noms de fichier fournis en ligne de commande. * @@ -511,7 +568,7 @@ static int open_binaries(char **files, int count) GStudyProject *project; /* Projet courant à compléter */ int i; /* Boucle de parcours */ GContentAttributes *attribs; /* Attributs à lier au contenu */ - const char *filename; /* Chemin d'accès au contenu */ + char *filename; /* Chemin d'accès au contenu */ GBinContent *content; /* Contenu binaire à charger */ result = EXIT_SUCCESS; @@ -520,11 +577,15 @@ static int open_binaries(char **files, int count) for (i = 0; i < count && result == EXIT_SUCCESS; i++) { - attribs = g_content_attributes_new(files[i]); - - filename = g_content_attributes_get_filename(attribs); + attribs = g_content_attributes_new(files[i], &filename); - content = g_file_content_new(filename); + if (filename == NULL) + content = NULL; + else + { + content = g_file_content_new(filename); + free(filename); + } if (content != NULL) { @@ -536,10 +597,9 @@ static int open_binaries(char **files, int count) } else - { - g_object_unref(G_OBJECT(attribs)); result = EXIT_FAILURE; - } + + g_object_unref(G_OBJECT(attribs)); } |