[BACK]Return to list.c CVS log [TXT][DIR] Up to [contributed] / early-roguelike / srogue

Annotation of early-roguelike/srogue/list.c, Revision 1.1.1.1

1.1       rubenllo    1: /*
                      2:  * Functions for dealing with linked lists of goodies
                      3:  *
                      4:  * @(#)list.c  9.0     (rdk)    7/17/84
                      5:  *
                      6:  * Super-Rogue
                      7:  * Copyright (C) 1984 Robert D. Kindelberger
                      8:  * All rights reserved.
                      9:  *
                     10:  * Based on "Rogue: Exploring the Dungeons of Doom"
                     11:  * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
                     12:  * All rights reserved.
                     13:  *
                     14:  * See the file LICENSE.TXT for full copyright and licensing information.
                     15:  */
                     16:
                     17: #include <stdlib.h>
                     18: #include "rogue.h"
                     19: #include "rogue.ext"
                     20:
                     21: /*
                     22:  * detach:
                     23:  *     Takes an item out of whatever linked list it might be in
                     24:  */
                     25:
                     26: void
                     27: _detach(struct linked_list **list, struct linked_list *item)
                     28: {
                     29:        if (*list == item)
                     30:                *list = next(item);
                     31:        if (prev(item) != NULL)
                     32:                item->l_prev->l_next = next(item);
                     33:        if (next(item) != NULL)
                     34:                item->l_next->l_prev = prev(item);
                     35:        item->l_next = NULL;
                     36:        item->l_prev = NULL;
                     37: }
                     38:
                     39: /*
                     40:  * _attach:    add an item to the head of a list
                     41:  */
                     42: void
                     43: _attach(struct linked_list **list, struct linked_list *item)
                     44: {
                     45:        if (*list != NULL)      {
                     46:                item->l_next = *list;
                     47:                (*list)->l_prev = item;
                     48:                item->l_prev = NULL;
                     49:        }
                     50:        else    {
                     51:                item->l_next = NULL;
                     52:                item->l_prev = NULL;
                     53:        }
                     54:        *list = item;
                     55: }
                     56:
                     57: /*
                     58:  * _free_list: Throw the whole blamed thing away
                     59:  */
                     60: void
                     61: _free_list(struct linked_list **ptr)
                     62: {
                     63:        register struct linked_list *item;
                     64:
                     65:        while (*ptr != NULL) {
                     66:                item = *ptr;
                     67:                *ptr = next(item);
                     68:                discard(item);
                     69:        }
                     70: }
                     71:
                     72: /*
                     73:  * discard:  free up an item
                     74:  */
                     75: void
                     76: discard(struct linked_list *item)
                     77: {
                     78:        total -= 2;
                     79:        FREE(item->l_data);
                     80:        FREE(item);
                     81: }
                     82:
                     83: /*
                     84:  * new_item:   get a new item with a specified size
                     85:  */
                     86: struct linked_list *
                     87: new_item(int size)
                     88: {
                     89:        register struct linked_list *item;
                     90:
                     91:        item = (struct linked_list *) new(sizeof *item);
                     92:        item->l_data = new(size);
                     93:        item->l_next = item->l_prev = NULL;
                     94:        return item;
                     95: }
                     96:
                     97: char *
                     98: new(int size)
                     99: {
                    100:        register char *space = ALLOC(size);
                    101:
                    102:        if (space == NULL) {
                    103:                sprintf(prbuf,"Rogue ran out of memory (%ld).", md_memused());
                    104:                fatal(prbuf);
                    105:        }
                    106:        total++;
                    107:        return space;
                    108: }

CVSweb