xcmsdb.c revision 16d7e2f1
12c7c4e3dSmrg/* $Xorg: xcmsdb.c,v 1.3 2000/08/17 19:54:13 cpqbld Exp $ */
22c7c4e3dSmrg
32c7c4e3dSmrg/*
42c7c4e3dSmrg * (c) Copyright 1990 Tektronix Inc.
52c7c4e3dSmrg * 	All Rights Reserved
62c7c4e3dSmrg *
72c7c4e3dSmrg * Permission to use, copy, modify, and distribute this software and its
82c7c4e3dSmrg * documentation for any purpose and without fee is hereby granted,
92c7c4e3dSmrg * provided that the above copyright notice appear in all copies and that
102c7c4e3dSmrg * both that copyright notice and this permission notice appear in
112c7c4e3dSmrg * supporting documentation, and that the name of Tektronix not be used
122c7c4e3dSmrg * in advertising or publicity pertaining to distribution of the software
132c7c4e3dSmrg * without specific, written prior permission.
142c7c4e3dSmrg *
152c7c4e3dSmrg * Tektronix disclaims all warranties with regard to this software, including
162c7c4e3dSmrg * all implied warranties of merchantability and fitness, in no event shall
172c7c4e3dSmrg * Tektronix be liable for any special, indirect or consequential damages or
182c7c4e3dSmrg * any damages whatsoever resulting from loss of use, data or profits,
192c7c4e3dSmrg * whether in an action of contract, negligence or other tortious action,
202c7c4e3dSmrg * arising out of or in connection with the use or performance of this
212c7c4e3dSmrg * software.
222c7c4e3dSmrg *
232c7c4e3dSmrg *
242c7c4e3dSmrg *	NAME
252c7c4e3dSmrg *		xcmsdb.c
262c7c4e3dSmrg *
272c7c4e3dSmrg *	DESCRIPTION
282c7c4e3dSmrg *		Program to load, query or remove the Screen Color
292c7c4e3dSmrg *		Characterization Data from the root window of the screen.
302c7c4e3dSmrg *
312c7c4e3dSmrg */
322c7c4e3dSmrg/* $XFree86: xc/programs/xcmsdb/xcmsdb.c,v 1.5 2001/01/17 23:45:19 dawes Exp $ */
332c7c4e3dSmrg
342c7c4e3dSmrg/*
352c7c4e3dSmrg *      INCLUDES
362c7c4e3dSmrg */
372c7c4e3dSmrg
382c7c4e3dSmrg#include <stdio.h>
392c7c4e3dSmrg#include <stdlib.h>
402c7c4e3dSmrg#include <X11/Xlib.h>
412c7c4e3dSmrg#include <X11/Xatom.h>
422c7c4e3dSmrg#include <X11/Xos.h>
432c7c4e3dSmrg#include <ctype.h>
442c7c4e3dSmrg
452c7c4e3dSmrg#include "SCCDFile.h"
462c7c4e3dSmrg
472c7c4e3dSmrgstatic void QuerySCCDataRGB(Display *dpy, Window root);
482c7c4e3dSmrgstatic void RemoveSCCData(Display *dpy, Window root, int colorFlag);
492c7c4e3dSmrgstatic unsigned long _XcmsGetElement(int format, char **pValue,
502c7c4e3dSmrg				     unsigned long *pCount);
512c7c4e3dSmrgstatic int _XcmsGetProperty(Display *pDpy, Window w, Atom property,
522c7c4e3dSmrg			    int *pFormat, unsigned long *pNItems,
532c7c4e3dSmrg			    unsigned long *pNBytes, char **pValue);
542c7c4e3dSmrg
552c7c4e3dSmrg
568650bb69Smrgstatic char *ProgramName;
572c7c4e3dSmrg
582c7c4e3dSmrgstatic void
592c7c4e3dSmrgSyntax (void)
602c7c4e3dSmrg{
612c7c4e3dSmrg    fprintf (stderr,
622c7c4e3dSmrg	     "usage:  %s [-options ...] [filename]\n\n",
632c7c4e3dSmrg	     ProgramName);
642c7c4e3dSmrg    fprintf (stderr,
652c7c4e3dSmrg	     "where options include:\n");
662c7c4e3dSmrg    fprintf (stderr,
672c7c4e3dSmrg	     "    -display host:dpy[.scrn]     display to use\n");
682c7c4e3dSmrg    fprintf (stderr,
692c7c4e3dSmrg	     "    -format [ 32 | 16 | 8 ]      property format\n");
702c7c4e3dSmrg    fprintf (stderr,
712c7c4e3dSmrg	     "    -query                       query Screen Color Characterization Data\n");
722c7c4e3dSmrg    fprintf (stderr,
732c7c4e3dSmrg	     "    -remove                      remove Screen Color Characterization Data\n");
742c7c4e3dSmrg#ifdef GRAY
752c7c4e3dSmrg    fprintf (stderr,
762c7c4e3dSmrg	     "    -color                       use color as default\n");
772c7c4e3dSmrg    fprintf (stderr,
782c7c4e3dSmrg	     "    -gray                        use gray-scale as default\n");
792c7c4e3dSmrg#endif /* GRAY */
802c7c4e3dSmrg    fprintf (stderr,
812c7c4e3dSmrg	     "\n");
822c7c4e3dSmrg    exit (1);
832c7c4e3dSmrg}
842c7c4e3dSmrg
852c7c4e3dSmrgstatic Bool
862c7c4e3dSmrgoptionmatch(char *opt, char *arg, int minlen)
872c7c4e3dSmrg{
882c7c4e3dSmrg    int arglen;
892c7c4e3dSmrg
902c7c4e3dSmrg    if (strcmp(opt, arg) == 0) {
912c7c4e3dSmrg	return(True);
922c7c4e3dSmrg    }
932c7c4e3dSmrg
942c7c4e3dSmrg    if ((arglen = strlen(arg)) >= (int)strlen(opt) || arglen < minlen) {
952c7c4e3dSmrg	return(False);
962c7c4e3dSmrg    }
972c7c4e3dSmrg
982c7c4e3dSmrg    if (strncmp (opt, arg, arglen) == 0) {
992c7c4e3dSmrg	return(True);
1002c7c4e3dSmrg    }
1012c7c4e3dSmrg
1022c7c4e3dSmrg    return(False);
1032c7c4e3dSmrg}
1042c7c4e3dSmrg
1052c7c4e3dSmrgint
1062c7c4e3dSmrgmain(int argc, char *argv[])
1072c7c4e3dSmrg{
1082c7c4e3dSmrg    Display *dpy;
1092c7c4e3dSmrg    int i;
1102c7c4e3dSmrg    char *displayname = NULL;
1112c7c4e3dSmrg    char *filename = NULL;
1122c7c4e3dSmrg    int query = 0;
1132c7c4e3dSmrg    int remove = 0;
1142c7c4e3dSmrg    int load = 0;
1152c7c4e3dSmrg    int color = -1;
1162c7c4e3dSmrg    int targetFormat = 32;
1172c7c4e3dSmrg
1182c7c4e3dSmrg    ProgramName = argv[0];
1192c7c4e3dSmrg
1202c7c4e3dSmrg    for (i = 1; i < argc; i++) {
1212c7c4e3dSmrg	char *arg = argv[i];
1222c7c4e3dSmrg
1232c7c4e3dSmrg	if (arg[0] == '-') {
1242c7c4e3dSmrg	    if (arg[1] == '\0') {
1252c7c4e3dSmrg		filename = NULL;
1262c7c4e3dSmrg		continue;
1272c7c4e3dSmrg	    } else if (optionmatch ("-help", arg, 1)) {
1282c7c4e3dSmrg		Syntax ();
1292c7c4e3dSmrg		/* doesn't return */
1302c7c4e3dSmrg	    } else if (optionmatch ("-display", arg, 1)) {
1312c7c4e3dSmrg		if (++i >= argc) Syntax ();
1322c7c4e3dSmrg		displayname = argv[i];
1332c7c4e3dSmrg		continue;
1342c7c4e3dSmrg	    } else if (optionmatch ("-format", arg, 1)) {
1352c7c4e3dSmrg		if (++i >= argc) Syntax ();
1362c7c4e3dSmrg		targetFormat = atoi(argv[i]);
1372c7c4e3dSmrg		if (targetFormat != 32 && targetFormat != 16 &&
1382c7c4e3dSmrg			targetFormat != 8) Syntax();
1392c7c4e3dSmrg		continue;
1402c7c4e3dSmrg	    } else if (optionmatch ("-query", arg, 1)) {
1412c7c4e3dSmrg		query = 1;
1422c7c4e3dSmrg		continue;
1432c7c4e3dSmrg	    } else if (optionmatch ("-remove", arg, 1)) {
1442c7c4e3dSmrg		remove = 1;
1452c7c4e3dSmrg		continue;
1462c7c4e3dSmrg#ifdef GRAY
1472c7c4e3dSmrg	    } else if (optionmatch ("-color", arg, 1)) {
1482c7c4e3dSmrg		color = 1;
1492c7c4e3dSmrg		continue;
1502c7c4e3dSmrg	    } else if (optionmatch ("-gray", arg, 1)) {
1512c7c4e3dSmrg		color = 0;
1522c7c4e3dSmrg		continue;
1532c7c4e3dSmrg#endif /* GRAY */
1542c7c4e3dSmrg	    }
1552c7c4e3dSmrg	    Syntax ();
1562c7c4e3dSmrg	} else {
1572c7c4e3dSmrg	    load = 1;
1582c7c4e3dSmrg	    filename = arg;
1592c7c4e3dSmrg	}
1602c7c4e3dSmrg    }
1612c7c4e3dSmrg
1622c7c4e3dSmrg    /* Open display  */
1632c7c4e3dSmrg    if (!(dpy = XOpenDisplay (displayname))) {
1642c7c4e3dSmrg      fprintf (stderr, "%s:  Can't open display '%s'\n",
1652c7c4e3dSmrg	       ProgramName, XDisplayName(displayname));
1662c7c4e3dSmrg      exit (1);
1672c7c4e3dSmrg    }
1682c7c4e3dSmrg
16916d7e2f1Smrg    if (query || remove) {
1702c7c4e3dSmrg	load = 0;
1712c7c4e3dSmrg    }
1722c7c4e3dSmrg
17316d7e2f1Smrg    if (load) {
1742c7c4e3dSmrg	LoadSCCData(dpy, DefaultScreen(dpy), filename, targetFormat);
1752c7c4e3dSmrg    }
1762c7c4e3dSmrg
1772c7c4e3dSmrg    if (query) {
1782c7c4e3dSmrg	if (color != 0)
1792c7c4e3dSmrg	    QuerySCCDataRGB(dpy, RootWindow(dpy, DefaultScreen(dpy)));
1802c7c4e3dSmrg#ifdef GRAY
1812c7c4e3dSmrg	if (color != 1)
1822c7c4e3dSmrg	    QuerySCCDataGray(dpy, RootWindow(dpy, DefaultScreen(dpy)));
1832c7c4e3dSmrg#endif /* GRAY */
1842c7c4e3dSmrg    }
1852c7c4e3dSmrg
1862c7c4e3dSmrg    if (remove) {
1872c7c4e3dSmrg	RemoveSCCData(dpy, RootWindow(dpy, DefaultScreen(dpy)), color);
1882c7c4e3dSmrg    }
1892c7c4e3dSmrg
1902c7c4e3dSmrg    XCloseDisplay(dpy);
1912c7c4e3dSmrg    exit (0);
1922c7c4e3dSmrg    /*NOTREACHED*/
1932c7c4e3dSmrg}
1942c7c4e3dSmrg
1952c7c4e3dSmrg
1962c7c4e3dSmrgstatic Atom
1972c7c4e3dSmrgParseAtom(Display *dpy, char *name, int only_flag)
1982c7c4e3dSmrg{
1992c7c4e3dSmrg    return(XInternAtom(dpy, name, only_flag));
2002c7c4e3dSmrg}
2012c7c4e3dSmrg
2022c7c4e3dSmrg
2032c7c4e3dSmrg/*
2042c7c4e3dSmrg *	NAME
2052c7c4e3dSmrg *		PrintTableType0
2062c7c4e3dSmrg *
2072c7c4e3dSmrg *	SYNOPSIS
2082c7c4e3dSmrg */
2092c7c4e3dSmrgstatic void
2102c7c4e3dSmrgPrintTableType0(int format, char **pChar, unsigned long *pCount)
2112c7c4e3dSmrg/*
2122c7c4e3dSmrg *	DESCRIPTION
2132c7c4e3dSmrg *
2142c7c4e3dSmrg *	RETURNS
2152c7c4e3dSmrg *		XcmsFailure if failed.
2162c7c4e3dSmrg *		XcmsSuccess if succeeded.
2172c7c4e3dSmrg *
2182c7c4e3dSmrg */
2192c7c4e3dSmrg{
2202c7c4e3dSmrg    unsigned int nElements;
2212c7c4e3dSmrg    unsigned short hValue;
2222c7c4e3dSmrg    XcmsFloat fValue;
2232c7c4e3dSmrg
2242c7c4e3dSmrg    nElements = _XcmsGetElement(format, pChar, pCount) + 1;
2252c7c4e3dSmrg    printf ("\t    length:%d\n", nElements);
2262c7c4e3dSmrg
2272c7c4e3dSmrg    switch (format) {
2282c7c4e3dSmrg      case 8:
2292c7c4e3dSmrg	while (nElements--) {
2302c7c4e3dSmrg	    /* 0xFFFF/0xFF = 0x101 */
2312c7c4e3dSmrg	    hValue = _XcmsGetElement (format, pChar, pCount) * 0x101;
2322c7c4e3dSmrg	    fValue = _XcmsGetElement (format, pChar, pCount)
2332c7c4e3dSmrg		    / (XcmsFloat)255.0;
2342c7c4e3dSmrg	    printf ("\t\t0x%x\t%8.5f\n", hValue, fValue);
2352c7c4e3dSmrg	}
2362c7c4e3dSmrg	break;
2372c7c4e3dSmrg      case 16:
2382c7c4e3dSmrg	while (nElements--) {
2392c7c4e3dSmrg	    hValue = _XcmsGetElement (format, pChar, pCount);
2402c7c4e3dSmrg	    fValue = _XcmsGetElement (format, pChar, pCount)
2412c7c4e3dSmrg		    / (XcmsFloat)65535.0;
2422c7c4e3dSmrg	    printf ("\t\t0x%x\t%8.5f\n", hValue, fValue);
2432c7c4e3dSmrg	}
2442c7c4e3dSmrg	break;
2452c7c4e3dSmrg      case 32:
2462c7c4e3dSmrg	while (nElements--) {
2472c7c4e3dSmrg	    hValue = _XcmsGetElement (format, pChar, pCount);
2482c7c4e3dSmrg	    fValue = _XcmsGetElement (format, pChar, pCount)
2492c7c4e3dSmrg		    / (XcmsFloat)4294967295.0;
2502c7c4e3dSmrg	    printf ("\t\t0x%x\t%8.5f\n", hValue, fValue);
2512c7c4e3dSmrg	}
2522c7c4e3dSmrg	break;
2532c7c4e3dSmrg      default:
2542c7c4e3dSmrg	return;
2552c7c4e3dSmrg    }
2562c7c4e3dSmrg}
2572c7c4e3dSmrg
2582c7c4e3dSmrg
2592c7c4e3dSmrg/*
2602c7c4e3dSmrg *	NAME
2612c7c4e3dSmrg *		PrintTableType1
2622c7c4e3dSmrg *
2632c7c4e3dSmrg *	SYNOPSIS
2642c7c4e3dSmrg */
2652c7c4e3dSmrgstatic void
2662c7c4e3dSmrgPrintTableType1(int format, char **pChar, unsigned long *pCount)
2672c7c4e3dSmrg/*
2682c7c4e3dSmrg *	DESCRIPTION
2692c7c4e3dSmrg *
2702c7c4e3dSmrg *	RETURNS
2712c7c4e3dSmrg *		XcmsFailure if failed.
2722c7c4e3dSmrg *		XcmsSuccess if succeeded.
2732c7c4e3dSmrg *
2742c7c4e3dSmrg */
2752c7c4e3dSmrg{
2762c7c4e3dSmrg    int count;
2772c7c4e3dSmrg    unsigned int max_index;
2782c7c4e3dSmrg    unsigned short hValue;
2792c7c4e3dSmrg    XcmsFloat fValue;
2802c7c4e3dSmrg
2812c7c4e3dSmrg    max_index = _XcmsGetElement(format, pChar, pCount);
2822c7c4e3dSmrg    printf ("\t    length:%d\n", max_index + 1);
2832c7c4e3dSmrg
2842c7c4e3dSmrg    switch (format) {
2852c7c4e3dSmrg      case 8:
2862c7c4e3dSmrg	for (count = 0; count < max_index+1; count++) {
2872c7c4e3dSmrg	    hValue = (count * 65535) / max_index;
2882c7c4e3dSmrg	    fValue = _XcmsGetElement (format, pChar, pCount)
2892c7c4e3dSmrg		    / (XcmsFloat)255.0;
2902c7c4e3dSmrg	    printf ("\t\t0x%x\t%8.5f\n", hValue, fValue);
2912c7c4e3dSmrg	}
2922c7c4e3dSmrg	break;
2932c7c4e3dSmrg      case 16:
2942c7c4e3dSmrg	for (count = 0; count < max_index+1; count++) {
2952c7c4e3dSmrg	    hValue = (count * 65535) / max_index;
2962c7c4e3dSmrg	    fValue = _XcmsGetElement (format, pChar, pCount)
2972c7c4e3dSmrg		    / (XcmsFloat)65535.0;
2982c7c4e3dSmrg	    printf ("\t\t0x%x\t%8.5f\n", hValue, fValue);
2992c7c4e3dSmrg	}
3002c7c4e3dSmrg	break;
3012c7c4e3dSmrg      case 32:
3022c7c4e3dSmrg	for (count = 0; count < max_index+1; count++) {
3032c7c4e3dSmrg	    hValue = (count * 65535) / max_index;
3042c7c4e3dSmrg	    fValue = _XcmsGetElement (format, pChar, pCount)
3052c7c4e3dSmrg		    / (XcmsFloat)4294967295.0;
3062c7c4e3dSmrg	    printf ("\t\t0x%x\t%8.5f\n", hValue, fValue);
3072c7c4e3dSmrg	}
3082c7c4e3dSmrg	break;
3092c7c4e3dSmrg      default:
3102c7c4e3dSmrg	return;
3112c7c4e3dSmrg    }
3122c7c4e3dSmrg}
3132c7c4e3dSmrg
3142c7c4e3dSmrg
3152c7c4e3dSmrg/*
3162c7c4e3dSmrg *      NAME
3172c7c4e3dSmrg *		QuerySCCData - Query for the SCC data on the root window
3182c7c4e3dSmrg *
3192c7c4e3dSmrg *      SYNOPSIS
3202c7c4e3dSmrg */
3212c7c4e3dSmrgstatic void
3222c7c4e3dSmrgQuerySCCDataRGB(Display *dpy, Window root)
3232c7c4e3dSmrg/*
3242c7c4e3dSmrg *      DESCRIPTION
3252c7c4e3dSmrg *
3262c7c4e3dSmrg *      RETURNS
3272c7c4e3dSmrg *		None
3282c7c4e3dSmrg */
3292c7c4e3dSmrg{
3302c7c4e3dSmrg    char *property_return, *pChar;
3312c7c4e3dSmrg    int  i, j;
3322c7c4e3dSmrg    int  count, format, cType, nTables;
3332c7c4e3dSmrg    unsigned long nitems, nbytes_return;
3342c7c4e3dSmrg    Atom MatricesAtom, CorrectAtom;
3352c7c4e3dSmrg    VisualID visualID;
3362c7c4e3dSmrg    XVisualInfo vinfo_template, *vinfo_ret;
3372c7c4e3dSmrg    int nvis;
3382c7c4e3dSmrg    static char *visual_strings[] = {
3392c7c4e3dSmrg	"StaticGray",
3402c7c4e3dSmrg	"GrayScale",
3412c7c4e3dSmrg	"StaticColor",
3422c7c4e3dSmrg	"PseudoColor",
3432c7c4e3dSmrg	"TrueColor",
3442c7c4e3dSmrg	"DirectColor"
3452c7c4e3dSmrg	};
3462c7c4e3dSmrg
3472c7c4e3dSmrg    /*
3482c7c4e3dSmrg     * Get Matrices
3492c7c4e3dSmrg     */
3502c7c4e3dSmrg    MatricesAtom = ParseAtom (dpy, XDCCC_MATRIX_ATOM_NAME, True);
3512c7c4e3dSmrg    if (MatricesAtom != None) {
3522c7c4e3dSmrg	if (_XcmsGetProperty (dpy, root, MatricesAtom, &format, &nitems,
3532c7c4e3dSmrg			  &nbytes_return, &property_return) == XcmsFailure) {
3542c7c4e3dSmrg	    format = 0;
3552c7c4e3dSmrg	} else if (nitems != 18) {
3562c7c4e3dSmrg	    printf ("Property %s had invalid length of %ld\n",
3572c7c4e3dSmrg		    XDCCC_MATRIX_ATOM_NAME, nitems);
3582c7c4e3dSmrg	    if (property_return) {
3592c7c4e3dSmrg		XFree (property_return);
3602c7c4e3dSmrg	    }
3612c7c4e3dSmrg	    return;
3622c7c4e3dSmrg	}
3632c7c4e3dSmrg    }
3642c7c4e3dSmrg    if (MatricesAtom == None || !format) {
3652c7c4e3dSmrg	printf ("Could not find property %s\n", XDCCC_MATRIX_ATOM_NAME);
3662c7c4e3dSmrg    } else if (format != 32) {
3672c7c4e3dSmrg	printf ("Data in property %s not in 32 bit format\n",
3682c7c4e3dSmrg		XDCCC_MATRIX_ATOM_NAME);
3692c7c4e3dSmrg    } else {
3702c7c4e3dSmrg	pChar = property_return;
3712c7c4e3dSmrg	printf ("Screen: %d\n", DefaultScreen(dpy));
3722c7c4e3dSmrg	printf ("Querying property %s\n", XDCCC_MATRIX_ATOM_NAME);
3732c7c4e3dSmrg	printf ("\tXYZtoRGB matrix :\n");
3742c7c4e3dSmrg	for (i = 0; i < 3; i++) {
3752c7c4e3dSmrg	    printf ("\t");
3762c7c4e3dSmrg	    for (j = 0; j < 3; j++) {
3772c7c4e3dSmrg		printf ("\t%8.5f",
3782c7c4e3dSmrg			(long)_XcmsGetElement(format, &pChar, &nitems)
3792c7c4e3dSmrg			/ (XcmsFloat) XDCCC_NUMBER);
3802c7c4e3dSmrg	    }
3812c7c4e3dSmrg	    printf ("\n");
3822c7c4e3dSmrg	}
3832c7c4e3dSmrg	printf ("\tRGBtoXYZ matrix :\n");
3842c7c4e3dSmrg	for (i = 0; i < 3; i++) {
3852c7c4e3dSmrg	    printf ("\t");
3862c7c4e3dSmrg	    for (j = 0; j < 3; j++) {
3872c7c4e3dSmrg		printf ("\t%8.5f",
3882c7c4e3dSmrg			(long) _XcmsGetElement(format, &pChar, &nitems)
3892c7c4e3dSmrg			/ (XcmsFloat) XDCCC_NUMBER);
3902c7c4e3dSmrg	    }
3912c7c4e3dSmrg	    printf ("\n");
3922c7c4e3dSmrg	}
3932c7c4e3dSmrg	XFree (property_return);
3942c7c4e3dSmrg    }
3952c7c4e3dSmrg
3962c7c4e3dSmrg
3972c7c4e3dSmrg    /*
3982c7c4e3dSmrg     * Get Intensity Tables
3992c7c4e3dSmrg     */
4002c7c4e3dSmrg    CorrectAtom = XInternAtom (dpy, XDCCC_CORRECT_ATOM_NAME, True);
4012c7c4e3dSmrg    if (CorrectAtom != None) {
4022c7c4e3dSmrg	if (_XcmsGetProperty (dpy, root, CorrectAtom, &format, &nitems,
4032c7c4e3dSmrg			  &nbytes_return, &property_return) == XcmsFailure) {
4042c7c4e3dSmrg	    format = 0;
4052c7c4e3dSmrg	} else if (nitems <= 0) {
4062c7c4e3dSmrg            printf ("Property %s had invalid length of %ld\n",
4072c7c4e3dSmrg		    XDCCC_CORRECT_ATOM_NAME, nitems);
4082c7c4e3dSmrg	    if (property_return) {
4092c7c4e3dSmrg		XFree (property_return);
4102c7c4e3dSmrg	    }
4112c7c4e3dSmrg	    return;
4122c7c4e3dSmrg	}
4132c7c4e3dSmrg    }
4142c7c4e3dSmrg    if (CorrectAtom == None || !format) {
4152c7c4e3dSmrg	printf ("Could not find property %s\n", XDCCC_CORRECT_ATOM_NAME);
4162c7c4e3dSmrg    } else {
4172c7c4e3dSmrg	printf ("\nQuerying property %s\n", XDCCC_CORRECT_ATOM_NAME);
4182c7c4e3dSmrg	pChar = property_return;
4192c7c4e3dSmrg
4202c7c4e3dSmrg	while (nitems) {
4212c7c4e3dSmrg	    switch (format) {
4222c7c4e3dSmrg	      case 8:
4232c7c4e3dSmrg		/*
4242c7c4e3dSmrg		 * Must have at least:
4252c7c4e3dSmrg		 *		VisualID0
4262c7c4e3dSmrg		 *		VisualID1
4272c7c4e3dSmrg		 *		VisualID2
4282c7c4e3dSmrg		 *		VisualID3
4292c7c4e3dSmrg		 *		type
4302c7c4e3dSmrg		 *		count
4312c7c4e3dSmrg		 *		length
4322c7c4e3dSmrg		 *		intensity1
4332c7c4e3dSmrg		 *		intensity2
4342c7c4e3dSmrg		 */
4352c7c4e3dSmrg		if (nitems < 9) {
4362c7c4e3dSmrg		    goto IntensityTblError;
4372c7c4e3dSmrg		}
4382c7c4e3dSmrg		count = 3;
4392c7c4e3dSmrg		break;
4402c7c4e3dSmrg	      case 16:
4412c7c4e3dSmrg		/*
4422c7c4e3dSmrg		 * Must have at least:
4432c7c4e3dSmrg		 *		VisualID0
4442c7c4e3dSmrg		 *		VisualID3
4452c7c4e3dSmrg		 *		type
4462c7c4e3dSmrg		 *		count
4472c7c4e3dSmrg		 *		length
4482c7c4e3dSmrg		 *		intensity1
4492c7c4e3dSmrg		 *		intensity2
4502c7c4e3dSmrg		 */
4512c7c4e3dSmrg		if (nitems < 7) {
4522c7c4e3dSmrg		    goto IntensityTblError;
4532c7c4e3dSmrg		}
4542c7c4e3dSmrg		count = 1;
4552c7c4e3dSmrg		break;
4562c7c4e3dSmrg	      case 32:
4572c7c4e3dSmrg		/*
4582c7c4e3dSmrg		 * Must have at least:
4592c7c4e3dSmrg		 *		VisualID0
4602c7c4e3dSmrg		 *		type
4612c7c4e3dSmrg		 *		count
4622c7c4e3dSmrg		 *		length
4632c7c4e3dSmrg		 *		intensity1
4642c7c4e3dSmrg		 *		intensity2
4652c7c4e3dSmrg		 */
4662c7c4e3dSmrg		if (nitems < 6) {
4672c7c4e3dSmrg		    goto IntensityTblError;
4682c7c4e3dSmrg		}
4692c7c4e3dSmrg		count = 0;
4702c7c4e3dSmrg		break;
4712c7c4e3dSmrg	      default:
4722c7c4e3dSmrg		goto IntensityTblError;
4732c7c4e3dSmrg	    }
4742c7c4e3dSmrg
4752c7c4e3dSmrg	    /*
4762c7c4e3dSmrg	     * Get VisualID
4772c7c4e3dSmrg	     */
4782c7c4e3dSmrg	    visualID = _XcmsGetElement(format, &pChar, &nitems);
4792c7c4e3dSmrg	    /* add the depth, class, and bits info in output */
4802c7c4e3dSmrg	    vinfo_template.visualid = visualID;
4812c7c4e3dSmrg	    vinfo_ret = XGetVisualInfo(dpy, VisualIDMask, &vinfo_template,
4822c7c4e3dSmrg				       &nvis);
4832c7c4e3dSmrg	    while (count--) {
4842c7c4e3dSmrg		visualID = visualID << format;
4852c7c4e3dSmrg		visualID |= _XcmsGetElement(format, &pChar, &nitems);
4862c7c4e3dSmrg	    }
4872c7c4e3dSmrg
4882c7c4e3dSmrg	    if (vinfo_ret != NULL) {
4892c7c4e3dSmrg		printf
4902c7c4e3dSmrg		 ("\n\tVisualID: 0x%lx class: %s depth: %d bits_per_rgb: %d\n",
4912c7c4e3dSmrg		  visualID, visual_strings[vinfo_ret->class],
4922c7c4e3dSmrg		  vinfo_ret->depth, vinfo_ret->bits_per_rgb);
4932c7c4e3dSmrg	    }
4942c7c4e3dSmrg	    else
4952c7c4e3dSmrg	    printf ("\n\tVisualID: 0x%lx\n", visualID);
4962c7c4e3dSmrg	    XFree(vinfo_ret);
4972c7c4e3dSmrg	    cType = _XcmsGetElement(format, &pChar, &nitems);
4982c7c4e3dSmrg	    printf ("\ttype: %d\n", cType);
4992c7c4e3dSmrg	    nTables = _XcmsGetElement(format, &pChar, &nitems);
5002c7c4e3dSmrg	    printf ("\tcount: %d\n", nTables);
5012c7c4e3dSmrg
5022c7c4e3dSmrg	    switch (cType) {
5032c7c4e3dSmrg	      case 0:
5042c7c4e3dSmrg		/* Red Table should always exist */
5052c7c4e3dSmrg		printf ("\tRed Conversion Table:\n");
5062c7c4e3dSmrg		PrintTableType0(format, &pChar, &nitems);
5072c7c4e3dSmrg		if (nTables > 1) {
5082c7c4e3dSmrg		    printf ("\tGreen Conversion Table:\n");
5092c7c4e3dSmrg		    PrintTableType0(format, &pChar, &nitems);
5102c7c4e3dSmrg		    printf ("\tBlue Conversion Table:\n");
5112c7c4e3dSmrg		    PrintTableType0(format, &pChar, &nitems);
5122c7c4e3dSmrg		}
5132c7c4e3dSmrg		break;
5142c7c4e3dSmrg	      case 1:
5152c7c4e3dSmrg		/* Red Table should always exist */
5162c7c4e3dSmrg		printf ("\tRed Conversion Table:\n");
5172c7c4e3dSmrg		PrintTableType1(format, &pChar, &nitems);
5182c7c4e3dSmrg		if (nTables > 1) {
5192c7c4e3dSmrg		    printf ("\tGreen Conversion Table:\n");
5202c7c4e3dSmrg		    PrintTableType1(format, &pChar, &nitems);
5212c7c4e3dSmrg		    printf ("\tBlue Conversion Table:\n");
5222c7c4e3dSmrg		    PrintTableType1(format, &pChar, &nitems);
5232c7c4e3dSmrg		}
5242c7c4e3dSmrg	        break;
5252c7c4e3dSmrg	      default:
5262c7c4e3dSmrg		goto IntensityTblError;
5272c7c4e3dSmrg	    }
5282c7c4e3dSmrg	}
5292c7c4e3dSmrg	XFree (property_return);
5302c7c4e3dSmrg    }
5312c7c4e3dSmrg    return;
5322c7c4e3dSmrg
5332c7c4e3dSmrgIntensityTblError:
5342c7c4e3dSmrg    XFree (property_return);
5352c7c4e3dSmrg    printf("Fatal error in %s property\n", XDCCC_CORRECT_ATOM_NAME);
5362c7c4e3dSmrg}
5372c7c4e3dSmrg
5382c7c4e3dSmrg
5392c7c4e3dSmrg#ifdef GRAY
5402c7c4e3dSmrg
5412c7c4e3dSmrg/*
5422c7c4e3dSmrg *      NAME
5432c7c4e3dSmrg *		QuerySCCDataGray - Query for the SCC data on the root window
5442c7c4e3dSmrg *
5452c7c4e3dSmrg *      SYNOPSIS
5462c7c4e3dSmrg */
5472c7c4e3dSmrgint
5482c7c4e3dSmrgQuerySCCDataGray(Display *dpy, Window root)
5492c7c4e3dSmrg/*
5502c7c4e3dSmrg *      DESCRIPTION
5512c7c4e3dSmrg *
5522c7c4e3dSmrg *      RETURNS
5532c7c4e3dSmrg *		None
5542c7c4e3dSmrg */
5552c7c4e3dSmrg{
5562c7c4e3dSmrg    char *property_return, *pChar;
5572c7c4e3dSmrg    int  j;
5582c7c4e3dSmrg    int  count, format, cType;
5592c7c4e3dSmrg    unsigned long  nitems, nbytes_return;
5602c7c4e3dSmrg    Atom MatricesAtom, CorrectAtom;
5612c7c4e3dSmrg    VisualID visualID;
5622c7c4e3dSmrg
5632c7c4e3dSmrg    MatricesAtom = ParseAtom (dpy, XDCCC_SCREENWHITEPT_ATOM_NAME, True);
5642c7c4e3dSmrg    if (MatricesAtom != None) {
5652c7c4e3dSmrg	if (_XcmsGetProperty (dpy, root, MatricesAtom, &format, &nitems,
5662c7c4e3dSmrg			  &nbytes_return, &property_return)  == XcmsFailure) {
5672c7c4e3dSmrg	    format = 0;
5682c7c4e3dSmrg	} else if (nitems != 3) {
5692c7c4e3dSmrg	    printf ("Property %s had invalid length of %d\n",
5702c7c4e3dSmrg		    XDCCC_SCREENWHITEPT_ATOM_NAME, nitems);
5712c7c4e3dSmrg	    if (property_return) {
5722c7c4e3dSmrg		XFree (property_return);
5732c7c4e3dSmrg	    }
5742c7c4e3dSmrg	    return;
5752c7c4e3dSmrg	}
5762c7c4e3dSmrg    }
5772c7c4e3dSmrg    if (MatricesAtom == None || !format) {
5782c7c4e3dSmrg	printf ("Could not find property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
5792c7c4e3dSmrg    } else {
5802c7c4e3dSmrg	pChar = property_return;
5812c7c4e3dSmrg	printf ("\nQuerying property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
5822c7c4e3dSmrg	printf ("\tWhite Point XYZ :\n");
5832c7c4e3dSmrg	printf ("\t");
5842c7c4e3dSmrg	for (j = 0; j < 3; j++) {
5852c7c4e3dSmrg	    printf ("\t%8.5lf",
5862c7c4e3dSmrg			(long) _XcmsGetElement(format, &pChar, &nitems) /
5872c7c4e3dSmrg			(XcmsFloat) XDCCC_NUMBER);
5882c7c4e3dSmrg	}
5892c7c4e3dSmrg	printf ("\n");
5902c7c4e3dSmrg	XFree (property_return);
5912c7c4e3dSmrg    }
5922c7c4e3dSmrg
5932c7c4e3dSmrg    CorrectAtom = XInternAtom (dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True);
5942c7c4e3dSmrg    if (CorrectAtom != None) {
5952c7c4e3dSmrg	if (_XcmsGetProperty (dpy, root, CorrectAtom, &format, &nitems,
5962c7c4e3dSmrg			  &nbytes_return, &property_return) == XcmsFailure) {
5972c7c4e3dSmrg	    format = 0;
5982c7c4e3dSmrg	} else if (nitems <= 0) {
5992c7c4e3dSmrg            printf ("Property %s had invalid length of %d\n",
6002c7c4e3dSmrg		    XDCCC_GRAY_CORRECT_ATOM_NAME, nitems);
6012c7c4e3dSmrg	    if (property_return) {
6022c7c4e3dSmrg		XFree (property_return);
6032c7c4e3dSmrg	    }
6042c7c4e3dSmrg	    return;
6052c7c4e3dSmrg	}
6062c7c4e3dSmrg    }
6072c7c4e3dSmrg    if (CorrectAtom == None || !format) {
6082c7c4e3dSmrg	printf ("Could not find property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME);
6092c7c4e3dSmrg    } else {
6102c7c4e3dSmrg	printf ("\nQuerying property %s\n\n", XDCCC_GRAY_CORRECT_ATOM_NAME);
6112c7c4e3dSmrg	pChar = property_return;
6122c7c4e3dSmrg
6132c7c4e3dSmrg	while (nitems) {
6142c7c4e3dSmrg	    switch (format) {
6152c7c4e3dSmrg	      case 8:
6162c7c4e3dSmrg		/*
6172c7c4e3dSmrg		 * Must have at least:
6182c7c4e3dSmrg		 *		VisualID0
6192c7c4e3dSmrg		 *		VisualID1
6202c7c4e3dSmrg		 *		VisualID2
6212c7c4e3dSmrg		 *		VisualID3
6222c7c4e3dSmrg		 *		type
6232c7c4e3dSmrg		 *		count
6242c7c4e3dSmrg		 *		length
6252c7c4e3dSmrg		 *		intensity1
6262c7c4e3dSmrg		 *		intensity2
6272c7c4e3dSmrg		 */
6282c7c4e3dSmrg		if (nitems < 9) {
6292c7c4e3dSmrg		    goto IntensityTblError;
6302c7c4e3dSmrg		}
6312c7c4e3dSmrg		count = 3;
6322c7c4e3dSmrg		break;
6332c7c4e3dSmrg	      case 16:
6342c7c4e3dSmrg		/*
6352c7c4e3dSmrg		 * Must have at least:
6362c7c4e3dSmrg		 *		VisualID0
6372c7c4e3dSmrg		 *		VisualID3
6382c7c4e3dSmrg		 *		type
6392c7c4e3dSmrg		 *		count
6402c7c4e3dSmrg		 *		length
6412c7c4e3dSmrg		 *		intensity1
6422c7c4e3dSmrg		 *		intensity2
6432c7c4e3dSmrg		 */
6442c7c4e3dSmrg		if (nitems < 7) {
6452c7c4e3dSmrg		    goto IntensityTblError;
6462c7c4e3dSmrg		}
6472c7c4e3dSmrg		count = 1;
6482c7c4e3dSmrg		break;
6492c7c4e3dSmrg	      case 32:
6502c7c4e3dSmrg		/*
6512c7c4e3dSmrg		 * Must have at least:
6522c7c4e3dSmrg		 *		VisualID0
6532c7c4e3dSmrg		 *		type
6542c7c4e3dSmrg		 *		count
6552c7c4e3dSmrg		 *		length
6562c7c4e3dSmrg		 *		intensity1
6572c7c4e3dSmrg		 *		intensity2
6582c7c4e3dSmrg		 */
6592c7c4e3dSmrg		if (nitems < 6) {
6602c7c4e3dSmrg		    goto IntensityTblError;
6612c7c4e3dSmrg		}
6622c7c4e3dSmrg		count = 0;
6632c7c4e3dSmrg		break;
6642c7c4e3dSmrg	      default:
6652c7c4e3dSmrg		goto IntensityTblError;
6662c7c4e3dSmrg		break;
6672c7c4e3dSmrg	    }
6682c7c4e3dSmrg
6692c7c4e3dSmrg	    /*
6702c7c4e3dSmrg	     * Get VisualID
6712c7c4e3dSmrg	     */
6722c7c4e3dSmrg	    visualID = _XcmsGetElement(format, &pChar, &nitems);
6732c7c4e3dSmrg	    while (count--) {
6742c7c4e3dSmrg		visualID = visualID << format;
6752c7c4e3dSmrg		visualID |= _XcmsGetElement(format, &pChar, &nitems);
6762c7c4e3dSmrg	    }
6772c7c4e3dSmrg
6782c7c4e3dSmrg	    printf ("\n\tVisualID: 0x%lx\n", visualID);
6792c7c4e3dSmrg	    cType = _XcmsGetElement(format, &pChar, &nitems);
6802c7c4e3dSmrg	    printf ("\ttype: %d\n", cType);
6812c7c4e3dSmrg	    printf ("\tGray Conversion Table:\n");
6822c7c4e3dSmrg	    switch (cType) {
6832c7c4e3dSmrg	      case 0:
6842c7c4e3dSmrg		PrintTableType0(format, &pChar, &nitems);
6852c7c4e3dSmrg		break;
6862c7c4e3dSmrg	      case 1:
6872c7c4e3dSmrg		PrintTableType1(format, &pChar, &nitems);
6882c7c4e3dSmrg		break;
6892c7c4e3dSmrg	      default:
6902c7c4e3dSmrg		goto IntensityTblError;
6912c7c4e3dSmrg	    }
6922c7c4e3dSmrg	}
6932c7c4e3dSmrg	XFree (property_return);
6942c7c4e3dSmrg    }
6952c7c4e3dSmrg    return;
6962c7c4e3dSmrgIntensityTblError:
6972c7c4e3dSmrg    XFree (property_return);
6982c7c4e3dSmrg    printf("Fatal error in %s property\n", XDCCC_CORRECT_ATOM_NAME);
6992c7c4e3dSmrg}
7002c7c4e3dSmrg#endif /* GRAY */
7012c7c4e3dSmrg
7022c7c4e3dSmrg
7032c7c4e3dSmrg/*
7042c7c4e3dSmrg *      NAME
7052c7c4e3dSmrg *		RemoveSCCData - Remove for the SCC data on the root window
7062c7c4e3dSmrg *
7072c7c4e3dSmrg *      SYNOPSIS
7082c7c4e3dSmrg */
7092c7c4e3dSmrgstatic void
7102c7c4e3dSmrgRemoveSCCData(Display *dpy, Window root, int colorFlag)
7112c7c4e3dSmrg/*
7122c7c4e3dSmrg *      DESCRIPTION
7132c7c4e3dSmrg *
7142c7c4e3dSmrg *      RETURNS
7152c7c4e3dSmrg *		None
7162c7c4e3dSmrg */
7172c7c4e3dSmrg{
7182c7c4e3dSmrg    unsigned char *ret_prop;
7192c7c4e3dSmrg    unsigned long ret_len, ret_after;
7202c7c4e3dSmrg    int  ret_format;
7212c7c4e3dSmrg    Atom MatricesAtom, CorrectAtom, ret_atom;
7222c7c4e3dSmrg
7232c7c4e3dSmrg    if (colorFlag != 0) {
7242c7c4e3dSmrg	MatricesAtom = ParseAtom (dpy, XDCCC_MATRIX_ATOM_NAME, True);
7252c7c4e3dSmrg	if (MatricesAtom != None) {
7262c7c4e3dSmrg	    XGetWindowProperty (dpy, root, MatricesAtom, 0, 8192, False,
7272c7c4e3dSmrg			XA_INTEGER, &ret_atom, &ret_format, &ret_len,
7282c7c4e3dSmrg			&ret_after, &ret_prop);
7292c7c4e3dSmrg	}
7302c7c4e3dSmrg	if (MatricesAtom == None || !ret_format) {
7312c7c4e3dSmrg	    printf ("Could not find property %s\n", XDCCC_MATRIX_ATOM_NAME);
7322c7c4e3dSmrg	} else {
7332c7c4e3dSmrg	    printf ("Deleting property %s\n", XDCCC_MATRIX_ATOM_NAME);
7342c7c4e3dSmrg	    XDeleteProperty (dpy, root, MatricesAtom);
7352c7c4e3dSmrg	    XFree ((char *)ret_prop);
7362c7c4e3dSmrg	}
7372c7c4e3dSmrg
7382c7c4e3dSmrg	CorrectAtom = XInternAtom (dpy, XDCCC_CORRECT_ATOM_NAME, True);
7392c7c4e3dSmrg	if (CorrectAtom != None) {
7402c7c4e3dSmrg	    XGetWindowProperty (dpy, root, CorrectAtom, 0, 8192, False,
7412c7c4e3dSmrg			XA_INTEGER, &ret_atom, &ret_format, &ret_len,
7422c7c4e3dSmrg			&ret_after, &ret_prop);
7432c7c4e3dSmrg	}
7442c7c4e3dSmrg	if (CorrectAtom == None || !ret_format) {
7452c7c4e3dSmrg	    printf ("Could not find property %s\n", XDCCC_CORRECT_ATOM_NAME);
7462c7c4e3dSmrg	} else {
7472c7c4e3dSmrg	    printf ("Deleting property %s\n", XDCCC_CORRECT_ATOM_NAME);
7482c7c4e3dSmrg	    XDeleteProperty (dpy, root, CorrectAtom);
7492c7c4e3dSmrg	    XFree ((char *)ret_prop);
7502c7c4e3dSmrg	}
7512c7c4e3dSmrg    }
7522c7c4e3dSmrg#ifdef GRAY
7532c7c4e3dSmrg    if (colorFlag != 1) {
7542c7c4e3dSmrg	MatricesAtom = ParseAtom (dpy, XDCCC_SCREENWHITEPT_ATOM_NAME, True);
7552c7c4e3dSmrg	if (MatricesAtom != None) {
7562c7c4e3dSmrg	    XGetWindowProperty (dpy, root, MatricesAtom, 0, 8192, False,
7572c7c4e3dSmrg			XA_INTEGER, &ret_atom, &ret_format, &ret_len,
7582c7c4e3dSmrg			&ret_after, &ret_prop);
7592c7c4e3dSmrg	}
7602c7c4e3dSmrg	if (MatricesAtom == None || !ret_format) {
7612c7c4e3dSmrg	    printf ("Could not find property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
7622c7c4e3dSmrg	} else {
7632c7c4e3dSmrg	    printf ("Deleting property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
7642c7c4e3dSmrg	    XDeleteProperty (dpy, root, MatricesAtom);
7652c7c4e3dSmrg	    XFree ((char *)ret_prop);
7662c7c4e3dSmrg	}
7672c7c4e3dSmrg
7682c7c4e3dSmrg	CorrectAtom = XInternAtom (dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True);
7692c7c4e3dSmrg	if (CorrectAtom != None) {
7702c7c4e3dSmrg	    XGetWindowProperty (dpy, root, CorrectAtom, 0, 8192, False,
7712c7c4e3dSmrg			XA_INTEGER, &ret_atom, &ret_format, &ret_len,
7722c7c4e3dSmrg			&ret_after, &ret_prop);
7732c7c4e3dSmrg	}
7742c7c4e3dSmrg	if (CorrectAtom == None || !ret_format) {
7752c7c4e3dSmrg	    printf ("Could not find property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME);
7762c7c4e3dSmrg	} else {
7772c7c4e3dSmrg	    printf ("Deleting property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME);
7782c7c4e3dSmrg	    XDeleteProperty (dpy, root, CorrectAtom);
7792c7c4e3dSmrg	    XFree ((char *)ret_prop);
7802c7c4e3dSmrg	}
7812c7c4e3dSmrg    }
7822c7c4e3dSmrg#endif /* GRAY */
7832c7c4e3dSmrg}
7842c7c4e3dSmrg
7852c7c4e3dSmrgstatic unsigned long
7862c7c4e3dSmrg_XcmsGetElement(int format, char **pValue, unsigned long *pCount)
7872c7c4e3dSmrg/*
7882c7c4e3dSmrg *	DESCRIPTION
7892c7c4e3dSmrg *	    Get the next element from the property and return it.
7902c7c4e3dSmrg *	    Also increment the pointer the amount needed.
7912c7c4e3dSmrg *
7922c7c4e3dSmrg *	Returns
7932c7c4e3dSmrg *	    unsigned long
7942c7c4e3dSmrg */
7952c7c4e3dSmrg{
7962c7c4e3dSmrg    unsigned long value;
7972c7c4e3dSmrg
7982c7c4e3dSmrg    switch (format) {
7992c7c4e3dSmrg      case 32:
8002c7c4e3dSmrg	value = *((unsigned long *)(*pValue)) & 0xFFFFFFFF;
8012c7c4e3dSmrg	*pValue += sizeof(unsigned long);
8022c7c4e3dSmrg	*pCount -= 1;
8032c7c4e3dSmrg	break;
8042c7c4e3dSmrg      case 16:
8052c7c4e3dSmrg	value = *((unsigned short *)(*pValue));
8062c7c4e3dSmrg	*pValue += sizeof(unsigned short);
8072c7c4e3dSmrg	*pCount -= 1;
8082c7c4e3dSmrg	break;
8092c7c4e3dSmrg      case 8:
8102c7c4e3dSmrg	value = *((unsigned char *) (*pValue));
8112c7c4e3dSmrg	*pValue += 1;
8122c7c4e3dSmrg	*pCount -= 1;
8132c7c4e3dSmrg	break;
8142c7c4e3dSmrg      default:
8152c7c4e3dSmrg	value = 0;
8162c7c4e3dSmrg	break;
8172c7c4e3dSmrg    }
8182c7c4e3dSmrg    return(value);
8192c7c4e3dSmrg}
8202c7c4e3dSmrg
8212c7c4e3dSmrg
8222c7c4e3dSmrg/*
8232c7c4e3dSmrg *	NAME
8242c7c4e3dSmrg *		_XcmsGetProperty -- Determine the existance of a property
8252c7c4e3dSmrg *
8262c7c4e3dSmrg *	SYNOPSIS
8272c7c4e3dSmrg */
8282c7c4e3dSmrgstatic int
8292c7c4e3dSmrg_XcmsGetProperty(Display *pDpy, Window w, Atom property, int *pFormat,
8302c7c4e3dSmrg		 unsigned long *pNItems, unsigned long *pNBytes,
8312c7c4e3dSmrg		 char **pValue)
8322c7c4e3dSmrg/*
8332c7c4e3dSmrg *	DESCRIPTION
8342c7c4e3dSmrg *
8352c7c4e3dSmrg *	Returns
8362c7c4e3dSmrg *	    0 if property does not exist.
8372c7c4e3dSmrg *	    1 if property exists.
8382c7c4e3dSmrg */
8392c7c4e3dSmrg{
8402c7c4e3dSmrg    char *prop_ret;
8412c7c4e3dSmrg    int format_ret;
8422c7c4e3dSmrg    long len = 6516;
8432c7c4e3dSmrg    unsigned long nitems_ret, after_ret;
8442c7c4e3dSmrg    Atom atom_ret;
8452c7c4e3dSmrg
8462c7c4e3dSmrg    while (XGetWindowProperty (pDpy, w, property, 0, len, False,
8472c7c4e3dSmrg			       XA_INTEGER, &atom_ret, &format_ret,
8482c7c4e3dSmrg			       &nitems_ret, &after_ret,
8492c7c4e3dSmrg			       (unsigned char **)&prop_ret)) {
8502c7c4e3dSmrg	if (after_ret > 0) {
8512c7c4e3dSmrg	    len += nitems_ret * (format_ret >> 3);
8522c7c4e3dSmrg	    XFree (prop_ret);
8532c7c4e3dSmrg	} else {
8542c7c4e3dSmrg	    break;
8552c7c4e3dSmrg	}
8562c7c4e3dSmrg    }
8572c7c4e3dSmrg    if (format_ret == 0 || nitems_ret == 0) {
8582c7c4e3dSmrg	/* the property does not exist or is of an unexpected type */
8592c7c4e3dSmrg	return(XcmsFailure);
8602c7c4e3dSmrg    }
8612c7c4e3dSmrg
8622c7c4e3dSmrg    *pFormat = format_ret;
8632c7c4e3dSmrg    *pNItems = nitems_ret;
8642c7c4e3dSmrg    *pNBytes = nitems_ret * (format_ret >> 3);
8652c7c4e3dSmrg    *pValue = prop_ret;
8662c7c4e3dSmrg    return(XcmsSuccess);
8672c7c4e3dSmrg}
868