1 /* $NetBSD: wsconsctl.c,v 1.17 2008/04/28 20:23:09 martin Exp $ */
4 * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
40 #include "wsconsctl.h"
42 #define PATH_KEYBOARD "/dev/wskbd"
43 #define PATH_MOUSE "/dev/wsmouse"
44 #define PATH_DISPLAY "/dev/ttyE0"
46 extern struct field keyboard_field_tab
[];
47 extern struct field mouse_field_tab
[];
48 extern struct field display_field_tab
[];
49 extern int keyboard_field_tab_len
;
50 extern int mouse_field_tab_len
;
51 extern int display_field_tab_len
;
53 static void usage(const char *) __dead
;
56 usage(const char *msg
)
58 const char *progname
= getprogname();
61 (void)fprintf(stderr
, "%s: %s\n\n", progname
, msg
);
64 "Usage: %s [-kmd] [-f file] [-n] name ...\n"
65 " -or- %s [-kmd] [-f file] [-n] -w name=value ...\n"
66 " -or- %s [-kmd] [-f file] [-n] -w name+=value ...\n"
67 " -or- %s [-kmd] [-f file] [-n] -a\n",
68 progname
, progname
, progname
, progname
);
74 main(int argc
, char **argv
)
77 int aflag
, dflag
, kflag
, mflag
, wflag
;
79 const char *sep
, *file
;
80 struct field
*f
, *field_tab
;
81 int do_merge
, field_tab_len
;
97 while ((ch
= getopt(argc
, argv
, "adf:kmnw")) != -1) {
129 if (dflag
+ kflag
+ mflag
== 0)
131 if (dflag
+ kflag
+ mflag
> 1)
132 usage("only one of -k, -d or -m may be given");
133 if (argc
> 0 && aflag
!= 0)
134 usage("excess arguments after -a");
135 if (aflag
!= 0 && wflag
!= 0)
136 usage("only one of -a or -w may be given");
140 file
= PATH_KEYBOARD
;
141 field_tab
= keyboard_field_tab
;
142 field_tab_len
= keyboard_field_tab_len
;
143 getval
= keyboard_get_values
;
144 putval
= keyboard_put_values
;
148 field_tab
= mouse_field_tab
;
149 field_tab_len
= mouse_field_tab_len
;
150 getval
= mouse_get_values
;
151 putval
= mouse_put_values
;
155 field_tab
= display_field_tab
;
156 field_tab_len
= display_field_tab_len
;
157 getval
= display_get_values
;
158 putval
= display_put_values
;
161 field_setup(field_tab
, field_tab_len
);
163 fd
= open(file
, O_WRONLY
);
165 fd
= open(file
, O_RDONLY
);
167 err(EXIT_FAILURE
, "%s", file
);
170 for (i
= 0; i
< field_tab_len
; i
++)
171 if ((field_tab
[i
].flags
& (FLG_NOAUTO
|FLG_WRONLY
)) == 0)
172 field_tab
[i
].flags
|= FLG_GET
;
174 for (i
= 0; i
< field_tab_len
; i
++)
175 if (field_tab
[i
].flags
& FLG_NOAUTO
)
176 warnx("\"%s\" not shown with -a; use \"%s %s\""
179 getprogname(), field_tab
[i
].name
);
180 else if (field_tab
[i
].flags
& FLG_GET
&&
181 !(field_tab
[i
].flags
& FLG_DISABLED
))
182 pr_field(field_tab
+ i
, sep
);
183 } else if (argc
> 0) {
185 for (i
= 0; i
< argc
; i
++) {
186 p
= strchr(argv
[i
], '=');
188 errx(EXIT_FAILURE
, "'=' not found");
189 if (p
> argv
[i
] && *(p
- 1) == '+') {
195 f
= field_by_name(argv
[i
]);
196 if ((f
->flags
& FLG_RDONLY
) != 0)
197 errx(EXIT_FAILURE
, "%s: read only",
200 if ((f
->flags
& FLG_MODIFY
) == 0)
202 "%s: can only be set",
206 f
->flags
&= ~FLG_GET
;
208 rd_field(f
, p
, do_merge
);
211 f
->flags
&= ~FLG_SET
;
214 for (i
= 0; i
< argc
; i
++) {
215 f
= field_by_name(argv
[i
]);
216 if ((f
->flags
& FLG_WRONLY
) != 0)
217 errx(EXIT_FAILURE
, "%s: write only",
222 for (i
= 0; i
< field_tab_len
; i
++) {
223 if (field_tab
[i
].flags
& FLG_DISABLED
)
225 "%s: no kernel support",
227 if (field_tab
[i
].flags
& FLG_GET
)
228 pr_field(field_tab
+ i
, sep
);