aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/otputil.c38
-rw-r--r--src/otputil.h4
2 files changed, 30 insertions, 12 deletions
diff --git a/src/otputil.c b/src/otputil.c
index 628fdf6..03ac39a 100644
--- a/src/otputil.c
+++ b/src/otputil.c
@@ -314,8 +314,9 @@ main(
314 // skip argument processing if called via alias 314 // skip argument processing if called via alias
315 if ((cnf->widget = otputil_widget_lookup(cnf->prog_name, 1)) != NULL) 315 if ((cnf->widget = otputil_widget_lookup(cnf->prog_name, 1)) != NULL)
316 { 316 {
317 cnf->argc = argc; 317 cnf->argc = argc;
318 cnf->argv = argv; 318 cnf->argv = argv;
319 cnf->symlinked = 1;
319 return(cnf->widget->func_exec(cnf)); 320 return(cnf->widget->func_exec(cnf));
320 }; 321 };
321 322
@@ -614,8 +615,8 @@ otputil_widget_lookup(
614 const char * wname, 615 const char * wname,
615 int exact ) 616 int exact )
616{ 617{
617 size_t x; 618 int x;
618 size_t y; 619 int y;
619 size_t len; 620 size_t len;
620 size_t wname_len; 621 size_t wname_len;
621 const char * alias; 622 const char * alias;
@@ -640,6 +641,7 @@ otputil_widget_lookup(
640 widget = &otputil_widget_map[x]; 641 widget = &otputil_widget_map[x];
641 if (widget->func_exec == NULL) 642 if (widget->func_exec == NULL)
642 continue; 643 continue;
644 widget->alias_idx = -1;
643 645
644 // compare widget name for match 646 // compare widget name for match
645 if (!(strncmp(widget->name, wname, wname_len))) 647 if (!(strncmp(widget->name, wname, wname_len)))
@@ -661,7 +663,10 @@ otputil_widget_lookup(
661 if (!(strncmp(alias, wname, wname_len))) 663 if (!(strncmp(alias, wname, wname_len)))
662 { 664 {
663 if (alias[wname_len] == '\0') 665 if (alias[wname_len] == '\0')
666 {
667 widget->alias_idx = y;
664 return(widget); 668 return(widget);
669 };
665 if ( ((match)) && (match != widget) ) 670 if ( ((match)) && (match != widget) )
666 return(NULL); 671 return(NULL);
667 if (exact == 0) 672 if (exact == 0)
@@ -708,11 +713,11 @@ int
708otputil_widget_usage( 713otputil_widget_usage(
709 otputil_config_t * cnf ) 714 otputil_config_t * cnf )
710{ 715{
711 size_t pos; 716 size_t pos;
712 const char * widget_name; 717 const char * widget_name;
713 const char * widget_help; 718 const char * widget_help;
714 const char * short_opt; 719 const char * short_opt;
715 otputil_widget_t * widget; 720 const otputil_widget_t * widget;
716 721
717 assert(cnf != NULL); 722 assert(cnf != NULL);
718 723
@@ -723,9 +728,18 @@ otputil_widget_usage(
723 if ((cnf->widget)) 728 if ((cnf->widget))
724 widget_help = ((cnf->widget->usage)) ? cnf->widget->usage : ""; 729 widget_help = ((cnf->widget->usage)) ? cnf->widget->usage : "";
725 730
726 printf("Usage: %s [OPTIONS] %s [OPTIONS]%s\n", PROGRAM_NAME, widget_name, widget_help); 731 if ((widget = cnf->widget) == NULL)
727 printf(" %s-%s [OPTIONS]%s\n", PROGRAM_NAME, widget_name, widget_help); 732 {
728 printf(" %s%s [OPTIONS]%s\n", PROGRAM_NAME, widget_name, widget_help); 733 printf("Usage: %s %s [OPTIONS]%s\n", PROGRAM_NAME, widget_name, widget_help);
734 printf(" %s-%s [OPTIONS]%s\n", PROGRAM_NAME, widget_name, widget_help);
735 printf(" %s%s [OPTIONS]%s\n", PROGRAM_NAME, widget_name, widget_help);
736 } else if (cnf->symlinked == 0)
737 {
738 widget_name = (widget->alias_idx == -1) ? widget_name : widget->aliases[widget->alias_idx];
739 printf("Usage: %s %s [OPTIONS]%s\n", PROGRAM_NAME, widget_name, widget_help);
740 }
741 else
742 printf("Usage: %s [OPTIONS]%s\n", cnf->prog_name, widget_help);
729 printf("OPTIONS:\n"); 743 printf("OPTIONS:\n");
730 if ((strchr(short_opt, 'c'))) printf(" -c num counter/sequence value\n"); 744 if ((strchr(short_opt, 'c'))) printf(" -c num counter/sequence value\n");
731 if ((strchr(short_opt, 'd'))) printf(" -d num number of digits in code\n"); 745 if ((strchr(short_opt, 'd'))) printf(" -d num number of digits in code\n");
diff --git a/src/otputil.h b/src/otputil.h
index 961d4ee..b58386a 100644
--- a/src/otputil.h
+++ b/src/otputil.h
@@ -77,6 +77,8 @@ struct _otputil_cli_widget
77 const char * const * aliases; 77 const char * const * aliases;
78 int arg_min; 78 int arg_min;
79 int arg_max; 79 int arg_max;
80 int alias_idx;
81 int padint;
80 int (*func_exec)(otputil_config_t * cnf); 82 int (*func_exec)(otputil_config_t * cnf);
81 int (*func_usage)(otputil_config_t * cnf); 83 int (*func_usage)(otputil_config_t * cnf);
82}; 84};
@@ -89,6 +91,8 @@ struct _otputil_cli_config
89 int opt_index; 91 int opt_index;
90 int prompt_user_pass; 92 int prompt_user_pass;
91 int prompt_otp_pass; 93 int prompt_otp_pass;
94 int symlinked;
95 int padint;
92 int argc; 96 int argc;
93 char ** argv; 97 char ** argv;
94 const char * prog_name; 98 const char * prog_name;