Use queue(3) Macros in paste(1)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Use queue(3) Macros in paste(1)

Ray Lai
Hi,

This diff replaces the custom linked list with queue(3) macros.  It
also renames _list to list to avoid stepping in the system's space.

-Ray-

Index: paste.c
===================================================================
RCS file: /cvs/src/usr.bin/paste/paste.c,v
retrieving revision 1.14
diff -u -r1.14 paste.c
--- paste.c 10 Oct 2004 03:29:29 -0000 1.14
+++ paste.c 4 Jan 2006 22:45:04 -0000
@@ -43,6 +43,7 @@
 static char rcsid[] = "$OpenBSD: paste.c,v 1.14 2004/10/10 03:29:29 mickey Exp $";
 #endif /* not lint */
 
+#include <sys/queue.h>
 #include <sys/types.h>
 #include <err.h>
 #include <errno.h>
@@ -95,45 +96,40 @@
  exit(0);
 }
 
-typedef struct _list {
- struct _list *next;
+struct list {
+ SIMPLEQ_ENTRY(list) entries;
  FILE *fp;
  int cnt;
  char *name;
-} LIST;
+};
 
 void
 parallel(char **argv)
 {
- LIST *lp;
+ SIMPLEQ_HEAD(, list) head = SIMPLEQ_HEAD_INITIALIZER(head);
+ struct list *lp;
  int cnt;
  char ch, *p;
- LIST *head, *tmp;
  int opencnt, output;
  char *buf, *lbuf;
  size_t len;
 
- for (cnt = 0, head = NULL; (p = *argv); ++argv, ++cnt) {
- if (!(lp = (LIST *)malloc((u_int)sizeof(LIST))))
+ for (cnt = 0; (p = *argv); ++argv, ++cnt) {
+ if (!(lp = malloc(sizeof(struct list))))
  err(1, "malloc");
 
  if (p[0] == '-' && !p[1])
  lp->fp = stdin;
  else if (!(lp->fp = fopen(p, "r")))
  err(1, "%s", p);
- lp->next = NULL;
  lp->cnt = cnt;
  lp->name = p;
- if (!head)
- head = tmp = lp;
- else {
- tmp->next = lp;
- tmp = lp;
- }
+ SIMPLEQ_INSERT_TAIL(&head, lp, entries);
  }
 
  for (opencnt = cnt; opencnt;) {
- for (output = 0, lp = head; lp; lp = lp->next) {
+ output = 0;
+ SIMPLEQ_FOREACH(lp, &head, entries) {
  lbuf = NULL;
  if (!lp->fp) {
  if (output && lp->cnt &&