summaryrefslogtreecommitdiff
path: root/usr.bin/sndioctl/sndioctl.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2020-04-27 21:44:48 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2020-04-27 21:44:48 +0000
commitaa2de24a52c51e24cffb0bf7ebf9cc9329a5ba9b (patch)
treeec2120f282177e38e1de68ff6c985a8985bd1077 /usr.bin/sndioctl/sndioctl.c
parentb1be0285ac170f59a6230af4d577d7b87ba447b0 (diff)
Display multi-state controls with exactly three decimal places.
Because for now, the maximum raw value of such controls is either 127 or 255, that assures that whenever the raw value changes, the displayed value changes, too. At the same time, it preserves the property that control values are not shown with excessive, misleading precision. If controls will ever be introduced that will have maximum raw values of less than 100 or of more than 999, the number of decimal places should then be reduced or increased for such controls as appropriate. With important help and an OK from ratchov@.
Diffstat (limited to 'usr.bin/sndioctl/sndioctl.c')
-rw-r--r--usr.bin/sndioctl/sndioctl.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/usr.bin/sndioctl/sndioctl.c b/usr.bin/sndioctl/sndioctl.c
index ff691dbe232..ce4ef8fe1a0 100644
--- a/usr.bin/sndioctl/sndioctl.c
+++ b/usr.bin/sndioctl/sndioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sndioctl.c,v 1.5 2020/04/16 12:57:14 ratchov Exp $ */
+/* $OpenBSD: sndioctl.c,v 1.6 2020/04/27 21:44:47 schwarze Exp $ */
/*
* Copyright (c) 2014-2020 Alexandre Ratchov <alex@caoua.org>
*
@@ -374,7 +374,14 @@ print_val(struct info *p, int mono)
switch (p->desc.type) {
case SIOCTL_NUM:
case SIOCTL_SW:
- printf("%.2g", p->curval / (float)p->desc.maxval);
+ if (p->desc.maxval == 1)
+ printf("%d", p->curval);
+ else
+ /*
+ * For now, maxval is always 127 or 255,
+ * so three decimals is always ideal.
+ */
+ printf("%.3f", p->curval / (float)p->desc.maxval);
break;
case SIOCTL_VEC:
case SIOCTL_LIST:
@@ -389,7 +396,11 @@ print_val(struct info *p, int mono)
if (more)
printf(",");
print_node(&e->desc.node1, mono);
- printf(":%.2g", e->curval / (float)e->desc.maxval);
+ if (e->desc.maxval == 1)
+ printf(":%d", e->curval);
+ else
+ printf(":%.3f",
+ e->curval / (float)e->desc.maxval);
more = 1;
}
}