2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * $XConsortium: dlist.C /main/5 1996/08/21 15:51:48 drk $
26 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
51 #include "dstr/dlist.h"
54 #include "utility/c_stream.h"
60 dlist::dlist(Boolean x) :
61 v_ct(0), v_head(0), v_tail(0), remove_cells_when_done(x)
67 if ( remove_cells_when_done == true )
75 dlist_cell *p = (dlist_cell*)ind;
81 void dlist::append(dlist* tail_list)
83 if ( tail_list == 0 ) return;
86 v_tail -> v_succ = tail_list -> v_head;
88 if ( tail_list -> v_head )
89 tail_list -> v_head -> v_pred = v_tail;
92 v_head = tail_list -> v_head;
94 v_tail = tail_list -> v_tail;
95 v_ct += tail_list -> v_ct;
97 tail_list -> v_head = tail_list -> v_tail = 0;
98 tail_list -> v_ct = 0;
101 void dlist::insert_before(dlist_cell* ref, dlist_cell* x)
104 debug(cerr, "insert before");
106 debug(cerr, int(head));
107 debug(cerr, int(tail));
110 x -> v_pred = x -> v_succ = 0;
113 if ( ref == v_head ) {
114 x -> v_succ = v_head ;
119 ref -> v_pred -> v_succ = x;
120 x -> v_pred = ref -> v_pred;
126 debug(cerr, "insert before done");
127 debug(cerr, int(head));
128 debug(cerr, int(tail));
132 void dlist::insert_after(dlist_cell* ref, dlist_cell* x)
135 x -> v_pred = x -> v_succ = 0;
138 if ( ref == v_tail ) {
144 ref -> v_succ -> v_pred = x;
145 x -> v_succ = ref -> v_succ;
152 void dlist::insert_as_head(dlist_cell* x)
155 x -> v_pred = x -> v_succ = 0;
158 v_head -> v_pred = x;
160 x -> v_succ = v_head;
166 void dlist::insert_as_tail(dlist_cell* x)
169 x -> v_pred = x -> v_succ = 0;
172 v_tail -> v_succ = x;
174 x -> v_pred = v_tail;
180 void dlist::delete_cell(dlist_cell* x)
183 MESSAGE(cerr, "delete_cell()");
185 debug(cerr, int(head));
186 debug(cerr, int(tail));
197 v_head = v_head -> v_succ;
198 v_head -> v_pred = 0;
202 v_tail = v_tail -> v_pred;
203 v_tail -> v_succ = 0;
205 x -> v_pred -> v_succ = x -> v_succ ;
206 x -> v_succ -> v_pred = x -> v_pred ;
211 x -> v_succ = x -> v_pred = 0;
221 return long (v_tail);
224 void dlist::next(long& index)
226 if ( index == long(v_tail) )
229 index = long( ((dlist_cell*)(index)) -> v_succ );