summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorAnthony J. Bentley <bentley@cvs.openbsd.org>2016-03-17 05:27:11 +0000
committerAnthony J. Bentley <bentley@cvs.openbsd.org>2016-03-17 05:27:11 +0000
commit8fcd372cac9eb2e1f5b77be5c644c16050a14ff5 (patch)
tree57ded33cc5e6839167ba569d1e58d6bb92f5bb85 /bin
parent06ada816bc102f9194fd229056dd05d0a1c41409 (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 'bin')
-rw-r--r--bin/ls/ls.114
-rw-r--r--bin/ls/ls.c26
-rw-r--r--bin/ps/ps.113
-rw-r--r--bin/ps/ps.c26
4 files changed, 36 insertions, 43 deletions
diff --git a/bin/ls/ls.1 b/bin/ls/ls.1
index 0d9cc32b157..5c35c1bf95b 100644
--- a/bin/ls/ls.1
+++ b/bin/ls/ls.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ls.1,v 1.74 2016/03/11 02:35:57 bentley Exp $
+.\" $OpenBSD: ls.1,v 1.75 2016/03/17 05:27:10 bentley Exp $
.\" $NetBSD: ls.1,v 1.14 1995/12/05 02:44:01 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
@@ -33,7 +33,7 @@
.\"
.\" @(#)ls.1 8.7 (Berkeley) 7/29/94
.\"
-.Dd $Mdocdate: March 11 2016 $
+.Dd $Mdocdate: March 17 2016 $
.Dt LS 1
.Os
.Sh NAME
@@ -436,10 +436,12 @@ option is not specified, the block counts
.Fl s )
will be displayed in units of that size block.
.It Ev COLUMNS
-If this variable contains a string representing a
-decimal integer, it is used as the
-column position width for displaying
-multiple-text-column output.
+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.
.It Ev LC_CTYPE
If set to a string ending in
.Qq .UTF-8 ,
diff --git a/bin/ls/ls.c b/bin/ls/ls.c
index 6341bfc6fa2..b16e82759aa 100644
--- a/bin/ls/ls.c
+++ b/bin/ls/ls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ls.c,v 1.44 2015/12/01 18:36:13 schwarze Exp $ */
+/* $OpenBSD: ls.c,v 1.45 2016/03/17 05:27:10 bentley Exp $ */
/* $NetBSD: ls.c,v 1.18 1996/07/09 09:16:29 mycroft Exp $ */
/*
@@ -66,7 +66,7 @@ static int (*sortfcn)(const FTSENT *, const FTSENT *);
#define BY_TIME 2
long blocksize; /* block size units */
-int termwidth = 80; /* default terminal width */
+int termwidth; /* default terminal width */
int sortkey = BY_NAME;
/* flags */
@@ -110,24 +110,20 @@ ls_main(int argc, char *argv[])
/* Terminal defaults to -Cq, non-terminal defaults to -1. */
if (isatty(STDOUT_FILENO)) {
- if ((p = getenv("COLUMNS")) != NULL)
- width = strtonum(p, 1, INT_MAX, NULL);
- if (width == 0 &&
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
- win.ws_col > 0)
- width = win.ws_col;
- if (width)
- termwidth = width;
f_column = f_nonprint = 1;
} else {
f_singlecol = 1;
- /* retrieve environment variable, in case of explicit -C */
- if ((p = getenv("COLUMNS")) != NULL)
- width = strtonum(p, 0, INT_MAX, NULL);
- if (width)
- termwidth = width;
}
+ 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 getpw", NULL) == -1)
err(1, "pledge");
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index d4b77f5b27c..9631a42202c 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ps.1,v 1.102 2015/10/22 22:21:41 benno Exp $
+.\" $OpenBSD: ps.1,v 1.103 2016/03/17 05:27:10 bentley Exp $
.\" $NetBSD: ps.1,v 1.16 1996/03/21 01:36:28 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1991, 1993, 1994
@@ -30,7 +30,7 @@
.\"
.\" @(#)ps.1 8.3 (Berkeley) 4/18/94
.\"
-.Dd $Mdocdate: October 22 2015 $
+.Dd $Mdocdate: March 17 2016 $
.Dt PS 1
.Os
.Sh NAME
@@ -543,10 +543,13 @@ The following environment variables affect the execution of
.Nm :
.Bl -tag -width "COLUMNS"
.It Ev COLUMNS
-If set, specifies the user's preferred output width in column positions.
-By default,
+If set to a positive integer,
+.Nm Ns 's
+output is formatted to the given width in columns.
+Otherwise,
.Nm
-attempts to automatically determine the terminal width.
+defaults to the terminal width \(mi 1, or 79 columns if the output is not a
+terminal.
.It Ev TZ
The time zone to use when displaying dates.
See
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index a7c4e43c812..ecbe683a04b 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ps.c,v 1.69 2016/01/10 14:04:16 schwarze Exp $ */
+/* $OpenBSD: ps.c,v 1.70 2016/03/17 05:27:10 bentley Exp $ */
/* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */
/*-
@@ -102,22 +102,14 @@ main(int argc, char *argv[])
setlocale(LC_CTYPE, "");
- if ((cols = getenv("COLUMNS")) != NULL && *cols != '\0') {
- const char *errstr;
-
- termwidth = strtonum(cols, 1, INT_MAX, &errstr);
- if (errstr != NULL)
- warnx("COLUMNS: %s: %s", cols, errstr);
- }
- if (termwidth == 0) {
- if ((ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == -1 &&
- ioctl(STDERR_FILENO, TIOCGWINSZ, &ws) == -1 &&
- ioctl(STDIN_FILENO, TIOCGWINSZ, &ws) == -1) ||
- ws.ws_col == 0)
- termwidth = 79;
- else
- termwidth = ws.ws_col - 1;
- }
+ termwidth = 0;
+ if ((cols = getenv("COLUMNS")) != NULL)
+ termwidth = strtonum(cols, 1, INT_MAX, NULL);
+ if (termwidth == 0 && ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0 &&
+ ws.ws_col > 0)
+ termwidth = ws.ws_col - 1;
+ if (termwidth == 0)
+ termwidth = 79;
if (argc > 1)
argv[1] = kludge_oldps_options(argv[1]);