diff options
author | 2002-05-22 20:36:06 +0000 | |
---|---|---|
committer | 2002-05-22 20:36:06 +0000 | |
commit | b8557c36d8b5c6d875574bcd60f6a0ce2899d81e (patch) | |
tree | 1a37e23e0dddf5ab97051d27bfd84fa8d69d4a80 | |
parent | Fix last commit. (diff) | |
download | wireguard-openbsd-b8557c36d8b5c6d875574bcd60f6a0ce2899d81e.tar.xz wireguard-openbsd-b8557c36d8b5c6d875574bcd60f6a0ce2899d81e.zip |
implement new type: %%, given min,cur,max print the value in %%.
also accepts -= and += to adjust the value.
implement new flags: INIT, DEAD.
init means to prefetch the variable before setting, where
dead means to assume the variable is not implemented
(enottty was observed, most likely), set by the low-level
routines (upon observing the ioctl results).
add the variables for screen brightness,contrast,backlight --
all are precent-type, also rework the display.c to be easier
on the eyes. requested, commented and helped upon by miod@ and drahn@.
there was a discussion on wheather truncate or round
(the thin and think ends of the same egg) where
decided to allow it to truncate until demanded
otherwise by the eager masses.
-rw-r--r-- | sbin/wsconsctl/display.c | 256 | ||||
-rw-r--r-- | sbin/wsconsctl/util.c | 36 | ||||
-rw-r--r-- | sbin/wsconsctl/wsconsctl.c | 32 | ||||
-rw-r--r-- | sbin/wsconsctl/wsconsctl.h | 9 |
4 files changed, 210 insertions, 123 deletions
diff --git a/sbin/wsconsctl/display.c b/sbin/wsconsctl/display.c index 9e7faa18e82..220c6242f31 100644 --- a/sbin/wsconsctl/display.c +++ b/sbin/wsconsctl/display.c @@ -1,4 +1,4 @@ -/* $OpenBSD: display.c,v 1.5 2001/10/24 17:45:59 miod Exp $ */ +/* $OpenBSD: display.c,v 1.6 2002/05/22 20:36:06 mickey Exp $ */ /* $NetBSD: display.c,v 1.1 1998/12/28 14:01:16 hannken Exp $ */ /*- @@ -40,71 +40,110 @@ #include <sys/ioctl.h> #include <sys/time.h> #include <dev/wscons/wsconsio.h> +#include <errno.h> #include <err.h> #include "wsconsctl.h" int dpytype; int focus; +struct field_pc brightness, contrast, backlight; 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 }, + { "type", &dpytype, FMT_DPYTYPE, FLG_RDONLY }, + { "focus", &focus, FMT_UINT, FLG_MODIFY }, + { "brightness", &brightness, FMT_PC, FLG_MODIFY|FLG_INIT }, + { "contrast", &contrast, FMT_PC, FLG_MODIFY|FLG_INIT }, + { "backlight", &backlight, FMT_PC, FLG_MODIFY|FLG_INIT }, + /* screen burner section, outact MUST BE THE LAST, see the set_values */ + { "screen_on", &burnon, FMT_UINT, FLG_MODIFY|FLG_INIT }, + { "screen_off", &burnoff, FMT_UINT, FLG_MODIFY|FLG_INIT }, + { "vblank", &vblank, FMT_BOOL, FLG_MODIFY|FLG_INIT }, + { "kbdact", &kbdact, FMT_BOOL, FLG_MODIFY|FLG_INIT }, + { "msact", &msact, FMT_BOOL, FLG_MODIFY|FLG_INIT }, + { "outact", &outact, FMT_BOOL, FLG_MODIFY|FLG_INIT }, { NULL } }; +#define fillioctl(n) { cmd = n; cmd_str = #n; } + void display_get_values(pre, fd) const char *pre; int fd; { struct wsdisplay_addscreendata gscr; - - if (field_by_value(display_field_tab, &dpytype)->flags & FLG_GET) - if (ioctl(fd, WSDISPLAYIO_GTYPE, &dpytype) < 0) - warn("WSDISPLAYIO_GTYPE"); + struct wsdisplay_param param; + struct wsdisplay_burner burners; + struct field *pf; + const char *cmd_str; + void *ptr; + unsigned long cmd; + int bon = 0; focus = gscr.idx = -1; - if (field_by_value(display_field_tab, &focus)->flags & FLG_GET) { - if (ioctl(fd, WSDISPLAYIO_GETSCREEN, &gscr) < 0) - warn("WSDISPLAYIO_GETSCREEN"); - } - - 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) { + for (pf = display_field_tab; pf->name; pf++) { + + if (!(pf->flags & FLG_GET) || pf->flags & FLG_DEAD) + continue; + + ptr = pf->valp; + + if (ptr == &dpytype) { + fillioctl(WSDISPLAYIO_GTYPE); + } else if (ptr == &focus) { + fillioctl(WSDISPLAYIO_GETSCREEN); + ptr = ℊ + } else if (ptr == &brightness) { + ptr = ¶m; + param.param = WSDISPLAYIO_PARAM_BRIGHTNESS; + } else if (ptr == &contrast) { + ptr = ¶m; + param.param = WSDISPLAYIO_PARAM_CONTRAST; + } else if (ptr == &backlight) { + ptr = ¶m; + param.param = WSDISPLAYIO_PARAM_BACKLIGHT; + } else if (ptr == &burnon || ptr == &burnoff || + ptr == &vblank || ptr == &kbdact || + ptr == &outact || ptr == &msact) { + fillioctl(WSDISPLAYIO_GBURNER); + ptr = &burners; + if (!bon) + bzero(&burners, sizeof(burners)); + } else + cmd = 0; + + if (ptr == ¶m) { + fillioctl(WSDISPLAYIO_GETPARAM); + } - struct wsdisplay_burner burners; + if (!bon || cmd != WSDISPLAYIO_GBURNER) { + errno = ENOTTY; + if (!cmd || ioctl(fd, cmd, ptr) < 0) { + if (errno == ENOTTY) { + pf->flags |= FLG_DEAD; + continue; + } else + warn(cmd_str); + } + } - if (ioctl(fd, WSDISPLAYIO_GBURNER, &burners) < 0) - warn("WSDISPLAYIO_GBURNER"); - else { - if (field_by_value(display_field_tab, &burnon)->flags & FLG_GET) + if (ptr == &burners) { + if (!bon) { burnon = burners.on; - - if (field_by_value(display_field_tab, &burnoff)->flags & FLG_GET) burnoff = burners.off; - - if (field_by_value(display_field_tab, &vblank)->flags & FLG_GET) vblank = burners.flags & WSDISPLAY_BURN_VBLANK; - - if (field_by_value(display_field_tab, &kbdact)->flags & FLG_GET) kbdact = burners.flags & WSDISPLAY_BURN_KBD; - - if (field_by_value(display_field_tab, &msact )->flags & FLG_GET) msact = burners.flags & WSDISPLAY_BURN_MOUSE; - - if (field_by_value(display_field_tab, &outact)->flags & FLG_GET) outact = burners.flags & WSDISPLAY_BURN_OUTPUT; + } + bon++; + } else if (ptr == ¶m) { + struct field_pc *pc = pf->valp; + + pc->min = param.min; + pc->cur = param.curval; + pc->max = param.max; } } } @@ -114,72 +153,81 @@ display_put_values(pre, fd) const char *pre; int fd; { - if (field_by_value(display_field_tab, &focus)->flags & FLG_SET) - if (ioctl(fd, WSDISPLAYIO_SETSCREEN, &focus) < 0) - warn("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) - warn("WSDISPLAYIO_GBURNER"); - else { - if (field_by_value(display_field_tab, &burnon)->flags & FLG_SET) - burners.on = burnon; - - if (field_by_value(display_field_tab, &burnoff)->flags & FLG_SET) - burners.off = burnoff; - - 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(display_field_tab, &kbdact)->flags & FLG_SET) { - if (kbdact) - burners.flags |= WSDISPLAY_BURN_KBD; - else - burners.flags &= ~WSDISPLAY_BURN_KBD; - } - - 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(display_field_tab, &outact)->flags & FLG_SET) { - if (outact) - burners.flags |= WSDISPLAY_BURN_OUTPUT; - else - burners.flags &= ~WSDISPLAY_BURN_OUTPUT; - } + struct wsdisplay_param param; + struct wsdisplay_burner burners; + struct field *pf; + const char *cmd_str; + void *ptr; + unsigned long cmd; + int id; + + for (pf = display_field_tab; pf->name; pf++) { + + if (!(pf->flags & FLG_SET) || pf->flags & FLG_DEAD) + continue; + + ptr = pf->valp; + + if (ptr == &focus) { + fillioctl(WSDISPLAYIO_SETSCREEN); + } else if (ptr == &brightness) { + ptr = ¶m; + id = WSDISPLAYIO_PARAM_BRIGHTNESS; + } else if (ptr == &contrast) { + ptr = ¶m; + id = WSDISPLAYIO_PARAM_CONTRAST; + } else if (ptr == &backlight) { + ptr = ¶m; + id = WSDISPLAYIO_PARAM_BACKLIGHT; + } else if (ptr == &burnon || ptr == &burnoff || + ptr == &vblank || ptr == &kbdact || + ptr == &outact || ptr == &msact) { + + bzero(&burners, sizeof(burners)); + burners.on = burnon; + burners.off = burnoff; + if (vblank) + burners.flags |= WSDISPLAY_BURN_VBLANK; + else + burners.flags &= ~WSDISPLAY_BURN_VBLANK; + if (kbdact) + burners.flags |= WSDISPLAY_BURN_KBD; + else + burners.flags &= ~WSDISPLAY_BURN_KBD; + if (msact) + burners.flags |= WSDISPLAY_BURN_MOUSE; + else + burners.flags &= ~WSDISPLAY_BURN_MOUSE; + if (outact) + burners.flags |= WSDISPLAY_BURN_OUTPUT; + else + burners.flags &= ~WSDISPLAY_BURN_OUTPUT; + + fillioctl(WSDISPLAYIO_SBURNER); + ptr = &burners; + } else + cmd = 0; + + if (ptr == ¶m) { + struct field_pc *pc = pf->valp; + + bzero(¶m, sizeof(param)); + param.param = id; + param.min = pc->min; + param.curval = pc->cur; + param.max = pc->max; + fillioctl(WSDISPLAYIO_SETPARAM); + } - if (ioctl(fd, WSDISPLAYIO_SBURNER, &burners) < 0) - warn("WSDISPLAYIO_SBURNER"); - else { - if (field_by_value(display_field_tab, &burnon)->flags & FLG_SET) - pr_field(pre, field_by_value(display_field_tab, &burnon), " -> "); - if (field_by_value(display_field_tab, &burnoff)->flags & FLG_SET) - pr_field(pre, field_by_value(display_field_tab, &burnoff), " -> "); - if (field_by_value(display_field_tab, &vblank)->flags & FLG_SET) - pr_field(pre, field_by_value(display_field_tab, &vblank), " -> "); - if (field_by_value(display_field_tab, &kbdact)->flags & FLG_SET) - pr_field(pre, field_by_value(display_field_tab, &kbdact), " -> "); - if (field_by_value(display_field_tab, &msact )->flags & FLG_SET) - pr_field(pre, field_by_value(display_field_tab, &msact), " -> "); - if (field_by_value(display_field_tab, &outact)->flags & FLG_SET) - pr_field(pre, field_by_value(display_field_tab, &outact), " -> "); - } + errno = ENOTTY; + if (!cmd || ioctl(fd, cmd, ptr) < 0) { + if (errno == ENOTTY) { + pf->flags |= FLG_DEAD; + continue; + } else + warn(cmd_str); } + + pr_field(pre, pf, " -> "); } } diff --git a/sbin/wsconsctl/util.c b/sbin/wsconsctl/util.c index 35e52d292f3..4a5d9737099 100644 --- a/sbin/wsconsctl/util.c +++ b/sbin/wsconsctl/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.8 2002/02/23 05:44:20 jason Exp $ */ +/* $OpenBSD: util.c,v 1.9 2002/05/22 20:36:06 mickey Exp $ */ /* $NetBSD: util.c,v 1.8 2000/03/14 08:11:53 sato Exp $ */ /*- @@ -127,7 +127,7 @@ field_by_name(field_tab, name) const char *p = strchr(name, '.'); if (!p++) - errx(1, "%s: illigale variable name", name); + errx(1, "%s: illegal variable name", name); for (; field_tab->name; field_tab++) if (strcmp(field_tab->name, p) == 0) @@ -187,9 +187,10 @@ pr_field(pre, f, sep) struct field *f; const char *sep; { - char *p; + struct field_pc *pc; u_int flags; - int i; + char *p; + int i, n; if (sep) printf("%s.%s%s", pre, f->name, sep); @@ -201,6 +202,12 @@ pr_field(pre, f, sep) case FMT_BOOL: printf("%s", *((u_int *) f->valp)? "on" : "off"); break; + case FMT_PC: + pc = f->valp; + i = pc->max - pc->min; + n = pc->cur - pc->min; + printf("%u.%02u%%", n * 100 / i, ((n * 100) % i) * 100 / i); + break; case FMT_KBDTYPE: p = int2name(*((u_int *) f->valp), 1, kbtype_tab, TABLEN(kbtype_tab)); @@ -247,8 +254,9 @@ rd_field(f, val, merge) char *val; int merge; { + struct field_pc *pc; int i; - u_int u; + u_int u, r, fr; char *p; struct wscons_keymap *mp; @@ -267,6 +275,24 @@ rd_field(f, val, merge) errx(1, "%s: invalid value (on/off)", val); *((u_int *) f->valp) = val[1] == 'n'? 1 : 0; break; + case FMT_PC: + fr = 0; + if ((i = sscanf(val, "%u.%u%%", &u, &fr)) != 2 && i != 1) + errx(1, "%s: not a valid number", val); + pc = f->valp; + r = pc->max - pc->min; + i = pc->min + (r * u) / 100 + (r * fr) / 100 / 100; + if (merge == '+') + pc->cur += i; + else if (merge == '-') + pc->cur -= i; + else + pc->cur = i; + if (pc->cur > pc->max) + pc->cur = pc->max; + if (pc->cur < pc->min) + pc->cur = pc->min; + break; case FMT_KBDENC: p = strchr(val, '.'); if (p != NULL) diff --git a/sbin/wsconsctl/wsconsctl.c b/sbin/wsconsctl/wsconsctl.c index 6dcd6333105..ef00cff202c 100644 --- a/sbin/wsconsctl/wsconsctl.c +++ b/sbin/wsconsctl/wsconsctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconsctl.c,v 1.10 2002/02/16 21:27:38 millert Exp $ */ +/* $OpenBSD: wsconsctl.c,v 1.11 2002/05/22 20:36:06 mickey Exp $ */ /* $NetBSD: wsconsctl.c,v 1.2 1998/12/29 22:40:20 hannken Exp $ */ /*- @@ -139,17 +139,18 @@ main(argc, argv) 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; + for (f = sw->field_tab; f->name; f++) + if ((f->flags & (FLG_NOAUTO|FLG_WRONLY)) == 0) + f->flags |= FLG_GET; (*sw->getval)(sw->name, sw->fd); - for (i = 0; sw->field_tab[i].name; i++) - if (sw->field_tab[i].flags & FLG_NOAUTO) + for (f = sw->field_tab; f->name; f++) + if (f->flags & FLG_DEAD) + continue; + else if (f->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); + sw->name, f->name); + else if (f->flags & FLG_GET) + pr_field(sw->name, f, sep); } } else if (argc > 0) { if (wflag != 0) @@ -159,9 +160,10 @@ main(argc, argv) warnx("'=' not found"); continue; } - if (p > argv[i] && *(p - 1) == '+') { + if (p > argv[i] && + (*(p - 1) == '+' || *(p - 1) == '-')) { + do_merge = *(p - 1); *(p - 1) = '\0'; - do_merge = 1; } else do_merge = 0; *p++ = '\0'; @@ -176,11 +178,13 @@ main(argc, argv) continue; } f = field_by_name(sw->field_tab, argv[i]); + if (f->flags & FLG_DEAD) + continue; if ((f->flags & FLG_RDONLY) != 0) { warnx("%s: read only", argv[i]); continue; } - if (do_merge) { + if (do_merge || f->flags & FLG_INIT) { if ((f->flags & FLG_MODIFY) == 0) errx(1, "%s: can only be set", argv[i]); @@ -206,6 +210,8 @@ main(argc, argv) continue; } f = field_by_name(sw->field_tab, argv[i]); + if (f->flags & FLG_DEAD) + continue; if ((f->flags & FLG_WRONLY) != 0) { warnx("%s: write only", argv[i]); continue; diff --git a/sbin/wsconsctl/wsconsctl.h b/sbin/wsconsctl/wsconsctl.h index 4fa15e90b1b..341851af90f 100644 --- a/sbin/wsconsctl/wsconsctl.h +++ b/sbin/wsconsctl/wsconsctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconsctl.h,v 1.4 2002/02/16 21:27:38 millert Exp $ */ +/* $OpenBSD: wsconsctl.h,v 1.5 2002/05/22 20:36:06 mickey Exp $ */ /* $NetBSD: wsconsctl.h 1.1 1998/12/28 14:01:17 hannken Exp $ */ /*- @@ -44,6 +44,7 @@ struct field { void *valp; #define FMT_UINT 1 /* unsigned integer */ #define FMT_BOOL 2 /* boolean on/off */ +#define FMT_PC 3 /* percentage fixed point 000.00 */ #define FMT_KBDTYPE 101 /* keyboard type */ #define FMT_MSTYPE 102 /* mouse type */ #define FMT_DPYTYPE 103 /* display type */ @@ -56,9 +57,15 @@ struct field { #define FLG_MODIFY 0x0008 /* variable may be modified with += */ #define FLG_GET 0x0100 /* read this variable from driver */ #define FLG_SET 0x0200 /* write this variable to driver */ +#define FLG_INIT 0x0400 /* init (read) before write */ +#define FLG_DEAD 0x0800 /* the var isn't there, let it rest */ int flags; }; +struct field_pc { + int max, min, cur; +}; + struct field *field_by_name(struct field *, char *); struct field *field_by_value(struct field *, void *); void pr_field(const char *, struct field *, const char *); |