2001-02-20 02:22:40 +03:00
|
|
|
/* $NetBSD: wsconscfg.c,v 1.8 2001/02/19 23:22:49 cgd Exp $ */
|
1999-01-13 20:15:44 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1999
|
|
|
|
* Matthias Drochner. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed for the NetBSD Project
|
|
|
|
* by Matthias Drochner.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2000-07-05 00:27:35 +04:00
|
|
|
#include <stdlib.h>
|
1999-01-13 20:15:44 +03:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <err.h>
|
1999-11-10 19:34:58 +03:00
|
|
|
#include <errno.h>
|
1999-01-13 20:15:44 +03:00
|
|
|
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
|
|
|
|
#define DEFDEV "/dev/ttyEcfg"
|
|
|
|
|
|
|
|
static void usage __P((void));
|
|
|
|
int main __P((int, char**));
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
|
|
|
|
(void)fprintf(stderr,
|
1999-07-29 22:24:09 +04:00
|
|
|
"Usage: %s [-f wsdev] [-d [-F]] [-k] [-m] [-t type]"
|
2001-02-20 02:22:40 +03:00
|
|
|
"[-e emul] {vt | [kbd] | [mux]}\n", getprogname());
|
1999-01-13 20:15:44 +03:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
char *wsdev;
|
1999-07-29 22:24:09 +04:00
|
|
|
int c, delete, kbd, idx, wsfd, res, mux;
|
1999-01-13 20:15:44 +03:00
|
|
|
struct wsdisplay_addscreendata asd;
|
|
|
|
struct wsdisplay_delscreendata dsd;
|
1999-07-29 22:24:09 +04:00
|
|
|
struct wsmux_device wmd;
|
1999-01-13 20:15:44 +03:00
|
|
|
|
|
|
|
wsdev = DEFDEV;
|
|
|
|
delete = 0;
|
1999-05-15 18:24:45 +04:00
|
|
|
kbd = 0;
|
1999-07-29 22:24:09 +04:00
|
|
|
mux = 0;
|
1999-01-13 20:15:44 +03:00
|
|
|
asd.screentype = 0;
|
|
|
|
asd.emul = 0;
|
|
|
|
dsd.flags = 0;
|
|
|
|
|
1999-07-29 22:24:09 +04:00
|
|
|
while ((c = getopt(argc, argv, "f:dkmt:e:F")) != -1) {
|
1999-01-13 20:15:44 +03:00
|
|
|
switch (c) {
|
|
|
|
case 'f':
|
|
|
|
wsdev = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
delete++;
|
|
|
|
break;
|
1999-05-15 18:24:45 +04:00
|
|
|
case 'k':
|
|
|
|
kbd++;
|
|
|
|
break;
|
1999-07-29 22:24:09 +04:00
|
|
|
case 'm':
|
|
|
|
mux++;
|
|
|
|
kbd++;
|
|
|
|
break;
|
1999-01-13 20:15:44 +03:00
|
|
|
case 't':
|
|
|
|
asd.screentype = optarg;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
asd.emul = optarg;
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
dsd.flags |= WSDISPLAY_DELSCR_FORCE;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1999-05-15 18:24:45 +04:00
|
|
|
if (kbd ? (argc > 1) : (argc != 1))
|
1999-01-13 20:15:44 +03:00
|
|
|
usage();
|
|
|
|
|
1999-05-15 18:24:45 +04:00
|
|
|
idx = -1;
|
|
|
|
if (argc > 0 && sscanf(argv[0], "%d", &idx) != 1)
|
1999-01-13 20:15:44 +03:00
|
|
|
errx(1, "invalid index");
|
|
|
|
|
|
|
|
wsfd = open(wsdev, O_RDWR, 0);
|
|
|
|
if (wsfd < 0)
|
2000-07-07 19:10:32 +04:00
|
|
|
err(2, "%s", wsdev);
|
1999-01-13 20:15:44 +03:00
|
|
|
|
1999-05-15 18:24:45 +04:00
|
|
|
if (kbd) {
|
1999-07-29 22:24:09 +04:00
|
|
|
if (mux)
|
|
|
|
wmd.type = WSMUX_MUX;
|
|
|
|
else
|
|
|
|
wmd.type = WSMUX_KBD;
|
|
|
|
wmd.idx = idx;
|
|
|
|
if (delete) {
|
|
|
|
res = ioctl(wsfd, WSMUX_REMOVE_DEVICE, &wmd);
|
|
|
|
if (res < 0)
|
|
|
|
err(3, "WSMUX_REMOVE_DEVICE");
|
|
|
|
} else {
|
|
|
|
res = ioctl(wsfd, WSMUX_ADD_DEVICE, &wmd);
|
|
|
|
if (res < 0)
|
|
|
|
err(3, "WSMUX_ADD_DEVICE");
|
|
|
|
}
|
1999-05-15 18:24:45 +04:00
|
|
|
} else if (delete) {
|
1999-01-13 20:15:44 +03:00
|
|
|
dsd.idx = idx;
|
|
|
|
res = ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd);
|
|
|
|
if (res < 0)
|
|
|
|
err(3, "WSDISPLAYIO_DELSCREEN");
|
|
|
|
} else {
|
|
|
|
asd.idx = idx;
|
|
|
|
res = ioctl(wsfd, WSDISPLAYIO_ADDSCREEN, &asd);
|
1999-11-10 19:34:58 +03:00
|
|
|
if (res < 0) {
|
|
|
|
if (errno == EBUSY)
|
|
|
|
errx(3, "screen %d is already configured", idx);
|
|
|
|
else
|
|
|
|
err(3, "WSDISPLAYIO_ADDSCREEN");
|
|
|
|
}
|
1999-01-13 20:15:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|