diff options
Diffstat (limited to 'tools/perf/util/parse-options.h')
| -rw-r--r-- | tools/perf/util/parse-options.h | 23 | 
1 files changed, 22 insertions, 1 deletions
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h index c7d72dce54b..d8dac8ac5f3 100644 --- a/tools/perf/util/parse-options.h +++ b/tools/perf/util/parse-options.h @@ -82,6 +82,9 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);   *   OPTION_{BIT,SET_UINT,SET_PTR} store the {mask,integer,pointer} to put in   *   the value when met.   *   CALLBACKS can use it like they want. + * + * `set`:: + *   whether an option was set by the user   */  struct option {  	enum parse_opt_type type; @@ -94,6 +97,7 @@ struct option {  	int flags;  	parse_opt_cb *callback;  	intptr_t defval; +	bool *set;  };  #define check_vtype(v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) @@ -103,6 +107,10 @@ struct option {  #define OPT_GROUP(h)                { .type = OPTION_GROUP, .help = (h) }  #define OPT_BIT(s, l, v, h, b)      { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h), .defval = (b) }  #define OPT_BOOLEAN(s, l, v, h)     { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) } +#define OPT_BOOLEAN_SET(s, l, v, os, h) \ +	{ .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), \ +	.value = check_vtype(v, bool *), .help = (h), \ +	.set = check_vtype(os, bool *)}  #define OPT_INCR(s, l, v, h)        { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) }  #define OPT_SET_UINT(s, l, v, h, i)  { .type = OPTION_SET_UINT, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h), .defval = (i) }  #define OPT_SET_PTR(s, l, v, h, p)  { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } @@ -119,6 +127,10 @@ struct option {  	{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG }  #define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \  	{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .defval = (intptr_t)d, .flags = PARSE_OPT_LASTARG_DEFAULT } +#define OPT_CALLBACK_DEFAULT_NOOPT(s, l, v, a, h, f, d) \ +	{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l),\ +	.value = (v), (a), .help = (h), .callback = (f), .defval = (intptr_t)d,\ +	.flags = PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NOARG}  /* parse_options() will filter out the processed options and leave the   * non-option argments in argv[]. @@ -128,6 +140,11 @@ extern int parse_options(int argc, const char **argv,                           const struct option *options,                           const char * const usagestr[], int flags); +extern int parse_options_subcommand(int argc, const char **argv, +				const struct option *options, +				const char *const subcommands[], +				const char *usagestr[], int flags); +  extern NORETURN void usage_with_options(const char * const *usagestr,                                          const struct option *options); @@ -136,6 +153,8 @@ extern NORETURN void usage_with_options(const char * const *usagestr,  enum {  	PARSE_OPT_HELP = -1,  	PARSE_OPT_DONE, +	PARSE_OPT_LIST_OPTS, +	PARSE_OPT_LIST_SUBCMDS,  	PARSE_OPT_UNKNOWN,  }; @@ -153,7 +172,9 @@ struct parse_opt_ctx_t {  };  extern int parse_options_usage(const char * const *usagestr, -			       const struct option *opts); +			       const struct option *opts, +			       const char *optstr, +			       bool short_opt);  extern void parse_options_start(struct parse_opt_ctx_t *ctx,  				int argc, const char **argv, int flags);  | 
