comparison src/xs_stil.c @ 402:f997b79a7251

More work on merging of improved STIL/SLDB handling code with completely dynamic memory allocation.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 01 Jun 2006 02:18:02 +0000
parents b571000e1f8c
children 7f694e5a1493
comparison
equal deleted inserted replaced
401:30da794755f7 402:f997b79a7251
39 if (nsubTunes >= pNode->nsubTunes) { 39 if (nsubTunes >= pNode->nsubTunes) {
40 pNode->subTunes = 40 pNode->subTunes =
41 (t_xs_stil_subnode **) g_realloc(pNode->subTunes, 41 (t_xs_stil_subnode **) g_realloc(pNode->subTunes,
42 (nsubTunes + 1) * sizeof(t_xs_stil_subnode **)); 42 (nsubTunes + 1) * sizeof(t_xs_stil_subnode **));
43 43
44 if (!pNode->subTunes) 44 if (!pNode->subTunes) {
45 xs_error("SubTune pointer structure realloc failed.\n");
45 return FALSE; 46 return FALSE;
47 }
46 48
47 /* Clear the newly allocated memory */ 49 /* Clear the newly allocated memory */
48 xs_memset(&(pNode->subTunes[pNode->nsubTunes]), 0, 50 xs_memset(&(pNode->subTunes[pNode->nsubTunes]), 0,
49 (nsubTunes + 1 - pNode->nsubTunes) * 51 (nsubTunes + 1 - pNode->nsubTunes) *
50 sizeof(t_xs_stil_subnode **)); 52 sizeof(t_xs_stil_subnode **));
51 } 53
52 54 pNode->nsubTunes = nsubTunes + 1;
55 }
56
53 /* Allocate memory for subTune */ 57 /* Allocate memory for subTune */
54 if (!pNode->subTunes[nsubTunes]) { 58 if (!pNode->subTunes[nsubTunes]) {
55 pNode->subTunes[nsubTunes] = (t_xs_stil_subnode *) 59 pNode->subTunes[nsubTunes] = (t_xs_stil_subnode *)
56 g_malloc0(sizeof(t_xs_stil_subnode)); 60 g_malloc0(sizeof(t_xs_stil_subnode));
57 61
58 if (!pNode->subTunes[nsubTunes]) 62 if (!pNode->subTunes[nsubTunes]) {
63 xs_error("SubTune structure malloc failed!\n");
59 return FALSE; 64 return FALSE;
65 }
60 } 66 }
61 67
62 return TRUE; 68 return TRUE;
63 } 69 }
64 70
245 XS_STILDB_ERR(lineNum, inLine, 251 XS_STILDB_ERR(lineNum, inLine,
246 "Entry data encountered outside of entry or syntax error!\n"); 252 "Entry data encountered outside of entry or syntax error!\n");
247 break; 253 break;
248 } 254 }
249 255
250 if (xs_stildb_node_realloc(tmpNode, subEntry)) { 256 if (!xs_stildb_node_realloc(tmpNode, subEntry)) {
251 XS_STILDB_ERR(lineNum, inLine, 257 XS_STILDB_ERR(lineNum, inLine,
252 "Could not (re)allocate memory for subEntries!\n"); 258 "Could not (re)allocate memory for subEntries!\n");
253 isError = TRUE; 259 isError = TRUE;
254 break; 260 break;
255 } 261 }
263 XS_STILDB_MULTI; 269 XS_STILDB_MULTI;
264 g_free(tmpNode->subTunes[subEntry]->pAuthor); 270 g_free(tmpNode->subTunes[subEntry]->pAuthor);
265 tmpNode->subTunes[subEntry]->pAuthor = g_strdup(&inLine[9]); 271 tmpNode->subTunes[subEntry]->pAuthor = g_strdup(&inLine[9]);
266 } else if (strncmp(inLine, " TITLE:", 8) == 0) { 272 } else if (strncmp(inLine, " TITLE:", 8) == 0) {
267 XS_STILDB_MULTI; 273 XS_STILDB_MULTI;
268 inLine[eolPos++] = '\n'; 274 isMulti = TRUE;
269 inLine[eolPos++] = 0;
270 xs_pstrcat(&(tmpNode->subTunes[subEntry]->pInfo), &inLine[2]); 275 xs_pstrcat(&(tmpNode->subTunes[subEntry]->pInfo), &inLine[2]);
271 } else if (strncmp(inLine, " ARTIST:", 8) == 0) { 276 } else if (strncmp(inLine, " ARTIST:", 8) == 0) {
272 XS_STILDB_MULTI; 277 XS_STILDB_MULTI;
273 inLine[eolPos++] = '\n'; 278 isMulti = TRUE;
274 inLine[eolPos++] = 0;
275 xs_pstrcat(&(tmpNode->subTunes[subEntry]->pInfo), &inLine[1]); 279 xs_pstrcat(&(tmpNode->subTunes[subEntry]->pInfo), &inLine[1]);
276 } else if (strncmp(inLine, "COMMENT:", 8) == 0) { 280 } else if (strncmp(inLine, "COMMENT:", 8) == 0) {
277 XS_STILDB_MULTI; 281 XS_STILDB_MULTI;
278 isMulti = TRUE; 282 isMulti = TRUE;
279 xs_pstrcat(&(tmpNode->subTunes[subEntry]->pInfo), inLine); 283 xs_pstrcat(&(tmpNode->subTunes[subEntry]->pInfo), inLine);