[05/10] queue.3, tailq.3: EXAMPLES: Move code from queue.3 to tailq.3

Message ID 20201025093651.4616-6-colomar.6.4.3@gmail.com
State Not applicable
Headers
Series tailq.3: fork from queue.3 |

Commit Message

Alejandro Colomar Oct. 25, 2020, 9:36 a.m. UTC
  Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man3/queue.3 | 56 ----------------------------------------------------
 man3/tailq.3 | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 56 deletions(-)
  

Patch

diff --git a/man3/queue.3 b/man3/queue.3
index f6e3b9369..4c597e123 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -170,62 +170,6 @@  The termination condition for traversal is more complex.
 Code size is about 40% greater and operations run about 45% slower than lists.
 .El
 .Sh EXAMPLES
-.Ss Tail queue example
-.Bd -literal
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/queue.h>
-
-struct entry {
-    int data;
-    TAILQ_ENTRY(entry) entries;             /* Tail queue. */
-};
-
-TAILQ_HEAD(tailhead, entry);
-
-int
-main(void)
-{
-    struct entry    *n1, *n2, *n3, *np;
-    struct tailhead head;                   /* Tail queue head. */
-    int     i;
-
-    TAILQ_INIT(&head);                      /* Initialize the queue. */
-
-    n1 = malloc(sizeof(struct entry));      /* Insert at the head. */
-    TAILQ_INSERT_HEAD(&head, n1, entries);
-
-    n1 = malloc(sizeof(struct entry));      /* Insert at the tail. */
-    TAILQ_INSERT_TAIL(&head, n1, entries);
-
-    n2 = malloc(sizeof(struct entry));      /* Insert after. */
-    TAILQ_INSERT_AFTER(&head, n1, n2, entries);
-
-    n3 = malloc(sizeof(struct entry));      /* Insert before. */
-    TAILQ_INSERT_BEFORE(n2, n3, entries);
-
-    TAILQ_REMOVE(&head, n2, entries);       /* Deletion. */
-    free(n2);
-                                            /* Forward traversal. */
-    i = 0;
-    TAILQ_FOREACH(np, &head, entries)
-        np->data = i++;
-                                            /* Reverse traversal. */
-    TAILQ_FOREACH_REVERSE(np, &head, tailhead, entries)
-        printf("%i\en", np->data);
-                                            /* TailQ Deletion. */
-    n1 = TAILQ_FIRST(&head);
-    while (n1 != NULL) {
-        n2 = TAILQ_NEXT(n1, entries);
-        free(n1);
-        n1 = n2;
-    }
-    TAILQ_INIT(&head);
-
-    exit(EXIT_SUCCESS);
-}
-.Ed
 .Sh CONFORMING TO
 Not in POSIX.1, POSIX.1-2001 or POSIX.1-2008.
 Present on the BSDs.
diff --git a/man3/tailq.3 b/man3/tailq.3
index 144a86f3f..28a7ac509 100644
--- a/man3/tailq.3
+++ b/man3/tailq.3
@@ -323,4 +323,60 @@  See the EXAMPLES section below for an example program using a tail queue.
 .SH CONFORMING TO
 .SH BUGS
 .SH EXAMPLES
+.Ss Tail queue example
+.Bd -literal
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+
+struct entry {
+    int data;
+    TAILQ_ENTRY(entry) entries;             /* Tail queue. */
+};
+
+TAILQ_HEAD(tailhead, entry);
+
+int
+main(void)
+{
+    struct entry    *n1, *n2, *n3, *np;
+    struct tailhead head;                   /* Tail queue head. */
+    int     i;
+
+    TAILQ_INIT(&head);                      /* Initialize the queue. */
+
+    n1 = malloc(sizeof(struct entry));      /* Insert at the head. */
+    TAILQ_INSERT_HEAD(&head, n1, entries);
+
+    n1 = malloc(sizeof(struct entry));      /* Insert at the tail. */
+    TAILQ_INSERT_TAIL(&head, n1, entries);
+
+    n2 = malloc(sizeof(struct entry));      /* Insert after. */
+    TAILQ_INSERT_AFTER(&head, n1, n2, entries);
+
+    n3 = malloc(sizeof(struct entry));      /* Insert before. */
+    TAILQ_INSERT_BEFORE(n2, n3, entries);
+
+    TAILQ_REMOVE(&head, n2, entries);       /* Deletion. */
+    free(n2);
+                                            /* Forward traversal. */
+    i = 0;
+    TAILQ_FOREACH(np, &head, entries)
+        np->data = i++;
+                                            /* Reverse traversal. */
+    TAILQ_FOREACH_REVERSE(np, &head, tailhead, entries)
+        printf("%i\en", np->data);
+                                            /* TailQ Deletion. */
+    n1 = TAILQ_FIRST(&head);
+    while (n1 != NULL) {
+        n2 = TAILQ_NEXT(n1, entries);
+        free(n1);
+        n1 = n2;
+    }
+    TAILQ_INIT(&head);
+
+    exit(EXIT_SUCCESS);
+}
+.Ed
 .SH SEE ALSO