IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 5, 2006, 3:52:41 AM (20 years ago)
Author:
eugene
Message:

changed queue key to allow multiple columns

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.data/queues.c

    r7917 r8190  
    141141}
    142142
    143 char *ChooseKey (char *line, int Key) {
     143char *ChooseSingleKey (char *line, int Key) {
    144144
    145145  int i;
     
    147147
    148148  key = line;
    149   if (Key != -1) {
    150     for (i = 0; (i < Key) && (key != NULL); i++) {
    151       p = nextword (key);
    152       key = p;
     149  if (Key == -1) return line;
     150
     151  for (i = 0; (i < Key) && (key != NULL); i++) {
     152    p = nextword (key);
     153    key = p;
     154  }
     155  key = thisword (key);
     156  return (key);
     157}
     158
     159/* construct merged key given keylist of the form K:N:M */
     160char *ChooseKey (char *line, char *keylist) {
     161
     162  char *output, *entry, *key, *p, *q;
     163  int first, keynum;
     164
     165  if (line == NULL) return (NULL);
     166  if (keylist == NULL) return (line);
     167
     168  ALLOCATE (output, char, strlen(line) + 1);
     169  memset (output, 0, strlen(line) + 1);
     170
     171  first = TRUE;
     172  p = q = keylist;
     173  while (q != NULL) {
     174    q = strchr (p, ':');
     175    if (q == NULL) {
     176      entry = strcreate (p);
     177    } else {
     178      entry = strncreate (p, q - p);
    153179    }
    154     key = thisword (key);
    155   }
    156   return (key);
     180    keynum = atoi (entry);
     181    free (entry);
     182
     183    key = ChooseSingleKey (line, keynum);
     184
     185    if (!first) strcat (output, ":");
     186    strcat (output, key);
     187    free (key);
     188
     189    if (q != NULL) p = q + 1;
     190    first = FALSE;
     191  }
     192
     193  return (output);
    157194}
    158195
    159196/* push line onto queue, skipping existing matches (optionally by key) */
    160 void PushQueueUnique (Queue *queue, char *line, int Key) {
     197void PushQueueUnique (Queue *queue, char *line, char *Key) {
    161198
    162199  int i, j, N, found;
     
    213250
    214251/* push line onto queue, replacing matches (optionally by Key) */
    215 void PushQueueReplace (Queue *queue, char *line, int Key) {
     252void PushQueueReplace (Queue *queue, char *line, char *Key) {
    216253
    217254  int i, j, N, found;
     
    291328
    292329/* pop the first entry which for which the key matches */
    293 char *PopQueueMatch (Queue *queue, int Key, char *value) {
     330char *PopQueueMatch (Queue *queue, char *Key, char *value) {
    294331
    295332  int i, choice, NLINES_2;
Note: See TracChangeset for help on using the changeset viewer.