summaryrefslogtreecommitdiff
path: root/usr.sbin/lpr
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 /usr.sbin/lpr
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 'usr.sbin/lpr')
-rw-r--r--usr.sbin/lpr/common_source/displayq.c19
-rw-r--r--usr.sbin/lpr/lpq/lpq.113
2 files changed, 20 insertions, 12 deletions
diff --git a/usr.sbin/lpr/common_source/displayq.c b/usr.sbin/lpr/common_source/displayq.c
index 866191736b9..415cd581865 100644
--- a/usr.sbin/lpr/common_source/displayq.c
+++ b/usr.sbin/lpr/common_source/displayq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: displayq.c,v 1.38 2016/01/12 23:35:13 tb Exp $ */
+/* $OpenBSD: displayq.c,v 1.39 2016/03/17 05:27:10 bentley Exp $ */
/* $NetBSD: displayq.c,v 1.21 2001/08/30 00:51:50 itojun Exp $ */
/*
@@ -101,14 +101,15 @@ displayq(int format)
struct stat statb;
FILE *fp;
- termwidth = 80;
- if (isatty(STDOUT_FILENO)) {
- if ((p = getenv("COLUMNS")) != NULL)
- termwidth = atoi(p);
- else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &win) == 0 &&
- win.ws_col > 0)
- termwidth = win.ws_col;
- }
+ 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 (termwidth < 60)
termwidth = 60;
diff --git a/usr.sbin/lpr/lpq/lpq.1 b/usr.sbin/lpr/lpq/lpq.1
index f2e072d4fd4..eddc42821b1 100644
--- a/usr.sbin/lpr/lpq/lpq.1
+++ b/usr.sbin/lpr/lpq/lpq.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: lpq.1,v 1.10 2007/05/31 19:20:25 jmc Exp $
+.\" $OpenBSD: lpq.1,v 1.11 2016/03/17 05:27:10 bentley Exp $
.\" $NetBSD: lpq.1,v 1.11 2002/01/19 03:23:11 wiz Exp $
.\"
.\" Copyright (c) 1983, 1990, 1993
@@ -30,7 +30,7 @@
.\"
.\" @(#)lpq.1 8.2 (Berkeley) 4/28/95
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: March 17 2016 $
.Dt LPQ 1
.Os
.Sh NAME
@@ -96,9 +96,16 @@ warns that there is no daemon present (i.e., due to some malfunction), the
.Xr lpc 8
command can be used to restart the printer daemon.
.Sh ENVIRONMENT
-If the following environment variable exists, it is used by
+If the following environment variables exist, they are used by
.Nm lpq :
.Bl -tag -width PRINTER
+.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.
.It Ev PRINTER
Specifies an alternate default printer.
.El