Signed-off-by: Nguyán ThÃi Ngác Duy <pclouds@xxxxxxxxx> --- column.c | 18 ++++++++++++++++++ column.h | 3 +++ parse-options.h | 2 ++ 3 files changed, 23 insertions(+), 0 deletions(-) diff --git a/column.c b/column.c index 4b92fa5..c4a90d5 100644 --- a/column.c +++ b/column.c @@ -175,3 +175,21 @@ void display_columns(const struct column_layout *c, int padding, const char *ind die("BUG: invalid mode %d", c->mode & COL_MODE); } } + +int parseopt_column_callback(const struct option *opt, const char *arg, int unset) +{ + struct column_layout *cp = opt->value; + if (unset) { + cp->mode = COL_PLAIN; + return 0; + } + if (!arg || !strcmp(arg, "column")) { + cp->mode |= COL_COLUMN_FIRST; + return 0; + } + if (!strcmp(arg, "dense")) { + cp->mode |= COL_DENSE; + return 0; + } + return error("unsupported style '%s'", arg); +} diff --git a/column.h b/column.h index 34435b0..7f0ae74 100644 --- a/column.h +++ b/column.h @@ -17,4 +17,7 @@ struct column_layout { extern void display_columns(const struct column_layout *c, int padding, const char *indent); +struct option; +extern int parseopt_column_callback(const struct option *opt, const char *arg, int unset); + #endif diff --git a/parse-options.h b/parse-options.h index 31ec5d2..2fed453 100644 --- a/parse-options.h +++ b/parse-options.h @@ -145,6 +145,8 @@ struct option { #define OPT_COLOR_FLAG(s, l, v, h) \ { OPTION_CALLBACK, (s), (l), (v), "when", (h), PARSE_OPT_OPTARG, \ parse_opt_color_flag_cb, (intptr_t)"always" } +#define OPT_COLUMN(s, l, v, h) \ + { OPTION_CALLBACK, (s), (l), (v), "style", (h), PARSE_OPT_OPTARG, parseopt_column_callback } /* parse_options() will filter out the processed options and leave the -- 1.7.2.2 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html