cmsProp.c revision 1ab64890
1/* $Xorg: cmsProp.c,v 1.3 2000/08/17 19:45:10 cpqbld Exp $ */ 2 3/* 4 * 5 * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. 6 * All Rights Reserved 7 * 8 * This file is a component of an X Window System-specific implementation 9 * of Xcms based on the TekColor Color Management System. Permission is 10 * hereby granted to use, copy, modify, sell, and otherwise distribute this 11 * software and its documentation for any purpose and without fee, provided 12 * that this copyright, permission, and disclaimer notice is reproduced in 13 * all copies of this software and in supporting documentation. TekColor 14 * is a trademark of Tektronix, Inc. 15 * 16 * Tektronix makes no representation about the suitability of this software 17 * for any purpose. It is provided "as is" and with all faults. 18 * 19 * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, 20 * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 21 * PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY 22 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 23 * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF 24 * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 25 * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. 26 * 27 * NAME 28 * XcmsProp.c 29 * 30 * DESCRIPTION 31 * This utility routines for manipulating properties. 32 * 33 */ 34/* $XFree86$ */ 35 36#ifdef HAVE_CONFIG_H 37#include <config.h> 38#endif 39#include <X11/Xatom.h> 40#include "Xlibint.h" 41#include "Xcmsint.h" 42#include "Cv.h" 43 44 45/************************************************************************ 46 * * 47 * API PRIVATE ROUTINES * 48 * * 49 ************************************************************************/ 50 51 52/* 53 * NAME 54 * _XcmsGetElement -- get an element value from the property passed 55 * 56 * SYNOPSIS 57 */ 58unsigned long 59_XcmsGetElement( 60 int format, 61 char **pValue, 62 unsigned long *pCount) 63/* 64 * DESCRIPTION 65 * Get the next element from the property and return it. 66 * Also increment the pointer the amount needed. 67 * 68 * Returns 69 * unsigned long 70 */ 71{ 72 unsigned long value; 73 74 switch (format) { 75 case 32: 76 value = *((unsigned long *)(*pValue)) & 0xFFFFFFFF; 77 *pValue += sizeof(unsigned long); 78 *pCount -= 1; 79 break; 80 case 16: 81 value = *((unsigned short *)(*pValue)); 82 *pValue += sizeof(unsigned short); 83 *pCount -= 1; 84 break; 85 case 8: 86 value = *((unsigned char *) (*pValue)); 87 *pValue += 1; 88 *pCount -= 1; 89 break; 90 default: 91 value = 0; 92 break; 93 } 94 return(value); 95} 96 97 98/* 99 * NAME 100 * _XcmsGetProperty -- Determine the existance of a property 101 * 102 * SYNOPSIS 103 */ 104int 105_XcmsGetProperty( 106 Display *pDpy, 107 Window w, 108 Atom property, 109 int *pFormat, 110 unsigned long *pNItems, 111 unsigned long *pNBytes, 112 char **pValue) 113/* 114 * DESCRIPTION 115 * 116 * Returns 117 * 0 if property does not exist. 118 * 1 if property exists. 119 */ 120{ 121 char *prop_ret; 122 int format_ret; 123 long len = 6516; 124 unsigned long nitems_ret, after_ret; 125 Atom atom_ret; 126 127 while (XGetWindowProperty (pDpy, w, property, 0, len, False, 128 XA_INTEGER, &atom_ret, &format_ret, 129 &nitems_ret, &after_ret, 130 (unsigned char **)&prop_ret)) { 131 if (after_ret > 0) { 132 len += nitems_ret * (format_ret >> 3); 133 XFree (prop_ret); 134 } else { 135 break; 136 } 137 } 138 if (format_ret == 0 || nitems_ret == 0) { 139 /* the property does not exist or is of an unexpected type */ 140 return(XcmsFailure); 141 } 142 143 *pFormat = format_ret; 144 *pNItems = nitems_ret; 145 *pNBytes = nitems_ret * (format_ret >> 3); 146 *pValue = prop_ret; 147 return(XcmsSuccess); 148} 149