diff options
author | Anthony J. Bentley <bentley@cvs.openbsd.org> | 2016-03-17 05:27:11 +0000 |
---|---|---|
committer | Anthony J. Bentley <bentley@cvs.openbsd.org> | 2016-03-17 05:27:11 +0000 |
commit | 8fcd372cac9eb2e1f5b77be5c644c16050a14ff5 (patch) | |
tree | 57ded33cc5e6839167ba569d1e58d6bb92f5bb85 /usr.bin | |
parent | 06ada816bc102f9194fd229056dd05d0a1c41409 (diff) |
Switch (non-curses, non-ksh) programs that use COLUMNS to a single idiom.
Previously behaviors were all over the map. This changes them to
use COLUMNS first, and either terminal width or a hardcoded value
(typically 80) as appropriate.
ok deraadt@; man bits ok jmc@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/column/column.1 | 14 | ||||
-rw-r--r-- | usr.bin/column/column.c | 18 | ||||
-rw-r--r-- | usr.bin/rusers/rusers.1 | 14 | ||||
-rw-r--r-- | usr.bin/rusers/rusers.c | 24 | ||||
-rw-r--r-- | usr.bin/sed/main.c | 10 | ||||
-rw-r--r-- | usr.bin/sed/sed.1 | 15 |
6 files changed, 56 insertions, 39 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"); diff --git a/usr.bin/rusers/rusers.1 b/usr.bin/rusers/rusers.1 index af5af77f727..3061be31ba1 100644 --- a/usr.bin/rusers/rusers.1 +++ b/usr.bin/rusers/rusers.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rusers.1,v 1.15 2014/04/24 15:03:04 tedu Exp $ +.\" $OpenBSD: rusers.1,v 1.16 2016/03/17 05:27:10 bentley Exp $ .\" .\" Copyright (c) 1983, 1990 The Regents of the University of California. .\" All rights reserved. @@ -29,7 +29,7 @@ .\" .\" from: @(#)rusers.1 6.7 (Berkeley) 4/23/91 .\" -.Dd $Mdocdate: April 24 2014 $ +.Dd $Mdocdate: March 17 2016 $ .Dt RUSERS 1 .Os .Sh NAME @@ -79,6 +79,16 @@ and the remote host they logged in from (if applicable). .It Fl u Sort by number of users logged in. .El +.Sh ENVIRONMENT +.Bl -tag -width COLUMNS +.It Ev COLUMNS +If set to a positive integer, +.Nm Ns 's +output is formatted to the given width in columns. +Otherwise, +.Nm +defaults to the terminal width, or 80 columns if the output is not a terminal. +.El .Sh DIAGNOSTICS .Bl -tag -width indent .It rusers: RPC: Program not registered diff --git a/usr.bin/rusers/rusers.c b/usr.bin/rusers/rusers.c index 33af706df8e..95b32f213aa 100644 --- a/usr.bin/rusers/rusers.c +++ b/usr.bin/rusers/rusers.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rusers.c,v 1.36 2015/12/09 19:39:10 mmcc Exp $ */ +/* $OpenBSD: rusers.c,v 1.37 2016/03/17 05:27:10 bentley Exp $ */ /* * Copyright (c) 2001, 2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -141,21 +141,15 @@ main(int argc, char **argv) if (hflag + iflag + uflag > 1) usage(); - if (isatty(STDOUT_FILENO)) { - if ((cp = getenv("COLUMNS")) != NULL && *cp != '\0') { - termwidth = strtol(cp, &ep, 10); - if (*ep != '\0' || termwidth >= INT_MAX || - termwidth < 0) - termwidth = 0; - } - if (termwidth == 0 && - ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && - win.ws_col > 0) - termwidth = win.ws_col; - else - termwidth = 80; - } else + termwidth = 0; + if ((cp = getenv("COLUMNS")) != NULL) + termwidth = strtonum(cp, 1, LONG_MAX, NULL); + if (termwidth == 0 && ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && + win.ws_col > 0) + termwidth = win.ws_col; + if (termwidth == 0) termwidth = 80; + setvbuf(stdout, NULL, _IOLBF, 0); if (argc == optind) { diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index cd42171d5f8..62c2b4ecd85 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.31 2016/01/01 20:55:13 tb Exp $ */ +/* $OpenBSD: main.c,v 1.32 2016/03/17 05:27:10 bentley Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. @@ -150,14 +150,14 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - if ((p = getenv("COLUMNS"))) + termwidth = 0; + if ((p = getenv("COLUMNS")) != NULL) termwidth = strtonum(p, 0, INT_MAX, NULL); - if (termwidth == 0 && - ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && + if (termwidth == 0 && ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 && win.ws_col > 0) termwidth = win.ws_col; if (termwidth == 0) - termwidth = 60; + termwidth = 80; if (inplace != NULL) { if (pledge("stdio rpath wpath cpath fattr", NULL) == -1) diff --git a/usr.bin/sed/sed.1 b/usr.bin/sed/sed.1 index f53821de8ac..1e15fcb909f 100644 --- a/usr.bin/sed/sed.1 +++ b/usr.bin/sed/sed.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sed.1,v 1.47 2015/11/04 21:28:27 tedu Exp $ +.\" $OpenBSD: sed.1,v 1.48 2016/03/17 05:27:10 bentley Exp $ .\" .\" Copyright (c) 1992, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" from: @(#)sed.1 8.2 (Berkeley) 12/30/93 .\" -.Dd $Mdocdate: November 4 2015 $ +.Dd $Mdocdate: March 17 2016 $ .Dt SED 1 .Os .Sh NAME @@ -512,6 +512,17 @@ This is the same as specifying the .Fl n option on the command line. .El +.Sh ENVIRONMENT +.Bl -tag -width COLUMNS +.It Ev COLUMNS +If set to a positive integer, +output from the +.Ic l +function is formatted to the given width in columns. +Otherwise, +.Nm +defaults to the terminal with, or 80 columns if the output is not a terminal. +.El .Sh EXIT STATUS .Ex -std sed .Sh EXAMPLES |