Index: trunk/Ohana/src/opihi/lib.data/queues.c
===================================================================
--- trunk/Ohana/src/opihi/lib.data/queues.c	(revision 4704)
+++ trunk/Ohana/src/opihi/lib.data/queues.c	(revision 6249)
@@ -281,4 +281,5 @@
   queue[0].Nlines --;
 
+  /* shrink queue allocation if small enough */
   NLINES_2 = MAX (16, queue[0].NLINES / 2);
   if (queue[0].Nlines < NLINES_2) {
@@ -289,4 +290,38 @@
 }
 
+/* pop the first entry which for which the key matches */
+char *PopQueueMatch (Queue *queue, int Key, char *value) {
+
+  int i, choice, NLINES_2;
+  char *line, *test;
+
+  if (queue[0].Nlines == 0) return (NULL);
+
+  /* find the matching key */
+  choice = -1;
+  for (i = 0; (i < queue[0].Nlines) && (choice == -1); i++) {
+      test = ChooseKey (queue[0].lines[i], Key);
+      if (test == NULL) continue;
+      if (strcmp (value, test)) continue;
+      choice = i;
+  }
+  if (choice == -1) return NULL;
+
+  line = queue[0].lines[choice];
+
+  for (i = choice; i < queue[0].Nlines - 1; i++) {
+    queue[0].lines[i] = queue[0].lines[i+1];
+  }
+  queue[0].Nlines --;
+
+  /* shrink queue allocation if small enough */
+  NLINES_2 = MAX (16, queue[0].NLINES / 2);
+  if (queue[0].Nlines < NLINES_2) {
+    queue[0].NLINES = NLINES_2;
+    REALLOCATE (queue[0].lines, char *, queue[0].NLINES);
+  }    
+  return (line);
+}
+
 int PrintQueue (FILE *f, Queue *queue) {
 
