lptcontrol.c revision 43993
167754Smsmith/*
267754Smsmith * Copyright (c) 1994 Geoffrey M. Rehmet
377424Smsmith * All rights reserved.
4104470Siwasaki *
567754Smsmith * Redistribution and use in source and binary forms, with or without
667754Smsmith * modification, are permitted provided that the following conditions
767754Smsmith * are met:
867754Smsmith * 1. Redistributions of source code must retain the above copyright
967754Smsmith *    notice, this list of conditions and the following disclaimer.
1067754Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1167754Smsmith *    notice, this list of conditions and the following disclaimer in the
1291116Smsmith *    documentation and/or other materials provided with the distribution.
1370243Smsmith * 3. All advertising materials mentioning features or use of this software
1467754Smsmith *    must display the following acknowledgement:
1567754Smsmith *      This product includes software developed by Geoffrey M. Rehmet
1667754Smsmith * 4. The name of the author may not be used to endorse or promote products
1767754Smsmith *    derived from this software withough specific prior written permission
1867754Smsmith *
1967754Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2067754Smsmith * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2167754Smsmith * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2267754Smsmith * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2367754Smsmith * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2467754Smsmith * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2567754Smsmith * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2667754Smsmith * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2767754Smsmith * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2867754Smsmith * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2967754Smsmith */
3067754Smsmith
3167754Smsmith#ifndef lint
3267754Smsmithstatic const char rcsid[] =
3367754Smsmith	"$Id: lptcontrol.c,v 1.7 1999/01/10 12:04:56 nsouch Exp $";
3467754Smsmith#endif /* not lint */
3567754Smsmith
3667754Smsmith#include <ctype.h>
3767754Smsmith#include <err.h>
3867754Smsmith#include <limits.h>
3967754Smsmith#include <paths.h>
4067754Smsmith#include <stdio.h>
4167754Smsmith#include <stdlib.h>
4267754Smsmith#include <string.h>
4367754Smsmith#include <unistd.h>
4467754Smsmith
4567754Smsmith#include <machine/lpt.h>
4667754Smsmith#include <sys/file.h>
4767754Smsmith#include <sys/ioctl.h>
4867754Smsmith#include <sys/types.h>
4967754Smsmith
5067754Smsmith
5167754Smsmith#define PATH_LPCTL	_PATH_DEV "lpctl"
5267754Smsmith#define DEFAULT_DEVICE	"/dev/lpt0"
5367754Smsmith#define IRQ_INVALID	-1
5467754Smsmith#define DO_POLL		0
5567754Smsmith#define USE_IRQ		1
5667754Smsmith#define USE_EXT_MODE	2
5767754Smsmith#define USE_STD_MODE	3
5867754Smsmith
5967754Smsmithstatic void usage()
6067754Smsmith{
6167754Smsmith	fprintf(stderr, "usage: lptcontrol -i | -p | -s | -e [-d device]\n");
6267754Smsmith	exit(1);
6367754Smsmith}
6467754Smsmith
6567754Smsmithstatic void set_interrupt_status(int irq_status, const char * file)
6667754Smsmith{
6767754Smsmith	int	fd;
6867754Smsmith
6967754Smsmith	if((fd = open(file, O_WRONLY, 0660)) < 0)
7067754Smsmith		err(1, "open");
7167754Smsmith	if(ioctl(fd, LPT_IRQ, &irq_status) < 0)
7267754Smsmith		err(1, "ioctl");
7367754Smsmith	close(fd);
7467754Smsmith}
7567754Smsmith
7667754Smsmithint main (int argc, char * argv[])
7767754Smsmith{
7867754Smsmith	int		opt;
7967754Smsmith	int		irq_status = IRQ_INVALID;
8067754Smsmith	char		*device = DEFAULT_DEVICE;
8167754Smsmith
8267754Smsmith	while((opt = getopt(argc, argv, "ipesd:")) != -1)
8367754Smsmith		switch(opt) {
8467754Smsmith		case 'i': irq_status = USE_IRQ; break;
8567754Smsmith		case 'p': irq_status = DO_POLL; break;
8667754Smsmith		case 'e': irq_status = USE_EXT_MODE; break;
8767754Smsmith		case 's': irq_status = USE_STD_MODE; break;
8867754Smsmith		case 'd': device = optarg; break;
8967754Smsmith		default : usage();
9067754Smsmith		}
9167754Smsmith	if(irq_status == IRQ_INVALID)
9267754Smsmith		usage();
9367754Smsmith
9467754Smsmith	set_interrupt_status(irq_status, device);
9567754Smsmith
9667754Smsmith	exit(0);
9767754Smsmith}
9867754Smsmith