changeset 891:5048b4799310

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 09 Nov 2012 06:39:43 +0200
parents 62d164e3f0ce
children f1b33b5e153d
files src/xs_slsup.c
diffstat 1 files changed, 69 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/src/xs_slsup.c	Fri Nov 09 06:20:48 2012 +0200
+++ b/src/xs_slsup.c	Fri Nov 09 06:39:43 2012 +0200
@@ -35,9 +35,11 @@
  */
 gint xs_stil_init(void)
 {
+    gint res = 0;
     XS_MUTEX_LOCK(xs_cfg);
 
-    if (!xs_cfg.stilDBPath) {
+    if (xs_cfg.stilDBPath == NULL)
+    {
         XS_MUTEX_UNLOCK(xs_cfg);
         return -1;
     }
@@ -50,33 +52,36 @@
 
     /* Allocate database */
     xs_stildb_db = (XSSTILDB *) g_malloc0(sizeof(XSSTILDB));
-    if (!xs_stildb_db) {
-        XS_MUTEX_UNLOCK(xs_cfg);
-        XS_MUTEX_UNLOCK(xs_stildb_db);
-        return -2;
+    if (xs_stildb_db == NULL)
+    {
+        res = -2;
+        goto error;
     }
 
     /* 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;
+    if (xs_stildb_read(xs_stildb_db, xs_cfg.stilDBPath) != 0)
+    {
+        res = -3;
+        goto error;
     }
 
     /* 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;
+    if (xs_stildb_index(xs_stildb_db) != 0)
+    {
+        res = -4;
+        goto error;
     }
 
     XS_MUTEX_UNLOCK(xs_cfg);
     XS_MUTEX_UNLOCK(xs_stildb_db);
     return 0;
+
+error:
+    xs_stildb_free(xs_stildb_db);
+    xs_stildb_db = NULL;
+    XS_MUTEX_UNLOCK(xs_cfg);
+    XS_MUTEX_UNLOCK(xs_stildb_db);
+    return res;
 }
 
 
@@ -92,13 +97,16 @@
 XSSTILNode *xs_stil_get(gchar *filename)
 {
     XSSTILNode *result;
-    gchar *tmpFilename;
 
     XS_MUTEX_LOCK(xs_stildb_db);
     XS_MUTEX_LOCK(xs_cfg);
 
-    if (xs_cfg.stilDBEnable && xs_stildb_db) {
-        if (xs_cfg.hvscPath) {
+    if (xs_cfg.stilDBEnable && xs_stildb_db != NULL)
+    {
+        gchar *tmpFilename;
+
+        if (xs_cfg.hvscPath != NULL)
+        {
             /* Remove postfixed directory separator from HVSC-path */
             tmpFilename = strrchr(xs_cfg.hvscPath, '/');
             if (tmpFilename && tmpFilename[1] == 0)
@@ -106,15 +114,17 @@
 
             /* Remove HVSC location-prefix from filename */
             tmpFilename = strstr(filename, xs_cfg.hvscPath);
-            if (tmpFilename)
+            if (tmpFilename != NULL)
                 tmpFilename += strlen(xs_cfg.hvscPath);
             else
                 tmpFilename = filename;
-        } else
+        }
+        else
             tmpFilename = filename;
 
         result = xs_stildb_get_node(xs_stildb_db, tmpFilename);
-    } else
+    }
+    else
         result = NULL;
 
     XS_MUTEX_UNLOCK(xs_stildb_db);
@@ -128,9 +138,11 @@
  */
 gint xs_songlen_init(void)
 {
-    XS_MUTEX_LOCK(xs_cfg);
+    gint res = 0;
 
-    if (!xs_cfg.songlenDBPath) {
+    XS_MUTEX_LOCK(xs_cfg);
+    if (xs_cfg.songlenDBPath == NULL)
+    {
         XS_MUTEX_UNLOCK(xs_cfg);
         return -1;
     }
@@ -138,38 +150,41 @@
     XS_MUTEX_LOCK(xs_sldb_db);
 
     /* Check if already initialized */
-    if (xs_sldb_db)
+    if (xs_sldb_db != NULL)
         xs_sldb_free(xs_sldb_db);
 
     /* Allocate database */
     xs_sldb_db = (XSSLDB *) g_malloc0(sizeof(XSSLDB));
-    if (!xs_sldb_db) {
-        XS_MUTEX_UNLOCK(xs_cfg);
-        XS_MUTEX_UNLOCK(xs_sldb_db);
-        return -2;
+    if (xs_sldb_db == NULL)
+    {
+        res = -1;
+        goto error;
     }
 
     /* 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;
+    if (xs_sldb_read(xs_sldb_db, xs_cfg.songlenDBPath) != 0)
+    {
+        res = -3;
+        goto error;
     }
 
     /* 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;
+    if (xs_sldb_index(xs_sldb_db) != 0)
+    {
+        res = -4;
+        goto error;
     }
 
     XS_MUTEX_UNLOCK(xs_cfg);
     XS_MUTEX_UNLOCK(xs_sldb_db);
     return 0;
+
+error:
+    xs_sldb_free(xs_sldb_db);
+    xs_sldb_db = NULL;
+    XS_MUTEX_UNLOCK(xs_cfg);
+    XS_MUTEX_UNLOCK(xs_sldb_db);
+    return res;
 }
 
 
@@ -213,14 +228,15 @@
 
     /* Allocate structure */
     result = (XSTuneInfo *) g_malloc0(sizeof(XSTuneInfo));
-    if (!result) {
+    if (result == NULL)
+    {
         xs_error("Could not allocate memory for tuneinfo ('%s')\n",
             filename);
         return NULL;
     }
 
-    result->sidFilename = XS_CS_FILENAME(filename);
-    if (!result->sidFilename) {
+    if ((result->sidFilename = XS_CS_FILENAME(filename)) == NULL)
+    {
         xs_error("Could not allocate sidFilename ('%s')\n",
             filename);
         g_free(result);
@@ -229,7 +245,8 @@
 
     /* Allocate space for subtune information */
     result->subTunes = g_malloc0(sizeof(XSSubTuneInfo) * (nsubTunes + 1));
-    if (!result->subTunes) {
+    if (!result->subTunes)
+    {
         xs_error("Could not allocate memory for subtuneinfo ('%s', %i)\n",
             filename, nsubTunes);
 
@@ -258,12 +275,10 @@
     tmpLength = xs_songlen_get(filename);
     
     /* Fill in sub-tune information */
-    for (i = 0; i < result->nsubTunes; i++) {
-        if (tmpLength && (i < tmpLength->nlengths))
-            result->subTunes[i].tuneLength = tmpLength->lengths[i];
-        else
-            result->subTunes[i].tuneLength = -1;
-        
+    for (i = 0; i < result->nsubTunes; i++)
+    {
+        result->subTunes[i].tuneLength =
+            (tmpLength && (i < tmpLength->nlengths)) ? tmpLength->lengths[i] : -1;
         result->subTunes[i].tuneSpeed = -1;
     }
     
@@ -275,7 +290,8 @@
  */
 void xs_tuneinfo_free(XSTuneInfo * tune)
 {
-    if (!tune) return;
+    if (tune == NULL)
+        return;
 
     g_free(tune->subTunes);
     g_free(tune->sidFilename);