From 803524799631bcc96ee1fa7e194516fb23d8d9b3 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Tue, 9 Jan 2018 14:27:48 +0100 Subject: Implementing option --help handling --- src/main.c | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main.c b/src/main.c index 86f071d..7757f9a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,25 +1,50 @@ #include #include +#include +#include #include "gui/gui.h" #include "MLV/MLV_path.h" int main(int argc, char **argv) { - if (argc < 3) { - fprintf(stderr, "Not enough argument (2 correct pathfiles required)\n"); - exit(-1); - } - if (argc > 3) { - fprintf(stderr, "Too much arguments (2 correct pathfiles required)\n"); - exit(-2); - } - if (!(MLV_path_is_a_file(argv[1])) || !(MLV_path_is_a_file(argv[2]))) { - fprintf(stderr, "One path is incorrect\n"); - exit(-3); + int opt = 0; + int help = -1; + static struct option long_options[] = { + {"help", 0, 0, 'h'}, + {0, 0, 0, 0} }; - GUI *gui = gui_create(argv[1], argv[2]); - while (mode != EXITING) { - gui_handle_event(gui); + int long_index = 0; + /*Option handling*/ + while ((opt = getopt_long_only(argc, argv, "h", long_options, &long_index)) != -1) { + switch (opt) { + case 'h': + help = 0; + break; + default: + exit(EXIT_FAILURE); + } + } + if (help == 0) { + printf( + "--Morphing's Help--\nTo use the morphing, you need to put two correct paths to image files.\n\nCorrect image format :\nICO(Icon)/CUR(Cursor)/BMP, PNM (PPM/PGM/PBM), XPM, LBM(IFF ILBM), PCX, GIF, JPEG, PNG, TGA, TIFF, and XV.\n\nMorphing made by:\n Pacien TRAN-GIRARD and Adam NAILI\n"); + } else { + int nbArg = argc - optind; + if (nbArg < 2) { + fprintf(stderr, "Not enough argument (2 correct pathfiles required)\n"); + exit(-1); + } + if (nbArg > 2) { + fprintf(stderr, "Too much arguments (2 correct pathfiles required)\n"); + exit(-2); + } + if (!(MLV_path_is_a_file(argv[optind])) || !(MLV_path_is_a_file(argv[optind + 1]))) { + fprintf(stderr, "One path is incorrect\n"); + exit(-3); + }; + GUI *gui = gui_create(argv[optind], argv[optind + 1]); + while (mode != EXITING) { + gui_handle_event(gui); + } + gui_destroy(gui); } - gui_destroy(gui); - return 0; + exit(EXIT_SUCCESS); } -- cgit v1.2.3