From 0033dc95e81ad356c95d3d248c44d2c289920543 Mon Sep 17 00:00:00 2001 From: khorben Date: Mon, 24 Dec 2012 01:20:12 +0000 Subject: [PATCH] Added a field type for signed integers. This is required when handling touchscreen calibration values, which is about to be implemented in wsconsctl (see PR kern/45872). Reviewed by uwe@ (thank you!) --- sbin/wsconsctl/util.c | 15 +++++++++++++-- sbin/wsconsctl/wsconsctl.h | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sbin/wsconsctl/util.c b/sbin/wsconsctl/util.c index bb9e9a944f30..b2a3e603adb3 100644 --- a/sbin/wsconsctl/util.c +++ b/sbin/wsconsctl/util.c @@ -1,7 +1,7 @@ -/* $NetBSD: util.c,v 1.30 2011/12/15 14:25:12 phx Exp $ */ +/* $NetBSD: util.c,v 1.31 2012/12/24 01:20:12 khorben Exp $ */ /*- - * Copyright (c) 1998, 2006 The NetBSD Foundation, Inc. + * Copyright (c) 1998, 2006, 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -257,6 +257,9 @@ pr_field(struct field *f, const char *sep) case FMT_UINT: (void)printf("%u", *((unsigned int *) f->valp)); break; + case FMT_INT: + (void)printf("%d", *((int *) f->valp)); + break; case FMT_STRING: (void)printf("\"%s\"", *((char **) f->valp)); break; @@ -361,6 +364,14 @@ rd_field(struct field *f, char *val, int merge) else *((unsigned int *) f->valp) = u; break; + case FMT_INT: + if (sscanf(val, "%d", &i) != 1) + errx(EXIT_FAILURE, "%s: not a number", val); + if (merge) + *((int *) f->valp) += i; + else + *((int *) f->valp) = i; + break; case FMT_STRING: if ((*((char **) f->valp) = strdup(val)) == NULL) err(EXIT_FAILURE, "strdup"); diff --git a/sbin/wsconsctl/wsconsctl.h b/sbin/wsconsctl/wsconsctl.h index f35583a523fe..588c3738b6ed 100644 --- a/sbin/wsconsctl/wsconsctl.h +++ b/sbin/wsconsctl/wsconsctl.h @@ -1,7 +1,7 @@ -/* $NetBSD: wsconsctl.h,v 1.11 2011/08/27 19:01:34 joerg Exp $ */ +/* $NetBSD: wsconsctl.h,v 1.12 2012/12/24 01:20:44 khorben Exp $ */ /*- - * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. + * Copyright (c) 1998, 2004, 2012 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -55,6 +55,7 @@ struct field { #define FMT_UINT 1 /* unsigned integer */ #define FMT_STRING 2 /* zero terminated string */ #define FMT_BITFIELD 3 /* bit field */ +#define FMT_INT 4 /* signed integer */ #define FMT_KBDTYPE 101 /* keyboard type */ #define FMT_MSTYPE 102 /* mouse type */ #define FMT_DPYTYPE 103 /* display type */