lptcontrol.c (b728350ee67c01f96c3c5121774536fee81ad176) lptcontrol.c (4ae6befa9382e45f903e42b869df75bc5e1b4292)
1/*
2 * Copyright (c) 1994 Geoffrey M. Rehmet
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD$");
33
1/*
2 * Copyright (c) 1994 Geoffrey M. Rehmet
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD$");
33
34#include <ctype.h>
34#include <dev/ppbus/lptio.h>
35
35#include <err.h>
36#include <err.h>
36#include <limits.h>
37#include <paths.h>
37#include <fcntl.h>
38#include <unistd.h>
39
38#include <stdio.h>
39#include <stdlib.h>
40#include <stdio.h>
41#include <stdlib.h>
40#include <string.h>
41#include <unistd.h>
42
42
43#include <dev/ppbus/lptio.h>
44#include <sys/file.h>
45#include <sys/ioctl.h>
46#include <sys/types.h>
47
48
49#define PATH_LPCTL _PATH_DEV "lpctl"
50#define DEFAULT_DEVICE _PATH_DEV "lpt0"
51#define IRQ_INVALID -1
43#define DEFAULT_DEVICE "/dev/lpt0.ctl"
44#define IRQ_UNSPECIFIED -1
52#define DO_POLL 0
53#define USE_IRQ 1
54#define USE_EXT_MODE 2
55#define USE_STD_MODE 3
56
57static void usage(void)
58{
45#define DO_POLL 0
46#define USE_IRQ 1
47#define USE_EXT_MODE 2
48#define USE_STD_MODE 3
49
50static void usage(void)
51{
59 fprintf(stderr, "usage: lptcontrol -i | -p | -s | -e [-d device]\n");
52 fprintf(stderr,
53 "usage: lptcontrol -e | -i | -p | -s [[-d] controldevice]\n");
60 exit(1);
61}
62
54 exit(1);
55}
56
63static void set_interrupt_status(int irq_status, const char * file)
57int main (int argc, char **argv)
64{
58{
65 int fd;
59 const char *device;
60 int fd;
61 int irq_status;
62 int opt;
66
63
67 if((fd = open(file, O_WRONLY, 0660)) < 0)
64 device = DEFAULT_DEVICE;
65 irq_status = IRQ_UNSPECIFIED;
66 while ((opt = getopt(argc, argv, "d:eips")) != -1)
67 switch (opt) {
68 case 'd':
69 device = optarg;
70 break;
71 case 'e':
72 irq_status = USE_EXT_MODE;
73 break;
74 case 'i':
75 irq_status = USE_IRQ;
76 break;
77 case 'p':
78 irq_status = DO_POLL;
79 break;
80 case 's':
81 irq_status = USE_STD_MODE;
82 break;
83 case '?':
84 default:
85 usage();
86 /* NOTREACHED */
87 }
88 argc -= optind;
89 argv += optind;
90 /* POLA: DTRT if -d was forgotten, but device name was specified. */
91 if (argc == 1) {
92 device = argv[0];
93 --argc;
94 }
95
96 if (irq_status == IRQ_UNSPECIFIED || argc != 0)
97 usage();
98
99 if ((fd = open(device, O_WRONLY, 0660)) < 0)
68 err(1, "open");
100 err(1, "open");
69 if(ioctl(fd, LPT_IRQ, &irq_status) < 0)
101 if (ioctl(fd, LPT_IRQ, &irq_status) < 0)
70 err(1, "ioctl");
71 close(fd);
102 err(1, "ioctl");
103 close(fd);
72}
73
104
74int main (int argc, char * argv[])
75{
76 int opt;
77 int irq_status = IRQ_INVALID;
78 const char *device = DEFAULT_DEVICE;
79
80 while((opt = getopt(argc, argv, "ipesd:")) != -1)
81 switch(opt) {
82 case 'i': irq_status = USE_IRQ; break;
83 case 'p': irq_status = DO_POLL; break;
84 case 'e': irq_status = USE_EXT_MODE; break;
85 case 's': irq_status = USE_STD_MODE; break;
86 case 'd': device = optarg; break;
87 default : usage();
88 }
89 if(irq_status == IRQ_INVALID)
90 usage();
91
92 set_interrupt_status(irq_status, device);
93
94 exit(0);
105 return(0);
95}
106}