Changeset 8190
- Timestamp:
- Aug 5, 2006, 3:52:41 AM (20 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 5 edited
-
cmd.data/queuepop.c (modified) (4 diffs)
-
cmd.data/queuepush.c (modified) (3 diffs)
-
doc/pantasks.txt (modified) (1 diff)
-
include/data.h (modified) (1 diff)
-
lib.data/queues.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.data/queuepop.c
r7917 r8190 3 3 int queuepop (int argc, char **argv) { 4 4 5 int N, Key; 5 int N; 6 char *Key; 6 7 char *var; 7 8 char *line; … … 16 17 } 17 18 18 Key = -1;19 Key = NULL; 19 20 if ((N = get_argument (argc, argv, "-key"))) { 20 21 remove_argument (N, &argc, argv); 21 Key = atoi(argv[N]);22 Key = strcreate (argv[N]); 22 23 remove_argument (N, &argc, argv); 23 24 Value = strcreate (argv[N]); … … 38 39 } 39 40 40 if (Key == -1) {41 line = PopQueue (queue);41 if (Key == NULL) { 42 line = PopQueue (queue); 42 43 } else { 43 line = PopQueueMatch (queue, Key, Value);44 line = PopQueueMatch (queue, Key, Value); 44 45 } 45 46 46 47 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 } 54 55 } 55 56 … … 61 62 62 63 free (line); 64 if (Key != NULL) free (Key); 65 63 66 return (TRUE); 64 67 } -
trunk/Ohana/src/opihi/cmd.data/queuepush.c
r7917 r8190 3 3 int queuepush (int argc, char **argv) { 4 4 5 int N, Unique, Replace, Key; 5 char *Key; 6 int N, Unique, Replace; 6 7 Queue *queue; 7 8 … … 18 19 } 19 20 20 Key = -1;21 Key = NULL; 21 22 if ((N = get_argument (argc, argv, "-key"))) { 22 23 remove_argument (N, &argc, argv); 23 Key = atoi(argv[N]);24 Key = strcreate (argv[N]); 24 25 remove_argument (N, &argc, argv); 25 26 } … … 42 43 PushQueue (queue, argv[2]); 43 44 } 45 46 if (Key != NULL) free (Key); 44 47 return (TRUE); 45 48 } -
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 1 7 2 8 - todo: -
trunk/Ohana/src/opihi/include/data.h
r7917 r8190 26 26 void PushNamedQueue (char *name, char *line); 27 27 char *PopQueue (Queue *queue); 28 char *PopQueueMatch (Queue *queue, intKey, char *value);29 void PushQueueUnique (Queue *queue, char *line, intKey);30 void PushQueueReplace (Queue *queue, char *line, intKey);28 char *PopQueueMatch (Queue *queue, char *Key, char *value); 29 void PushQueueUnique (Queue *queue, char *line, char *Key); 30 void PushQueueReplace (Queue *queue, char *line, char *Key); 31 31 int InitQueue (Queue *queue); 32 32 int DeleteQueue (Queue *queue); -
trunk/Ohana/src/opihi/lib.data/queues.c
r7917 r8190 141 141 } 142 142 143 char *Choose Key (char *line, int Key) {143 char *ChooseSingleKey (char *line, int Key) { 144 144 145 145 int i; … … 147 147 148 148 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 */ 160 char *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); 153 179 } 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); 157 194 } 158 195 159 196 /* push line onto queue, skipping existing matches (optionally by key) */ 160 void PushQueueUnique (Queue *queue, char *line, intKey) {197 void PushQueueUnique (Queue *queue, char *line, char *Key) { 161 198 162 199 int i, j, N, found; … … 213 250 214 251 /* push line onto queue, replacing matches (optionally by Key) */ 215 void PushQueueReplace (Queue *queue, char *line, intKey) {252 void PushQueueReplace (Queue *queue, char *line, char *Key) { 216 253 217 254 int i, j, N, found; … … 291 328 292 329 /* pop the first entry which for which the key matches */ 293 char *PopQueueMatch (Queue *queue, intKey, char *value) {330 char *PopQueueMatch (Queue *queue, char *Key, char *value) { 294 331 295 332 int i, choice, NLINES_2;
Note:
See TracChangeset
for help on using the changeset viewer.
