On Tue, Sep 20, 2011 at 03:54:22PM -0700, Jason Gerecke wrote:
> The new wacom-util.h should be the place to store defines which
> may be handy to use anywhere. At the moment this includes things
> like ARRAY_SIZE, bit manipulation, and mask manipulation defines.
> 
> Signed-off-by: Jason Gerecke <killert...@gmail.com>
> ---
> Changes from v3:
> 
>  * Not present in v3
> 
>  include/wacom-util.h |   51 
> ++++++++++++++++++++++++++++++++++++++++++++++++++
>  src/xf86Wacom.h      |    3 +-
>  src/xf86WacomDefs.h  |   24 -----------------------
>  tools/xsetwacom.c    |   13 +++++------
>  4 files changed, 58 insertions(+), 33 deletions(-)
>  create mode 100644 include/wacom-util.h
> 
> diff --git a/include/wacom-util.h b/include/wacom-util.h
> new file mode 100644
> index 0000000..ed42947
> --- /dev/null
> +++ b/include/wacom-util.h
> @@ -0,0 +1,51 @@
> +/*
> + * Copyright 2011 by Jason Gerecke, Wacom. <jason.gere...@wacom.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
> + */
> +
> +#ifndef WACOM_UTIL_H_
> +#define WACOM_UTIL_H_
> +
> +/**
> + * Get the number of elements in an array
> + */
> +#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
> +
> +/* to access kernel defined bits */

it's pretty much to access any bits :)
I'd apprecitate if you could document these a bit more because there's a bit
of extra knowledge that you need.

In fact, I'd even like a renaming of these to something self-explanatory.
e.g. bit_of_long, bits_set_in_long, or something like that.
I'm fine with a follow-up patch on that though.

I'm missing the Makefile.am change for this. If you run make distcheck
you'll probably notice that the new file won't be included in the tarball.
If you could add that part I'm happy with the patch otherwise.

Cheers,
  Peter

> +#define BIT(x)               (1UL<<((x) & (BITS_PER_LONG - 1)))
> +#define BITS_PER_LONG        (sizeof(long) * 8)
> +#define NBITS(x)     ((((x)-1)/BITS_PER_LONG)+1)
> +#define ISBITSET(x,y)        ((x)[LONG(y)] & BIT(y))
> +#define SETBIT(x,y)  ((x)[LONG(y)] |= BIT(y))
> +#define CLEARBIT(x,y)        ((x)[LONG(y)] &= ~BIT(y))
> +#define OFF(x)               ((x)%BITS_PER_LONG)
> +#define LONG(x)              ((x)/BITS_PER_LONG)
> +
> +/**
> + * Test if the mask is set in the given bitfield.
> + * @return TRUE if set or FALSE otherwise.
> + */
> +#define MaskIsSet(bitfield, mask) !!(((bitfield) & (mask)) == (mask))
> +/**
> + * Set the given mask for the given bitfield.
> + */
> +#define MaskSet(bitfield, mask) ((bitfield) |= (mask))
> +/**
> + * Clear the given mask from the given bitfield
> + */
> +#define MaskClear(bitfield, mask) ((bitfield) &= ~(mask))
> +
> +#endif /* WACOM_UTIL_H_ */
> diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h
> index 60353dc..c1b55c9 100644
> --- a/src/xf86Wacom.h
> +++ b/src/xf86Wacom.h
> @@ -23,10 +23,9 @@
>  #include <xorg-server.h>
>  #include <xorgVersion.h>
>  
> +#include <wacom-util.h>
>  #include "Xwacom.h"
>  
> -#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
> -
>  /* max number of input events to read in one read call */
>  #define MAX_EVENTS 50
>  
> diff --git a/src/xf86WacomDefs.h b/src/xf86WacomDefs.h
> index 94eee2e..cf16648 100644
> --- a/src/xf86WacomDefs.h
> +++ b/src/xf86WacomDefs.h
> @@ -94,30 +94,6 @@
>  #define ERASER_PROX     4
>  #define OTHER_PROX      1
>  
> -/* to access kernel defined bits */
> -#define BIT(x)               (1UL<<((x) & (BITS_PER_LONG - 1)))
> -#define BITS_PER_LONG        (sizeof(long) * 8)
> -#define NBITS(x)     ((((x)-1)/BITS_PER_LONG)+1)
> -#define ISBITSET(x,y)        ((x)[LONG(y)] & BIT(y))
> -#define SETBIT(x,y)  ((x)[LONG(y)] |= BIT(y))
> -#define CLEARBIT(x,y)        ((x)[LONG(y)] &= ~BIT(y))
> -#define OFF(x)               ((x)%BITS_PER_LONG)
> -#define LONG(x)              ((x)/BITS_PER_LONG)
> -
> -/**
> - * Test if the mask is set in the given bitfield.
> - * @return TRUE if set or FALSE otherwise.
> - */
> -#define MaskIsSet(bitfield, mask) !!(((bitfield) & (mask)) == (mask))
> -/**
> - * Set the given mask for the given bitfield.
> - */
> -#define MaskSet(bitfield, mask) ((bitfield) |= (mask))
> -/**
> - * Clear the given mask from the given bitfield
> - */
> -#define MaskClear(bitfield, mask) ((bitfield) &= ~(mask))
> -
>  
> /******************************************************************************
>   * Forward Declarations
>   
> *****************************************************************************/
> diff --git a/tools/xsetwacom.c b/tools/xsetwacom.c
> index 9d47ea6..a0056a7 100644
> --- a/tools/xsetwacom.c
> +++ b/tools/xsetwacom.c
> @@ -22,6 +22,7 @@
>  #endif
>  
>  #include <wacom-properties.h>
> +#include <wacom-util.h>
>  #include "Xwacom.h"
>  
>  #include <errno.h>
> @@ -43,8 +44,6 @@
>  #define TRACE(...) \
>       if (verbose) fprintf(stderr, "... " __VA_ARGS__)
>  
> -#define ArrayLength(a) ((unsigned int)(sizeof(a) / (sizeof((a)[0]))))
> -
>  static int verbose = False;
>  
>  enum printformat {
> @@ -785,11 +784,11 @@ static void list_mod(Display *dpy)
>  {
>       struct modifier *m = modifiers;
>  
> -     printf("%d modifiers are supported:\n", ArrayLength(modifiers) - 1);
> +     printf("%d modifiers are supported:\n", ARRAY_SIZE(modifiers) - 1);
>       while(m->name)
>               printf("        %s\n", m++->name);
>  
> -     printf("\n%d specialkeys are supported:\n", ArrayLength(specialkeys) - 
> 1);
> +     printf("\n%d specialkeys are supported:\n", ARRAY_SIZE(specialkeys) - 
> 1);
>       m = specialkeys;
>       while(m->name)
>               printf("        %s\n", m++->name);
> @@ -1948,7 +1947,7 @@ static void _set_matrix_prop(Display *dpy, XDevice 
> *dev, const float fmatrix[9])
>  
>       /* XI1 expects 32 bit properties (including float) as long,
>        * regardless of architecture */
> -     for (i = 0; i < sizeof(matrix)/sizeof(matrix[0]); i++)
> +     for (i = 0; i < ARRAY_SIZE(matrix); i++)
>               *(float*)(matrix + i) = fmatrix[i];
>  
>       XGetDeviceProperty(dpy, dev, matrix_prop, 0, 9, False,
> @@ -2448,8 +2447,8 @@ static void test_parameter_number(void)
>        * deprecated them.
>        * Numbers include trailing NULL entry.
>        */
> -     assert(ArrayLength(parameters) == 34);
> -     assert(ArrayLength(deprecated_parameters) == 17);
> +     assert(ARRAY_SIZE(parameters) == 34);
> +     assert(ARRAY_SIZE(deprecated_parameters) == 17);
>  }
>  
>  /**
> -- 
> 1.7.6


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to