From 4ffb572c4d6fdd429acc7e440de0cd2e98df9d50 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Fri, 2 Jun 2017 19:24:34 +0200 Subject: Cleaned the code of the entry point. --- ChangeLog | 5 +++ src/main.c | 140 ++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 101 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index fab1917..99f4354 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +17-06-02 Cyrille Bagard + + * src/main.c: + Clean the code of the entry point. + 17-05-23 Cyrille Bagard * src/analysis/disass/area.c: diff --git a/src/main.c b/src/main.c index 60bfd0f..9002ed9 100644 --- a/src/main.c +++ b/src/main.c @@ -22,6 +22,7 @@ */ +#include #include #include #include @@ -35,21 +36,51 @@ #include "core/core.h" #include "core/params.h" #include "glibext/delayed.h" -#include "glibext/gbinportion.h" #include "gui/editor.h" #include "gui/core/core.h" #include "gui/core/global.h" #include "plugins/pglist.h" -// TODO : remme! -#include "format/mangling/itanium/abi.h" -#include "analysis/db/cdb.h" + +/* Affiche des indications quant à l'utilisation du programme. */ +static void show_chrysalide_help(const char *); + +/* Affiche des indications sur la version courante du programme. */ +static void show_chrysalide_version(void); /****************************************************************************** * * +* Paramètres : name = nom du programme en question. * +* * +* Description : Affiche des indications quant à l'utilisation du programme. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void show_chrysalide_help(const char *name) +{ + printf("\n"); + + printf("Usage: %s [--help] [--version]\n", name); + + printf("\n"); + + printf("\t--help\t\tShow this help message.\n"); + printf("\t--version\tDisplay the program version.\n"); + + printf("\n"); + +} + + +/****************************************************************************** +* * * Paramètres : - * * * * Description : Affiche des indications sur la version courante du programme.* @@ -60,7 +91,7 @@ * * ******************************************************************************/ -static void show_version(void) +static void show_chrysalide_version(void) { printf("\n"); @@ -94,6 +125,10 @@ static void show_version(void) int main(int argc, char **argv) { int result; /* Bilan de l'exécution */ + bool show_help; /* Affichage de l'aide ? */ + bool show_version; /* Affichage de la version ? */ + int index; /* Indice d'argument */ + int ret; /* Bilan d'un appel */ GtkWidget *editor; /* Fenêtre graphique */ GDbServer *server; /* Enregistrements locaux */ GGenConfig *config; /* Configuration globale */ @@ -105,65 +140,80 @@ int main(int argc, char **argv) bool welcome; /* Affichage de la bienvenue ? */ + static struct option long_options[] = { + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, + { NULL, 0, NULL, 0 } + }; + result = EXIT_FAILURE; - if (argc > 1 && strcmp(argv[1], "--version") == 0) - { - show_version(); - return EXIT_SUCCESS; - } + /** + * Initialisation de la bibliothèque et validation des correspondances + * d'ABI entre la version du moment de la compilation et celle présente + * sur le système courant. + */ + LIBXML_TEST_VERSION; - setlocale(LC_ALL, ""); - bindtextdomain(PACKAGE, LOCALE_DIR); - textdomain(PACKAGE); + /* Décodage des options */ - /* Initialisation de GTK */ - g_set_prgname("Chrysalide"); - setlocale (LC_ALL, ""); - gtk_init(&argc, &argv); + show_help = false; + show_version = false; - /* Initialisation du programme */ - if (!load_all_basic_components()) - return EXIT_FAILURE; + while (true) + { + ret = getopt_long(argc, argv, "hv", long_options, &index); + if (ret == -1) break; - /* - * this initialize the library and check potential ABI mismatches - * between the version it was compiled for and the actual shared - * library used. - */ - /*LIBXML_TEST_VERSION*/ + switch (ret) + { + case 'h': + show_help = true; + break; - //add_pixmap_directory(PACKAGE_DATA_DIR); - //add_pixmap_directory(PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "pixmaps"); + case 'v': + show_version = true; + break; - /* Création de l'interface */ + } - //test_itanium(); - //exit(-1); + } + /* Actions de base */ -#if 0 - do + if (show_help) { - core_db_info info; + show_chrysalide_help(argv[0]); + result = EXIT_SUCCESS; + goto done; + } - strcpy(info.hash, "47cd68c5c46f36a5d48ebf347d6558a8eee23e11f9420227935658c3e97b6e27"); + if (show_version) + { + show_chrysalide_version(); + result = EXIT_SUCCESS; + goto done; + } + /* Lancement des choses sérieuses */ - GCdbArchive *archive = g_cdb_archive_new(true, NULL, &info); + setlocale(LC_ALL, ""); + bindtextdomain(PACKAGE, LOCALE_DIR); + textdomain(PACKAGE); - printf("written ? %d\n", - g_cdb_archive_write(archive) - ); + /* Initialisation de GTK */ + g_set_prgname("Chrysalide"); + setlocale (LC_ALL, ""); + gtk_init(&argc, &argv); + /* Initialisation du programme */ + if (!load_all_basic_components()) + return EXIT_FAILURE; - exit(0); + /* Création de l'interface */ - } - while (0); -#endif editor = create_editor(); @@ -233,12 +283,14 @@ int main(int argc, char **argv) exit_all_plugins(); - //gtk_widget_destroy(editor); + gtk_widget_destroy(editor); failed_to_load_editor: unload_all_basic_components(); + done: + return result; } -- cgit v0.11.2-87-g4458