changeset 622:d7389ea52113

Move SLDB and STIL utility functions to xs_slsup.[ch] and amend some changes between XMMS-SID and Aud-SID via a macro mess.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 03 Sep 2007 00:22:04 +0000
parents 11e24183ff23
children c1f10da42684
files src/xmms-sid.c src/xmms-sid.h src/xs_fileinfo.c src/xs_slsup.c src/xs_slsup.h src/xs_stil.c
diffstat 6 files changed, 329 insertions(+), 268 deletions(-) [+]
line wrap: on
line diff
--- a/src/xmms-sid.c	Mon Sep 03 00:21:05 2007 +0000
+++ b/src/xmms-sid.c	Mon Sep 03 00:22:04 2007 +0000
@@ -39,6 +39,8 @@
 #include "xs_interface.h"
 #include "xs_glade.h"
 #include "xs_player.h"
+#include "xs_slsup.h"
+
 
 /*
  * Include player engines
@@ -94,13 +96,6 @@
 void		xs_subctrl_close(void);
 void		xs_subctrl_update(void);
 
-static t_xs_sldb *xs_sldb_db = NULL;
-XS_MUTEX(xs_sldb_db);
-
-gint		xs_songlen_init(void);
-void		xs_songlen_close(void);
-t_xs_sldb_node *xs_songlen_get(const gchar *);
-
 
 /*
  * Error messages
@@ -976,165 +971,3 @@
 	XS_MUTEX_UNLOCK(xs_status);
 }
 
-
-/* Allocate a new tune information structure
- */
-t_xs_tuneinfo *xs_tuneinfo_new(const gchar * pcFilename,
-		gint nsubTunes, gint startTune, const gchar * sidName,
-		const gchar * sidComposer, const gchar * sidCopyright,
-		gint loadAddr, gint initAddr, gint playAddr,
-		gint dataFileLen, const gchar *sidFormat, gint sidModel)
-{
-	t_xs_tuneinfo *pResult;
-	t_xs_sldb_node *tmpLength;
-	gint i;
-
-	/* Allocate structure */
-	pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo));
-	if (!pResult) {
-		xs_error(_("Could not allocate memory for t_xs_tuneinfo ('%s')\n"),
-			pcFilename);
-		return NULL;
-	}
-
-	pResult->sidFilename = g_strdup(pcFilename);
-	if (!pResult->sidFilename) {
-		xs_error(_("Could not allocate sidFilename ('%s')\n"),
-			pcFilename);
-		g_free(pResult);
-		return NULL;
-	}
-
-	/* Allocate space for subtune information */
-	pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * (nsubTunes + 1));
-	if (!pResult->subTunes) {
-		xs_error(_("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n"),
-			pcFilename, nsubTunes);
-
-		g_free(pResult->sidFilename);
-		g_free(pResult);
-		return NULL;
-	}
-
-	/* The following allocations don't matter if they fail */
-	pResult->sidName = g_strdup(sidName);
-	pResult->sidComposer = g_strdup(sidComposer);
-	pResult->sidCopyright = g_strdup(sidCopyright);
-
-	pResult->nsubTunes = nsubTunes;
-	pResult->startTune = startTune;
-
-	pResult->loadAddr = loadAddr;
-	pResult->initAddr = initAddr;
-	pResult->playAddr = playAddr;
-	pResult->dataFileLen = dataFileLen;
-	pResult->sidFormat = g_strdup(sidFormat);
-	
-	pResult->sidModel = sidModel;
-
-	/* Get length information (NOTE: Do not free this!) */
-	tmpLength = xs_songlen_get(pcFilename);
-	
-	/* Fill in sub-tune information */
-	for (i = 0; i < pResult->nsubTunes; i++) {
-		if (tmpLength && (i < tmpLength->nLengths))
-			pResult->subTunes[i].tuneLength = tmpLength->sLengths[i];
-		else
-			pResult->subTunes[i].tuneLength = -1;
-		
-		pResult->subTunes[i].tuneSpeed = -1;
-	}
-	
-	return pResult;
-}
-
-
-/* Free given tune information structure
- */
-void xs_tuneinfo_free(t_xs_tuneinfo * pTune)
-{
-	if (!pTune) return;
-
-	g_free(pTune->subTunes);
-	g_free(pTune->sidFilename);
-	g_free(pTune->sidName);
-	g_free(pTune->sidComposer);
-	g_free(pTune->sidCopyright);
-	g_free(pTune->sidFormat);
-	g_free(pTune);
-}
-
-
-/* Song length database handling glue
- */
-gint xs_songlen_init(void)
-{
-	XS_MUTEX_LOCK(xs_cfg);
-
-	if (!xs_cfg.songlenDBPath) {
-		XS_MUTEX_UNLOCK(xs_cfg);
-		return -1;
-	}
-
-	XS_MUTEX_LOCK(xs_sldb_db);
-
-	/* Check if already initialized */
-	if (xs_sldb_db)
-		xs_sldb_free(xs_sldb_db);
-
-	/* Allocate database */
-	xs_sldb_db = (t_xs_sldb *) g_malloc0(sizeof(t_xs_sldb));
-	if (!xs_sldb_db) {
-		XS_MUTEX_UNLOCK(xs_cfg);
-		XS_MUTEX_UNLOCK(xs_sldb_db);
-		return -2;
-	}
-
-	/* Read the database */
-	if (xs_sldb_read(xs_sldb_db, xs_cfg.songlenDBPath) != 0) {
-		xs_sldb_free(xs_sldb_db);
-		xs_sldb_db = NULL;
-		XS_MUTEX_UNLOCK(xs_cfg);
-		XS_MUTEX_UNLOCK(xs_sldb_db);
-		return -3;
-	}
-
-	/* Create index */
-	if (xs_sldb_index(xs_sldb_db) != 0) {
-		xs_sldb_free(xs_sldb_db);
-		xs_sldb_db = NULL;
-		XS_MUTEX_UNLOCK(xs_cfg);
-		XS_MUTEX_UNLOCK(xs_sldb_db);
-		return -4;
-	}
-
-	XS_MUTEX_UNLOCK(xs_cfg);
-	XS_MUTEX_UNLOCK(xs_sldb_db);
-	return 0;
-}
-
-
-void xs_songlen_close(void)
-{
-	XS_MUTEX_LOCK(xs_sldb_db);
-	xs_sldb_free(xs_sldb_db);
-	xs_sldb_db = NULL;
-	XS_MUTEX_UNLOCK(xs_sldb_db);
-}
-
-
-t_xs_sldb_node *xs_songlen_get(const gchar * pcFilename)
-{
-	t_xs_sldb_node *pResult;
-
-	XS_MUTEX_LOCK(xs_sldb_db);
-
-	if (xs_cfg.songlenDBEnable && xs_sldb_db)
-		pResult = xs_sldb_get(xs_sldb_db, pcFilename);
-	else
-		pResult = NULL;
-
-	XS_MUTEX_UNLOCK(xs_sldb_db);
-
-	return pResult;
-}
--- a/src/xmms-sid.h	Mon Sep 03 00:21:05 2007 +0000
+++ b/src/xmms-sid.h	Mon Sep 03 00:22:04 2007 +0000
@@ -118,6 +118,13 @@
 #  define XS_MUTEX_UNLOCK(M)	pthread_mutex_unlock(&XS_MPP(M))
 #endif
 
+/* Character set conversion helper macros
+ */
+#define XS_CS_FILENAME(M)	g_strdup(M)
+#define XS_CS_SID(M)		g_strdup(M)
+#define XS_CS_STIL(M)		M
+#define XS_CS_FREE(M)
+
 /* Shorthands for linked lists
  */
 #define LPREV	(pNode->pPrev)
--- a/src/xs_fileinfo.c	Mon Sep 03 00:21:05 2007 +0000
+++ b/src/xs_fileinfo.c	Mon Sep 03 00:22:04 2007 +0000
@@ -26,14 +26,11 @@
 #include "xs_fileinfo.h"
 #include "xs_player.h"
 #include "xs_support.h"
-#include "xs_stil.h"
 #include "xs_config.h"
 #include "xs_interface.h"
 #include "xs_glade.h"
-
+#include "xs_slsup.h"
 
-static t_xs_stildb *xs_stildb_db = NULL;
-XS_MUTEX(xs_stildb_db);
 
 static GtkWidget *xs_fileinfowin = NULL;
 static t_xs_stil_node *xs_fileinfostil = NULL;
@@ -42,101 +39,7 @@
 #define LUW(x)	lookup_widget(xs_fileinfowin, x)
 
 
-/* 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;
-}
-
-
+#ifndef AUDACIOUS_PLUGIN
 void xs_fileinfo_update(void)
 {
 	XS_MUTEX_LOCK(xs_status);
@@ -189,6 +92,7 @@
 	XS_MUTEX_UNLOCK(xs_fileinfowin);
 	XS_MUTEX_UNLOCK(xs_status);
 }
+#endif /* AUDACIOUS_PLUGIN */
 
 
 void xs_fileinfo_ok(void)
@@ -354,5 +258,7 @@
 
 	XS_MUTEX_UNLOCK(xs_fileinfowin);
 
+#ifndef AUDACIOUS_PLUGIN
 	xs_fileinfo_update();
+#endif
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/xs_slsup.c	Mon Sep 03 00:22:04 2007 +0000
@@ -0,0 +1,287 @@
+/*
+   XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
+
+   File information window
+
+   Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
+   (C) Copyright 1999-2007 Tecnic Software productions (TNSP)
+
+   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.,
+   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include "xs_slsup.h"
+#include "xs_config.h"
+
+
+static t_xs_sldb *xs_sldb_db = NULL;
+XS_MUTEX(xs_sldb_db);
+
+static t_xs_stildb *xs_stildb_db = NULL;
+XS_MUTEX(xs_stildb_db);
+
+
+/* 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;
+
+		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;
+}
+
+
+/* Song length database handling glue
+ */
+gint xs_songlen_init(void)
+{
+	XS_MUTEX_LOCK(xs_cfg);
+
+	if (!xs_cfg.songlenDBPath) {
+		XS_MUTEX_UNLOCK(xs_cfg);
+		return -1;
+	}
+
+	XS_MUTEX_LOCK(xs_sldb_db);
+
+	/* Check if already initialized */
+	if (xs_sldb_db)
+		xs_sldb_free(xs_sldb_db);
+
+	/* Allocate database */
+	xs_sldb_db = (t_xs_sldb *) g_malloc0(sizeof(t_xs_sldb));
+	if (!xs_sldb_db) {
+		XS_MUTEX_UNLOCK(xs_cfg);
+		XS_MUTEX_UNLOCK(xs_sldb_db);
+		return -2;
+	}
+
+	/* Read the database */
+	if (xs_sldb_read(xs_sldb_db, xs_cfg.songlenDBPath) != 0) {
+		xs_sldb_free(xs_sldb_db);
+		xs_sldb_db = NULL;
+		XS_MUTEX_UNLOCK(xs_cfg);
+		XS_MUTEX_UNLOCK(xs_sldb_db);
+		return -3;
+	}
+
+	/* Create index */
+	if (xs_sldb_index(xs_sldb_db) != 0) {
+		xs_sldb_free(xs_sldb_db);
+		xs_sldb_db = NULL;
+		XS_MUTEX_UNLOCK(xs_cfg);
+		XS_MUTEX_UNLOCK(xs_sldb_db);
+		return -4;
+	}
+
+	XS_MUTEX_UNLOCK(xs_cfg);
+	XS_MUTEX_UNLOCK(xs_sldb_db);
+	return 0;
+}
+
+
+void xs_songlen_close(void)
+{
+	XS_MUTEX_LOCK(xs_sldb_db);
+	xs_sldb_free(xs_sldb_db);
+	xs_sldb_db = NULL;
+	XS_MUTEX_UNLOCK(xs_sldb_db);
+}
+
+
+t_xs_sldb_node *xs_songlen_get(const gchar * pcFilename)
+{
+	t_xs_sldb_node *pResult;
+
+	XS_MUTEX_LOCK(xs_sldb_db);
+
+	if (xs_cfg.songlenDBEnable && xs_sldb_db)
+		pResult = xs_sldb_get(xs_sldb_db, pcFilename);
+	else
+		pResult = NULL;
+
+	XS_MUTEX_UNLOCK(xs_sldb_db);
+
+	return pResult;
+}
+
+
+/* Allocate a new tune information structure
+ */
+t_xs_tuneinfo *xs_tuneinfo_new(const gchar * pcFilename,
+		gint nsubTunes, gint startTune, const gchar * sidName,
+		const gchar * sidComposer, const gchar * sidCopyright,
+		gint loadAddr, gint initAddr, gint playAddr,
+		gint dataFileLen, const gchar *sidFormat, gint sidModel)
+{
+	t_xs_tuneinfo *pResult;
+	t_xs_sldb_node *tmpLength;
+	gint i;
+
+	/* Allocate structure */
+	pResult = (t_xs_tuneinfo *) g_malloc0(sizeof(t_xs_tuneinfo));
+	if (!pResult) {
+		xs_error(_("Could not allocate memory for t_xs_tuneinfo ('%s')\n"),
+			pcFilename);
+		return NULL;
+	}
+
+	pResult->sidFilename = XS_CS_FILENAME(pcFilename);
+	if (!pResult->sidFilename) {
+		xs_error(_("Could not allocate sidFilename ('%s')\n"),
+			pcFilename);
+		g_free(pResult);
+		return NULL;
+	}
+
+	/* Allocate space for subtune information */
+	pResult->subTunes = g_malloc0(sizeof(t_xs_subtuneinfo) * (nsubTunes + 1));
+	if (!pResult->subTunes) {
+		xs_error(_("Could not allocate memory for t_xs_subtuneinfo ('%s', %i)\n"),
+			pcFilename, nsubTunes);
+
+		g_free(pResult->sidFilename);
+		g_free(pResult);
+		return NULL;
+	}
+
+	/* The following allocations don't matter if they fail */
+	pResult->sidName = XS_CS_SID(sidName);
+	pResult->sidComposer = XS_CS_SID(sidComposer);
+	pResult->sidCopyright = XS_CS_SID(sidCopyright);
+
+	pResult->nsubTunes = nsubTunes;
+	pResult->startTune = startTune;
+
+	pResult->loadAddr = loadAddr;
+	pResult->initAddr = initAddr;
+	pResult->playAddr = playAddr;
+	pResult->dataFileLen = dataFileLen;
+	pResult->sidFormat = XS_CS_SID(sidFormat);
+	
+	pResult->sidModel = sidModel;
+
+	/* Get length information (NOTE: Do not free this!) */
+	tmpLength = xs_songlen_get(pcFilename);
+	
+	/* Fill in sub-tune information */
+	for (i = 0; i < pResult->nsubTunes; i++) {
+		if (tmpLength && (i < tmpLength->nLengths))
+			pResult->subTunes[i].tuneLength = tmpLength->sLengths[i];
+		else
+			pResult->subTunes[i].tuneLength = -1;
+		
+		pResult->subTunes[i].tuneSpeed = -1;
+	}
+	
+	return pResult;
+}
+
+
+/* Free given tune information structure
+ */
+void xs_tuneinfo_free(t_xs_tuneinfo * pTune)
+{
+	if (!pTune) return;
+
+	g_free(pTune->subTunes);
+	g_free(pTune->sidFilename);
+	g_free(pTune->sidName);
+	g_free(pTune->sidComposer);
+	g_free(pTune->sidCopyright);
+	g_free(pTune->sidFormat);
+	g_free(pTune);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/xs_slsup.h	Mon Sep 03 00:22:04 2007 +0000
@@ -0,0 +1,24 @@
+#ifndef XS_SLSUP_H
+#define XS_SLSUP_H
+
+#include "xmms-sid.h"
+#include "xs_stil.h"
+#include "xs_length.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+gint		xs_stil_init(void);
+void		xs_stil_close(void);
+t_xs_stil_node *xs_stil_get(gchar *pcFilename);
+
+gint		xs_songlen_init(void);
+void		xs_songlen_close(void);
+t_xs_sldb_node *xs_songlen_get(const gchar *);
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* XS_SLSUP_H */
--- a/src/xs_stil.c	Mon Sep 03 00:21:05 2007 +0000
+++ b/src/xs_stil.c	Mon Sep 03 00:22:04 2007 +0000
@@ -182,6 +182,8 @@
 		xs_findeol(inLine, &eolPos);
 		inLine[eolPos] = 0;
 		lineNum++;
+		
+		tmpLine = XS_CS_STIL(inLine);
 
 		switch (tmpLine[0]) {
 		case '/':
@@ -296,6 +298,8 @@
 			}
 			break;
 		}
+		
+		XS_CS_FREE(tmpLine);
 
 	} /* while */