16dc3c6f7SGeoff Rehmet /* 26dc3c6f7SGeoff Rehmet * Copyright (c) 1994 Geoffrey M. Rehmet 36dc3c6f7SGeoff Rehmet * All rights reserved. 46dc3c6f7SGeoff Rehmet * 56dc3c6f7SGeoff Rehmet * Redistribution and use in source and binary forms, with or without 66dc3c6f7SGeoff Rehmet * modification, are permitted provided that the following conditions 76dc3c6f7SGeoff Rehmet * are met: 86dc3c6f7SGeoff Rehmet * 1. Redistributions of source code must retain the above copyright 96dc3c6f7SGeoff Rehmet * notice, this list of conditions and the following disclaimer. 106dc3c6f7SGeoff Rehmet * 2. Redistributions in binary form must reproduce the above copyright 116dc3c6f7SGeoff Rehmet * notice, this list of conditions and the following disclaimer in the 126dc3c6f7SGeoff Rehmet * documentation and/or other materials provided with the distribution. 136dc3c6f7SGeoff Rehmet * 3. All advertising materials mentioning features or use of this software 146dc3c6f7SGeoff Rehmet * must display the following acknowledgement: 156dc3c6f7SGeoff Rehmet * This product includes software developed by Geoffrey M. Rehmet 166dc3c6f7SGeoff Rehmet * 4. The name of the author may not be used to endorse or promote products 176dc3c6f7SGeoff Rehmet * derived from this software withough specific prior written permission 186dc3c6f7SGeoff Rehmet * 196dc3c6f7SGeoff Rehmet * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 206dc3c6f7SGeoff Rehmet * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 216dc3c6f7SGeoff Rehmet * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 226dc3c6f7SGeoff Rehmet * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 236dc3c6f7SGeoff Rehmet * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 246dc3c6f7SGeoff Rehmet * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 256dc3c6f7SGeoff Rehmet * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 266dc3c6f7SGeoff Rehmet * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 276dc3c6f7SGeoff Rehmet * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 286dc3c6f7SGeoff Rehmet * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 296dc3c6f7SGeoff Rehmet */ 306dc3c6f7SGeoff Rehmet 31fe577fe9SPhilippe Charnier #ifndef lint 32fe577fe9SPhilippe Charnier static const char rcsid[] = 33fe577fe9SPhilippe Charnier "$Id$"; 34fe577fe9SPhilippe Charnier #endif /* not lint */ 35fe577fe9SPhilippe Charnier 3612365022SGeoff Rehmet #include <ctype.h> 37fe577fe9SPhilippe Charnier #include <err.h> 3812365022SGeoff Rehmet #include <limits.h> 3912365022SGeoff Rehmet #include <paths.h> 4012365022SGeoff Rehmet #include <stdio.h> 4112365022SGeoff Rehmet #include <stdlib.h> 4212365022SGeoff Rehmet #include <string.h> 4312365022SGeoff Rehmet #include <unistd.h> 4412365022SGeoff Rehmet 4512365022SGeoff Rehmet #include <machine/lpt.h> 466dc3c6f7SGeoff Rehmet #include <sys/file.h> 476dc3c6f7SGeoff Rehmet #include <sys/ioctl.h> 4812365022SGeoff Rehmet #include <sys/types.h> 496dc3c6f7SGeoff Rehmet 506dc3c6f7SGeoff Rehmet 5112365022SGeoff Rehmet #define PATH_LPCTL _PATH_DEV "lpctl" 5212365022SGeoff Rehmet #define DEFAULT_UNIT "0" 536dc3c6f7SGeoff Rehmet #define IRQ_INVALID -1 546dc3c6f7SGeoff Rehmet #define DO_POLL 0 556dc3c6f7SGeoff Rehmet #define USE_IRQ 1 566dc3c6f7SGeoff Rehmet 57fe577fe9SPhilippe Charnier static void usage() 586dc3c6f7SGeoff Rehmet { 59fe577fe9SPhilippe Charnier fprintf(stderr, "usage: lptcontrol -i | -p [-u <unit no.>]\n"); 606dc3c6f7SGeoff Rehmet exit(1); 616dc3c6f7SGeoff Rehmet } 626dc3c6f7SGeoff Rehmet 636dc3c6f7SGeoff Rehmet static void set_interrupt_status(int irq_status, const char * file) 646dc3c6f7SGeoff Rehmet { 656dc3c6f7SGeoff Rehmet int fd; 666dc3c6f7SGeoff Rehmet 67fe577fe9SPhilippe Charnier if((fd = open(file, O_WRONLY, 0660)) < 0) 68fe577fe9SPhilippe Charnier err(1, "open"); 69fe577fe9SPhilippe Charnier if(ioctl(fd, LPT_IRQ, &irq_status) < 0) 70fe577fe9SPhilippe Charnier err(1, "ioctl"); 716dc3c6f7SGeoff Rehmet close(fd); 726dc3c6f7SGeoff Rehmet } 736dc3c6f7SGeoff Rehmet 7412365022SGeoff Rehmet static char * dev_file(char unit_no) 7512365022SGeoff Rehmet { 7612365022SGeoff Rehmet static char devname[_POSIX_PATH_MAX+1]; 7712365022SGeoff Rehmet int len; 7812365022SGeoff Rehmet 7912365022SGeoff Rehmet strncpy(devname, PATH_LPCTL, _POSIX_PATH_MAX); 8012365022SGeoff Rehmet devname[len = strlen(devname)] = unit_no; 8112365022SGeoff Rehmet devname[++len] = '\0'; 8212365022SGeoff Rehmet 8312365022SGeoff Rehmet return(devname); 8412365022SGeoff Rehmet } 856dc3c6f7SGeoff Rehmet 866dc3c6f7SGeoff Rehmet int main (int argc, char * argv[]) 876dc3c6f7SGeoff Rehmet { 886dc3c6f7SGeoff Rehmet int opt; 8912365022SGeoff Rehmet int irq_status = IRQ_INVALID; 9012365022SGeoff Rehmet char * unit = DEFAULT_UNIT; 916dc3c6f7SGeoff Rehmet 9212365022SGeoff Rehmet while((opt = getopt(argc, argv, "ipu:")) != -1) 936dc3c6f7SGeoff Rehmet switch(opt) { 946dc3c6f7SGeoff Rehmet case 'i': irq_status = USE_IRQ; break; 956dc3c6f7SGeoff Rehmet case 'p': irq_status = DO_POLL; break; 9612365022SGeoff Rehmet case 'u': unit = optarg; 9712365022SGeoff Rehmet if(!isdigit(*unit)) 98fe577fe9SPhilippe Charnier usage(); 9912365022SGeoff Rehmet break; 100fe577fe9SPhilippe Charnier default : usage(); 1016dc3c6f7SGeoff Rehmet } 10212365022SGeoff Rehmet if(irq_status == IRQ_INVALID) 103fe577fe9SPhilippe Charnier usage(); 1046dc3c6f7SGeoff Rehmet 10512365022SGeoff Rehmet set_interrupt_status(irq_status, dev_file(*unit)); 1066dc3c6f7SGeoff Rehmet 1076dc3c6f7SGeoff Rehmet exit(0); 1086dc3c6f7SGeoff Rehmet } 109