IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8190


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

changed queue key to allow multiple columns

Location:
trunk/Ohana/src/opihi
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/queuepop.c

    r7917 r8190  
    33int queuepop (int argc, char **argv) {
    44 
    5   int N, Key;
     5  int N;
     6  char *Key;
    67  char *var;
    78  char *line;
     
    1617  }
    1718
    18   Key = -1;
     19  Key = NULL;
    1920  if ((N = get_argument (argc, argv, "-key"))) {
    2021    remove_argument (N, &argc, argv);
    21     Key = atoi (argv[N]);
     22    Key = strcreate (argv[N]);
    2223    remove_argument (N, &argc, argv);
    2324    Value = strcreate (argv[N]);
     
    3839  }
    3940
    40   if (Key == -1) {
    41       line = PopQueue (queue);
     41  if (Key == NULL) {
     42    line = PopQueue (queue);
    4243  } else {
    43       line = PopQueueMatch (queue, Key, Value);
     44    line = PopQueueMatch (queue, Key, Value);
    4445  }
    4546
    4647  if (var == NULL) {
    47       if (line == NULL) {
    48           gprint (GP_ERR, "queue %s is empty or match not found\n", argv[1]);
    49           return (FALSE);
    50       } else {
    51           gprint (GP_ERR, "%s\n", line);
    52           return (TRUE);
    53       }
     48    if (line == NULL) {
     49      gprint (GP_ERR, "queue %s is empty or match not found\n", argv[1]);
     50      return (FALSE);
     51    } else {
     52      gprint (GP_ERR, "%s\n", line);
     53      return (TRUE);
     54    }
    5455  }
    5556
     
    6162
    6263  free (line);
     64  if (Key != NULL) free (Key);
     65
    6366  return (TRUE);
    6467}
  • trunk/Ohana/src/opihi/cmd.data/queuepush.c

    r7917 r8190  
    33int queuepush (int argc, char **argv) {
    44 
    5   int N, Unique, Replace, Key;
     5  char *Key;
     6  int N, Unique, Replace;
    67  Queue *queue;
    78
     
    1819  }
    1920
    20   Key = -1;
     21  Key = NULL;
    2122  if ((N = get_argument (argc, argv, "-key"))) {
    2223    remove_argument (N, &argc, argv);
    23     Key = atoi (argv[N]);
     24    Key = strcreate (argv[N]);
    2425    remove_argument (N, &argc, argv);
    2526  }
     
    4243    PushQueue (queue, argv[2]);
    4344  }
     45
     46  if (Key != NULL) free (Key);
    4447  return (TRUE);
    4548}
  • trunk/Ohana/src/opihi/doc/pantasks.txt

    r7952 r8190  
     1
     2- updates for queues:
     3
     4  -key 1:2:4 (key is string with possibly multiple columns joined)
     5  string function to drop first word
     6
    17
    28- todo:
  • trunk/Ohana/src/opihi/include/data.h

    r7917 r8190  
    2626void PushNamedQueue (char *name, char *line);
    2727char *PopQueue (Queue *queue);
    28 char *PopQueueMatch (Queue *queue, int Key, char *value);
    29 void PushQueueUnique (Queue *queue, char *line, int Key);
    30 void PushQueueReplace (Queue *queue, char *line, int Key);
     28char *PopQueueMatch (Queue *queue, char *Key, char *value);
     29void PushQueueUnique (Queue *queue, char *line, char *Key);
     30void PushQueueReplace (Queue *queue, char *line, char *Key);
    3131int InitQueue (Queue *queue);
    3232int DeleteQueue (Queue *queue);
  • 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.