From 305ff4a7e0f878f0888f8b566f7d5689a6861fe9 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Thu, 31 Mar 2022 11:51:40 -0800 Subject: tinyrad: updating how prog_name is calculated --- src/tru/tinyradutil.c | 17 ++++++++++------- src/tru/widget-config.c | 4 ++-- src/tru/widget-dict.c | 4 ++-- src/tru/widget-url.c | 4 ++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/tru/tinyradutil.c b/src/tru/tinyradutil.c index a27b874..f0a17ac 100644 --- a/src/tru/tinyradutil.c +++ b/src/tru/tinyradutil.c @@ -160,6 +160,7 @@ int main(int argc, char * argv[]) TinyRadDict * dict; TinyRadUtilConf cnfdata; TinyRadUtilConf * cnf; + char prog_name[128]; // getopt options static char short_opt[] = "+" TRU_COMMON_SHORT; @@ -190,8 +191,8 @@ int main(int argc, char * argv[]) }; if ((argc - optind) < 1) { - fprintf(stderr, "%s: missing required argument\n", PROGRAM_NAME); - fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); + fprintf(stderr, "%s: missing required argument\n", cnf->prog_name); + fprintf(stderr, "Try `%s --help' for more information.\n", cnf->prog_name); return(1); }; @@ -202,10 +203,12 @@ int main(int argc, char * argv[]) // looks up widget if ((cnf->widget = tru_widget_lookup(argv[optind], TRAD_NO)) == NULL) { - fprintf(stderr, "%s: unknown or ambiguous widget -- \"%s\"\n", PROGRAM_NAME, cnf->argv[0]); - fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); + fprintf(stderr, "%s: unknown or ambiguous widget -- \"%s\"\n", cnf->prog_name, cnf->argv[0]); + fprintf(stderr, "Try `%s --help' for more information.\n", cnf->prog_name); return(1); }; + snprintf(prog_name, sizeof(prog_name), "%s %s", cnf->prog_name, argv[optind]); + cnf->prog_name = prog_name; }; // call widget @@ -335,12 +338,12 @@ tru_cli_parse( return(TRU_GETOPT_EXIT); case '?': - fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); + fprintf(stderr, "Try `%s --help' for more information.\n", cnf->prog_name); return(TRU_GETOPT_ERROR); default: - fprintf(stderr, "%s: unrecognized option `--%c'\n", PROGRAM_NAME, c); - fprintf(stderr, "Try `%s --help' for more information.\n", PROGRAM_NAME); + fprintf(stderr, "%s: unrecognized option `--%c'\n", cnf->prog_name, c); + fprintf(stderr, "Try `%s --help' for more information.\n", cnf->prog_name); return(TRU_GETOPT_ERROR); }; }; diff --git a/src/tru/widget-config.c b/src/tru/widget-config.c index cf52aec..1ff145a 100644 --- a/src/tru/widget-config.c +++ b/src/tru/widget-config.c @@ -66,8 +66,8 @@ tru_widget_config( return((rc == TRU_GETOPT_EXIT) ? 0 : 1); if (optind < cnf->argc) { - fprintf(stderr, "%s: unrecognized argument `-- %s'\n", PROGRAM_NAME, cnf->argv[optind+1]); - fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget_name); + fprintf(stderr, "%s: unrecognized argument `-- %s'\n", cnf->prog_name, cnf->argv[optind+1]); + fprintf(stderr, "Try `%s --help' for more information.\n", cnf->prog_name); return(1); }; diff --git a/src/tru/widget-dict.c b/src/tru/widget-dict.c index ac297d1..ff0165f 100644 --- a/src/tru/widget-dict.c +++ b/src/tru/widget-dict.c @@ -66,8 +66,8 @@ tru_widget_dict( return((rc == TRU_GETOPT_EXIT) ? 0 : 1); if (optind < cnf->argc) { - fprintf(stderr, "%s: unrecognized argument `-- %s'\n", PROGRAM_NAME, cnf->argv[optind+1]); - fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget_name); + fprintf(stderr, "%s: unrecognized argument `-- %s'\n", cnf->prog_name, cnf->argv[optind+1]); + fprintf(stderr, "Try `%s --help' for more information.\n", cnf->prog_name); return(1); }; diff --git a/src/tru/widget-url.c b/src/tru/widget-url.c index 4ff83d8..c712dda 100644 --- a/src/tru/widget-url.c +++ b/src/tru/widget-url.c @@ -109,8 +109,8 @@ tru_widget_url( return((rc == TRU_GETOPT_EXIT) ? 0 : 1); if ( (optind >= cnf->argc) && (!(cnf->url)) ) { - fprintf(stderr, "%s: missing required argument\n", PROGRAM_NAME); - fprintf(stderr, "Try `%s %s --help' for more information.\n", PROGRAM_NAME, cnf->widget_name); + fprintf(stderr, "%s: missing required argument\n", cnf->prog_name); + fprintf(stderr, "Try `%s --help' for more information.\n", cnf->prog_name); return(1); }; -- cgit v1.2.3