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"
61 dlist::dlist(Boolean x) :
62 v_ct(0), v_head(0), v_tail(0), remove_cells_when_done(x)
68 if ( remove_cells_when_done == true )
76 dlist_cell *p = (dlist_cell*)ind;
82 void dlist::append(dlist* tail_list)
84 if ( tail_list == 0 ) return;
87 v_tail -> v_succ = tail_list -> v_head;
89 if ( tail_list -> v_head )
90 tail_list -> v_head -> v_pred = v_tail;
93 v_head = tail_list -> v_head;
95 v_tail = tail_list -> v_tail;
96 v_ct += tail_list -> v_ct;
98 tail_list -> v_head = tail_list -> v_tail = 0;
99 tail_list -> v_ct = 0;
102 void dlist::insert_before(dlist_cell* ref, dlist_cell* x)
105 debug(cerr, "insert before");
107 debug(cerr, int(head));
108 debug(cerr, int(tail));
111 x -> v_pred = x -> v_succ = 0;
114 if ( ref == v_head ) {
115 x -> v_succ = v_head ;
120 ref -> v_pred -> v_succ = x;
121 x -> v_pred = ref -> v_pred;
127 debug(cerr, "insert before done");
128 debug(cerr, int(head));
129 debug(cerr, int(tail));
133 void dlist::insert_after(dlist_cell* ref, dlist_cell* x)
136 x -> v_pred = x -> v_succ = 0;
139 if ( ref == v_tail ) {
145 ref -> v_succ -> v_pred = x;
146 x -> v_succ = ref -> v_succ;
153 void dlist::insert_as_head(dlist_cell* x)
156 x -> v_pred = x -> v_succ = 0;
159 v_head -> v_pred = x;
161 x -> v_succ = v_head;
167 void dlist::insert_as_tail(dlist_cell* x)
170 x -> v_pred = x -> v_succ = 0;
173 v_tail -> v_succ = x;
175 x -> v_pred = v_tail;
181 void dlist::delete_cell(dlist_cell* x)
184 MESSAGE(cerr, "delete_cell()");
186 debug(cerr, int(head));
187 debug(cerr, int(tail));
198 v_head = v_head -> v_succ;
199 v_head -> v_pred = 0;
203 v_tail = v_tail -> v_pred;
204 v_tail -> v_succ = 0;
206 x -> v_pred -> v_succ = x -> v_succ ;
207 x -> v_succ -> v_pred = x -> v_pred ;
212 x -> v_succ = x -> v_pred = 0;
222 return long (v_tail);
225 void dlist::next(long& index)
227 if ( index == long(v_tail) )
230 index = long( ((dlist_cell*)(index)) -> v_succ );