From 8ccbb6548b615e81dc6c1f39162effc36f4d844b Mon Sep 17 00:00:00 2001 From: louie Date: Sun, 12 May 2024 23:34:53 -0400 Subject: Add version flag --- src/Makefile.in | 3 ++- src/draw.c | 35 +++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Makefile.in b/src/Makefile.in index 231c8c0..c64fb8a 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -100,6 +100,7 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" @@ -135,7 +136,7 @@ AM_V_at = $(am__v_at_@AM_V@) am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) am__v_at_0 = @ am__v_at_1 = -DEFAULT_INCLUDES = -I.@am__isrc@ +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__maybe_remake_depfiles = depfiles am__depfiles_remade = \ diff --git a/src/draw.c b/src/draw.c index 894f6f2..16e9596 100644 --- a/src/draw.c +++ b/src/draw.c @@ -7,6 +7,7 @@ #include +#include "config.h" #include "include/cache.h" #include "include/draw.h" #include "include/entry.h" @@ -20,6 +21,7 @@ bool *handle_args(int argc, char **argv, char **cfg_path); void print_help(char *exec_name); +void print_version(); void update_display(bool resize); void draw_title(); void draw_win(WINDOW *new, char *title); @@ -62,6 +64,7 @@ int main(int argc, char **argv){ } if(flags_set[1]) return(0); //exit if help flag was passed if(flags_set[2]) freopen("/dev/null", "w", stdout); //turn off output if quiet flag was passed + if(flags_set[3]) return(0); // exit if version flag was passed if(!flags_set[0]) strcpy(cfg_path, find_config()); //find_config if not config flag was passed //Fill Groups @@ -193,19 +196,21 @@ bool *handle_args(int argc, char **argv, char **cfg_path){ // 0 -> -c|--config // 1 -> -h|--help // 2 -> -q|--quiet + // 3 -> -v|--version int opt = 0; struct option long_options[] = { - {"config", required_argument, NULL, 'c'}, - {"help", no_argument, NULL, 'h'}, - {"quiet", no_argument, NULL, 'q'}, - {0, 0, 0, 0} + {"config", required_argument, NULL, 'c'}, + {"help", no_argument, NULL, 'h'}, + {"quiet", no_argument, NULL, 'q'}, + {"version", no_argument, NULL, 'v'}, + {0, 0, 0, 0} }; bool *flags_set = calloc(FLAG_COUNT, sizeof(bool)); int i = 0; while(opt != -1){ - opt = getopt_long(argc, argv, "c:hq", long_options, &i); + opt = getopt_long(argc, argv, "c:hqv", long_options, &i); switch(opt){ case 0: printf("Unknown long option '%s'", long_options[i].name); @@ -225,6 +230,11 @@ bool *handle_args(int argc, char **argv, char **cfg_path){ case 'q': flags_set[2] = true; break; + case 'v': + print_version(); + flags_set[3] = true; + opt = -1; // break out of the while loop + break; case '?': return NULL; // error parsing arguments case -1: @@ -241,9 +251,18 @@ void print_help(char *exec_name){ printf("Usage: %s [OPTION]\n", exec_name); printf("Draw an Ncurses Menu to Launch Media from\n\n"); - printf(" -c, --config=FILE Specify a configuration file path\n"); - printf(" -h, --help Print this help message\n"); - printf(" -q, --quiet Suppress stdout messages\n"); + printf(" -c, --config=FILE Specify a configuration file path\n"); + printf(" -h, --help Print this help message\n"); + printf(" -q, --quiet Suppress stdout messages\n"); + printf(" -v, --version Print version information and exit\n"); +} + +void print_version() { + printf("%s\n", PACKAGE_STRING); + printf("Copyright (C) Louie S.\n"); + printf("License GPLv3: GNU GPL version 3 \n"); + printf("\n"); + printf("Written by Louie S.\n"); } void update_display(bool resize){ -- cgit