Module Name: src
Committed By: rillig
Date: Tue Nov 24 19:46:29 UTC 2020
Modified Files:
src/usr.bin/make: lst.c lst.h
Log Message:
make(1): indent list functions with tabs instead of spaces
To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/usr.bin/make/lst.c
cvs rdiff -u -r1.85 -r1.86 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.92 src/usr.bin/make/lst.c:1.93
--- src/usr.bin/make/lst.c:1.92 Sun Nov 8 01:29:26 2020
+++ src/usr.bin/make/lst.c Tue Nov 24 19:46:29 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.92 2020/11/08 01:29:26 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.93 2020/11/24 19:46:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -34,42 +34,44 @@
#include "make.h"
-MAKE_RCSID("$NetBSD: lst.c,v 1.92 2020/11/08 01:29:26 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.93 2020/11/24 19:46:29 rillig Exp $");
static ListNode *
LstNodeNew(ListNode *prev, ListNode *next, void *datum)
{
- ListNode *ln = bmake_malloc(sizeof *ln);
- ln->prev = prev;
- ln->next = next;
- ln->datum = datum;
- return ln;
+ ListNode *ln = bmake_malloc(sizeof *ln);
+
+ ln->prev = prev;
+ ln->next = next;
+ ln->datum = datum;
+
+ return ln;
}
/* Create and initialize a new, empty list. */
List *
Lst_New(void)
{
- List *list = bmake_malloc(sizeof *list);
+ List *list = bmake_malloc(sizeof *list);
- list->first = NULL;
- list->last = NULL;
+ list->first = NULL;
+ list->last = NULL;
- return list;
+ return list;
}
/* Free a list and all its nodes. The node data are not freed though. */
void
Lst_Free(List *list)
{
- ListNode *ln, *next;
+ ListNode *ln, *next;
- for (ln = list->first; ln != NULL; ln = next) {
- next = ln->next;
- free(ln);
- }
+ for (ln = list->first; ln != NULL; ln = next) {
+ next = ln->next;
+ free(ln);
+ }
- free(list);
+ free(list);
}
/* Destroy a list and free all its resources. The freeProc is called with the
@@ -77,71 +79,71 @@ Lst_Free(List *list)
void
Lst_Destroy(List *list, LstFreeProc freeProc)
{
- ListNode *ln, *next;
+ ListNode *ln, *next;
- for (ln = list->first; ln != NULL; ln = next) {
- next = ln->next;
- freeProc(ln->datum);
- free(ln);
- }
+ for (ln = list->first; ln != NULL; ln = next) {
+ next = ln->next;
+ freeProc(ln->datum);
+ free(ln);
+ }
- free(list);
+ free(list);
}
/* Insert a new node with the datum before the given node. */
void
Lst_InsertBefore(List *list, ListNode *ln, void *datum)
{
- ListNode *newNode;
+ ListNode *newNode;
- assert(datum != NULL);
+ assert(datum != NULL);
- newNode = LstNodeNew(ln->prev, ln, datum);
+ newNode = LstNodeNew(ln->prev, ln, datum);
- if (ln->prev != NULL)
- ln->prev->next = newNode;
- ln->prev = newNode;
+ if (ln->prev != NULL)
+ ln->prev->next = newNode;
+ ln->prev = newNode;
- if (ln == list->first)
- list->first = newNode;
+ if (ln == list->first)
+ list->first = newNode;
}
/* Add a piece of data at the start of the given list. */
void
Lst_Prepend(List *list, void *datum)
{
- ListNode *ln;
+ ListNode *ln;
- assert(datum != NULL);
+ assert(datum != NULL);
- ln = LstNodeNew(NULL, list->first, datum);
+ ln = LstNodeNew(NULL, list->first, datum);
- if (list->first == NULL) {
- list->first = ln;
- list->last = ln;
- } else {
- list->first->prev = ln;
- list->first = ln;
- }
+ if (list->first == NULL) {
+ list->first = ln;
+ list->last = ln;
+ } else {
+ list->first->prev = ln;
+ list->first = ln;
+ }
}
/* Add a piece of data at the end of the given list. */
void
Lst_Append(List *list, void *datum)
{
- ListNode *ln;
+ ListNode *ln;
- assert(datum != NULL);
+ assert(datum != NULL);
- ln = LstNodeNew(list->last, NULL, datum);
+ ln = LstNodeNew(list->last, NULL, datum);
- if (list->last == NULL) {
- list->first = ln;
- list->last = ln;
- } else {
- list->last->next = ln;
- list->last = ln;
- }
+ if (list->last == NULL) {
+ list->first = ln;
+ list->last = ln;
+ } else {
+ list->last->next = ln;
+ list->last = ln;
+ }
}
/* Remove the given node from the given list.
@@ -149,26 +151,26 @@ Lst_Append(List *list, void *datum)
void
Lst_Remove(List *list, ListNode *ln)
{
- /* unlink it from its neighbors */
- if (ln->next != NULL)
- ln->next->prev = ln->prev;
- if (ln->prev != NULL)
- ln->prev->next = ln->next;
-
- /* unlink it from the list */
- if (list->first == ln)
- list->first = ln->next;
- if (list->last == ln)
- list->last = ln->prev;
+ /* unlink it from its neighbors */
+ if (ln->next != NULL)
+ ln->next->prev = ln->prev;
+ if (ln->prev != NULL)
+ ln->prev->next = ln->next;
+
+ /* unlink it from the list */
+ if (list->first == ln)
+ list->first = ln->next;
+ if (list->last == ln)
+ list->last = ln->prev;
}
/* Replace the datum in the given node with the new datum. */
void
LstNode_Set(ListNode *ln, void *datum)
{
- assert(datum != NULL);
+ assert(datum != NULL);
- ln->datum = datum;
+ ln->datum = datum;
}
/* Replace the datum in the given node with NULL.
@@ -176,7 +178,7 @@ LstNode_Set(ListNode *ln, void *datum)
void
LstNode_SetNull(ListNode *ln)
{
- ln->datum = NULL;
+ ln->datum = NULL;
}
/* Return the first node that contains the given datum, or NULL.
@@ -185,29 +187,29 @@ LstNode_SetNull(ListNode *ln)
ListNode *
Lst_FindDatum(List *list, const void *datum)
{
- ListNode *ln;
+ ListNode *ln;
- assert(datum != NULL);
+ assert(datum != NULL);
- for (ln = list->first; ln != NULL; ln = ln->next)
- if (ln->datum == datum)
- return ln;
+ for (ln = list->first; ln != NULL; ln = ln->next)
+ if (ln->datum == datum)
+ return ln;
- return NULL;
+ return NULL;
}
int
Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
{
- ListNode *ln;
- int result = 0;
+ ListNode *ln;
+ int result = 0;
- for (ln = list->first; ln != NULL; ln = ln->next) {
- result = proc(ln->datum, procData);
- if (result != 0)
- break;
- }
- return result;
+ for (ln = list->first; ln != NULL; ln = ln->next) {
+ result = proc(ln->datum, procData);
+ if (result != 0)
+ break;
+ }
+ return result;
}
/* Move all nodes from src to the end of dst.
@@ -215,34 +217,36 @@ Lst_ForEachUntil(List *list, LstActionUn
void
Lst_MoveAll(List *dst, List *src)
{
- if (src->first != NULL) {
- src->first->prev = dst->last;
- if (dst->last != NULL)
- dst->last->next = src->first;
- else
- dst->first = src->first;
-
- dst->last = src->last;
- }
- free(src);
+ if (src->first != NULL) {
+ src->first->prev = dst->last;
+ if (dst->last != NULL)
+ dst->last->next = src->first;
+ else
+ dst->first = src->first;
+
+ dst->last = src->last;
+ }
+ free(src);
}
/* Copy the element data from src to the start of dst. */
void
Lst_PrependAll(List *dst, List *src)
{
- ListNode *node;
- for (node = src->last; node != NULL; node = node->prev)
- Lst_Prepend(dst, node->datum);
+ ListNode *node;
+
+ for (node = src->last; node != NULL; node = node->prev)
+ Lst_Prepend(dst, node->datum);
}
/* Copy the element data from src to the end of dst. */
void
Lst_AppendAll(List *dst, List *src)
{
- ListNode *node;
- for (node = src->first; node != NULL; node = node->next)
- Lst_Append(dst, node->datum);
+ ListNode *node;
+
+ for (node = src->first; node != NULL; node = node->next)
+ Lst_Append(dst, node->datum);
}
/*
@@ -253,26 +257,26 @@ Lst_AppendAll(List *dst, List *src)
void
Lst_Enqueue(List *list, void *datum)
{
- Lst_Append(list, datum);
+ Lst_Append(list, datum);
}
/* Remove and return the datum at the head of the given list. */
void *
Lst_Dequeue(List *list)
{
- void *datum = list->first->datum;
- Lst_Remove(list, list->first);
- assert(datum != NULL); /* since NULL would mean end of the list */
- return datum;
+ void *datum = list->first->datum;
+ Lst_Remove(list, list->first);
+ assert(datum != NULL); /* since NULL would mean end of the list */
+ return datum;
}
void
Vector_Init(Vector *v, size_t itemSize)
{
- v->len = 0;
- v->priv_cap = 10;
- v->itemSize = itemSize;
- v->items = bmake_malloc(v->priv_cap * v->itemSize);
+ v->len = 0;
+ v->priv_cap = 10;
+ v->itemSize = itemSize;
+ v->items = bmake_malloc(v->priv_cap * v->itemSize);
}
/* Add space for a new item to the vector and return a pointer to that space.
@@ -280,12 +284,12 @@ Vector_Init(Vector *v, size_t itemSize)
void *
Vector_Push(Vector *v)
{
- if (v->len >= v->priv_cap) {
- v->priv_cap *= 2;
- v->items = bmake_realloc(v->items, v->priv_cap * v->itemSize);
- }
- v->len++;
- return Vector_Get(v, v->len - 1);
+ if (v->len >= v->priv_cap) {
+ v->priv_cap *= 2;
+ v->items = bmake_realloc(v->items, v->priv_cap * v->itemSize);
+ }
+ v->len++;
+ return Vector_Get(v, v->len - 1);
}
/* Return the pointer to the last item in the vector.
@@ -293,13 +297,13 @@ Vector_Push(Vector *v)
void *
Vector_Pop(Vector *v)
{
- assert(v->len > 0);
- v->len--;
- return Vector_Get(v, v->len);
+ assert(v->len > 0);
+ v->len--;
+ return Vector_Get(v, v->len);
}
void
Vector_Done(Vector *v)
{
- free(v->items);
+ free(v->items);
}
Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.85 src/usr.bin/make/lst.h:1.86
--- src/usr.bin/make/lst.h:1.85 Tue Nov 10 00:32:12 2020
+++ src/usr.bin/make/lst.h Tue Nov 24 19:46:29 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.h,v 1.85 2020/11/10 00:32:12 rillig Exp $ */
+/* $NetBSD: lst.h,v 1.86 2020/11/24 19:46:29 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -83,23 +83,23 @@
#include <stdlib.h>
/* A doubly-linked list of pointers. */
-typedef struct List List;
+typedef struct List List;
/* A single node in the doubly-linked list. */
-typedef struct ListNode ListNode;
+typedef struct ListNode ListNode;
struct ListNode {
- ListNode *prev; /* previous node in list, or NULL */
- ListNode *next; /* next node in list, or NULL */
- union {
- void *datum; /* datum associated with this element */
- const struct GNode *priv_gnode; /* alias, just for debugging */
- const char *priv_str; /* alias, just for debugging */
- };
+ ListNode *prev; /* previous node in list, or NULL */
+ ListNode *next; /* next node in list, or NULL */
+ union {
+ void *datum; /* datum associated with this element */
+ const struct GNode *priv_gnode; /* alias, just for debugging */
+ const char *priv_str; /* alias, just for debugging */
+ };
};
struct List {
- ListNode *first; /* first node in list */
- ListNode *last; /* last node in list */
+ ListNode *first; /* first node in list */
+ ListNode *last; /* last node in list */
};
/* Free the datum of a node, called before freeing the node itself. */
@@ -119,7 +119,8 @@ void Lst_Destroy(List *, LstFreeProc);
/* Get information about a list */
MAKE_INLINE Boolean
-Lst_IsEmpty(List *list) { return list->first == NULL; }
+Lst_IsEmpty(List *list)
+{ return list->first == NULL; }
/* Find the first node that contains the given datum, or NULL. */
ListNode *Lst_FindDatum(List *, const void *);
@@ -163,10 +164,10 @@ void *Lst_Dequeue(List *);
/* A vector is an ordered collection of items, allowing for fast indexed
* access. */
typedef struct Vector {
- void *items; /* memory holding the items */
- size_t itemSize; /* size of a single item in bytes */
- size_t len; /* number of actually usable elements */
- size_t priv_cap; /* capacity */
+ void *items; /* memory holding the items */
+ size_t itemSize; /* size of a single item in bytes */
+ size_t len; /* number of actually usable elements */
+ size_t priv_cap; /* capacity */
} Vector;
void Vector_Init(Vector *, size_t);
@@ -176,8 +177,8 @@ void Vector_Init(Vector *, size_t);
MAKE_INLINE void *
Vector_Get(Vector *v, size_t i)
{
- unsigned char *items = v->items;
- return items + i * v->itemSize;
+ unsigned char *items = v->items;
+ return items + i * v->itemSize;
}
void *Vector_Push(Vector *);