summaryrefslogtreecommitdiff
path: root/issuemem.c
diff options
context:
space:
mode:
authorNick White <arch@njw.me.uk>2007-04-30 08:34:43 +0000
committerNick White <arch@njw.me.uk>2007-04-30 08:34:43 +0000
commit1edf37e3b0ad7b0556ba0902b5880044933ced66 (patch)
tree13447080a2c59a6345fa26301e365fcbb7b8ad4d /issuemem.c
parent1f0a1fd57bd1dbddab4ad189a721fbe67f59ca3a (diff)
Removed last of static issue array code, added sorting
Removed defined constants from issue.h previously used to determine size of static arrays Removed unused separate show media structure function Remove clean media & clean issue functions Added issue sorting code git-archimport-id: getht@sv.gnu.org/getht--mainline--0.1--patch-22
Diffstat (limited to 'issuemem.c')
-rw-r--r--issuemem.c73
1 files changed, 70 insertions, 3 deletions
diff --git a/issuemem.c b/issuemem.c
index f915de7..3a40d7e 100644
--- a/issuemem.c
+++ b/issuemem.c
@@ -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;
+}