diff options
author | midipix <writeonce@midipix.org> | 2015-11-22 01:03:06 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-11-10 23:35:25 -0500 |
commit | 5888e8c839f0aff24d63b5581ed902da47ba36c3 (patch) | |
tree | c6d70e5f4f5259d0c18589748b9dbfa055cc5c5b | |
parent | ab024a80297e6c3ea6a7a0d77b5a8d51800ba203 (diff) | |
download | perk-5888e8c839f0aff24d63b5581ed902da47ba36c3.tar.bz2 perk-5888e8c839f0aff24d63b5581ed902da47ba36c3.tar.xz |
driver integration 4/9: argument vector parser: derive program name as needed.
-rw-r--r-- | src/internal/argv/argv.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/internal/argv/argv.h b/src/internal/argv/argv.h index 4749769..0cb3c40 100644 --- a/src/internal/argv/argv.h +++ b/src/internal/argv/argv.h @@ -82,6 +82,8 @@ struct argv_ctx { const char * program; }; +static const char * argv_program_name(const char *); + static void argv_usage( FILE *, const char * header, @@ -377,6 +379,21 @@ static void argv_scan( } } +static const char * argv_program_name(const char * program_path) +{ + const char * ch; + + if (program_path) { + if ((ch = strrchr(program_path,'/'))) + return *(++ch) ? ch : 0; + + if ((ch = strrchr(program_path,'\\'))) + return *(++ch) ? ch : 0; + } + + return program_path; +} + static void argv_show_error(struct argv_ctx * ctx) { fprintf(stderr,"%s: error: ",ctx->program); @@ -538,8 +555,12 @@ static struct argv_meta * argv_get( argv_scan(argv,options,&ctx,0); if (ctx.errcode != ARGV_ERROR_OK) { + if (!ctx.program) + ctx.program = argv_program_name(argv[0]); + if (ctx.flags & ARGV_VERBOSITY_ERRORS) argv_show_error(&ctx); + return 0; } |