Annotation of 43BSDReno/usr.bin/make/lst.lib/lstRemove.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Adam de Boor.
                      7:  *
                      8:  * Redistribution and use in source and binary forms are permitted
                      9:  * provided that: (1) source distributions retain this entire copyright
                     10:  * notice and comment, and (2) distributions including binaries display
                     11:  * the following acknowledgement:  ``This product includes software
                     12:  * developed by the University of California, Berkeley and its contributors''
                     13:  * in the documentation or other materials provided with the distribution
                     14:  * and in all advertising materials mentioning features or use of this
                     15:  * software. Neither the name of the University nor the names of its
                     16:  * contributors may be used to endorse or promote products derived
                     17:  * from this software without specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: #ifndef lint
                     24: static char sccsid[] = "@(#)lstRemove.c        5.3 (Berkeley) 6/1/90";
                     25: #endif /* not lint */
                     26: 
                     27: /*-
                     28:  * LstRemove.c --
                     29:  *     Remove an element from a list
                     30:  */
                     31: 
                     32: #include       "lstInt.h"
                     33: 
                     34: /*-
                     35:  *-----------------------------------------------------------------------
                     36:  * Lst_Remove --
                     37:  *     Remove the given node from the given list.
                     38:  *
                     39:  * Results:
                     40:  *     SUCCESS or FAILURE.
                     41:  *
                     42:  * Side Effects:
                     43:  *     The list's firstPtr will be set to NilListNode if ln is the last
                     44:  *     node on the list. firsPtr and lastPtr will be altered if ln is
                     45:  *     either the first or last node, respectively, on the list.
                     46:  *
                     47:  *-----------------------------------------------------------------------
                     48:  */
                     49: ReturnStatus
                     50: Lst_Remove (l, ln)
                     51:     Lst                        l;
                     52:     LstNode            ln;
                     53: {
                     54:     register List      list = (List) l;
                     55:     register ListNode  lNode = (ListNode) ln;
                     56: 
                     57:     if (!LstValid (l) ||
                     58:        !LstNodeValid (ln, l)) {
                     59:            return (FAILURE);
                     60:     }
                     61:     
                     62:     /*
                     63:      * unlink it from the list
                     64:      */
                     65:     if (lNode->nextPtr != NilListNode) {
                     66:        lNode->nextPtr->prevPtr = lNode->prevPtr;
                     67:     }
                     68:     if (lNode->prevPtr != NilListNode) {
                     69:        lNode->prevPtr->nextPtr = lNode->nextPtr;
                     70:     }
                     71:     
                     72:     /*
                     73:      * if either the firstPtr or lastPtr of the list point to this node,
                     74:      * adjust them accordingly
                     75:      */
                     76:     if (list->firstPtr == lNode) {
                     77:        list->firstPtr = lNode->nextPtr;
                     78:     }
                     79:     if (list->lastPtr == lNode) {
                     80:        list->lastPtr = lNode->prevPtr;
                     81:     }
                     82: 
                     83:     /*
                     84:      * Sequential access stuff. If the node we're removing is the current
                     85:      * node in the list, reset the current node to the previous one. If the
                     86:      * previous one was non-existent (prevPtr == NilListNode), we set the
                     87:      * end to be Unknown, since it is.
                     88:      */
                     89:     if (list->isOpen && (list->curPtr == lNode)) {
                     90:        list->curPtr = list->prevPtr;
                     91:        if (list->curPtr == NilListNode) {
                     92:            list->atEnd = Unknown;
                     93:        }
                     94:     }
                     95: 
                     96:     /*
                     97:      * the only way firstPtr can still point to ln is if ln is the last
                     98:      * node on the list (the list is circular, so lNode->nextptr == lNode in
                     99:      * this case). The list is, therefore, empty and is marked as such
                    100:      */
                    101:     if (list->firstPtr == lNode) {
                    102:        list->firstPtr = NilListNode;
                    103:     }
                    104:     
                    105:     /*
                    106:      * note that the datum is unmolested. The caller must free it as
                    107:      * necessary and as expected.
                    108:      */
                    109:     if (lNode->useCount == 0) {
                    110:        free ((Address)ln);
                    111:     } else {
                    112:        lNode->flags |= LN_DELETED;
                    113:     }
                    114:     
                    115:     return (SUCCESS);
                    116: }
                    117: 

unix.superglobalmegacorp.com

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