]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
circleq.3, queue.3: EXAMPLES: Move circleq example program from queue.3 to circleq.3
authorAlejandro Colomar <colomar.6.4.3@gmail.com>
Fri, 23 Oct 2020 14:57:31 +0000 (16:57 +0200)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Fri, 23 Oct 2020 16:13:06 +0000 (18:13 +0200)
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
man3/circleq.3
man3/queue.3

index a28a8291900c46f134fa4f47aa572e4f2823cf2c..2d683b441be8c4b2178f4e50a5ab93f797e8af18 100644 (file)
@@ -210,4 +210,60 @@ from the circular queue.
 .SH CONFORMING TO
 .SH BUGS
 .SH EXAMPLES
+.Ss Circular queue example
+.Bd -literal
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+
+struct entry {
+    int data;
+    CIRCLEQ_ENTRY(entry) entries;           /* Queue. */
+};
+
+CIRCLEQ_HEAD(circlehead, entry);
+
+int
+main(void)
+{
+    struct entry    *n1, *n2, *n3, *np;
+    struct circlehead head;                 /* Queue head. */
+    int     i;
+
+    CIRCLEQ_INIT(&head);                    /* Initialize the queue. */
+
+    n1 = malloc(sizeof(struct entry));      /* Insert at the head. */
+    CIRCLEQ_INSERT_HEAD(&head, n1, entries);
+
+    n1 = malloc(sizeof(struct entry));      /* Insert at the tail. */
+    CIRCLEQ_INSERT_TAIL(&head, n1, entries);
+
+    n2 = malloc(sizeof(struct entry));      /* Insert after. */
+    CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);
+
+    n3 = malloc(sizeof(struct entry));      /* Insert before. */
+    CIRCLEQ_INSERT_BEFORE(&head, n2, n3, entries);
+
+    CIRCLEQ_REMOVE(&head, n2, entries);     /* Deletion. */
+    free(n2);
+                                            /* Forward traversal. */
+    i = 0;
+    CIRCLEQ_FOREACH(np, &head, entries)
+        np->data = i++;
+                                            /* Reverse traversal. */
+    CIRCLEQ_FOREACH_REVERSE(np, &head, entries)
+        printf("%i\en", np->data);
+                                            /* Queue deletion. */
+    n1 = CIRCLEQ_FIRST(&head);
+    while (n1 != (void *)&head) {
+        n2 = CIRCLEQ_NEXT(n1, entries);
+        free(n1);
+        n1 = n2;
+    }
+    CIRCLEQ_INIT(&head);
+
+    exit(EXIT_SUCCESS);
+}
+.Ed
 .SH SEE ALSO
index 7947908810dc1a55476ba0cc6a80214d4548e914..26e304b2f9f734cd84798d0e1e71ee8363642ca9 100644 (file)
@@ -791,62 +791,6 @@ main(void)
     exit(EXIT_SUCCESS);
 }
 .Ed
-.Ss Circular queue example
-.Bd -literal
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/queue.h>
-
-struct entry {
-    int data;
-    CIRCLEQ_ENTRY(entry) entries;           /* Queue. */
-};
-
-CIRCLEQ_HEAD(circlehead, entry);
-
-int
-main(void)
-{
-    struct entry    *n1, *n2, *n3, *np;
-    struct circlehead head;                 /* Queue head. */
-    int     i;
-
-    CIRCLEQ_INIT(&head);                    /* Initialize the queue. */
-
-    n1 = malloc(sizeof(struct entry));      /* Insert at the head. */
-    CIRCLEQ_INSERT_HEAD(&head, n1, entries);
-
-    n1 = malloc(sizeof(struct entry));      /* Insert at the tail. */
-    CIRCLEQ_INSERT_TAIL(&head, n1, entries);
-
-    n2 = malloc(sizeof(struct entry));      /* Insert after. */
-    CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);
-
-    n3 = malloc(sizeof(struct entry));      /* Insert before. */
-    CIRCLEQ_INSERT_BEFORE(&head, n2, n3, entries);
-
-    CIRCLEQ_REMOVE(&head, n2, entries);     /* Deletion. */
-    free(n2);
-                                            /* Forward traversal. */
-    i = 0;
-    CIRCLEQ_FOREACH(np, &head, entries)
-        np->data = i++;
-                                            /* Reverse traversal. */
-    CIRCLEQ_FOREACH_REVERSE(np, &head, entries)
-        printf("%i\en", np->data);
-                                            /* Queue deletion. */
-    n1 = CIRCLEQ_FIRST(&head);
-    while (n1 != (void *)&head) {
-        n2 = CIRCLEQ_NEXT(n1, entries);
-        free(n1);
-        n1 = n2;
-    }
-    CIRCLEQ_INIT(&head);
-
-    exit(EXIT_SUCCESS);
-}
-.Ed
 .Sh CONFORMING TO
 Not in POSIX.1, POSIX.1-2001 or POSIX.1-2008.
 Present on the BSDs.