2 * (c) Copyright 1995 Digital Equipment Corporation.
3 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
4 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
5 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
6 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
7 * (c) Copyright 1995 FUJITSU LIMITED.
8 * (c) Copyright 1995 Hitachi.
10 * $XConsortium: SmProp.c /main/4 1996/10/07 10:29:51 drk $
14 #include <X11/Intrinsic.h>
15 #include <X11/SM/SMlib.h>
19 * Forward declarations
21 static SmPropValue * CopyPropValues (
23 SmPropValue * thePropValues);
29 SmPointer managerData,
33 ClientRecPtr pClient = (ClientRecPtr) managerData;
39 (void) printf ("Received SET PROPERTIES [%p]\n", smsConn);
45 for (i = 0; i < numProps; i++) {
49 if (theProps[i]->num_vals == 0)
52 for (pProp = pClient->props;
54 pProp = pProp->next) {
56 if (!strcmp (theProps[i]->name, pProp->prop.name) &&
57 !strcmp (theProps[i]->type, pProp->prop.type)) {
59 * Reuse this property but replace its
63 for (j = 0; j < pProp->prop.num_vals; j++) {
64 XtFree (pProp->prop.vals[j].value);
67 if (pProp->prop.num_vals > 0)
68 XtFree ((char *) pProp->prop.vals);
70 pProp->prop.vals = CopyPropValues (
71 theProps[i]->num_vals,
74 pProp->prop.num_vals = theProps[i]->num_vals;
84 * Put it at the end of the list (or the beginning
85 * if this client has no properties)
87 PropertyRecPtr trail = pClient->props;
88 for (pProp = pClient->props;
90 trail = pProp, pProp = pProp->next);
93 pProp = (PropertyRecPtr)XtMalloc (sizeof (PropertyRec));
100 pClient->props = pProp;
102 pProp->prop.name = XtNewString (theProps[i]->name);
103 pProp->prop.type = XtNewString (theProps[i]->type);
104 pProp->prop.num_vals = theProps[i]->num_vals;
107 pProp->prop.vals = CopyPropValues (
108 theProps[i]->num_vals, theProps[i]->vals);
111 SmFreeProperty (theProps[i]);
115 free ((char *) theProps);
118 for (i = 0, pProp = pClient->props;
120 i++, pProp = pProp->next) {
121 (void) printf ("\t[%2d] name = %s\n", i + 1,
123 (void) printf ("\t[%2d] type = %s\n", i + 1,
125 (void) printf ("\t[%2d] num props = %d\n", i + 1,
126 pProp->prop.num_vals);
127 for (j = 0; j < pProp->prop.num_vals; j++) {
128 (void) printf ("\t\t [%2d] (%3d bytes) = %s\n", j + 1,
129 pProp->prop.vals[j].length,
130 pProp->prop.vals[j].value);
138 DeletePropertiesProc (
140 SmPointer managerData,
144 ClientRecPtr pClient = (ClientRecPtr) managerData;
148 (void) printf ("Received DELETE PROPERTIES [%p] - %d properties\n",
150 for (i = 0; i < numProps; i++)
151 (void) printf ("\t%s\n", propNames[i]);
157 for (i = 0; i < numProps; i++) {
159 PropertyRecPtr pProp;
161 PropertyRecPtr trail;
163 for (pProp = pClient->props, trail = pClient->props ;
165 trail = pProp, pProp = pProp->next) {
167 if (!strcmp (pProp->prop.name, propNames[i])) {
171 XtFree (pProp->prop.name);
172 XtFree (pProp->prop.type);
174 for (j = 0; j < pProp->prop.num_vals; j++) {
175 XtFree (pProp->prop.vals[j].value);
178 if (pProp->prop.num_vals > 0)
179 XtFree ((char *) pProp->prop.vals);
181 * Remove the record from the list and then
184 trail->next = pProp->next;
185 XtFree ((char *) pProp);
193 free ((char *) propNames);
200 SmPointer managerData)
202 ClientRecPtr pClient = (ClientRecPtr) managerData;
203 PropertyRecPtr pProp;
204 PropertyRecPtr trail;
210 (void) printf ("Received GET PROPERTIES [%p]\n", smsConn);
213 if (!pClient->props) {
214 SmsReturnProperties (smsConn, 0, NULL);
218 for (pProp = pClient->props, numProps = 0;
220 pProp = pProp->next, numProps++);
222 pPropsRet = (SmProp **) XtMalloc (numProps * sizeof (SmProp *));
225 SmsReturnProperties (smsConn, 0, NULL);
230 * This function must return an array of pointers to SmProp
231 * structures and since the properties are actually stored
232 * in a linked list, a transformation is required.
234 for (i=0, pProp = pClient->props;
236 i++, pProp = pProp->next) {
238 pPropsRet[i] = (SmProp *) XtMalloc (sizeof (SmProp));
240 SmsReturnProperties (smsConn, 0, NULL);
244 pPropsRet[i]->name = XtNewString (pProp->prop.name);
245 pPropsRet[i]->type = XtNewString (pProp->prop.type);
246 pPropsRet[i]->num_vals = pProp->prop.num_vals;
247 pPropsRet[i]->vals = (SmPropValue *) XtMalloc (
248 pProp->prop.num_vals * sizeof (SmPropValue));
250 if (!pPropsRet[i]->vals) {
251 SmsReturnProperties (smsConn, 0, NULL);
255 for (j = 0; j < pProp->prop.num_vals; j++) {
257 pPropsRet[i]->vals[j].length =
258 pProp->prop.vals[j].length;
259 pPropsRet[i]->vals[j].value = (SmPointer)
260 XtMalloc (pProp->prop.vals[j].length);
262 if (!pPropsRet[i]->vals[j].value) {
263 SmsReturnProperties (smsConn, 0, NULL);
267 memcpy (pPropsRet[i]->vals[j].value,
268 pProp->prop.vals[j].value,
269 pProp->prop.vals[j].length);
273 SmsReturnProperties (smsConn, numProps, pPropsRet);
276 for (i = 0; i < numProps; i++) {
277 (void) printf ("\t[%2d] name = %s\n", i + 1,
279 (void) printf ("\t[%2d] type = %s\n", i + 1,
281 (void) printf ("\t[%2d] num props = %d\n", i + 1,
282 pPropsRet[i]->num_vals);
283 for (j = 0; j < pPropsRet[i]->num_vals; j++) {
284 (void) printf ("\t\t [%2d] (%3d bytes) = %s\n", j + 1,
285 pPropsRet[i]->vals[j].length,
286 pPropsRet[i]->vals[j].value);
291 for (i = 0; i < numProps; i++)
292 SmFreeProperty (pPropsRet[i]);
294 XtFree ((char *) pPropsRet);
301 SmPropValue * thePropValues)
303 SmPropValue * pPropValueRet;
306 pPropValueRet = (SmPropValue *) XtMalloc (numPropValues *
307 sizeof (SmPropValue));
312 for (i = 0; i < numPropValues; i++) {
314 pPropValueRet[i].length = thePropValues[i].length;
315 pPropValueRet[i].value = (SmPointer)
316 XtMalloc(thePropValues[i].length + 1);
318 if (!pPropValueRet[i].value)
321 memcpy (pPropValueRet[i].value,
322 thePropValues[i].value,
323 thePropValues[i].length);
325 ((char *) pPropValueRet[i].value)[pPropValueRet[i].length]='\0';
328 return (pPropValueRet);
333 * Returns a ptr to the property record list for the given
338 ClientRecPtr pClientRec,
341 PropertyRecPtr pPropRec;
343 for (pPropRec = pClientRec->props; pPropRec;
344 pPropRec = pPropRec->next) {
346 if (!strcmp (propName, pPropRec->prop.name))
356 * If the given property exists, it returns a ptr to the first
357 * value of the property if the type of the property is SmARRAY8
361 GetArrayPropertyValue (
362 ClientRecPtr pClientRec,
365 PropertyRecPtr pPropRec;
367 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
370 if ((!strcmp (pPropRec->prop.type, SmARRAY8)) &&
371 (pPropRec->prop.num_vals >= 1))
372 return (pPropRec->prop.vals[0].value);
378 /*************************************<->*************************************
380 * GetListOfArrayPropertyValue -
382 * Description: If the specified property exits and its type is
383 * a LISTofARRAY8, then a NULL-terminated array of pointers
384 * to the values is returned.
386 * Returns: NULL-terminated array of values or NULL
388 * Comments: caller is responsible for using XtFree to free the returned
389 * pointer if it is not NULL
391 *************************************<->***********************************/
393 GetListOfArrayPropertyValue (
394 ClientRecPtr pClientRec,
397 PropertyRecPtr pPropRec;
401 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
404 if ((strcmp (pPropRec->prop.type, SmLISTofARRAY8)) ||
405 (pPropRec->prop.num_vals <= 0))
408 ppchar = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
413 for (i = 0; i < pPropRec->prop.num_vals; i++)
414 ppchar[i] = pPropRec->prop.vals[i].value;
416 ppchar[pPropRec->prop.num_vals] = NULL;
422 /*************************************<->*************************************
424 * GetCardPropertyValue -
426 * Description: If the specified property exits and its type is
427 * a CARD8, then return its value.
429 * Returns: True if the property is found; False otherwise
431 *************************************<->***********************************/
433 GetCardPropertyValue (
434 ClientRecPtr pClientRec,
436 int * propValue) /* MODIFIED */
438 PropertyRecPtr pPropRec;
440 if ((pPropRec = GetPropertyRec (pClientRec, propName)) == NULL)
443 if ((!strcmp (pPropRec->prop.type, SmCARD8)) &&
444 (pPropRec->prop.num_vals >= 1)) {
445 int hint = (int) *((char *) (pPropRec->prop.vals[0].value));