/* * adds a user to a channel by adding another link to the channels member * chain. */ void add_user_to_channel(aChannel *chptr, aClient *who, int flags) { Member *ptr; Membership *ptr2; if (who->user) { ptr = make_member(); ptr->cptr = who; ptr->flags = flags; ptr->next = chptr->members; chptr->members = ptr; chptr->users++; ptr2 = make_membership(MyClient(who)); /* we should make this more efficient --stskeeps is now, as we only use it in membership */ ptr2->chptr = chptr; ptr2->next = who->user->channel; ptr2->flags = flags; who->user->channel = ptr2; who->user->joined++; } }
/* Test code entry point */ int main(int argc, // IN char **argv) // IN { member *c1; member *c2; member *c3; member *c4; DblLnkLst_Links h; member *a1; member *a2; member *a3; printf("Circular list: there is no origin\n"); /* Create the 1st member */ c1 = make_member(1); /* Special case: there is no list to merge with, initially */ /* Add the 2nd member _after_ the 1st one */ c2 = make_member(2); DblLnkLst_Link(&c1->l, &c2->l); /* Add the 3rd member _after_ the 2nd one */ c3 = make_member(3); DblLnkLst_Link(&c1->l, &c3->l); /* Add the 4th member _before_ the 3rd one */ c4 = make_member(4); DblLnkLst_Link(&c3->l, &c4->l); printf("See it from this member...\n"); dump_circular(c1); printf("...Or from this one\n"); dump_circular(c4); printf("\n"); printf("Anchored (linear) list: it has a beginning and an end\n"); /* Create the 'head' of the list */ DblLnkLst_Init(&h); /* Add the 1st member at the _end_ */ a1 = make_member(5); DblLnkLst_LinkLast(&h, &a1->l); /* Add the 2nd member at the _beginning_ */ a2 = make_member(6); DblLnkLst_LinkFirst(&h, &a2->l); /* Add the 3rd member _before_ the 1st one */ a3 = make_member(7); DblLnkLst_Link(&a1->l, &a3->l); dump_anchored(&h); printf("\n"); printf("Merge both lists: the result is an anchored list\n"); DblLnkLst_Link(&h, &c4->l); dump_anchored(&h); printf("\n"); printf("Remove a member\n"); DblLnkLst_Unlink1(&c3->l); dump_anchored(&h); printf("\n"); printf("Split the result in two lists: an anchored one and a circular " "one\n"); DblLnkLst_Unlink(&h, &a1->l); dump_anchored(&h); dump_circular(a1); return 0; }