1*40411Sbostic /*- 2*40411Sbostic * LstDestroy.c -- 3*40411Sbostic * Nuke a list and all its resources 4*40411Sbostic * 5*40411Sbostic * Copyright (c) 1988 by University of California Regents 6*40411Sbostic * 7*40411Sbostic * Permission to use, copy, modify, and distribute this 8*40411Sbostic * software and its documentation for any purpose and without 9*40411Sbostic * fee is hereby granted, provided that the above copyright 10*40411Sbostic * notice appears in all copies. Neither the University of California nor 11*40411Sbostic * Adam de Boor makes any representations about the suitability of this 12*40411Sbostic * software for any purpose. It is provided "as is" without 13*40411Sbostic * express or implied warranty. 14*40411Sbostic */ 15*40411Sbostic #ifndef lint 16*40411Sbostic static char *rcsid = 17*40411Sbostic "$Id: lstDestroy.c,v 1.5 88/11/17 20:52:15 adam Exp $ SPRITE (Berkeley)"; 18*40411Sbostic #endif lint 19*40411Sbostic 20*40411Sbostic #include "lstInt.h" 21*40411Sbostic 22*40411Sbostic /*- 23*40411Sbostic *----------------------------------------------------------------------- 24*40411Sbostic * Lst_Destroy -- 25*40411Sbostic * Destroy a list and free all its resources. If the freeProc is 26*40411Sbostic * given, it is called with the datum from each node in turn before 27*40411Sbostic * the node is freed. 28*40411Sbostic * 29*40411Sbostic * Results: 30*40411Sbostic * None. 31*40411Sbostic * 32*40411Sbostic * Side Effects: 33*40411Sbostic * The given list is freed in its entirety. 34*40411Sbostic * 35*40411Sbostic *----------------------------------------------------------------------- 36*40411Sbostic */ 37*40411Sbostic void 38*40411Sbostic Lst_Destroy (l, freeProc) 39*40411Sbostic Lst l; 40*40411Sbostic register void (*freeProc)(); 41*40411Sbostic { 42*40411Sbostic register ListNode ln; 43*40411Sbostic register ListNode tln = NilListNode; 44*40411Sbostic register List list = (List)l; 45*40411Sbostic 46*40411Sbostic if (l == NILLST || ! l) { 47*40411Sbostic /* 48*40411Sbostic * Note the check for l == (Lst)0 to catch uninitialized static Lst's. 49*40411Sbostic * Gross, but useful. 50*40411Sbostic */ 51*40411Sbostic return; 52*40411Sbostic } 53*40411Sbostic 54*40411Sbostic if (freeProc) { 55*40411Sbostic for (ln = list->firstPtr; 56*40411Sbostic ln != NilListNode && tln != list->firstPtr; 57*40411Sbostic ln = tln) { 58*40411Sbostic tln = ln->nextPtr; 59*40411Sbostic (*freeProc) (ln->datum); 60*40411Sbostic free ((Address)ln); 61*40411Sbostic } 62*40411Sbostic } else { 63*40411Sbostic for (ln = list->firstPtr; 64*40411Sbostic ln != NilListNode && tln != list->firstPtr; 65*40411Sbostic ln = tln) { 66*40411Sbostic tln = ln->nextPtr; 67*40411Sbostic free ((Address)ln); 68*40411Sbostic } 69*40411Sbostic } 70*40411Sbostic 71*40411Sbostic free ((Address)l); 72*40411Sbostic } 73