From ac228c26bd1eb84d04020f56771a7bcb04afde75 Mon Sep 17 00:00:00 2001 From: "Liam J. Foy" Date: Sun, 23 Jan 2005 19:52:30 +0000 Subject: [PATCH] General clean up of lptcontrol. Similar to FreeBSD 1.15 with my modifications: - Remove many unnecessary headers and sort them - Remove unused #define (PATH_LPCTL) - Don't bother calling set_interrupt_status. Just call both open(2) and ioctl(2) in main. - Remove modes in open(2) --- usr.sbin/lptcontrol/lptcontrol.c | 77 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/usr.sbin/lptcontrol/lptcontrol.c b/usr.sbin/lptcontrol/lptcontrol.c index cce6cfe210..69add2b0fe 100644 --- a/usr.sbin/lptcontrol/lptcontrol.c +++ b/usr.sbin/lptcontrol/lptcontrol.c @@ -28,25 +28,18 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/usr.sbin/lptcontrol/lptcontrol.c,v 1.9.2.2 2001/07/30 10:22:57 dd Exp $ - * $DragonFly: src/usr.sbin/lptcontrol/lptcontrol.c,v 1.3 2003/08/08 04:18:46 dillon Exp $ + * $DragonFly: src/usr.sbin/lptcontrol/lptcontrol.c,v 1.4 2005/01/23 19:52:30 liamfoy Exp $ */ +#include -#include #include -#include -#include +#include #include #include -#include #include #include -#include -#include -#include - -#define PATH_LPCTL _PATH_DEV "lpctl" #define DEFAULT_DEVICE "/dev/lpt0" #define IRQ_INVALID -1 #define DO_POLL 0 @@ -54,42 +47,54 @@ #define USE_EXT_MODE 2 #define USE_STD_MODE 3 -static void usage(void) +static void +usage(void) { fprintf(stderr, "usage: lptcontrol -i | -p | -s | -e [-d device]\n"); exit(1); } -static void set_interrupt_status(int irq_status, const char * file) +int +main(int argc, char *argv[]) { - int fd; - - 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 opt; + int fd; + int irq_status = IRQ_INVALID; + const char *device = DEFAULT_DEVICE; -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(); + 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(); } - if(irq_status == IRQ_INVALID) + } + argc -= optind; + argv += optind; + + if (argc == 1 || irq_status == IRQ_INVALID) usage(); - set_interrupt_status(irq_status, device); + if ((fd = open(device, O_WRONLY)) < 0) + err(1, "open failed: %s", device); + if (ioctl(fd, LPT_IRQ, &irq_status) < 0) + err(1, "ioctl failed"); + + close(fd); exit(0); } -- 2.41.0