Annotation of 43BSDReno/usr.bin/make/lst.lib/lstAppend.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[] = "@(#)lstAppend.c        5.3 (Berkeley) 6/1/90";
                     25: #endif /* not lint */
                     26: 
                     27: /*-
                     28:  * LstAppend.c --
                     29:  *     Add a new node with a new datum after an existing node
                     30:  */
                     31: 
                     32: #include       "lstInt.h"
                     33: 
                     34: /*-
                     35:  *-----------------------------------------------------------------------
                     36:  * Lst_Append --
                     37:  *     Create a new node and add it to the given list after the given node.
                     38:  *
                     39:  * Results:
                     40:  *     SUCCESS if all went well.
                     41:  *
                     42:  * Side Effects:
                     43:  *     A new ListNode is created and linked in to the List. The lastPtr
                     44:  *     field of the List will be altered if ln is the last node in the
                     45:  *     list. lastPtr and firstPtr will alter if the list was empty and
                     46:  *     ln was NILLNODE.
                     47:  *
                     48:  *-----------------------------------------------------------------------
                     49:  */
                     50: ReturnStatus
                     51: Lst_Append (l, ln, d)
                     52:     Lst                l;      /* affected list */
                     53:     LstNode    ln;     /* node after which to append the datum */
                     54:     ClientData d;      /* said datum */
                     55: {
                     56:     register List      list;
                     57:     register ListNode  lNode;
                     58:     register ListNode  nLNode;
                     59:     
                     60:     if (LstValid (l) && (ln == NILLNODE && LstIsEmpty (l))) {
                     61:        goto ok;
                     62:     }
                     63:     
                     64:     if (!LstValid (l) || LstIsEmpty (l)  || ! LstNodeValid (ln, l)) {
                     65:        return (FAILURE);
                     66:     }
                     67:     ok:
                     68:     
                     69:     list = (List)l;
                     70:     lNode = (ListNode)ln;
                     71: 
                     72:     PAlloc (nLNode, ListNode);
                     73:     nLNode->datum = d;
                     74:     nLNode->useCount = nLNode->flags = 0;
                     75:     
                     76:     if (lNode == NilListNode) {
                     77:        if (list->isCirc) {
                     78:            nLNode->nextPtr = nLNode->prevPtr = nLNode;
                     79:        } else {
                     80:            nLNode->nextPtr = nLNode->prevPtr = NilListNode;
                     81:        }
                     82:        list->firstPtr = list->lastPtr = nLNode;
                     83:     } else {
                     84:        nLNode->prevPtr = lNode;
                     85:        nLNode->nextPtr = lNode->nextPtr;
                     86:        
                     87:        lNode->nextPtr = nLNode;
                     88:        if (nLNode->nextPtr != NilListNode) {
                     89:            nLNode->nextPtr->prevPtr = nLNode;
                     90:        }
                     91:        
                     92:        if (lNode == list->lastPtr) {
                     93:            list->lastPtr = nLNode;
                     94:        }
                     95:     }
                     96:     
                     97:     return (SUCCESS);
                     98: }
                     99: 

unix.superglobalmegacorp.com

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