1961df886506819259ee1f495afd504f6b6cf6b8
[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 #ifndef lint
29         static char sccsid[] = "@(#)isdlink.c 1.4 89/09/01 Copyr 1988 Sun Micro";
30 #endif
31
32 /*
33  * Copyright (c) 1988 by Sun Microsystems, Inc.
34  */
35
36 /*
37  * isdlink.c
38  *
39  * Description:
40  *      Double link list functions
41  */
42
43 #include "isam_impl.h"
44
45 /* _isdln_base_insert () - Insert element into list (at the front) -----------*/
46 void _isdln_base_insert (register char *base, register struct dlink *l,
47                          register struct dlink *e)
48 {
49         e->dln_forward = l->dln_forward;
50         l->dln_forward = (char *)e - base;
51         
52         e->dln_backward = (char *)l - base;
53         ((struct dlink *)(base + e->dln_forward))->dln_backward = (char *)e - base;
54 }
55
56 /* _isdln_base_append () - Append element to list (at the end) -------------*/
57 void _isdln_base_append (register char *base, register struct dlink *l,
58                          register struct dlink *e)
59 {
60         e->dln_backward = l->dln_backward;
61         l->dln_backward = (char *)e - base;
62         
63         e->dln_forward = (char *)l - base;
64         ((struct dlink *)(base + e->dln_backward))->dln_forward = (char *)e - base;
65 }
66
67 /* _isdln_base_remove () - Remove element from list -------------------------*/
68 void _isdln_base_remove (register char *base, register struct dlink *e)
69 {
70         ((struct dlink *)(base + e->dln_backward))->dln_forward = e->dln_forward;
71         ((struct dlink *)(base + e->dln_forward))->dln_backward = e->dln_backward;
72 }
73
74 /* _isdln_base_first () - Return first element of the list -------------------*/
75 struct dlink * _isdln_base_first(register char *base, register struct dlink *l)
76 {
77         struct dlink *val = (struct dlink *)(base + l->dln_forward);
78
79         if (val == NULL) {
80                 if (NULL == (struct dlink *)(base + l->dln_forward) &&
81                     NULL == (struct dlink *)(base + l->dln_backward))
82                         _isdln_base_makeempty(base, l);
83                 val = l;
84         }
85         return(val);
86 }
87
88 /* _isdln_base_next () - Return next element in the list --------------------*/
89 struct dlink * _isdln_base_next(register char *base, register struct dlink *l)
90 {
91         return (((struct dlink *)(base + l->dln_forward))); 
92 }
93
94 /* _isdln_base_prev () - Return previous element in the list ----------------*/
95 struct dlink * _isdln_base_prev(register char *base, register struct dlink *l)
96 {
97         return  (((struct dlink *)(base + l->dln_backward))); 
98 }
99
100 /* _isdln_base_makeempty () - Make head of empty list -----------------------*/
101 void _isdln_base_makeempty(register char *base, register struct dlink *l)
102 {
103         l->dln_forward = l->dln_backward = (char *)l - base;
104 }
105
106 /* _isdln_base_isempty () - Test if list is empty---------------------------*/
107 int _isdln_base_isempty(register char *base, register struct dlink *l)
108 {
109         return (l->dln_forward == (char *)l - base &&
110                 l->dln_backward == (char *)l - base);
111 }