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