dthelp: Change to ANSI function definitions
[oweals/cde.git] / cde / programs / dtmail / dtmail / Node.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 /*
24  *+SNOTICE
25  *
26  *      $XConsortium: Node.C /main/4 1996/04/21 19:42:41 drk $
27  *
28  *      RESTRICTED CONFIDENTIAL INFORMATION:
29  *      
30  *      The information in this document is subject to special
31  *      restrictions in a confidential disclosure agreement between
32  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
33  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
34  *      Sun's specific written approval.  This document and all copies
35  *      and derivative works thereof must be returned or destroyed at
36  *      Sun's request.
37  *
38  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
39  *
40  *+ENOTICE
41  */
42
43 #include <stdio.h>
44
45 #include        "Node.h"
46
47 // In the design, we had abstracted out the DOMF related activities
48 // (insertion in lookup table, creation of the objref corresponding to
49 // servant...) into <>Impl classes.
50 // The <>Servant classes derive from the <>Impl classes.
51 // Note how, in the constructor of the NodeServant class, we call the 
52 // constructor of the parent NodeImpl class passing in "this".
53 // The NodeImpl constructor uses "this" to insert into the lookup table...
54
55
56 Node::Node()
57 {
58
59     my_message_handle    = NULL;
60     my_message_header    = NULL;
61
62     homep = DTM_FALSE;
63     deleted_p = DTM_FALSE;
64     my_previous_node = NULL;
65     my_next_node  = NULL;
66 }
67
68 Node::Node(
69     DtMailMessageHandle msg_num,
70     char*     hdr
71 )
72 {
73     my_message_handle    = msg_num;
74     my_message_header    = hdr;
75
76     homep = DTM_FALSE;
77     deleted_p = DTM_FALSE;
78     my_previous_node = NULL;
79     my_next_node  = NULL;
80 }
81
82 Node::~Node() {}
83
84 void 
85 Node::set_homep(
86 )
87 {
88     homep = DTM_TRUE;
89 }
90
91 boolean
92 Node::is_home(
93 )
94 {
95     return(homep);
96 }
97
98 // Starting with the current node "this", traverse nodes until
99 // home node is reached.
100
101 Node*
102 Node::get_home(
103 )
104 {
105     Node* a_node;
106     unsigned char  is_home_p;
107
108
109     a_node = this;
110
111     is_home_p = a_node->is_home();
112
113     if (is_home_p) {
114         return (this);
115     }
116     else {
117         Node* n;
118         
119         n = a_node->next();
120         n->get_home();
121     }
122 }
123
124 void
125 Node::set_message_handle(
126     DtMailMessageHandle a_hndl
127 )
128 {
129     my_message_handle = a_hndl;
130 }
131
132
133 DtMailMessageHandle
134 Node::get_message_handle()
135 {
136     return(my_message_handle);
137 }
138
139 void
140 Node::set_message_header(
141     char* hdr
142 )
143 {
144     my_message_header = hdr;
145 }
146
147 char* 
148 Node::get_message_header()
149 {
150     return(my_message_header);
151 }
152
153 Node* 
154 Node::next(
155 )
156 {
157
158     return(my_next_node);
159
160 }
161
162 // Don't attempt duplicating a nil objref!
163
164 Node* 
165 Node::prev(
166 )
167 {
168
169     return(my_previous_node);
170
171 }
172
173 // Don't attempt duplicating a nil objref!
174
175 void
176 Node::set_previous_node(
177         Node* a_node
178 )
179 {
180     my_previous_node = a_node;
181
182 }
183
184 // Don't attempt duplicating a nil objref!
185
186 void
187 Node::set_next_node(
188         Node* a_node
189 )
190 {
191     my_next_node = a_node;
192 }
193
194 // append anyNode to self
195
196 void 
197 Node::append(
198         Node* anyNode
199 )
200 {
201
202     Node* tmpNext;
203     Node* tmpSelf;
204     Node* inNode;
205
206     if (anyNode == NULL) {
207         printf("Cannot append NIL node!");
208         return;
209     }
210
211     inNode = anyNode;
212
213     tmpSelf = this;
214
215     if (my_next_node)
216       {
217           tmpNext = my_next_node;
218           my_next_node = inNode;
219           inNode->set_previous_node(tmpSelf);
220           inNode->set_next_node(my_next_node);
221           tmpNext->set_previous_node(inNode);
222       }
223     else
224       {
225           my_next_node = inNode;
226           my_previous_node      = inNode;
227           inNode->set_previous_node(tmpSelf);
228           inNode->set_next_node(tmpSelf);
229       }
230 }
231
232 // prepend anyNode to self
233
234 void
235 Node::prepend(
236         Node* anyNode
237 )
238 {
239     
240     Node* tmpPrev;
241     Node* inNode;
242     Node* tmpSelf;
243
244     if (anyNode == NULL) {
245         printf("Cannot prepend NIL node!");
246         return;
247     }
248
249     inNode  = anyNode;
250     tmpSelf = this;
251
252     if (my_previous_node)
253       {
254           tmpPrev = my_previous_node;
255           my_previous_node = inNode;
256           inNode->set_next_node(tmpSelf);
257           inNode->set_previous_node(tmpPrev);
258           tmpPrev->set_next_node(inNode);
259       }
260     else
261       {
262           my_next_node = inNode;
263           my_previous_node = inNode;
264           inNode->set_previous_node(tmpSelf);
265           inNode->set_next_node(tmpSelf);
266       }
267
268 }
269
270 // Good etiquette requires that clients remove() a node
271 // before destroy()-ing it.
272     
273 void 
274 Node::remove(
275 )
276 {
277
278     my_previous_node->set_next_node(my_next_node);
279
280     my_next_node->set_previous_node(my_previous_node);
281
282 }
283
284
285 void
286 Node::set_number(int i)
287 {
288     bogus_number = i;
289
290 }
291
292 int
293 Node::get_number()
294 {
295     return(bogus_number);
296 }
297
298
299
300