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: Mrmwcrwr.c /main/14 1996/11/13 14:06:42 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 all the CWR routines (Create Widget Record)
44  *	which create the contents of a widget record in a resource context.
45  *
46  *--
47  */
48 
49 
50 /*
51  *
52  *  INCLUDE FILES
53  *
54  */
55 
56 #include <Mrm/MrmAppl.h>
57 #include <Mrm/Mrm.h>
58 #include "MrmosI.h"
59 #include "MrmMsgI.h"
60 
61 /*
62  *
63  *  TABLE OF CONTENTS
64  *
65  *	UrmCWRInit			Initialize CWR
66  *
67  *	UrmCWRSetClass			Set class name/code/variety
68  *
69  *	UrmCWRInitArglist		Initialize arglist
70  *
71  *	UrmCWRSetCompressedArgTag	Set compressed tag in arglist
72  *
73  *	UrmCWRSetUncompressedArgTag	Set uncompressed tag in arglist
74  *
75  *	UrmCWRSetArgValue		Set arg value (immediate)
76  *
77  *	UrmCWRSetArgResourceRef		Set arg value (resource reference)
78  *
79  *	UrmCWRSetArgChar8Vec		Set arg value to vector of strings
80  *
81  *	UrmCWRSetArgCStringVec		Set arg value to compound string vector
82  *
83  *	UrmCWRSetArgCallback		Set arg to be callback list
84  *
85  *	UrmCWRSetCallbackItem		Set callback item to immediate value
86  *
87  *	UrmCWRSetCallbackItemRes	Set callback item to resource
88  *
89  *	UrmCWRSetExtraArgs		Set extra args count
90  *
91  *	UrmCWRInitChildren		Initialize children list
92  *
93  *	UrmCWRSetChild			Set child in list
94  *
95  *	UrmCWRSetComment		Set widget comment
96  *
97  *	UrmCWRSetCreationCallback	Set widget creation callback
98  *
99  *	UrmCWR__AppendString		Append a string to the record
100  *
101  *	UrmCWR__GuaranteeSpace		Guarantee enough space in the record
102  *
103  *	UrmCWR__AppendResource		Append a resource descriptor
104  *
105  */
106 
107 
108 /*
109  *++
110  *
111  *  PROCEDURE DESCRIPTION:
112  *
113  *	UrmCWRInit initializes a context for creating a new widget record.
114  *	It initializes a widget record in the context (reusing the already
115  *	allocate buffer if possible). It stores the widget name, and correctly
116  *	initializes the size field of the RGMWidgetRecord struct. This is used
117  *	and maintained by all UrmCWR... routines to locate the next
118  *	available location in the record. The access and locking attributes
119  *	of the record are also set.
120  *
121  *  FORMAL PARAMETERS:
122  *
123  *	context_id	resource context to initialize for the widget (must
124  *			be already allocated with UrmGetResourceContext
125  *	name		name of widget
126  *	access		URMaPublic or URMaPrivate
127  *	lock		TRUE if widget is to be write-protected
128  *
129  *  IMPLICIT INPUTS:
130  *
131  *  IMPLICIT OUTPUTS:
132  *
133  *  FUNCTION VALUE:
134  *
135  *	MrmSUCCESS	operation succeeded
136  *	MrmBAD_CONTEXT	resource context invalid
137  *
138  *  SIDE EFFECTS:
139  *
140  *--
141  */
142 
143 Cardinal
144 UrmCWRInit (URMResourceContextPtr	context_id,
145 	    String			name,
146 	    MrmCode			access,
147 	    MrmCode			lock)
148 {
149 
150   /*
151    *  Local variables
152    */
153   Cardinal		result ;	/* function results */
154   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
155   MrmOffset		offset ;	/* offset for name */
156 
157   /*
158    * Validate record
159    */
160   if ( ! UrmRCValid(context_id) )
161     return Urm__UT_Error ("UrmCWRInit", _MrmMMsg_0043,
162 			  NULL, context_id, MrmBAD_CONTEXT) ;
163 
164   /*
165    * Set validation code, and set record size to size of header
166    */
167   if ( UrmRCSize(context_id) <= _FULLWORD(RGMWidgetRecordHdrSize) )
168     {
169       result = UrmResizeResourceContext (context_id,
170 					 _FULLWORD(RGMWidgetRecordHdrSize)) ;
171       if ( result != MrmSUCCESS ) return result ;
172     }
173   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
174   widgetrec->validation = URMWidgetRecordValid ;
175   widgetrec->size = _FULLWORD (RGMWidgetRecordHdrSize) ;
176   widgetrec->access = access ;
177   widgetrec->lock = lock ;
178   UrmRCSetSize (context_id, widgetrec->size) ;
179 
180   /*
181    * Move in the name
182    */
183   result = UrmCWR__AppendString (context_id, name, &offset) ;
184   if ( result != MrmSUCCESS ) return result ;
185   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
186   widgetrec->name_offs = offset ;
187 
188   /*
189    * Null out all other fields and offsets
190    */
191   widgetrec->type = 0 ;
192   widgetrec->class_offs = 0 ;
193   widgetrec->arglist_offs = 0 ;
194   widgetrec->children_offs = 0 ;
195   widgetrec->comment_offs = 0 ;
196   widgetrec->creation_offs = 0 ;
197   widgetrec->variety = 0 ;
198   widgetrec->annex = 0 ;
199 
200   /*
201    * Successfully initialized
202    */
203   return MrmSUCCESS ;
204 
205 }
206 
207 
208 
209 /*
210  *++
211  *
212  *  PROCEDURE DESCRIPTION:
213  *
214  *	UrmSetClass appends the class specification to the widget record.
215  *
216  *  FORMAL PARAMETERS:
217  *
218  *	context_id	resource context containing widget record
219  *	type		Class type, from URMwc...
220  *	class		string identifying class if not a toolkit/SDT widget.
221  *			This string is stored only if type == URMwcUnknown
222  *
223  *  IMPLICIT INPUTS:
224  *
225  *  IMPLICIT OUTPUTS:
226  *
227  *  FUNCTION VALUE:
228  *
229  *	MrmSUCCESS		operation succeeded
230  *	MrmBAD_CONTEXT		context not valid
231  *	MrmBAD_WIDGET_REC	widget record not valid
232  *	MrmBAD_CLASS_TYPE	unknown class type
233  *	MrmNO_CLASS_NAME	empty class name for user (URMwcUnknown) class
234  *
235  *  SIDE EFFECTS:
236  *
237  *--
238  */
239 
240 Cardinal
UrmCWRSetClass(URMResourceContextPtr context_id,MrmCode type,String class,unsigned long variety)241 UrmCWRSetClass (URMResourceContextPtr	context_id,
242 		MrmCode			type,
243 		String			class,
244 		unsigned long		variety)
245 {
246   /*
247    *  Local variables
248    */
249   Cardinal		result ;	/* function results */
250   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
251   MrmOffset		offset ;	/* class name offset */
252 
253 
254   /*
255    * Validate record
256    */
257   UrmCWR__ValidateContext (context_id, "UrmCWRSetClass") ;
258 
259   /*
260    * Validate the class code. If unknown, must have a non-null class name.
261    * Else needs only the code.
262    */
263   if ( type == UilMrmUnknownCode )
264     {
265       if ( strlen(class) <= 0 )
266 	return Urm__UT_Error ("UrmCWRSetClass", _MrmMMsg_0090,
267 			      NULL, context_id, MrmNO_CLASS_NAME) ;
268       result = UrmCWR__AppendString (context_id, class, &offset) ;
269       if ( result != MrmSUCCESS ) return result ;
270       widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
271       widgetrec->type = URMwcUnknown ;
272       widgetrec->class_offs = offset ;
273       widgetrec->variety = variety;
274       return MrmSUCCESS ;
275     }
276   else
277     {
278       if ( type < UilMrmMinValidCode )
279 	return Urm__UT_Error ("UrmCWRSetClass", _MrmMMsg_0091,
280 			      NULL, context_id, MrmBAD_CLASS_TYPE) ;
281       widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
282       widgetrec->type = type ;
283       widgetrec->class_offs = 0 ;
284       widgetrec->variety = variety;
285       return MrmSUCCESS ;
286     }
287 
288 }
289 
290 
291 
292 /*
293  *++
294  *
295  *  PROCEDURE DESCRIPTION:
296  *
297  *	UrmCWRInitArglist appends an empty RGMArgListDesc struct to the
298  *	record. The arglist contains narg RGMArgument descriptors in a vector
299  *	following the arglist header. These are then filled in by
300  *	UrmCWRSet*ArgTag, and UrmCWRSet*ArgValue and its analogs.
301  *
302  *  FORMAL PARAMETERS:
303  *
304  *	context_id	resource context containing widget record
305  *	nargs		number of arguments in arglist
306  *
307  *  IMPLICIT INPUTS:
308  *
309  *  IMPLICIT OUTPUTS:
310  *
311  *  FUNCTION VALUE:
312  *
313  *	MrmSUCCESS		operation succeeded
314  *	MrmBAD_CONTEXT		context not valid
315  *	MrmBAD_WIDGET_REC	widget record not valid
316  *	MrmTOO_MANY		number of arguments exceeds internal limit
317  *
318  *  SIDE EFFECTS:
319  *
320  *--
321  */
322 
323 Cardinal
UrmCWRInitArglist(URMResourceContextPtr context_id,Cardinal nargs)324 UrmCWRInitArglist (URMResourceContextPtr	context_id,
325 		   Cardinal			nargs)
326 {
327   /*
328    *  Local variables
329    */
330   Cardinal		result ;	/* function results */
331   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
332   MrmSize			descsiz ;	/* descriptor size */
333   MrmOffset		offset ;	/* arglist descriptor offset */
334   RGMArgListDescPtr	argdesc ;	/* pointer to arglist in record */
335   int			ndx ;		/* loop index */
336 
337   /*
338    * Validate record
339    */
340   UrmCWR__ValidateContext (context_id, "UrmCWRInitArglist") ;
341 
342   /*
343    * Error check that the number of arguments is reasonable
344    */
345   if ( nargs > RGMListSizeMax )
346     return Urm__UT_Error ("UrmCWRInitArgList", _MrmMMsg_0092,
347 			  NULL, context_id, MrmTOO_MANY) ;
348 
349   /*
350    * compute the size required for the descriptor and the argument list,
351    * and acquire the memory in the record. Note their is one argument
352    * preallocated in the descriptor.
353    */
354   descsiz = sizeof(RGMArgListDesc) + (nargs-1)*sizeof(RGMArgument) ;
355   result = UrmCWR__GuaranteeSpace (context_id, descsiz, &offset,
356 				   (char **)&argdesc) ;
357   if ( result != MrmSUCCESS ) return result ;
358   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
359   widgetrec->arglist_offs = offset ;
360 
361   /*
362    * initialize the descriptor and all the arguments
363    */
364   argdesc->count = nargs ;
365   argdesc->extra = 0 ;
366   for ( ndx=0 ; ndx<nargs ; ndx++ )
367     {
368       argdesc->args[ndx].tag_code = 0 ;
369       argdesc->args[ndx].stg_or_relcode.tag_offs = 0 ;
370       argdesc->args[ndx].arg_val.datum.ival = 0L ;
371     }
372 
373   /*
374    * successfully added
375    */
376   return MrmSUCCESS ;
377 
378 }
379 
380 
381 
382 /*
383  *++
384  *
385  *  PROCEDURE DESCRIPTION:
386  *
387  *	UrmCWRSetCompressedArgTag sets the tag of the specified argument
388  *	in the arglist. UrmCWRSetCompressedTag is provided for callers who
389  *	already know the compressed code for the tag.
390  *
391  *  FORMAL PARAMETERS:
392  *
393  *	context_id	resource context containing widget record
394  *	arg_ndx		the 0-based index of the argument in the arglist
395  *	tag		code specifying tag for argument from a compression
396  *			code set
397  *	related_tag	code for a related argument from the same compression
398  *			code set
399  *
400  *  IMPLICIT INPUTS:
401  *
402  *  IMPLICIT OUTPUTS:
403  *
404  *  FUNCTION VALUE:
405  *
406  *	MrmSUCCESS		operation succeeded
407  *	MrmBAD_CONTEXT		resource context invalid
408  *	MrmBAD_WIDGET_REC	widget record not valid
409  *	MrmNULL_DESC		arglist descriptor is null
410  *	MrmOUT_OF_BOUNDS	arg_ndx out of bounds
411  *	MrmBAD_COMPRESS		invalid compressed string code
412  *
413  *  SIDE EFFECTS:
414  *
415  *--
416  */
417 
418 Cardinal
UrmCWRSetCompressedArgTag(URMResourceContextPtr context_id,Cardinal arg_ndx,MrmCode tag,MrmCode related_tag)419 UrmCWRSetCompressedArgTag (URMResourceContextPtr	context_id,
420 			   Cardinal			arg_ndx,
421 			   MrmCode			tag,
422 			   MrmCode			related_tag)
423 {
424   /*
425    *  Local variables
426    */
427   RGMArgListDescPtr	argdesc ;	/* arglist desc in record */
428   RGMArgumentPtr	argptr ;	/* argument being set */
429 
430 
431   /*
432    * Validate record, arglist descriptor, and argument number
433    */
434   UrmCWR__ValidateContext (context_id, "UrmCWRSetCompressedArgTag") ;
435   UrmCWR__BindArgPtrs
436     (context_id, "UrmCWRSetCompressedArgTag", arg_ndx, &argdesc, &argptr) ;
437 
438   /*
439    * Validate the compressed code and set the argument.
440    */
441   if ( tag < UilMrmMinValidCode )
442     return Urm__UT_Error ("UrmCWRSetCompressedArgTag", _MrmMMsg_0093,
443 			  NULL, context_id, MrmBAD_COMPRESS) ;
444 
445   argptr->tag_code = tag ;
446   argptr->stg_or_relcode.related_code = related_tag;
447 
448   /*
449    * successfully added
450    */
451   return MrmSUCCESS ;
452 
453 }
454 
455 
456 
457 /*
458  *++
459  *
460  *  PROCEDURE DESCRIPTION:
461  *
462  *	UrmCWRSetUncompressedArgTag sets the tag of the specified argument
463  *	in thearglist.
464  *
465  *  FORMAL PARAMETERS:
466  *
467  *	context_id	resource context containing widget record
468  *	arg_ndx		the 0-based index of the argument in the arglist
469  *	tag		string nameing the argument
470  *
471  *  IMPLICIT INPUTS:
472  *
473  *  IMPLICIT OUTPUTS:
474  *
475  *  FUNCTION VALUE:
476  *
477  *	MrmSUCCESS		operation succeeded
478  *	MrmBAD_CONTEXT		resource context invalid
479  *	MrmBAD_WIDGET_REC	widget record not valid
480  *	MrmNULL_DESC		arglist descriptor is null
481  *	MrmOUT_OF_BOUNDS	arg_ndx out of bounds
482  *
483  *  SIDE EFFECTS:
484  *
485  *--
486  */
487 
488 Cardinal
UrmCWRSetUncompressedArgTag(URMResourceContextPtr context_id,Cardinal arg_ndx,String tag)489 UrmCWRSetUncompressedArgTag (URMResourceContextPtr	context_id ,
490 			     Cardinal			arg_ndx ,
491 			     String			tag )
492 {
493   /*
494    *  Local variables
495    */
496   Cardinal		result ;	/* function results */
497   RGMArgListDescPtr	argdesc ;	/* arglist desc in record */
498   RGMArgumentPtr	argptr ;	/* argument being set */
499   MrmOffset		offset ;	/* tag string offset */
500 
501 
502   /*
503    * Validate record, arglist descriptor, and argument number
504    */
505   UrmCWR__ValidateContext (context_id, "UrmCWRSetUncompressedArgTag") ;
506   UrmCWR__BindArgPtrs
507     (context_id, "UrmCWRSetUncompressedArgTag", arg_ndx, &argdesc, &argptr) ;
508 
509   /*
510    * Append the tag string to the record and set the argument
511    */
512   result = UrmCWR__AppendString (context_id, tag, &offset) ;
513   if ( result != MrmSUCCESS ) return result ;
514 
515   UrmCWR__BindArgPtrs
516     (context_id, "UrmCWRSetUncompressedArgTag", arg_ndx, &argdesc, &argptr) ;
517 
518   argptr->tag_code = UilMrmUnknownCode ;
519   argptr->stg_or_relcode.tag_offs = offset ;
520 
521   /*
522    * successfully added
523    */
524   return MrmSUCCESS ;
525 
526 }
527 
528 
529 
530 /*
531  *++
532  *
533  *  PROCEDURE DESCRIPTION:
534  *
535  *	UrmCWRSetArgValue is used to supply the value for an argument for
536  *	all representation types listed below. For others, see below. The usage
537  *	of the arg_val parameter depends on the value of the type parameter, as
538  *	follows; arg_val is CAST in order to access the caller's value for the
539  *	argument:
540  *
541  *
542  *	MrmRtypeInteger (value):	arg_val is CAST to an integer
543  *
544  *	MrmRtypeBoolean (value):	arg_val is CAST to a boolean value
545  *
546  *	MrmRtypeSingleFloat (value):	arg_val is CAST to a float
547  *
548  *	MrmRtypeChar8 (reference):	arg_val is CAST to a pointer to a
549  *	MrmRtypeAddrName (reference):	string
550  *	MrmRtypeTransTable (reference):
551  *	MrmRtypeClassRecName (reference):
552  *	MrmRtypeKeysym(reference):
553  *
554  *	MrmRtypeCString (reference):	arg_val is CAST to a pointer to a
555  *					compound string
556  *
557  *	MrmRtypeFloat (reference):	arg_val is CAST to a pointer to a
558  *					double constant
559  *
560  *	MrmRtypeNull			No value, enter null.
561  *
562  *	MrmRtypeColorTable		Allocate and copy the color table
563  *
564  *	MrmRtypeIconImage		Allocate and copy the icon. Currently,
565  *					the color table must be allocated
566  *					with the icon imate.
567  *
568  *  FORMAL PARAMETERS:
569  *
570  *	context_id	resource context containing widget record
571  *	arg_ndx		the 0-based index of the argument in the arglist
572  *	type		the representation type for the value, from RGMrType...
573  *	arg_val		a longword which will be CAST and used as required to
574  *			access the value to be stored (copied) into the widget
575  *			record.
576  *
577  *  IMPLICIT INPUTS:
578  *
579  *  IMPLICIT OUTPUTS:
580  *
581  *  FUNCTION VALUE:
582  *
583  *	MrmSUCCESS		operation succeeded
584  *	MrmBAD_CONTEXT		resource context invalid
585  *	MrmBAD_WIDGET_REC	widget record not valid
586  *	MrmNULL_DESC		arglist descriptor is null
587  *	MrmOUT_OF_BOUNDS	arg_ndx out of bounds
588  *	MrmBAD_ARG_TYPE		unknown or unhandled representation type
589  *
590  *  SIDE EFFECTS:
591  *
592  *--
593  */
594 
595 Cardinal
UrmCWRSetArgValue(URMResourceContextPtr context_id,Cardinal arg_ndx,MrmCode type,unsigned long arg_val)596 UrmCWRSetArgValue (URMResourceContextPtr	context_id,
597 		   Cardinal			arg_ndx,
598 		   MrmCode			type,
599 		   unsigned long		arg_val)
600 {
601   /*
602    *  Local variables
603    */
604   Cardinal		result ;	/* function results */
605   RGMArgListDescPtr	argdesc ;	/* arglist desc in record */
606   RGMArgumentPtr	argptr ;	/* argument being set */
607   MrmOffset		offset, dumoff; /* non-immediate value offset */
608   double		*dblptr ;	/* pointer to double constant */
609   char			*dumaddr;	/* dummy address for GuaranteeSpace */
610   Cardinal		diff;		/* alignment diff for dblptr */
611   RGMColorTablePtr	src_ct ;	/* arg_val as color table pointer */
612   RGMColorTablePtr	dst_ct ;	/* color table allocated in record */
613   RGMIconImagePtr	src_icon ;	/* arg_val as icon pointer */
614   RGMIconImagePtr	dst_icon ;	/* icon allocated in record */
615 
616 
617   /*
618    * Validate record, arglist descriptor, and argument number.
619    * Set the argument type now.
620    */
621   UrmCWR__ValidateContext (context_id, "UrmCWRSetArgValue") ;
622   UrmCWR__BindArgPtrs
623     (context_id, "UrmCWRSetArgValue", arg_ndx, &argdesc, &argptr) ;
624 
625   argptr->arg_val.rep_type = type ;
626 
627   /*
628    * Set the argument value depending on the type
629    */
630   switch ( type )
631     {
632     case MrmRtypeInteger:
633     case MrmRtypeHorizontalInteger:
634     case MrmRtypeVerticalInteger:
635     case MrmRtypeBoolean:
636       argptr->arg_val.datum.ival = (long) arg_val ;
637       return MrmSUCCESS ;
638 
639     case MrmRtypeSingleFloat:
640       _MrmOSHostFloatToIEEE((float *) &arg_val);
641       argptr->arg_val.datum.ival = (long)arg_val ;
642       return MrmSUCCESS ;
643 
644     case MrmRtypeChar8:
645     case MrmRtypeAddrName:
646     case MrmRtypeTransTable:
647     case MrmRtypeClassRecName:
648     case MrmRtypeKeysym:
649       result = UrmCWR__AppendString
650 	(context_id, (char *)arg_val, &offset) ;
651       if ( result != MrmSUCCESS ) return result ;
652       UrmCWR__BindArgPtrs
653 	(context_id, "UrmCWRSetArgValue", arg_ndx, &argdesc, &argptr) ;
654       argptr->arg_val.datum.offset = offset ;
655       return MrmSUCCESS ;
656 
657     case MrmRtypeCString:
658       result = UrmCWR__AppendCString
659 	(context_id, (XmString)arg_val, &offset) ;
660       if ( result != MrmSUCCESS ) return result ;
661       UrmCWR__BindArgPtrs
662 	(context_id, "UrmCWRSetArgValue", arg_ndx, &argdesc, &argptr) ;
663       argptr->arg_val.datum.offset = offset ;
664       return MrmSUCCESS ;
665 
666     case MrmRtypeWideCharacter:
667       result = UrmCWR__AppendWcharString
668 	(context_id, (wchar_t *)arg_val, &offset) ;
669       if ( result != MrmSUCCESS ) return result ;
670       UrmCWR__BindArgPtrs
671 	(context_id, "UrmCWRSetArgValue", arg_ndx, &argdesc, &argptr) ;
672       argptr->arg_val.datum.offset = offset ;
673       return MrmSUCCESS ;
674 
675     case MrmRtypeFloat:
676     case MrmRtypeHorizontalFloat:
677     case MrmRtypeVerticalFloat:
678       result = UrmCWR__GuaranteeSpace
679 	(context_id, sizeof(double), &offset, (char **) &dblptr) ;
680       if ( result != MrmSUCCESS ) return result ;
681 
682 #ifdef USE_ORIGINAL_MOTIF_CODE
683       /* This is necessary for machines (such as hp9000) that require
684 	 doubles to be aligned on 8 byte boundaries. */
685       diff = ((long)dblptr % 8);
686 
687       if (diff != 0)
688 	{
689 	  result = UrmCWR__GuaranteeSpace
690 	    (context_id, diff, &dumoff, &dumaddr) ;
691 	  if ( result != MrmSUCCESS ) return result ;
692 	}
693       dblptr = (double *)((char *)dblptr + diff);
694 #endif
695 
696       *dblptr = *((double *) arg_val) ;
697       _MrmOSHostDoubleToIEEE(dblptr);
698       UrmCWR__BindArgPtrs
699 	(context_id, "UrmCWRSetArgValue", arg_ndx, &argdesc, &argptr) ;
700       argptr->arg_val.datum.offset = offset ;
701       return MrmSUCCESS ;
702 
703     case MrmRtypeNull:
704       argptr->arg_val.datum.ival = 0L ;
705       return MrmSUCCESS ;
706 
707     case MrmRtypeColorTable:
708       src_ct = (RGMColorTablePtr) arg_val ;
709       result = UrmCWR__GuaranteeSpace
710 	(context_id, UrmColorTableSize(src_ct), &offset, (char **)&dst_ct) ;
711       if ( result != MrmSUCCESS )
712 	return result ;
713       UrmCWR__BindArgPtrs
714 	(context_id, "UrmCWRSetArgValue", arg_ndx, &argdesc, &argptr) ;
715       argptr->arg_val.datum.offset = offset ;
716       return MrmSUCCESS ;
717 
718     case MrmRtypeIconImage:
719       src_icon = (RGMIconImagePtr) arg_val ;
720       result = UrmCWR__GuaranteeSpace
721 	(context_id, UrmIconImageSize(src_icon), &offset, (char **)&dst_icon) ;
722       if ( result != MrmSUCCESS )
723 	return result ;
724       UrmCopyAllocatedIconImage (dst_icon, src_icon) ;
725       /* ??relocate pointers to offsets?? */
726       UrmCWR__BindArgPtrs
727 	(context_id, "UrmCWRSetArgValue", arg_ndx, &argdesc, &argptr) ;
728       argptr->arg_val.datum.offset = offset ;
729       return MrmSUCCESS ;
730 
731     default:
732       return Urm__UT_Error ("UrmCWRSetArgValue", _MrmMMsg_0094,
733 			    NULL, context_id, MrmBAD_ARG_TYPE) ;
734     }
735 
736 }
737 
738 
739 
740 /*
741  *++
742  *
743  *  PROCEDURE DESCRIPTION:
744  *
745  *	UrmCCWRSetArgResourceRef creates a resource reference as the value
746  *	of a MrmRtypeResource argument. Only one of the index or resource_id
747  *	parameters is used, depending on the value of the key_type parameter.
748  *	The resource group and type are as given, but are currently meaningful
749  *	only if the group is either URMgLiteral or URMgWidget. The type may
750  *	by unspecified (URMtNul).
751  *
752  *  FORMAL PARAMETERS:
753  *
754  *	context_id	resource context containing widget record
755  *	arg_ndx		the 0-based index of the argument in the arglist
756  *	access		the access to the resource - URMaPublic or URMaPrivate
757  *	group		the resource group, usually URMgLiteral or URMgWidget
758  *	type		the literal type, from RGMrType... or URMwc...
759  *			URMtNul is also legal
760  *	key_type	the key type - URMrIndex or URMrRID
761  *	index		index for URMaIndex literal
762  *	resource_id	resource id for URMaRID literal
763  *
764  *  IMPLICIT INPUTS:
765  *
766  *  IMPLICIT OUTPUTS:
767  *
768  *  FUNCTION VALUE:
769  *
770  *	MrmSUCCESS		operation succeeded
771  *	MrmBAD_CONTEXT		resource context invalid
772  *	MrmBAD_WIDGET_REC	widget record not valid
773  *	MrmNULL_DESC		arglist descriptor is null
774  *	MrmOUT_OF_BOUNDS	arg_ndx out of bounds
775  *
776  *  SIDE EFFECTS:
777  *
778  *--
779  */
780 
781 Cardinal
UrmCWRSetArgResourceRef(URMResourceContextPtr context_id,Cardinal arg_ndx,MrmCode access,MrmGroup group,MrmCode type,MrmCode key_type,String index,MrmResource_id resource_id)782 UrmCWRSetArgResourceRef(URMResourceContextPtr	context_id,
783 			Cardinal		arg_ndx,
784 			MrmCode			access,
785 			MrmGroup		group,
786 			MrmCode			type,
787 			MrmCode			key_type,
788 			String			index,
789 			MrmResource_id		resource_id)
790 {
791   /*
792    *  Local variables
793    */
794   Cardinal		result ;	/* function results */
795   RGMArgListDescPtr	argdesc ;	/* arglist desc in record */
796   RGMArgumentPtr	argptr ;	/* argument being set */
797   MrmOffset		offset ;	/* RGMResourceDesc offset */
798 
799 
800   /*
801    * Validate record, arglist descriptor, and argument number.
802    * Set the argument type.
803    */
804   UrmCWR__ValidateContext (context_id, "UrmCWRSetArgResourceRef") ;
805   UrmCWR__BindArgPtrs
806     (context_id, "UrmCWRSetArgResourceRef", arg_ndx, &argdesc, &argptr) ;
807 
808   argptr->arg_val.rep_type = MrmRtypeResource ;
809 
810   /*
811    * Acquire a resource descriptor, and bind the value to it.
812    */
813   result = UrmCWR__AppendResource
814     (context_id, access, group, type, key_type, index, resource_id, &offset) ;
815   if ( result != MrmSUCCESS ) return result ;
816 
817   UrmCWR__BindArgPtrs
818     (context_id, "UrmCWRSetArgResourceRef", arg_ndx, &argdesc, &argptr) ;
819   argptr->arg_val.datum.offset = offset ;
820 
821   /*
822    * successfully added
823    */
824   return MrmSUCCESS ;
825 
826 }
827 
828 
829 
830 /*
831  *++
832  *
833  *  PROCEDURE DESCRIPTION:
834  *
835  *	This routine sets the value of an argument in the arglist to
836  *	be a vector of ASCIZ strings.
837  *
838  *  FORMAL PARAMETERS:
839  *
840  *	context_id	resource context containing widget record
841  *	arg_ndx		the 0-based index of the argument in the arglist
842  *	stg_vec		a vector of ASCIZ string pointers
843  *	num_stg		the number of pointers in stg_vec
844  *
845  *  IMPLICIT INPUTS:
846  *
847  *  IMPLICIT OUTPUTS:
848  *
849  *  FUNCTION VALUE:
850  *
851  *	MrmSUCCESS		operation succeeded
852  *	MrmBAD_CONTEXT		resource context invalid
853  *	MrmBAD_WIDGET_REC	widget record not valid
854  *	MrmNULL_DESC		arglist descriptor is null
855  *	MrmOUT_OF_BOUNDS	arg_ndx out of bounds
856  *	MrmVEC_TOO_BIG		vector size exceeds internal limit
857  *
858  *  SIDE EFFECTS:
859  *
860  *--
861  */
862 
863 Cardinal
UrmCWRSetArgChar8Vec(URMResourceContextPtr context_id,Cardinal arg_ndx,String * stg_vec,MrmCount num_stg)864 UrmCWRSetArgChar8Vec (URMResourceContextPtr	context_id,
865 		      Cardinal			arg_ndx,
866 		      String			*stg_vec,
867 		      MrmCount			num_stg)
868 {
869   /*
870    *  Local variables
871    */
872   Cardinal		result ;	/* function results */
873   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
874   RGMArgListDescPtr	argdesc ;	/* arglist desc in record */
875   RGMArgumentPtr	argptr ;	/* argument being set */
876   RGMTextVectorPtr	vecptr ;	/* text vector in record */
877   MrmOffset		vecoffs ;	/* text vector offset */
878   MrmOffset		offset ;	/* current string offset */
879   MrmSize		vecsiz ;	/* # bytes for text vector */
880   int			ndx ;		/* loop index */
881 
882 
883   /*
884    * Validate record, arglist descriptor, and argument number.
885    */
886   UrmCWR__ValidateContext (context_id, "UrmCWRSetArgChar8Vec") ;
887   UrmCWR__BindArgPtrs
888     (context_id, "UrmCWRSetArgChar8Vec", arg_ndx, &argdesc, &argptr) ;
889 
890   /*
891    * Validate vector - make sure it doesn't contain too many elements
892    */
893   if ( num_stg > RGMListSizeMax )
894     return Urm__UT_Error ("DwUrmCWRSetArgChar8Vec", _MrmMMsg_0095,
895 			  NULL, context_id, MrmVEC_TOO_BIG) ;
896 
897   /*
898    * Allocate the text vector. Then loop and append each string in
899    * the input vector to the record, setting its offset in the
900    * record vector. This list requires count+1 entries so it may be
901    * overwritten as an in-memory list at runtime with a terminating NULL.
902    * One item is already allocated, so num_stg additional entries are needed.
903    */
904   vecsiz = sizeof(RGMTextVector) + (num_stg)*sizeof(RGMTextEntry) ;
905   result = UrmCWR__GuaranteeSpace (context_id, vecsiz, &vecoffs,
906 				   (char **)&vecptr) ;
907   if ( result != MrmSUCCESS ) return result ;
908 
909   UrmCWR__BindArgPtrs
910     (context_id, "UrmCWRSetArgChar8Vec", arg_ndx, &argdesc, &argptr) ;
911   argptr->arg_val.rep_type = MrmRtypeChar8Vector ;
912   argptr->arg_val.datum.offset = vecoffs ;
913 
914   vecptr->validation = URMTextVectorValid ;
915   vecptr->count = num_stg ;
916 
917   for ( ndx=0 ; ndx<num_stg ; ndx++ )
918     {
919       result = UrmCWR__AppendString (context_id, stg_vec[ndx], &offset) ;
920       if ( result != MrmSUCCESS ) return result ;
921       widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
922       UrmCWR__BindArgPtrs
923         (context_id, "UrmCWRSetArgChar8Vec", arg_ndx, &argdesc, &argptr) ;
924       vecptr = (RGMTextVectorPtr) ((char *)widgetrec + vecoffs) ;
925       vecptr->item[ndx].text_item.rep_type = MrmRtypeChar8 ;
926       vecptr->item[ndx].text_item.offset = offset ;
927     }
928 
929   /*
930    * set terminating null
931    */
932   vecptr->item[num_stg].pointer = NULL ;
933 
934   /*
935    * Successfully added
936    */
937   return MrmSUCCESS ;
938 
939 }
940 
941 
942 
943 /*
944  *++
945  *
946  *  PROCEDURE DESCRIPTION:
947  *
948  *	This routine sets the value of an argument in the arglist to
949  *	be a vector of compound strings
950  *
951  *  FORMAL PARAMETERS:
952  *
953  *	context_id	resource context containing widget record
954  *	arg_ndx		the 0-based index of the argument in the arglist
955  *	cstg_vec	a vector of compound string pointers
956  *	num_cstg	the number of pointers in cstg_vec
957  *
958  *  IMPLICIT INPUTS:
959  *
960  *  IMPLICIT OUTPUTS:
961  *
962  *  FUNCTION VALUE:
963  *
964  *	MrmSUCCESS		operation succeeded
965  *	MrmBAD_CONTEXT		resource context invalid
966  *	MrmBAD_WIDGET_REC	widget record not valid
967  *	MrmNULL_DESC		arglist descriptor is null
968  *	MrmOUT_OF_BOUNDS	arg_ndx out of bounds
969  *	MrmVEC_TOO_BIG		vector size exceeds internal limit
970  *
971  *  SIDE EFFECTS:
972  *
973  *--
974  */
975 
976 Cardinal
UrmCWRSetArgCStringVec(URMResourceContextPtr context_id,Cardinal arg_ndx,XmString * cstg_vec,MrmCount num_cstg)977 UrmCWRSetArgCStringVec (URMResourceContextPtr	context_id,
978 			Cardinal		arg_ndx,
979 			XmString		*cstg_vec,
980 			MrmCount		num_cstg)
981 {
982   /*
983    *  Local variables
984    */
985   Cardinal		result ;	/* function results */
986   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
987   RGMArgListDescPtr	argdesc ;	/* arglist desc in record */
988   RGMArgumentPtr	argptr ;	/* argument being set */
989   RGMTextVectorPtr	vecptr ;	/* text vector in record */
990   MrmOffset		vecoffs ;	/* text vector offset */
991   MrmOffset		offset ;	/* current compound string offset */
992   MrmSize		vecsiz ;	/* # bytes for text vector */
993   int			ndx ;		/* loop index */
994 
995 
996   /*
997    * Validate record, arglist descriptor, and argument number.
998    */
999   UrmCWR__ValidateContext (context_id, "UrmCWRSetArgCStringVec") ;
1000   UrmCWR__BindArgPtrs
1001     (context_id, "UrmCWRSetArgCStringVec", arg_ndx, &argdesc, &argptr) ;
1002 
1003   /*
1004    * Validate vector - make sure it doesn't contain too many elements
1005    */
1006   if ( num_cstg > RGMListSizeMax )
1007     return Urm__UT_Error ("DwUrmCWRSetArgCStringVec", _MrmMMsg_0095,
1008 			  NULL, context_id, MrmVEC_TOO_BIG) ;
1009 
1010   /*
1011    * Allocate the text vector. Then loop and append each string in
1012    * the input vector to the record, setting its offset in the
1013    * record vector. This list requires count+1 entries so it may be
1014    * overwritten as an in-memory list at runtime with a terminating NULL.
1015    * One item is already allocated, so num_cstg additional entries are needed.
1016    */
1017   vecsiz = sizeof(RGMTextVector) + (num_cstg)*sizeof(RGMTextEntry) ;
1018   result = UrmCWR__GuaranteeSpace (context_id, vecsiz, &vecoffs,
1019 				   (char **)&vecptr) ;
1020   if ( result != MrmSUCCESS ) return result ;
1021 
1022   UrmCWR__BindArgPtrs
1023     (context_id, "UrmCWRSetArgCStringVec", arg_ndx, &argdesc, &argptr) ;
1024   argptr->arg_val.rep_type = MrmRtypeCStringVector ;
1025   argptr->arg_val.datum.offset = vecoffs ;
1026 
1027   vecptr->validation = URMTextVectorValid ;
1028   vecptr->count = num_cstg ;
1029 
1030   for ( ndx=0 ; ndx<num_cstg ; ndx++ )
1031     {
1032       result = UrmCWR__AppendCString (context_id, cstg_vec[ndx], &offset) ;
1033       if ( result != MrmSUCCESS ) return result ;
1034       widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
1035       UrmCWR__BindArgPtrs
1036         (context_id, "UrmCWRSetArgCStringVec", arg_ndx, &argdesc, &argptr) ;
1037       vecptr = (RGMTextVectorPtr) ((char *)widgetrec + vecoffs) ;
1038       vecptr->item[ndx].text_item.rep_type = MrmRtypeCString ;
1039       vecptr->item[ndx].text_item.offset = offset ;
1040     }
1041 
1042   /*
1043    * set terminating null
1044    */
1045   vecptr->item[num_cstg].pointer = NULL ;
1046 
1047   /*
1048    * Successfully added
1049    */
1050   return MrmSUCCESS ;
1051 
1052 }
1053 
1054 
1055 
1056 /*
1057  *++
1058  *
1059  *  PROCEDURE DESCRIPTION:
1060  *
1061  *	UrmCWRSetArgCallback creates a callback descriptor for a
1062  *	MrmRtypeCallback argument. The callback descriptor is created with a
1063  *	vector of callback item descriptors whose length is nitems. The
1064  *	callback items may then be filled in with UrmCWRSetCallbackItem
1065  *	and UrmCWRSetCallbackItemRes. The offset of the new callback
1066  *	descriptor is returned for use in the set callback item routines.
1067  *
1068  *  FORMAL PARAMETERS:
1069  *
1070  *	context		resource context containing widget record
1071  *	arg_ndx		the 0-based index of the argument in the arglist
1072  *	nitems		number of items to appear in the callback list
1073  *	cb_offs_return	to return offset of RGMCallbackDesc struct created in
1074  *			widget record
1075  *
1076  *  IMPLICIT INPUTS:
1077  *
1078  *  IMPLICIT OUTPUTS:
1079  *
1080  *  FUNCTION VALUE:
1081  *
1082  *	MrmSUCCESS		operation succeeded
1083  *	MrmBAD_CONTEXT		resource context invalid
1084  *	MrmBAD_WIDGET_REC	widget record not valid
1085  *	MrmNULL_DESC		arglist descriptor is null
1086  *	MrmOUT_OF_BOUNDS	arg_ndx out of bounds
1087  *	MrmTOO_MANY		number of items exceeds internal limit
1088  *
1089  *  SIDE EFFECTS:
1090  *
1091  *--
1092  */
1093 
1094 Cardinal
UrmCWRSetArgCallback(URMResourceContextPtr context_id,Cardinal arg_ndx,Cardinal nitems,MrmOffset * cb_offs_return)1095 UrmCWRSetArgCallback (URMResourceContextPtr	context_id ,
1096 		      Cardinal			arg_ndx ,
1097 		      Cardinal			nitems ,
1098 		      MrmOffset			*cb_offs_return )
1099 {
1100   /*
1101    *  Local variables
1102    */
1103   Cardinal		result ;	/* function results */
1104   RGMArgListDescPtr	argdesc ;	/* arglist desc in record */
1105   RGMArgumentPtr	argptr ;	/* argument being set */
1106   MrmSize		descsiz ;	/* descriptor size */
1107   MrmOffset		offset ;	/* RGMCallbackDesc offset */
1108   RGMCallbackDescPtr	cbdesc ;	/* resource descriptor */
1109   int			ndx ;		/* loop index */
1110 
1111 
1112   /*
1113    * Validate record, arglist descriptor, and argument number.
1114    * Set the argument type.
1115    */
1116   UrmCWR__ValidateContext (context_id, "UrmCWRSetArgCallback") ;
1117   UrmCWR__BindArgPtrs
1118     (context_id, "UrmCWRSetArgCallback", arg_ndx, &argdesc, &argptr) ;
1119 
1120   argptr->arg_val.rep_type = MrmRtypeCallback ;
1121 
1122   /*
1123    * Confirm that the number of items is reasonable, then size and
1124    * allocate a callback descriptor. Initialize it. Note an extra
1125    * item is added for a terminating NULL for runtime use as an
1126    * in-memory list.
1127    */
1128   if ( nitems > RGMListSizeMax )
1129     return Urm__UT_Error ("UrmCWRSetArgCallback", _MrmMMsg_0109,
1130 			  NULL, context_id, MrmTOO_MANY) ;
1131 
1132   descsiz = sizeof(RGMCallbackDesc) + (nitems)*sizeof(RGMCallbackItem) ;
1133   result = UrmCWR__GuaranteeSpace (context_id, descsiz, &offset,
1134 				   (char **)&cbdesc) ;
1135   if ( result != MrmSUCCESS ) return result ;
1136 
1137   UrmCWR__BindArgPtrs
1138     (context_id, "UrmCWRSetArgCallback", arg_ndx, &argdesc, &argptr) ;
1139   argptr->arg_val.datum.offset = offset ;
1140 
1141   cbdesc->validation = URMCallbackDescriptorValid ;
1142   cbdesc->count = nitems ;
1143   cbdesc->unres_ref_count = 0 ;
1144   for ( ndx=0 ; ndx<nitems ; ndx++ )
1145     {
1146       cbdesc->item[ndx].cb_item.routine = 0 ;
1147       cbdesc->item[ndx].cb_item.rep_type = 0 ;
1148       cbdesc->item[ndx].cb_item.datum.ival = 0L ;
1149     }
1150 
1151   /*
1152    * Set terminating NULL
1153    */
1154 
1155   cbdesc->item[nitems].runtime.callback.callback = NULL ;
1156   cbdesc->item[nitems].runtime.callback.closure = 0 ;
1157 
1158   /*
1159    * successfully added
1160    */
1161   *cb_offs_return = offset ;
1162   return MrmSUCCESS ;
1163 
1164 }
1165 
1166 
1167 
1168 /*
1169  *++
1170  *
1171  *  PROCEDURE DESCRIPTION:
1172  *
1173  *	UrmCWRSetCallbackItem sets the routine name for the callback item
1174  *	to the given routine, and sets the tag value to the immedidate value
1175  *	specified by the type and itm_val parameters. The usage of the type
1176  *	and itm_val parameters is identical to UrmCWRSetArgValue.
1177  *
1178  *  FORMAL PARAMETERS:
1179  *
1180  *	context_id	resource context containing widget record
1181  *	cb_offs		offset to the callback descriptor in the widget
1182  *			record (NOT a memory pointer, in case a new buffer
1183  *			is allocated).
1184  *	item_ndx	the 0-based index of the item in the callback list
1185  *	routine		routine name associated with this item
1186  *	type		the representation type for the tag value, from
1187  *			RGMrType...
1188  *	itm_val		a longword which will be CAST and used as required to
1189  *			access the value to be stored (copied) into the widget
1190  *			record for this tag value.
1191  *
1192  *  IMPLICIT INPUTS:
1193  *
1194  *  IMPLICIT OUTPUTS:
1195  *
1196  *  FUNCTION VALUE:
1197  *
1198  *	MrmSUCCESS		operation succeeded
1199  *	URMBadcontext		resource context invalid
1200  *	MrmBAD_WIDGET_REC	widget record not valid
1201  *	MrmBAD_CALLBACK		invalid callback descriptor
1202  *	MrmOUT_OF_BOUNDS	item_ndx out of bounds
1203  *	MrmBAD_ARG_TYPE		unknown or unhandled representation type
1204  *	MrmNULL_ROUTINE		routine name is empty
1205  *
1206  *  SIDE EFFECTS:
1207  *
1208  *--
1209  */
1210 
1211 Cardinal
UrmCWRSetCallbackItem(URMResourceContextPtr context_id,MrmOffset cb_offs,Cardinal item_ndx,String routine,MrmCode type,unsigned long itm_val)1212 UrmCWRSetCallbackItem (URMResourceContextPtr	context_id,
1213 		       MrmOffset		cb_offs,
1214 		       Cardinal			item_ndx,
1215 		       String			routine,
1216 		       MrmCode			type,
1217 		       unsigned long		itm_val)
1218 {
1219   /*
1220    *  Local variables
1221    */
1222   Cardinal		result ;	/* function results */
1223   RGMCallbackDescPtr	cbdesc ;	/* callback descriptor */
1224   RGMCallbackItemPtr	itmptr ;	/* callback item in list */
1225   MrmOffset		offset ;	/* appended data offset */
1226   double		*dblptr ;	/* pointer to double constant */
1227 
1228 
1229   /*
1230    * Validate context and bind pointers to callback descriptor and item
1231    */
1232   UrmCWR__ValidateContext (context_id, "UrmCWRSetCallbackItem") ;
1233   UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItem",
1234 			    cb_offs, item_ndx, &cbdesc, &itmptr) ;
1235 
1236   /*
1237    * Validate the routine (must be non-empty)
1238    */
1239   if ( strlen(routine) <= 0 )
1240     return Urm__UT_Error ("UrmCWRSetCallbackItem", _MrmMMsg_0096,
1241 			  NULL, context_id, MrmNULL_ROUTINE) ;
1242 
1243   /*
1244    * Append the routine string and set the item
1245    */
1246   result = UrmCWR__AppendString (context_id, routine, &offset) ;
1247   if ( result != MrmSUCCESS ) return result ;
1248 
1249   UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItem",
1250 			    cb_offs, item_ndx, &cbdesc, &itmptr) ;
1251   itmptr->cb_item.routine = offset ;
1252 
1253   /*
1254    * Set the tag to the literal value as in SetArgValue
1255    */
1256   itmptr->cb_item.rep_type = type ;
1257   switch ( type )
1258     {
1259     case MrmRtypeInteger:
1260     case MrmRtypeHorizontalInteger:
1261     case MrmRtypeVerticalInteger:
1262     case MrmRtypeBoolean:
1263       itmptr->cb_item.datum.ival = (int) itm_val ;
1264       return MrmSUCCESS ;
1265 
1266     case MrmRtypeSingleFloat:
1267       _MrmOSHostFloatToIEEE((float *)&itm_val);
1268       itmptr->cb_item.datum.ival = (int) itm_val ;
1269       return MrmSUCCESS ;
1270 
1271     case MrmRtypeChar8:
1272     case MrmRtypeAddrName:
1273     case MrmRtypeTransTable:
1274     case MrmRtypeKeysym:
1275       result = UrmCWR__AppendString
1276 	(context_id, (char *)itm_val, &offset) ;
1277       if ( result != MrmSUCCESS ) return result ;
1278       UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItem",
1279 				cb_offs, item_ndx, &cbdesc, &itmptr) ;
1280       itmptr->cb_item.datum.offset = offset ;
1281       return MrmSUCCESS ;
1282 
1283     case MrmRtypeChar8Vector:
1284       return Urm__UT_Error ("UrmCWRSetCallbackItem", _MrmMMsg_0097,
1285 			    NULL, context_id, MrmBAD_ARG_TYPE) ;
1286 
1287     case MrmRtypeCString:
1288       result = UrmCWR__AppendCString
1289 	(context_id, (XmString)itm_val, &offset) ;
1290       if ( result != MrmSUCCESS ) return result ;
1291       UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItem",
1292 				cb_offs, item_ndx, &cbdesc, &itmptr) ;
1293       itmptr->cb_item.datum.offset = offset ;
1294       return MrmSUCCESS ;
1295 
1296     case MrmRtypeWideCharacter:
1297       result = UrmCWR__AppendWcharString
1298 	(context_id, (wchar_t *)itm_val, &offset) ;
1299       if ( result != MrmSUCCESS ) return result ;
1300       UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItem",
1301 				cb_offs, item_ndx, &cbdesc, &itmptr) ;
1302       itmptr->cb_item.datum.offset = offset ;
1303       return MrmSUCCESS ;
1304 
1305     case MrmRtypeCStringVector:
1306       return Urm__UT_Error ("UrmCWRSetCallbackItem", _MrmMMsg_0098,
1307 			    NULL, context_id, MrmBAD_ARG_TYPE) ;
1308 
1309     case MrmRtypeFloat:
1310     case MrmRtypeHorizontalFloat:
1311     case MrmRtypeVerticalFloat:
1312       result = UrmCWR__GuaranteeSpace
1313 	(context_id, sizeof(double), &offset, (char **)&dblptr) ;
1314       if ( result != MrmSUCCESS ) return result ;
1315       *dblptr = *((double *) itm_val) ;
1316       _MrmOSHostDoubleToIEEE(dblptr);
1317       UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItem",
1318 				cb_offs, item_ndx, &cbdesc, &itmptr) ;
1319       itmptr->cb_item.datum.offset = offset ;
1320       return MrmSUCCESS ;
1321 
1322     case MrmRtypeNull:
1323       itmptr->cb_item.datum.ival = 0L ;
1324       return MrmSUCCESS ;
1325 
1326     default:
1327       return Urm__UT_Error ("UrmCWRSetCallbackItem", _MrmMMsg_0094,
1328 			    NULL, context_id, MrmBAD_ARG_TYPE) ;
1329     }
1330 
1331 }
1332 
1333 
1334 
1335 /*
1336  *++
1337  *
1338  *  PROCEDURE DESCRIPTION:
1339  *
1340  *	UrmCWRSetCallbackItemRes sets the callback item routine name for
1341  *	the callback item to the given routine, and sets the tag value to
1342  *	be a resource reference. The interpretation of the resource
1343  *	specification parameters is identical to UrmCWRSetArgResourceRef.
1344  *
1345  *  FORMAL PARAMETERS:
1346  *
1347  *	context_id	resource context containing widget record
1348  *	cb_offs		offset to the callback descriptor in the widget record
1349  *			(NOTa memory pointer, in case a new buffer is
1350  *			allocated).
1351  *	item_ndx	the 0-based index of the item in the callback list
1352  *	routine		name of the routine for the callback item
1353  *	access		the access to the resource - URMaPublic or URMaPrivate
1354  *	group		the resource group. Only URMgLiteral makes sense,
1355  *			but the parameter is available for completeness
1356  *	type		the literal type, from RGMrType... (or URMtNul)
1357  *	key_type	the key type - URMrIndex or URMrRID
1358  *	index		index for URMaIndex literal
1359  *	resource_id	resource id for URMaRID literal
1360  *
1361  *  IMPLICIT INPUTS:
1362  *
1363  *  IMPLICIT OUTPUTS:
1364  *
1365  *  FUNCTION VALUE:
1366  *
1367  *	MrmSUCCESS		operation succeeded
1368  *	MrmBAD_CONTEXT		resource context invalid
1369  *	MrmBAD_WIDGET_REC	widget record not valid
1370  *	MrmBAD_CALLBACK		invalid callback descriptor
1371  *	MrmOUT_OF_BOUNDS	item_ndx out of bounds
1372  *	DMNullIndex		empty index string
1373  *	MrmNULL_ROUTINE		routine name is empty
1374  *
1375  *  SIDE EFFECTS:
1376  *
1377  *--
1378  */
1379 
1380 Cardinal
UrmCWRSetCallbackItemRes(URMResourceContextPtr context_id,MrmOffset cb_offs,Cardinal item_ndx,String routine,MrmGroup group,MrmCode access,MrmCode type,MrmCode key_type,String index,MrmResource_id resource_id)1381 UrmCWRSetCallbackItemRes (URMResourceContextPtr		context_id,
1382 			  MrmOffset			cb_offs,
1383 			  Cardinal			item_ndx,
1384 			  String			routine,
1385 			  MrmGroup			group,
1386 			  MrmCode			access,
1387 			  MrmCode			type,
1388 			  MrmCode			key_type,
1389 			  String			index,
1390 			  MrmResource_id		resource_id)
1391 {
1392   /*
1393    *  Local variables
1394    */
1395   Cardinal		result ;	/* function results */
1396   RGMCallbackDescPtr	cbdesc ;	/* callback descriptor */
1397   RGMCallbackItemPtr	itmptr ;	/* callback item in list */
1398   MrmOffset		offset ;	/* appended data offset */
1399 
1400 
1401   /*
1402    * Validate context and bind pointers to callback descriptor and item
1403    */
1404   UrmCWR__ValidateContext (context_id, "UrmCWRSetCallbackItemRes") ;
1405   UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItemRes",
1406 			    cb_offs, item_ndx, &cbdesc, &itmptr) ;
1407 
1408   /*
1409    * Validate the routine (must be non-empty)
1410    */
1411   if ( strlen(routine) <= 0 )
1412     return Urm__UT_Error ("UrmCWRSetCallbackItemRes", _MrmMMsg_0096,
1413 			  NULL, context_id, MrmNULL_ROUTINE) ;
1414 
1415   /*
1416    * Append the routine string and set the item
1417    */
1418   result = UrmCWR__AppendString (context_id, routine, &offset) ;
1419   if ( result != MrmSUCCESS ) return result ;
1420 
1421   UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItemRes",
1422 			    cb_offs, item_ndx, &cbdesc, &itmptr) ;
1423   itmptr->cb_item.routine = offset ;
1424 
1425   /*
1426    * Acquire and set a resource descriptor
1427    */
1428   result = UrmCWR__AppendResource
1429     (context_id, access, group, type, key_type, index, resource_id, &offset) ;
1430   if ( result != MrmSUCCESS ) return result ;
1431 
1432   UrmCWR__BindCallbackPtrs (context_id, "UrmCWRSetCallbackItemRes",
1433 			    cb_offs, item_ndx, &cbdesc, &itmptr) ;
1434   itmptr->cb_item.rep_type = MrmRtypeResource ;
1435   itmptr->cb_item.datum.offset = offset ;
1436 
1437   /*
1438    * Successfully added
1439    */
1440   return MrmSUCCESS ;
1441 
1442 }
1443 
1444 
1445 
1446 /*
1447  *++
1448  *
1449  *  PROCEDURE DESCRIPTION:
1450  *
1451  *	This routine sets the extra args count in the arglist descriptor
1452  *	to the given value
1453  *
1454  *  FORMAL PARAMETERS:
1455  *
1456  *	context_id	resource context containing widget record
1457  *	nextra		# of extra args which should be allocated by URM
1458  *			at runtime to deal with args URM creates which
1459  *			are related to those in the arglist (already
1460  *			set to 0).
1461  *
1462  *  IMPLICIT INPUTS:
1463  *
1464  *  IMPLICIT OUTPUTS:
1465  *
1466  *  FUNCTION VALUE:
1467  *
1468  *	MrmSUCCESS		operation succeeded
1469  *	MrmBAD_CONTEXT		resource context invalid
1470  *	MrmBAD_WIDGET_REC	widget record not valid
1471  *	MrmNULL_DESC		arglist descriptor is null
1472  *
1473  *  SIDE EFFECTS:
1474  *
1475  *--
1476  */
1477 
1478 Cardinal
UrmCWRSetExtraArgs(URMResourceContextPtr context_id,Cardinal nextra)1479 UrmCWRSetExtraArgs (URMResourceContextPtr	context_id ,
1480 		    Cardinal			nextra )
1481 {
1482   /*
1483    *  Local variables
1484    */
1485   RGMArgListDescPtr	argdesc ;	/* arglist desc in record */
1486   RGMArgumentPtr	argptr ;	/* argument being set */
1487 
1488 
1489   /*
1490    * Validate record, arglist descriptor. Bind usual pointers, although
1491    * argptr not used. Set the extra args field.
1492    */
1493   UrmCWR__ValidateContext (context_id, "UrmCWRSetExtraArgs") ;
1494   UrmCWR__BindArgPtrs
1495     (context_id, "UrmCWRSetExtraArgs", 0, &argdesc, &argptr) ;
1496 
1497   argdesc->extra = nextra ;
1498   return MrmSUCCESS ;
1499 
1500 }
1501 
1502 
1503 
1504 /*
1505  *++
1506  *
1507  *  PROCEDURE DESCRIPTION:
1508  *
1509  *	UrmCWRInitChildren appends an empty RGMChildrenDesc struct to the
1510  *	record, preparing it for setting children. The descriptor is
1511  *	allocated a vector of child descriptors whose length is given by the
1512  *	nchildren parameter. Each child is then set with UrmCWRSetChild.
1513  *
1514  *	The children descriptor's access field is set from the record's
1515  *	access field.
1516  *
1517  *  FORMAL PARAMETERS:
1518  *
1519  *	context_id	resource context containing widget record
1520  *	nchildren	number of children in list
1521  *
1522  *  IMPLICIT INPUTS:
1523  *
1524  *  IMPLICIT OUTPUTS:
1525  *
1526  *  FUNCTION VALUE:
1527  *
1528  *	MrmSUCCESS		operation succeeded
1529  *	MrmBAD_CONTEXT		resource context invalid
1530  *	MrmBAD_WIDGET_REC	widget record not valid
1531  *	MrmTOO_MANY		number of children exceeded internal limit
1532  *
1533  *  SIDE EFFECTS:
1534  *
1535  *--
1536  */
1537 
1538 Cardinal
UrmCWRInitChildren(URMResourceContextPtr context_id,Cardinal nchildren)1539 UrmCWRInitChildren (URMResourceContextPtr	context_id ,
1540 		    Cardinal			nchildren )
1541 {
1542   /*
1543    *  Local variables
1544    */
1545   Cardinal		result ;	/* function results */
1546   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
1547   MrmSize			descsiz ;	/* descriptor size */
1548   MrmOffset		offset ;	/* children descriptor offset */
1549   RGMChildrenDescPtr	listdesc ;	/* pointer to desc in record */
1550   int			ndx ;		/* loop index */
1551 
1552   /*
1553    * Validate record
1554    */
1555   UrmCWR__ValidateContext (context_id, "UrmCWRInitChildren") ;
1556 
1557   /*
1558    * Error check that the number of children is reasonable
1559    */
1560   if ( nchildren > RGMListSizeMax )
1561     return Urm__UT_Error ("UrmCWRInitChildren", _MrmMMsg_0099,
1562 			  NULL, context_id, MrmTOO_MANY) ;
1563 
1564   /*
1565    * compute the size required for the descriptor and the child list,
1566    * and acquire the memory in the record. Note there is one child
1567    * preallocated in the descriptor.
1568    */
1569   descsiz = sizeof(RGMChildrenDesc) + (nchildren-1)*sizeof(RGMChildDesc) ;
1570   result = UrmCWR__GuaranteeSpace (context_id, descsiz, &offset,
1571 				   (char **)&listdesc) ;
1572   if ( result != MrmSUCCESS ) return result ;
1573   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
1574   widgetrec->children_offs = offset ;
1575 
1576   /*
1577    * initialize the descriptor and all the arguments
1578    */
1579   listdesc->count = nchildren ;
1580   listdesc->annex1 = 0 ;
1581   for ( ndx=0 ; ndx<nchildren ; ndx++ )
1582     {
1583       listdesc->child[ndx].manage = 0 ;
1584       listdesc->child[ndx].access = 0 ;
1585       listdesc->child[ndx].type = 0 ;
1586       listdesc->child[ndx].annex1 = 0 ;
1587       listdesc->child[ndx].key.id = 0 ;
1588     }
1589 
1590   /*
1591    * successfully added
1592    */
1593   return MrmSUCCESS ;
1594 
1595 }
1596 
1597 
1598 
1599 /*
1600  *++
1601  *
1602  *  PROCEDURE DESCRIPTION:
1603  *
1604  *	UrmCWRSetChild sets a child descriptor in the children list for
1605  *	the widget record. Only one of the index or resource_id parameters
1606  *	is used, depending on the value of the key_type parameter.
1607  *
1608  *  FORMAL PARAMETERS:
1609  *
1610  *	context_id	resource context containing widget record
1611  *	child_ndx	index of child descriptor in children list descriptor
1612  *	manage		true/false indicating child is managed with parent at
1613  *			initialization time
1614  *	access		the access to the child - URMaPublic or URMaPrivate
1615  *	key_type	the key type - URMrIndex or URMrRID
1616  *	index		index for URMrIndex child
1617  *	resource_id	resource id for URMaRID child
1618  *
1619  *  IMPLICIT INPUTS:
1620  *
1621  *  IMPLICIT OUTPUTS:
1622  *
1623  *  FUNCTION VALUE:
1624  *
1625  *	MrmSUCCESS		operation succeeded
1626  *	MrmBAD_CONTEXT		resource context invalid
1627  *	MrmBAD_WIDGET_REC	widget record not valid
1628  *	MrmNULL_DESC		children descriptor is null
1629  *	MrmOUT_OF_BOUNDS	child_ndx was out of bounds
1630  *	MrmNULL_INDEX		empty index string for URMrIndex
1631  *	MrmBAD_KEY_TYPE		key_type was an unknown type
1632  *
1633  *  SIDE EFFECTS:
1634  *
1635  *--
1636  */
1637 
1638 Cardinal
UrmCWRSetChild(URMResourceContextPtr context_id,Cardinal child_ndx,Boolean manage,MrmCode access,MrmCode key_type,String index,MrmResource_id resource_id)1639 UrmCWRSetChild (URMResourceContextPtr	context_id,
1640 		Cardinal		child_ndx,
1641 		Boolean			manage,
1642 		MrmCode			access,
1643 		MrmCode			key_type,
1644 		String			index,
1645 		MrmResource_id		resource_id)
1646 {
1647   /*
1648    *  Local variables
1649    */
1650   Cardinal		result ;	/* function results */
1651   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
1652   MrmOffset		offset ;	/* child index offset */
1653   RGMChildrenDescPtr	listdesc ;	/* pointer to desc in record */
1654   RGMChildDescPtr	childptr ;	/* child in list */
1655 
1656   /*
1657    * Validate record
1658    */
1659   UrmCWR__ValidateContext (context_id, "UrmCWRSetChild") ;
1660 
1661   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
1662   if ( widgetrec->children_offs == 0 )
1663     return Urm__UT_Error ("UrmCWRSetChild", _MrmMMsg_0100,
1664 			  NULL, context_id, MrmNULL_DESC) ;
1665   listdesc = (RGMChildrenDescPtr) ((char*)widgetrec + widgetrec->children_offs);
1666 
1667   if ( child_ndx >= listdesc->count )
1668     return Urm__UT_Error ("UrmCWRSetChild", _MrmMMsg_0101,
1669 			  NULL, context_id, MrmOUT_OF_BOUNDS) ;
1670   childptr = &listdesc->child[child_ndx] ;
1671 
1672   /*
1673    * set child descriptor
1674    */
1675   childptr->manage = manage ;
1676   childptr->access = access ;
1677   childptr->type = key_type ;
1678   switch ( childptr->type )
1679     {
1680     case URMrIndex:
1681       if ( strlen(index) <= 0 )
1682 	return Urm__UT_Error ("UrmCWRSetChild", _MrmMMsg_0102,
1683 			      NULL, context_id, MrmNULL_INDEX) ;
1684       result = UrmCWR__AppendString (context_id, index, &offset) ;
1685       if ( result != MrmSUCCESS ) return result ;
1686       widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
1687       listdesc =
1688 	(RGMChildrenDescPtr) ((char *)widgetrec + widgetrec->children_offs) ;
1689       childptr = &listdesc->child[child_ndx] ;
1690       childptr->key.index_offs = offset ;
1691       return MrmSUCCESS ;
1692 
1693     case URMrRID:
1694       childptr->key.id = resource_id ;
1695       return MrmSUCCESS ;
1696 
1697     default:
1698       return Urm__UT_Error ("UrmCWRSetChild", _MrmMMsg_0103,
1699 			    NULL, context_id, MrmBAD_KEY_TYPE) ;
1700     }
1701 
1702 }
1703 
1704 
1705 
1706 /*
1707  *++
1708  *
1709  *  PROCEDURE DESCRIPTION:
1710  *
1711  *	UrmSetComment appends a comment to the widget record.
1712  *
1713  *  FORMAL PARAMETERS:
1714  *
1715  *	context_id	resource context containing widget record
1716  *	comment		comment string for this widget
1717  *
1718  *  IMPLICIT INPUTS:
1719  *
1720  *  IMPLICIT OUTPUTS:
1721  *
1722  *  FUNCTION VALUE:
1723  *
1724  *	MrmSUCCESS		operation succeeded
1725  *	MrmBAD_CONTEXT		resource context invalid
1726  *	MrmBAD_WIDGET_REC	widget record not valid
1727  *
1728  *  SIDE EFFECTS:
1729  *
1730  *--
1731  */
1732 
UrmCWRSetComment(URMResourceContextPtr context_id,String comment)1733 Cardinal UrmCWRSetComment (URMResourceContextPtr	context_id ,
1734 			   String			comment )
1735 {
1736   /*
1737    *  Local variables
1738    */
1739   Cardinal		result ;	/* function results */
1740   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
1741   MrmOffset		offset ;	/* comment offset */
1742 
1743 
1744   /*
1745    * Validate record
1746    */
1747   UrmCWR__ValidateContext (context_id, "UrmCWRSetComment") ;
1748 
1749   /*
1750    * Append the comment if it is non-empty
1751    */
1752   if ( strlen(comment) <= 0 )
1753     {
1754       widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
1755       widgetrec->comment_offs = 0 ;
1756       return MrmSUCCESS ;
1757     }
1758 
1759   result = UrmCWR__AppendString (context_id, comment, &offset) ;
1760   if ( result != MrmSUCCESS ) return result ;
1761   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
1762   widgetrec->comment_offs = offset ;
1763 
1764   /*
1765    * successfully added
1766    */
1767   return MrmSUCCESS ;
1768 
1769 }
1770 
1771 
1772 
1773 /*
1774  *++
1775  *
1776  *
1777  *  PROCEDURE DESCRIPTION:
1778  *
1779  *	UrmCWRSetCreationCallback initialize a callback descriptor for the
1780  *	URM creation callback for this widget. It is similar to
1781  *	UrmCWRSetArgCallback in returning the offset of a RGMCallbackDesc
1782  *	struct which may then be completed with calls to
1783  *	UrmCWRSetCallbackItem or UrmCWRSetCallbackItemRes.
1784  *
1785  *  FORMAL PARAMETERS:
1786  *
1787  *	context_id	resource context containing widget record
1788  *	nitems		number of items to appear in the callback list
1789  *	cb_offs_return	to return offset of RGMCallbackDesc struct created in
1790  *			widget record
1791  *
1792  *  IMPLICIT INPUTS:
1793  *
1794  *  IMPLICIT OUTPUTS:
1795  *
1796  *  FUNCTION VALUE:
1797  *
1798  *	MrmSUCCESS		operation succeeded
1799  *	MrmBAD_CONTEXT		resource context invalid
1800  *	MrmBAD_WIDGET_REC	widget record not valid
1801  *	MrmTOO_MANY		number of items exceeds internal limit
1802  *
1803  *  SIDE EFFECTS:
1804  *
1805  *--
1806  */
1807 
1808 Cardinal
UrmCWRSetCreationCallback(URMResourceContextPtr context_id,Cardinal nitems,MrmOffset * cb_offs_return)1809 UrmCWRSetCreationCallback (URMResourceContextPtr	context_id ,
1810 			   Cardinal			nitems ,
1811 			   MrmOffset			*cb_offs_return )
1812 {
1813   /*
1814    *  Local variables
1815    */
1816   Cardinal		result ;	/* function results */
1817   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
1818   MrmSize		descsiz ;	/* descriptor size */
1819   MrmOffset		offset ;	/* RGMCallbackDesc offset */
1820   RGMCallbackDescPtr	cbdesc ;	/* resource descriptor */
1821   int			ndx ;		/* loop index */
1822 
1823 
1824   /*
1825    * Validate record, arglist descriptor, and argument number.
1826    * Set the argument type.
1827    */
1828   UrmCWR__ValidateContext (context_id, "UrmCWRSetCreationCallback") ;
1829 
1830   /*
1831    * Confirm that the number of items is reasonable, then size and
1832    * allocate a callback descriptor. Initialize it. As in SetArgCallbac,
1833    * an extra item is added for runtime use.
1834    */
1835   if ( nitems > RGMListSizeMax )
1836     return Urm__UT_Error ("UrmCWRSetCreationCallback", _MrmMMsg_0109,
1837 			  NULL, context_id, MrmTOO_MANY) ;
1838 
1839   descsiz = sizeof(RGMCallbackDesc) + (nitems)*sizeof(RGMCallbackItem) ;
1840   result = UrmCWR__GuaranteeSpace (context_id, descsiz, &offset,
1841 				   (char **)&cbdesc) ;
1842   if ( result != MrmSUCCESS ) return result ;
1843 
1844   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer (context_id) ;
1845   widgetrec->creation_offs = offset ;
1846 
1847   cbdesc->validation = URMCallbackDescriptorValid ;
1848   cbdesc->count = nitems ;
1849   cbdesc->unres_ref_count = 0 ;
1850   for ( ndx=0 ; ndx<nitems ; ndx++ )
1851     {
1852       cbdesc->item[ndx].cb_item.routine = 0 ;
1853       cbdesc->item[ndx].cb_item.rep_type = 0 ;
1854       cbdesc->item[ndx].cb_item.datum.ival = 0L ;
1855     }
1856 
1857   /*
1858    * Set terminating NULL
1859    */
1860 
1861   cbdesc->item[nitems].runtime.callback.callback = NULL ;
1862   cbdesc->item[nitems].runtime.callback.closure = 0 ;
1863 
1864   /*
1865    * successfully added
1866    */
1867   *cb_offs_return = offset ;
1868   return MrmSUCCESS ;
1869 
1870 }
1871 
1872 
1873 
1874 /*
1875  *++
1876  *
1877  *  PROCEDURE DESCRIPTION:
1878  *
1879  *	This routine appends a string into the widget record at the
1880  *	next available location in the record. It resizes the context
1881  *	if necessary.
1882  *
1883  *  FORMAL PARAMETERS:
1884  *
1885  *	context_id	context containing the widget record
1886  *	stg		the string to append. Nothing is done if empty
1887  *	offset		To return offset in record. 0 is returned if
1888  *			the string is empty.
1889  *
1890  *  IMPLICIT INPUTS:
1891  *
1892  *  IMPLICIT OUTPUTS:
1893  *
1894  *  FUNCTION VALUE:
1895  *
1896  *	See UrmResizeResourceContext
1897  *
1898  *  SIDE EFFECTS:
1899  *
1900  *--
1901  */
1902 
1903 Cardinal
UrmCWR__AppendString(URMResourceContextPtr context_id,String stg,MrmOffset * offset)1904 UrmCWR__AppendString (URMResourceContextPtr	context_id ,
1905 		      String			stg ,
1906 		      MrmOffset			*offset )
1907 {
1908   /*
1909    *  Local variables
1910    */
1911   Cardinal		result ;	/* function results */
1912   int			len ;		/* string length */
1913   String		stgadr ;	/* destination address in record */
1914 
1915 
1916   /*
1917    * Offset zero for NULL pointer
1918    */
1919   if ( stg == NULL )
1920     {
1921       *offset = 0;
1922       return MrmSUCCESS ;
1923     }
1924 
1925   /*
1926    * Guarantee space and copy in string
1927    */
1928   len = strlen (stg) + 1 ;
1929   result = UrmCWR__GuaranteeSpace (context_id, len, offset, &stgadr) ;
1930   if ( result != MrmSUCCESS ) return result ;
1931   memcpy (stgadr, stg, len) ;
1932   return MrmSUCCESS ;
1933 
1934 }
1935 
1936 
1937 
1938 /*
1939  *++
1940  *
1941  *  PROCEDURE DESCRIPTION:
1942  *
1943  *	This routine appends a compound string into the widget record at the
1944  *	next available location in the record. It resizes the context
1945  *	if necessary.
1946  *
1947  *  FORMAL PARAMETERS:
1948  *
1949  *	context_id	context containing the widget record
1950  *	cstg		the compound string to append. Nothing is done if empty
1951  *	offset		To return offset in record. 0 is returned if
1952  *			the string is empty.
1953  *
1954  *  IMPLICIT INPUTS:
1955  *
1956  *  IMPLICIT OUTPUTS:
1957  *
1958  *  FUNCTION VALUE:
1959  *
1960  *	See UrmResizeResourceContext
1961  *
1962  *  SIDE EFFECTS:
1963  *
1964  *--
1965  */
1966 
1967 Cardinal
UrmCWR__AppendCString(URMResourceContextPtr context_id,XmString cstg,MrmOffset * offset)1968 UrmCWR__AppendCString (URMResourceContextPtr	context_id ,
1969 		       XmString			cstg ,
1970 		       MrmOffset		*offset )
1971 {
1972   /*
1973    *  Local variables
1974    */
1975   Cardinal		result ;	/* function results */
1976   int			len ;		/* length of string */
1977   char			*cstgadr ;	/* destination address in record */
1978   unsigned char		*asn1;
1979 
1980   /*
1981    * Offset zero for empty string or NULL pointer
1982    */
1983   if ( cstg == NULL )
1984     {
1985       *offset = 0;
1986       return MrmSUCCESS ;
1987     }
1988 
1989 
1990   len = XmCvtXmStringToByteStream(cstg, &asn1) ;
1991 
1992   if ( len <= 0 )
1993     {
1994       *offset = 0;
1995       return MrmSUCCESS ;
1996     }
1997 
1998   /*
1999    * Guarantee space and copy in string
2000    */
2001   result = UrmCWR__GuaranteeSpace (context_id, len, offset, &cstgadr) ;
2002   if ( result != MrmSUCCESS ) return result ;
2003   memcpy (cstgadr, (char *)asn1, len) ;
2004   return MrmSUCCESS ;
2005 
2006 }
2007 
2008 
2009 
2010 /*
2011  *++
2012  *
2013  *  PROCEDURE DESCRIPTION:
2014  *
2015  *	This routine appends a wide character string into the widget record at
2016  *	the next available location in the record. It resizes the context
2017  *	if necessary.
2018  *
2019  *  FORMAL PARAMETERS:
2020  *
2021  *	context_id	context containing the widget record
2022  *	wcs		the wide character string to append.
2023  *			Nothing is done if empty.
2024  *	offset		To return offset in record. 0 is returned if
2025  *			the string is empty.
2026  *
2027  *  IMPLICIT INPUTS:
2028  *
2029  *  IMPLICIT OUTPUTS:
2030  *
2031  *  FUNCTION VALUE:
2032  *
2033  *	See UrmResizeResourceContext
2034  *
2035  *  SIDE EFFECTS:
2036  *
2037  *--
2038  */
2039 
2040 Cardinal
UrmCWR__AppendWcharString(URMResourceContextPtr context_id,wchar_t * wcs,MrmOffset * offset)2041 UrmCWR__AppendWcharString (URMResourceContextPtr	context_id ,
2042 			   wchar_t			*wcs ,
2043 			   MrmOffset			*offset )
2044 {
2045   /*
2046    *  Local variables
2047    */
2048   Cardinal		result ;	/* function results */
2049   MrmSize		len ;		/* string length */
2050   wchar_t		*wcsadr ;	/* destination address in record */
2051   int			cnt;
2052 
2053   /*
2054    * Offset zero for NULL pointer
2055    */
2056   if ( wcs == NULL )
2057     {
2058       *offset = 0;
2059       return MrmSUCCESS ;
2060     }
2061 
2062   /*
2063    * Guarantee space and copy in string
2064    */
2065   for (cnt = 0; ; cnt++) if (wcs[cnt] == 0) break;
2066   len = (cnt+1) * sizeof(wchar_t);
2067   result = UrmCWR__GuaranteeSpace (context_id, len, offset, (char **)&wcsadr) ;
2068   if ( result != MrmSUCCESS ) return result ;
2069   memcpy (wcsadr, wcs, len) ;
2070   return MrmSUCCESS ;
2071 }
2072 
2073 
2074 /*
2075  *++
2076  *
2077  *  PROCEDURE DESCRIPTION:
2078  *
2079  *	This routine guarantees that there is enough space in the
2080  *	widget record in the context for an append operation. It
2081  *	returns the address in the record of the available space. It
2082  *	also resets the widget record size to include the delta space.
2083  *	It guarantees that all space so granted is on a fullword boundary.
2084  *
2085  *  FORMAL PARAMETERS:
2086  *
2087  *	context_id	context containing the widget record
2088  *	delta		the number of additional bytes needed for the append
2089  *	offset		to return the offset in the record
2090  *	addr		to return the address in the record
2091  *
2092  *  IMPLICIT INPUTS:
2093  *
2094  *  IMPLICIT OUTPUTS:
2095  *
2096  *  FUNCTION VALUE:
2097  *
2098  *  SIDE EFFECTS:
2099  *
2100  *--
2101  */
2102 
2103 Cardinal
UrmCWR__GuaranteeSpace(URMResourceContextPtr context_id,MrmSize delta,MrmOffset * offset,char ** addr)2104 UrmCWR__GuaranteeSpace (URMResourceContextPtr	context_id,
2105 			MrmSize			delta,
2106 			MrmOffset		*offset,
2107 			char			**addr)
2108 {
2109   /*
2110    *  Local variables
2111    */
2112   Cardinal		result ;	/* function results */
2113   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
2114 
2115   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
2116   if ( ! UrmWRValid(widgetrec) )
2117     return Urm__UT_Error ("UrmCWR__GuaranteeSpace", _MrmMMsg_0026,
2118 			  NULL, context_id, MrmBAD_RECORD) ;
2119 
2120   delta = _FULLWORD (delta) ;
2121   result = UrmResizeResourceContext (context_id, widgetrec->size+delta) ;
2122   if ( result != MrmSUCCESS ) return result ;
2123 
2124   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
2125   *offset = widgetrec->size ;
2126   *addr = (char *) widgetrec+widgetrec->size ;
2127   widgetrec->size += delta ;
2128   UrmRCSetSize (context_id, widgetrec->size) ;
2129 
2130   return MrmSUCCESS ;
2131 
2132 }
2133 
2134 
2135 
2136 /*
2137  *++
2138  *
2139  *  PROCEDURE DESCRIPTION:
2140  *
2141  *	UrmCCWR__AppendResource creates a resource reference and appends
2142  *	it to the record. Only one of the index or resource_id
2143  *	parameters is used, depending on the value of the key_type parameter.
2144  *	The only currently meaningful groups are URMgLiteral and URMgWidget.
2145  *	The resource type is taken from the type parameter (which may be
2146  *	URMtNul).
2147  *
2148  *  FORMAL PARAMETERS:
2149  *
2150  *	context_id	resource context containing widget record
2151  *	access		the access to the resource - URMaPublic or URMaPrivate
2152  *	group		resource group, usually URMgLiteral or URMgWidget
2153  *	type		conversion type for argument values, from RGMrType...
2154  *	key_type	the key type - URMrIndex or URMrRID
2155  *	index		index for URMrIndex literal
2156  *	resource_id	resource id for URMaRID literal
2157  *	offset		to return offset of descriptor
2158  *
2159  *  IMPLICIT INPUTS:
2160  *
2161  *  IMPLICIT OUTPUTS:
2162  *
2163  *  FUNCTION VALUE:
2164  *
2165  *	MrmSUCCESS		operation succeeded
2166  *	MrmBAD_CONTEXT		resource context invalid
2167  *	MrmBAD_WIDGET_REC	widget record not valid
2168  *
2169  *  SIDE EFFECTS:
2170  *
2171  *--
2172  */
2173 
2174 Cardinal
UrmCWR__AppendResource(URMResourceContextPtr context_id,MrmCode access,MrmCode group,MrmCode type,MrmCode key_type,String index,MrmResource_id resource_id,MrmOffset * offset)2175 UrmCWR__AppendResource (URMResourceContextPtr	context_id,
2176 			MrmCode			access,
2177 			MrmCode			group,
2178 			MrmCode			type,
2179 			MrmCode			key_type,
2180 			String			index,
2181 			MrmResource_id		resource_id,
2182 			MrmOffset		*offset)
2183 {
2184   /*
2185    *  Local variables
2186    */
2187   Cardinal		result ;	/* function results */
2188   MrmSize		descsiz ;	/* descriptor size */
2189   RGMResourceDescPtr	resdesc ;	/* resource descriptor */
2190 
2191 
2192   /*
2193    * Acquire and set a resource descriptor. If an RID reference, no extra is
2194    * needed. If an index, extra space for the string is required. Since
2195    * one character is allocated already, no extra is needed for the NUL.
2196    */
2197   switch ( key_type )
2198     {
2199     case URMrIndex:
2200       if ( strlen(index) <= 0 )
2201 	return Urm__UT_Error ("UrmCWR__AppendResource", _MrmMMsg_0102,
2202 			      NULL, context_id, MrmNULL_INDEX) ;
2203       descsiz = sizeof(RGMResourceDesc) + strlen(index) ;
2204       result = UrmCWR__GuaranteeSpace
2205 	(context_id, descsiz, offset, (char **)&resdesc) ;
2206       if ( result != MrmSUCCESS ) return result ;
2207 
2208       resdesc->size = descsiz ;
2209       resdesc->access = access ;
2210       resdesc->type = URMrIndex ;
2211       resdesc->res_group = group ;
2212       resdesc->cvt_type = type ;
2213       resdesc->annex1 = 0 ;
2214       strcpy (resdesc->key.index, index) ;
2215       return MrmSUCCESS ;
2216 
2217     case URMrRID:
2218       descsiz = sizeof(RGMResourceDesc) ;
2219       result = UrmCWR__GuaranteeSpace
2220 	(context_id, descsiz, offset, (char **)&resdesc) ;
2221       if ( result != MrmSUCCESS ) return result ;
2222       resdesc->size = descsiz ;
2223       resdesc->access = access ;
2224       resdesc->type = URMrRID ;
2225       resdesc->res_group = group ;
2226       resdesc->cvt_type = type ;
2227       resdesc->annex1 = 0 ;
2228       resdesc->key.id = resource_id ;
2229       return MrmSUCCESS ;
2230 
2231     default:
2232       return Urm__UT_Error ("UrmCWR__AppendResource", _MrmMMsg_0103,
2233 			    NULL, context_id, MrmBAD_KEY_TYPE) ;
2234     }
2235 
2236 }
2237 
2238 
2239 
2240 /*
2241  *++
2242  *
2243  *  PROCEDURE DESCRIPTION:
2244  *
2245  *	This routine checks that the context is valid and contains
2246  *	a valid widget record. It signals and returns an error
2247  *	otherwise.
2248  *
2249  *  FORMAL PARAMETERS:
2250  *
2251  *	context_id	resource context containing record
2252  *	routine		Name of calling routine for error signal.
2253  *
2254  *  IMPLICIT INPUTS:
2255  *
2256  *  IMPLICIT OUTPUTS:
2257  *
2258  *  FUNCTION VALUE:
2259  *
2260  *	MrmSUCCESS		Validation succeeded
2261  *	MrmBAD_CONTEXT		Invalid resource context
2262  *	MrmBAD_WIDGET_REC	Invalid widget record in context
2263  *
2264  *  SIDE EFFECTS:
2265  *
2266  *--
2267  */
2268 
2269 Cardinal
UrmCWR__ValidateContext(URMResourceContextPtr context_id,String routine)2270 UrmCWR__ValidateContext (URMResourceContextPtr	context_id ,
2271 			 String			routine )
2272 {
2273   /*
2274    *  Local variables
2275    */
2276   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
2277 
2278 
2279   if ( ! UrmRCValid(context_id) )
2280     return Urm__UT_Error (routine, _MrmMMsg_0043,
2281 			  NULL, NULL, MrmBAD_CONTEXT) ;
2282   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
2283   if ( ! UrmWRValid(widgetrec) )
2284     return Urm__UT_Error (routine, _MrmMMsg_0026,
2285 			  NULL, context_id, MrmBAD_WIDGET_REC) ;
2286   return MrmSUCCESS ;
2287 
2288 }
2289 
2290 
2291 
2292 /*
2293  *++
2294  *
2295  *  PROCEDURE DESCRIPTION:
2296  *
2297  *	This routine bind an arglist descriptor pointer and an argument pointer
2298  *	to the arglist descriptor and designated argument item in a
2299  *	widget  record. It also performs the following validations:
2300  *		non-null arglist descriptor
2301  *		argument index in bounds
2302  *
2303  *  FORMAL PARAMETERS:
2304  *
2305  *	context_id	resource context containing record
2306  *	routine		name of calling routine for error signal
2307  *	argndx		0-based argument index in list
2308  *	descptr		to return pointer to arglist descriptor
2309  *	argptr		to return pointer to designated argument item
2310  *
2311  *  IMPLICIT INPUTS:
2312  *
2313  *  IMPLICIT OUTPUTS:
2314  *
2315  *  FUNCTION VALUE:
2316  *
2317  *	MrmSUCCESS		operation succeeded
2318  *	MrmNULL_DESC		arglist descriptor is null
2319  *	MrmOUT_OF_BOUNDS	argument index out of bounds
2320  *
2321  *  SIDE EFFECTS:
2322  *
2323  *--
2324  */
2325 
2326 Cardinal
UrmCWR__BindArgPtrs(URMResourceContextPtr context_id,String routine,Cardinal argndx,RGMArgListDescPtr * descptr,RGMArgumentPtr * argptr)2327 UrmCWR__BindArgPtrs (URMResourceContextPtr	context_id ,
2328 		     String			routine ,
2329 		     Cardinal			argndx ,
2330 		     RGMArgListDescPtr		*descptr ,
2331 		     RGMArgumentPtr		*argptr )
2332 {
2333   /*
2334    *  Local variables
2335    */
2336   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
2337 
2338 
2339   /*
2340    * Pick up a widget  record, and set descriptor pointer.
2341    */
2342   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
2343   if ( UrmWRValid(widgetrec) )
2344     *descptr = (RGMArgListDescPtr) ((char *)widgetrec+widgetrec->arglist_offs) ;
2345   else
2346     return Urm__UT_Error (routine, _MrmMMsg_0026,
2347 			  NULL, context_id, MrmBAD_RECORD) ;
2348 
2349   /*
2350    * Validate argument index and set pointer
2351    */
2352   if ( argndx >= (*descptr)->count )
2353     return Urm__UT_Error (routine, _MrmMMsg_0104,
2354 			  NULL, context_id, MrmOUT_OF_BOUNDS) ;
2355   *argptr = &(*descptr)->args[argndx] ;
2356 
2357   return MrmSUCCESS ;
2358 
2359 }
2360 
2361 
2362 
2363 /*
2364  *++
2365  *
2366  *  PROCEDURE DESCRIPTION:
2367  *
2368  *	This routine binds pointers to a callback descriptor in a widget
2369  *	record, and a designated item in the callback list. It also
2370  *	performs the following validations:
2371  *		valid callback descriptor
2372  *		item index in bounds
2373  *
2374  *  FORMAL PARAMETERS:
2375  *
2376  *	context_id	context containing widget record
2377  *	routine		name of calling routine for error signal
2378  *	descoffs	offset of descriptor in record
2379  *	itemndx		0-based index of item in callback list
2380  *	descptr		to return callback descriptor pointer
2381  *	itmptr		to return callback item pointer
2382  *
2383  *  IMPLICIT INPUTS:
2384  *
2385  *  IMPLICIT OUTPUTS:
2386  *
2387  *  FUNCTION VALUE:
2388  *
2389  *	MrmSUCCESS		operation succeeded
2390  *	MrmBAD_CALLBACK		invalid callback descriptor
2391  *	MrmOUT_OF_BOUNDS	item index out of bounds
2392  *
2393  *  SIDE EFFECTS:
2394  *
2395  *--
2396  */
2397 
2398 Cardinal
UrmCWR__BindCallbackPtrs(URMResourceContextPtr context_id,String routine,MrmOffset descoffs,Cardinal itemndx,RGMCallbackDescPtr * descptr,RGMCallbackItemPtr * itmptr)2399 UrmCWR__BindCallbackPtrs (URMResourceContextPtr		context_id,
2400 			  String			routine,
2401 			  MrmOffset			descoffs,
2402 			  Cardinal			itemndx,
2403 			  RGMCallbackDescPtr		*descptr,
2404 			  RGMCallbackItemPtr		*itmptr)
2405 
2406 {
2407   /*
2408    *  Local variables
2409    */
2410   RGMWidgetRecordPtr	widgetrec ;	/* widget record in context */
2411 
2412   /*
2413    * Pick up a widget  record, and set descriptor pointer.
2414    */
2415   widgetrec = (RGMWidgetRecordPtr) UrmRCBuffer(context_id) ;
2416   if ( UrmWRValid(widgetrec) )
2417     *descptr = (RGMCallbackDescPtr) ((char *)widgetrec+descoffs) ;
2418   else
2419     return Urm__UT_Error (routine, _MrmMMsg_0105,
2420 			  NULL, context_id, MrmBAD_RECORD) ;
2421 
2422   if ( (*descptr)->validation != URMCallbackDescriptorValid )
2423     return Urm__UT_Error (routine, _MrmMMsg_0106,
2424 			  NULL, context_id, MrmBAD_CALLBACK) ;
2425 
2426   /*
2427    * validate item index and compute item pointer
2428    */
2429   if ( itemndx >= (*descptr)->count )
2430     return Urm__UT_Error (routine, _MrmMMsg_0107,
2431 			  NULL, context_id, MrmOUT_OF_BOUNDS) ;
2432   *itmptr = &(*descptr)->item[itemndx] ;
2433   return MrmSUCCESS ;
2434 
2435 }
2436 
2437