From: Michael D. Lowis Date: Mon, 3 Nov 2014 21:40:47 +0000 (-0500) Subject: Added interface function for grabbing the program name from the command line options X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=ab5becaf6e61ddbc8efacd3cd53bd4121bd559c0;p=projs%2Fopts.git Added interface function for grabbing the program name from the command line options --- diff --git a/source/opts.c b/source/opts.c index f4e77d0..ad13f27 100755 --- a/source/opts.c +++ b/source/opts.c @@ -25,6 +25,7 @@ typedef struct { opts_cfg_t* options; } StreamContext_T; +static const char* Program_Name = NULL; static entry_t* Options = NULL; static entry_t* Arguments = NULL; @@ -49,11 +50,14 @@ void opts_parse( opts_cfg_t* opts, int argc, char** argv ) { StreamContext_T ctx; ctx.line_idx = 0; ctx.col_idx = -1; - ctx.arg_count = argc; - ctx.arg_vect = argv; + ctx.arg_count = argc-1; + ctx.arg_vect = &argv[1]; ctx.options = opts; (void)opts_next_char( &ctx ); /* Loads up the first char */ + /* Record the program name */ + Program_Name = argv[0]; + /* Until we run out of characters */ while (ctx.current != EOF) { opts_consume_ws( &ctx ); @@ -307,6 +311,10 @@ const char** opts_arguments(void) { return ret; } +const char* opts_prog_name(void) { + return Program_Name; +} + /*****************************************************************************/ static int opts_calc_padding(opts_cfg_t* opts) { diff --git a/source/opts.h b/source/opts.h index 1fdeb6a..e686b62 100755 --- a/source/opts.h +++ b/source/opts.h @@ -29,6 +29,8 @@ const char** opts_select(const char* name, const char* tag); const char** opts_arguments(void); +const char* opts_prog_name(void); + void opts_print_help(FILE* ofile, opts_cfg_t* opts); #ifdef __cplusplus