On Wed, 2012-04-18 at 14:52 +1000, Peter Hutterer wrote:
> Don't hardcode a single stylus definition file, scan the directory for
> .stylus files

What's the use?

> Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
> ---
>  libwacom/libwacom-database.c |   37 +++++++++++++++++++++++++++++++++++--
>  libwacom/libwacomint.h       |    1 -
>  2 files changed, 35 insertions(+), 3 deletions(-)
> 
> diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
> index 5a6d212..fcc9f03 100644
> --- a/libwacom/libwacom-database.c
> +++ b/libwacom/libwacom-database.c
> @@ -37,6 +37,7 @@
>  #include <stdio.h>
>  
>  #define TABLET_SUFFIX ".tablet"
> +#define STYLUS_SUFFIX ".stylus"
>  #define FEATURES_GROUP "Features"
>  #define DEVICE_GROUP "Device"
>  #define BUTTONS_GROUP "Buttons"
> @@ -396,6 +397,24 @@ scandir_tablet_filter(const struct dirent *entry)
>       return !strcmp(&name[len - suffix_len], TABLET_SUFFIX);
>  }
>  
> +static int
> +scandir_stylus_filter(const struct dirent *entry)
> +{
> +     const char *name = entry->d_name;
> +     int len, suffix_len;
> +
> +     if (!name || name[0] == '.')
> +             return 0;
> +
> +     len = strlen(name);
> +     suffix_len = strlen(STYLUS_SUFFIX);
> +     if (len <= suffix_len)
> +             return 0;
> +
> +     return !strcmp(&name[len - suffix_len], STYLUS_SUFFIX);
> +}
> +
> +
>  WacomDeviceDatabase *
>  libwacom_database_new_for_path (const char *datadir)
>  {
> @@ -435,12 +454,26 @@ libwacom_database_new_for_path (const char *datadir)
>      free(files);
>  
>      /* Load styli */
> -    path = g_build_filename (datadir, STYLUS_DATA_FILE, NULL);
> +    n = scandir(datadir, &files, scandir_stylus_filter, alphasort);
> +    if (n <= 0) {
> +         libwacom_database_destroy(db);
> +         return NULL;
> +    }
> +
>      db->stylus_ht = g_hash_table_new_full (g_direct_hash,
>                                          g_direct_equal,
>                                          NULL,
>                                          (GDestroyNotify) 
> libwacom_stylus_destroy);
> -    libwacom_parse_stylus_keyfile(db, path);
> +    nfiles = n;
> +    while(n--) {
> +         path = g_build_filename (datadir, files[n]->d_name, NULL);
> +         libwacom_parse_stylus_keyfile(db, path);
> +         g_free(path);
> +    }
> +
> +    while(nfiles--)
> +         free(files[nfiles]);
> +    free(files);
>  
>      /* If we couldn't load _anything_ then something's wrong */
>      if (g_hash_table_size (db->device_ht) == 0 &&
> diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
> index 66202b0..5dcff6a 100644
> --- a/libwacom/libwacomint.h
> +++ b/libwacom/libwacomint.h
> @@ -54,7 +54,6 @@
>  
> 
>  #define GENERIC_DEVICE_MATCH "generic"
> -#define STYLUS_DATA_FILE "libwacom.stylus"
>  
>  typedef enum {
>       IS_BUILTIN_UNSET        = -1,



------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to