summaryrefslogtreecommitdiff
path: root/src/issuemem.c
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2010-05-19 17:15:41 +0100
committerNick White <git@njw.me.uk>2010-05-19 17:15:41 +0100
commite91ec0d87aa31cb465fe8cf934d405ad56342eba (patch)
tree1709e437c0d8f144bec479975a777c6ae8580eba /src/issuemem.c
parent6cf58b46037cf04915fa507813ab7419db2e45ec (diff)
Switched to simpler build system, and fixed bugs
Now there's a proper build system in place, which is actually simple enough to understand. I also fixed plenty of warnings about the code (reminding me how badly I knew C when I wrote this). Hinduism today aren't indexing their new issues using the index file I was sourcing any more, so I don't expect to fix any more bugs or improve this much.
Diffstat (limited to 'src/issuemem.c')
-rw-r--r--src/issuemem.c148
1 files changed, 0 insertions, 148 deletions
diff --git a/src/issuemem.c b/src/issuemem.c
deleted file mode 100644
index 354c7d9..0000000
--- a/src/issuemem.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright 2006,2008 Nick White
- *
- * This file is part of GetHT
- *
- * GetHT is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * GetHT is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GetHT. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "issue.h"
-
-void nogo_mem()
-/* called if memory assignation fails
- * TODO: handle freeing of memory to avoid leaks */
-{
- fprintf(stderr, "Could not assign memory, exitting\n");
- exit(1);
-}
-
-iss ** assignnew_iss(iss ** issue, int *no_of_issues)
-/* assign memory for new issue */
-{
- iss ** tmp = NULL;
-
- if(*no_of_issues < 0)
- { /* make issue** a new array of issue pointers */
- if( (tmp = malloc(sizeof(iss *))) == NULL )
- nogo_mem();
- }
- else
- { /* add a new pointer to issue pointer list */
- if( (tmp = realloc(issue, sizeof(iss *) + (((*no_of_issues)+1) * sizeof(iss *)))) == NULL )
- nogo_mem();
- }
-
- (*no_of_issues)++;
-
- /* make new array item a pointer to issue */
- if( (tmp[*no_of_issues] = malloc(sizeof(iss))) == NULL )
- nogo_mem();
-
- return tmp;
-}
-
-sec ** assignnew_sec(sec ** section, int *no_of_sections)
-/* assign memory for new section */
-{
- sec ** tmp = NULL;
-
- if(*no_of_sections < 0)
- { /* make **section a new array of section pointers */
- if( (tmp = malloc(sizeof(sec *))) == NULL )
- nogo_mem();
- }
- else
- { /* add a new pointer to section pointer list */
- if( (tmp = realloc(section, sizeof(sec *) + (((*no_of_sections)+1) * sizeof(sec *)))) == NULL )
- nogo_mem();
- }
-
- (*no_of_sections)++;
-
- /* make new array item a pointer to issue */
- if( (tmp[*no_of_sections] = malloc(sizeof(sec))) == NULL )
- nogo_mem();
-
- return tmp;
-}
-
-it ** assignnew_it(it ** item, int * no_of_items)
-{
- it ** tmp = NULL;
-
- if(*no_of_items < 0)
- { /* make **item a new array of item pointers */
- if( (tmp = malloc(sizeof(it *))) == NULL )
- nogo_mem();
- }
- else
- { /* add a new pointer to item pointer list */
- if( (tmp = realloc(item, sizeof(it *) + (((*no_of_items)+1) * sizeof(it *)))) == NULL )
- nogo_mem();
- }
-
- (*no_of_items)++;
-
- /* make new array item a pointer to item */
- if( (tmp[*no_of_items] = malloc(sizeof(it))) == 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;
-}