* [PATCH 1/8] stailq.3: New page that will hold the (stailq) contents of queue.3
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
@ 2020-10-24 22:21 ` Alejandro Colomar
2020-10-24 22:21 ` [PATCH 2/8] queue.3, stailq.3: NAME: Move code from queue.3 to stailq.3 Alejandro Colomar
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:21 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/stailq.3 | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
create mode 100644 man3/stailq.3
diff --git a/man3/stailq.3 b/man3/stailq.3
new file mode 100644
index 000000000..39b693c01
--- /dev/null
+++ b/man3/stailq.3
@@ -0,0 +1,40 @@
+.\" Copyright (c) 1993
+.\" The Regents of the University of California. All rights reserved.
+.\" and Copyright (c) 2020 by Alejandro Colomar <colomar.6.4.3@gmail.com>
+.\"
+.\" %%%LICENSE_START(BSD_3_CLAUSE_UCB)
+.\" 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. 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.
+.\" %%%LICENSE_END
+.\"
+.\"
+.TH STAILQ 3 2020-10-21 "GNU" "Linux Programmer's Manual"
+.SH NAME
+.SH SYNOPSIS
+.SH DESCRIPTION
+.SH RETURN VALUE
+.SH CONFORMING TO
+.SH BUGS
+.SH EXAMPLES
+.SH SEE ALSO
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 2/8] queue.3, stailq.3: NAME: Move code from queue.3 to stailq.3
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
2020-10-24 22:21 ` [PATCH 1/8] stailq.3: New page that will hold the (stailq) contents of queue.3 Alejandro Colomar
@ 2020-10-24 22:21 ` Alejandro Colomar
2020-10-24 22:21 ` [PATCH 3/8] queue.3, stailq.3: SYNOPSIS: " Alejandro Colomar
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:21 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/queue.3 | 20 --------------------
man3/stailq.3 | 20 ++++++++++++++++++++
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/man3/queue.3 b/man3/queue.3
index 0c57f8ef6..5b05c0d6e 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -34,26 +34,6 @@
.Dt QUEUE 3
.Os
.Sh NAME
-.Nm STAILQ_CONCAT ,
-.Nm STAILQ_EMPTY ,
-.Nm STAILQ_ENTRY ,
-.Nm STAILQ_FIRST ,
-.Nm STAILQ_FOREACH ,
-.\" .Nm STAILQ_FOREACH_FROM ,
-.\" .Nm STAILQ_FOREACH_FROM_SAFE ,
-.\" .Nm STAILQ_FOREACH_SAFE ,
-.Nm STAILQ_HEAD ,
-.Nm STAILQ_HEAD_INITIALIZER ,
-.Nm STAILQ_INIT ,
-.Nm STAILQ_INSERT_AFTER ,
-.Nm STAILQ_INSERT_HEAD ,
-.Nm STAILQ_INSERT_TAIL ,
-.\" .Nm STAILQ_LAST ,
-.Nm STAILQ_NEXT ,
-.Nm STAILQ_REMOVE ,
-.\" .Nm STAILQ_REMOVE_AFTER ,
-.Nm STAILQ_REMOVE_HEAD ,
-.\" .Nm STAILQ_SWAP ,
.Nm TAILQ_CONCAT ,
.Nm TAILQ_EMPTY ,
.Nm TAILQ_ENTRY ,
diff --git a/man3/stailq.3 b/man3/stailq.3
index 39b693c01..156f607cb 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -31,6 +31,26 @@
.\"
.TH STAILQ 3 2020-10-21 "GNU" "Linux Programmer's Manual"
.SH NAME
+.Nm STAILQ_CONCAT ,
+.Nm STAILQ_EMPTY ,
+.Nm STAILQ_ENTRY ,
+.Nm STAILQ_FIRST ,
+.Nm STAILQ_FOREACH ,
+.\" .Nm STAILQ_FOREACH_FROM ,
+.\" .Nm STAILQ_FOREACH_FROM_SAFE ,
+.\" .Nm STAILQ_FOREACH_SAFE ,
+.Nm STAILQ_HEAD ,
+.Nm STAILQ_HEAD_INITIALIZER ,
+.Nm STAILQ_INIT ,
+.Nm STAILQ_INSERT_AFTER ,
+.Nm STAILQ_INSERT_HEAD ,
+.Nm STAILQ_INSERT_TAIL ,
+.\" .Nm STAILQ_LAST ,
+.Nm STAILQ_NEXT ,
+.Nm STAILQ_REMOVE ,
+.\" .Nm STAILQ_REMOVE_AFTER ,
+.Nm STAILQ_REMOVE_HEAD ,
+.\" .Nm STAILQ_SWAP ,
.SH SYNOPSIS
.SH DESCRIPTION
.SH RETURN VALUE
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 3/8] queue.3, stailq.3: SYNOPSIS: Move code from queue.3 to stailq.3
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
2020-10-24 22:21 ` [PATCH 1/8] stailq.3: New page that will hold the (stailq) contents of queue.3 Alejandro Colomar
2020-10-24 22:21 ` [PATCH 2/8] queue.3, stailq.3: NAME: Move code from queue.3 to stailq.3 Alejandro Colomar
@ 2020-10-24 22:21 ` Alejandro Colomar
2020-10-24 22:21 ` [PATCH 4/8] queue.3, stailq.3: DESCRIPTION: Move stailq specific " Alejandro Colomar
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:21 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/queue.3 | 21 ---------------------
man3/stailq.3 | 21 +++++++++++++++++++++
2 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/man3/queue.3 b/man3/queue.3
index 5b05c0d6e..72ec892ad 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -63,27 +63,6 @@ lists, tail queues, and circular queues
.Sh SYNOPSIS
.In sys/queue.h
.\"
-.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
-.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
-.Fn STAILQ_ENTRY "TYPE"
-.Fn STAILQ_FIRST "STAILQ_HEAD *head"
-.Fn STAILQ_FOREACH "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_FOREACH_FROM "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_FOREACH_FROM_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
-.\" .Fn STAILQ_FOREACH_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
-.Fn STAILQ_HEAD "HEADNAME" "TYPE"
-.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head"
-.Fn STAILQ_INIT "STAILQ_HEAD *head"
-.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "STAILQ_ENTRY NAME"
-.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
-.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_LAST "STAILQ_HEAD *head" "TYPE" "STAILQ_ENTRY NAME"
-.Fn STAILQ_NEXT "TYPE *elm" "STAILQ_ENTRY NAME"
-.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "TYPE *elm" "TYPE" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_REMOVE_AFTER "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
-.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_SWAP "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" "STAILQ_ENTRY NAME"
-.\"
.Fn TAILQ_CONCAT "TAILQ_HEAD *head1" "TAILQ_HEAD *head2" "TAILQ_ENTRY NAME"
.Fn TAILQ_EMPTY "TAILQ_HEAD *head"
.Fn TAILQ_ENTRY "TYPE"
diff --git a/man3/stailq.3 b/man3/stailq.3
index 156f607cb..161b7c3f0 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -52,6 +52,27 @@
.Nm STAILQ_REMOVE_HEAD ,
.\" .Nm STAILQ_SWAP ,
.SH SYNOPSIS
+.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
+.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
+.Fn STAILQ_ENTRY "TYPE"
+.Fn STAILQ_FIRST "STAILQ_HEAD *head"
+.Fn STAILQ_FOREACH "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
+.\" .Fn STAILQ_FOREACH_FROM "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
+.\" .Fn STAILQ_FOREACH_FROM_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
+.\" .Fn STAILQ_FOREACH_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
+.Fn STAILQ_HEAD "HEADNAME" "TYPE"
+.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head"
+.Fn STAILQ_INIT "STAILQ_HEAD *head"
+.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
+.\" .Fn STAILQ_LAST "STAILQ_HEAD *head" "TYPE" "STAILQ_ENTRY NAME"
+.Fn STAILQ_NEXT "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "TYPE *elm" "TYPE" "STAILQ_ENTRY NAME"
+.\" .Fn STAILQ_REMOVE_AFTER "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
+.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
+.\" .Fn STAILQ_SWAP "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" "STAILQ_ENTRY NAME"
+.\"
.SH DESCRIPTION
.SH RETURN VALUE
.SH CONFORMING TO
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 4/8] queue.3, stailq.3: DESCRIPTION: Move stailq specific code from queue.3 to stailq.3
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
` (2 preceding siblings ...)
2020-10-24 22:21 ` [PATCH 3/8] queue.3, stailq.3: SYNOPSIS: " Alejandro Colomar
@ 2020-10-24 22:21 ` Alejandro Colomar
2020-10-24 22:21 ` [PATCH 5/8] queue.3, stailq.3: EXAMPLES: Move stailq example " Alejandro Colomar
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:21 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/queue.3 | 177 --------------------------------------------------
man3/stailq.3 | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 177 insertions(+), 177 deletions(-)
diff --git a/man3/queue.3 b/man3/queue.3
index 72ec892ad..ee15e60be 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -245,183 +245,6 @@ or
.Li CIRCLEQ_HEAD .
See the examples below for further explanation of how these
macros are used.
-.Ss Singly-linked tail queues
-A singly-linked tail queue is headed by a structure defined by the
-.Nm STAILQ_HEAD
-macro.
-This structure contains a pair of pointers,
-one to the first element in the tail queue and the other to
-the last element in the tail queue.
-The elements are singly linked for minimum space and pointer
-manipulation overhead at the expense of O(n) removal for arbitrary
-elements.
-New elements can be added to the tail queue after an existing element,
-at the head of the tail queue, or at the end of the tail queue.
-A
-.Fa STAILQ_HEAD
-structure is declared as follows:
-.Bd -literal -offset indent
-STAILQ_HEAD(HEADNAME, TYPE) head;
-.Ed
-.Pp
-where
-.Li HEADNAME
-is the name of the structure to be defined, and
-.Li TYPE
-is the type of the elements to be linked into the tail queue.
-A pointer to the head of the tail queue can later be declared as:
-.Bd -literal -offset indent
-struct HEADNAME *headp;
-.Ed
-.Pp
-(The names
-.Li head
-and
-.Li headp
-are user selectable.)
-.Pp
-The macro
-.Nm STAILQ_HEAD_INITIALIZER
-evaluates to an initializer for the tail queue
-.Fa head .
-.Pp
-The macro
-.Nm STAILQ_CONCAT
-concatenates the tail queue headed by
-.Fa head2
-onto the end of the one headed by
-.Fa head1
-removing all entries from the former.
-.Pp
-The macro
-.Nm STAILQ_EMPTY
-evaluates to true if there are no items on the tail queue.
-.Pp
-The macro
-.Nm STAILQ_ENTRY
-declares a structure that connects the elements in
-the tail queue.
-.Pp
-The macro
-.Nm STAILQ_FIRST
-returns the first item on the tail queue or NULL if the tail queue
-is empty.
-.Pp
-The macro
-.Nm STAILQ_FOREACH
-traverses the tail queue referenced by
-.Fa head
-in the forward direction, assigning each element
-in turn to
-.Fa var .
-.\" .Pp
-.\" The macro
-.\" .Nm STAILQ_FOREACH_FROM
-.\" behaves identically to
-.\" .Nm STAILQ_FOREACH
-.\" when
-.\" .Fa var
-.\" is NULL, else it treats
-.\" .Fa var
-.\" as a previously found STAILQ element and begins the loop at
-.\" .Fa var
-.\" instead of the first element in the STAILQ referenced by
-.\" .Fa head .
-.\" .Pp
-.\" The macro
-.\" .Nm STAILQ_FOREACH_SAFE
-.\" traverses the tail queue referenced by
-.\" .Fa head
-.\" in the forward direction, assigning each element
-.\" in turn to
-.\" .Fa var .
-.\" However, unlike
-.\" .Fn STAILQ_FOREACH
-.\" here it is permitted to both remove
-.\" .Fa var
-.\" as well as free it from within the loop safely without interfering with the
-.\" traversal.
-.\" .Pp
-.\" The macro
-.\" .Nm STAILQ_FOREACH_FROM_SAFE
-.\" behaves identically to
-.\" .Nm STAILQ_FOREACH_SAFE
-.\" when
-.\" .Fa var
-.\" is NULL, else it treats
-.\" .Fa var
-.\" as a previously found STAILQ element and begins the loop at
-.\" .Fa var
-.\" instead of the first element in the STAILQ referenced by
-.\" .Fa head .
-.Pp
-The macro
-.Nm STAILQ_INIT
-initializes the tail queue referenced by
-.Fa head .
-.Pp
-The macro
-.Nm STAILQ_INSERT_HEAD
-inserts the new element
-.Fa elm
-at the head of the tail queue.
-.Pp
-The macro
-.Nm STAILQ_INSERT_TAIL
-inserts the new element
-.Fa elm
-at the end of the tail queue.
-.Pp
-The macro
-.Nm STAILQ_INSERT_AFTER
-inserts the new element
-.Fa elm
-after the element
-.Fa listelm .
-.\" .Pp
-.\" The macro
-.\" .Nm STAILQ_LAST
-.\" returns the last item on the tail queue.
-.\" If the tail queue is empty the return value is
-.\" .Dv NULL .
-.Pp
-The macro
-.Nm STAILQ_NEXT
-returns the next item on the tail queue, or NULL this item is the last.
-.\" .Pp
-.\" The macro
-.\" .Nm STAILQ_REMOVE_AFTER
-.\" removes the element after
-.\" .Fa elm
-.\" from the tail queue.
-.\" Unlike
-.\" .Fa STAILQ_REMOVE ,
-.\" this macro does not traverse the entire tail queue.
-.Pp
-The macro
-.Nm STAILQ_REMOVE_HEAD
-removes the element at the head of the tail queue.
-For optimum efficiency,
-elements being removed from the head of the tail queue should
-use this macro explicitly rather than the generic
-.Fa STAILQ_REMOVE
-macro.
-.Pp
-The macro
-.Nm STAILQ_REMOVE
-removes the element
-.Fa elm
-from the tail queue.
-.\" .Pp
-.\" The macro
-.\" .Nm STAILQ_SWAP
-.\" swaps the contents of
-.\" .Fa head1
-.\" and
-.\" .Fa head2 .
-.Pp
-See the EXAMPLES section below for an example program
-using a singly-linked tail queue.
.Ss Tail queues
A tail queue is headed by a structure defined by the
.Nm TAILQ_HEAD
diff --git a/man3/stailq.3 b/man3/stailq.3
index 161b7c3f0..9b0322e68 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -74,6 +74,183 @@
.\" .Fn STAILQ_SWAP "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" "STAILQ_ENTRY NAME"
.\"
.SH DESCRIPTION
+.Ss Singly-linked tail queues
+A singly-linked tail queue is headed by a structure defined by the
+.Nm STAILQ_HEAD
+macro.
+This structure contains a pair of pointers,
+one to the first element in the tail queue and the other to
+the last element in the tail queue.
+The elements are singly linked for minimum space and pointer
+manipulation overhead at the expense of O(n) removal for arbitrary
+elements.
+New elements can be added to the tail queue after an existing element,
+at the head of the tail queue, or at the end of the tail queue.
+A
+.Fa STAILQ_HEAD
+structure is declared as follows:
+.Bd -literal -offset indent
+STAILQ_HEAD(HEADNAME, TYPE) head;
+.Ed
+.Pp
+where
+.Li HEADNAME
+is the name of the structure to be defined, and
+.Li TYPE
+is the type of the elements to be linked into the tail queue.
+A pointer to the head of the tail queue can later be declared as:
+.Bd -literal -offset indent
+struct HEADNAME *headp;
+.Ed
+.Pp
+(The names
+.Li head
+and
+.Li headp
+are user selectable.)
+.Pp
+The macro
+.Nm STAILQ_HEAD_INITIALIZER
+evaluates to an initializer for the tail queue
+.Fa head .
+.Pp
+The macro
+.Nm STAILQ_CONCAT
+concatenates the tail queue headed by
+.Fa head2
+onto the end of the one headed by
+.Fa head1
+removing all entries from the former.
+.Pp
+The macro
+.Nm STAILQ_EMPTY
+evaluates to true if there are no items on the tail queue.
+.Pp
+The macro
+.Nm STAILQ_ENTRY
+declares a structure that connects the elements in
+the tail queue.
+.Pp
+The macro
+.Nm STAILQ_FIRST
+returns the first item on the tail queue or NULL if the tail queue
+is empty.
+.Pp
+The macro
+.Nm STAILQ_FOREACH
+traverses the tail queue referenced by
+.Fa head
+in the forward direction, assigning each element
+in turn to
+.Fa var .
+.\" .Pp
+.\" The macro
+.\" .Nm STAILQ_FOREACH_FROM
+.\" behaves identically to
+.\" .Nm STAILQ_FOREACH
+.\" when
+.\" .Fa var
+.\" is NULL, else it treats
+.\" .Fa var
+.\" as a previously found STAILQ element and begins the loop at
+.\" .Fa var
+.\" instead of the first element in the STAILQ referenced by
+.\" .Fa head .
+.\" .Pp
+.\" The macro
+.\" .Nm STAILQ_FOREACH_SAFE
+.\" traverses the tail queue referenced by
+.\" .Fa head
+.\" in the forward direction, assigning each element
+.\" in turn to
+.\" .Fa var .
+.\" However, unlike
+.\" .Fn STAILQ_FOREACH
+.\" here it is permitted to both remove
+.\" .Fa var
+.\" as well as free it from within the loop safely without interfering with the
+.\" traversal.
+.\" .Pp
+.\" The macro
+.\" .Nm STAILQ_FOREACH_FROM_SAFE
+.\" behaves identically to
+.\" .Nm STAILQ_FOREACH_SAFE
+.\" when
+.\" .Fa var
+.\" is NULL, else it treats
+.\" .Fa var
+.\" as a previously found STAILQ element and begins the loop at
+.\" .Fa var
+.\" instead of the first element in the STAILQ referenced by
+.\" .Fa head .
+.Pp
+The macro
+.Nm STAILQ_INIT
+initializes the tail queue referenced by
+.Fa head .
+.Pp
+The macro
+.Nm STAILQ_INSERT_HEAD
+inserts the new element
+.Fa elm
+at the head of the tail queue.
+.Pp
+The macro
+.Nm STAILQ_INSERT_TAIL
+inserts the new element
+.Fa elm
+at the end of the tail queue.
+.Pp
+The macro
+.Nm STAILQ_INSERT_AFTER
+inserts the new element
+.Fa elm
+after the element
+.Fa listelm .
+.\" .Pp
+.\" The macro
+.\" .Nm STAILQ_LAST
+.\" returns the last item on the tail queue.
+.\" If the tail queue is empty the return value is
+.\" .Dv NULL .
+.Pp
+The macro
+.Nm STAILQ_NEXT
+returns the next item on the tail queue, or NULL this item is the last.
+.\" .Pp
+.\" The macro
+.\" .Nm STAILQ_REMOVE_AFTER
+.\" removes the element after
+.\" .Fa elm
+.\" from the tail queue.
+.\" Unlike
+.\" .Fa STAILQ_REMOVE ,
+.\" this macro does not traverse the entire tail queue.
+.Pp
+The macro
+.Nm STAILQ_REMOVE_HEAD
+removes the element at the head of the tail queue.
+For optimum efficiency,
+elements being removed from the head of the tail queue should
+use this macro explicitly rather than the generic
+.Fa STAILQ_REMOVE
+macro.
+.Pp
+The macro
+.Nm STAILQ_REMOVE
+removes the element
+.Fa elm
+from the tail queue.
+.\" .Pp
+.\" The macro
+.\" .Nm STAILQ_SWAP
+.\" swaps the contents of
+.\" .Fa head1
+.\" and
+.\" .Fa head2 .
+.Pp
+See the EXAMPLES section below for an example program
+using a singly-linked tail queue.
.SH RETURN VALUE
.SH CONFORMING TO
.SH BUGS
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 5/8] queue.3, stailq.3: EXAMPLES: Move stailq example from queue.3 to stailq.3
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
` (3 preceding siblings ...)
2020-10-24 22:21 ` [PATCH 4/8] queue.3, stailq.3: DESCRIPTION: Move stailq specific " Alejandro Colomar
@ 2020-10-24 22:21 ` Alejandro Colomar
2020-10-24 22:21 ` [PATCH 6/8] stailq.3: Copy and adapt code from queue.3 Alejandro Colomar
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:21 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/queue.3 | 61 ---------------------------------------------------
man3/stailq.3 | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 61 deletions(-)
diff --git a/man3/queue.3 b/man3/queue.3
index ee15e60be..bebfc7a25 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -456,67 +456,6 @@ from the tail queue.
.Pp
See the EXAMPLES section below for an example program using a tail queue.
.Sh EXAMPLES
-.Ss Singly-linked tail queue example
-.Bd -literal
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/queue.h>
-
-struct entry {
- int data;
- STAILQ_ENTRY(entry) entries; /* Singly-linked tail queue. */
-};
-
-STAILQ_HEAD(stailhead, entry);
-
-int
-main(void)
-{
- struct entry *n1, *n2, *n3, *np;
- struct stailhead head; /* Singly-linked tail queue
- head. */
-
- STAILQ_INIT(&head); /* Initialize the queue. */
-
- n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
- STAILQ_INSERT_HEAD(&head, n1, entries);
-
- n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */
- STAILQ_INSERT_TAIL(&head, n1, entries);
-
- n2 = malloc(sizeof(struct entry)); /* Insert after. */
- STAILQ_INSERT_AFTER(&head, n1, n2, entries);
-
- STAILQ_REMOVE(&head, n2, entry, entries);/* Deletion. */
- free(n2);
-
- n3 = STAILQ_FIRST(&head);
- STAILQ_REMOVE_HEAD(&head, entries); /* Deletion from the head. */
- free(n3);
-
- n1 = STAILQ_FIRST(&head);
- n1->data = 0;
- for (int i = 1; i < 5; i++) {
- n1 = malloc(sizeof(struct entry));
- STAILQ_INSERT_HEAD(&head, n1, entries);
- n1->data = i;
- }
- /* Forward traversal. */
- STAILQ_FOREACH(np, &head, entries)
- printf("%i\en", np->data);
- /* TailQ Deletion. */
- n1 = STAILQ_FIRST(&head);
- while (n1 != NULL) {
- n2 = STAILQ_NEXT(n1, entries);
- free(n1);
- n1 = n2;
- }
- STAILQ_INIT(&head);
-
- exit(EXIT_SUCCESS);
-}
-.Ed
.Ss Tail queue example
.Bd -literal
#include <stddef.h>
diff --git a/man3/stailq.3 b/man3/stailq.3
index 9b0322e68..88cdccbbc 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -255,4 +255,65 @@ using a singly-linked tail queue.
.SH CONFORMING TO
.SH BUGS
.SH EXAMPLES
+.Ss Singly-linked tail queue example
+.Bd -literal
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+
+struct entry {
+ int data;
+ STAILQ_ENTRY(entry) entries; /* Singly-linked tail queue. */
+};
+
+STAILQ_HEAD(stailhead, entry);
+
+int
+main(void)
+{
+ struct entry *n1, *n2, *n3, *np;
+ struct stailhead head; /* Singly-linked tail queue
+ head. */
+
+ STAILQ_INIT(&head); /* Initialize the queue. */
+
+ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
+ STAILQ_INSERT_HEAD(&head, n1, entries);
+
+ n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */
+ STAILQ_INSERT_TAIL(&head, n1, entries);
+
+ n2 = malloc(sizeof(struct entry)); /* Insert after. */
+ STAILQ_INSERT_AFTER(&head, n1, n2, entries);
+
+ STAILQ_REMOVE(&head, n2, entry, entries);/* Deletion. */
+ free(n2);
+
+ n3 = STAILQ_FIRST(&head);
+ STAILQ_REMOVE_HEAD(&head, entries); /* Deletion from the head. */
+ free(n3);
+
+ n1 = STAILQ_FIRST(&head);
+ n1->data = 0;
+ for (int i = 1; i < 5; i++) {
+ n1 = malloc(sizeof(struct entry));
+ STAILQ_INSERT_HEAD(&head, n1, entries);
+ n1->data = i;
+ }
+ /* Forward traversal. */
+ STAILQ_FOREACH(np, &head, entries)
+ printf("%i\en", np->data);
+ /* TailQ Deletion. */
+ n1 = STAILQ_FIRST(&head);
+ while (n1 != NULL) {
+ n2 = STAILQ_NEXT(n1, entries);
+ free(n1);
+ n1 = n2;
+ }
+ STAILQ_INIT(&head);
+
+ exit(EXIT_SUCCESS);
+}
+.Ed
.SH SEE ALSO
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 6/8] stailq.3: Copy and adapt code from queue.3
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
` (4 preceding siblings ...)
2020-10-24 22:21 ` [PATCH 5/8] queue.3, stailq.3: EXAMPLES: Move stailq example " Alejandro Colomar
@ 2020-10-24 22:21 ` Alejandro Colomar
2020-10-24 22:21 ` [PATCH 7/8] stailq.3: ffix: Use man markup Alejandro Colomar
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:21 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/stailq.3 | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/man3/stailq.3 b/man3/stailq.3
index 88cdccbbc..9306176d2 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -52,6 +52,8 @@
.Nm STAILQ_REMOVE_HEAD ,
.\" .Nm STAILQ_SWAP ,
.SH SYNOPSIS
+.In sys/queue.h
+.\"
.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
.Fn STAILQ_ENTRY "TYPE"
@@ -74,6 +76,18 @@
.\" .Fn STAILQ_SWAP "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" "STAILQ_ENTRY NAME"
.\"
.SH DESCRIPTION
+In the macro definitions,
+.Fa TYPE
+is the name of a user-defined structure,
+that must contain a field of type
+.Li STAILQ_ENTRY ,
+named
+.Fa NAME .
+The argument
+.Fa HEADNAME
+is the name of a user-defined structure that must be declared
+using the macro
+.Li STAILQ_HEAD .
.Ss Singly-linked tail queues
A singly-linked tail queue is headed by a structure defined by the
.Nm STAILQ_HEAD
@@ -248,11 +262,12 @@ from the tail queue.
.\" .Fa head1
.\" and
.\" .Fa head2 .
-.Pp
-See the EXAMPLES section below for an example program
-using a singly-linked tail queue.
.SH RETURN VALUE
.SH CONFORMING TO
+Not in POSIX.1, POSIX.1-2001 or POSIX.1-2008.
+Present on the BSDs
+(STAILQ macros first appeared in
+.Bx 4.4 ).
.SH BUGS
.SH EXAMPLES
.Ss Singly-linked tail queue example
@@ -272,7 +287,7 @@ STAILQ_HEAD(stailhead, entry);
int
main(void)
{
- struct entry *n1, *n2, *n3, *np;
+ struct entry *n1, *n2, *n3, *np;
struct stailhead head; /* Singly-linked tail queue
head. */
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 7/8] stailq.3: ffix: Use man markup
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
` (5 preceding siblings ...)
2020-10-24 22:21 ` [PATCH 6/8] stailq.3: Copy and adapt code from queue.3 Alejandro Colomar
@ 2020-10-24 22:21 ` Alejandro Colomar
2020-10-24 22:21 ` [PATCH 8/8] stailq.3: Add remaining details to complete the page Alejandro Colomar
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:21 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/stailq.3 | 317 +++++++++++++++++++++++++++-----------------------
1 file changed, 172 insertions(+), 145 deletions(-)
diff --git a/man3/stailq.3 b/man3/stailq.3
index 9306176d2..0abacd824 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -31,66 +31,90 @@
.\"
.TH STAILQ 3 2020-10-21 "GNU" "Linux Programmer's Manual"
.SH NAME
-.Nm STAILQ_CONCAT ,
-.Nm STAILQ_EMPTY ,
-.Nm STAILQ_ENTRY ,
-.Nm STAILQ_FIRST ,
-.Nm STAILQ_FOREACH ,
-.\" .Nm STAILQ_FOREACH_FROM ,
-.\" .Nm STAILQ_FOREACH_FROM_SAFE ,
-.\" .Nm STAILQ_FOREACH_SAFE ,
-.Nm STAILQ_HEAD ,
-.Nm STAILQ_HEAD_INITIALIZER ,
-.Nm STAILQ_INIT ,
-.Nm STAILQ_INSERT_AFTER ,
-.Nm STAILQ_INSERT_HEAD ,
-.Nm STAILQ_INSERT_TAIL ,
-.\" .Nm STAILQ_LAST ,
-.Nm STAILQ_NEXT ,
-.Nm STAILQ_REMOVE ,
-.\" .Nm STAILQ_REMOVE_AFTER ,
-.Nm STAILQ_REMOVE_HEAD ,
-.\" .Nm STAILQ_SWAP ,
+STAILQ_CONCAT,
+STAILQ_EMPTY,
+STAILQ_ENTRY,
+STAILQ_FIRST,
+STAILQ_FOREACH,
+.\"STAILQ_FOREACH_FROM,
+.\"STAILQ_FOREACH_FROM_SAFE,
+.\"STAILQ_FOREACH_SAFE,
+STAILQ_HEAD,
+STAILQ_HEAD_INITIALIZER,
+STAILQ_INIT,
+STAILQ_INSERT_AFTER,
+STAILQ_INSERT_HEAD,
+STAILQ_INSERT_TAIL,
+.\"STAILQ_LAST,
+STAILQ_NEXT,
+STAILQ_REMOVE,
+.\"STAILQ_REMOVE_AFTER,
+STAILQ_REMOVE_HEAD,
+.\"STAILQ_SWAP
.SH SYNOPSIS
-.In sys/queue.h
-.\"
-.Fn STAILQ_CONCAT "STAILQ_HEAD *head1" "STAILQ_HEAD *head2"
-.Fn STAILQ_EMPTY "STAILQ_HEAD *head"
-.Fn STAILQ_ENTRY "TYPE"
-.Fn STAILQ_FIRST "STAILQ_HEAD *head"
-.Fn STAILQ_FOREACH "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_FOREACH_FROM "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_FOREACH_FROM_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
-.\" .Fn STAILQ_FOREACH_SAFE "TYPE *var" "STAILQ_HEAD *head" "STAILQ_ENTRY NAME" "TYPE *temp_var"
-.Fn STAILQ_HEAD "HEADNAME" "TYPE"
-.Fn STAILQ_HEAD_INITIALIZER "STAILQ_HEAD head"
-.Fn STAILQ_INIT "STAILQ_HEAD *head"
-.Fn STAILQ_INSERT_AFTER "STAILQ_HEAD *head" "TYPE *listelm" "TYPE *elm" "STAILQ_ENTRY NAME"
-.Fn STAILQ_INSERT_HEAD "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
-.Fn STAILQ_INSERT_TAIL "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_LAST "STAILQ_HEAD *head" "TYPE" "STAILQ_ENTRY NAME"
-.Fn STAILQ_NEXT "TYPE *elm" "STAILQ_ENTRY NAME"
-.Fn STAILQ_REMOVE "STAILQ_HEAD *head" "TYPE *elm" "TYPE" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_REMOVE_AFTER "STAILQ_HEAD *head" "TYPE *elm" "STAILQ_ENTRY NAME"
-.Fn STAILQ_REMOVE_HEAD "STAILQ_HEAD *head" "STAILQ_ENTRY NAME"
-.\" .Fn STAILQ_SWAP "STAILQ_HEAD *head1" "STAILQ_HEAD *head2" "STAILQ_ENTRY NAME"
-.\"
+.nf
+.B #include <sys/queue.h>
+.PP
+.BI "void STAILQ_CONCAT(STAILQ_HEAD *" head1 ", STAILQ_HEAD *" head2 ");"
+.PP
+.BI "int STAILQ_EMPTY(STAILQ_HEAD *" head ");"
+.PP
+.B STAILQ_ENTRY(TYPE);
+.PP
+.BI "STAILQ_ENTRY *STAILQ_FIRST(STAILQ_HEAD *" head ");"
+.PP
+.BI "STAILQ_FOREACH(TYPE *" var ", STAILQ_HEAD *" head ", STAILQ_ENTRY " NAME ");"
+.\" .PP
+.\" .BI "STAILQ_FOREACH_FROM(TYPE *" var ", STAILQ_HEAD *" head ", STAILQ_ENTRY " NAME ");"
+.\" .PP
+.\" .BI "STAILQ_FOREACH_FROM_SAFE(TYPE *" var ", STAILQ_HEAD *" head ", STAILQ_ENTRY " NAME ", TYPE *" temp_var ");"
+.\" .PP
+.\" .BI "STAILQ_FOREACH_SAFE(TYPE *" var ", STAILQ_HEAD *" head ", STAILQ_ENTRY " NAME ", TYPE *" temp_var ");"
+.PP
+.B STAILQ_HEAD(HEADNAME, TYPE);
+.PP
+.BI "STAILQ_HEAD STAILQ_HEAD_INITIALIZER(STAILQ_HEAD " head ");"
+.PP
+.BI "void STAILQ_INIT(STAILQ_HEAD *" head ");"
+.PP
+.BI "void STAILQ_INSERT_AFTER(STAILQ_HEAD *" head ", TYPE *" listelm ", TYPE *" elm ","
+.BI " STAILQ_ENTRY " NAME ");"
+.PP
+.BI "void STAILQ_INSERT_HEAD(STAILQ_HEAD *" head ", TYPE *" elm ", STAILQ_ENTRY " NAME ");"
+.PP
+.BI "void STAILQ_INSERT_TAIL(STAILQ_HEAD *" head ", TYPE *" elm ", STAILQ_ENTRY " NAME ");"
+.\" .PP
+.\" .BI "STAILQ_ENTRY *STAILQ_LAST(STAILQ_HEAD *" head ", TYPE *" elm ", STAILQ_ENTRY " NAME ");"
+.PP
+.BI "STAILQ_ENTRY *STAILQ_NEXT(TYPE *" elm ", STAILQ_ENTRY " NAME ");"
+.PP
+.BI "void STAILQ_REMOVE(STAILQ_HEAD *" head ", TYPE *" elm ", TYPE,"
+.BI " STAILQ_ENTRY " NAME ");"
+.\" .PP
+.\" .BI "void STAILQ_REMOVE_AFTER(STAILQ_HEAD *" head ", TYPE *" elm ","
+.\" .BI " STAILQ_ENTRY " NAME ");"
+.PP
+.BI "void STAILQ_REMOVE_HEAD(STAILQ_HEAD *" head ", STAILQ_ENTRY " NAME ");"
+.\" .PP
+.\" .BI "void STAILQ_SWAP(STAILQ_HEAD *" head1 ", STAILQ_HEAD *" head2 ","
+.\" .BI " STAILQ_ENTRY " NAME ");"
+.fi
.SH DESCRIPTION
In the macro definitions,
-.Fa TYPE
+.I TYPE
is the name of a user-defined structure,
that must contain a field of type
-.Li STAILQ_ENTRY ,
+.IR STAILQ_ENTRY ,
named
-.Fa NAME .
+.IR NAME .
The argument
-.Fa HEADNAME
+.I HEADNAME
is the name of a user-defined structure that must be declared
using the macro
-.Li STAILQ_HEAD .
+.BR STAILQ_HEAD ().
.Ss Singly-linked tail queues
A singly-linked tail queue is headed by a structure defined by the
-.Nm STAILQ_HEAD
+.BR STAILQ_HEAD ()
macro.
This structure contains a pair of pointers,
one to the first element in the tail queue and the other to
@@ -101,177 +125,180 @@ elements.
New elements can be added to the tail queue after an existing element,
at the head of the tail queue, or at the end of the tail queue.
A
-.Fa STAILQ_HEAD
+.I STAILQ_HEAD
structure is declared as follows:
-.Bd -literal -offset indent
+.PP
+.in +4
+.EX
STAILQ_HEAD(HEADNAME, TYPE) head;
-.Ed
-.Pp
+.EE
+.in
+.PP
where
-.Li HEADNAME
+.I HEADNAME
is the name of the structure to be defined, and
-.Li TYPE
+.I TYPE
is the type of the elements to be linked into the tail queue.
A pointer to the head of the tail queue can later be declared as:
-.Bd -literal -offset indent
+.PP
+.in +4
+.EX
struct HEADNAME *headp;
-.Ed
-.Pp
+.EE
+.in
+.PP
(The names
-.Li head
+.I head
and
-.Li headp
+.I headp
are user selectable.)
-.Pp
+.PP
The macro
-.Nm STAILQ_HEAD_INITIALIZER
+.BR STAILQ_HEAD_INITIALIZER ()
evaluates to an initializer for the tail queue
-.Fa head .
-.Pp
+.IR head .
+.PP
The macro
-.Nm STAILQ_CONCAT
+.BR STAILQ_CONCAT ()
concatenates the tail queue headed by
-.Fa head2
+.I head2
onto the end of the one headed by
-.Fa head1
+.I head1
removing all entries from the former.
-.Pp
+.PP
The macro
-.Nm STAILQ_EMPTY
+.BR STAILQ_EMPTY ()
evaluates to true if there are no items on the tail queue.
-.Pp
+.PP
The macro
-.Nm STAILQ_ENTRY
+.BR STAILQ_ENTRY ()
declares a structure that connects the elements in
the tail queue.
-.Pp
+.PP
The macro
-.Nm STAILQ_FIRST
+.BR STAILQ_FIRST ()
returns the first item on the tail queue or NULL if the tail queue
is empty.
-.Pp
+.PP
The macro
-.Nm STAILQ_FOREACH
+.BR STAILQ_FOREACH ()
traverses the tail queue referenced by
-.Fa head
+.I head
in the forward direction, assigning each element
in turn to
-.Fa var .
-.\" .Pp
+.IR var .
+.\" .PP
.\" The macro
-.\" .Nm STAILQ_FOREACH_FROM
+.\" .BR STAILQ_FOREACH_FROM ()
.\" behaves identically to
-.\" .Nm STAILQ_FOREACH
+.\" .BR STAILQ_FOREACH ()
.\" when
-.\" .Fa var
+.\" .I var
.\" is NULL, else it treats
-.\" .Fa var
+.\" .I var
.\" as a previously found STAILQ element and begins the loop at
-.\" .Fa var
+.\" .I var
.\" instead of the first element in the STAILQ referenced by
-.\" .Fa head .
-.\" .Pp
+.\" .IR head .
+.\" .PP
.\" The macro
-.\" .Nm STAILQ_FOREACH_SAFE
+.\" .BR STAILQ_FOREACH_SAFE ()
.\" traverses the tail queue referenced by
-.\" .Fa head
+.\" .I head
.\" in the forward direction, assigning each element
.\" in turn to
-.\" .Fa var .
+.\" .IR var .
.\" However, unlike
-.\" .Fn STAILQ_FOREACH
+.\" .BR STAILQ_FOREACH ()
.\" here it is permitted to both remove
-.\" .Fa var
+.\" .I var
.\" as well as free it from within the loop safely without interfering with the
.\" traversal.
-.\" .Pp
+.\" .PP
.\" The macro
-.\" .Nm STAILQ_FOREACH_FROM_SAFE
+.\" .BR STAILQ_FOREACH_FROM_SAFE ()
.\" behaves identically to
-.\" .Nm STAILQ_FOREACH_SAFE
+.\" .BR STAILQ_FOREACH_SAFE ()
.\" when
-.\" .Fa var
+.\" .I var
.\" is NULL, else it treats
-.\" .Fa var
+.\" .I var
.\" as a previously found STAILQ element and begins the loop at
-.\" .Fa var
+.\" .I var
.\" instead of the first element in the STAILQ referenced by
-.\" .Fa head .
-.Pp
+.\" .IR head .
+.PP
The macro
-.Nm STAILQ_INIT
+.BR STAILQ_INIT ()
initializes the tail queue referenced by
-.Fa head .
-.Pp
+.IR head .
+.PP
The macro
-.Nm STAILQ_INSERT_HEAD
+.BR STAILQ_INSERT_HEAD ()
inserts the new element
-.Fa elm
+.I elm
at the head of the tail queue.
-.Pp
+.PP
The macro
-.Nm STAILQ_INSERT_TAIL
+.BR STAILQ_INSERT_TAIL ()
inserts the new element
-.Fa elm
+.I elm
at the end of the tail queue.
-.Pp
+.PP
The macro
-.Nm STAILQ_INSERT_AFTER
+.BR STAILQ_INSERT_AFTER ()
inserts the new element
-.Fa elm
+.I elm
after the element
-.Fa listelm .
-.\" .Pp
+.IR listelm .
+.\" .PP
.\" The macro
-.\" .Nm STAILQ_LAST
+.\" .BR STAILQ_LAST ()
.\" returns the last item on the tail queue.
-.\" If the tail queue is empty the return value is
-.\" .Dv NULL .
-.Pp
+.\" If the tail queue is empty the return value is NULL .
+.PP
The macro
-.Nm STAILQ_NEXT
+.BR STAILQ_NEXT ()
returns the next item on the tail queue, or NULL this item is the last.
-.\" .Pp
+.\" .PP
.\" The macro
-.\" .Nm STAILQ_REMOVE_AFTER
+.\" .BR STAILQ_REMOVE_AFTER ()
.\" removes the element after
-.\" .Fa elm
+.\" .I elm
.\" from the tail queue.
.\" Unlike
-.\" .Fa STAILQ_REMOVE ,
+.\" .BR STAILQ_REMOVE (),
.\" this macro does not traverse the entire tail queue.
-.Pp
+.PP
The macro
-.Nm STAILQ_REMOVE_HEAD
+.BR STAILQ_REMOVE_HEAD ()
removes the element at the head of the tail queue.
For optimum efficiency,
elements being removed from the head of the tail queue should
use this macro explicitly rather than the generic
-.Fa STAILQ_REMOVE
+.BR STAILQ_REMOVE ()
macro.
-.Pp
+.PP
The macro
-.Nm STAILQ_REMOVE
+.BR STAILQ_REMOVE ()
removes the element
-.Fa elm
+.I elm
from the tail queue.
-.\" .Pp
+.\" .PP
.\" The macro
-.\" .Nm STAILQ_SWAP
+.\" .BR STAILQ_SWAP ()
.\" swaps the contents of
-.\" .Fa head1
+.\" .I head1
.\" and
-.\" .Fa head2 .
+.\" .IR head2 .
.SH RETURN VALUE
.SH CONFORMING TO
Not in POSIX.1, POSIX.1-2001 or POSIX.1-2008.
Present on the BSDs
-(STAILQ macros first appeared in
-.Bx 4.4 ).
+(STAILQ macros first appeared in 4.4BSD).
.SH BUGS
.SH EXAMPLES
-.Ss Singly-linked tail queue example
-.Bd -literal
+.EX
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -279,7 +306,7 @@ Present on the BSDs
struct entry {
int data;
- STAILQ_ENTRY(entry) entries; /* Singly-linked tail queue. */
+ STAILQ_ENTRY(entry) entries; /* Singly-linked tail queue. */
};
STAILQ_HEAD(stailhead, entry);
@@ -288,25 +315,25 @@ int
main(void)
{
struct entry *n1, *n2, *n3, *np;
- struct stailhead head; /* Singly-linked tail queue
- head. */
+ struct stailhead head; /* Singly-linked tail queue
+ head. */
- STAILQ_INIT(&head); /* Initialize the queue. */
+ STAILQ_INIT(&head); /* Initialize the queue. */
- n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
+ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
STAILQ_INSERT_HEAD(&head, n1, entries);
- n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */
+ n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */
STAILQ_INSERT_TAIL(&head, n1, entries);
- n2 = malloc(sizeof(struct entry)); /* Insert after. */
+ n2 = malloc(sizeof(struct entry)); /* Insert after. */
STAILQ_INSERT_AFTER(&head, n1, n2, entries);
STAILQ_REMOVE(&head, n2, entry, entries);/* Deletion. */
free(n2);
n3 = STAILQ_FIRST(&head);
- STAILQ_REMOVE_HEAD(&head, entries); /* Deletion from the head. */
+ STAILQ_REMOVE_HEAD(&head, entries); /* Deletion from the head. */
free(n3);
n1 = STAILQ_FIRST(&head);
@@ -316,10 +343,10 @@ main(void)
STAILQ_INSERT_HEAD(&head, n1, entries);
n1->data = i;
}
- /* Forward traversal. */
+ /* Forward traversal. */
STAILQ_FOREACH(np, &head, entries)
printf("%i\en", np->data);
- /* TailQ Deletion. */
+ /* TailQ Deletion. */
n1 = STAILQ_FIRST(&head);
while (n1 != NULL) {
n2 = STAILQ_NEXT(n1, entries);
@@ -330,5 +357,5 @@ main(void)
exit(EXIT_SUCCESS);
}
-.Ed
+.EE
.SH SEE ALSO
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 8/8] stailq.3: Add remaining details to complete the page
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
` (6 preceding siblings ...)
2020-10-24 22:21 ` [PATCH 7/8] stailq.3: ffix: Use man markup Alejandro Colomar
@ 2020-10-24 22:21 ` Alejandro Colomar
2020-10-24 22:30 ` [PATCH 09/10] STAILQ_CONCAT.3, STAILQ_EMPTY.3, STAILQ_ENTRY.3, STAILQ_FIRST.3, STAILQ_FOREACH.3, STAILQ_HEAD.3, STAILQ_HEAD_INITIALIZER.3, STAILQ_INIT.3, STAILQ_INSERT_AFTER.3, STAILQ_INSERT_HEAD.3, STAILQ_INSERT_TAIL.3, STAILQ_NEXT.3, STAILQ_REMOVE.3, STAILQ_REMOVE_HEAD.3: Link to the new stailq(3) page instead of queue(3) Alejandro Colomar
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:21 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/stailq.3 | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/man3/stailq.3 b/man3/stailq.3
index 0abacd824..2896d27c9 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -51,6 +51,7 @@ STAILQ_REMOVE,
.\"STAILQ_REMOVE_AFTER,
STAILQ_REMOVE_HEAD,
.\"STAILQ_SWAP
+\- implementation of a singly-linked tail queue
.SH SYNOPSIS
.nf
.B #include <sys/queue.h>
@@ -100,6 +101,8 @@ STAILQ_REMOVE_HEAD,
.\" .BI " STAILQ_ENTRY " NAME ");"
.fi
.SH DESCRIPTION
+These macros define and operate on singly-linked tail queues.
+.PP
In the macro definitions,
.I TYPE
is the name of a user-defined structure,
@@ -292,11 +295,38 @@ from the tail queue.
.\" and
.\" .IR head2 .
.SH RETURN VALUE
+.BR STAILQ_EMPTY ()
+returns nonzero if the queue is empty,
+and zero if the queue contains at least one entry.
+.PP
+.BR STAILQ_FIRST (),
+and
+.BR STAILQ_NEXT ()
+return a pointer to the first or next
+.I STAILQ_ENTRY
+structure, respectively.
+.PP
+.BR STAILQ_HEAD_INITIALIZER ()
+returns an initializer that can be assigned to the queue
+.IR head .
.SH CONFORMING TO
Not in POSIX.1, POSIX.1-2001 or POSIX.1-2008.
Present on the BSDs
(STAILQ macros first appeared in 4.4BSD).
.SH BUGS
+The macro
+.BR STAILQ_FOREACH ()
+doesn't allow
+.I var
+to be removed or freed within the loop,
+as it would interfere with the traversal.
+The macro
+.BR STAILQ_FOREACH_SAFE (),
+which is present on the BSDs but is not present in glibc,
+fixes this limitation by allowing
+.I var
+to safely be removed from the list and freed from within the loop
+without interfering with the traversal.
.SH EXAMPLES
.EX
#include <stddef.h>
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 09/10] STAILQ_CONCAT.3, STAILQ_EMPTY.3, STAILQ_ENTRY.3, STAILQ_FIRST.3, STAILQ_FOREACH.3, STAILQ_HEAD.3, STAILQ_HEAD_INITIALIZER.3, STAILQ_INIT.3, STAILQ_INSERT_AFTER.3, STAILQ_INSERT_HEAD.3, STAILQ_INSERT_TAIL.3, STAILQ_NEXT.3, STAILQ_REMOVE.3, STAILQ_REMOVE_HEAD.3: Link to the new stailq(3) page instead of queue(3)
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
` (7 preceding siblings ...)
2020-10-24 22:21 ` [PATCH 8/8] stailq.3: Add remaining details to complete the page Alejandro Colomar
@ 2020-10-24 22:30 ` Alejandro Colomar
2020-10-24 22:30 ` [PATCH 10/10] queue.3: SEE ALSO: Add stailq(3) Alejandro Colomar
2020-10-25 9:13 ` [PATCH 0/8] stailq.3 Michael Kerrisk (man-pages)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:30 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
I forgot these two commits. Sending them now.
man3/STAILQ_CONCAT.3 | 2 +-
man3/STAILQ_EMPTY.3 | 2 +-
man3/STAILQ_ENTRY.3 | 2 +-
man3/STAILQ_FIRST.3 | 2 +-
man3/STAILQ_FOREACH.3 | 2 +-
man3/STAILQ_HEAD.3 | 2 +-
man3/STAILQ_HEAD_INITIALIZER.3 | 2 +-
man3/STAILQ_INIT.3 | 2 +-
man3/STAILQ_INSERT_AFTER.3 | 2 +-
man3/STAILQ_INSERT_HEAD.3 | 2 +-
man3/STAILQ_INSERT_TAIL.3 | 2 +-
man3/STAILQ_NEXT.3 | 2 +-
man3/STAILQ_REMOVE.3 | 2 +-
man3/STAILQ_REMOVE_HEAD.3 | 2 +-
14 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/man3/STAILQ_CONCAT.3 b/man3/STAILQ_CONCAT.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_CONCAT.3
+++ b/man3/STAILQ_CONCAT.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_EMPTY.3 b/man3/STAILQ_EMPTY.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_EMPTY.3
+++ b/man3/STAILQ_EMPTY.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_ENTRY.3 b/man3/STAILQ_ENTRY.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_ENTRY.3
+++ b/man3/STAILQ_ENTRY.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_FIRST.3 b/man3/STAILQ_FIRST.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_FIRST.3
+++ b/man3/STAILQ_FIRST.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_FOREACH.3 b/man3/STAILQ_FOREACH.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_FOREACH.3
+++ b/man3/STAILQ_FOREACH.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_HEAD.3 b/man3/STAILQ_HEAD.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_HEAD.3
+++ b/man3/STAILQ_HEAD.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_HEAD_INITIALIZER.3 b/man3/STAILQ_HEAD_INITIALIZER.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_HEAD_INITIALIZER.3
+++ b/man3/STAILQ_HEAD_INITIALIZER.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_INIT.3 b/man3/STAILQ_INIT.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_INIT.3
+++ b/man3/STAILQ_INIT.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_INSERT_AFTER.3 b/man3/STAILQ_INSERT_AFTER.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_INSERT_AFTER.3
+++ b/man3/STAILQ_INSERT_AFTER.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_INSERT_HEAD.3 b/man3/STAILQ_INSERT_HEAD.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_INSERT_HEAD.3
+++ b/man3/STAILQ_INSERT_HEAD.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_INSERT_TAIL.3 b/man3/STAILQ_INSERT_TAIL.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_INSERT_TAIL.3
+++ b/man3/STAILQ_INSERT_TAIL.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_NEXT.3 b/man3/STAILQ_NEXT.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_NEXT.3
+++ b/man3/STAILQ_NEXT.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_REMOVE.3 b/man3/STAILQ_REMOVE.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_REMOVE.3
+++ b/man3/STAILQ_REMOVE.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
diff --git a/man3/STAILQ_REMOVE_HEAD.3 b/man3/STAILQ_REMOVE_HEAD.3
index c2956c9fc..fbb71f02c 100644
--- a/man3/STAILQ_REMOVE_HEAD.3
+++ b/man3/STAILQ_REMOVE_HEAD.3
@@ -1 +1 @@
-.so man3/queue.3
+.so man3/stailq.3
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH 10/10] queue.3: SEE ALSO: Add stailq(3)
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
` (8 preceding siblings ...)
2020-10-24 22:30 ` [PATCH 09/10] STAILQ_CONCAT.3, STAILQ_EMPTY.3, STAILQ_ENTRY.3, STAILQ_FIRST.3, STAILQ_FOREACH.3, STAILQ_HEAD.3, STAILQ_HEAD_INITIALIZER.3, STAILQ_INIT.3, STAILQ_INSERT_AFTER.3, STAILQ_INSERT_HEAD.3, STAILQ_INSERT_TAIL.3, STAILQ_NEXT.3, STAILQ_REMOVE.3, STAILQ_REMOVE_HEAD.3: Link to the new stailq(3) page instead of queue(3) Alejandro Colomar
@ 2020-10-24 22:30 ` Alejandro Colomar
2020-10-25 9:13 ` [PATCH 0/8] stailq.3 Michael Kerrisk (man-pages)
10 siblings, 0 replies; 12+ messages in thread
From: Alejandro Colomar @ 2020-10-24 22:30 UTC (permalink / raw)
To: mtk.manpages; +Cc: Alejandro Colomar, linux-man, libc-alpha
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
man3/queue.3 | 1 +
1 file changed, 1 insertion(+)
diff --git a/man3/queue.3 b/man3/queue.3
index 00fd36b91..4c597e123 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -181,4 +181,5 @@ functions first appeared in
.Xr insque 3
.Xr list 3
.Xr slist 3
+.Xr stailq 3
.\" .Xr tree 3
--
2.28.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 0/8] stailq.3
2020-10-24 22:21 [PATCH 0/8] stailq.3 Alejandro Colomar
` (9 preceding siblings ...)
2020-10-24 22:30 ` [PATCH 10/10] queue.3: SEE ALSO: Add stailq(3) Alejandro Colomar
@ 2020-10-25 9:13 ` Michael Kerrisk (man-pages)
10 siblings, 0 replies; 12+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-10-25 9:13 UTC (permalink / raw)
To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, libc-alpha
Hi Alex,
On 10/25/20 12:21 AM, Alejandro Colomar wrote:
> Hi Michael,
Thanks! I've merged and pushed this series of patches.
> It's almost done.
Yup!
> I'm thinking about what to do with queue.3.
> You can see its current contents in my branch 'queue'.
> Do you have any suggestions for it?
How about:
====
Change
[[
These macros define and operate...
]]
to:
[[
The <sys/queue.h> header file provides a set of
macros that define and operate...
]]
====
Split up the remainder of the DESCRIPTION using subsections:
[[
.SS Singly-linked lists (SLIST)
Singly-linked lists are the simplest
and support only the above functionality.
...
For further details, see
.BR slist (3).
...
]]
Would that be workable?
====
Rather than writing your lists as:
[[
.TP
-
Insertion of a new entry at the head of the list.
.TP
-
Insertion of a new entry after any element in the list.
...
]]
I'd prefer:
[[
.IP * 3
Insertion of a new entry at the head of the list.
.IP *
Insertion of a new entry after any element in the list.
...
]]
Thanks,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
^ permalink raw reply [flat|nested] 12+ messages in thread