wsconscfg.c revision 1.5 1 /* $NetBSD: wsconscfg.c,v 1.5 1999/11/10 16:34:58 drochner 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 <fcntl.h>
37 #include <unistd.h>
38 #include <sys/types.h>
39 #include <sys/ioctl.h>
40 #include <err.h>
41 #include <errno.h>
42
43 #include <dev/wscons/wsconsio.h>
44
45 #define DEFDEV "/dev/ttyEcfg"
46
47 static void usage __P((void));
48 int main __P((int, char**));
49
50 static void
51 usage()
52 {
53 extern char *__progname;
54
55 (void)fprintf(stderr,
56 "Usage: %s [-f wsdev] [-d [-F]] [-k] [-m] [-t type]"
57 "[-e emul] {vt | [kbd] | [mux]}\n", __progname);
58 exit(1);
59 }
60
61 int
62 main(argc, argv)
63 int argc;
64 char **argv;
65 {
66 char *wsdev;
67 int c, delete, kbd, idx, wsfd, res, mux;
68 struct wsdisplay_addscreendata asd;
69 struct wsdisplay_delscreendata dsd;
70 struct wsmux_device wmd;
71
72 wsdev = DEFDEV;
73 delete = 0;
74 kbd = 0;
75 mux = 0;
76 asd.screentype = 0;
77 asd.emul = 0;
78 dsd.flags = 0;
79
80 while ((c = getopt(argc, argv, "f:dkmt:e:F")) != -1) {
81 switch (c) {
82 case 'f':
83 wsdev = optarg;
84 break;
85 case 'd':
86 delete++;
87 break;
88 case 'k':
89 kbd++;
90 break;
91 case 'm':
92 mux++;
93 kbd++;
94 break;
95 case 't':
96 asd.screentype = optarg;
97 break;
98 case 'e':
99 asd.emul = optarg;
100 break;
101 case 'F':
102 dsd.flags |= WSDISPLAY_DELSCR_FORCE;
103 break;
104 case '?':
105 default:
106 usage();
107 break;
108 }
109 }
110 argc -= optind;
111 argv += optind;
112
113 if (kbd ? (argc > 1) : (argc != 1))
114 usage();
115
116 idx = -1;
117 if (argc > 0 && sscanf(argv[0], "%d", &idx) != 1)
118 errx(1, "invalid index");
119
120 wsfd = open(wsdev, O_RDWR, 0);
121 if (wsfd < 0)
122 err(2, wsdev);
123
124 if (kbd) {
125 if (mux)
126 wmd.type = WSMUX_MUX;
127 else
128 wmd.type = WSMUX_KBD;
129 wmd.idx = idx;
130 if (delete) {
131 res = ioctl(wsfd, WSMUX_REMOVE_DEVICE, &wmd);
132 if (res < 0)
133 err(3, "WSMUX_REMOVE_DEVICE");
134 } else {
135 res = ioctl(wsfd, WSMUX_ADD_DEVICE, &wmd);
136 if (res < 0)
137 err(3, "WSMUX_ADD_DEVICE");
138 }
139 } else if (delete) {
140 dsd.idx = idx;
141 res = ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd);
142 if (res < 0)
143 err(3, "WSDISPLAYIO_DELSCREEN");
144 } else {
145 asd.idx = idx;
146 res = ioctl(wsfd, WSDISPLAYIO_ADDSCREEN, &asd);
147 if (res < 0) {
148 if (errno == EBUSY)
149 errx(3, "screen %d is already configured", idx);
150 else
151 err(3, "WSDISPLAYIO_ADDSCREEN");
152 }
153 }
154
155 return (0);
156 }
157