Annotation of 43BSDReno/contrib/jove/list.c, revision 1.1.1.1

1.1       root        1: #include "jove.h"
                      2: #include "list.h"
                      3: 
                      4: extern char    *emalloc();
                      5: 
                      6: private List *
                      7: list_new()
                      8: {
                      9:        List    *new;
                     10: 
                     11:        new = (List *) emalloc(sizeof (List));
                     12:        new->car = NIL;
                     13:        return new;
                     14: }
                     15: 
                     16: /* push an object to the beginning of list */
                     17: 
                     18: Element *
                     19: list_push(list, element)
                     20: register List  **list;
                     21: Element        *element;
                     22: {
                     23:        List    *new;
                     24: 
                     25:        new = list_new();
                     26:        new->cdr = *list;
                     27:        new->car = element;
                     28:        *list = new;
                     29:        return element;
                     30: }
                     31: 
                     32: Element *
                     33: list_pop(list)
                     34: List   **list;
                     35: {
                     36:        List    *cell;
                     37:        Element *element;
                     38: 
                     39:        if (*list == NIL)
                     40:                return NIL;
                     41:        cell = *list;
                     42:        element = cell->car;
                     43:        free((char *) cell);
                     44:        *list = (*list)->cdr;
                     45: 
                     46:        return element;
                     47: }
                     48: 
                     49: #ifdef NEVER
                     50: Element *
                     51: list_remove(list_head, element)
                     52: List   **list_head;
                     53: Element        *element;
                     54: {
                     55:        register List   *cp = *list_head,
                     56:                        *prev = NIL;
                     57: 
                     58:        while (cp != NIL) {
                     59:                if (cp->car == element)
                     60:                        break;
                     61:                prev = cp;
                     62:                cp = cp->cdr;
                     63:        }
                     64:        if (cp == NIL)
                     65:                return NIL;
                     66:        if (prev == NIL)
                     67:                *list_head = (*list_head)->cdr;
                     68:        else
                     69:                prev->cdr = cp->cdr;
                     70: 
                     71:        return element;
                     72: }
                     73: 
                     74: Element *
                     75: list_append(list, element)
                     76: List   **list;
                     77: Element        *element;
                     78: {
                     79:        List    *new, *lp;
                     80: 
                     81:        lp = *list;
                     82:        if (lp == NIL)
                     83:                return list_push(list, element);
                     84: 
                     85:        while (lp->cdr != NIL)
                     86:                lp = lp->cdr;
                     87:        new = list_new();
                     88:        lp->cdr = new;
                     89:        new->car = element;
                     90: 
                     91:        return element;
                     92: }
                     93: 
                     94: Element *
                     95: list_find(list, element)
                     96: List   *list;
                     97: Element        *element;
                     98: {
                     99:        while (list != NIL)
                    100:                if (list->car == element)
                    101:                        return element;
                    102:        return NIL;
                    103: }
                    104: #endif /* NEVER */

unix.superglobalmegacorp.com

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