summaryrefslogtreecommitdiff
path: root/text-utils/column.c
diff options
context:
space:
mode:
authorSami Kerola <kerolasa@iki.fi>2010-10-04 20:57:57 +0200
committerKarel Zak <kzak@redhat.com>2010-10-07 10:12:34 +0200
commita4cc8dfe7d603e7c9386a782c1e128c64bcc27e2 (patch)
treed73b726d89a142cc21c60c1a6069293862af1748 /text-utils/column.c
parentfac8b4bd78cd0f33cf71f4a8525f2f56b5e6b3f2 (diff)
downloadutil-linux-old-a4cc8dfe7d603e7c9386a782c1e128c64bcc27e2.tar.gz
column: getopt_long and new help output
[kzak@redhat.com: - remove __progname, cleanup usage()] Signed-off-by: Sami Kerola <kerolasa@iki.fi> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'text-utils/column.c')
-rw-r--r--text-utils/column.c50
1 files changed, 36 insertions, 14 deletions
diff --git a/text-utils/column.c b/text-utils/column.c
index f5d41a2c..e7cd3346 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,6 @@ 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));
int termwidth = 80; /* default terminal width */
@@ -79,6 +80,34 @@ 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 },
+};
+
+static void __attribute__((__noreturn__)) usage(int rc)
+{
+ FILE *out = rc == EXIT_FAILURE ? stderr : stdout;
+
+ fprintf(out, _("\nUsage: %s [options] [file ...]\n"),
+ program_invocation_short_name);
+ fprintf(out, _("\nOptions:\n"));
+
+ fprintf(out, _(
+ " -h, --help displays this help text\n"
+ " -c, --columns <width> width of output in number of characters\n"
+ " -t, --table create a table\n"
+ " -s, --separator <string> table delimeter\n"
+ " -x, --fillrows fill rows before columns\n"));
+
+ fprintf(out, _("\nFor more information see column(1).\n"));
+ exit(rc);
+}
int
main(int argc, char **argv)
{
@@ -87,9 +116,6 @@ main(int argc, char **argv)
int ch, tflag, xflag;
char *p;
- extern char *__progname;
- __progname = argv[0];
-
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -101,8 +127,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 +145,8 @@ main(int argc, char **argv)
case 'x':
xflag = 1;
break;
- case '?':
default:
- usage();
+ usage(EXIT_FAILURE);
}
argc -= optind;
argv += optind;
@@ -366,11 +395,4 @@ emalloc(size)
return (p);
}
-static void
-usage()
-{
- (void)fprintf(stderr,
- _("usage: column [-tx] [-c columns] [file ...]\n"));
- exit(1);
-}