1 | #include <config.h> |
---|---|
2 | #include "lst.h" |
3 | |
4 | HLST lstOpenCursor( HLST hBase, int (*pFilterFunc)( HLST, void * ), void *pExtras ) |
5 | { |
6 | HLST hLst = NULL; |
7 | |
8 | if ( !hBase ) |
9 | return NULL; |
10 | |
11 | /************************* |
12 | * CREATE A NEW LIST |
13 | *************************/ |
14 | hLst = lstOpen(); |
15 | if ( !hLst ) |
16 | return NULL; |
17 | |
18 | hBase->nRefs++; |
19 | |
20 | hLst->pFilter = pFilterFunc; |
21 | hLst->pFree = NULL; /* never free pData in a cursor */ |
22 | hLst->pExtras = pExtras; |
23 | |
24 | /************************* |
25 | * ADD ITEMS FROM hBase (skipping any bDelete items) |
26 | *************************/ |
27 | lstFirst( hBase ); |
28 | if ( pFilterFunc ) |
29 | { |
30 | while ( !lstEOL( hBase ) ) |
31 | { |
32 | if ( pFilterFunc( hLst, lstGet( hBase ) ) ) |
33 | lstAppend( hLst, hBase->hCurrent ); |
34 | |
35 | lstNext( hBase ); |
36 | } |
37 | } |
38 | else |
39 | { |
40 | while ( !lstEOL( hBase ) ) |
41 | { |
42 | lstAppend( hLst, hBase->hCurrent ); |
43 | |
44 | lstNext( hBase ); |
45 | } |
46 | } |
47 | |
48 | /************************* |
49 | * THIS *MUST* BE DONE AFTER THE LIST IS LOADED |
50 | * OTHERWISE lstAppend() WILL APPEND INTO ROOT LIST AND MAKE A REF IN THIS LIST |
51 | *************************/ |
52 | hLst->hLstBase = hBase; |
53 | |
54 | return hLst; |
55 | } |
56 | |
57 |