Tue, 01 Mar 2005 22:57:57 +0100
Use install-sh.
94
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
1 | /* |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
2 | * libtu/iterable.c |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
3 | * |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
4 | * Copyright (c) Tuomo Valkonen 2005. |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
5 | * |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
6 | * You may distribute and modify this library under the terms of either |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
7 | * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
8 | */ |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
9 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
10 | #include "iterable.h" |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
11 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
12 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
13 | void *iterable_nth(uint n, VoidIterator *iter, void *st) |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
14 | { |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
15 | void *p; |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
16 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
17 | while(1){ |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
18 | p=iter(st); |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
19 | if(p==NULL || n==0) |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
20 | break; |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
21 | n--; |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
22 | } |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
23 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
24 | return p; |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
25 | } |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
26 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
27 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
28 | bool iterable_is_on(void *p, VoidIterator *iter, void *st) |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
29 | { |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
30 | while(1){ |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
31 | void *p2=iter(st); |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
32 | if(p2==NULL) |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
33 | return FALSE; |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
34 | if(p==p2) |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
35 | return TRUE; |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
36 | } |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
37 | } |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
38 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
39 | |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
40 | void *iterable_find(BoolFilter *f, void *fparam, |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
41 | VoidIterator *iter, void *st) |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
42 | { |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
43 | while(1){ |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
44 | void *p=iter(st); |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
45 | if(p==NULL) |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
46 | return NULL; |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
47 | if(f(p, fparam)) |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
48 | return p; |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
49 | } |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
50 | } |
f48ffd2f2224
Added routinesn for generic iterables.
Tuomo Valkonen <tuomov@iki.fi>
parents:
diff
changeset
|
51 |