Skip to content

Commit

Permalink
perf tools: Add PARSE_OPT_DISABLED flag
Browse files Browse the repository at this point in the history
In some cases, we need to reuse exising options with some of them
disabled.  To do that, add PARSE_OPT_DISABLED flag and
set_option_flag() function.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Alexander Yarygin <yarygin@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Hemant Kumar <hemant@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1413990949-13953-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed Oct 29, 2014
1 parent 29f9e52 commit d152d1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/perf/util/parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ static int get_value(struct parse_opt_ctx_t *p,
return opterror(opt, "takes no value", flags);
if (unset && (opt->flags & PARSE_OPT_NONEG))
return opterror(opt, "isn't available", flags);
if (opt->flags & PARSE_OPT_DISABLED)
return opterror(opt, "is not usable", flags);

if (!(flags & OPT_SHORT) && p->opt) {
switch (opt->type) {
Expand Down Expand Up @@ -509,6 +511,8 @@ static void print_option_help(const struct option *opts, int full)
}
if (!full && (opts->flags & PARSE_OPT_HIDDEN))
return;
if (opts->flags & PARSE_OPT_DISABLED)
return;

pos = fprintf(stderr, " ");
if (opts->short_name)
Expand Down Expand Up @@ -679,3 +683,16 @@ int parse_opt_verbosity_cb(const struct option *opt,
}
return 0;
}

void set_option_flag(struct option *opts, int shortopt, const char *longopt,
int flag)
{
for (; opts->type != OPTION_END; opts++) {
if ((shortopt && opts->short_name == shortopt) ||
(opts->long_name && longopt &&
!strcmp(opts->long_name, longopt))) {
opts->flags |= flag;
break;
}
}
}
2 changes: 2 additions & 0 deletions tools/perf/util/parse-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum parse_opt_option_flags {
PARSE_OPT_NONEG = 4,
PARSE_OPT_HIDDEN = 8,
PARSE_OPT_LASTARG_DEFAULT = 16,
PARSE_OPT_DISABLED = 32,
};

struct option;
Expand Down Expand Up @@ -211,4 +212,5 @@ extern int parse_opt_verbosity_cb(const struct option *, const char *, int);

extern const char *parse_options_fix_filename(const char *prefix, const char *file);

void set_option_flag(struct option *opts, int sopt, const char *lopt, int flag);
#endif /* __PERF_PARSE_OPTIONS_H */

0 comments on commit d152d1b

Please sign in to comment.