# HG changeset patch # User Matti Hamalainen # Date 1169681281 0 # Node ID a1224c1f8670cb6f3854250eeed555c3d3713b3e # Parent 9e683fb666bab4e52675c6facdd8a0ff9c1d7ab2 STILdb handling glue moved to xmms-sid.c diff -r 9e683fb666ba -r a1224c1f8670 src/xmms-sid.c --- a/src/xmms-sid.c Wed Jan 24 22:10:00 2007 +0000 +++ b/src/xmms-sid.c Wed Jan 24 23:28:01 2007 +0000 @@ -93,8 +93,13 @@ static GtkObject *xs_subctrl_adj = NULL; XS_MUTEX(xs_subctrl); -void xs_subctrl_close(void); -void xs_subctrl_update(void); +static t_xs_stildb *xs_stildb_db = NULL; +XS_MUTEX(xs_stildb_db); + +void xs_subctrl_close(void); +void xs_subctrl_update(void); +gint xs_stil_init(void); +void xs_stil_close(void); /* @@ -122,6 +127,7 @@ } #endif + /* * Initialization functions */ @@ -1042,3 +1048,99 @@ g_free(pTune->sidFormat); g_free(pTune); } + + +/* + * STIL-database handling + */ +gint xs_stil_init(void) +{ + XS_MUTEX_LOCK(xs_cfg); + + if (!xs_cfg.stilDBPath) { + XS_MUTEX_UNLOCK(xs_cfg); + return -1; + } + + XS_MUTEX_LOCK(xs_stildb_db); + + /* Check if already initialized */ + if (xs_stildb_db) + xs_stildb_free(xs_stildb_db); + + /* Allocate database */ + xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb)); + if (!xs_stildb_db) { + XS_MUTEX_UNLOCK(xs_cfg); + XS_MUTEX_UNLOCK(xs_stildb_db); + return -2; + } + + /* Read the database */ + if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0) { + xs_stildb_free(xs_stildb_db); + xs_stildb_db = NULL; + XS_MUTEX_UNLOCK(xs_cfg); + XS_MUTEX_UNLOCK(xs_stildb_db); + return -3; + } + + /* Create index */ + if (xs_stildb_index(xs_stildb_db) != 0) { + xs_stildb_free(xs_stildb_db); + xs_stildb_db = NULL; + XS_MUTEX_UNLOCK(xs_cfg); + XS_MUTEX_UNLOCK(xs_stildb_db); + return -4; + } + + XS_MUTEX_UNLOCK(xs_cfg); + XS_MUTEX_UNLOCK(xs_stildb_db); + return 0; +} + + +void xs_stil_close(void) +{ + XS_MUTEX_LOCK(xs_stildb_db); + xs_stildb_free(xs_stildb_db); + xs_stildb_db = NULL; + XS_MUTEX_UNLOCK(xs_stildb_db); +} + + +t_xs_stil_node *xs_stil_get(gchar *pcFilename) +{ + t_xs_stil_node *pResult; + gchar *tmpFilename; + + XS_MUTEX_LOCK(xs_stildb_db); + XS_MUTEX_LOCK(xs_cfg); + + if (xs_cfg.stilDBEnable && xs_stildb_db) { + if (xs_cfg.hvscPath) { + /* Remove postfixed directory separator from HVSC-path */ + tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/'); + if (tmpFilename && (tmpFilename[1] == 0)) + tmpFilename[0] = 0; + + /* Remove HVSC location-prefix from filename */ + tmpFilename = strstr(pcFilename, xs_cfg.hvscPath); + if (tmpFilename) + tmpFilename += strlen(xs_cfg.hvscPath); + else + tmpFilename = pcFilename; + } else + tmpFilename = pcFilename; + + XSDEBUG("xs_stil_get('%s') = '%s'\n", pcFilename, tmpFilename); + + pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename); + } else + pResult = NULL; + + XS_MUTEX_UNLOCK(xs_stildb_db); + XS_MUTEX_UNLOCK(xs_cfg); + + return pResult; +} diff -r 9e683fb666ba -r a1224c1f8670 src/xs_stil.c --- a/src/xs_stil.c Wed Jan 24 22:10:00 2007 +0000 +++ b/src/xs_stil.c Wed Jan 24 23:28:01 2007 +0000 @@ -22,7 +22,6 @@ */ #include "xs_stil.h" #include "xs_support.h" -#include "xs_config.h" #include #include #include @@ -141,7 +140,7 @@ xs_pstrcat(&(tmpNode->subTunes[subEntry]->pInfo), "\n");\ } -void XS_STILDB_ERR(gint lineNum, gchar *inLine, const char *fmt, ...) +static void XS_STILDB_ERR(gint lineNum, gchar *inLine, const char *fmt, ...) { va_list ap; @@ -393,7 +392,7 @@ /* Get STIL information node from database */ -static t_xs_stil_node *xs_stildb_get_node(t_xs_stildb *db, gchar *pcFilename) +t_xs_stil_node *xs_stildb_get_node(t_xs_stildb *db, gchar *pcFilename) { gint iStartNode, iEndNode, iQNode, r, i; gboolean iFound; @@ -447,102 +446,3 @@ return pResult; } - - -/* - * These should be moved out of this module some day ... - */ -static t_xs_stildb *xs_stildb_db = NULL; -XS_MUTEX(xs_stildb_db); - -gint xs_stil_init(void) -{ - XS_MUTEX_LOCK(xs_cfg); - - if (!xs_cfg.stilDBPath) { - XS_MUTEX_UNLOCK(xs_cfg); - return -1; - } - - XS_MUTEX_LOCK(xs_stildb_db); - - /* Check if already initialized */ - if (xs_stildb_db) - xs_stildb_free(xs_stildb_db); - - /* Allocate database */ - xs_stildb_db = (t_xs_stildb *) g_malloc0(sizeof(t_xs_stildb)); - if (!xs_stildb_db) { - XS_MUTEX_UNLOCK(xs_cfg); - XS_MUTEX_UNLOCK(xs_stildb_db); - return -2; - } - - /* Read the database */ - if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0) { - xs_stildb_free(xs_stildb_db); - xs_stildb_db = NULL; - XS_MUTEX_UNLOCK(xs_cfg); - XS_MUTEX_UNLOCK(xs_stildb_db); - return -3; - } - - /* Create index */ - if (xs_stildb_index(xs_stildb_db) != 0) { - xs_stildb_free(xs_stildb_db); - xs_stildb_db = NULL; - XS_MUTEX_UNLOCK(xs_cfg); - XS_MUTEX_UNLOCK(xs_stildb_db); - return -4; - } - - XS_MUTEX_UNLOCK(xs_cfg); - XS_MUTEX_UNLOCK(xs_stildb_db); - return 0; -} - - -void xs_stil_close(void) -{ - XS_MUTEX_LOCK(xs_stildb_db); - xs_stildb_free(xs_stildb_db); - xs_stildb_db = NULL; - XS_MUTEX_UNLOCK(xs_stildb_db); -} - - -t_xs_stil_node *xs_stil_get(gchar *pcFilename) -{ - t_xs_stil_node *pResult; - gchar *tmpFilename; - - XS_MUTEX_LOCK(xs_stildb_db); - XS_MUTEX_LOCK(xs_cfg); - - if (xs_cfg.stilDBEnable && xs_stildb_db) { - if (xs_cfg.hvscPath) { - /* Remove postfixed directory separator from HVSC-path */ - tmpFilename = xs_strrchr(xs_cfg.hvscPath, '/'); - if (tmpFilename && (tmpFilename[1] == 0)) - tmpFilename[0] = 0; - - /* Remove HVSC location-prefix from filename */ - tmpFilename = strstr(pcFilename, xs_cfg.hvscPath); - if (tmpFilename) - tmpFilename += strlen(xs_cfg.hvscPath); - else - tmpFilename = pcFilename; - } else - tmpFilename = pcFilename; - - XSDEBUG("xs_stil_get('%s') = '%s'\n", pcFilename, tmpFilename); - - pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename); - } else - pResult = NULL; - - XS_MUTEX_UNLOCK(xs_stildb_db); - XS_MUTEX_UNLOCK(xs_cfg); - - return pResult; -} diff -r 9e683fb666ba -r a1224c1f8670 src/xs_stil.h --- a/src/xs_stil.h Wed Jan 24 22:10:00 2007 +0000 +++ b/src/xs_stil.h Wed Jan 24 23:28:01 2007 +0000 @@ -39,12 +39,8 @@ gint xs_stildb_read(t_xs_stildb *, gchar *); gint xs_stildb_index(t_xs_stildb *); void xs_stildb_free(t_xs_stildb *); -t_xs_stil_node * xs_stildb_get(t_xs_stildb *, gchar *, gchar *); - +t_xs_stil_node * xs_stildb_get_node(t_xs_stildb *, gchar *); -gint xs_stil_init(void); -void xs_stil_close(void); -t_xs_stil_node * xs_stil_get(gchar *); #ifdef __cplusplus }