tadpolectl.c revision 1.1 1 /* $NetBSD: tadpolectl.c,v 1.1 1999/12/17 05:30:03 garbled Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <ctype.h>
40 #include <err.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <stdlib.h>
44 #include <fcntl.h>
45 #include <unistd.h>
46 #include <sys/ioctl.h>
47 #include <sys/types.h>
48 #include <sys/envsys.h>
49 #include <sys/apmvar.h>
50 #include <machine/tctrl.h>
51
52 int aflag, nflag, wflag, dev;
53
54 #define PROTO(x) int x __P((int, int, int));
55 char *dashdot __P((char *));
56 PROTO(hw_version)
57 PROTO(hw_microcontroller_version)
58 PROTO(hw_poweroncycles)
59 PROTO(hw_poweronseconds)
60 PROTO(hw_power_mains)
61 PROTO(hw_power_battery_int)
62 PROTO(hw_power_battery_ext)
63 PROTO(hw_power_battery_int_chargerate)
64 PROTO(hw_power_battery_ext_chargerate)
65 PROTO(hw_power_battery_int_chargelevel)
66 PROTO(hw_power_battery_ext_chargelevel)
67 PROTO(hw_video_external)
68 PROTO(hw_video_lid)
69 PROTO(hw_video_syncinva)
70 PROTO(hw_video_syncinvb)
71 PROTO(hw_video_compsync)
72 PROTO(hw_video_tft_brightness)
73 PROTO(hw_speaker_freq)
74 PROTO(hw_speaker_volume)
75 PROTO(hw_kbd_repeat_delay)
76 PROTO(hw_kbd_repeat_speed)
77 PROTO(hw_mouse_recalibrate)
78 PROTO(hw_power_battery_chargedisabled)
79 PROTO(hw_mouse_disable)
80 PROTO(hw_kbd_click)
81 PROTO(hw_mouse_intclick)
82 PROTO(hw_mouse_extclick)
83 PROTO(hw_mouse_sensitivity)
84
85 #define NUM_MIBS 28
86 #define TABLE(n) { __STRING(n), 0, n }
87
88 struct {
89 char *mib;
90 int value;
91 int (*funcptr)(int, int, int);
92 } table[NUM_MIBS] = {
93 TABLE(hw_microcontroller_version),
94 TABLE(hw_version),
95 TABLE(hw_poweroncycles),
96 TABLE(hw_poweronseconds),
97 TABLE(hw_power_mains),
98 TABLE(hw_power_battery_int),
99 TABLE(hw_power_battery_ext),
100 TABLE(hw_power_battery_chargedisabled),
101 TABLE(hw_power_battery_int_chargerate),
102 TABLE(hw_power_battery_ext_chargerate),
103 TABLE(hw_power_battery_int_chargelevel),
104 TABLE(hw_power_battery_ext_chargelevel),
105 TABLE(hw_video_external),
106 TABLE(hw_video_lid),
107 TABLE(hw_video_syncinva),
108 TABLE(hw_video_syncinvb),
109 TABLE(hw_video_compsync),
110 TABLE(hw_video_tft_brightness),
111 TABLE(hw_speaker_freq),
112 TABLE(hw_speaker_volume),
113 TABLE(hw_kbd_repeat_delay),
114 TABLE(hw_kbd_repeat_speed),
115 TABLE(hw_kbd_click),
116 TABLE(hw_mouse_recalibrate),
117 TABLE(hw_mouse_disable),
118 TABLE(hw_mouse_intclick),
119 TABLE(hw_mouse_extclick),
120 TABLE(hw_mouse_sensitivity),
121 };
122
123 #define FUNC(x) \
124 int \
125 x(read, new, num) \
126 int read, new, num;
127
128 #define READ_REQ(a, b, c) \
129 req.cmdbuf[0] = a; \
130 req.cmdlen = b; \
131 req.rsplen = c; \
132 ioctl(dev, TCTRL_CMD_REQ, &req)
133
134 #define WRITE_REQ(a, b, c) \
135 req.cmdbuf[0] = a; \
136 req.cmdlen = b; \
137 req.rsplen = c; \
138 ioctl(dev, TCTRL_CMD_REQ, &req)
139
140 #define READ_ONLY \
141 if (!read) \
142 return(0)
143
144 /* hardware functions */
145
146 FUNC(hw_mouse_sensitivity)
147 {
148 struct tctrl_req req;
149
150 req.cmdbuf[1] = 0xff;
151 req.cmdbuf[2] = 0x00;
152 READ_REQ(0x2c, 3, 2);
153 table[num].value = req.rspbuf[0];
154 if (read)
155 return(1);
156 if (new == 0)
157 req.cmdbuf[2] = 0x00;
158 else if (new > 255)
159 req.cmdbuf[2] = 0xff;
160 else
161 req.cmdbuf[2] = new;
162 req.cmdbuf[1] = 0x00;
163 WRITE_REQ(0x2c, 3, 2);
164 req.cmdbuf[1] = 0xff;
165 req.cmdbuf[2] = 0x00;
166 READ_REQ(0x2c, 3, 2);
167 table[num].value = req.rspbuf[0];
168 return(1);
169 }
170
171 FUNC(hw_power_battery_chargedisabled)
172 {
173 struct tctrl_req req;
174
175 req.cmdbuf[1] = 0xff;
176 req.cmdbuf[2] = 0x00;
177 READ_REQ(0x22, 3, 2);
178 table[num].value = req.rspbuf[0]&0x01 ? 1 : 0;
179 if (read)
180 return(1);
181 if (new == 0)
182 req.cmdbuf[2] = 0x00;
183 else
184 req.cmdbuf[2] = 0x01;
185 req.cmdbuf[1] = ~0x01;
186 WRITE_REQ(0x22, 3, 2);
187 req.cmdbuf[1] = 0xff;
188 req.cmdbuf[2] = 0x00;
189 READ_REQ(0x22, 3, 2);
190 table[num].value = req.rspbuf[0]&0x01 ? 1 : 0;
191 return(1);
192 }
193
194 FUNC(hw_mouse_disable)
195 {
196 struct tctrl_req req;
197
198 req.cmdbuf[1] = 0xff;
199 req.cmdbuf[2] = 0x00;
200 READ_REQ(0x22, 3, 2);
201 table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
202 if (read)
203 return(1);
204 if (new == 0)
205 req.cmdbuf[2] = 0x00;
206 else
207 req.cmdbuf[2] = 0x02;
208 req.cmdbuf[1] = ~0x02;
209 WRITE_REQ(0x22, 3, 2);
210 req.cmdbuf[1] = 0xff;
211 req.cmdbuf[2] = 0x00;
212 READ_REQ(0x22, 3, 2);
213 table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
214 return(1);
215 }
216
217 FUNC(hw_kbd_click)
218 {
219 struct tctrl_req req;
220
221 req.cmdbuf[1] = 0xff;
222 req.cmdbuf[2] = 0x00;
223 READ_REQ(0x22, 3, 2);
224 table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
225 if (read)
226 return(1);
227 if (new == 0)
228 req.cmdbuf[2] = 0x00;
229 else
230 req.cmdbuf[2] = 0x04;
231 req.cmdbuf[1] = ~0x04;
232 WRITE_REQ(0x22, 3, 2);
233 req.cmdbuf[1] = 0xff;
234 req.cmdbuf[2] = 0x00;
235 READ_REQ(0x22, 3, 2);
236 table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
237 return(1);
238 }
239
240 FUNC(hw_mouse_intclick)
241 {
242 struct tctrl_req req;
243
244 req.cmdbuf[1] = 0xff;
245 req.cmdbuf[2] = 0x00;
246 READ_REQ(0x22, 3, 2);
247 table[num].value = req.rspbuf[0]&0x08 ? 1 : 0;
248 if (read)
249 return(1);
250 if (new == 0)
251 req.cmdbuf[2] = 0x00;
252 else
253 req.cmdbuf[2] = 0x08;
254 req.cmdbuf[1] = ~0x08;
255 WRITE_REQ(0x22, 3, 2);
256 req.cmdbuf[1] = 0xff;
257 req.cmdbuf[2] = 0x00;
258 READ_REQ(0x22, 3, 2);
259 table[num].value = req.rspbuf[0]&0x08 ? 1 : 0;
260 return(1);
261 }
262
263 FUNC(hw_mouse_extclick)
264 {
265 struct tctrl_req req;
266
267 req.cmdbuf[1] = 0xff;
268 req.cmdbuf[2] = 0x00;
269 READ_REQ(0x22, 3, 2);
270 table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
271 if (read)
272 return(1);
273 if (new == 0)
274 req.cmdbuf[2] = 0x00;
275 else
276 req.cmdbuf[2] = 0x10;
277 req.cmdbuf[1] = ~0x10;
278 WRITE_REQ(0x22, 3, 2);
279 req.cmdbuf[1] = 0xff;
280 req.cmdbuf[2] = 0x00;
281 READ_REQ(0x22, 3, 2);
282 table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
283 return(1);
284 }
285
286 /* ARGSUSED */
287 FUNC(hw_mouse_recalibrate)
288 {
289 struct tctrl_req req;
290
291 table[num].value = 0;
292 if (read)
293 return(1);
294 READ_REQ(0x36, 1, 1);
295 return(1);
296 }
297
298 FUNC(hw_kbd_repeat_delay)
299 {
300 struct tctrl_req req;
301
302 req.cmdbuf[1] = 0xff;
303 req.cmdbuf[2] = 0x00;
304 READ_REQ(0x28, 3, 2);
305 table[num].value = req.rspbuf[0];
306 if (read)
307 return(1);
308 if (new == 0)
309 req.cmdbuf[2] = 0x00;
310 else if (new > 255)
311 req.cmdbuf[2] = 0xff;
312 else
313 req.cmdbuf[2] = new;
314 req.cmdbuf[1] = 0x00;
315 WRITE_REQ(0x28, 3, 2);
316 req.cmdbuf[1] = 0xff;
317 req.cmdbuf[2] = 0x00;
318 READ_REQ(0x28, 3, 2);
319 table[num].value = req.rspbuf[0];
320 return(1);
321 }
322
323 FUNC(hw_kbd_repeat_speed)
324 {
325 struct tctrl_req req;
326
327 req.cmdbuf[1] = 0xff;
328 req.cmdbuf[2] = 0x00;
329 READ_REQ(0x29, 3, 2);
330 table[num].value = req.rspbuf[0];
331 if (read)
332 return(1);
333 if (new == 0)
334 req.cmdbuf[2] = 0x00;
335 else if (new > 255)
336 req.cmdbuf[2] = 0xff;
337 else
338 req.cmdbuf[2] = new;
339 req.cmdbuf[1] = 0x00;
340 WRITE_REQ(0x29, 3, 2);
341 req.cmdbuf[1] = 0xff;
342 req.cmdbuf[2] = 0x00;
343 READ_REQ(0x29, 3, 2);
344 table[num].value = req.rspbuf[0];
345 return(1);
346 }
347
348 FUNC(hw_speaker_freq)
349 {
350 struct tctrl_req req;
351
352 table[num].value = 0;
353 if (read)
354 return(1);
355 req.cmdbuf[1] = new * 256;
356 req.cmdbuf[2] = new % 256;
357 WRITE_REQ(0x37, 3, 1);
358 return(1);
359 }
360
361 FUNC(hw_speaker_volume)
362 {
363 struct tctrl_req req;
364
365 req.cmdbuf[1] = 0xff;
366 req.cmdbuf[2] = 0x00;
367 READ_REQ(0x23, 3, 2);
368 table[num].value = req.rspbuf[0];
369 if (read)
370 return(1);
371 if (new == 0)
372 req.cmdbuf[2] = 0x00;
373 else if (new > 255)
374 req.cmdbuf[2] = 0xff;
375 else
376 req.cmdbuf[2] = new;
377 req.cmdbuf[1] = 0x00;
378 WRITE_REQ(0x23, 3, 2);
379 req.cmdbuf[1] = 0xff;
380 req.cmdbuf[2] = 0x00;
381 READ_REQ(0x23, 3, 2);
382 table[num].value = req.rspbuf[0];
383 return(1);
384 }
385
386 FUNC(hw_video_tft_brightness)
387 {
388 struct tctrl_req req;
389
390 req.cmdbuf[1] = 0xff;
391 req.cmdbuf[2] = 0x00;
392 READ_REQ(0x24, 3, 2);
393 table[num].value = req.rspbuf[0];
394 if (read)
395 return(1);
396 if (new == 0)
397 req.cmdbuf[2] = 0x00;
398 else if (new > 255)
399 req.cmdbuf[2] = 0xff;
400 else
401 req.cmdbuf[2] = new;
402 req.cmdbuf[1] = 0x00;
403 WRITE_REQ(0x24, 3, 2);
404 req.cmdbuf[1] = 0xff;
405 req.cmdbuf[2] = 0x00;
406 READ_REQ(0x24, 3, 2);
407 table[num].value = req.rspbuf[0];
408 return(1);
409 }
410
411 FUNC(hw_video_syncinva)
412 {
413 struct tctrl_req req;
414
415 req.cmdbuf[1] = 0xff;
416 req.cmdbuf[2] = 0x00;
417 READ_REQ(0x21, 3, 2);
418 table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
419 if (read)
420 return(1);
421 if (new == 0)
422 req.cmdbuf[2] = 0x00;
423 else
424 req.cmdbuf[2] = 0x02;
425 req.cmdbuf[1] = ~0x02;
426 WRITE_REQ(0x21, 3, 2);
427 req.cmdbuf[1] = 0xff;
428 req.cmdbuf[2] = 0x00;
429 READ_REQ(0x21, 3, 2);
430 table[num].value = req.rspbuf[0]&0x02 ? 1 : 0;
431 return(1);
432 }
433
434 FUNC(hw_video_syncinvb)
435 {
436 struct tctrl_req req;
437
438 req.cmdbuf[1] = 0xff;
439 req.cmdbuf[2] = 0x00;
440 READ_REQ(0x21, 3, 2);
441 table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
442 if (read)
443 return(1);
444 if (new == 0)
445 req.cmdbuf[2] = 0x00;
446 else
447 req.cmdbuf[2] = 0x04;
448 req.cmdbuf[1] = ~0x04;
449 WRITE_REQ(0x21, 3, 2);
450 req.cmdbuf[1] = 0xff;
451 req.cmdbuf[2] = 0x00;
452 READ_REQ(0x21, 3, 2);
453 table[num].value = req.rspbuf[0]&0x04 ? 1 : 0;
454 return(1);
455 }
456
457 FUNC(hw_video_compsync)
458 {
459 struct tctrl_req req;
460
461 req.cmdbuf[1] = 0xff;
462 req.cmdbuf[2] = 0x00;
463 READ_REQ(0x21, 3, 2);
464 table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
465 if (read)
466 return(1);
467 if (new == 0)
468 req.cmdbuf[2] = 0x00;
469 else
470 req.cmdbuf[2] = 0x10;
471 req.cmdbuf[1] = ~0x10;
472 WRITE_REQ(0x21, 3, 2);
473 req.cmdbuf[1] = 0xff;
474 req.cmdbuf[2] = 0x00;
475 READ_REQ(0x21, 3, 2);
476 table[num].value = req.rspbuf[0]&0x10 ? 1 : 0;
477 return(1);
478 }
479
480 /* ARGSUSED */
481 FUNC(hw_video_lid)
482 {
483 struct tctrl_req req;
484 short i;
485
486 READ_ONLY;
487 READ_REQ(0x11, 1, 3);
488 i = (req.rspbuf[0]<<8) + req.rspbuf[1];
489 table[num].value = i&0x0040 ? 0 : 1;
490 return(1);
491 }
492
493 /* ARGSUSED */
494 FUNC(hw_video_external)
495 {
496 struct tctrl_req req;
497 short i;
498
499 READ_ONLY;
500 READ_REQ(0x11, 1, 3);
501 i = (req.rspbuf[0]<<8) + req.rspbuf[1];
502 table[num].value = i&0x0008 ? 1 : 0;
503 return(1);
504 }
505
506 /* ARGSUSED */
507 FUNC(hw_power_battery_int_chargelevel)
508 {
509 struct tctrl_req req;
510
511 READ_ONLY;
512 READ_REQ(0x7a, 1, 3);
513 table[num].value = req.rspbuf[0] == 0xfb ? 0 : req.rspbuf[0];
514 return(1);
515
516 }
517
518 /* ARGSUSED */
519 FUNC(hw_power_battery_ext_chargelevel)
520 {
521 struct tctrl_req req;
522
523 READ_ONLY;
524 READ_REQ(0x7b, 1, 3);
525 table[num].value = req.rspbuf[0] == 0xfb ? 0 : req.rspbuf[0];
526 return(1);
527 }
528
529 FUNC(hw_power_battery_int_chargerate)
530 {
531 struct tctrl_req req;
532
533 READ_REQ(0x18, 1, 2);
534 table[num].value = req.rspbuf[0];
535 if (read)
536 return(1);
537 req.cmdbuf[1] = new < 255 ? new : 255;
538 WRITE_REQ(0x39, 2, 1);
539 READ_REQ(0x18, 1, 2);
540 table[num].value = req.rspbuf[0];
541 return(1);
542 }
543
544 FUNC(hw_power_battery_ext_chargerate)
545 {
546 struct tctrl_req req;
547
548 READ_REQ(0x18, 1, 2);
549 table[num].value = req.rspbuf[0];
550 if (read)
551 return(1);
552 req.cmdbuf[1] = new < 255 ? new : 255;
553 WRITE_REQ(0x39, 2, 1);
554 READ_REQ(0x18, 1, 2);
555 table[num].value = req.rspbuf[0];
556 return(1);
557 }
558
559 /* ARGSUSED */
560 FUNC(hw_power_battery_ext)
561 {
562 int i;
563 struct tctrl_req req;
564
565 READ_ONLY;
566 READ_REQ(0x11, 1, 3);
567 i = (req.rspbuf[0]<<8) + req.rspbuf[1];
568 table[num].value = i&0x0004 ? 1 : 0;
569 return(1);
570 }
571
572 /* ARGSUSED */
573 FUNC(hw_power_battery_int)
574 {
575 int i;
576 struct tctrl_req req;
577
578 READ_ONLY;
579 READ_REQ(0x11, 1, 3);
580 i = (req.rspbuf[0]<<8) + req.rspbuf[1];
581 table[num].value = i&0x0002 ? 1 : 0;
582 return(1);
583 }
584
585 /* ARGSUSED */
586 FUNC(hw_power_mains)
587 {
588 int i;
589 struct tctrl_req req;
590
591 READ_ONLY;
592 READ_REQ(0x11, 1, 3);
593 i = (req.rspbuf[0]<<8) + req.rspbuf[1];
594 table[num].value = i&0x0001 ? 1 : 0;
595 return(1);
596 }
597
598 /* ARGSUSED */
599 FUNC(hw_poweroncycles)
600 {
601 struct tctrl_req req;
602
603 READ_ONLY;
604 READ_REQ(0x09, 1, 5);
605 table[num].value = (req.rspbuf[0]<<24)+(req.rspbuf[1]<<16)+
606 (req.rspbuf[2]<<8)+req.rspbuf[3];
607 return(1);
608 }
609
610 /* ARGSUSED */
611 FUNC(hw_poweronseconds)
612 {
613 struct tctrl_req req;
614
615 READ_ONLY;
616 READ_REQ(0x0a, 1, 5);
617 table[num].value = (req.rspbuf[0]<<24)+(req.rspbuf[1]<<16)+
618 (req.rspbuf[2]<<8)+req.rspbuf[3];
619 return(1);
620 }
621
622 /* ARGSUSED */
623 FUNC(hw_microcontroller_version)
624 {
625 char *bufp, buf[BUFSIZ];
626 struct tctrl_req req;
627
628 READ_ONLY;
629 READ_REQ(0x04, 1, 3);
630 bufp = buf;
631 sprintf(bufp, "%d%d", req.rspbuf[0]*1000, req.rspbuf[1]*10);
632 table[num].value = atoi(strdup(bufp));
633 return(1);
634 }
635
636
637 /* ARGSUSED */
638 FUNC(hw_version)
639 {
640 char *bufp, buf[BUFSIZ];
641 struct tctrl_req req;
642
643 READ_ONLY;
644 READ_REQ(0x03, 1, 3);
645 bufp = buf;
646 sprintf(bufp, "%d%d", req.rspbuf[0]*1000, req.rspbuf[1]*10);
647 table[num].value = atoi(strdup(bufp));
648 return(1);
649 }
650
651 void
652 usage()
653 {
654 (void)fprintf(stderr,
655 "usage: tadpolectl [-n] name ...\n"
656 " tadpolectl [-n] -w name=value\n"
657 " tadpolectl [-n] -a\n");
658 exit(1);
659 }
660
661 static void
662 parse(string)
663 char *string;
664 {
665 char *cp, buf[BUFSIZ];
666 int newval = 0;
667 int i, j, ret;
668
669 string = dashdot(string);
670 snprintf(buf, (size_t)BUFSIZ, "%s", string);
671 if ((cp = strchr(string, '=')) != NULL) {
672 if (!wflag)
673 errx(2, "Must specify -w to set variables");
674 *strchr(buf, '=') = '\0';
675 *cp++ = '\0';
676 while (isspace((unsigned char) *cp))
677 cp++;
678 newval = atoi(cp);
679 }
680 for (j=0,i=-1; j < NUM_MIBS; j++) {
681 if (strcmp(string, table[j].mib) == 0) {
682 i = j;
683 break;
684 }
685 }
686 if (i == -1)
687 errx(2, "Named value does not exist");
688
689 if (wflag) {
690 ret = (*table[i].funcptr)(0, newval, i);
691 if (!ret)
692 errx(2, "Cannot modify this value");
693 } else
694 ret = (*table[i].funcptr)(1, 0, i);
695 if (nflag)
696 printf("%d\n", table[i].value);
697 else
698 printf("%s = %d\n", dashdot(table[i].mib), table[i].value);
699 }
700
701 char *
702 dashdot(string)
703 char *string;
704 {
705 char *p;
706 char *save;
707
708 p = strdup(string);
709 save = p;
710
711 for (; (*p = *string) != '\0'; ++p, ++string) {
712 if (*p == '.')
713 *p = '_';
714 else if (*p == '_')
715 *p = '.';
716 }
717 return(save);
718 }
719
720 int
721 main(argc, argv)
722 int argc;
723 char *argv[];
724 {
725 extern int optind;
726 int ch, j;
727
728 while ((ch = getopt(argc, argv, "anw")) != -1) {
729 switch (ch) {
730
731 case 'a':
732 aflag = 1;
733 break;
734 case 'n':
735 nflag = 1;
736 break;
737 case 'w':
738 wflag = 1;
739 break;
740 default:
741 usage();
742 }
743 }
744 argc -= optind;
745 argv += optind;
746
747 dev = open("/dev/tctrl0", O_RDONLY, NULL);
748
749 if (aflag) {
750 for (j=0; j < NUM_MIBS; j++) {
751 (void)(*table[j].funcptr)(1, 0, j);
752 if (nflag)
753 printf("%d\n", table[j].value);
754 else
755 printf("%s = %d\n", dashdot(table[j].mib),
756 table[j].value);
757 }
758 return(0);
759 }
760 if (argc == 0)
761 usage();
762 while (argc-- > 0)
763 parse(*argv++);
764 return(0);
765 }
766