mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
util_opt: Change util_opt_init() to honor current command, if set
Function util_opt_init() build the option string for getopt_long(). If a command has been set via util_opt_set_command(), then util_opt_init() must honor that command and only add those options that match the command, or are command independent. That way the same option can be used in different commands with different flags and different argument settings. E.g. for command 'a' option '-x' might require an argument, for command 'b' the same option '-x' might not require an argument. The behavior of util_opt_init() is unchanged if no command is set, and also if different commands use the same option, but with the same flags and argument settings. Currently only the zkey tools set a command, but use unique options per command. Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com> Acked-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
c31eba5e00
commit
2f87cba1c7
+7
-2
@@ -49,6 +49,7 @@ struct util_opt_l *util_opt_l = &l;
|
||||
#define MAX_OPTLEN 256
|
||||
|
||||
static int opt_max_len(void);
|
||||
static bool opt_is_active(struct util_opt *opt);
|
||||
|
||||
/**
|
||||
* Initialize the command line options
|
||||
@@ -68,7 +69,9 @@ void util_opt_init(struct util_opt *opt_vec, const char *opt_prefix)
|
||||
|
||||
opterr = 0;
|
||||
/* Get number of options */
|
||||
for (count = 0; opt_vec[count].desc != NULL; count++);
|
||||
for (i = 0, count = 0; opt_vec[i].desc != NULL; i++)
|
||||
if (opt_is_active(&opt_vec[i]))
|
||||
count++;
|
||||
/*
|
||||
* Allocate short option string for worst case when all options have
|
||||
* optional parameters e.g "x::" and long option string.
|
||||
@@ -85,7 +88,9 @@ void util_opt_init(struct util_opt *opt_vec, const char *opt_prefix)
|
||||
/* Force getopt_long() to return ':' for missing required arguments */
|
||||
*str++ = ':';
|
||||
/* Construction of input structures for getopt_long() function. */
|
||||
for (i = 0, j = 0; i < count; i++) {
|
||||
for (i = 0, j = 0; opt_vec[i].desc != NULL; i++) {
|
||||
if (!opt_is_active(&opt_vec[i]))
|
||||
continue;
|
||||
if (opt_vec[i].flags & UTIL_OPT_FLAG_SECTION)
|
||||
continue;
|
||||
if (!(opt_vec[i].flags & UTIL_OPT_FLAG_NOLONG)) {
|
||||
|
||||
Reference in New Issue
Block a user