[PATCH 19/22] list.3, queue.3: EXAMPLES: Move example program from queue.3 to list.3

Alejandro Colomar
2020-10-20T14:23:45Z

man3/list.3 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++
man3/queue.3 | 53 ----------------------------------------------------
2 files changed, 53 insertions(+), 53 deletions(-)

diff --git a/man3/list.3 b/man3/list.3
index 82ab4dae4..b22453ab9 100644
--- a/man3/list.3
+++ b/man3/list.3
@@ -262,6 +262,59 @@ Present on the BSDs
(LIST macros first appeared in 4.4BSD).
.SH BUGS
.SH EXAMPLES
+.Ss List example
+.Bd -literal
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+
+struct entry {
+ int data;
+ LIST_ENTRY(entry) entries; /* List. */
+};
+
+LIST_HEAD(listhead, entry);
+
+int
+main(void)
+{
+ struct entry *n1, *n2, *n3, *np;
+ struct listhead head; /* List head. */
+ int i;
+
+ LIST_INIT(&head); /* Initialize the list. */
+
+ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
+ LIST_INSERT_HEAD(&head, n1, entries);
+
+ n2 = malloc(sizeof(struct entry)); /* Insert after. */
+ LIST_INSERT_AFTER(n1, n2, entries);
+
+ n3 = malloc(sizeof(struct entry)); /* Insert before. */
+ LIST_INSERT_BEFORE(n2, n3, entries);
+
+ i = 0; /* Forward traversal. */
+ LIST_FOREACH(np, &head, entries)
+ np->data = i++;
+
+ LIST_REMOVE(n2, entries); /* Deletion. */
+ free(n2);
+ /* Forward traversal. */
+ LIST_FOREACH(np, &head, entries)
+ printf("%i\en", np->data);
+ /* List Deletion. */
+ n1 = LIST_FIRST(&head);
+ while (n1 != NULL) {
+ n2 = LIST_NEXT(n1, entries);
+ free(n1);
+ n1 = n2;
+ }
+ LIST_INIT(&head);
+
+ exit(EXIT_SUCCESS);
+}
+.Ed
.SH SEE ALSO
.BR insque (3),
.BR queue (3)
diff --git a/man3/queue.3 b/man3/queue.3
index 6ee793e25..0f55a899e 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -1155,59 +1155,6 @@ main(void)
exit(EXIT_SUCCESS);
}
.Ed
-.Ss List example
-.Bd -literal
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/queue.h>
-
-struct entry {
- int data;
- LIST_ENTRY(entry) entries; /* List. */
-};
-
-LIST_HEAD(listhead, entry);
-
-int
-main(void)
-{
- struct entry *n1, *n2, *n3, *np;
- struct listhead head; /* List head. */
- int i;
-
- LIST_INIT(&head); /* Initialize the list. */
-
- n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
- LIST_INSERT_HEAD(&head, n1, entries);
-
- n2 = malloc(sizeof(struct entry)); /* Insert after. */
- LIST_INSERT_AFTER(n1, n2, entries);
-
- n3 = malloc(sizeof(struct entry)); /* Insert before. */
- LIST_INSERT_BEFORE(n2, n3, entries);
-
- i = 0; /* Forward traversal. */
- LIST_FOREACH(np, &head, entries)
- np->data = i++;
-
- LIST_REMOVE(n2, entries); /* Deletion. */
- free(n2);
- /* Forward traversal. */
- LIST_FOREACH(np, &head, entries)
- printf("%i\en", np->data);
- /* List Deletion. */
- n1 = LIST_FIRST(&head);
- while (n1 != NULL) {
- n2 = LIST_NEXT(n1, entries);
- free(n1);
- n1 = n2;
- }
- LIST_INIT(&head);
-
- exit(EXIT_SUCCESS);
-}
-.Ed
.Ss Tail queue example
.Bd -literal
#include <stddef.h>
--
2.28.0