diff options
Diffstat (limited to 'usr.bin/column')
-rw-r--r-- | usr.bin/column/column.1 | 14 | ||||
-rw-r--r-- | usr.bin/column/column.c | 18 |
2 files changed, 17 insertions, 15 deletions
diff --git a/usr.bin/column/column.1 b/usr.bin/column/column.1 index 8e9c3b13893..86c38f78d1d 100644 --- a/usr.bin/column/column.1 +++ b/usr.bin/column/column.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: column.1,v 1.14 2015/03/13 19:58:41 jmc Exp $ +.\" $OpenBSD: column.1,v 1.15 2016/03/17 05:27:10 bentley Exp $ .\" $NetBSD: column.1,v 1.3 1995/03/26 09:08:28 glass Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)column.1 8.1 (Berkeley) 6/6/93 .\" -.Dd $Mdocdate: March 13 2015 $ +.Dd $Mdocdate: March 17 2016 $ .Dt COLUMN 1 .Os .Sh NAME @@ -75,10 +75,12 @@ Fill columns before filling rows. .Sh ENVIRONMENT .Bl -tag -width COLUMNS .It Ev COLUMNS -The environment variable -.Ev COLUMNS -is used to determine the size of -the screen if no other information is available. +If set to a positive integer, +.Nm Ns 's +output is formatted to the given width in (terminal) columns. +Otherwise, +.Nm +defaults to the terminal width, or 80 columns if the output is not a terminal. .El .Sh EXIT STATUS .Ex -std column diff --git a/usr.bin/column/column.c b/usr.bin/column/column.c index 20fa4f7401c..918ba51c94d 100644 --- a/usr.bin/column/column.c +++ b/usr.bin/column/column.c @@ -1,4 +1,4 @@ -/* $OpenBSD: column.c,v 1.22 2015/11/03 04:55:44 mmcc Exp $ */ +/* $OpenBSD: column.c,v 1.23 2016/03/17 05:27:10 bentley Exp $ */ /* $NetBSD: column.c,v 1.4 1995/09/02 05:53:03 jtc Exp $ */ /* @@ -50,7 +50,7 @@ void print(void); void r_columnate(void); void usage(void); -int termwidth = 80; /* default terminal width */ +int termwidth; /* default terminal width */ int entries; /* number of records */ int eval; /* exit value */ @@ -67,14 +67,14 @@ main(int argc, char *argv[]) char *p; const char *errstr; - if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col) { - if ((p = getenv("COLUMNS")) && *p != '\0') { - termwidth = strtonum(p, 1, INT_MAX, &errstr); - if (errstr != NULL) - errx(1, "%s: %s", errstr, p); - } - } else + termwidth = 0; + if ((p = getenv("COLUMNS")) != NULL) + termwidth = strtonum(p, 1, INT_MAX, NULL); + if (termwidth == 0 && ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && + win.ws_col > 0) termwidth = win.ws_col; + if (termwidth == 0) + termwidth = 80; if (pledge("stdio rpath", NULL) == -1) err(1, "pledge"); |