diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-06-30 02:12:58 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-06-30 02:12:58 +0000 |
commit | 44b0c22175e11d9ff38b0894365e03c886c4666a (patch) | |
tree | 619bfb6126b3d21e63d035072fba2c1511fedd71 /sbin | |
parent | 6bb0905cce6d7e15db395fa110acd0589c12d78f (diff) |
make it more sysctl-like, ommit -kmd switches.
no backwards compatibility keeped.
add ability to change screens from cmd line.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/wsconsctl/display.c | 78 | ||||
-rw-r--r-- | sbin/wsconsctl/keyboard.c | 92 | ||||
-rw-r--r-- | sbin/wsconsctl/mouse.c | 22 | ||||
-rw-r--r-- | sbin/wsconsctl/util.c | 46 | ||||
-rw-r--r-- | sbin/wsconsctl/wsconsctl.8 | 28 | ||||
-rw-r--r-- | sbin/wsconsctl/wsconsctl.c | 205 | ||||
-rw-r--r-- | sbin/wsconsctl/wsconsctl.h | 21 |
7 files changed, 244 insertions, 248 deletions
diff --git a/sbin/wsconsctl/display.c b/sbin/wsconsctl/display.c index 656ec69300a..656c814326a 100644 --- a/sbin/wsconsctl/display.c +++ b/sbin/wsconsctl/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.2 2001/05/08 22:31:09 mickey Exp $ */ +/* $OpenBSD: display.c,v 1.3 2001/06/30 02:12:57 mickey Exp $ */ /* $NetBSD: display.c,v 1.1 1998/12/28 14:01:16 hannken Exp $ */ /*- @@ -44,104 +44,120 @@ #include "wsconsctl.h" int dpytype; +int focus; int burnon, burnoff, vblank, kbdact, msact, outact; struct field display_field_tab[] = { { "type", &dpytype, FMT_DPYTYPE, FLG_RDONLY }, + { "focus", &focus, FMT_UINT, FLG_MODIFY }, { "screen_on", &burnon, FMT_UINT, FLG_MODIFY }, { "screen_off", &burnoff, FMT_UINT, FLG_MODIFY }, { "vblank", &vblank, FMT_BOOL, FLG_MODIFY }, { "kbdact", &kbdact, FMT_BOOL, FLG_MODIFY }, { "msact", &msact, FMT_BOOL, FLG_MODIFY }, { "outact", &outact, FMT_BOOL, FLG_MODIFY }, + { NULL } }; -int display_field_tab_len = sizeof(display_field_tab)/ - sizeof(display_field_tab[0]); - void -display_get_values(fd) +display_get_values(pre, fd) + const char *pre; int fd; { - if (field_by_value(&dpytype)->flags & FLG_GET) + struct wsdisplay_addscreendata gscr; + + if (field_by_value(display_field_tab, &dpytype)->flags & FLG_GET) if (ioctl(fd, WSDISPLAYIO_GTYPE, &dpytype) < 0) err(1, "WSDISPLAYIO_GTYPE"); - if (field_by_value(&burnon)->flags & FLG_GET || - field_by_value(&burnoff)->flags & FLG_GET || - field_by_value(&vblank)->flags & FLG_GET || - field_by_value(&kbdact)->flags & FLG_GET || - field_by_value(&msact )->flags & FLG_GET || - field_by_value(&outact)->flags & FLG_GET) { + + gscr.idx = -1; + if (field_by_value(display_field_tab, &focus)->flags & FLG_GET) + if (ioctl(fd, WSDISPLAYIO_GETSCREEN, &gscr) < 0) + err(1, "WSDISPLAYIO_GETSCREEN"); + else + focus = gscr.idx; + + if (field_by_value(display_field_tab, &burnon)->flags & FLG_GET || + field_by_value(display_field_tab, &burnoff)->flags & FLG_GET || + field_by_value(display_field_tab, &vblank)->flags & FLG_GET || + field_by_value(display_field_tab, &kbdact)->flags & FLG_GET || + field_by_value(display_field_tab, &msact )->flags & FLG_GET || + field_by_value(display_field_tab, &outact)->flags & FLG_GET) { struct wsdisplay_burner burners; if (ioctl(fd, WSDISPLAYIO_GBURNER, &burners) < 0) err(1, "WSDISPLAYIO_GBURNER"); - if (field_by_value(&burnon)->flags & FLG_GET) + if (field_by_value(display_field_tab, &burnon)->flags & FLG_GET) burnon = burners.on; - if (field_by_value(&burnoff)->flags & FLG_GET) + if (field_by_value(display_field_tab, &burnoff)->flags & FLG_GET) burnoff = burners.off; - if (field_by_value(&vblank)->flags & FLG_GET) + if (field_by_value(display_field_tab, &vblank)->flags & FLG_GET) vblank = burners.flags & WSDISPLAY_BURN_VBLANK; - if (field_by_value(&kbdact)->flags & FLG_GET) + if (field_by_value(display_field_tab, &kbdact)->flags & FLG_GET) kbdact = burners.flags & WSDISPLAY_BURN_KBD; - if (field_by_value(&msact )->flags & FLG_GET) + if (field_by_value(display_field_tab, &msact )->flags & FLG_GET) msact = burners.flags & WSDISPLAY_BURN_MOUSE; - if (field_by_value(&outact)->flags & FLG_GET) + if (field_by_value(display_field_tab, &outact)->flags & FLG_GET) outact = burners.flags & WSDISPLAY_BURN_OUTPUT; } } void -display_put_values(fd) +display_put_values(pre, fd) + const char *pre; int fd; { - if (field_by_value(&burnon)->flags & FLG_SET || - field_by_value(&burnoff)->flags & FLG_SET || - field_by_value(&vblank)->flags & FLG_SET || - field_by_value(&kbdact)->flags & FLG_SET || - field_by_value(&msact )->flags & FLG_SET || - field_by_value(&outact)->flags & FLG_SET) { + if (field_by_value(display_field_tab, &focus)->flags & FLG_SET) + if (ioctl(fd, WSDISPLAYIO_SETSCREEN, &focus) < 0) + err(1, "WSDISPLAYIO_SETSCREEN"); + + if (field_by_value(display_field_tab, &burnon)->flags & FLG_SET || + field_by_value(display_field_tab, &burnoff)->flags & FLG_SET || + field_by_value(display_field_tab, &vblank)->flags & FLG_SET || + field_by_value(display_field_tab, &kbdact)->flags & FLG_SET || + field_by_value(display_field_tab, &msact )->flags & FLG_SET || + field_by_value(display_field_tab, &outact)->flags & FLG_SET) { struct wsdisplay_burner burners; if (ioctl(fd, WSDISPLAYIO_GBURNER, &burners) < 0) err(1, "WSDISPLAYIO_GBURNER"); - if (field_by_value(&burnon)->flags & FLG_SET) + if (field_by_value(display_field_tab, &burnon)->flags & FLG_SET) burners.on = burnon; - if (field_by_value(&burnoff)->flags & FLG_SET) + if (field_by_value(display_field_tab, &burnoff)->flags & FLG_SET) burners.off = burnoff; - if (field_by_value(&vblank)->flags & FLG_SET) { + if (field_by_value(display_field_tab, &vblank)->flags & FLG_SET) { if (vblank) burners.flags |= WSDISPLAY_BURN_VBLANK; else burners.flags &= ~WSDISPLAY_BURN_VBLANK; } - if (field_by_value(&kbdact)->flags & FLG_SET) { + if (field_by_value(display_field_tab, &kbdact)->flags & FLG_SET) { if (kbdact) burners.flags |= WSDISPLAY_BURN_KBD; else burners.flags &= ~WSDISPLAY_BURN_KBD; } - if (field_by_value(&msact )->flags & FLG_SET) { + if (field_by_value(display_field_tab, &msact )->flags & FLG_SET) { if (msact) burners.flags |= WSDISPLAY_BURN_MOUSE; else burners.flags &= ~WSDISPLAY_BURN_MOUSE; } - if (field_by_value(&outact)->flags & FLG_SET) { + if (field_by_value(display_field_tab, &outact)->flags & FLG_SET) { if (outact) burners.flags |= WSDISPLAY_BURN_OUTPUT; else diff --git a/sbin/wsconsctl/keyboard.c b/sbin/wsconsctl/keyboard.c index d2d9e188890..a1b5f2d0762 100644 --- a/sbin/wsconsctl/keyboard.c +++ b/sbin/wsconsctl/keyboard.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyboard.c,v 1.1 2000/07/01 23:52:45 mickey Exp $ */ +/* $OpenBSD: keyboard.c,v 1.2 2001/06/30 02:12:57 mickey Exp $ */ /* $NetBSD: keyboard.c 1.1 1998/12/28 14:01:17 hannken Exp $ */ /*- @@ -70,151 +70,151 @@ struct field keyboard_field_tab[] = { { "repeat.deln.default", &dfrepeat.delN, FMT_UINT, FLG_MODIFY }, { "ledstate", &ledstate, FMT_UINT, 0 }, { "encoding", &kbdencoding, FMT_KBDENC, FLG_MODIFY }, + { NULL } }; -int keyboard_field_tab_len = sizeof(keyboard_field_tab)/ - sizeof(keyboard_field_tab[0]); - void -keyboard_get_values(fd) +keyboard_get_values(pre, fd) + const char *pre; int fd; { - if (field_by_value(&kbtype)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &kbtype)->flags & FLG_GET) if (ioctl(fd, WSKBDIO_GTYPE, &kbtype) < 0) err(1, "WSKBDIO_GTYPE"); bell.which = 0; - if (field_by_value(&bell.pitch)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &bell.pitch)->flags & FLG_GET) bell.which |= WSKBD_BELL_DOPITCH; - if (field_by_value(&bell.period)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &bell.period)->flags & FLG_GET) bell.which |= WSKBD_BELL_DOPERIOD; - if (field_by_value(&bell.volume)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &bell.volume)->flags & FLG_GET) bell.which |= WSKBD_BELL_DOVOLUME; if (bell.which != 0 && ioctl(fd, WSKBDIO_GETBELL, &bell) < 0) err(1, "WSKBDIO_GETBELL"); dfbell.which = 0; - if (field_by_value(&dfbell.pitch)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &dfbell.pitch)->flags & FLG_GET) dfbell.which |= WSKBD_BELL_DOPITCH; - if (field_by_value(&dfbell.period)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &dfbell.period)->flags & FLG_GET) dfbell.which |= WSKBD_BELL_DOPERIOD; - if (field_by_value(&dfbell.volume)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &dfbell.volume)->flags & FLG_GET) dfbell.which |= WSKBD_BELL_DOVOLUME; if (dfbell.which != 0 && ioctl(fd, WSKBDIO_GETDEFAULTBELL, &dfbell) < 0) err(1, "WSKBDIO_GETDEFAULTBELL"); - if (field_by_value(&kbmap)->flags & FLG_GET) { + if (field_by_value(keyboard_field_tab, &kbmap)->flags & FLG_GET) { kbmap.maplen = KS_NUMKEYCODES; if (ioctl(fd, WSKBDIO_GETMAP, &kbmap) < 0) err(1, "WSKBDIO_GETMAP"); } repeat.which = 0; - if (field_by_value(&repeat.del1)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &repeat.del1)->flags & FLG_GET) repeat.which |= WSKBD_KEYREPEAT_DODEL1; - if (field_by_value(&repeat.delN)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &repeat.delN)->flags & FLG_GET) repeat.which |= WSKBD_KEYREPEAT_DODELN; if (repeat.which != 0 && ioctl(fd, WSKBDIO_GETKEYREPEAT, &repeat) < 0) err(1, "WSKBDIO_GETKEYREPEAT"); dfrepeat.which = 0; - if (field_by_value(&dfrepeat.del1)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &dfrepeat.del1)->flags & FLG_GET) dfrepeat.which |= WSKBD_KEYREPEAT_DODEL1; - if (field_by_value(&dfrepeat.delN)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &dfrepeat.delN)->flags & FLG_GET) dfrepeat.which |= WSKBD_KEYREPEAT_DODELN; if (dfrepeat.which != 0 && ioctl(fd, WSKBDIO_GETKEYREPEAT, &dfrepeat) < 0) err(1, "WSKBDIO_GETKEYREPEAT"); - if (field_by_value(&ledstate)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &ledstate)->flags & FLG_GET) if (ioctl(fd, WSKBDIO_GETLEDS, &ledstate) < 0) err(1, "WSKBDIO_GETLEDS"); - if (field_by_value(&kbdencoding)->flags & FLG_GET) + if (field_by_value(keyboard_field_tab, &kbdencoding)->flags & FLG_GET) if (ioctl(fd, WSKBDIO_GETENCODING, &kbdencoding) < 0) err(1, "WSKBDIO_GETENCODING"); } void -keyboard_put_values(fd) +keyboard_put_values(pre, fd) + const char *pre; int fd; { bell.which = 0; - if (field_by_value(&bell.pitch)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &bell.pitch)->flags & FLG_SET) bell.which |= WSKBD_BELL_DOPITCH; - if (field_by_value(&bell.period)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &bell.period)->flags & FLG_SET) bell.which |= WSKBD_BELL_DOPERIOD; - if (field_by_value(&bell.volume)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &bell.volume)->flags & FLG_SET) bell.which |= WSKBD_BELL_DOVOLUME; if (bell.which != 0 && ioctl(fd, WSKBDIO_SETBELL, &bell) < 0) err(1, "WSKBDIO_SETBELL"); if (bell.which & WSKBD_BELL_DOPITCH) - pr_field(field_by_value(&bell.pitch), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &bell.pitch), " -> "); if (bell.which & WSKBD_BELL_DOPERIOD) - pr_field(field_by_value(&bell.period), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &bell.period), " -> "); if (bell.which & WSKBD_BELL_DOVOLUME) - pr_field(field_by_value(&bell.volume), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &bell.volume), " -> "); dfbell.which = 0; - if (field_by_value(&dfbell.pitch)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &dfbell.pitch)->flags & FLG_SET) dfbell.which |= WSKBD_BELL_DOPITCH; - if (field_by_value(&dfbell.period)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &dfbell.period)->flags & FLG_SET) dfbell.which |= WSKBD_BELL_DOPERIOD; - if (field_by_value(&dfbell.volume)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &dfbell.volume)->flags & FLG_SET) dfbell.which |= WSKBD_BELL_DOVOLUME; if (dfbell.which != 0 && ioctl(fd, WSKBDIO_SETDEFAULTBELL, &dfbell) < 0) err(1, "WSKBDIO_SETDEFAULTBELL"); if (dfbell.which & WSKBD_BELL_DOPITCH) - pr_field(field_by_value(&dfbell.pitch), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &dfbell.pitch), " -> "); if (dfbell.which & WSKBD_BELL_DOPERIOD) - pr_field(field_by_value(&dfbell.period), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &dfbell.period), " -> "); if (dfbell.which & WSKBD_BELL_DOVOLUME) - pr_field(field_by_value(&dfbell.volume), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &dfbell.volume), " -> "); - if (field_by_value(&kbmap)->flags & FLG_SET) { + if (field_by_value(keyboard_field_tab, &kbmap)->flags & FLG_SET) { if (ioctl(fd, WSKBDIO_SETMAP, &kbmap) < 0) err(1, "WSKBDIO_SETMAP"); - pr_field(field_by_value(&kbmap), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &kbmap), " -> "); } repeat.which = 0; - if (field_by_value(&repeat.del1)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &repeat.del1)->flags & FLG_SET) repeat.which |= WSKBD_KEYREPEAT_DODEL1; - if (field_by_value(&repeat.delN)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &repeat.delN)->flags & FLG_SET) repeat.which |= WSKBD_KEYREPEAT_DODELN; if (repeat.which != 0 && ioctl(fd, WSKBDIO_SETKEYREPEAT, &repeat) < 0) err(1, "WSKBDIO_SETKEYREPEAT"); if (repeat.which & WSKBD_KEYREPEAT_DODEL1) - pr_field(field_by_value(&repeat.del1), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &repeat.del1), " -> "); if (repeat.which & WSKBD_KEYREPEAT_DODELN) - pr_field(field_by_value(&repeat.delN), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &repeat.delN), " -> "); dfrepeat.which = 0; - if (field_by_value(&dfrepeat.del1)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &dfrepeat.del1)->flags & FLG_SET) dfrepeat.which |= WSKBD_KEYREPEAT_DODEL1; - if (field_by_value(&dfrepeat.delN)->flags & FLG_SET) + if (field_by_value(keyboard_field_tab, &dfrepeat.delN)->flags & FLG_SET) dfrepeat.which |= WSKBD_KEYREPEAT_DODELN; if (dfrepeat.which != 0 && ioctl(fd, WSKBDIO_SETDEFAULTKEYREPEAT, &dfrepeat) < 0) err(1, "WSKBDIO_SETDEFAULTKEYREPEAT"); if (dfrepeat.which &WSKBD_KEYREPEAT_DODEL1) - pr_field(field_by_value(&dfrepeat.del1), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &dfrepeat.del1), " -> "); if (dfrepeat.which & WSKBD_KEYREPEAT_DODELN) - pr_field(field_by_value(&dfrepeat.delN), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &dfrepeat.delN), " -> "); - if (field_by_value(&ledstate)->flags & FLG_SET) { + if (field_by_value(keyboard_field_tab, &ledstate)->flags & FLG_SET) { if (ioctl(fd, WSKBDIO_SETLEDS, &ledstate) < 0) err(1, "WSKBDIO_SETLEDS"); - pr_field(field_by_value(&ledstate), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &ledstate), " -> "); } - if (field_by_value(&kbdencoding)->flags & FLG_SET) { + if (field_by_value(keyboard_field_tab, &kbdencoding)->flags & FLG_SET) { if (ioctl(fd, WSKBDIO_SETENCODING, &kbdencoding) < 0) err(1, "WSKBDIO_SETENCODING"); - pr_field(field_by_value(&kbdencoding), " -> "); + pr_field(pre, field_by_value(keyboard_field_tab, &kbdencoding), " -> "); } } diff --git a/sbin/wsconsctl/mouse.c b/sbin/wsconsctl/mouse.c index aa51cf2af10..5c82044f781 100644 --- a/sbin/wsconsctl/mouse.c +++ b/sbin/wsconsctl/mouse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mouse.c,v 1.1 2000/07/01 23:52:45 mickey Exp $ */ +/* $OpenBSD: mouse.c,v 1.2 2001/06/30 02:12:57 mickey Exp $ */ /* $NetBSD: mouse.c,v 1.3 1999/11/15 13:47:30 ad Exp $ */ /*- @@ -51,36 +51,36 @@ struct field mouse_field_tab[] = { { "resolution", &resolution, FMT_UINT, FLG_WRONLY }, { "samplerate", &samplerate, FMT_UINT, FLG_WRONLY }, { "type", &mstype, FMT_MSTYPE, FLG_RDONLY }, + { NULL } }; -int mouse_field_tab_len = sizeof(mouse_field_tab)/ - sizeof(mouse_field_tab[0]); - void -mouse_get_values(fd) +mouse_get_values(pre, fd) + const char *pre; int fd; { - if (field_by_value(&mstype)->flags & FLG_GET) + if (field_by_value(mouse_field_tab, &mstype)->flags & FLG_GET) if (ioctl(fd, WSMOUSEIO_GTYPE, &mstype) < 0) err(1, "WSMOUSEIO_GTYPE"); } void -mouse_put_values(fd) +mouse_put_values(pre, fd) + const char *pre; int fd; { int tmp; - if (field_by_value(&resolution)->flags & FLG_SET) { + if (field_by_value(mouse_field_tab, &resolution)->flags & FLG_SET) { tmp = resolution; if (ioctl(fd, WSMOUSEIO_SRES, &tmp) < 0) err(1, "WSMOUSEIO_SRES"); - pr_field(field_by_value(&resolution), " -> "); + pr_field(pre, field_by_value(mouse_field_tab, &resolution), " -> "); } - if (field_by_value(&samplerate)->flags & FLG_SET) { + if (field_by_value(mouse_field_tab, &samplerate)->flags & FLG_SET) { tmp = samplerate; if (ioctl(fd, WSMOUSEIO_SRATE, &tmp) < 0) err(1, "WSMOUSEIO_SRES"); - pr_field(field_by_value(&tmp), " -> "); + pr_field(pre, field_by_value(mouse_field_tab, &tmp), " -> "); } } diff --git a/sbin/wsconsctl/util.c b/sbin/wsconsctl/util.c index ea0435efae2..2cf0e2830e2 100644 --- a/sbin/wsconsctl/util.c +++ b/sbin/wsconsctl/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.4 2001/05/08 22:31:09 mickey Exp $ */ +/* $OpenBSD: util.c,v 1.5 2001/06/30 02:12:57 mickey Exp $ */ /* $NetBSD: util.c,v 1.8 2000/03/14 08:11:53 sato Exp $ */ /*- @@ -102,44 +102,35 @@ static struct nameint kbdvar_tab[] = { KB_VARTAB }; -static struct field *field_tab; -static int field_tab_len; - static char *int2name __P((int, int, struct nameint *, int)); static int name2int __P((char *, struct nameint *, int)); static void print_kmap __P((struct wskbd_map_data *)); -void -field_setup(ftab, len) - struct field *ftab; - int len; -{ - field_tab = ftab; - field_tab_len = len; -} - struct field * -field_by_name(name) +field_by_name(field_tab, name) + struct field *field_tab; char *name; { - int i; + const char *p = strchr(name, '.'); + + if (!p++) + errx(1, "%s: illigale variable name", name); - for (i = 0; i < field_tab_len; i++) - if (strcmp(field_tab[i].name, name) == 0) - return(field_tab + i); + for (; field_tab->name; field_tab++) + if (strcmp(field_tab->name, p) == 0) + return (field_tab); errx(1, "%s: not found", name); } struct field * -field_by_value(addr) +field_by_value(field_tab, addr) + struct field *field_tab; void *addr; { - int i; - - for (i = 0; i < field_tab_len; i++) - if (field_tab[i].valp == addr) - return(field_tab + i); + for (; field_tab->name; field_tab++) + if (field_tab->valp == addr) + return (field_tab); errx(1, "internal error: field_by_value: not found"); } @@ -180,16 +171,17 @@ name2int(val, tab, len) } void -pr_field(f, sep) +pr_field(pre, f, sep) + const char *pre; struct field *f; - char *sep; + const char *sep; { char *p; u_int flags; int i; if (sep) - printf("%s%s", f->name, sep); + printf("%s.%s%s", pre, f->name, sep); switch (f->format) { case FMT_UINT: diff --git a/sbin/wsconsctl/wsconsctl.8 b/sbin/wsconsctl/wsconsctl.8 index 00ca08fcb3e..7a559ed6005 100644 --- a/sbin/wsconsctl/wsconsctl.8 +++ b/sbin/wsconsctl/wsconsctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: wsconsctl.8,v 1.5 2001/03/09 16:07:20 aaron Exp $ +.\" $OpenBSD: wsconsctl.8,v 1.6 2001/06/30 02:12:57 mickey Exp $ .\" $NetBSD: wsconsctl.8,v 1.5 1999/09/12 18:47:11 kleink Exp $ .\" .\" Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -43,24 +43,16 @@ .Nd get or set wscons state .Sh SYNOPSIS .Nm wsconsctl -.Op Fl kdm -.Op Fl f Ar file .Op Fl n .Fl a .Nm wsconsctl -.Op Fl kdm -.Op Fl f Ar file .Op Fl n .Ar name ... .Nm wsconsctl -.Op Fl kdm -.Op Fl f Ar file .Op Fl n .Fl w .Ar name=value ... .Nm wsconsctl -.Op Fl kdm -.Op Fl f Ar file .Op Fl n .Fl w .Ar name+=value ... @@ -90,16 +82,8 @@ symbol. See the .Sx EXAMPLES section for more details. -.It Fl f Ar file -Specify an alternative control device. .It Fl n Suppress printing of the variable name in the output. -.It Fl k -Selects the keyboard portion of the device (this is the default). -.It Fl d -Selects the display portion of the device. -.It Fl m -Selects the mouse portion of the device. .El .Pp The @@ -127,11 +111,11 @@ Use the utility to determine which keyboard encodings are available for your country. .Sh EXAMPLES -.Cm wsconsctl -w encoding=uk +.Cm wsconsctl -w keyboard.encoding=uk .Pp Sets a UK keyboard encoding. .Pp -.Cm wsconsctl -w map+="keysym Caps_Lock = Control_L" +.Cm wsconsctl -w keyboard.map+="keysym Caps_Lock = Control_L" .Pp Modifies the current keyboard encoding so that, when the .Ar Caps Lock @@ -143,7 +127,7 @@ to the .Ar /usr/include/dev/wscons/wsksymdef.h file. .Pp -.Cm wsconsctl -w encoding=us.swapctrlcaps +.Cm wsconsctl -w keyboard.encoding=us.swapctrlcaps .Pp Sets a US keyboard encoding, with the .Ar Caps Lock @@ -158,11 +142,11 @@ by the .Ar Caps Lock key is enough - see the previous example for details. .Pp -.Cm wsconsctl -w bell.pitch=1200 +.Cm wsconsctl -w keyboard.bell.pitch=1200 .Pp Sets the bell pitch to be 1200. .Pp -.Cm wsconsctl -w bell.pitch+=200 +.Cm wsconsctl -w keyboard.bell.pitch+=200 .Pp Adds 200 to the current pitch of the bell. .Sh FILES diff --git a/sbin/wsconsctl/wsconsctl.c b/sbin/wsconsctl/wsconsctl.c index 9f9f00df1eb..3bac2da488c 100644 --- a/sbin/wsconsctl/wsconsctl.c +++ b/sbin/wsconsctl/wsconsctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconsctl.c,v 1.4 2001/05/18 08:06:08 mickey Exp $ */ +/* $OpenBSD: wsconsctl.c,v 1.5 2001/06/30 02:12:57 mickey Exp $ */ /* $NetBSD: wsconsctl.c,v 1.2 1998/12/29 22:40:20 hannken Exp $ */ /*- @@ -53,25 +53,38 @@ extern const char *__progname; /* from crt0.o */ extern struct field keyboard_field_tab[]; extern struct field mouse_field_tab[]; extern struct field display_field_tab[]; -extern int keyboard_field_tab_len; -extern int mouse_field_tab_len; -extern int display_field_tab_len; -static void usage __P((char *)); -int main __P((int, char **)); - -static void +void usage __P((char *)); + +const struct vartypesw { + const char *name, *file; + struct field *field_tab; + void (*getval) __P((const char *pre, int)); + void (*putval) __P((const char *pre, int)); +} typesw[] = { + { "keyboard", PATH_KEYBOARD, keyboard_field_tab, + keyboard_get_values, keyboard_put_values }, + { "mouse", PATH_MOUSE, mouse_field_tab, + mouse_get_values, mouse_put_values }, + { "display", PATH_DISPLAY, display_field_tab, + display_get_values, display_put_values }, + { NULL } +}; + +const struct vartypesw *tab_by_name __P((const char *)); + +void usage(msg) char *msg; { if (msg != NULL) fprintf(stderr, "%s: %s\n\n", __progname, msg); - fprintf(stderr, "usage: %s [-kmd] [-f file] [-n] name ...\n", - __progname); - fprintf(stderr, " -or- %s [-kmd] [-f file] [-n] -w name=value ...\n", - __progname); - fprintf(stderr, " -or- %s [-kmd] [-f file] [-n] -a\n", __progname); + fprintf(stderr, + "usage: %s [-f file] [-n] name ...\n" + " %s [-f file] [-n] -w name=value ...\n" + " %s [-f file] [-n] -a\n", __progname, + __progname, __progname); exit(1); } @@ -81,39 +94,22 @@ main(argc, argv) int argc; char **argv; { - int i, ch, fd; - int aflag, dflag, kflag, mflag, wflag; - char *file, *sep, *p; - struct field *f, *field_tab; - int do_merge, field_tab_len; - void (*getval) __P((int)); - void (*putval) __P((int)); - - aflag = 0; - dflag = 0; - kflag = 0; - mflag = 0; - wflag = 0; - file = NULL; + int i, ch, fd, error; + int aflag, wflag; + char *sep, *p; + const struct vartypesw *sw; + struct field *f; + int do_merge; + + error = aflag = wflag = 0; + sw = NULL; sep = "="; - while ((ch = getopt(argc, argv, "adf:kmnw")) != -1) { + while ((ch = getopt(argc, argv, "anw")) != -1) { switch(ch) { case 'a': aflag = 1; break; - case 'd': - dflag = 1; - break; - case 'f': - file = optarg; - break; - case 'k': - kflag = 1; - break; - case 'm': - mflag = 1; - break; case 'n': sep = NULL; break; @@ -129,99 +125,108 @@ main(argc, argv) argc -= optind; argv += optind; - if (dflag + kflag + mflag == 0) - kflag = 1; - if (dflag + kflag + mflag > 1) - usage("only one of -k, -d or -m may be given"); if (argc > 0 && aflag != 0) usage("excess arguments after -a"); if (aflag != 0 && wflag != 0) usage("only one of -a or -w may be given"); - if (kflag) { - if (file == NULL) - file = PATH_KEYBOARD; - field_tab = keyboard_field_tab; - field_tab_len = keyboard_field_tab_len; - getval = keyboard_get_values; - putval = keyboard_put_values; - } else if (mflag) { - if (file == NULL) - file = PATH_MOUSE; - field_tab = mouse_field_tab; - field_tab_len = mouse_field_tab_len; - getval = mouse_get_values; - putval = mouse_put_values; - } else if (dflag) { - if (file == NULL) - file = PATH_DISPLAY; - field_tab = display_field_tab; - field_tab_len = display_field_tab_len; - getval = display_get_values; - putval = display_put_values; - } - - field_setup(field_tab, field_tab_len); - - fd = open(file, O_WRONLY); - if (fd < 0) - fd = open(file, O_RDONLY); - if (fd < 0) - err(1, "%s", file); - if (aflag != 0) { - for (i = 0; i < field_tab_len; i++) - if ((field_tab[i].flags & (FLG_NOAUTO|FLG_WRONLY)) == 0) - field_tab[i].flags |= FLG_GET; - (*getval)(fd); - for (i = 0; i < field_tab_len; i++) - if (field_tab[i].flags & FLG_NOAUTO) - warnx("Use explicit arg to view %s.", - field_tab[i].name); - else if (field_tab[i].flags & FLG_GET) - pr_field(field_tab + i, sep); + for (sw = typesw; sw->name; sw++) { + if ((fd = open(sw->file, O_WRONLY)) < 0 && + (fd = open(sw->file, O_RDONLY)) < 0) { + warn("%s", sw->file); + error = 1; + continue; + } + for (i = 0; sw->field_tab[i].name; i++) + if ((sw->field_tab[i].flags & + (FLG_NOAUTO|FLG_WRONLY)) == 0) + sw->field_tab[i].flags |= FLG_GET; + (*sw->getval)(sw->name, fd); + for (i = 0; sw->field_tab[i].name; i++) + if (sw->field_tab[i].flags & FLG_NOAUTO) + warnx("Use explicit arg to view %s.%s.", + sw->name, sw->field_tab[i].name); + else if (sw->field_tab[i].flags & FLG_GET) + pr_field(sw->name, sw->field_tab + i, sep); + close(fd); + } } else if (argc > 0) { if (wflag != 0) { for (i = 0; i < argc; i++) { p = strchr(argv[i], '='); - if (p == NULL) - errx(1, "'=' not found"); + if (p == NULL) { + warnx("'=' not found"); + continue; + } if (p > argv[i] && *(p - 1) == '+') { *(p - 1) = '\0'; do_merge = 1; } else do_merge = 0; *p++ = '\0'; - f = field_by_name(argv[i]); - if ((f->flags & FLG_RDONLY) != 0) - errx(1, "%s: read only", argv[i]); + sw = tab_by_name(argv[i]); + if (!sw) + continue; + f = field_by_name(sw->field_tab, argv[i]); + if ((f->flags & FLG_RDONLY) != 0) { + warnx("%s: read only", argv[i]); + continue; + } if (do_merge) { if ((f->flags & FLG_MODIFY) == 0) errx(1, "%s: can only be set", argv[i]); f->flags |= FLG_GET; - (*getval)(fd); + (*sw->getval)(sw->name, fd); f->flags &= ~FLG_GET; } rd_field(f, p, do_merge); f->flags |= FLG_SET; - (*putval)(fd); + (*sw->putval)(sw->name, fd); f->flags &= ~FLG_SET; } } else { for (i = 0; i < argc; i++) { - f = field_by_name(argv[i]); - if ((f->flags & FLG_WRONLY) != 0) - errx(1, "%s: write only", argv[i]); + sw = tab_by_name(argv[i]); + if (!sw) + continue; + f = field_by_name(sw->field_tab, argv[i]); + if ((f->flags & FLG_WRONLY) != 0) { + warnx("%s: write only", argv[i]); + continue; + } f->flags |= FLG_GET; + (*sw->getval)(sw->name, fd); + pr_field(sw->name, f, sep); } - (*getval)(fd); - for (i = 0; i < field_tab_len; i++) - if (field_tab[i].flags & FLG_GET) - pr_field(field_tab + i, sep); } } else usage(NULL); - return (0); + return (error); +} + +const struct vartypesw * +tab_by_name(var) + const char *var; +{ + const struct vartypesw *sw; + const char *p = strchr(var, '.'); + + if (!p) { + warnx("%s: illegal variable name", var); + return (NULL); + } + + for (sw = typesw; sw->name; sw++) + if (!strncmp(sw->name, var, p - var)) + break; + + if (!sw->name) { + warnx("%s: no such variable", var); + return (NULL); + } + + return (sw); } diff --git a/sbin/wsconsctl/wsconsctl.h b/sbin/wsconsctl/wsconsctl.h index fc8568b7995..ab639cbc184 100644 --- a/sbin/wsconsctl/wsconsctl.h +++ b/sbin/wsconsctl/wsconsctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconsctl.h,v 1.2 2001/05/08 22:31:09 mickey Exp $ */ +/* $OpenBSD: wsconsctl.h,v 1.3 2001/06/30 02:12:57 mickey Exp $ */ /* $NetBSD: wsconsctl.h 1.1 1998/12/28 14:01:17 hannken Exp $ */ /*- @@ -59,20 +59,19 @@ struct field { int flags; }; -void field_setup __P((struct field *, int)); -struct field *field_by_name __P((char *)); -struct field *field_by_value __P((void *)); -void pr_field __P((struct field *, char *)); +struct field *field_by_name __P((struct field *, char *)); +struct field *field_by_value __P((struct field *, void *)); +void pr_field __P((const char *, struct field *, const char *)); void rd_field __P((struct field *, char *, int)); int name2ksym __P((char *)); char *ksym2name __P((int)); keysym_t ksym_upcase __P((keysym_t)); -void keyboard_get_values __P((int)); -void keyboard_put_values __P((int)); -void mouse_get_values __P((int)); -void mouse_put_values __P((int)); -void display_get_values __P((int)); -void display_put_values __P((int)); +void keyboard_get_values __P((const char *,int)); +void keyboard_put_values __P((const char *,int)); +void mouse_get_values __P((const char *,int)); +void mouse_put_values __P((const char *,int)); +void display_get_values __P((const char *,int)); +void display_put_values __P((const char *,int)); int yyparse __P((void)); void yyerror __P((char *)); int yylex __P((void)); |