mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-30 16:51:41 +00:00
General overhaul:
- Makefile: WARNS=6 - man page: sort options, better xrefs, informative BUGS section - C source: proper option parsing, use printer control (.ctl) device, removed heaps of bit rot, style(9) cleanup, WARNS=6 cleanup. Prodded by: joerg
This commit is contained in:
parent
886ea9fc5c
commit
4ae6befa93
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=136037
@ -3,6 +3,6 @@
|
||||
PROG= lptcontrol
|
||||
MAN= lptcontrol.8
|
||||
|
||||
WARNS?= 2
|
||||
WARNS?= 6
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -11,7 +11,7 @@
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.Dd September 3, 1994
|
||||
.Dd October 1, 2004
|
||||
.Dt LPTCONTROL 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -19,13 +19,13 @@
|
||||
.Nd a utility for manipulating the lpt printer driver
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Fl i | p | e | s
|
||||
.Op Fl d Ar device
|
||||
.Fl e | i | p | s
|
||||
.Op Fl d Ar control_device
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
utility is used to set either the interrupt-driven, extended or polling mode
|
||||
of individual
|
||||
utility is used to set either the interrupt-driven, extended, standard,
|
||||
or polling mode of individual
|
||||
.Xr lpt 4
|
||||
devices.
|
||||
When a printer is switched from
|
||||
@ -38,27 +38,27 @@ ECP/ISA parallel port, it may be FIFO+DMA or ECP.
|
||||
.Pp
|
||||
The following command line options are supported:
|
||||
.Bl -tag -width indent
|
||||
.It Fl e
|
||||
Turn on extended mode.
|
||||
.It Fl i
|
||||
Turn on interrupt-driven mode.
|
||||
.It Fl p
|
||||
Turn on polled mode.
|
||||
.It Fl e
|
||||
Turn on extended mode.
|
||||
.It Fl s
|
||||
Turn on standard mode, i.e., turn off extended mode.
|
||||
.It Fl d Ar device
|
||||
Set the mode of the printer device specified by
|
||||
.Ar device .
|
||||
.It Fl d Ar control_device
|
||||
Set the mode of the printer control device specified by
|
||||
.Ar control_device .
|
||||
The default value for
|
||||
.Ar device
|
||||
.Ar control_device
|
||||
is
|
||||
.Pa /dev/lpt0 .
|
||||
.Pa /dev/lpt0.ctl .
|
||||
.El
|
||||
.Pp
|
||||
One of
|
||||
.Fl i , p
|
||||
.Fl e , i , p
|
||||
or
|
||||
.Fl e
|
||||
.Fl s
|
||||
must be specified.
|
||||
.Sh FILES
|
||||
.Bl -tag -width /sys/i386/conf/GENERIC -compact
|
||||
@ -68,11 +68,18 @@ printer devices
|
||||
printer control devices
|
||||
.It Pa /sys/i386/conf/GENERIC
|
||||
kernel configuration file
|
||||
.It Pa /boot/device.hints
|
||||
Device hints for the parallel port chipset driver,
|
||||
.Xr ppc 4
|
||||
.El
|
||||
.Sh BUGS
|
||||
Sure to be some.
|
||||
The control device name should never have been an option,
|
||||
but should have been an optional argument.
|
||||
Because of this, a single argument is treated as a device name.
|
||||
.Sh SEE ALSO
|
||||
.Xr lpt 4
|
||||
.Xr lpt 4 ,
|
||||
.Xr ppc 4 ,
|
||||
.Xr device.hints 5
|
||||
.Sh AUTHORS
|
||||
.An Geoffrey M. Rehmet
|
||||
.Sh HISTORY
|
||||
|
@ -31,24 +31,17 @@
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <ctype.h>
|
||||
#include <dev/ppbus/lptio.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <limits.h>
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <dev/ppbus/lptio.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#define PATH_LPCTL _PATH_DEV "lpctl"
|
||||
#define DEFAULT_DEVICE _PATH_DEV "lpt0"
|
||||
#define IRQ_INVALID -1
|
||||
#define DEFAULT_DEVICE "/dev/lpt0.ctl"
|
||||
#define IRQ_UNSPECIFIED -1
|
||||
#define DO_POLL 0
|
||||
#define USE_IRQ 1
|
||||
#define USE_EXT_MODE 2
|
||||
@ -56,40 +49,58 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: lptcontrol -i | -p | -s | -e [-d device]\n");
|
||||
fprintf(stderr,
|
||||
"usage: lptcontrol -e | -i | -p | -s [[-d] controldevice]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void set_interrupt_status(int irq_status, const char * file)
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
const char *device;
|
||||
int fd;
|
||||
int irq_status;
|
||||
int opt;
|
||||
|
||||
if((fd = open(file, O_WRONLY, 0660)) < 0)
|
||||
err(1, "open");
|
||||
if(ioctl(fd, LPT_IRQ, &irq_status) < 0)
|
||||
err(1, "ioctl");
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int main (int argc, char * argv[])
|
||||
{
|
||||
int opt;
|
||||
int irq_status = IRQ_INVALID;
|
||||
const char *device = DEFAULT_DEVICE;
|
||||
|
||||
while((opt = getopt(argc, argv, "ipesd:")) != -1)
|
||||
switch(opt) {
|
||||
case 'i': irq_status = USE_IRQ; break;
|
||||
case 'p': irq_status = DO_POLL; break;
|
||||
case 'e': irq_status = USE_EXT_MODE; break;
|
||||
case 's': irq_status = USE_STD_MODE; break;
|
||||
case 'd': device = optarg; break;
|
||||
default : usage();
|
||||
device = DEFAULT_DEVICE;
|
||||
irq_status = IRQ_UNSPECIFIED;
|
||||
while ((opt = getopt(argc, argv, "d:eips")) != -1)
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
device = optarg;
|
||||
break;
|
||||
case 'e':
|
||||
irq_status = USE_EXT_MODE;
|
||||
break;
|
||||
case 'i':
|
||||
irq_status = USE_IRQ;
|
||||
break;
|
||||
case 'p':
|
||||
irq_status = DO_POLL;
|
||||
break;
|
||||
case 's':
|
||||
irq_status = USE_STD_MODE;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
/* NOTREACHED */
|
||||
}
|
||||
if(irq_status == IRQ_INVALID)
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
/* POLA: DTRT if -d was forgotten, but device name was specified. */
|
||||
if (argc == 1) {
|
||||
device = argv[0];
|
||||
--argc;
|
||||
}
|
||||
|
||||
if (irq_status == IRQ_UNSPECIFIED || argc != 0)
|
||||
usage();
|
||||
|
||||
set_interrupt_status(irq_status, device);
|
||||
if ((fd = open(device, O_WRONLY, 0660)) < 0)
|
||||
err(1, "open");
|
||||
if (ioctl(fd, LPT_IRQ, &irq_status) < 0)
|
||||
err(1, "ioctl");
|
||||
close(fd);
|
||||
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user