diff options
-rw-r--r-- | getht.c | 81 | ||||
-rw-r--r-- | issue.h | 13 | ||||
-rw-r--r-- | issuemem.c | 73 | ||||
-rw-r--r-- | mediarev.c | 29 | ||||
-rw-r--r-- | mediaxml.c | 52 | ||||
-rw-r--r-- | tocxml.c | 9 |
6 files changed, 126 insertions, 131 deletions
@@ -36,10 +36,6 @@ int update_contents_files(); med * findnewestmed(iss ** issue, int no_of_issues); void show_iss_struct(iss ** issue, int no_of_issues); -void show_med_struct(med * issue); - -void clearmed(med * cur_media); -void cleariss(iss * cur_issue); void showusage(); @@ -297,20 +293,10 @@ int update_contents_files() if(save_file(NULL, MEDIA_TOC_URL, media_rev)) return 1; - med temp_med[MED_NO]; - - clearmed(temp_med); - /* BUG: for no good reason, this resets title[] too... - * Until we can find why, just get the title again */ - - cur_identifiers(issue_xml, isstitle, &date); - + med ** temp_med; int med_no = -1; - if(parsemediagz(media_rev, temp_med, &med_no)) - return 1; - /* BUG: this blanks title too... strange - * Until we can find why, just get the title again */ - cur_identifiers(issue_xml, isstitle, &date); + + temp_med = parsemediagz(media_rev, &med_no); unlink(media_rev); @@ -325,7 +311,7 @@ void show_iss_struct(iss ** issue, int no_of_issues) { int iss_no, sec_no, med_no, it_no; printf("%i Issues\n",no_of_issues); - for(iss_no=0;iss_no<no_of_issues;iss_no++) + for(iss_no=0;iss_no<=no_of_issues;iss_no++) { printf("-Issue %i-\n", (iss_no+1)); printf("Title:\t'%s'\n", issue[iss_no]->title); @@ -366,65 +352,6 @@ void show_iss_struct(iss ** issue, int no_of_issues) } } -void show_med_struct(med * cur_media) -/* Prints media information */ -{ - int tmp; - for(tmp=0;tmp<MED_NO;cur_media++,tmp++) - { - printf("--Media item--\n"); - - printf("uri: '%s'\n", cur_media->uri); - printf("title: '%s'\n", cur_media->title); - printf("comment: '%s'\n", cur_media->comment); - printf("preview_uri: '%s'\n", cur_media->preview_uri); - printf("size: '%i'\n", cur_media->size); - - printf("\n"); - } -} - -void cleariss(iss * cur_issue) -/* turns off exist flags for all issue structures */ -{ - int tmp; - for(tmp=0; tmp<MAX_ISS; cur_issue++,tmp++) - { - cur_issue->preview_uri[0] = '\0'; - cur_issue->title[0] = '\0'; - cur_issue->size = 0; - cur_issue->no_of_sections = -1; - cur_issue->section = NULL; - cur_issue->no_of_media = -1; - cur_issue->media = NULL; - //clearmed(cur_issue->media); - } -} - -void clearmed(med * cur_media) -/* clears the members of a media array */ -{ - cur_media->uri[0] = '\0'; - cur_media->title[0] = '\0'; - cur_media->comment[0] = '\0'; - cur_media->preview_uri[0] = '\0'; - cur_media->size = 0; -} - -void clearsec(sec * cur_section) -/* clears all members of section arrays */ -{ - int tmp; - for(tmp=0; tmp<=SEC_NO; cur_section++,tmp++) - { - cur_section->uri[0] = '\0'; - cur_section->title[0] = '\0'; - cur_section->size = 0; - cur_section->number = 0; - cur_section->no_of_items = 0; - } -} - int findnewestiss(iss ** issue, int no_of_issues) /* returns newest issue indice */ { @@ -19,10 +19,6 @@ * */ -#define SEC_NO 5 -#define ITEM_NO 30 -#define MED_NO 2 - /* all sizes are in bytes and are child-inclusive */ typedef struct @@ -73,6 +69,9 @@ typedef struct iss ** parsetoc(char *filepath, int * iss_no, int * latest); iss ** parsemedia(char * filepath, iss ** issue, int * no_of_issues); -iss ** assignnew_iss(int *no_of_issues, iss ** issue); -sec ** assignnew_sec(int *no_of_sections, sec ** section); -it ** assignnew_it(int * no_of_items, it ** item); +med ** parsemediagz(char * media_path, int * no_of_media); + +iss ** assignnew_iss(iss ** issue, int *no_of_issues); +sec ** assignnew_sec(sec ** section, int * no_of_sections); +it ** assignnew_it(it ** item, int * no_of_items); +med ** assignnew_med(med ** media, int * no_of_media); @@ -21,6 +21,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "issue.h" @@ -32,7 +33,7 @@ void nogo_mem() exit(1); } -iss ** assignnew_iss(int *no_of_issues, iss ** issue) +iss ** assignnew_iss(iss ** issue, int *no_of_issues) /* assign memory for new issue */ { iss ** tmp = NULL; @@ -57,7 +58,7 @@ iss ** assignnew_iss(int *no_of_issues, iss ** issue) return tmp; } -sec ** assignnew_sec(int *no_of_sections, sec ** section) +sec ** assignnew_sec(sec ** section, int *no_of_sections) /* assign memory for new section */ { sec ** tmp = NULL; @@ -82,7 +83,7 @@ sec ** assignnew_sec(int *no_of_sections, sec ** section) return tmp; } -it ** assignnew_it(int * no_of_items, it ** item) +it ** assignnew_it(it ** item, int * no_of_items) { it ** tmp = NULL; @@ -105,3 +106,69 @@ it ** assignnew_it(int * no_of_items, it ** item) return tmp; } + +med ** assignnew_med(med ** media, int * no_of_media) +{ + med ** tmp = NULL; + + if(*no_of_media < 0) + { /* make **section a new array of section pointers */ + if( (tmp = malloc(sizeof(med *))) == NULL ) + nogo_mem(); + } + else + { /* add a new pointer to media pointer list */ + if( (tmp = realloc(media, sizeof(med *) + (((*no_of_media)+1) * sizeof(med *)))) == NULL ) + nogo_mem(); + } + + (*no_of_media)++; + + /* make new array item a pointer to issue */ + if( (tmp[*no_of_media] = malloc(sizeof(med))) == NULL ) + nogo_mem(); + + return tmp; +} + +int issuesort(iss ** issue, int no_of_issues) +/* does a basic bubble sort, by date, returning sorted issue */ +{ + int sortindex[no_of_issues]; + + int count1, count2, temp; + + for(count1 = 0; count1 <= no_of_issues; count1++) + sortindex[count1] = count1; + + /* find correct order of issues using a bubble sort */ + for(count1 = 0; count1 <=no_of_issues; count1++) + { + for(count2 = 0; count2 < no_of_issues; count2++) + { + if(issue[sortindex[count2]]->date.year < issue[sortindex[count2+1]]->date.year) + { + temp = sortindex[count2]; + sortindex[count2] = sortindex[count2+1]; + sortindex[count2+1] = temp; + } + else if((issue[sortindex[count2]]->date.year == issue[sortindex[count2+1]]->date.year) && + (issue[sortindex[count2]]->date.firstmonth < issue[sortindex[count2+1]]->date.firstmonth)) + { + temp = sortindex[count2]; + sortindex[count2] = sortindex[count2+1]; + sortindex[count2+1] = temp; + } + } + } + + iss * sortedissue[no_of_issues]; + + for(count1 = 0; count1 <= no_of_issues; count1++) + sortedissue[count1] = issue[sortindex[count1]]; + + for(count1 = 0; count1 <= no_of_issues; count1++) + issue[count1] = sortedissue[count1]; + + return 0; +} @@ -30,17 +30,21 @@ int smilurl(char * smilurl, med * cur_media); void getquote(char * input, char * label); void removeleadingspace(char * cur_line); -int parsemediagz(char * media_path, med * cur_media, int * no_of_media) +med ** parsemediagz(char * media_path, int * no_of_media) /* Parses gzipped adobe pagemaker files for media urls and metadata, - * filling cur_media with the information. */ + * filling media with the information. */ { char cur_line[STR_MAX]; gzFile mediagz; + med ** media = NULL; + strcpy(cur_line,""); /* reset cur_line */ mediagz = gzopen(media_path, "r"); + med * cur_media; + while(gzeof(mediagz)==0) { gzgets(mediagz, cur_line, STR_MAX); @@ -49,6 +53,20 @@ int parsemediagz(char * media_path, med * cur_media, int * no_of_media) if(!strcmp(cur_line,"on mouseUp")) { strcpy(cur_line,""); /* reset cur_line */ + + /* assign memory for the new media */ + media = assignnew_med(media, no_of_media); + + cur_media = media[*no_of_media]; + + /* setup media globals */ + cur_media->uri[0] = '\0'; + cur_media->title[0] = '\0'; + cur_media->comment[0] = '\0'; + cur_media->preview_uri[0] = '\0'; + cur_media->size = 0; + + /* process rev file */ while(strcmp(cur_line,"end mouseUp") && gzeof(mediagz)==0) { strcpy(cur_line,""); /* reset cur_line */ @@ -72,16 +90,11 @@ int parsemediagz(char * media_path, med * cur_media, int * no_of_media) getquote(cur_line,cur_media->comment); } } - *cur_media++; - (*no_of_media)++; } strcpy(cur_line,""); /* reset cur_line */ } - if(*no_of_media == -1) - return 1; - - return 0; + return media; } int smilurl(char * smilurl, med * cur_media) @@ -66,7 +66,7 @@ int media_accounted_for(char * filepath, issdates * date) return found; } -int addmediaissue(char * filepath, char * title, issdates * date, med * media, int med_no) +int addmediaissue(char * filepath, char * title, issdates * date, med ** media, int med_no) /* Appends data from media structures to xml file. */ { xmlDocPtr media_file; @@ -99,17 +99,18 @@ int addmediaissue(char * filepath, char * title, issdates * date, med * media, i xmlNewProp(curissue, "lastmonth", tmp); xmlNodePtr curitem; - int i; - for(i = 0; i <= med_no; i++) + + int count; + for(count = 0; count <= med_no; count++) { - curitem = xmlNewTextChild(curissue, NULL, "item", media[i].title); + curitem = xmlNewTextChild(curissue, NULL, "item", media[count]->title); - xmlNewProp(curitem, "uri", media[i].uri); + xmlNewProp(curitem, "uri", media[count]->uri); - if(media[i].comment) - xmlNewProp(curitem, "comment", media[i].comment); - if(media[i].preview_uri) - xmlNewProp(curitem, "preview_uri", media[i].preview_uri); + if(media[count]->comment) + xmlNewProp(curitem, "comment", media[count]->comment); + if(media[count]->preview_uri) + xmlNewProp(curitem, "preview_uri", media[count]->preview_uri); } xmlKeepBlanksDefault(0); @@ -198,8 +199,6 @@ iss ** parsemedia(char * filepath, iss ** issue, int * no_of_issues) issue[tmp]->no_of_media = -1; - med ** tmpmed = NULL; - itnode = node->xmlChildrenNode; while (itnode != NULL) @@ -207,30 +206,17 @@ 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 */ + /* assign memory for the new media */ + cur_issue->media = assignnew_med(cur_issue->media, &(cur_issue->no_of_media)); + /* setup media globals */ cur_media = cur_issue->media[cur_issue->no_of_media]; - clearmed(cur_media); + cur_media->uri[0] = '\0'; + cur_media->title[0] = '\0'; + cur_media->comment[0] = '\0'; + cur_media->preview_uri[0] = '\0'; + cur_media->size = 0; /* add media info to cur_media */ if(xmlGetProp(itnode, "uri")) @@ -254,5 +240,7 @@ iss ** parsemedia(char * filepath, iss ** issue, int * no_of_issues) xmlFreeDoc(media_file); + issuesort(issue, no_of_issues); + return issue; } @@ -50,7 +50,6 @@ iss ** parsetoc(char *filepath, int * iss_no, int * latest) no_of_issues = -1; iss ** issue = NULL; - //iss ** tmp = NULL; int year; @@ -66,7 +65,7 @@ iss ** parsetoc(char *filepath, int * iss_no, int * latest) if(!xmlStrncmp(cnode->name,(char *) "issue",5)) { /* assign memory for the new issue */ - issue = assignnew_iss(&no_of_issues, issue); + issue = assignnew_iss(issue, &no_of_issues); /* setup issue globals */ issue[no_of_issues]->no_of_media = -1; @@ -91,6 +90,8 @@ iss ** parsetoc(char *filepath, int * iss_no, int * latest) *iss_no = no_of_issues; + issuesort(issue, no_of_issues); + return issue; } @@ -111,7 +112,7 @@ int parseissue(xmlDocPtr file, xmlNodePtr node, iss * cur_issue, int * latest) { /* assign memory for new section */ cur_issue->section = - assignnew_sec(&(cur_issue->no_of_sections), cur_issue->section); + assignnew_sec(cur_issue->section, &(cur_issue->no_of_sections)); /* setup section globals */ cur_issue->section[cur_issue->no_of_sections]->no_of_items = -1; @@ -153,7 +154,7 @@ void parsesection(xmlDocPtr file, xmlNodePtr node, sec * cur_section) { /* assign memory for new item */ cur_section->item = - assignnew_it( &(cur_section->no_of_items), cur_section->item); + assignnew_it( cur_section->item, &(cur_section->no_of_items)); cur_item = cur_section->item[cur_section->no_of_items]; |