From 3b56eea7c99589bd6b80576de9ce185fee5cd7d2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 15 May 2012 17:46:20 +0200 Subject: text-utils: cleanup strtoxx_or_err() Signed-off-by: Karel Zak --- text-utils/column.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'text-utils/column.c') diff --git a/text-utils/column.c b/text-utils/column.c index b210a9381..aab9187ea 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -42,20 +42,20 @@ #include #include -#include #include #include #include #include #include #include -#include "nls.h" +#include "nls.h" #include "widechar.h" #include "c.h" #include "xalloc.h" #include "strutils.h" #include "closestream.h" +#include "ttyutils.h" #ifdef HAVE_WIDECHAR #define wcs_width(s) wcswidth(s,wcslen(s)) @@ -105,10 +105,9 @@ static void __attribute__((__noreturn__)) usage(int rc) int main(int argc, char **argv) { - struct winsize win; int ch, tflag = 0, xflag = 0; int i; - long termwidth = 80; + int termwidth = 80; int entries = 0; /* number of records */ unsigned int eval = 0; /* exit value */ int maxlength = 0; /* longest record */ @@ -134,14 +133,9 @@ int main(int argc, char **argv) textdomain(PACKAGE); atexit(close_stdout); - if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win) == -1 || !win.ws_col) { - char *p; - - if ((p = getenv("COLUMNS")) != NULL) - termwidth = strtol_or_err(p, - _("terminal environment COLUMNS failed")); - } else - termwidth = win.ws_col; + termwidth = get_terminal_width(); + if (termwidth <= 0) + termwidth = 80; while ((ch = getopt_long(argc, argv, "hVc:s:tx", longopts, NULL)) != -1) switch(ch) { @@ -153,11 +147,7 @@ int main(int argc, char **argv) PACKAGE_STRING); return EXIT_SUCCESS; case 'c': - termwidth = strtol_or_err(optarg, - _("bad columns width value")); - if (termwidth < 1) - errx(EXIT_FAILURE, - _("-%c positive integer expected as an argument"), ch); + termwidth = strtou32_or_err(optarg, _("invalid columns argument")); break; case 's': separator = mbs_to_wcs(optarg); -- cgit v1.2.3-55-g7522