wsconscfg.c revision 1.7 1 /* $NetBSD: wsconscfg.c,v 1.7 2000/07/07 15:11:47 itojun Exp $ */
2
3 /*
4 * Copyright (c) 1999
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project
18 * by Matthias Drochner.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <fcntl.h>
38 #include <unistd.h>
39 #include <sys/types.h>
40 #include <sys/ioctl.h>
41 #include <err.h>
42 #include <errno.h>
43
44 #include <dev/wscons/wsconsio.h>
45
46 #define DEFDEV "/dev/ttyEcfg"
47
48 static void usage __P((void));
49 int main __P((int, char**));
50
51 static void
52 usage()
53 {
54 extern char *__progname;
55
56 (void)fprintf(stderr,
57 "Usage: %s [-f wsdev] [-d [-F]] [-k] [-m] [-t type]"
58 "[-e emul] {vt | [kbd] | [mux]}\n", __progname);
59 exit(1);
60 }
61
62 int
63 main(argc, argv)
64 int argc;
65 char **argv;
66 {
67 char *wsdev;
68 int c, delete, kbd, idx, wsfd, res, mux;
69 struct wsdisplay_addscreendata asd;
70 struct wsdisplay_delscreendata dsd;
71 struct wsmux_device wmd;
72
73 wsdev = DEFDEV;
74 delete = 0;
75 kbd = 0;
76 mux = 0;
77 asd.screentype = 0;
78 asd.emul = 0;
79 dsd.flags = 0;
80
81 while ((c = getopt(argc, argv, "f:dkmt:e:F")) != -1) {
82 switch (c) {
83 case 'f':
84 wsdev = optarg;
85 break;
86 case 'd':
87 delete++;
88 break;
89 case 'k':
90 kbd++;
91 break;
92 case 'm':
93 mux++;
94 kbd++;
95 break;
96 case 't':
97 asd.screentype = optarg;
98 break;
99 case 'e':
100 asd.emul = optarg;
101 break;
102 case 'F':
103 dsd.flags |= WSDISPLAY_DELSCR_FORCE;
104 break;
105 case '?':
106 default:
107 usage();
108 break;
109 }
110 }
111 argc -= optind;
112 argv += optind;
113
114 if (kbd ? (argc > 1) : (argc != 1))
115 usage();
116
117 idx = -1;
118 if (argc > 0 && sscanf(argv[0], "%d", &idx) != 1)
119 errx(1, "invalid index");
120
121 wsfd = open(wsdev, O_RDWR, 0);
122 if (wsfd < 0)
123 err(2, "%s", wsdev);
124
125 if (kbd) {
126 if (mux)
127 wmd.type = WSMUX_MUX;
128 else
129 wmd.type = WSMUX_KBD;
130 wmd.idx = idx;
131 if (delete) {
132 res = ioctl(wsfd, WSMUX_REMOVE_DEVICE, &wmd);
133 if (res < 0)
134 err(3, "WSMUX_REMOVE_DEVICE");
135 } else {
136 res = ioctl(wsfd, WSMUX_ADD_DEVICE, &wmd);
137 if (res < 0)
138 err(3, "WSMUX_ADD_DEVICE");
139 }
140 } else if (delete) {
141 dsd.idx = idx;
142 res = ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd);
143 if (res < 0)
144 err(3, "WSDISPLAYIO_DELSCREEN");
145 } else {
146 asd.idx = idx;
147 res = ioctl(wsfd, WSDISPLAYIO_ADDSCREEN, &asd);
148 if (res < 0) {
149 if (errno == EBUSY)
150 errx(3, "screen %d is already configured", idx);
151 else
152 err(3, "WSDISPLAYIO_ADDSCREEN");
153 }
154 }
155
156 return (0);
157 }
158