Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / libABobj / obj_names_list.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 librararies 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 /*
25  *      $XConsortium: obj_names_list.c /main/3 1995/11/06 18:37:04 rswiston $
26  *
27  *      @(#)obj_names_list.c    1.1 26 May 1994 cde_app_builder/src/libABobj
28  *
29  *      RESTRICTED CONFIDENTIAL INFORMATION:
30  *      
31  *      The information in this document is subject to special
32  *      restrictions in a confidential disclosure agreement between
33  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
35  *      Sun's specific written approval.  This document and all copies
36  *      and derivative works thereof must be returned or destroyed at
37  *      Sun's request.
38  *
39  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40  *
41  */
42
43
44 /*
45  *  template.c - template c file.
46  */
47
48 #include "objP.h"
49 #include <ab_private/trav.h>
50 #include "obj_names_listP.h"
51
52 /*************************************************************************
53 **                                                                      **
54 **       Constants (#define and const)                                  **
55 **                                                                      **
56 **************************************************************************/
57
58 /*************************************************************************
59 **                                                                      **
60 **       Private Functions (C declarations and macros)                  **
61 **                                                                      **
62 **************************************************************************/
63
64 /*************************************************************************
65 **                                                                      **
66 **       Function Definitions                                           **
67 **                                                                      **
68 **************************************************************************/
69
70 ABObj           
71 objP_get_names_scope_obj(ABObj obj)
72 {
73     ABObj       namesObj = obj_get_module(obj);
74     
75     if (obj_is_project(obj))
76     {
77         return NULL;
78     }
79     else if ((namesObj == NULL) || obj_is_module(obj))
80     {
81         /* module names go in project */
82         namesObj = obj_get_project(obj);
83     }
84     return namesObj;
85 }
86
87
88 StringList
89 objP_get_names_scope(ABObj obj)
90 {
91     ABObj       nameScopeObj = objP_get_names_scope_obj(obj);
92     if (nameScopeObj != NULL)
93     {
94         return objP_get_names_list(nameScopeObj);
95     }
96     return NULL;
97 }
98
99
100 ABObj
101 objP_get_names_scope_obj_for_children(ABObj parent)
102 {
103     ABObj       scopeObj = obj_get_module(parent);
104     if (scopeObj == NULL)
105     {
106         scopeObj = obj_get_project(parent);
107     }
108     return scopeObj;
109 }
110
111
112 StringList
113 objP_get_names_scope_for_children(ABObj parent)
114 {
115     ABObj       scopeObj = objP_get_names_scope_obj_for_children(parent);
116     if (scopeObj != NULL)
117     {
118         return objP_get_names_list(scopeObj);
119     }
120     return NULL;
121 }
122
123
124 StringList      
125 objP_get_names_list(ABObj obj)
126 {
127     switch (obj->type)
128     {
129         case AB_TYPE_MODULE:
130             return obj->info.module.obj_names_list;
131         case AB_TYPE_PROJECT:
132             return obj->info.project.obj_names_list;
133     }
134
135     return NULL;
136 }
137
138
139 int
140 objP_add_to_names_list(ABObj obj)
141 {
142     StringList  names = NULL;
143     
144     names = objP_get_names_scope(obj);
145     if (names != NULL)
146     {
147         strlist_add_istr(names, obj->name, obj);
148     }
149     return 0;
150 }
151
152
153 int
154 objP_remove_from_names_list(ABObj obj)
155 {
156     StringList  names = objP_get_names_scope(obj);
157     if (names != NULL)
158     {
159         strlist_remove_istr(names, obj->name);
160     }
161     return 0;
162 }
163
164
165 int
166 objP_tree_add_to_names_list(ABObj tree)
167 {
168     ABObj               scopeObj = objP_get_names_scope_obj(tree);
169     StringList          names = NULL;
170     AB_TRAVERSAL        trav;
171     ABObj               obj = NULL;
172
173     if (scopeObj != NULL)
174     {
175         names = objP_get_names_list(scopeObj);
176     }
177     if (names == NULL)
178     {
179         return NULL;
180     }
181
182     for (trav_open(&trav, tree, AB_TRAV_ALL);
183         (obj = trav_next(&trav)) != NULL; )
184     {
185         if (objP_get_names_scope_obj(obj) == scopeObj)
186         {
187             strlist_add_istr(names, obj->name, obj);
188         }
189     }
190     trav_close(&trav);
191
192     return 0;
193 }
194
195
196 int
197 objP_tree_remove_from_names_list(ABObj tree)
198 {
199     ABObj               scopeObj = objP_get_names_scope_obj(tree);
200     StringList          names = NULL;
201     AB_TRAVERSAL        trav;
202     ABObj               obj = NULL;
203
204     if (scopeObj != NULL)
205     {
206         names = objP_get_names_list(scopeObj);
207     }
208     if (names == NULL)
209     {
210         return NULL;
211     }
212
213     for (trav_open(&trav, tree, AB_TRAV_ALL);
214         (obj = trav_next(&trav)) != NULL; )
215     {
216         if (objP_get_names_scope_obj(obj) == scopeObj)
217         {
218             strlist_remove_istr(names, obj->name);
219         }
220     }
221     trav_close(&trav);
222
223     return 0;
224 }
225
226