DragonFly submit List (threaded) for 2004-12
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]
usr.bin/make Remove list.h and Merge lstInt. into lst.h
After applying the following patch remove these files.
rm list.h
rm lst.lib/lstInt.h
rm lst.lib/lstIsEmpty.c
Nax
---------------------
PatchSet 382
Date: 2004/11/29 08:38:16
Author: harti
Log:
Merge the contents of lstInt.h into the public lst.h. This let's us get
rid of a lot of uneccesary casts and temporary variables that have just
obfuscated the code. This also let's us implement a couple of the one-
liner list functions as macros (the first one is Lst_IsEmpty) and
simplify life once we start to throw consts on the code.
Members:
Makefile:1.36->1.37
lst.h:1.15->1.16
lst.lib/lstAppend.c:1.11->1.12
lst.lib/lstAtEnd.c:1.10->1.11
lst.lib/lstAtFront.c:1.10->1.11
lst.lib/lstClose.c:1.9->1.10
lst.lib/lstConcat.c:1.12->1.13
lst.lib/lstDatum.c:1.10->1.11
lst.lib/lstDeQueue.c:1.11->1.12
lst.lib/lstDestroy.c:1.13->1.14
lst.lib/lstDupl.c:1.13->1.14
lst.lib/lstEnQueue.c:1.10->1.11
lst.lib/lstFind.c:1.12->1.13
lst.lib/lstFindFrom.c:1.13->1.14
lst.lib/lstFirst.c:1.9->1.10
lst.lib/lstForEach.c:1.11->1.12
lst.lib/lstForEachFrom.c:1.13->1.14
lst.lib/lstInit.c:1.10->1.11
lst.lib/lstInsert.c:1.11->1.12
lst.lib/lstInt.h:1.10->1.11(DEAD)
lst.lib/lstIsAtEnd.c:1.8->1.9
lst.lib/lstIsEmpty.c:1.9->1.10(DEAD)
lst.lib/lstLast.c:1.8->1.9
lst.lib/lstMember.c:1.11->1.12
lst.lib/lstNext.c:1.10->1.11
lst.lib/lstOpen.c:1.9->1.10
lst.lib/lstRemove.c:1.11->1.12
lst.lib/lstReplace.c:1.10->1.11
lst.lib/lstSucc.c:1.9->1.10
Index: Makefile
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/Makefile,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- Makefile 25 Nov 2004 12:51:51 -0000 1.36
+++ Makefile 29 Nov 2004 08:38:16 -0000 1.37
@@ -9,7 +9,7 @@
SRCS+= lstAppend.c lstAtEnd.c lstAtFront.c lstClose.c lstConcat.c \
lstDatum.c lstDeQueue.c lstDestroy.c lstDupl.c lstEnQueue.c \
lstFind.c lstFindFrom.c lstFirst.c lstForEach.c lstForEachFrom.c \
- lstInit.c lstInsert.c lstIsAtEnd.c lstIsEmpty.c lstLast.c \
+ lstInit.c lstInsert.c lstIsAtEnd.c lstLast.c \
lstMember.c lstNext.c lstOpen.c lstRemove.c lstReplace.c lstSucc.c
.PATH: ${.CURDIR}/lst.lib
Index: lst.h
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- lst.h 17 Sep 2002 21:29:06 -0000 1.15
+++ lst.h 29 Nov 2004 08:38:16 -0000 1.16
@@ -52,11 +52,46 @@
#include "sprite.h"
/*
- * basic typedef. This is what the Lst_ functions handle
+ * Structure of a list node.
*/
+struct LstNode {
+ struct LstNode *prevPtr; /* previous element in list */
+ struct LstNode *nextPtr; /* next in list */
+ int useCount:8; /* Count of functions using the node. Node may not
+ * be deleted until count goes to 0 */
+ int flags:8; /* Node status flags */
+ void *datum; /* datum associated with this element */
+};
+typedef struct LstNode *LstNode;
+
+/*
+ * Flags required for synchronization
+ */
+#define LN_DELETED 0x0001 /* List node should be removed when done */
+typedef enum {
+ LstHead, LstMiddle, LstTail, LstUnknown
+} LstWhere;
+
+/*
+ * The list itself
+ */
+struct Lst {
+ LstNode firstPtr; /* first node in list */
+ LstNode lastPtr; /* last node in list */
+ Boolean isCirc; /* true if the list should be considered
+ * circular */
+ /*
+ * fields for sequential access
+ */
+ LstWhere atEnd; /* Where in the list the last access was */
+ Boolean isOpen; /* true if list has been Lst_Open'ed */
+ LstNode curPtr; /* current node, if open. NULL if
+ * *just* opened */
+ LstNode prevPtr; /* Previous node, if open. Used by
+ * Lst_Remove */
+};
typedef struct Lst *Lst;
-typedef struct LstNode *LstNode;
/*
* NOFREE can be used as the freeProc to Lst_Destroy when the elements are
@@ -78,8 +113,6 @@
Lst Lst_Duplicate(Lst, void * (*)(void *));
/* Destroy an old one */
void Lst_Destroy(Lst, void (*)(void *));
-/* True if list is empty */
-Boolean Lst_IsEmpty(Lst);
/*
* Functions to modify a list
@@ -152,5 +185,24 @@
ReturnStatus Lst_EnQueue(Lst, void *);
/* Remove an element from head of queue */
void * Lst_DeQueue(Lst);
+
+/*
+ * LstValid (L) --
+ * Return TRUE if the list L is valid
+ */
+#define Lst_Valid(L) (((L) == NULL) ? FALSE : TRUE)
+
+/*
+ * LstNodeValid (LN, L) --
+ * Return TRUE if the LstNode LN is valid with respect to L
+ */
+#define Lst_NodeValid(LN, L) (((LN) == NULL) ? FALSE : TRUE)
+
+/*
+ * Lst_IsEmpty(L) --
+ * TRUE if the list L is empty.
+ */
+#define Lst_IsEmpty(L) (!Lst_Valid(L) || (L)->firstPtr == NULL)
+
#endif /* _LST_H_ */
Index: lst.lib/lstAppend.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstAppend.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- lst.lib/lstAppend.c 26 Nov 2004 12:17:22 -0000 1.11
+++ lst.lib/lstAppend.c 29 Nov 2004 08:38:16 -0000 1.12
@@ -46,7 +46,8 @@
* Add a new node with a new datum after an existing node
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -70,29 +71,24 @@
*-----------------------------------------------------------------------
*/
ReturnStatus
-Lst_Append (Lst l, LstNode ln, void *d)
+Lst_Append(Lst list, LstNode ln, void *d)
{
- List list;
- ListNode lNode;
- ListNode nLNode;
+ LstNode nLNode;
- if (LstValid (l) && (ln == NULL && LstIsEmpty (l))) {
+ if (Lst_Valid (list) && (ln == NULL && Lst_IsEmpty (list))) {
goto ok;
}
- if (!LstValid (l) || LstIsEmpty (l) || ! LstNodeValid (ln, l)) {
+ if (!Lst_Valid (list) || Lst_IsEmpty (list) || ! Lst_NodeValid(ln, list)) {
return (FAILURE);
}
ok:
- list = (List)l;
- lNode = (ListNode)ln;
-
- PAlloc (nLNode, ListNode);
+ nLNode = emalloc(sizeof(*nLNode));
nLNode->datum = d;
nLNode->useCount = nLNode->flags = 0;
- if (lNode == NULL) {
+ if (ln == NULL) {
if (list->isCirc) {
nLNode->nextPtr = nLNode->prevPtr = nLNode;
} else {
@@ -100,15 +96,15 @@
}
list->firstPtr = list->lastPtr = nLNode;
} else {
- nLNode->prevPtr = lNode;
- nLNode->nextPtr = lNode->nextPtr;
+ nLNode->prevPtr = ln;
+ nLNode->nextPtr = ln->nextPtr;
- lNode->nextPtr = nLNode;
+ ln->nextPtr = nLNode;
if (nLNode->nextPtr != NULL) {
nLNode->nextPtr->prevPtr = nLNode;
}
- if (lNode == list->lastPtr) {
+ if (ln == list->lastPtr) {
list->lastPtr = nLNode;
}
}
Index: lst.lib/lstAtEnd.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstAtEnd.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- lst.lib/lstAtEnd.c 26 Nov 2004 12:17:22 -0000 1.10
+++ lst.lib/lstAtEnd.c 29 Nov 2004 08:38:16 -0000 1.11
@@ -46,7 +46,8 @@
* Add a node at the end of the list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
Index: lst.lib/lstAtFront.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstAtFront.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- lst.lib/lstAtFront.c 26 Nov 2004 12:17:22 -0000 1.10
+++ lst.lib/lstAtFront.c 29 Nov 2004 08:38:16 -0000 1.11
@@ -46,7 +46,8 @@
* Add a node at the front of the list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
Index: lst.lib/lstClose.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstClose.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- lst.lib/lstClose.c 26 Nov 2004 12:17:22 -0000 1.9
+++ lst.lib/lstClose.c 29 Nov 2004 08:38:16 -0000 1.10
@@ -51,7 +51,8 @@
* used to determine when to stop.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -70,13 +71,11 @@
*-----------------------------------------------------------------------
*/
void
-Lst_Close(Lst l)
+Lst_Close(Lst list)
{
- List list = (List) l;
- if (LstValid(l) == TRUE) {
+ if (Lst_Valid(list) == TRUE) {
list->isOpen = FALSE;
- list->atEnd = Unknown;
+ list->atEnd = LstUnknown;
}
}
-
Index: lst.lib/lstConcat.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstConcat.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- lst.lib/lstConcat.c 26 Nov 2004 12:17:22 -0000 1.12
+++ lst.lib/lstConcat.c 29 Nov 2004 08:38:16 -0000 1.13
@@ -46,7 +46,8 @@
* Function to concatentate two lists.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -62,8 +63,8 @@
* SUCCESS if all went well. FAILURE otherwise.
*
* Arguments:
- * l1 The list to which l2 is to be appended
- * l2 The list to append to l1
+ * list1 The list to which list2 is to be appended
+ * list2 The list to append to list1
* flags LST_CONCNEW if LstNode's should be duplicated
* LST_CONCLINK if should just be relinked
*
@@ -72,16 +73,13 @@
*-----------------------------------------------------------------------
*/
ReturnStatus
-Lst_Concat(Lst l1, Lst l2, int flags)
+Lst_Concat(Lst list1, Lst list2, int flags)
{
- ListNode ln; /* original LstNode */
- ListNode nln; /* new LstNode */
- ListNode last; /* the last element in the list. Keeps
- * bookkeeping until the end */
- List list1 = (List)l1;
- List list2 = (List)l2;
-
- if (!LstValid (l1) || !LstValid (l2)) {
+ LstNode ln; /* original LstNode */
+ LstNode nln; /* new LstNode */
+ LstNode last; /* the last element in the list. Keeps
+ * bookkeeping until the end */
+ if (!Lst_Valid (list1) || !Lst_Valid (list2)) {
return (FAILURE);
}
@@ -121,15 +119,15 @@
list1->firstPtr->prevPtr = list1->lastPtr;
list1->lastPtr->nextPtr = list1->firstPtr;
}
- free (l2);
+ free (list2);
} else if (list2->firstPtr != NULL) {
/*
* We set the nextPtr of the last element of list 2 to be NULL to make
* the loop less difficult. The loop simply goes through the entire
* second list creating new LstNodes and filling in the nextPtr, and
- * prevPtr to fit into l1 and its datum field from the
- * datum field of the corresponding element in l2. The 'last' node
- * follows the last of the new nodes along until the entire l2 has
+ * prevPtr to fit into list1 and its datum field from the
+ * datum field of the corresponding element in list2. The 'last' node
+ * follows the last of the new nodes along until the entire list2 has
* been appended. Only then does the bookkeeping catch up with the
* changes. During the first iteration of the loop, if 'last' is NULL,
* the first list must have been empty so the newly-created node is
@@ -140,7 +138,7 @@
ln != NULL;
ln = ln->nextPtr)
{
- PAlloc (nln, ListNode);
+ nln = emalloc(sizeof(*nln));
nln->datum = ln->datum;
if (last != NULL) {
last->nextPtr = nln;
Index: lst.lib/lstDatum.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstDatum.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- lst.lib/lstDatum.c 26 Nov 2004 12:17:22 -0000 1.10
+++ lst.lib/lstDatum.c 29 Nov 2004 08:38:16 -0000 1.11
@@ -46,7 +46,8 @@
* Return the datum associated with a list node.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -66,8 +67,8 @@
{
if (ln != NULL) {
- return (((ListNode)ln)->datum);
+ return (ln->datum);
} else {
- return ((void *) NULL);
+ return (NULL);
}
}
Index: lst.lib/lstDeQueue.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstDeQueue.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- lst.lib/lstDeQueue.c 26 Nov 2004 12:17:22 -0000 1.11
+++ lst.lib/lstDeQueue.c 29 Nov 2004 08:38:16 -0000 1.12
@@ -46,7 +46,8 @@
* Remove the node and return its datum from the head of the list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -66,16 +67,16 @@
Lst_DeQueue(Lst l)
{
void * rd;
- ListNode tln;
+ LstNode tln;
- tln = (ListNode) Lst_First (l);
+ tln = Lst_First (l);
if (tln == NULL) {
- return ((void *) NULL);
+ return (NULL);
}
rd = tln->datum;
- if (Lst_Remove (l, (LstNode)tln) == FAILURE) {
- return ((void *) NULL);
+ if (Lst_Remove (l, tln) == FAILURE) {
+ return (NULL);
} else {
return (rd);
}
Index: lst.lib/lstDestroy.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstDestroy.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- lst.lib/lstDestroy.c 26 Nov 2004 12:17:22 -0000 1.13
+++ lst.lib/lstDestroy.c 29 Nov 2004 08:38:16 -0000 1.14
@@ -46,7 +46,8 @@
* Nuke a list and all its resources
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -64,13 +65,12 @@
*-----------------------------------------------------------------------
*/
void
-Lst_Destroy(Lst l, void (*freeProc)(void *))
+Lst_Destroy(Lst list, void (*freeProc)(void *))
{
- ListNode ln;
- ListNode tln = NULL;
- List list = (List)l;
+ LstNode ln;
+ LstNode tln = NULL;
- if (l == NULL || ! l) {
+ if (list == NULL || ! list) {
/*
* Note the check for l == (Lst)0 to catch uninitialized static Lst's.
* Gross, but useful.
@@ -82,7 +82,7 @@
if (list->lastPtr != NULL)
list->lastPtr->nextPtr = NULL;
else {
- free (l);
+ free (list);
return;
}
@@ -99,5 +99,5 @@
}
}
- free (l);
+ free (list);
}
Index: lst.lib/lstDupl.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstDupl.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- lst.lib/lstDupl.c 26 Nov 2004 12:17:22 -0000 1.13
+++ lst.lib/lstDupl.c 29 Nov 2004 08:38:16 -0000 1.14
@@ -47,7 +47,8 @@
* elements.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -67,13 +68,12 @@
*-----------------------------------------------------------------------
*/
Lst
-Lst_Duplicate(Lst l, void *(*copyProc)(void *))
+Lst_Duplicate(Lst list, void *(*copyProc)(void *))
{
Lst nl;
- ListNode ln;
- List list = (List)l;
+ LstNode ln;
- if (!LstValid (l)) {
+ if (!Lst_Valid (list)) {
return (NULL);
}
Index: lst.lib/lstEnQueue.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstEnQueue.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- lst.lib/lstEnQueue.c 26 Nov 2004 12:17:22 -0000 1.10
+++ lst.lib/lstEnQueue.c 29 Nov 2004 08:38:16 -0000 1.11
@@ -46,7 +46,8 @@
* Treat the list as a queue and place a datum at its end
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -66,7 +67,7 @@
Lst_EnQueue(Lst l, void *d)
{
- if (LstValid (l) == FALSE) {
+ if (Lst_Valid (l) == FALSE) {
return (FAILURE);
}
Index: lst.lib/lstFind.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstFind.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- lst.lib/lstFind.c 26 Nov 2004 12:17:22 -0000 1.12
+++ lst.lib/lstFind.c 29 Nov 2004 08:38:16 -0000 1.13
@@ -46,7 +46,8 @@
* Find a node on a list.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
Index: lst.lib/lstFindFrom.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstFindFrom.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- lst.lib/lstFindFrom.c 26 Nov 2004 12:17:22 -0000 1.13
+++ lst.lib/lstFindFrom.c 29 Nov 2004 08:38:16 -0000 1.14
@@ -46,7 +46,8 @@
* Find a node on a list from a given starting point. Used by Lst_Find.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -66,14 +67,14 @@
LstNode
Lst_FindFrom(Lst l, LstNode ln, void *d, int (*cProc)(void *, void *))
{
- ListNode tln;
+ LstNode tln;
Boolean found = FALSE;
- if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
+ if (!Lst_Valid (l) || Lst_IsEmpty (l) || !Lst_NodeValid (ln, l)) {
return (NULL);
}
- tln = (ListNode)ln;
+ tln = ln;
do {
if ((*cProc) (tln->datum, d) == 0) {
@@ -82,10 +83,10 @@
} else {
tln = tln->nextPtr;
}
- } while (tln != (ListNode)ln && tln != NULL);
+ } while (tln != ln && tln != NULL);
if (found) {
- return ((LstNode)tln);
+ return (tln);
} else {
return (NULL);
}
Index: lst.lib/lstFirst.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstFirst.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- lst.lib/lstFirst.c 26 Nov 2004 12:17:22 -0000 1.9
+++ lst.lib/lstFirst.c 29 Nov 2004 08:38:16 -0000 1.10
@@ -46,7 +46,8 @@
* Return the first node of a list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -65,9 +66,9 @@
Lst_First(Lst l)
{
- if (!LstValid (l) || LstIsEmpty (l)) {
+ if (!Lst_Valid (l) || Lst_IsEmpty (l)) {
return (NULL);
} else {
- return ((LstNode)((List)l)->firstPtr);
+ return (l->firstPtr);
}
}
Index: lst.lib/lstForEach.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstForEach.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- lst.lib/lstForEach.c 26 Nov 2004 12:17:22 -0000 1.11
+++ lst.lib/lstForEach.c 29 Nov 2004 08:38:16 -0000 1.12
@@ -46,7 +46,8 @@
* Perform a given function on all elements of a list.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
Index: lst.lib/lstForEachFrom.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstForEachFrom.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- lst.lib/lstForEachFrom.c 26 Nov 2004 12:17:22 -0000 1.13
+++ lst.lib/lstForEachFrom.c 29 Nov 2004 08:38:16 -0000 1.14
@@ -47,7 +47,8 @@
* a given point.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -65,15 +66,13 @@
*-----------------------------------------------------------------------
*/
void
-Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(void *, void *), void *d)
+Lst_ForEachFrom(Lst list, LstNode ln, int (*proc)(void *, void *), void *d)
{
- ListNode tln = (ListNode)ln;
- List list = (List)l;
- ListNode next;
+ LstNode next;
Boolean done;
int result;
- if (!LstValid (list) || LstIsEmpty (list)) {
+ if (!Lst_Valid (list) || Lst_IsEmpty (list)) {
return;
}
@@ -83,11 +82,11 @@
* us.
*/
- next = tln->nextPtr;
+ next = ln->nextPtr;
- (void) tln->useCount++;
- result = (*proc) (tln->datum, d);
- (void) tln->useCount--;
+ (void) ln->useCount++;
+ result = (*proc) (ln->datum, d);
+ (void) ln->useCount--;
/*
* We're done with the traversal if
@@ -95,14 +94,14 @@
* - the next node to examine is the first in the queue or
* doesn't exist.
*/
- done = (next == tln->nextPtr &&
+ done = (next == ln->nextPtr &&
(next == NULL || next == list->firstPtr));
- next = tln->nextPtr;
+ next = ln->nextPtr;
- if (tln->flags & LN_DELETED) {
- free((char *)tln);
+ if (ln->flags & LN_DELETED) {
+ free(ln);
}
- tln = next;
- } while (!result && !LstIsEmpty(list) && !done);
+ ln = next;
+ } while (!result && !Lst_IsEmpty(list) && !done);
}
Index: lst.lib/lstInit.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstInit.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- lst.lib/lstInit.c 26 Nov 2004 12:17:22 -0000 1.10
+++ lst.lib/lstInit.c 29 Nov 2004 08:38:16 -0000 1.11
@@ -46,7 +46,8 @@
* Initialize a new linked list.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -67,15 +68,15 @@
Lst
Lst_Init(Boolean circ)
{
- List nList;
+ Lst nList;
- PAlloc (nList, List);
+ nList = emalloc(sizeof(*nList));
nList->firstPtr = NULL;
nList->lastPtr = NULL;
nList->isOpen = FALSE;
nList->isCirc = circ;
- nList->atEnd = Unknown;
+ nList->atEnd = LstUnknown;
- return ((Lst)nList);
+ return (nList);
}
Index: lst.lib/lstInsert.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstInsert.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- lst.lib/lstInsert.c 26 Nov 2004 12:17:22 -0000 1.11
+++ lst.lib/lstInsert.c 29 Nov 2004 08:38:16 -0000 1.12
@@ -46,7 +46,8 @@
* Insert a new datum before an old one
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -68,24 +69,22 @@
*-----------------------------------------------------------------------
*/
ReturnStatus
-Lst_Insert(Lst l, LstNode ln, void *d)
+Lst_Insert(Lst list, LstNode ln, void *d)
{
- ListNode nLNode; /* new lnode for d */
- ListNode lNode = (ListNode)ln;
- List list = (List)l;
+ LstNode nLNode; /* new lnode for d */
/*
* check validity of arguments
*/
- if (LstValid (l) && (LstIsEmpty (l) && ln == NULL))
+ if (Lst_Valid (list) && (Lst_IsEmpty (list) && ln == NULL))
goto ok;
- if (!LstValid (l) || LstIsEmpty (l) || !LstNodeValid (ln, l)) {
+ if (!Lst_Valid (list) || Lst_IsEmpty (list) || !Lst_NodeValid (ln, list)) {
return (FAILURE);
}
ok:
- PAlloc (nLNode, ListNode);
+ nLNode = emalloc(sizeof(*nLNode));
nLNode->datum = d;
nLNode->useCount = nLNode->flags = 0;
@@ -98,15 +97,15 @@
}
list->firstPtr = list->lastPtr = nLNode;
} else {
- nLNode->prevPtr = lNode->prevPtr;
- nLNode->nextPtr = lNode;
+ nLNode->prevPtr = ln->prevPtr;
+ nLNode->nextPtr = ln;
if (nLNode->prevPtr != NULL) {
nLNode->prevPtr->nextPtr = nLNode;
}
- lNode->prevPtr = nLNode;
+ ln->prevPtr = nLNode;
- if (lNode == list->firstPtr) {
+ if (ln == list->firstPtr) {
list->firstPtr = nLNode;
}
}
Index: lst.lib/lstIsAtEnd.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstIsAtEnd.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- lst.lib/lstIsAtEnd.c 26 Nov 2004 12:17:22 -0000 1.8
+++ lst.lib/lstIsAtEnd.c 29 Nov 2004 08:38:16 -0000 1.9
@@ -51,7 +51,8 @@
* used to determine when to stop.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -73,10 +74,9 @@
*-----------------------------------------------------------------------
*/
Boolean
-Lst_IsAtEnd(Lst l)
+Lst_IsAtEnd(Lst list)
{
- List list = (List) l;
- return (!LstValid (l) || !list->isOpen ||
- (list->atEnd == Head) || (list->atEnd == Tail));
+ return (!Lst_Valid (list) || !list->isOpen ||
+ (list->atEnd == LstHead) || (list->atEnd == LstTail));
}
Index: lst.lib/lstLast.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstLast.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- lst.lib/lstLast.c 9 Oct 2002 02:00:22 -0000 1.8
+++ lst.lib/lstLast.c 29 Nov 2004 08:38:16 -0000 1.9
@@ -46,7 +46,8 @@
* Return the last element of a list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -62,13 +63,12 @@
*-----------------------------------------------------------------------
*/
LstNode
-Lst_Last (l)
- Lst l;
+Lst_Last(Lst l)
{
- if (!LstValid(l) || LstIsEmpty (l)) {
+
+ if (!Lst_Valid(l) || Lst_IsEmpty (l)) {
return (NULL);
} else {
- return ((LstNode)((List)l)->lastPtr);
+ return (l->lastPtr);
}
}
-
Index: lst.lib/lstMember.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstMember.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- lst.lib/lstMember.c 26 Nov 2004 12:17:22 -0000 1.11
+++ lst.lib/lstMember.c 29 Nov 2004 08:38:16 -0000 1.12
@@ -46,25 +46,25 @@
* See if a given datum is on a given list.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
LstNode
-Lst_Member(Lst l, void *d)
+Lst_Member(Lst list, void *d)
{
- List list = (List) l;
- ListNode lNode;
+ LstNode lNode;
lNode = list->firstPtr;
if (lNode == NULL) {
- return NULL;
+ return (NULL);
}
do {
if (lNode->datum == d) {
- return (LstNode)lNode;
+ return (lNode);
}
lNode = lNode->nextPtr;
} while (lNode != NULL && lNode != list->firstPtr);
- return NULL;
+ return (NULL);
}
Index: lst.lib/lstNext.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstNext.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- lst.lib/lstNext.c 26 Nov 2004 12:17:22 -0000 1.10
+++ lst.lib/lstNext.c 29 Nov 2004 08:38:16 -0000 1.11
@@ -51,7 +51,8 @@
* used to determine when to stop.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -69,30 +70,28 @@
*-----------------------------------------------------------------------
*/
LstNode
-Lst_Next(Lst l)
+Lst_Next(Lst list)
{
- ListNode tln;
- List list = (List)l;
+ LstNode tln;
- if ((LstValid (l) == FALSE) ||
- (list->isOpen == FALSE)) {
+ if ((Lst_Valid (list) == FALSE) || (list->isOpen == FALSE)) {
return (NULL);
}
list->prevPtr = list->curPtr;
if (list->curPtr == NULL) {
- if (list->atEnd == Unknown) {
+ if (list->atEnd == LstUnknown) {
/*
* If we're just starting out, atEnd will be Unknown.
* Then we want to start this thing off in the right
* direction -- at the start with atEnd being Middle.
*/
list->curPtr = tln = list->firstPtr;
- list->atEnd = Middle;
+ list->atEnd = LstMiddle;
} else {
tln = NULL;
- list->atEnd = Tail;
+ list->atEnd = LstTail;
}
} else {
tln = list->curPtr->nextPtr;
@@ -102,14 +101,14 @@
/*
* If back at the front, then we've hit the end...
*/
- list->atEnd = Tail;
+ list->atEnd = LstTail;
} else {
/*
* Reset to Middle if gone past first.
*/
- list->atEnd = Middle;
+ list->atEnd = LstMiddle;
}
}
- return ((LstNode)tln);
+ return (tln);
}
Index: lst.lib/lstOpen.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstOpen.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- lst.lib/lstOpen.c 26 Nov 2004 12:17:22 -0000 1.9
+++ lst.lib/lstOpen.c 29 Nov 2004 08:38:16 -0000 1.10
@@ -50,7 +50,8 @@
* the list forever. Lst_IsAtEnd must be used to determine when to stop.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -72,12 +73,12 @@
Lst_Open(Lst l)
{
- if (LstValid (l) == FALSE) {
+ if (Lst_Valid (l) == FALSE) {
return (FAILURE);
}
- ((List) l)->isOpen = TRUE;
- ((List) l)->atEnd = LstIsEmpty (l) ? Head : Unknown;
- ((List) l)->curPtr = NULL;
+ l->isOpen = TRUE;
+ l->atEnd = Lst_IsEmpty (l) ? LstHead : LstUnknown;
+ l->curPtr = NULL;
return (SUCCESS);
}
Index: lst.lib/lstRemove.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstRemove.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- lst.lib/lstRemove.c 26 Nov 2004 12:17:23 -0000 1.11
+++ lst.lib/lstRemove.c 29 Nov 2004 08:38:16 -0000 1.12
@@ -46,7 +46,8 @@
* Remove an element from a list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -64,35 +65,32 @@
*-----------------------------------------------------------------------
*/
ReturnStatus
-Lst_Remove(Lst l, LstNode ln)
+Lst_Remove(Lst list, LstNode ln)
{
- List list = (List) l;
- ListNode lNode = (ListNode) ln;
- if (!LstValid (l) ||
- !LstNodeValid (ln, l)) {
+ if (!Lst_Valid (list) || !Lst_NodeValid (ln, list)) {
return (FAILURE);
}
/*
* unlink it from the list
*/
- if (lNode->nextPtr != NULL) {
- lNode->nextPtr->prevPtr = lNode->prevPtr;
+ if (ln->nextPtr != NULL) {
+ ln->nextPtr->prevPtr = ln->prevPtr;
}
- if (lNode->prevPtr != NULL) {
- lNode->prevPtr->nextPtr = lNode->nextPtr;
+ if (ln->prevPtr != NULL) {
+ ln->prevPtr->nextPtr = ln->nextPtr;
}
/*
* if either the firstPtr or lastPtr of the list point to this node,
* adjust them accordingly
*/
- if (list->firstPtr == lNode) {
- list->firstPtr = lNode->nextPtr;
+ if (list->firstPtr == ln) {
+ list->firstPtr = ln->nextPtr;
}
- if (list->lastPtr == lNode) {
- list->lastPtr = lNode->prevPtr;
+ if (list->lastPtr == ln) {
+ list->lastPtr = ln->prevPtr;
}
/*
@@ -101,19 +99,19 @@
* previous one was non-existent (prevPtr == NULL), we set the
* end to be Unknown, since it is.
*/
- if (list->isOpen && (list->curPtr == lNode)) {
+ if (list->isOpen && (list->curPtr == ln)) {
list->curPtr = list->prevPtr;
if (list->curPtr == NULL) {
- list->atEnd = Unknown;
+ list->atEnd = LstUnknown;
}
}
/*
* the only way firstPtr can still point to ln is if ln is the last
- * node on the list (the list is circular, so lNode->nextptr == lNode in
+ * node on the list (the list is circular, so ln->nextptr == ln in
* this case). The list is, therefore, empty and is marked as such
*/
- if (list->firstPtr == lNode) {
+ if (list->firstPtr == ln) {
list->firstPtr = NULL;
}
@@ -121,12 +119,11 @@
* note that the datum is unmolested. The caller must free it as
* necessary and as expected.
*/
- if (lNode->useCount == 0) {
- free (ln);
+ if (ln->useCount == 0) {
+ free(ln);
} else {
- lNode->flags |= LN_DELETED;
+ ln->flags |= LN_DELETED;
}
return (SUCCESS);
}
-
Index: lst.lib/lstReplace.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstReplace.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- lst.lib/lstReplace.c 26 Nov 2004 12:17:23 -0000 1.10
+++ lst.lib/lstReplace.c 29 Nov 2004 08:38:16 -0000 1.11
@@ -46,7 +46,8 @@
* Replace the datum in a node with a new datum
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -68,8 +69,7 @@
if (ln == NULL) {
return (FAILURE);
} else {
- ((ListNode) ln)->datum = d;
+ ln->datum = d;
return (SUCCESS);
}
}
-
Index: lst.lib/lstSucc.c
===================================================================
RCS file: /usr/home/okumoto/Work/make/fbsd-cvs/src/usr.bin/make/lst.lib/lstSucc.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- lst.lib/lstSucc.c 26 Nov 2004 12:17:23 -0000 1.9
+++ lst.lib/lstSucc.c 29 Nov 2004 08:38:16 -0000 1.10
@@ -46,7 +46,8 @@
* return the successor to a given node
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -70,6 +71,6 @@
if (ln == NULL) {
return (NULL);
} else {
- return ((LstNode) ((ListNode) ln)->nextPtr);
+ return (ln->nextPtr);
}
}
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
[
Date Index][
Thread Index]