Use err(3).

This commit is contained in:
Philippe Charnier 1997-09-25 06:36:29 +00:00
parent 985ae608d7
commit fe577fe939
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=29846
2 changed files with 35 additions and 34 deletions

View File

@ -11,13 +11,13 @@
.\" documentation and/or other materials provided with the distribution.
.\"
.\"
.\" $Id$
.\" $Id: lptcontrol.8,v 1.5 1997/02/22 16:06:24 peter Exp $
.Dd September 3, 1994
.Dt LPTCONTROL 8
.Os FreeBSD 2
.Sh NAME
.Nm \&lptcontrol
.Nd a utility for manipulating the lpt printer driver.
.Nd a utility for manipulating the lpt printer driver
.Sh SYNOPSIS
.Nm \&lptcontrol
.Cm -i
@ -26,7 +26,7 @@
.Op Fl u Ar unit no
.Sh DESCRIPTION
The
.Nm lptcontrol
.Nm
command is used to set either the interrupt-driven or polling mode
of individual
.Xr lpt 4
@ -38,16 +38,18 @@ the next time the device is opened.
The following command line options are supported:
.Bl -tag -width indent
.It Fl i
Turns on interrupt-driven mode.
Turn on interrupt-driven mode.
.It Fl p
Turns on polled mode.
Turn on polled mode.
.It Fl u Ar n
Sets the mode of the printer device specified by
Set the mode of the printer device specified by
.Em n .
The default value for
.Em n
is
.Em 0 (ie. /dev/lpt0)
.Em 0
(ie.
.Pa /dev/lpt0 )
.El
.Pp
One of
@ -57,17 +59,21 @@ or
must be specified.
.Pp
.Sh FILES
.Bl -tag -width indent -compact
.It Pa /dev/lpt? - printer devices
.It Pa /dev/lpctl? - printer control devices
.It Pa /sys/i386/conf/GENERIC - kernel configuration file
.Bl -tag -width /sys/i386/conf/GENERIC -compact
.It Pa /dev/lpt?
Printer devices.
.It Pa /dev/lpctl?
Printer control devices.
.It Pa /sys/i386/conf/GENERIC
Kernel configuration file.
.El
.Sh BUGS
Sure to be some.
.Sh "SEE ALSO"
.Xr lpt 4
.Sh AUTHOR
Geoffrey M. Rehmet
.An Geoffrey M. Rehmet
.Sh HISTORY
.Nm lptcontrol
first appeared in FreeBSD 1.1.5
.Nm Lptcontrol
first appeared in
.Fx 1.1.5

View File

@ -26,11 +26,15 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <ctype.h>
#include <err.h>
#include <limits.h>
#include <paths.h>
#include <stdio.h>
@ -39,7 +43,6 @@
#include <unistd.h>
#include <machine/lpt.h>
#include <sys/errno.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@ -51,11 +54,9 @@
#define DO_POLL 0
#define USE_IRQ 1
static void usage(const char * progname)
static void usage()
{
fprintf(stderr, "usage: %s -i | -p [-u <unit no.>]\n", progname);
fprintf(stderr, "\tUnit no. is a value in the range 0 to 3\n");
fprintf(stderr, "\tThe default unit no is 0 (ie. /dev/lpt0)\n");
fprintf(stderr, "usage: lptcontrol -i | -p [-u <unit no.>]\n");
exit(1);
}
@ -63,14 +64,10 @@ static void set_interrupt_status(int irq_status, const char * file)
{
int fd;
if((fd = open(file, O_WRONLY, 0660)) < 0) {
perror("open");
exit(1);
}
if(ioctl(fd, LPT_IRQ, &irq_status) < 0) {
perror("ioctl");
exit(1);
}
if((fd = open(file, O_WRONLY, 0660)) < 0)
err(1, "open");
if(ioctl(fd, LPT_IRQ, &irq_status) < 0)
err(1, "ioctl");
close(fd);
}
@ -98,16 +95,14 @@ int main (int argc, char * argv[])
case 'p': irq_status = DO_POLL; break;
case 'u': unit = optarg;
if(!isdigit(*unit))
usage(argv[0]);
usage();
break;
default : usage(argv[0]);
default : usage();
}
if(irq_status == IRQ_INVALID)
usage(argv[0]);
usage();
set_interrupt_status(irq_status, dev_file(*unit));
exit(0);
}