Module Name: src
Committed By: rillig
Date: Fri Aug 21 07:00:32 UTC 2020
Modified Files:
src/usr.bin/make: lst.c lst.h
Log Message:
make(1): remove type information from local variables in list library
Every node in this file is of type LstNode, which makes the 'l' in the
name 'ln' redundant. The name 'ln' is quite close to the name 'l',
which in turn can easily be confused with the digit '1'. Therefore,
rename 'l' to 'list' and 'ln' to 'node'.
To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/usr.bin/make/lst.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/make/lst.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.15 src/usr.bin/make/lst.c:1.16
--- src/usr.bin/make/lst.c:1.15 Fri Aug 21 06:38:29 2020
+++ src/usr.bin/make/lst.c Fri Aug 21 07:00:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.15 2020/08/21 06:38:29 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.16 2020/08/21 07:00:32 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -38,11 +38,11 @@
#include "make_malloc.h"
#ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.15 2020/08/21 06:38:29 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.16 2020/08/21 07:00:32 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.15 2020/08/21 06:38:29 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.16 2020/08/21 07:00:32 rillig Exp $");
#endif /* not lint */
#endif
@@ -76,49 +76,49 @@ struct List {
/* Return TRUE if the list is valid. */
static Boolean
-LstValid(Lst l)
+LstValid(Lst list)
{
- return l != NULL;
+ return list != NULL;
}
/* Return TRUE if the list node is valid. */
static Boolean
-LstNodeValid(LstNode ln)
+LstNodeValid(LstNode node)
{
- return ln != NULL;
+ return node != NULL;
}
static LstNode
LstNodeNew(void *datum)
{
- LstNode ln = bmake_malloc(sizeof *ln);
+ LstNode node = bmake_malloc(sizeof *node);
/* prev will be initialized by the calling code. */
/* next will be initialized by the calling code. */
- ln->useCount = 0;
- ln->deleted = FALSE;
- ln->datum = datum;
- return ln;
+ node->useCount = 0;
+ node->deleted = FALSE;
+ node->datum = datum;
+ return node;
}
/* Return TRUE if the list is empty. */
static Boolean
-LstIsEmpty(Lst l)
+LstIsEmpty(Lst list)
{
- return l->first == NULL;
+ return list->first == NULL;
}
/* Create and initialize a new, empty list. */
Lst
Lst_Init(void)
{
- Lst nList = bmake_malloc(sizeof *nList);
+ Lst list = bmake_malloc(sizeof *list);
- nList->first = NULL;
- nList->last = NULL;
- nList->isOpen = FALSE;
- nList->lastAccess = Unknown;
+ list->first = NULL;
+ list->last = NULL;
+ list->isOpen = FALSE;
+ list->lastAccess = Unknown;
- return nList;
+ return list;
}
/* Duplicate an entire list, usually by copying the datum pointers.
@@ -126,35 +126,34 @@ Lst_Init(void)
* old datum, usually by creating a copy of it.
* Return the new list, or NULL on failure. */
Lst
-Lst_Duplicate(Lst l, DuplicateProc *copyProc)
+Lst_Duplicate(Lst list, DuplicateProc *copyProc)
{
- Lst nl;
- LstNode ln;
- Lst list = l;
+ Lst newList;
+ LstNode node;
- if (!LstValid(l)) {
+ if (!LstValid(list)) {
return NULL;
}
- nl = Lst_Init();
- if (nl == NULL) {
+ newList = Lst_Init();
+ if (newList == NULL) {
return NULL;
}
- ln = list->first;
- while (ln != NULL) {
+ node = list->first;
+ while (node != NULL) {
if (copyProc != NULL) {
- if (Lst_AtEnd(nl, copyProc(ln->datum)) == FAILURE) {
+ if (Lst_AtEnd(newList, copyProc(node->datum)) == FAILURE) {
return NULL;
}
- } else if (Lst_AtEnd(nl, ln->datum) == FAILURE) {
+ } else if (Lst_AtEnd(newList, node->datum) == FAILURE) {
return NULL;
}
- ln = ln->next;
+ node = node->next;
}
- return nl;
+ return newList;
}
/* Destroy a list and free all its resources. If the freeProc is given, it is
@@ -162,8 +161,8 @@ Lst_Duplicate(Lst l, DuplicateProc *copy
void
Lst_Destroy(Lst list, FreeProc *freeProc)
{
- LstNode ln;
- LstNode tln = NULL;
+ LstNode node;
+ LstNode next = NULL;
if (list == NULL)
return;
@@ -177,15 +176,15 @@ Lst_Destroy(Lst list, FreeProc *freeProc
}
if (freeProc) {
- for (ln = list->first; ln != NULL; ln = tln) {
- tln = ln->next;
- freeProc(ln->datum);
- free(ln);
+ for (node = list->first; node != NULL; node = next) {
+ next = node->next;
+ freeProc(node->datum);
+ free(node);
}
} else {
- for (ln = list->first; ln != NULL; ln = tln) {
- tln = ln->next;
- free(ln);
+ for (node = list->first; node != NULL; node = next) {
+ next = node->next;
+ free(node);
}
}
@@ -199,40 +198,37 @@ Lst_Destroy(Lst list, FreeProc *freeProc
/* Insert a new node with the given piece of data before the given node in the
* given list. */
ReturnStatus
-Lst_InsertBefore(Lst l, LstNode ln, void *d)
+Lst_InsertBefore(Lst list, LstNode node, void *datum)
{
- LstNode nLNode; /* new lnode for d */
- LstNode lNode = ln;
- Lst list = l;
-
+ LstNode newNode;
/*
* check validity of arguments
*/
- if (LstValid(l) && (LstIsEmpty(l) && ln == NULL))
+ if (LstValid(list) && (LstIsEmpty(list) && node == NULL))
goto ok;
- if (!LstValid(l) || LstIsEmpty(l) || !LstNodeValid(ln)) {
+ if (!LstValid(list) || LstIsEmpty(list) || !LstNodeValid(node)) {
return FAILURE;
}
ok:
- nLNode = LstNodeNew(d);
+ newNode = LstNodeNew(datum);
- if (ln == NULL) {
- nLNode->prev = nLNode->next = NULL;
- list->first = list->last = nLNode;
+ if (node == NULL) {
+ newNode->prev = newNode->next = NULL;
+ list->first = list->last = newNode;
} else {
- nLNode->prev = lNode->prev;
- nLNode->next = lNode;
+ newNode->prev = node->prev;
+ newNode->next = node;
- if (nLNode->prev != NULL) {
- nLNode->prev->next = nLNode;
+ if (newNode->prev != NULL) {
+ newNode->prev->next = newNode;
}
- lNode->prev = nLNode;
+ node->prev = newNode;
- if (lNode == list->first) {
- list->first = nLNode;
+ if (node == list->first) {
+ list->first = newNode;
}
}
@@ -242,39 +238,34 @@ Lst_InsertBefore(Lst l, LstNode ln, void
/* Insert a new node with the given piece of data after the given node in the
* given list. */
ReturnStatus
-Lst_InsertAfter(Lst l, LstNode ln, void *d)
+Lst_InsertAfter(Lst list, LstNode node, void *datum)
{
- Lst list;
- LstNode lNode;
LstNode nLNode;
- if (LstValid(l) && (ln == NULL && LstIsEmpty(l))) {
+ if (LstValid(list) && (node == NULL && LstIsEmpty(list))) {
goto ok;
}
- if (!LstValid(l) || LstIsEmpty(l) || !LstNodeValid(ln)) {
+ if (!LstValid(list) || LstIsEmpty(list) || !LstNodeValid(node)) {
return FAILURE;
}
ok:
- list = l;
- lNode = ln;
+ nLNode = LstNodeNew(datum);
- nLNode = LstNodeNew(d);
-
- if (lNode == NULL) {
+ if (node == NULL) {
nLNode->next = nLNode->prev = NULL;
list->first = list->last = nLNode;
} else {
- nLNode->prev = lNode;
- nLNode->next = lNode->next;
+ nLNode->prev = node;
+ nLNode->next = node->next;
- lNode->next = nLNode;
+ node->next = nLNode;
if (nLNode->next != NULL) {
nLNode->next->prev = nLNode;
}
- if (lNode == list->last) {
+ if (node == list->last) {
list->last = nLNode;
}
}
@@ -284,54 +275,47 @@ Lst_InsertAfter(Lst l, LstNode ln, void
/* Add a piece of data at the front of the given list. */
ReturnStatus
-Lst_AtFront(Lst l, void *d)
+Lst_AtFront(Lst list, void *datum)
{
- LstNode front;
-
- front = Lst_First(l);
- return Lst_InsertBefore(l, front, d);
+ LstNode front = Lst_First(list);
+ return Lst_InsertBefore(list, front, datum);
}
/* Add a piece of data at the end of the given list. */
ReturnStatus
-Lst_AtEnd(Lst l, void *d)
+Lst_AtEnd(Lst list, void *datum)
{
- LstNode end;
-
- end = Lst_Last(l);
- return Lst_InsertAfter(l, end, d);
+ LstNode end = Lst_Last(list);
+ return Lst_InsertAfter(list, end, datum);
}
/* Remove the given node from the given list.
* The datum stored in the node must be freed by the caller, if necessary. */
void
-Lst_RemoveS(Lst l, LstNode ln)
+Lst_RemoveS(Lst list, LstNode node)
{
- Lst list = l;
- LstNode lNode = ln;
-
- assert(LstValid(l));
- assert(LstNodeValid(ln));
+ assert(LstValid(list));
+ assert(LstNodeValid(node));
/*
* unlink it from the list
*/
- if (lNode->next != NULL) {
- lNode->next->prev = lNode->prev;
+ if (node->next != NULL) {
+ node->next->prev = node->prev;
}
- if (lNode->prev != NULL) {
- lNode->prev->next = lNode->next;
+ if (node->prev != NULL) {
+ node->prev->next = node->next;
}
/*
* if either the first or last of the list point to this node,
* adjust them accordingly
*/
- if (list->first == lNode) {
- list->first = lNode->next;
+ if (list->first == node) {
+ list->first = node->next;
}
- if (list->last == lNode) {
- list->last = lNode->prev;
+ if (list->last == node) {
+ list->last = node->prev;
}
/*
@@ -340,7 +324,7 @@ Lst_RemoveS(Lst l, LstNode ln)
* previous one was non-existent (prev == NULL), we set the
* end to be Unknown, since it is.
*/
- if (list->isOpen && (list->curr == lNode)) {
+ if (list->isOpen && list->curr == node) {
list->curr = list->prev;
if (list->curr == NULL) {
list->lastAccess = Unknown;
@@ -351,18 +335,18 @@ Lst_RemoveS(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 (node->useCount == 0) {
+ free(node);
} else {
- lNode->deleted = TRUE;
+ node->deleted = TRUE;
}
}
/* Replace the datum in the given node with the new datum. */
void
-Lst_ReplaceS(LstNode ln, void *d)
+Lst_ReplaceS(LstNode node, void *datum)
{
- ln->datum = d;
+ node->datum = datum;
}
@@ -373,55 +357,55 @@ Lst_ReplaceS(LstNode ln, void *d)
/* Return the first node from the given list, or NULL if the list is empty or
* invalid. */
LstNode
-Lst_First(Lst l)
+Lst_First(Lst list)
{
- if (!LstValid(l) || LstIsEmpty(l)) {
+ if (!LstValid(list) || LstIsEmpty(list)) {
return NULL;
} else {
- return l->first;
+ return list->first;
}
}
/* Return the last node from the given list, or NULL if the list is empty or
* invalid. */
LstNode
-Lst_Last(Lst l)
+Lst_Last(Lst list)
{
- if (!LstValid(l) || LstIsEmpty(l)) {
+ if (!LstValid(list) || LstIsEmpty(list)) {
return NULL;
} else {
- return l->last;
+ return list->last;
}
}
/* Return the successor to the given node on its list, or NULL. */
LstNode
-Lst_Succ(LstNode ln)
+Lst_Succ(LstNode node)
{
- if (ln == NULL) {
+ if (node == NULL) {
return NULL;
} else {
- return ln->next;
+ return node->next;
}
}
/* Return the predecessor to the given node on its list, or NULL. */
LstNode
-Lst_Prev(LstNode ln)
+Lst_Prev(LstNode node)
{
- if (ln == NULL) {
+ if (node == NULL) {
return NULL;
} else {
- return ln->prev;
+ return node->prev;
}
}
/* Return the datum stored in the given node, or NULL if the node is invalid. */
void *
-Lst_Datum(LstNode ln)
+Lst_Datum(LstNode node)
{
- if (ln != NULL) {
- return ln->datum;
+ if (node != NULL) {
+ return node->datum;
} else {
return NULL;
}
@@ -434,64 +418,63 @@ Lst_Datum(LstNode ln)
/* Return TRUE if the given list is empty or invalid. */
Boolean
-Lst_IsEmpty(Lst l)
+Lst_IsEmpty(Lst list)
{
- return !LstValid(l) || LstIsEmpty(l);
+ return !LstValid(list) || LstIsEmpty(list);
}
/* Return the first node from the given list for which the given comparison
* function returns 0, or NULL if none of the nodes matches. */
LstNode
-Lst_Find(Lst l, const void *d, int (*cProc)(const void *, const void *))
+Lst_Find(Lst list, const void *cmpData, int (*cmp)(const void *, const void *))
{
- return Lst_FindFrom(l, Lst_First(l), d, cProc);
+ return Lst_FindFrom(list, Lst_First(list), cmpData, cmp);
}
/* Return the first node from the given list, starting at the given node, for
* which the given comparison function returns 0, or NULL if none of the nodes
* matches. */
LstNode
-Lst_FindFrom(Lst l, LstNode ln, const void *d,
- int (*cProc)(const void *, const void *))
+Lst_FindFrom(Lst list, LstNode node, const void *cmpData,
+ int (*cmp)(const void *, const void *))
{
LstNode tln;
- if (!LstValid(l) || LstIsEmpty(l) || !LstNodeValid(ln)) {
+ if (!LstValid(list) || LstIsEmpty(list) || !LstNodeValid(node)) {
return NULL;
}
- tln = ln;
+ tln = node;
do {
- if ((*cProc)(tln->datum, d) == 0)
+ if ((*cmp)(tln->datum, cmpData) == 0)
return tln;
tln = tln->next;
- } while (tln != ln && tln != NULL);
+ } while (tln != node && tln != NULL);
return NULL;
}
/* Return the first node that contains the given datum, or NULL. */
LstNode
-Lst_Member(Lst l, void *d)
+Lst_Member(Lst list, void *datum)
{
- Lst list = l;
- LstNode lNode;
+ LstNode node;
if (list == NULL) {
return NULL;
}
- lNode = list->first;
- if (lNode == NULL) {
+ node = list->first;
+ if (node == NULL) {
return NULL;
}
do {
- if (lNode->datum == d) {
- return lNode;
+ if (node->datum == datum) {
+ return node;
}
- lNode = lNode->next;
- } while (lNode != NULL && lNode != list->first);
+ node = node->next;
+ } while (node != NULL && node != list->first);
return NULL;
}
@@ -500,20 +483,19 @@ Lst_Member(Lst l, void *d)
* should return 0 if traversal should continue and non-zero if it should
* abort. */
int
-Lst_ForEach(Lst l, int (*proc)(void *, void *), void *d)
+Lst_ForEach(Lst list, int (*proc)(void *, void *), void *procData)
{
- return Lst_ForEachFrom(l, Lst_First(l), proc, d);
+ return Lst_ForEachFrom(list, Lst_First(list), proc, procData);
}
/* Apply the given function to each element of the given list, starting from
* the given node. The function should return 0 if traversal should continue,
* and non-zero if it should abort. */
int
-Lst_ForEachFrom(Lst l, LstNode ln, int (*proc)(void *, void *),
- void *d)
+Lst_ForEachFrom(Lst list, LstNode node,
+ int (*proc)(void *, void *), void *procData)
{
- LstNode tln = ln;
- Lst list = l;
+ LstNode tln = node;
LstNode next;
Boolean done;
int result;
@@ -540,7 +522,7 @@ Lst_ForEachFrom(Lst l, LstNode ln, int (
done = (next == NULL || next == list->first);
(void)tln->useCount++;
- result = (*proc)(tln->datum, d);
+ result = (*proc)(tln->datum, procData);
(void)tln->useCount--;
/*
@@ -570,22 +552,20 @@ Lst_ForEachFrom(Lst l, LstNode ln, int (
* longer usable.
*
* Input:
- * 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 the list nodes should be duplicated
* LST_CONCLINK if the list nodes should just be relinked
*/
ReturnStatus
-Lst_Concat(Lst l1, Lst l2, int flags)
+Lst_Concat(Lst list1, Lst list2, int flags)
{
- LstNode ln; /* original LstNode */
- LstNode nln; /* new LstNode */
- LstNode last; /* the last element in the list. Keeps
- * bookkeeping until the end */
- Lst list1 = l1;
- Lst list2 = l2;
+ LstNode node; /* original node */
+ LstNode newNode;
+ LstNode last; /* the last element in the list.
+ * Keeps bookkeeping until the end */
- if (!LstValid(l1) || !LstValid(l2)) {
+ if (!LstValid(list1) || !LstValid(list2)) {
return FAILURE;
}
@@ -607,30 +587,33 @@ Lst_Concat(Lst l1, Lst l2, int flags)
}
list1->last = list2->last;
}
- free(l2);
+ free(list2);
} else if (list2->first != NULL) {
/*
* We set the 'next' of the last element of list 2 to be nil to make
* the loop less difficult. The loop simply goes through the entire
* second list creating new LstNodes and filling in the 'next', and
- * 'prev' 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
+ * 'prev' 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 nil,
* the first list must have been empty so the newly-created node is
* made the first node of the list.
*/
list2->last->next = NULL;
- for (last = list1->last, ln = list2->first; ln != NULL; ln = ln->next) {
- nln = LstNodeNew(ln->datum);
+ for (last = list1->last, node = list2->first;
+ node != NULL;
+ node = node->next)
+ {
+ newNode = LstNodeNew(node->datum);
if (last != NULL) {
- last->next = nln;
+ last->next = newNode;
} else {
- list1->first = nln;
+ list1->first = newNode;
}
- nln->prev = last;
- last = nln;
+ newNode->prev = last;
+ last = newNode;
}
/*
@@ -658,14 +641,14 @@ Lst_Concat(Lst l1, Lst l2, int flags)
/* Open a list for sequential access. A list can still be searched, etc.,
* without confusing these functions. */
ReturnStatus
-Lst_Open(Lst l)
+Lst_Open(Lst list)
{
- if (LstValid(l) == FALSE) {
+ if (!LstValid(list)) {
return FAILURE;
}
- l->isOpen = TRUE;
- l->lastAccess = LstIsEmpty(l) ? Head : Unknown;
- l->curr = NULL;
+ list->isOpen = TRUE;
+ list->lastAccess = LstIsEmpty(list) ? Head : Unknown;
+ list->curr = NULL;
return SUCCESS;
}
@@ -673,25 +656,24 @@ Lst_Open(Lst l)
/* Open a list for sequential access. A list can still be searched, etc.,
* without confusing these functions. */
void
-Lst_OpenS(Lst l)
+Lst_OpenS(Lst list)
{
- assert(LstValid(l));
- assert(!l->isOpen);
+ assert(LstValid(list));
+ assert(!list->isOpen);
- l->isOpen = TRUE;
- l->lastAccess = LstIsEmpty(l) ? Head : Unknown;
- l->curr = NULL;
+ list->isOpen = TRUE;
+ list->lastAccess = LstIsEmpty(list) ? Head : Unknown;
+ list->curr = NULL;
}
/* Return the next node for the given list, or NULL if the end has been
* reached. */
LstNode
-Lst_NextS(Lst l)
+Lst_NextS(Lst list)
{
- LstNode tln;
- Lst list = l;
+ LstNode node;
- assert(LstValid(l));
+ assert(LstValid(list));
assert(list->isOpen);
list->prev = list->curr;
@@ -703,17 +685,17 @@ Lst_NextS(Lst l)
* Then we want to start this thing off in the right
* direction -- at the start with lastAccess being Middle.
*/
- list->curr = tln = list->first;
+ list->curr = node = list->first;
list->lastAccess = Middle;
} else {
- tln = NULL;
+ node = NULL;
list->lastAccess = Tail;
}
} else {
- tln = list->curr->next;
- list->curr = tln;
+ node = list->curr->next;
+ list->curr = node;
- if (tln == list->first || tln == NULL) {
+ if (node == list->first || node == NULL) {
/*
* If back at the front, then we've hit the end...
*/
@@ -726,17 +708,16 @@ Lst_NextS(Lst l)
}
}
- return tln;
+ return node;
}
/* Close a list which was opened for sequential access. */
void
-Lst_CloseS(Lst l)
+Lst_CloseS(Lst list)
{
- Lst list = l;
-
- assert(LstValid(l));
+ assert(LstValid(list));
assert(list->isOpen);
+
list->isOpen = FALSE;
list->lastAccess = Unknown;
}
@@ -748,29 +729,29 @@ Lst_CloseS(Lst l)
/* Add the datum to the tail of the given list. */
ReturnStatus
-Lst_EnQueue(Lst l, void *d)
+Lst_EnQueue(Lst list, void *datum)
{
- if (LstValid(l) == FALSE) {
+ if (!LstValid(list)) {
return FAILURE;
}
- return Lst_InsertAfter(l, Lst_Last(l), d);
+ return Lst_InsertAfter(list, Lst_Last(list), datum);
}
/* Remove and return the datum at the head of the given list, or NULL if the
* list is empty. */
void *
-Lst_DeQueue(Lst l)
+Lst_DeQueue(Lst list)
{
- void *rd;
- LstNode tln;
+ LstNode head;
+ void *datum;
- tln = Lst_First(l);
- if (tln == NULL) {
+ head = Lst_First(list);
+ if (head == NULL) {
return NULL;
}
- rd = tln->datum;
- Lst_RemoveS(l, tln);
- return rd;
+ datum = head->datum;
+ Lst_RemoveS(list, head);
+ return datum;
}
Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.26 src/usr.bin/make/lst.h:1.27
--- src/usr.bin/make/lst.h:1.26 Fri Aug 21 04:42:02 2020
+++ src/usr.bin/make/lst.h Fri Aug 21 07:00:32 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.h,v 1.26 2020/08/21 04:42:02 rillig Exp $ */
+/* $NetBSD: lst.h,v 1.27 2020/08/21 07:00:32 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -149,7 +149,7 @@ void *Lst_Datum(LstNode);
LstNode Lst_Find(Lst, const void *, int (*)(const void *, const void *));
/* Find an element starting from somewhere */
LstNode Lst_FindFrom(Lst, LstNode, const void *,
- int (*cProc)(const void *, const void *));
+ int (*cmp)(const void *, const void *));
/*
* See if the given datum is on the list. Returns the LstNode containing
* the datum