[CODE] some macros for doubly-linked lists

From: d. hall (dhall@APK.NET)
Date: 01/05/98

Getting a palmpilot for Christmas can seriously dampen any useful [mud]
programming that you have going.  Trying to get a m68k cross-compiler can
be a serious trial and error ordeal.

Anyways, someone mentioned the idea of doubly linked lists to be added to
their mud server.  Although that would be a major programming experience,
and if you're digging around that much with the base structures, you might
as well rewrite the server from scratch... but anyways, I've implemented
small subpackage of macros to deal with a doubly-linked list.

Again, like the previous zstack source, glist (generic list) is part of a
large library of functions (which when I'm done fiddling with and debugging
might release).  It's currently ported to linux 2.0.33 and solaris 2.5.1
(w/ gcc

kalloc is a macro:
#define kalloc(type, size)      ((type *) icalloc (sizeof (type) * (size)))

isyslog is function:
extern int isyslog (const char *, ...) __attribute__ ((format (printf, 1, 2)));

        you can replace with fprintf (stderr, blah);

The reason why I used macro's instead of functions was that I couldn't be
sure of what the next and prev member names will be, and instead of making
a doubly-linked list of void pointers which you need to cast the members of
constantly, glist uses the idea of a sentinel node, which monitors a list,
and keeps track of head, tail and size.  This node uses void pointers,
insert and append macros will stuff them into the head and tail pointers
respectively.  I've been using this source for stuff other than mud
programming and haven't really hit any snags with it, YMMV.


Brief program example:

char_data *c1, *c2, *c3;
list_data *player_list;

c1 = player_create ();
c2 = player_create ();
c3 = player_create ();

player_list = glist_create ();
room_list = glist_create ();

GL_APPEND (c2, char_data, total_list, next, prev);
GL_APPEND (c3, char_data, total_list, next, prev);
GL_INSERT (c1, char_data, total_list, next, prev);

GL_INSERT (c1, char_data, room_list, next_in_room, prev_in_room);
GL_INSERT (c3, char_data, room_list, next_in_room, prev_in_room);

GL_DELETE (c2, char_char, total_list, next, prev);

+------------------------------------------------------------+ | Ensure that you have read the CircleMUD Mailing List FAQ: | | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html | +------------------------------------------------------------+

This archive was generated by hypermail 2b30 : 12/15/00 PST