1 | #include <config.h> |
---|---|
2 | #include "lst.h" |
3 | |
4 | /************************* |
5 | * lstAppend |
6 | * |
7 | * 1. APPEND TO BASE LIST IF hLst IS A CURSOR |
8 | * 2. APPEND REF TO THIS LIST |
9 | *************************/ |
10 | int lstAppend( HLST hLst, void *pData ) |
11 | { |
12 | HLSTITEM hItem; |
13 | |
14 | if ( !hLst ) |
15 | return LST_ERROR; |
16 | |
17 | /********************** |
18 | * CREATE AN ITEM |
19 | **********************/ |
20 | hItem = (HLSTITEM) malloc( sizeof(LSTITEM) ); |
21 | if ( !hItem ) |
22 | return LST_ERROR; |
23 | |
24 | hItem->bDelete = false; |
25 | hItem->bHide = false; |
26 | hItem->hLst = hLst; |
27 | hItem->nRefs = 0; |
28 | hItem->pData = NULL; |
29 | hItem->pNext = NULL; |
30 | hItem->pPrev = NULL; |
31 | |
32 | if ( hLst->hLstBase ) |
33 | { |
34 | /********************** |
35 | * WE ARE A CURSOR LIST SO... |
36 | * 1. ADD TO BASE LIST |
37 | * 2. ADD TO THIS LIST (ref to base list) |
38 | **********************/ |
39 | lstAppend( hLst->hLstBase, pData ); |
40 | hItem->pData = hLst->hLstBase->hCurrent; |
41 | hLst->hLstBase->hCurrent->nRefs++; |
42 | _lstAppend( hLst, hItem ); |
43 | } |
44 | else |
45 | { |
46 | /********************** |
47 | * WE ARE THE ROOT SO... |
48 | * 1. ADD TO THIS LIST |
49 | **********************/ |
50 | hItem->pData = pData; |
51 | _lstAppend( hLst, hItem ); |
52 | } |
53 | |
54 | return LST_SUCCESS; |
55 | } |
56 | |
57 | |
58 | /************************* |
59 | * SIMPLY CONNECTS THE LINKS/POINTERS AND SETS CURRENT |
60 | *************************/ |
61 | int _lstAppend( HLST hLst, HLSTITEM hItem ) |
62 | { |
63 | |
64 | if ( hLst->hFirst ) |
65 | { |
66 | hItem->pPrev = hLst->hLast; |
67 | hLst->hLast->pNext = hItem; |
68 | hLst->hLast = hItem; |
69 | } |
70 | else |
71 | { |
72 | hItem->pPrev = NULL; |
73 | hLst->hFirst = hItem; |
74 | hLst->hLast = hItem; |
75 | } |
76 | hLst->hCurrent = hItem; |
77 | hLst->nItems++; |
78 | |
79 | return LST_SUCCESS; |
80 | } |
81 | |
82 |