#include "groups.h" void setGroupList(struct chatgroup * xgrouplist) { grouplist = xgrouplist; } struct chatgroup * getGroupList() { return grouplist; } /* Read groups from a stream */ struct chatgroup * readgroups(int connection) { long value = 0, tvalue = 0; long groups = 0, tgroups = 0; long c = 0; char * gname, final; short glen, tglen; struct chatgroup * current = NULL, * tmpgroup = NULL; recv(connection, &tvalue, sizeof(tvalue), 0); value = ntohl(tvalue); recv(connection, &tgroups, sizeof(tgroups), 0); groups = ntohl(tgroups); for(c=0;cprev = NULL; tmpgroup->next = NULL; tmpgroup->name = (char *) malloc(strlen(name) + 1); strcpy(tmpgroup->name,name); return tmpgroup; }; void disposegroup(struct chatgroup * group) { struct chatgroup * tmpprev = NULL; struct chatgroup * tmpnext = NULL; if (group == NULL) { return; }; tmpprev = group->prev; tmpnext = group->next; if (tmpprev) { tmpprev->next = tmpnext; }; if (tmpnext) { tmpnext->prev = tmpprev; }; if (group->name) { free(group->name); }; free(group); }; void disposeallgroups(struct chatgroup * group) { if (group) { struct chatgroup * current = firstgroup(group); while (current) { struct chatgroup * next = current->next; disposegroup(current); } } } struct chatgroup * insertgroup(struct chatgroup * before, struct chatgroup * newgroup) { struct chatgroup * tmpprev = NULL; struct chatgroup * tmpnext = NULL; if (before == NULL) { return newgroup; } tmpprev = before; tmpnext = before->next; before->next = newgroup; newgroup->prev = before; newgroup->next = tmpnext; if (tmpnext) { tmpnext->prev = newgroup; }; }; struct chatgroup * firstgroup(struct chatgroup * group) { if (group == NULL) { return NULL; }; while (group->prev != NULL) { group = group->prev; } return group; }; struct chatgroup * lastgroup(struct chatgroup * group) { if (group == NULL) { return NULL; }; while (group->next != NULL) { group = group->next; } return group; };