Index: trunk/Ohana/src/opihi/lib.data/queues.c
===================================================================
--- trunk/Ohana/src/opihi/lib.data/queues.c	(revision 7917)
+++ trunk/Ohana/src/opihi/lib.data/queues.c	(revision 8190)
@@ -141,5 +141,5 @@
 }
 
-char *ChooseKey (char *line, int Key) {
+char *ChooseSingleKey (char *line, int Key) {
 
   int i;
@@ -147,16 +147,53 @@
 
   key = line;
-  if (Key != -1) {
-    for (i = 0; (i < Key) && (key != NULL); i++) {
-      p = nextword (key);
-      key = p;
+  if (Key == -1) return line;
+
+  for (i = 0; (i < Key) && (key != NULL); i++) {
+    p = nextword (key);
+    key = p;
+  }
+  key = thisword (key);
+  return (key);
+}
+
+/* construct merged key given keylist of the form K:N:M */ 
+char *ChooseKey (char *line, char *keylist) {
+
+  char *output, *entry, *key, *p, *q;
+  int first, keynum;
+
+  if (line == NULL) return (NULL);
+  if (keylist == NULL) return (line);
+
+  ALLOCATE (output, char, strlen(line) + 1);
+  memset (output, 0, strlen(line) + 1);
+
+  first = TRUE;
+  p = q = keylist;
+  while (q != NULL) {
+    q = strchr (p, ':');
+    if (q == NULL) {
+      entry = strcreate (p);
+    } else {
+      entry = strncreate (p, q - p);
     }
-    key = thisword (key);
-  } 
-  return (key);
+    keynum = atoi (entry);
+    free (entry);
+
+    key = ChooseSingleKey (line, keynum);
+
+    if (!first) strcat (output, ":");
+    strcat (output, key);
+    free (key);
+
+    if (q != NULL) p = q + 1;
+    first = FALSE;
+  }
+
+  return (output);
 }
 
 /* push line onto queue, skipping existing matches (optionally by key) */
-void PushQueueUnique (Queue *queue, char *line, int Key) {
+void PushQueueUnique (Queue *queue, char *line, char *Key) {
 
   int i, j, N, found;
@@ -213,5 +250,5 @@
 
 /* push line onto queue, replacing matches (optionally by Key) */
-void PushQueueReplace (Queue *queue, char *line, int Key) {
+void PushQueueReplace (Queue *queue, char *line, char *Key) {
 
   int i, j, N, found;
@@ -291,5 +328,5 @@
 
 /* pop the first entry which for which the key matches */
-char *PopQueueMatch (Queue *queue, int Key, char *value) {
+char *PopQueueMatch (Queue *queue, char *Key, char *value) {
 
   int i, choice, NLINES_2;
