From 78f2b9e7df82b43cd497b5885125d15dc5526c01 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 23 Oct 2024 11:16:18 +1000 Subject: [PATCH] database: allow for multiple entries in a database path Split the given database path by colon, same as PATH behavior, to allow callers to pass multiple database paths. --- libwacom/libwacom-database.c | 20 ++++++++++++-------- libwacom/libwacom.h | 2 ++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c index 152b554a..bfa12ec4 100644 --- a/libwacom/libwacom-database.c +++ b/libwacom/libwacom-database.c @@ -1132,10 +1132,10 @@ stylus_compare(WacomStylusId *a, WacomStylusId *b) } static WacomDeviceDatabase * -database_new_for_paths (const char **datadirs) +database_new_for_paths (char * const *datadirs) { WacomDeviceDatabase *db; - const char **datadir; + char * const *datadir; db = g_new0 (WacomDeviceDatabase, 1); db->device_ht = g_hash_table_new_full (g_str_hash, @@ -1174,17 +1174,21 @@ database_new_for_paths (const char **datadirs) LIBWACOM_EXPORT WacomDeviceDatabase * libwacom_database_new_for_path (const char *datadir) { - const char *datadirs[] = { - datadir, - NULL, - }; - return database_new_for_paths(datadirs); + WacomDeviceDatabase *db; + char **paths; + + paths = g_strsplit(datadir, ":", 0); + db = database_new_for_paths(paths); + + g_strfreev(paths); + + return db; } LIBWACOM_EXPORT WacomDeviceDatabase * libwacom_database_new (void) { - const char *datadir[] = { + char *datadir[] = { ETCDIR, DATADIR, NULL, diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h index 8797e884..2882fcff 100644 --- a/libwacom/libwacom.h +++ b/libwacom/libwacom.h @@ -362,6 +362,8 @@ WacomDeviceDatabase* libwacom_database_new(void); * a layouts/ subdirectory for the svg files if any of the .tablet * files references an svg. * + * datadir may be a colon-separated list of directories. + * * @return A new database or NULL on error. * * @ingroup context