2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: PdmXp.c /main/4 1996/08/12 18:43:03 cde-hp $ */
28 * (c) Copyright 1996 Digital Equipment Corporation.
29 * (c) Copyright 1996 Hewlett-Packard Company.
30 * (c) Copyright 1996 International Business Machines Corp.
31 * (c) Copyright 1996 Sun Microsystems, Inc.
32 * (c) Copyright 1996 Novell, Inc.
33 * (c) Copyright 1996 FUJITSU LIMITED.
34 * (c) Copyright 1996 Hitachi.
40 #include <X11/Intrinsic.h>
43 PDMXP_JOB, PDMXP_DOC, PDMXP_PRINTER, PDMXP_SERVER,
44 PDMXP_BAD_POOL /* should always be last in list */
49 * static function declarations
51 static const char* PdmXpGetQualifier(PdmXp* me);
52 static char* PdmXpBuildResourceName(PdmXp* me, PdmOid id_att);
53 #if 0 && defined(PRINTING_SUPPORTED)
54 static XrmDatabase PdmXpLoadPool(PdmXp* me, XPAttributes type);
55 #endif /* PRINTING_SUPPORTED */
59 * ------------------------------------------------------------------------
64 * Creates a new PdmXp instance structure.
68 * The new PdmXp instance structure.
74 return (PdmXp*)XtCalloc(1, sizeof(PdmXp));
78 * ------------------------------------------------------------------------
83 * Closes an existing Xp connection, and frees the passed
84 * PdmXp instance structure.
92 PdmXpDelete(PdmXp* me)
99 * ------------------------------------------------------------------------
104 * This function opens the passed print display specifier and sets
105 * the passed print context on the newly opened print display.
109 * If successful, the print display pointer is returned. If unable to
110 * open the display, or if the display does not support the Xp
111 * extension, NULL is returned.
120 * only maintain one connection
124 * open the passed display spec
126 me->display = XOpenDisplay(display_spec);
132 * check to see if the display is a print server
134 #if 0 && defined(PRINTING_SUPPORTED)
135 if(XpQueryExtension(me->display, &event_base, &error_base))
138 * set the passed print context on the print display
140 me->context = strtoul(context_str, (char**)NULL, 0);
142 * load the resource DB qualifier
144 PdmXpGetQualifier(me);
148 #endif /* PRINTING_SUPPORTED */
149 XCloseDisplay(me->display);
150 me->display = (Display*)NULL;
151 #if 0 && defined(PRINTING_SUPPORTED)
153 #endif /* PRINTING_SUPPORTED */
160 * ------------------------------------------------------------------------
165 * Closes the print display.
173 PdmXpClose(PdmXp* me)
179 for(i = 0; i < PDMXP_POOL_COUNT; i++)
181 if(me->pool[i] != (XrmDatabase)NULL)
183 XrmDestroyDatabase(me->pool[i]);
184 me->pool[i] = (XrmDatabase)NULL;
187 XCloseDisplay(me->display);
189 #if 0 && defined(PRINTING_SUPPORTED)
190 me->context = (XPContext)NULL;
191 #endif /* PRINTING_SUPPORTED */
196 * ------------------------------------------------------------------------
197 * Name: PdmXpLoadPool
208 #if 0 && defined(PRINTING_SUPPORTED)
210 PdmXpLoadPool(PdmXp* me, XPAttributes type)
214 * determine the index into the pool array based on the Xp pool type
231 return (XrmDatabase)NULL;
235 * get the attributes from the X print server
237 if(me->pool[i] == (XrmDatabase)NULL)
239 XTextProperty text_prop;
243 text_prop.value = (unsigned char*)
244 XpGetAttributes(me->display, me->context, type);
245 text_prop.encoding = XInternAtom(me->display, "COMPOUND_TEXT", False);
246 text_prop.format = 8;
247 text_prop.nitems = strlen((char*)text_prop.value);
249 XmbTextPropertyToTextList(me->display, &text_prop, &list, &count))
252 me->pool[i] = XrmGetStringDatabase(list[0]);
254 XFreeStringList(list);
260 #endif /* PRINTING_SUPPORTED */
263 * ------------------------------------------------------------------------
264 * Name: PdmXpGetQualifier
275 PdmXpGetQualifier(PdmXp* me)
277 if(me->qualifier == (char*)NULL)
279 #if 0 && defined(PRINTING_SUPPORTED)
280 if(PdmXpLoadPool(me, XPPrinterAttr) != (XrmDatabase)NULL)
285 if(XrmGetResource(me->pool[PDMXP_PRINTER],
286 "qualifier", "qualifier", &str_type, &value))
288 me->qualifier = XtNewString((char*)value.addr);
289 me->qualifier_len = strlen(me->qualifier);
292 #endif /* PRINTING_SUPPORTED */
294 return me->qualifier;
300 * ------------------------------------------------------------------------
301 * Name: PdmXpBuildResourceName
309 * A new fully-qualified resource name. It is the caller's
310 * responsibility to free the returned string by calling XtFree.
314 PdmXpBuildResourceName(PdmXp* me, PdmOid id_att)
320 * allocate memory for the resource name
322 oid_str_len = PdmOidStringLength(id_att);
324 XtMalloc(me->qualifier_len + 1 + oid_str_len + 1);
326 * build the resource name from the printer name and the string value
327 * for the passed attribute id
329 strncpy(ptr, me->qualifier, me->qualifier_len);
330 ptr += me->qualifier_len;
333 strncpy(ptr, PdmOidString(id_att), oid_str_len);
344 * ------------------------------------------------------------------------
345 * Name: PdmXpGetValue
353 * pdmoid_none if the attribute value is not found.
356 #if 0 && defined(PRINTING_SUPPORTED)
358 PdmXpGetValue(PdmXp* me,
364 value = PdmXpGetStringValue(me, type, id_att);
366 return PdmOidFromString(value);
368 #endif /* PRINTING_SUPPORTED */
371 * ------------------------------------------------------------------------
372 * Name: PdmXpGetStringValue
380 * NULL if the attribute value is not found, or if the resource
381 * representation type is not a string.
384 #if 0 && defined(PRINTING_SUPPORTED)
386 PdmXpGetStringValue(PdmXp* me,
397 pool = PdmXpLoadPool(me, type);
398 if(pool == (XrmDatabase)NULL)
399 return (const char*)NULL;
401 res_name = PdmXpBuildResourceName(me, id_att);
402 found = XrmGetResource(pool, res_name, res_name, &str_type, &value);
409 return (const char*)value.addr;
411 return (const char*)NULL;
413 #endif /* PRINTING_SUPPORTED */
416 * ------------------------------------------------------------------------
417 * Name: PdmXpSetValue
428 #if 0 && defined(PRINTING_SUPPORTED)
430 PdmXpSetValue(PdmXp* me,
435 PdmXpSetStringValue(me, type, id_att, PdmOidString(id_val));
437 #endif /* PRINTING_SUPPORTED */
440 * ------------------------------------------------------------------------
441 * Name: PdmXpSetStringValue
452 #if 0 && defined(PRINTING_SUPPORTED)
454 PdmXpSetStringValue(PdmXp* me,
463 pool = PdmXpLoadPool(me, type);
464 if(pool == (XrmDatabase)NULL)
467 res_name = PdmXpBuildResourceName(me, id_att);
468 XrmPutStringResource(&pool, res_name, (char*)str_val);
471 #endif /* PRINTING_SUPPORTED */
475 * ------------------------------------------------------------------------
476 * Name: PdmXpUpdateAttributes
488 PdmXpUpdateAttributes(PdmXp* me)
490 #if 0 && defined(PRINTING_SUPPORTED)
491 char fname[L_tmpnam];
503 XTextProperty text_prop;
505 for(i = 0; i < PDMXP_POOL_COUNT; i++)
507 if(me->pool[i] != (XrmDatabase)NULL)
521 * write out the attribute pool to a file Xrm DB
523 XrmPutFileDatabase(me->pool[i], fname);
525 * open the new file Xrm DB
527 if(fp = fopen(fname, "r"))
530 * read the file to create a string Xrm DB
532 fstat(fileno(fp), &stbuf);
533 if(stbuf.st_size + 1 > data_size)
535 data_size = stbuf.st_size + 1;
536 data = XtRealloc(data, data_size);
538 retlen = read(fileno(fp), data, stbuf.st_size);
543 * convert to compund text
546 XmbTextListToTextProperty(me->display,
552 * use the string Xrm DB to update the Xp server
554 XpSetAttributes(me->display, me->context,
555 type, (char*)text_prop.value,
558 XFree(text_prop.value);
566 #endif /* PRINTING_SUPPORTED */