(find): Fix copy-n-paste error.
(iter): Return error code. (main): Create iterators on demand. New command `close'.
Showing
1 changed file
with
25 additions
and
21 deletions
... | @@ -183,7 +183,7 @@ repl (mu_list_t list, int argc, char **argv) | ... | @@ -183,7 +183,7 @@ repl (mu_list_t list, int argc, char **argv) |
183 | 183 | ||
184 | #define NITR 4 | 184 | #define NITR 4 |
185 | 185 | ||
186 | void | 186 | int |
187 | iter (int *pnum, int argc, char **argv) | 187 | iter (int *pnum, int argc, char **argv) |
188 | { | 188 | { |
189 | int n; | 189 | int n; |
... | @@ -191,16 +191,17 @@ iter (int *pnum, int argc, char **argv) | ... | @@ -191,16 +191,17 @@ iter (int *pnum, int argc, char **argv) |
191 | if (argc != 2) | 191 | if (argc != 2) |
192 | { | 192 | { |
193 | fprintf (stderr, "iter num?\n"); | 193 | fprintf (stderr, "iter num?\n"); |
194 | return; | 194 | return 1; |
195 | } | 195 | } |
196 | 196 | ||
197 | n = strtoul (argv[1], NULL, 0); | 197 | n = strtoul (argv[1], NULL, 0); |
198 | if (n < 0 || n >= NITR) | 198 | if (n < 0 || n >= NITR) |
199 | { | 199 | { |
200 | fprintf (stderr, "iter [0-3]?\n"); | 200 | fprintf (stderr, "iter [0-3]?\n"); |
201 | return; | 201 | return 1; |
202 | } | 202 | } |
203 | *pnum = n; | 203 | *pnum = n; |
204 | return 0; | ||
204 | } | 205 | } |
205 | 206 | ||
206 | void | 207 | void |
... | @@ -225,15 +226,6 @@ find (mu_iterator_t itr, char *arg) | ... | @@ -225,15 +226,6 @@ find (mu_iterator_t itr, char *arg) |
225 | } | 226 | } |
226 | 227 | ||
227 | fprintf (stderr, "%s not in list\n", arg); | 228 | fprintf (stderr, "%s not in list\n", arg); |
228 | |||
229 | for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) | ||
230 | { | ||
231 | char *item; | ||
232 | |||
233 | mu_iterator_current (itr, (void**)&item); | ||
234 | if (strcmp (text, item) == 0) | ||
235 | return; | ||
236 | } | ||
237 | } | 229 | } |
238 | 230 | ||
239 | void | 231 | void |
... | @@ -261,14 +253,6 @@ shell (mu_list_t list) | ... | @@ -261,14 +253,6 @@ shell (mu_list_t list) |
261 | mu_iterator_t itr[NITR]; | 253 | mu_iterator_t itr[NITR]; |
262 | int rc; | 254 | int rc; |
263 | 255 | ||
264 | for (num = 0; num < NITR; num++) | ||
265 | { | ||
266 | rc = mu_list_get_iterator (list, &itr[num]); | ||
267 | if (rc) | ||
268 | lperror ("mu_list_get_iterator", rc); | ||
269 | mu_iterator_first (itr[num]); | ||
270 | } | ||
271 | |||
272 | num = 0; | 256 | num = 0; |
273 | while (1) | 257 | while (1) |
274 | { | 258 | { |
... | @@ -310,7 +294,27 @@ shell (mu_list_t list) | ... | @@ -310,7 +294,27 @@ shell (mu_list_t list) |
310 | else if (strcmp (argv[0], "quit") == 0) | 294 | else if (strcmp (argv[0], "quit") == 0) |
311 | return; | 295 | return; |
312 | else if (strcmp (argv[0], "iter") == 0) | 296 | else if (strcmp (argv[0], "iter") == 0) |
313 | iter (&num, argc, argv); | 297 | { |
298 | int n; | ||
299 | if (iter (&n, argc, argv) == 0 && !itr[n]) | ||
300 | { | ||
301 | rc = mu_list_get_iterator (list, &itr[n]); | ||
302 | if (rc) | ||
303 | lperror ("mu_list_get_iterator", rc); | ||
304 | mu_iterator_first (itr[n]); | ||
305 | } | ||
306 | num = n; | ||
307 | } | ||
308 | else if (strcmp (argv[0], "close") == 0) | ||
309 | { | ||
310 | int n; | ||
311 | if (iter (&n, argc, argv) == 0) | ||
312 | { | ||
313 | mu_iterator_destroy (&itr[n]); | ||
314 | if (n == num && ++num == NITR) | ||
315 | num = 0; | ||
316 | } | ||
317 | } | ||
314 | else if (strcmp (argv[0], "find") == 0) | 318 | else if (strcmp (argv[0], "find") == 0) |
315 | find (itr[num], argv[1]); | 319 | find (itr[num], argv[1]); |
316 | else if (strcmp (argv[0], "help") == 0) | 320 | else if (strcmp (argv[0], "help") == 0) | ... | ... |
-
Please register or sign in to post a comment