summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2004-11-29 08:38:16 +0000
committerharti <harti@FreeBSD.org>2004-11-29 08:38:16 +0000
commitd5b4f65a8216257f046436c3c0ac72f8c8099131 (patch)
treebde3042541b06db5578bb35a6e09b846114bd06c /usr.bin
parentf0a7bdfddcf63921df4dcc4d26441e33dfdf7630 (diff)
downloadFreeBSD-src-d5b4f65a8216257f046436c3c0ac72f8c8099131.zip
FreeBSD-src-d5b4f65a8216257f046436c3c0ac72f8c8099131.tar.gz
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.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/make/Makefile2
-rw-r--r--usr.bin/make/lst.h60
-rw-r--r--usr.bin/make/lst.lib/lstAppend.c28
-rw-r--r--usr.bin/make/lst.lib/lstAtEnd.c3
-rw-r--r--usr.bin/make/lst.lib/lstAtFront.c3
-rw-r--r--usr.bin/make/lst.lib/lstClose.c11
-rw-r--r--usr.bin/make/lst.lib/lstConcat.c32
-rw-r--r--usr.bin/make/lst.lib/lstDatum.c7
-rw-r--r--usr.bin/make/lst.lib/lstDeQueue.c13
-rw-r--r--usr.bin/make/lst.lib/lstDestroy.c16
-rw-r--r--usr.bin/make/lst.lib/lstDupl.c10
-rw-r--r--usr.bin/make/lst.lib/lstEnQueue.c5
-rw-r--r--usr.bin/make/lst.lib/lstFind.c3
-rw-r--r--usr.bin/make/lst.lib/lstFindFrom.c13
-rw-r--r--usr.bin/make/lst.lib/lstFirst.c7
-rw-r--r--usr.bin/make/lst.lib/lstForEach.c3
-rw-r--r--usr.bin/make/lst.lib/lstForEachFrom.c31
-rw-r--r--usr.bin/make/lst.lib/lstInit.c11
-rw-r--r--usr.bin/make/lst.lib/lstInsert.c23
-rw-r--r--usr.bin/make/lst.lib/lstInt.h108
-rw-r--r--usr.bin/make/lst.lib/lstIsAtEnd.c10
-rw-r--r--usr.bin/make/lst.lib/lstIsEmpty.c71
-rw-r--r--usr.bin/make/lst.lib/lstLast.c12
-rw-r--r--usr.bin/make/lst.lib/lstMember.c14
-rw-r--r--usr.bin/make/lst.lib/lstNext.c23
-rw-r--r--usr.bin/make/lst.lib/lstOpen.c11
-rw-r--r--usr.bin/make/lst.lib/lstRemove.c41
-rw-r--r--usr.bin/make/lst.lib/lstReplace.c6
-rw-r--r--usr.bin/make/lst.lib/lstSucc.c5
29 files changed, 227 insertions, 355 deletions
diff --git a/usr.bin/make/Makefile b/usr.bin/make/Makefile
index bb67818..63a028f 100644
--- a/usr.bin/make/Makefile
+++ b/usr.bin/make/Makefile
@@ -9,7 +9,7 @@ SRCS= arch.c buf.c compat.c cond.c dir.c for.c hash.c job.c main.c \
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
diff --git a/usr.bin/make/lst.h b/usr.bin/make/lst.h
index da3e7166..1842061 100644
--- a/usr.bin/make/lst.h
+++ b/usr.bin/make/lst.h
@@ -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_Init(Boolean);
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
@@ -153,4 +186,23 @@ 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_ */
diff --git a/usr.bin/make/lst.lib/lstAppend.c b/usr.bin/make/lst.lib/lstAppend.c
index 48093f6..9ff3f86 100644
--- a/usr.bin/make/lst.lib/lstAppend.c
+++ b/usr.bin/make/lst.lib/lstAppend.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* 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 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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 @@ Lst_Append (Lst l, LstNode ln, void *d)
}
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;
}
}
diff --git a/usr.bin/make/lst.lib/lstAtEnd.c b/usr.bin/make/lst.lib/lstAtEnd.c
index 9b4c7de..02d44d3 100644
--- a/usr.bin/make/lst.lib/lstAtEnd.c
+++ b/usr.bin/make/lst.lib/lstAtEnd.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Add a node at the end of the list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
diff --git a/usr.bin/make/lst.lib/lstAtFront.c b/usr.bin/make/lst.lib/lstAtFront.c
index 81a4908..d24b8ce 100644
--- a/usr.bin/make/lst.lib/lstAtFront.c
+++ b/usr.bin/make/lst.lib/lstAtFront.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Add a node at the front of the list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
diff --git a/usr.bin/make/lst.lib/lstClose.c b/usr.bin/make/lst.lib/lstClose.c
index 11fb07a..58745b8 100644
--- a/usr.bin/make/lst.lib/lstClose.c
+++ b/usr.bin/make/lst.lib/lstClose.c
@@ -51,7 +51,8 @@ __FBSDID("$FreeBSD$");
* used to determine when to stop.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -70,13 +71,11 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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;
}
}
-
diff --git a/usr.bin/make/lst.lib/lstConcat.c b/usr.bin/make/lst.lib/lstConcat.c
index 94590df..330425f 100644
--- a/usr.bin/make/lst.lib/lstConcat.c
+++ b/usr.bin/make/lst.lib/lstConcat.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Function to concatentate two lists.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -62,8 +63,8 @@ __FBSDID("$FreeBSD$");
* 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 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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 @@ Lst_Concat(Lst l1, Lst l2, int flags)
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 @@ Lst_Concat(Lst l1, Lst l2, int flags)
ln != NULL;
ln = ln->nextPtr)
{
- PAlloc (nln, ListNode);
+ nln = emalloc(sizeof(*nln));
nln->datum = ln->datum;
if (last != NULL) {
last->nextPtr = nln;
diff --git a/usr.bin/make/lst.lib/lstDatum.c b/usr.bin/make/lst.lib/lstDatum.c
index 4cb6708..5a8f874 100644
--- a/usr.bin/make/lst.lib/lstDatum.c
+++ b/usr.bin/make/lst.lib/lstDatum.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Return the datum associated with a list node.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -66,8 +67,8 @@ Lst_Datum(LstNode ln)
{
if (ln != NULL) {
- return (((ListNode)ln)->datum);
+ return (ln->datum);
} else {
- return ((void *) NULL);
+ return (NULL);
}
}
diff --git a/usr.bin/make/lst.lib/lstDeQueue.c b/usr.bin/make/lst.lib/lstDeQueue.c
index 1bd494e..7cfb476 100644
--- a/usr.bin/make/lst.lib/lstDeQueue.c
+++ b/usr.bin/make/lst.lib/lstDeQueue.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* 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 @@ void *
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);
}
diff --git a/usr.bin/make/lst.lib/lstDestroy.c b/usr.bin/make/lst.lib/lstDestroy.c
index 4e511d2..8942ddf 100644
--- a/usr.bin/make/lst.lib/lstDestroy.c
+++ b/usr.bin/make/lst.lib/lstDestroy.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Nuke a list and all its resources
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -64,13 +65,12 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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 @@ Lst_Destroy(Lst l, void (*freeProc)(void *))
if (list->lastPtr != NULL)
list->lastPtr->nextPtr = NULL;
else {
- free (l);
+ free (list);
return;
}
@@ -99,5 +99,5 @@ Lst_Destroy(Lst l, void (*freeProc)(void *))
}
}
- free (l);
+ free (list);
}
diff --git a/usr.bin/make/lst.lib/lstDupl.c b/usr.bin/make/lst.lib/lstDupl.c
index 0c3d750..4c1842d 100644
--- a/usr.bin/make/lst.lib/lstDupl.c
+++ b/usr.bin/make/lst.lib/lstDupl.c
@@ -47,7 +47,8 @@ __FBSDID("$FreeBSD$");
* elements.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -67,13 +68,12 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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);
}
diff --git a/usr.bin/make/lst.lib/lstEnQueue.c b/usr.bin/make/lst.lib/lstEnQueue.c
index de1b533..bfd00c23 100644
--- a/usr.bin/make/lst.lib/lstEnQueue.c
+++ b/usr.bin/make/lst.lib/lstEnQueue.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* 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 @@ ReturnStatus
Lst_EnQueue(Lst l, void *d)
{
- if (LstValid (l) == FALSE) {
+ if (Lst_Valid (l) == FALSE) {
return (FAILURE);
}
diff --git a/usr.bin/make/lst.lib/lstFind.c b/usr.bin/make/lst.lib/lstFind.c
index 8572847..d27907c 100644
--- a/usr.bin/make/lst.lib/lstFind.c
+++ b/usr.bin/make/lst.lib/lstFind.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Find a node on a list.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
diff --git a/usr.bin/make/lst.lib/lstFindFrom.c b/usr.bin/make/lst.lib/lstFindFrom.c
index cecaef7..25b8c13 100644
--- a/usr.bin/make/lst.lib/lstFindFrom.c
+++ b/usr.bin/make/lst.lib/lstFindFrom.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* 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 @@ __FBSDID("$FreeBSD$");
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 @@ Lst_FindFrom(Lst l, LstNode ln, void *d, int (*cProc)(void *, void *))
} 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);
}
diff --git a/usr.bin/make/lst.lib/lstFirst.c b/usr.bin/make/lst.lib/lstFirst.c
index daa83fb..05094e7 100644
--- a/usr.bin/make/lst.lib/lstFirst.c
+++ b/usr.bin/make/lst.lib/lstFirst.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Return the first node of a list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -65,9 +66,9 @@ LstNode
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);
}
}
diff --git a/usr.bin/make/lst.lib/lstForEach.c b/usr.bin/make/lst.lib/lstForEach.c
index b3a7e66..ee3e041 100644
--- a/usr.bin/make/lst.lib/lstForEach.c
+++ b/usr.bin/make/lst.lib/lstForEach.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Perform a given function on all elements of a list.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
diff --git a/usr.bin/make/lst.lib/lstForEachFrom.c b/usr.bin/make/lst.lib/lstForEachFrom.c
index 12a31b7..26c5858 100644
--- a/usr.bin/make/lst.lib/lstForEachFrom.c
+++ b/usr.bin/make/lst.lib/lstForEachFrom.c
@@ -47,7 +47,8 @@ __FBSDID("$FreeBSD$");
* a given point.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -65,15 +66,13 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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 @@ Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(void *, void *), void *d)
* 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 @@ Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(void *, void *), void *d)
* - 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);
}
diff --git a/usr.bin/make/lst.lib/lstInit.c b/usr.bin/make/lst.lib/lstInit.c
index da6b7b9..57059a3 100644
--- a/usr.bin/make/lst.lib/lstInit.c
+++ b/usr.bin/make/lst.lib/lstInit.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Initialize a new linked list.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -67,15 +68,15 @@ __FBSDID("$FreeBSD$");
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);
}
diff --git a/usr.bin/make/lst.lib/lstInsert.c b/usr.bin/make/lst.lib/lstInsert.c
index 99fe138..486565e 100644
--- a/usr.bin/make/lst.lib/lstInsert.c
+++ b/usr.bin/make/lst.lib/lstInsert.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Insert a new datum before an old one
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -68,24 +69,22 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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 @@ Lst_Insert(Lst l, LstNode ln, void *d)
}
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;
}
}
diff --git a/usr.bin/make/lst.lib/lstInt.h b/usr.bin/make/lst.lib/lstInt.h
deleted file mode 100644
index cc5e8f3..0000000
--- a/usr.bin/make/lst.lib/lstInt.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 1988, 1989, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Adam de Boor.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: @(#)lstInt.h 8.1 (Berkeley) 6/6/93
- * $FreeBSD$
- */
-
-/*-
- * lstInt.h --
- * Internals for the list library
- */
-#ifndef _LSTINT_H_
-#define _LSTINT_H_
-
-#include "make.h"
-#include "lst.h"
-
-typedef struct ListNode {
- struct ListNode *prevPtr; /* previous element in list */
- struct ListNode *nextPtr; /* next in list */
- int useCount:8, /* Count of functions using the node.
- * node may not be deleted until count
- * goes to 0 */
- flags:8; /* Node status flags */
- void * datum; /* datum associated with this element */
-} *ListNode;
-/*
- * Flags required for synchronization
- */
-#define LN_DELETED 0x0001 /* List node should be removed when done */
-
-typedef enum {
- Head, Middle, Tail, Unknown
-} Where;
-
-typedef struct {
- ListNode firstPtr; /* first node in list */
- ListNode lastPtr; /* last node in list */
- Boolean isCirc; /* true if the list should be considered
- * circular */
-/*
- * fields for sequential access
- */
- Where atEnd; /* Where in the list the last access was */
- Boolean isOpen; /* true if list has been Lst_Open'ed */
- ListNode curPtr; /* current node, if open. NULL if
- * *just* opened */
- ListNode prevPtr; /* Previous node, if open. Used by
- * Lst_Remove */
-} *List;
-
-/*
- * PAlloc (var, ptype) --
- * Allocate a pointer-typedef structure 'ptype' into the variable 'var'
- */
-#define PAlloc(var,ptype) var = (ptype) emalloc (sizeof (*var))
-
-/*
- * LstValid (l) --
- * Return TRUE if the list l is valid
- */
-#define LstValid(l) (((Lst)l == NULL) ? FALSE : TRUE)
-
-/*
- * LstNodeValid (ln, l) --
- * Return TRUE if the LstNode ln is valid with respect to l
- */
-#define LstNodeValid(ln, l) ((((LstNode)ln) == NULL) ? FALSE : TRUE)
-
-/*
- * LstIsEmpty (l) --
- * TRUE if the list l is empty.
- */
-#define LstIsEmpty(l) (((List)l)->firstPtr == NULL)
-
-#endif /* _LSTINT_H_ */
diff --git a/usr.bin/make/lst.lib/lstIsAtEnd.c b/usr.bin/make/lst.lib/lstIsAtEnd.c
index 34d97d0..5f42b70 100644
--- a/usr.bin/make/lst.lib/lstIsAtEnd.c
+++ b/usr.bin/make/lst.lib/lstIsAtEnd.c
@@ -51,7 +51,8 @@ __FBSDID("$FreeBSD$");
* used to determine when to stop.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -73,10 +74,9 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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));
}
diff --git a/usr.bin/make/lst.lib/lstIsEmpty.c b/usr.bin/make/lst.lib/lstIsEmpty.c
deleted file mode 100644
index 06a3661..0000000
--- a/usr.bin/make/lst.lib/lstIsEmpty.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 1988, 1989, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Adam de Boor.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)lstIsEmpty.c 8.1 (Berkeley) 6/6/93
- */
-
-#ifndef lint
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-#endif /* not lint */
-
-/*-
- * LstIsEmpty.c --
- * A single function to decide if a list is empty
- */
-
-#include "lstInt.h"
-
-/*-
- *-----------------------------------------------------------------------
- * Lst_IsEmpty --
- * Return TRUE if the given list is empty.
- *
- * Results:
- * TRUE if the list is empty, FALSE otherwise.
- *
- * Side Effects:
- * None.
- *
- * A list is considered empty if its firstPtr == NULL (or if
- * the list itself is NULLLIST).
- *-----------------------------------------------------------------------
- */
-Boolean
-Lst_IsEmpty(Lst l)
-{
-
- return ( ! LstValid (l) || LstIsEmpty(l));
-}
diff --git a/usr.bin/make/lst.lib/lstLast.c b/usr.bin/make/lst.lib/lstLast.c
index 37f579b..5332b4f 100644
--- a/usr.bin/make/lst.lib/lstLast.c
+++ b/usr.bin/make/lst.lib/lstLast.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Return the last element of a list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -62,13 +63,12 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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);
}
}
-
diff --git a/usr.bin/make/lst.lib/lstMember.c b/usr.bin/make/lst.lib/lstMember.c
index fdf3224..a1158e6 100644
--- a/usr.bin/make/lst.lib/lstMember.c
+++ b/usr.bin/make/lst.lib/lstMember.c
@@ -46,25 +46,25 @@ __FBSDID("$FreeBSD$");
* 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);
}
diff --git a/usr.bin/make/lst.lib/lstNext.c b/usr.bin/make/lst.lib/lstNext.c
index 1f31e61..db112c5 100644
--- a/usr.bin/make/lst.lib/lstNext.c
+++ b/usr.bin/make/lst.lib/lstNext.c
@@ -51,7 +51,8 @@ __FBSDID("$FreeBSD$");
* used to determine when to stop.
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -69,30 +70,28 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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 @@ Lst_Next(Lst l)
/*
* 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);
}
diff --git a/usr.bin/make/lst.lib/lstOpen.c b/usr.bin/make/lst.lib/lstOpen.c
index a35f714..11559ab 100644
--- a/usr.bin/make/lst.lib/lstOpen.c
+++ b/usr.bin/make/lst.lib/lstOpen.c
@@ -50,7 +50,8 @@ __FBSDID("$FreeBSD$");
* 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 @@ ReturnStatus
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);
}
diff --git a/usr.bin/make/lst.lib/lstRemove.c b/usr.bin/make/lst.lib/lstRemove.c
index a37cedd..5da603f 100644
--- a/usr.bin/make/lst.lib/lstRemove.c
+++ b/usr.bin/make/lst.lib/lstRemove.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Remove an element from a list
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -64,35 +65,32 @@ __FBSDID("$FreeBSD$");
*-----------------------------------------------------------------------
*/
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 @@ Lst_Remove(Lst l, LstNode ln)
* 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 @@ Lst_Remove(Lst l, LstNode ln)
* 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);
}
-
diff --git a/usr.bin/make/lst.lib/lstReplace.c b/usr.bin/make/lst.lib/lstReplace.c
index c41dea1..f321583 100644
--- a/usr.bin/make/lst.lib/lstReplace.c
+++ b/usr.bin/make/lst.lib/lstReplace.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* Replace the datum in a node with a new datum
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -68,8 +69,7 @@ Lst_Replace(LstNode ln, void *d)
if (ln == NULL) {
return (FAILURE);
} else {
- ((ListNode) ln)->datum = d;
+ ln->datum = d;
return (SUCCESS);
}
}
-
diff --git a/usr.bin/make/lst.lib/lstSucc.c b/usr.bin/make/lst.lib/lstSucc.c
index ff1dd68..edd3961 100644
--- a/usr.bin/make/lst.lib/lstSucc.c
+++ b/usr.bin/make/lst.lib/lstSucc.c
@@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$");
* return the successor to a given node
*/
-#include "lstInt.h"
+#include "make.h"
+#include "lst.h"
/*-
*-----------------------------------------------------------------------
@@ -70,6 +71,6 @@ Lst_Succ(LstNode ln)
if (ln == NULL) {
return (NULL);
} else {
- return ((LstNode) ((ListNode) ln)->nextPtr);
+ return (ln->nextPtr);
}
}
OpenPOWER on IntegriCloud