lptcontrol.c revision 2470
1179193Sjb/* 2179193Sjb * Copyright (c) 1994 Geoffrey M. Rehmet 3179193Sjb * All rights reserved. 4179193Sjb * 5179193Sjb * Redistribution and use in source and binary forms, with or without 6179193Sjb * modification, are permitted provided that the following conditions 7179193Sjb * are met: 8179193Sjb * 1. Redistributions of source code must retain the above copyright 9179193Sjb * notice, this list of conditions and the following disclaimer. 10179193Sjb * 2. Redistributions in binary form must reproduce the above copyright 11179193Sjb * notice, this list of conditions and the following disclaimer in the 12179193Sjb * documentation and/or other materials provided with the distribution. 13179193Sjb * 3. All advertising materials mentioning features or use of this software 14179193Sjb * must display the following acknowledgement: 15179193Sjb * This product includes software developed by Geoffrey M. Rehmet 16179193Sjb * 4. The name of the author may not be used to endorse or promote products 17179193Sjb * derived from this software withough specific prior written permission 18179193Sjb * 19179193Sjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20179193Sjb * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21179193Sjb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22179193Sjb * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23179193Sjb * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24179193Sjb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25179193Sjb * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26179193Sjb * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27179193Sjb * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28179193Sjb * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29179193Sjb * 30179193Sjb * $Id: lptcontrol.c,v 1.2 1994/04/08 22:23:39 csgr Exp $ 31179193Sjb */ 32179193Sjb 33179193Sjb#include <sys/types.h> 34179193Sjb#include <sys/file.h> 35179193Sjb#include <sys/ioctl.h> 36179193Sjb#include <machine/lpt.h> 37179193Sjb#include <stdlib.h> 38179193Sjb#include <unistd.h> 39179193Sjb#include <stdio.h> 40179193Sjb#include <string.h> 41179193Sjb#include <sys/errno.h> 42179193Sjb 43179193Sjb 44179193Sjb#define DEFAULT_LPT "/dev/lpt0" 45179193Sjb#define IRQ_INVALID -1 46179193Sjb#define DO_POLL 0 47179193Sjb#define USE_IRQ 1 48179193Sjb 49179193Sjbstatic char default_printer[] = DEFAULT_LPT; 50179193Sjb 51179193Sjbstatic void usage(const char * progname) 52179193Sjb{ 53179193Sjb fprintf(stderr, "usage: %s -i | -p [-f <file name>]\n", progname); 54179193Sjb exit(1); 55179193Sjb} 56179193Sjb 57179193Sjbstatic void set_interrupt_status(int irq_status, const char * file) 58179193Sjb{ 59179193Sjb int fd; 60179193Sjb 61179193Sjb if((fd = open(file, O_WRONLY, 0660)) < 0) { 62179193Sjb perror("open"); 63179193Sjb exit(1); 64179193Sjb } 65179193Sjb if(ioctl(fd, LPT_IRQ, &irq_status) < 0) { 66179193Sjb perror("ioctl"); 67179193Sjb exit(1); 68179193Sjb } 69179193Sjb close(fd); 70179193Sjb} 71179193Sjb 72179193Sjb 73179193Sjbint main (int argc, char * argv[]) 74179193Sjb{ 75179193Sjb int opt; 76179193Sjb int irq_status = -1; 77179193Sjb char * file = default_printer; 78179193Sjb 79179193Sjb while((opt = getopt(argc, argv, "pif:")) != -1) 80179193Sjb switch(opt) { 81179193Sjb case 'i': irq_status = USE_IRQ; break; 82179193Sjb case 'p': irq_status = DO_POLL; break; 83179193Sjb case 'f': file = optarg; break; 84179193Sjb default : usage(argv[0]); 85179193Sjb } 86179193Sjb if(irq_status == IRQ_INVALID) usage(argv[0]); 87179193Sjb 88179193Sjb set_interrupt_status(irq_status, file); 89179193Sjb 90179193Sjb exit(0); 91179193Sjb} 92179193Sjb 93179193Sjb 94179193Sjb