wsconscfg.c revision 1.2 1 /* $NetBSD: wsconscfg.c,v 1.2 1999/03/13 17:25:55 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
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]] [-t type] [-e emul] vt\n",
56 __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, idx, wsfd, res;
67 struct wsdisplay_addscreendata asd;
68 struct wsdisplay_delscreendata dsd;
69
70 wsdev = DEFDEV;
71 delete = 0;
72 asd.screentype = 0;
73 asd.emul = 0;
74 dsd.flags = 0;
75
76 while ((c = getopt(argc, argv, "f:dt:e:F")) != -1) {
77 switch (c) {
78 case 'f':
79 wsdev = optarg;
80 break;
81 case 'd':
82 delete++;
83 break;
84 case 't':
85 asd.screentype = optarg;
86 break;
87 case 'e':
88 asd.emul = optarg;
89 break;
90 case 'F':
91 dsd.flags |= WSDISPLAY_DELSCR_FORCE;
92 break;
93 case '?':
94 default:
95 usage();
96 break;
97 }
98 }
99 argc -= optind;
100 argv += optind;
101
102 if (argc != 1)
103 usage();
104
105 if (sscanf(argv[0], "%d", &idx) != 1)
106 errx(1, "invalid index");
107
108 wsfd = open(wsdev, O_RDWR, 0);
109 if (wsfd < 0)
110 err(2, wsdev);
111
112 if (delete) {
113 dsd.idx = idx;
114 res = ioctl(wsfd, WSDISPLAYIO_DELSCREEN, &dsd);
115 if (res < 0)
116 err(3, "WSDISPLAYIO_DELSCREEN");
117 } else {
118 asd.idx = idx;
119 res = ioctl(wsfd, WSDISPLAYIO_ADDSCREEN, &asd);
120 if (res < 0)
121 err(3, "WSDISPLAYIO_ADDSCREEN");
122 }
123
124 return (0);
125 }
126