Commit 73c53211 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

General cleanup. Many unused functions deleted. Some functions

changed name.
parent 48efc9de
......@@ -10,64 +10,13 @@
#include "memory.h"
#include "exp.h"
#include "lyskomd.h"
#include "log.h"
static int text_list_cnt = 0;
static int mark_list_cnt = 0;
static int membership_list_cnt = 0;
static int membership_cnt = 0;
static int person_cnt = 0;
static int member_list_cnt = 0;
static int conference_cnt = 0;
static int text_stat_cnt = 0;
EXPORT Text_list *
alloc_text_list(void)
{
Text_list *t;
text_list_cnt++;
t = smalloc(sizeof(Text_list));
*t = EMPTY_TEXT_LIST;
return t;
}
EXPORT Mark_list *
alloc_mark_list(void)
{
Mark_list *m;
mark_list_cnt++;
m = smalloc(sizeof(Mark_list));
*m = EMPTY_MARK_LIST;
return m;
}
EXPORT Membership_list *
alloc_membership_list(void)
{
Membership_list *m;
membership_list_cnt++;
m = smalloc(sizeof(Membership_list));
*m = EMPTY_MEMBERSHIP_LIST;
return m;
}
EXPORT Membership *
alloc_membership(void)
{
Membership *m;
membership_cnt++;
m = smalloc(sizeof(Membership));
*m = EMPTY_MEMBERSHIP;
return m;
}
EXPORT Person *
alloc_person(void)
......@@ -81,18 +30,6 @@ alloc_person(void)
return p;
}
EXPORT Member_list *
alloc_member_list(void)
{
Member_list *m;
member_list_cnt++;
m = smalloc(sizeof(Member_list));
*m = EMPTY_MEMBER_LIST;
return m;
}
EXPORT Conference *
alloc_conference(void)
......@@ -118,71 +55,75 @@ alloc_text_stat(void)
return t;
}
EXPORT void
free_text_list(Text_list *text_list)
static void
clear_text_list(Text_list *text_list)
{
if ( text_list == NULL )
{
log("clear_text_list(): text_list == NULL.\n");
return;
text_list_cnt--;
}
sfree(text_list->texts);
text_list->texts = NULL;
text_list->no_of_texts = 0;
*text_list = EMPTY_TEXT_LIST;
}
EXPORT void
free_mark_list(Mark_list *mark_list)
static void
clear_mark_list(Mark_list *mark_list)
{
if ( mark_list == NULL )
{
log("clear_mark_list(): mark_list == NULL.\n");
return;
mark_list_cnt--;
}
sfree(mark_list->marks);
mark_list->marks = NULL;
mark_list->no_of_marks = 0;
*mark_list = EMPTY_MARK_LIST;
}
EXPORT void
free_membership_list(Membership_list *mlist)
{
int i;
if ( mlist == NULL )
return;
membership_list_cnt--;
for ( i = 0; i < mlist->no_of_confs; i++ )
static void
clear_membership(Membership *mship)
{
if ( mship == NULL )
{
free_membership(&mlist->confs[i]);
log("clear_membership(): mship == NULL.\n");
return;
}
mlist->confs = NULL;
mlist->no_of_confs = 0;
sfree(mship->read_texts);
*mship = EMPTY_MEMBERSHIP;
}
EXPORT void
free_membership(Membership *mship)
clear_membership_list(Membership_list *mlist)
{
if ( mship == NULL )
int i;
if ( mlist == NULL )
{
log("clear_membership_list(): membership_list == NULL.\n");
return;
}
membership_cnt--;
for ( i = 0; i < mlist->no_of_confs; i++ )
{
clear_membership(&mlist->confs[i]);
}
sfree(mship->read_texts);
mship->read_texts = NULL;
mship->no_of_read = 0;
sfree(mlist->confs);
*mlist = EMPTY_MEMBERSHIP_LIST;
}
EXPORT void
clear_person(Person *person)
{
s_clear(&person->username);
free_text_list(&person->created_texts);
free_mark_list(&person->marks);
free_membership_list(&person->conferences);
clear_text_list(&person->created_texts);
clear_mark_list(&person->marks);
clear_membership_list(&person->conferences);
*person = EMPTY_PERSON;
}
......@@ -193,32 +134,27 @@ free_person(Person *person)
return;
person_cnt--;
clear_person(person);
sfree(person);
}
EXPORT void
free_member_list(Member_list *m)
clear_member_list(Member_list *m)
{
if ( m == NULL )
return;
member_list_cnt--;
sfree(m->members);
m->members = NULL;
m->no_of_members = 0;
*m = EMPTY_MEMBER_LIST;
}
EXPORT void
clear_conference(Conference *confp)
{
s_clear(&confp->name);
free_member_list(&confp->members);
free_text_list(&confp->texts);
clear_member_list(&confp->members);
clear_text_list(&confp->texts);
*confp = EMPTY_CONFERENCE;
}
......@@ -276,51 +212,7 @@ free_text_stat(Text_stat *t)
sfree(t);
}
EXPORT Person *
copy_person(Person *p)
{
Person *c;
c = alloc_person();
*c = *p;
c->username = EMPTY_STRING;
s_strcpy(&c->username, p->username);
c->created_texts = copy_text_list(p->created_texts);
c->marks = copy_mark_list(p->marks);
c->conferences = copy_membership_list(p->conferences);
return c;
}
EXPORT Conference *
copy_conf(Conference *o)
{
Conference *c;
c = alloc_conference();
*c = *o;
c->name = EMPTY_STRING;
s_strcpy(&c->name, o->name);
c->members = copy_member_list(o->members);
c->texts = copy_text_list(o->texts);
return c;
}
EXPORT Text_stat *
copy_text_stat(Text_stat *t)
{
Text_stat *c;
c = alloc_text_stat();
*c = *t;
c->misc_items = smalloc(c->no_of_misc * sizeof(Misc_info));
memcpy(c->misc_items, t->misc_items, c->no_of_misc * sizeof(Misc_info));
return c;
}
EXPORT Text_list
static Text_list
copy_text_list(Text_list tl)
{
Text_list r;
......@@ -332,7 +224,7 @@ copy_text_list(Text_list tl)
return r;
}
EXPORT Mark_list
static Mark_list
copy_mark_list(Mark_list ml)
{
Mark_list r;
......@@ -343,6 +235,7 @@ copy_mark_list(Mark_list ml)
return r;
}
static Membership
copy_membership(Membership m)
{
......@@ -354,7 +247,8 @@ copy_membership(Membership m)
return res;
}
EXPORT Membership_list
static Membership_list
copy_membership_list(Membership_list ml)
{
Membership_list r;
......@@ -371,7 +265,24 @@ copy_membership_list(Membership_list ml)
return r;
}
EXPORT Member_list
EXPORT Person *
copy_person(Person *p)
{
Person *c;
c = alloc_person();
*c = *p;
c->username = EMPTY_STRING;
s_strcpy(&c->username, p->username);
c->created_texts = copy_text_list(p->created_texts);
c->marks = copy_mark_list(p->marks);
c->conferences = copy_membership_list(p->conferences);
return c;
}
static Member_list
copy_member_list(Member_list ml)
{
Member_list res;
......@@ -382,27 +293,41 @@ copy_member_list(Member_list ml)
return res;
}
EXPORT Conference *
copy_conf(Conference *o)
{
Conference *c;
c = alloc_conference();
*c = *o;
c->name = EMPTY_STRING;
s_strcpy(&c->name, o->name);
c->members = copy_member_list(o->members);
c->texts = copy_text_list(o->texts);
return c;
}
EXPORT Text_stat *
copy_text_stat(Text_stat *t)
{
Text_stat *c;
c = alloc_text_stat();
*c = *t;
c->misc_items = smalloc(c->no_of_misc * sizeof(Misc_info));
memcpy(c->misc_items, t->misc_items, c->no_of_misc * sizeof(Misc_info));
return c;
}
EXPORT void
dump_alloc_counts(FILE *fp)
{
fprintf(fp, "---memory.c:\n"
"\ttext_list: %d\n"
"\tmark_list: %d\n"
"\tmembership_list: %d\n"
"\tmembership: %d\n"
"\tperson: %d\n"
"\tmember_list: %d\n"
"\tconference: %d\n"
"\ttext_stat: %d\n\n",
text_list_cnt,
mark_list_cnt,
membership_list_cnt,
membership_cnt,
"\ttext_stat: %d\n",
person_cnt,
member_list_cnt,
conference_cnt,
text_stat_cnt);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment