From: Sami Kerola <kerolasa@xxxxxx> Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- text-utils/column.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 files changed, 36 insertions(+), 8 deletions(-) diff --git a/text-utils/column.c b/text-utils/column.c index f5d41a2..a224932 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -48,6 +48,8 @@ #include <stdlib.h> #include <string.h> #include <err.h> +#include <errno.h> +#include <getopt.h> #include "nls.h" #include "widechar.h" @@ -68,7 +70,7 @@ static void input __P((FILE *)); static void maketbl __P((void)); static void print __P((void)); static void r_columnate __P((void)); -static void usage __P((void)); +static void usage __P((int)); int termwidth = 80; /* default terminal width */ @@ -79,6 +81,16 @@ wchar_t **list; /* array of pointers to records */ wchar_t default_separator[] = { '\t', ' ', 0 }; wchar_t *separator = default_separator; /* field separator for table option */ +struct option longopts[] = +{ + { "help", 0, 0, 'h' }, + { "columns", 0, 0, 'c' }, + { "table", 0, 0, 't' }, + { "separator", 0, 0, 's' }, + { "fillrows", 0, 0, 'x' }, + { NULL, 0, 0, 0 }, +}; + int main(int argc, char **argv) { @@ -101,8 +113,12 @@ main(int argc, char **argv) termwidth = win.ws_col; tflag = xflag = 0; - while ((ch = getopt(argc, argv, "c:s:tx")) != -1) + while ((ch = getopt_long(argc, argv, "h?c:s:tx", longopts, NULL)) != -1) switch(ch) { + case 'h': + case '?': + usage(EXIT_SUCCESS); + break; case 'c': termwidth = atoi(optarg); break; @@ -115,9 +131,8 @@ main(int argc, char **argv) case 'x': xflag = 1; break; - case '?': default: - usage(); + usage(EXIT_FAILURE); } argc -= optind; argv += optind; @@ -367,10 +382,23 @@ emalloc(size) } static void -usage() +usage(int rc) { + const char *p = program_invocation_short_name; + + if (!*p) + p = "column"; + + printf(_("\nUsage: %s [options] [file ...]\n"), p); + printf(_("\nOptions:\n")); + + printf(_( + " -h, --help displays this help text\n" + " -c, --columns width of output in number of characters\n" + " -t, --table create a table\n" + " -s, --separator table delimeter string\n" + " -x, --fillrows fill rows before columns\n")); - (void)fprintf(stderr, - _("usage: column [-tx] [-c columns] [file ...]\n")); - exit(1); + printf(_("\nFor more information see column(1).\n")); + exit(rc); } -- 1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html