diff options
author | Nick White <arch@njw.me.uk> | 2007-04-29 13:07:45 +0000 |
---|---|---|
committer | Nick White <arch@njw.me.uk> | 2007-04-29 13:07:45 +0000 |
commit | 1f0a1fd57bd1dbddab4ad189a721fbe67f59ca3a (patch) | |
tree | 0e923adfe47783a5329f8871fdbb2245bca7f261 /mediaxml.c | |
parent | e2296304a88112cad84482e0a06b2504e51a3b21 (diff) |
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
Diffstat (limited to 'mediaxml.c')
-rw-r--r-- | mediaxml.c | 35 |
1 files changed, 29 insertions, 6 deletions
@@ -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; |