1 /* $NetBSD: wsconscfg.c,v 1.16 2007/12/15 19:44:57 perry Exp $ */
5 * Matthias Drochner. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
34 #include <sys/types.h>
35 #include <sys/ioctl.h>
39 #include <dev/wscons/wsconsio.h>
40 #include <dev/wscons/wsdisplay_usl_io.h>
42 #define DEFDEV "/dev/ttyEcfg"
44 static void usage(void) __dead
;
45 int main(int, char **);
50 const char *p
= getprogname();
52 "Usage: %s [-e emul] [-f ctldev] [-t type] index\n"
53 "\t%s -d [-F] [-f ctldev] index\n"
54 "\t%s -g [-f ctldev]\n"
55 "\t%s -k | -m [-d] [-f ctldev] [index]\n"
56 "\t%s -s [-f ctldev] index\n", p
, p
, p
, p
, p
);
61 main(int argc
, char **argv
)
64 int c
, delete, kbd
, idx
, wsfd
, swtch
, get
, mux
;
65 struct wsdisplay_addscreendata asd
;
66 struct wsdisplay_delscreendata dsd
;
67 struct wsmux_device wmd
;
81 while ((c
= getopt(argc
, argv
, "de:Ff:gkmst:")) != -1) {
90 dsd
.flags
|= WSDISPLAY_DELSCR_FORCE
;
109 asd
.screentype
= optarg
;
120 if (!get
|| argc
!= 0) {
121 if ((kbd
|| swtch
) ? (argc
> 1) : (argc
!= 1))
124 if (argc
> 0 && sscanf(argv
[0], "%d", &idx
) != 1)
125 errx(1, "invalid index");
127 if ((wsfd
= open(wsdev
, get
? O_RDONLY
: O_RDWR
)) == -1)
128 err(EXIT_FAILURE
, "Cannot open `%s'", wsdev
);
132 if (ioctl(wsfd
, VT_ACTIVATE
, idx
) == -1)
133 err(EXIT_FAILURE
, "Cannot switch to %d", idx
);
135 if (ioctl(wsfd
, VT_GETACTIVE
, &idx
) == -1)
136 err(EXIT_FAILURE
, "Cannot get current screen");
137 (void)printf("%d\n", idx
);
139 wmd
.type
= mux
? WSMUX_MUX
: WSMUX_KBD
;
142 if (ioctl(wsfd
, WSMUX_REMOVE_DEVICE
, &wmd
) == -1)
143 err(EXIT_FAILURE
, "WSMUX_REMOVE_DEVICE");
145 if (ioctl(wsfd
, WSMUX_ADD_DEVICE
, &wmd
) == -1)
146 err(EXIT_FAILURE
, "WSMUX_ADD_DEVICE");
150 if (ioctl(wsfd
, WSDISPLAYIO_DELSCREEN
, &dsd
) == -1)
151 err(EXIT_FAILURE
, "WSDISPLAYIO_DELSCREEN");
154 if (ioctl(wsfd
, WSDISPLAYIO_ADDSCREEN
, &asd
) == -1) {
157 "screen %d is already configured", idx
);
159 err(EXIT_FAILURE
, "WSDISPLAYIO_ADDSCREEN");