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