Annotation of researchv10no/games/rogue/list.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Functions for dealing with linked lists of goodies
                      3:  *
                      4:  * @(#)list.c  3.3 (Berkeley) 6/15/81
                      5:  */
                      6: 
                      7: #include <curses.h>
                      8: #include "rogue.h"
                      9: 
                     10: /*
                     11:  * detach:
                     12:  *     Takes an item out of whatever linked list it might be in
                     13:  */
                     14: 
                     15: _detach(list, item)
                     16: register struct linked_list **list, *item;
                     17: {
                     18:     if (*list == item)
                     19:        *list = next(item);
                     20:     if (prev(item) != NULL) item->l_prev->l_next = next(item);
                     21:     if (next(item) != NULL) item->l_next->l_prev = prev(item);
                     22:     item->l_next = NULL;
                     23:     item->l_prev = NULL;
                     24: }
                     25: 
                     26: /*
                     27:  * _attach:
                     28:  *     add an item to the head of a list
                     29:  */
                     30: 
                     31: _attach(list, item)
                     32: register struct linked_list **list, *item;
                     33: {
                     34:     if (*list != NULL)
                     35:     {
                     36:        item->l_next = *list;
                     37:        (*list)->l_prev = item;
                     38:        item->l_prev = NULL;
                     39:     }
                     40:     else
                     41:     {
                     42:        item->l_next = NULL;
                     43:        item->l_prev = NULL;
                     44:     }
                     45: 
                     46:     *list = item;
                     47: }
                     48: 
                     49: /*
                     50:  * _free_list:
                     51:  *     Throw the whole blamed thing away
                     52:  */
                     53: 
                     54: _free_list(ptr)
                     55: register struct linked_list **ptr;
                     56: {
                     57:     register struct linked_list *item;
                     58: 
                     59:     while (*ptr != NULL)
                     60:     {
                     61:        item = *ptr;
                     62:        *ptr = next(item);
                     63:        discard(item);
                     64:     }
                     65: }
                     66: 
                     67: /*
                     68:  * discard:
                     69:  *     free up an item
                     70:  */
                     71: 
                     72: discard(item)
                     73: register struct linked_list *item;
                     74: {
                     75:     total -= 2;
                     76:     FREE(item->l_data);
                     77:     FREE(item);
                     78: }
                     79: 
                     80: /*
                     81:  * new_item
                     82:  *     get a new item with a specified size
                     83:  */
                     84: 
                     85: struct linked_list *
                     86: new_item(size)
                     87: int size;
                     88: {
                     89:     register struct linked_list *item;
                     90: 
                     91:     if ((item = (struct linked_list *) new(sizeof *item)) == NULL)
                     92:        msg("Ran out of memory for header after %d items", total);
                     93:     if ((item->l_data = new(size)) == NULL)
                     94:        msg("Ran out of memory for data after %d items", total);
                     95:     item->l_next = item->l_prev = NULL;
                     96:     return item;
                     97: }
                     98: 
                     99: char *
                    100: new(size)
                    101: int size;
                    102: {
                    103:     register char *space = ALLOC(size);
                    104: 
                    105:     if (space == NULL)
                    106:        fatal(sprintf(prbuf, "Rogue ran out of memory (%d).  Fatal error!", sbrk(0)));
                    107:     total++;
                    108:     return space;
                    109: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.