1 /*
2 * Motif
3 *
4 * Copyright (c) 1987-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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27
28 #ifdef REV_INFO
29 #ifndef lint
30 static char rcsid[] = "$XConsortium: Mrmwread.c /main/11 1996/11/13 14:07:06 drk $"
31 #endif
32 #endif
33
34
35 /*
36 *++
37 * FACILITY:
38 *
39 * UIL Resource Manager (URM):
40 *
41 * ABSTRACT:
42 *
43 * This module contains the widget read routines. All these routines
44 * read a widget from a hierarchy or IDB file into a resource context.
45 *
46 *--
47 */
48
49
50 /*
51 *
52 * INCLUDE FILES
53 *
54 */
55
56
57 #include <Mrm/MrmAppl.h>
58 #include <Mrm/Mrm.h>
59 #include "MrmMsgI.h"
60
61
62 /*
63 *
64 * TABLE OF CONTENTS
65 *
66 * UrmHGetWidget Read indexed widget from hierarchy
67 *
68 * UrmGetIndexedWidget Read indexed widget from IDB file
69 *
70 * UrmGetRIDWidget Read RID widget from IDB file
71 *
72 */
73
74
75 /*
76 *++
77 *
78 * PROCEDURE DESCRIPTION:
79 *
80 * UrmHGetWidget searches the database hierarchy for a public
81 * (EXPORTed) widget given its index. It returns the RGM widget record
82 * in a resource context.
83 *
84 * FORMAL PARAMETERS:
85 *
86 * hierarchy_id id of an open URM database hierarchy
87 * index index of the desired widget
88 * context_id widget context in which to return record read in
89 * file_id_return to return IDB file in which widget was found
90 *
91 * IMPLICIT INPUTS:
92 *
93 * IMPLICIT OUTPUTS:
94 *
95 * FUNCTION VALUE:
96 *
97 * MrmSUCCESS operation succeeded
98 * MrmNOT_FOUND widget not found
99 * MrmBAD_HIERARCHY invalid URM file hierarchy
100 * MrmBAD_WIDGET_REC invalid widget record in context
101 * Others see UrmGetIndexedWidget
102 *
103 * SIDE EFFECTS:
104 *
105 *--
106 */
107
108 Cardinal
109 UrmHGetWidget (MrmHierarchy hierarchy_id,
110 String index,
111 URMResourceContextPtr context_id,
112 IDBFile *file_id_return)
113 {
114 /*
115 * Local variables
116 */
117 Cardinal result ; /* function results */
118 RGMWidgetRecordPtr widgetrec ; /* widget record in context */
119
120
121 /*
122 * Get the widget
123 */
124 result = UrmHGetIndexedResource
125 (hierarchy_id, index, URMgWidget, URMtNul, context_id, file_id_return) ;
126 if ( result != MrmSUCCESS ) return result ;
127
128 /*
129 * Validate the widget record in the context
130 */
131 widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
132 if ( UrmWRValid(widgetrec) )
133 return MrmSUCCESS ;
134 else
135 {
136 if ( (*file_id_return)->byte_swapped ) swapbytes(widgetrec->validation);
137 if ( UrmWRValid(widgetrec) )
138 {
139 Urm__SwapRGMWidgetRecord(widgetrec);
140 return MrmSUCCESS ;
141 }
142 }
143
144 return Urm__UT_Error("UrmHGetIndexedWidget", _MrmMMsg_0026,
145 NULL, context_id, MrmBAD_WIDGET_REC) ;
146 }
147
148 /*
149 *++
150 *
151 * PROCEDURE DESCRIPTION:
152 *
153 * UrmGetIndexedWidget searches a single database file for a widget
154 * given its index (i.e. it gets a public widget from a single file).
155 * It returns the RGM widget record.
156 *
157 * FORMAL PARAMETERS:
158 *
159 * file_id id of an open URM database file (IDB file)
160 * index index of the desired widget
161 * context_id widget context in which to return record read in
162 *
163 * IMPLICIT INPUTS:
164 *
165 * IMPLICIT OUTPUTS:
166 *
167 * FUNCTION VALUE:
168 *
169 * MrmSUCCESS operation succeeded
170 * MrmBAD_CONTEXT invalid resource context
171 * Other See UrmIdbGetIndexedResource
172 *
173 * SIDE EFFECTS:
174 *
175 *--
176 */
177
178 Cardinal
UrmGetIndexedWidget(IDBFile file_id,String index,URMResourceContextPtr context_id)179 UrmGetIndexedWidget (IDBFile file_id,
180 String index,
181 URMResourceContextPtr context_id)
182 {
183 /*
184 * Local variables
185 */
186 Cardinal result ; /* function results */
187 RGMWidgetRecordPtr widgetrec ; /* widget record in context */
188
189
190 /*
191 * Validate context, then attempt the read.
192 */
193 if ( ! UrmRCValid(context_id) )
194 return Urm__UT_Error ("UrmGetIndexedWidget", _MrmMMsg_0043,
195 file_id, NULL, MrmBAD_CONTEXT) ;
196
197 result =
198 UrmIdbGetIndexedResource (file_id, index, URMgWidget, URMtNul, context_id) ;
199 if ( result != MrmSUCCESS ) return result ;
200
201 /*
202 * Validate the widget record in the context
203 */
204 widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
205 if ( UrmWRValid(widgetrec) )
206 return MrmSUCCESS ;
207 else
208 {
209 if ( file_id->byte_swapped ) swapbytes(widgetrec->validation);
210 if ( UrmWRValid(widgetrec) )
211 {
212 Urm__SwapRGMWidgetRecord(widgetrec);
213 return MrmSUCCESS ;
214 }
215 }
216
217 return Urm__UT_Error("UrmGetIndexedWidget", _MrmMMsg_0026,
218 NULL, context_id, MrmBAD_WIDGET_REC) ;
219 }
220
221
222 /*
223 *++
224 *
225 * PROCEDURE DESCRIPTION:
226 *
227 * UrmGetRIDWidget retrieves a widget from a single database file
228 * given its resource id as an accessor. It returns the widget record.
229 *
230 * FORMAL PARAMETERS:
231 *
232 * file_id id of an open URM database file (IDB file)
233 * resource_id resource id for widget
234 * context_id widget context in which to return record read in
235 *
236 * IMPLICIT INPUTS:
237 *
238 * IMPLICIT OUTPUTS:
239 *
240 * FUNCTION VALUE:
241 *
242 * MrmSUCCESS operation succeeded
243 * MrmNOT_FOUND widget not found
244 * MrmFAILURE operation failed, further reason not given.
245 *
246 * SIDE EFFECTS:
247 *
248 *--
249 */
250
251 Cardinal
UrmGetRIDWidget(IDBFile file_id,MrmResource_id resource_id,URMResourceContextPtr context_id)252 UrmGetRIDWidget (IDBFile file_id,
253 MrmResource_id resource_id,
254 URMResourceContextPtr context_id)
255 {
256 /*
257 * Local variables
258 */
259 Cardinal result ; /* function results */
260 RGMWidgetRecordPtr widgetrec ; /* widget record in context */
261
262
263 /*
264 * Validate context, then attempt the read.
265 */
266 if ( ! UrmRCValid(context_id) )
267 return Urm__UT_Error ("UrmGetRIDWidget", _MrmMMsg_0043,
268 file_id, NULL, MrmBAD_CONTEXT) ;
269
270 result = UrmIdbGetRIDResource (file_id, resource_id,
271 URMgWidget, URMgNul, context_id) ;
272 if ( result != MrmSUCCESS ) return result ;
273
274 /*
275 * Validate the widget record in the context
276 */
277 widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
278 if ( UrmWRValid(widgetrec) )
279 return MrmSUCCESS ;
280 else
281 {
282 if ( file_id->byte_swapped ) swapbytes(widgetrec->validation);
283 if ( UrmWRValid(widgetrec) )
284 {
285 Urm__SwapRGMWidgetRecord(widgetrec);
286 return MrmSUCCESS ;
287 }
288 }
289 return Urm__UT_Error("UrmGetRIDWidget", _MrmMMsg_0026,
290 NULL, context_id, MrmBAD_WIDGET_REC) ;
291
292 }
293
294