From 1f0a1fd57bd1dbddab4ad189a721fbe67f59ca3a Mon Sep 17 00:00:00 2001 From: Nick White Date: Sun, 29 Apr 2007 13:07:45 +0000 Subject: Completed issue malloc, fixed build warnings Used malloc to dynamically assign enough memory for sections, items, and media, using the functionality of issuemem.c Included some function definitions in issue.h to remove various build warnings git-archimport-id: getht@sv.gnu.org/getht--mainline--0.1--patch-21 --- mediaxml.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'mediaxml.c') diff --git a/mediaxml.c b/mediaxml.c index 54dd514..a86386a 100644 --- a/mediaxml.c +++ b/mediaxml.c @@ -165,7 +165,7 @@ iss ** parsemedia(char * filepath, iss ** issue, int * no_of_issues) if(!issue_there) { /* advance to the next free issue */ - iss ** tmpiss; + iss ** tmpiss = NULL; if(*no_of_issues == -1) { /* make issue** a new array of issue pointers */ if( (tmpiss = malloc(sizeof(iss *))) == NULL ) @@ -194,9 +194,11 @@ iss ** parsemedia(char * filepath, iss ** issue, int * no_of_issues) tmp = *no_of_issues; } + iss * cur_issue = issue[tmp]; + issue[tmp]->no_of_media = -1; - cur_media = issue[tmp]->media; + med ** tmpmed = NULL; itnode = node->xmlChildrenNode; @@ -205,6 +207,31 @@ iss ** parsemedia(char * filepath, iss ** issue, int * no_of_issues) if(!xmlStrcmp(itnode->name,(char *) "item")) { + /* assign memory for new media */ + if(cur_issue->no_of_media < 0) + { /* make **section a new array of section pointers */ + if( (tmpmed = malloc(sizeof(med *))) == NULL ) + nogo_mem(); + } + else + { /* add a new pointer to media pointer list */ + if( (tmpmed = realloc(cur_issue->media, sizeof(med *) + ((cur_issue->no_of_media+1) * sizeof(med *)))) == NULL ) + nogo_mem(); + } + + cur_issue->no_of_media++; + + /* make new array item a pointer to issue */ + if( (tmpmed[cur_issue->no_of_media] = malloc(sizeof(med))) == NULL ) + nogo_mem(); + + cur_issue->media = tmpmed; + /* memory for seoction all dealt with */ + + cur_media = cur_issue->media[cur_issue->no_of_media]; + + clearmed(cur_media); + /* add media info to cur_media */ if(xmlGetProp(itnode, "uri")) strncpy(cur_media->uri, (char *) xmlGetProp(itnode, "uri"), STR_MAX); @@ -216,10 +243,6 @@ iss ** parsemedia(char * filepath, iss ** issue, int * no_of_issues) strncpy(cur_media->preview_uri, (char *) xmlGetProp(itnode, "preview_uri"), STR_MAX); strncpy(cur_media->title, (char *) xmlNodeListGetString(media_file, itnode->xmlChildrenNode, 1), STR_MAX); - - issue[tmp]->no_of_media++; - - cur_media++; } itnode = itnode->next; -- cgit v1.2.3