diff options
author | schweikh <schweikh@FreeBSD.org> | 2004-10-01 20:04:20 +0000 |
---|---|---|
committer | schweikh <schweikh@FreeBSD.org> | 2004-10-01 20:04:20 +0000 |
commit | 7a133f54fc8f49ace0ad42bbf7ad3cfc5a4f41b3 (patch) | |
tree | a5a376c1e90c21bea39624ae7cdca6a86b6af6b9 | |
parent | 3a3e9a66ad3eb77cd38cfc51e164c887be662a16 (diff) | |
download | FreeBSD-src-7a133f54fc8f49ace0ad42bbf7ad3cfc5a4f41b3.zip FreeBSD-src-7a133f54fc8f49ace0ad42bbf7ad3cfc5a4f41b3.tar.gz |
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
-rw-r--r-- | usr.sbin/lptcontrol/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/lptcontrol/lptcontrol.8 | 39 | ||||
-rw-r--r-- | usr.sbin/lptcontrol/lptcontrol.c | 93 |
3 files changed, 76 insertions, 58 deletions
diff --git a/usr.sbin/lptcontrol/Makefile b/usr.sbin/lptcontrol/Makefile index 76f4f2d..3f7a939 100644 --- a/usr.sbin/lptcontrol/Makefile +++ b/usr.sbin/lptcontrol/Makefile @@ -3,6 +3,6 @@ PROG= lptcontrol MAN= lptcontrol.8 -WARNS?= 2 +WARNS?= 6 .include <bsd.prog.mk> diff --git a/usr.sbin/lptcontrol/lptcontrol.8 b/usr.sbin/lptcontrol/lptcontrol.8 index 239de00..474f64f 100644 --- a/usr.sbin/lptcontrol/lptcontrol.8 +++ b/usr.sbin/lptcontrol/lptcontrol.8 @@ -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 diff --git a/usr.sbin/lptcontrol/lptcontrol.c b/usr.sbin/lptcontrol/lptcontrol.c index 5fb9798..387fc9e 100644 --- a/usr.sbin/lptcontrol/lptcontrol.c +++ b/usr.sbin/lptcontrol/lptcontrol.c @@ -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); } |