Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ remque(3C) — DG/UX 4.30

Media Vault

Software Library

Restoration Projects

Artifacts Sought



     remque(3C)                 DG/UX 4.30                  remque(3C)



     NAME
          remque - Remove an element from a circular queue.

     SYNOPSIS
          struct qelem {
          struct qelem *qforw;
          struct qelem *qback;
          /* User data follows */
          } *elem;

          int remque();
          remque(elem);


          where   elem is a pointer to the structure to remove from a
                  linked list.


     DESCRIPTION
          The remque function removes an element from a circular
          linked list; this function comes from the University of
          California Berkeley UNIX (BSD) system.

          The structures in the linked list must reserve the first two
          double words for use as the forward and backward pointers.
          Since the linked list is a circular list, the initial
          element must have forward and backward links to itself.

     RETURNS
          The remque function does not return a value.

     SEE ALSO
          See also the insque function.

     EXAMPLE
          This program reads lines from standard input, creates a
          linked list, removes elements from the list with remque, and
          prints the elements.
          /* Program test for the remque() function */

          #include <stdio.h>

          #define LSIZE 256       /* line size */

          extern char  *malloc();
          extern int   insque(), remque();
          extern void  free();

          struct qelem {
              struct qelem *q_forw;       /* forward link */
              struct qelem *q_back;       /* backward link */
              char buffer[LSIZE];         /* line buffer */



     Licensed material--property of copyright holder(s)         Page 1





     remque(3C)                 DG/UX 4.30                  remque(3C)



          };

          struct qelem head = {&head, &head}; /* head of queue */
          struct qelem *p_last = &head;   /* last item */
          struct qelem *p_line;           /* ptr to walk list */
          struct qelem *p_next;           /* next item in list */

          main() {
              for (;;) {
                  p_line = (struct qelem *)
                           malloc(sizeof(struct qelem));
                  if (p_line == (struct qelem *)0) {
                      printf("Out of memory.\n");
                      exit(1);
                  }
                  if (!fgets(p_line -> buffer, LSIZE, stdin))
                      break;      /* End of file found */
                  (void) insque(p_line, p_last);
                  p_last = p_line;
              }
              free((char *)p_line);

              /* Now walk list and print elements */

              for (p_line = head.q_forw; p_line != &head;
                   p_line = p_next) {
                  p_next = p_line -> q_forw;
                  (void) remque(p_line);
                  fputs(p_line -> buffer, stdout);
                  free((char *)p_line);
              }
              return 0;
          }






















     Licensed material--property of copyright holder(s)         Page 2



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026