Merge branch 'master' into cde-next
[oweals/cde.git] / cde / lib / tt / mini_isam / isdlink.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $TOG: isdlink.c /main/4 1999/09/29 15:03:15 mgreess $                                                      */
28
29 /*
30  * Copyright (c) 1988 by Sun Microsystems, Inc.
31  */
32
33 /*
34  * isdlink.c
35  *
36  * Description:
37  *      Double link list functions
38  */
39
40 #include "isam_impl.h"
41
42 /* _isdln_base_insert () - Insert element into list (at the front) -----------*/
43 void _isdln_base_insert (char *base, struct dlink *l,
44                          struct dlink *e)
45 {
46         e->dln_forward = l->dln_forward;
47         l->dln_forward = (char *)e - base;
48         
49         e->dln_backward = (char *)l - base;
50         ((struct dlink *)(base + e->dln_forward))->dln_backward = (char *)e - base;
51 }
52
53 /* _isdln_base_append () - Append element to list (at the end) -------------*/
54 void _isdln_base_append (char *base, struct dlink *l,
55                          struct dlink *e)
56 {
57         e->dln_backward = l->dln_backward;
58         l->dln_backward = (char *)e - base;
59         
60         e->dln_forward = (char *)l - base;
61         ((struct dlink *)(base + e->dln_backward))->dln_forward = (char *)e - base;
62 }
63
64 /* _isdln_base_remove () - Remove element from list -------------------------*/
65 void _isdln_base_remove (char *base, struct dlink *e)
66 {
67         ((struct dlink *)(base + e->dln_backward))->dln_forward = e->dln_forward;
68         ((struct dlink *)(base + e->dln_forward))->dln_backward = e->dln_backward;
69 }
70
71 /* _isdln_base_first () - Return first element of the list -------------------*/
72 struct dlink * _isdln_base_first(char *base, struct dlink *l)
73 {
74         struct dlink *val = (struct dlink *)(base + l->dln_forward);
75
76         if (val == NULL) {
77                 if (NULL == (struct dlink *)(base + l->dln_forward) &&
78                     NULL == (struct dlink *)(base + l->dln_backward))
79                         _isdln_base_makeempty(base, l);
80                 val = l;
81         }
82         return(val);
83 }
84
85 /* _isdln_base_next () - Return next element in the list --------------------*/
86 struct dlink * _isdln_base_next(char *base, struct dlink *l)
87 {
88         return (((struct dlink *)(base + l->dln_forward))); 
89 }
90
91 /* _isdln_base_prev () - Return previous element in the list ----------------*/
92 struct dlink * _isdln_base_prev(char *base, struct dlink *l)
93 {
94         return  (((struct dlink *)(base + l->dln_backward))); 
95 }
96
97 /* _isdln_base_makeempty () - Make head of empty list -----------------------*/
98 void _isdln_base_makeempty(char *base, struct dlink *l)
99 {
100         l->dln_forward = l->dln_backward = (char *)l - base;
101 }
102
103 /* _isdln_base_isempty () - Test if list is empty---------------------------*/
104 int _isdln_base_isempty(char *base, struct dlink *l)
105 {
106         return (l->dln_forward == (char *)l - base &&
107                 l->dln_backward == (char *)l - base);
108 }