140412Sbostic /* 240412Sbostic * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. 340412Sbostic * All rights reserved. 440411Sbostic * 540412Sbostic * This code is derived from software contributed to Berkeley by 640412Sbostic * Adam de Boor. 740411Sbostic * 8*42741Sbostic * %sccs.include.redist.c% 940411Sbostic */ 1040412Sbostic 1140411Sbostic #ifndef lint 12*42741Sbostic static char sccsid[] = "@(#)lstDestroy.c 5.3 (Berkeley) 06/01/90"; 1340412Sbostic #endif /* not lint */ 1440411Sbostic 1540412Sbostic /*- 1640412Sbostic * LstDestroy.c -- 1740412Sbostic * Nuke a list and all its resources 1840412Sbostic */ 1940412Sbostic 2040411Sbostic #include "lstInt.h" 2140411Sbostic 2240411Sbostic /*- 2340411Sbostic *----------------------------------------------------------------------- 2440411Sbostic * Lst_Destroy -- 2540411Sbostic * Destroy a list and free all its resources. If the freeProc is 2640411Sbostic * given, it is called with the datum from each node in turn before 2740411Sbostic * the node is freed. 2840411Sbostic * 2940411Sbostic * Results: 3040411Sbostic * None. 3140411Sbostic * 3240411Sbostic * Side Effects: 3340411Sbostic * The given list is freed in its entirety. 3440411Sbostic * 3540411Sbostic *----------------------------------------------------------------------- 3640411Sbostic */ 3740411Sbostic void 3840411Sbostic Lst_Destroy (l, freeProc) 3940411Sbostic Lst l; 4040411Sbostic register void (*freeProc)(); 4140411Sbostic { 4240411Sbostic register ListNode ln; 4340411Sbostic register ListNode tln = NilListNode; 4440411Sbostic register List list = (List)l; 4540411Sbostic 4640411Sbostic if (l == NILLST || ! l) { 4740411Sbostic /* 4840411Sbostic * Note the check for l == (Lst)0 to catch uninitialized static Lst's. 4940411Sbostic * Gross, but useful. 5040411Sbostic */ 5140411Sbostic return; 5240411Sbostic } 5340411Sbostic 5440411Sbostic if (freeProc) { 5540411Sbostic for (ln = list->firstPtr; 5640411Sbostic ln != NilListNode && tln != list->firstPtr; 5740411Sbostic ln = tln) { 5840411Sbostic tln = ln->nextPtr; 5940411Sbostic (*freeProc) (ln->datum); 6040411Sbostic free ((Address)ln); 6140411Sbostic } 6240411Sbostic } else { 6340411Sbostic for (ln = list->firstPtr; 6440411Sbostic ln != NilListNode && tln != list->firstPtr; 6540411Sbostic ln = tln) { 6640411Sbostic tln = ln->nextPtr; 6740411Sbostic free ((Address)ln); 6840411Sbostic } 6940411Sbostic } 7040411Sbostic 7140411Sbostic free ((Address)l); 7240411Sbostic } 73