]> git.mdlowis.com Git - projs/opts.git/commitdiff
Added interface function for grabbing the program name from the command line options
authorMichael D. Lowis <mike.lowis@gentex.com>
Mon, 3 Nov 2014 21:40:47 +0000 (16:40 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Mon, 3 Nov 2014 21:40:47 +0000 (16:40 -0500)
source/opts.c
source/opts.h

index f4e77d09c8024dd4d41124df93816a5d36a48bc4..ad13f273fd6afe71b5095b95095a967bf5c1f8ed 100755 (executable)
@@ -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) {
index 1fdeb6a81b831a66c25788094454f97f7d31a8e5..e686b62ffb46ceb8d0d06d37effd81cd1811fbf5 100755 (executable)
@@ -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