diff options
author | Martynas Venckus <martynas@cvs.openbsd.org> | 2009-07-15 20:32:29 +0000 |
---|---|---|
committer | Martynas Venckus <martynas@cvs.openbsd.org> | 2009-07-15 20:32:29 +0000 |
commit | 5982ddc6ed98967c73889e15576dc2a8f2c2e6d2 (patch) | |
tree | 933bcc588649a83182556de891c0635403c007f7 /sbin | |
parent | 2d64145026946ef281fa3700543852ff2b5a745b (diff) |
for rw query and print value that has actually been set in the
similar way that mixerctl does. so that info for setting things
like brightness makes sense (since we scale, like, 8 values to
per-cent). also, it consistifies get/put, shrinks code since we
don't need to do that in every single 'driver'. ok miod@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/wsconsctl/display.c | 12 | ||||
-rw-r--r-- | sbin/wsconsctl/keyboard.c | 68 | ||||
-rw-r--r-- | sbin/wsconsctl/mouse.c | 32 | ||||
-rw-r--r-- | sbin/wsconsctl/wsconsctl.c | 19 | ||||
-rw-r--r-- | sbin/wsconsctl/wsconsctl.h | 8 |
5 files changed, 59 insertions, 80 deletions
diff --git a/sbin/wsconsctl/display.c b/sbin/wsconsctl/display.c index 6c0c53729d4..53e44c28a78 100644 --- a/sbin/wsconsctl/display.c +++ b/sbin/wsconsctl/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.11 2008/06/26 05:42:06 ray Exp $ */ +/* $OpenBSD: display.c,v 1.12 2009/07/15 20:32:28 martynas Exp $ */ /* $NetBSD: display.c,v 1.1 1998/12/28 14:01:16 hannken Exp $ */ /*- @@ -141,7 +141,7 @@ display_get_values(const char *pre, int fd) } } -void +int display_put_values(const char *pre, int fd) { struct wsdisplay_param param; @@ -215,10 +215,12 @@ display_put_values(const char *pre, int fd) if (errno == ENOTTY) { pf->flags |= FLG_DEAD; continue; - } else + } else { warn(cmd_str); + return 1; + } } - - pr_field(pre, pf, " -> "); } + + return 0; } diff --git a/sbin/wsconsctl/keyboard.c b/sbin/wsconsctl/keyboard.c index 0b4e4d626bb..2539e565bd5 100644 --- a/sbin/wsconsctl/keyboard.c +++ b/sbin/wsconsctl/keyboard.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyboard.c,v 1.6 2008/06/26 05:42:06 ray Exp $ */ +/* $OpenBSD: keyboard.c,v 1.7 2009/07/15 20:32:28 martynas Exp $ */ /* $NetBSD: keyboard.c 1.1 1998/12/28 14:01:17 hannken Exp $ */ /*- @@ -127,7 +127,7 @@ keyboard_get_values(const char *pre, int fd) warn("WSKBDIO_GETENCODING"); } -void +int keyboard_put_values(const char *pre, int fd) { bell.which = 0; @@ -137,18 +137,9 @@ keyboard_put_values(const char *pre, int fd) bell.which |= WSKBD_BELL_DOPERIOD; 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) + if (bell.which != 0 && ioctl(fd, WSKBDIO_SETBELL, &bell) < 0) { warn("WSKBDIO_SETBELL"); - else { - if (bell.which & WSKBD_BELL_DOPITCH) - pr_field(pre, field_by_value(keyboard_field_tab, - &bell.pitch), " -> "); - if (bell.which & WSKBD_BELL_DOPERIOD) - pr_field(pre, field_by_value(keyboard_field_tab, - &bell.period), " -> "); - if (bell.which & WSKBD_BELL_DOVOLUME) - pr_field(pre, field_by_value(keyboard_field_tab, - &bell.volume), " -> "); + return 1; } dfbell.which = 0; @@ -159,23 +150,16 @@ keyboard_put_values(const char *pre, int fd) 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) + ioctl(fd, WSKBDIO_SETDEFAULTBELL, &dfbell) < 0) { warn("WSKBDIO_SETDEFAULTBELL"); - else { - if (dfbell.which & WSKBD_BELL_DOPITCH) - pr_field(pre, field_by_value(keyboard_field_tab, - &dfbell.pitch), " -> "); - if (dfbell.which & WSKBD_BELL_DOPERIOD) - pr_field(pre, field_by_value(keyboard_field_tab, - &dfbell.period), " -> "); - if (dfbell.which & WSKBD_BELL_DOVOLUME) - pr_field(pre, field_by_value(keyboard_field_tab, - &dfbell.volume), " -> "); + return 1; } if (field_by_value(keyboard_field_tab, &kbmap)->flags & FLG_SET) { - if (ioctl(fd, WSKBDIO_SETMAP, &kbmap) < 0) + if (ioctl(fd, WSKBDIO_SETMAP, &kbmap) < 0) { warn("WSKBDIO_SETMAP"); + return 1; + } } repeat.which = 0; @@ -184,15 +168,9 @@ keyboard_put_values(const char *pre, int fd) 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) + ioctl(fd, WSKBDIO_SETKEYREPEAT, &repeat) < 0) { warn("WSKBDIO_SETKEYREPEAT"); - else { - if (repeat.which & WSKBD_KEYREPEAT_DODEL1) - pr_field(pre, field_by_value(keyboard_field_tab, - &repeat.del1), " -> "); - if (repeat.which & WSKBD_KEYREPEAT_DODELN) - pr_field(pre, field_by_value(keyboard_field_tab, - &repeat.delN), " -> "); + return 1; } dfrepeat.which = 0; @@ -201,32 +179,24 @@ keyboard_put_values(const char *pre, int fd) 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) + ioctl(fd, WSKBDIO_SETDEFAULTKEYREPEAT, &dfrepeat) < 0) { warn("WSKBDIO_SETDEFAULTKEYREPEAT"); - else { - if (dfrepeat.which &WSKBD_KEYREPEAT_DODEL1) - pr_field(pre, field_by_value(keyboard_field_tab, - &dfrepeat.del1), " -> "); - if (dfrepeat.which & WSKBD_KEYREPEAT_DODELN) - pr_field(pre, field_by_value(keyboard_field_tab, - &dfrepeat.delN), " -> "); + return 1; } if (field_by_value(keyboard_field_tab, &ledstate)->flags & FLG_SET) { - if (ioctl(fd, WSKBDIO_SETLEDS, &ledstate) < 0) + if (ioctl(fd, WSKBDIO_SETLEDS, &ledstate) < 0) { warn("WSKBDIO_SETLEDS"); - else { - pr_field(pre, field_by_value(keyboard_field_tab, - &ledstate), " -> "); + return 1; } } if (field_by_value(keyboard_field_tab, &kbdencoding)->flags & FLG_SET) { - if (ioctl(fd, WSKBDIO_SETENCODING, &kbdencoding) < 0) + if (ioctl(fd, WSKBDIO_SETENCODING, &kbdencoding) < 0) { warn("WSKBDIO_SETENCODING"); - else { - pr_field(pre, field_by_value(keyboard_field_tab, - &kbdencoding), " -> "); + return 1; } } + + return 0; } diff --git a/sbin/wsconsctl/mouse.c b/sbin/wsconsctl/mouse.c index 6a9ac296c9a..daefd4a3a6a 100644 --- a/sbin/wsconsctl/mouse.c +++ b/sbin/wsconsctl/mouse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mouse.c,v 1.7 2008/06/26 05:42:06 ray Exp $ */ +/* $OpenBSD: mouse.c,v 1.8 2009/07/15 20:32:28 martynas Exp $ */ /* $NetBSD: mouse.c,v 1.3 1999/11/15 13:47:30 ad Exp $ */ /*- @@ -81,23 +81,19 @@ mouse_get_values(const char *pre, int fd) } } -void +int mouse_put_values(const char *pre, int fd) { if (field_by_value(mouse_field_tab, &resolution)->flags & FLG_SET) { - if (ioctl(fd, WSMOUSEIO_SRES, &resolution) < 0) + if (ioctl(fd, WSMOUSEIO_SRES, &resolution) < 0) { warn("WSMOUSEIO_SRES"); - else { - pr_field(pre, field_by_value(mouse_field_tab, - &resolution), " -> "); + return 1; } } if (field_by_value(mouse_field_tab, &samplerate)->flags & FLG_SET) { - if (ioctl(fd, WSMOUSEIO_SRATE, &samplerate) < 0) + if (ioctl(fd, WSMOUSEIO_SRATE, &samplerate) < 0) { warn("WSMOUSEIO_SRATE"); - else { - pr_field(pre, field_by_value(mouse_field_tab, - &samplerate), " -> "); + return 1; } } if (field_by_value(mouse_field_tab, &rawmode)->flags & FLG_SET) { @@ -106,11 +102,10 @@ mouse_put_values(const char *pre, int fd) if (errno == ENOTTY) { field_by_value(mouse_field_tab, &rawmode)->flags |= FLG_DEAD; - } else + } else { warn("WSMOUSEIO_SCALIBCOORDS"); - } else { - pr_field(pre, field_by_value(mouse_field_tab, - &rawmode), " -> "); + return 1; + } } } if (field_by_value(mouse_field_tab, &wmcoords)->flags & FLG_SET) { @@ -118,11 +113,12 @@ mouse_put_values(const char *pre, int fd) if (errno == ENOTTY) { field_by_value(mouse_field_tab, &wmcoords)->flags |= FLG_DEAD; - } else + } else { warn("WSMOUSEIO_SCALIBCOORDS"); - } else { - pr_field(pre, field_by_value(mouse_field_tab, - &wmcoords), " -> "); + return 1; + } } } + + return 0; } diff --git a/sbin/wsconsctl/wsconsctl.c b/sbin/wsconsctl/wsconsctl.c index df90528bebc..8685cfae252 100644 --- a/sbin/wsconsctl/wsconsctl.c +++ b/sbin/wsconsctl/wsconsctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconsctl.c,v 1.21 2008/06/26 05:42:06 ray Exp $ */ +/* $OpenBSD: wsconsctl.c,v 1.22 2009/07/15 20:32:28 martynas Exp $ */ /* $NetBSD: wsconsctl.c,v 1.2 1998/12/29 22:40:20 hannken Exp $ */ /*- @@ -55,7 +55,7 @@ struct vartypesw { int fd; struct field *field_tab; void (*getval)(const char *pre, int); - void (*putval)(const char *pre, int); + int (*putval)(const char *pre, int); } typesw[] = { { "keyboard", PATH_KEYBOARD, -1, keyboard_field_tab, keyboard_get_values, keyboard_put_values }, @@ -87,7 +87,7 @@ usage(char *msg) int main(int argc, char *argv[]) { - int i, ch, error = 0, aflag = 0, do_merge; + int i, ch, error = 0, aflag = 0, do_merge, putval; struct vartypesw *sw = NULL; char *sep = "=", *p; char *wdev = NULL; @@ -212,8 +212,19 @@ main(int argc, char *argv[]) } rd_field(f, p, do_merge); f->flags |= FLG_SET; - (*sw->putval)(sw->name, sw->fd); + putval = (*sw->putval)(sw->name, sw->fd); f->flags &= ~FLG_SET; + if (putval != 0 || f->flags & FLG_DEAD) + continue; + if (f->flags & FLG_WRONLY) { + pr_field(sw->name, f, " -> "); + } else { + f->flags |= FLG_GET; + (*sw->getval)(sw->name, sw->fd); + if (f->flags & FLG_DEAD) + continue; + pr_field(sw->name, f, " -> "); + } } } else usage(NULL); diff --git a/sbin/wsconsctl/wsconsctl.h b/sbin/wsconsctl/wsconsctl.h index 18cd165d817..5319bc1f6db 100644 --- a/sbin/wsconsctl/wsconsctl.h +++ b/sbin/wsconsctl/wsconsctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconsctl.h,v 1.8 2008/06/26 05:42:06 ray Exp $ */ +/* $OpenBSD: wsconsctl.h,v 1.9 2009/07/15 20:32:28 martynas Exp $ */ /* $NetBSD: wsconsctl.h 1.1 1998/12/28 14:01:17 hannken Exp $ */ /*- @@ -69,11 +69,11 @@ int name2ksym(char *); char *ksym2name(int); keysym_t ksym_upcase(keysym_t); void keyboard_get_values(const char *,int); -void keyboard_put_values(const char *,int); +int keyboard_put_values(const char *,int); void mouse_get_values(const char *,int); -void mouse_put_values(const char *,int); +int mouse_put_values(const char *,int); void display_get_values(const char *,int); -void display_put_values(const char *,int); +int display_put_values(const char *,int); int yyparse(void); void yyerror(char *); int yylex(void); |