1 | #include <config.h> |
---|---|
2 | #include "lst.h" |
3 | |
4 | int _lstDeleteFlag( HLSTITEM hItem ); |
5 | |
6 | /*********************** |
7 | * lstDelete |
8 | * |
9 | * Do not call unless you want to delete the item |
10 | * from the cursor (if the list is one) **AND** the |
11 | * root list. In other words; this should not be |
12 | * called from functions such as lstClose() which |
13 | * desire to simply free memory used by a specific |
14 | * the list. |
15 | * |
16 | * This is the only function to set bDelete in the root |
17 | * item (as required). |
18 | * |
19 | * lstFreeItem will decrement ref counters and do a real |
20 | * delete when refs are 0. |
21 | ************************/ |
22 | int lstDelete( HLST hLst ) |
23 | { |
24 | HLSTITEM hItem = NULL; |
25 | HLSTITEM hItemRoot = NULL; |
26 | |
27 | if ( !hLst ) |
28 | return LST_ERROR; |
29 | |
30 | hItem = hLst->hCurrent; |
31 | |
32 | if ( !hItem ) |
33 | return LST_ERROR; |
34 | |
35 | /********************* |
36 | * ARE WE A CURSOR LIST |
37 | *********************/ |
38 | if ( hLst->hLstBase ) |
39 | { |
40 | hItemRoot = (HLSTITEM)hItem->pData; |
41 | _lstDeleteFlag( hItemRoot ); |
42 | return _lstFreeItem( hItem ); |
43 | } |
44 | |
45 | /********************* |
46 | * WE ARE root LIST. CHECK FOR REFS BEFORE CALLING FREE |
47 | *********************/ |
48 | _lstDeleteFlag( hItem ); |
49 | if ( hItem->nRefs < 1 ) |
50 | return _lstFreeItem( hItem ); |
51 | |
52 | return LST_SUCCESS; |
53 | } |
54 | |
55 | /*************************** |
56 | * FLAG FOR DELETE (should only be called if root list) |
57 | ***************************/ |
58 | int _lstDeleteFlag( HLSTITEM hItem ) |
59 | { |
60 | HLST hLst; |
61 | |
62 | hLst = (HLST)hItem->hLst; |
63 | |
64 | if ( !hItem->bDelete ) |
65 | hLst->nItems--; |
66 | |
67 | hItem->bDelete = true; |
68 | |
69 | if ( hLst->hCurrent == hItem ) |
70 | _lstAdjustCurrent( hLst ); |
71 | |
72 | return true; |
73 | } |
74 | |
75 | |
76 | |
77 |