changeset 473:f1a997715ef5

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 25 Jan 2007 07:21:05 +0000
parents 3f02945a0c48
children 3fdc7238f208
files src/xs_fileinfo.c src/xs_stil.c src/xs_stil.h
diffstat 3 files changed, 26 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/xs_fileinfo.c	Thu Jan 25 05:58:05 2007 +0000
+++ b/src/xs_fileinfo.c	Thu Jan 25 07:21:05 2007 +0000
@@ -123,7 +123,7 @@
 		} else
 			tmpFilename = pcFilename;
 
-		XSDEBUG("xs_stil_get('%s') = '%s'\n", pcFilename, tmpFilename);
+XSDEBUG("xs_stil_get('%s') = '%s'\n", pcFilename, tmpFilename);
 		
 		pResult = xs_stildb_get_node(xs_stildb_db, tmpFilename);
 	} else
@@ -321,17 +321,18 @@
 	/* Other menu items */
 	for (n = 1; n <= tmpInfo->nsubTunes; n++) {
 		gchar tmpStr[64];
-		if (xs_fileinfostil && n <= xs_fileinfostil->nsubTunes) {
+		if (xs_fileinfostil && n <= xs_fileinfostil->nsubTunes && xs_fileinfostil->subTunes[n]) {
 			t_xs_stil_subnode *tmpNode = xs_fileinfostil->subTunes[n];
 			
 			g_snprintf(tmpStr, sizeof(tmpStr), _("Tune #%i: "), n);
 
-			if (tmpNode) {
-				if (tmpNode->pName)
-					xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pName);
-				else if (tmpNode->pInfo)
-					xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pInfo);
-			} else
+			if (tmpNode->pName)
+				xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pName);
+			else if (tmpNode->pTitle)
+				xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pTitle);
+			else if (tmpNode->pInfo)
+				xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pInfo);
+			else
 				xs_pnstrcat(tmpStr, sizeof(tmpStr), "---");
 		} else {
 			g_snprintf(tmpStr, sizeof(tmpStr), _("Tune #%i"), n);
--- a/src/xs_stil.c	Thu Jan 25 05:58:05 2007 +0000
+++ b/src/xs_stil.c	Thu Jan 25 07:21:05 2007 +0000
@@ -35,7 +35,7 @@
 	if (!pNode) return FALSE;
 
 	/* Re-allocate subTune structure if needed */
-	if (nsubTunes >= pNode->nsubTunes) {
+	if (nsubTunes > pNode->nsubTunes) {
 		pNode->subTunes =
 			(t_xs_stil_subnode **) g_realloc(pNode->subTunes,
 			(nsubTunes + 1) * sizeof(t_xs_stil_subnode **));
@@ -80,6 +80,7 @@
 				g_free(pSub->pName);
 				g_free(pSub->pAuthor);
 				g_free(pSub->pInfo);
+				g_free(pSub->pTitle);
 
 				g_free(pSub);
 			}
@@ -211,10 +212,11 @@
 			linePos++;
 			if (inLine[linePos] == '#') {
 				linePos++;
-				if (inLine[linePos]) {
+				if (isdigit(inLine[linePos])) {
+					size_t savePos = linePos;
 					xs_findnum(inLine, &linePos);
 					inLine[linePos] = 0;
-					subEntry = atol(&inLine[2]);
+					subEntry = atol(&inLine[savePos]);
 
 					/* Sanity check */
 					if (subEntry < 1) {
@@ -223,10 +225,15 @@
 							subEntry, tmpNode->pcFilename);
 						subEntry = 0;
 					}
+				} else {
+					XS_STILDB_ERR(lineNum, inLine,
+						"Syntax error, expected subEntry number.\n");
+					subEntry = 0;
 				}
 			} else {
 				XS_STILDB_ERR(lineNum, inLine,
-					"Syntax error, expected subEntry number.\n");
+					"Syntax error, expected '#' before subEntry number.\n");
+				subEntry = 0;
 			}
 
 			break;
@@ -260,18 +267,18 @@
 			}
 			
 			/* Some other type */
-			if (strncmp(inLine, "   NAME:", 8) == 0) {
+			if (strncmp(inLine, " NAME:", 8) == 0) {
 				XS_STILDB_MULTI;
 				g_free(tmpNode->subTunes[subEntry]->pName);
 				tmpNode->subTunes[subEntry]->pName = g_strdup(&inLine[9]);
+			} else if (strncmp(inLine, "  TITLE:", 8) == 0) {
+				XS_STILDB_MULTI;
+				g_free(tmpNode->subTunes[subEntry]->pTitle);
+				tmpNode->subTunes[subEntry]->pTitle = g_strdup(&inLine[9]);
 			} else if (strncmp(inLine, " AUTHOR:", 8) == 0) {
 				XS_STILDB_MULTI;
 				g_free(tmpNode->subTunes[subEntry]->pAuthor);
 				tmpNode->subTunes[subEntry]->pAuthor = g_strdup(&inLine[9]);
-			} else if (strncmp(inLine, "  TITLE:", 8) == 0) {
-				XS_STILDB_MULTI;
-				isMulti = TRUE;
-				xs_pstrcat(&(tmpNode->subTunes[subEntry]->pInfo), &inLine[2]);
 			} else if (strncmp(inLine, " ARTIST:", 8) == 0) {
 				XS_STILDB_MULTI;
 				isMulti = TRUE;
--- a/src/xs_stil.h	Thu Jan 25 05:58:05 2007 +0000
+++ b/src/xs_stil.h	Thu Jan 25 07:21:05 2007 +0000
@@ -13,6 +13,7 @@
 typedef struct {
 	gchar	*pName,
 		*pAuthor,
+		*pTitle,
 		*pInfo;
 } t_xs_stil_subnode;