home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / xcmsdb / xcmsdb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-22  |  20.1 KB  |  884 lines

  1. /* $XConsortium: xcmsdb.c,v 1.7 91/07/22 17:23:15 rws Exp $ */
  2.  
  3. /*
  4.  * (c) Copyright 1990 Tektronix Inc.
  5.  *     All Rights Reserved
  6.  *
  7.  * Permission to use, copy, modify, and distribute this software and its
  8.  * documentation for any purpose and without fee is hereby granted,
  9.  * provided that the above copyright notice appear in all copies and that
  10.  * both that copyright notice and this permission notice appear in
  11.  * supporting documentation, and that the name of Tektronix not be used
  12.  * in advertising or publicity pertaining to distribution of the software
  13.  * without specific, written prior permission.
  14.  *
  15.  * Tektronix disclaims all warranties with regard to this software, including
  16.  * all implied warranties of merchantability and fitness, in no event shall
  17.  * Tektronix be liable for any special, indirect or consequential damages or
  18.  * any damages whatsoever resulting from loss of use, data or profits,
  19.  * whether in an action of contract, negligence or other tortious action,
  20.  * arising out of or in connection with the use or performance of this
  21.  * software.
  22.  *
  23.  *
  24.  *    NAME
  25.  *        xcmsdb.c
  26.  *
  27.  *    DESCRIPTION
  28.  *        Program to load, query or remove the Screen Color 
  29.  *        Characterization Data from the root window of the screen.
  30.  *
  31.  */
  32.  
  33. /*
  34.  *      INCLUDES
  35.  */
  36.  
  37. #include <stdio.h>
  38. #include <X11/Xlib.h>
  39. #include <X11/Xatom.h>
  40. #include <X11/Xos.h>
  41. #include <ctype.h>
  42.  
  43. #include "Xcmsint.h"
  44. #include "SCCDFile.h"
  45.  
  46. #ifdef CRAY
  47. #define WORD64
  48. #endif
  49.  
  50. static unsigned long _XcmsGetElement();
  51. static int _XcmsGetProperty();
  52.  
  53. char *ProgramName;
  54.  
  55. void Syntax ()
  56. {
  57.     fprintf (stderr, 
  58.          "usage:  %s [-options ...] [filename]\n\n",
  59.          ProgramName);
  60.     fprintf (stderr, 
  61.          "where options include:\n");
  62.     fprintf (stderr, 
  63.          "    -display host:dpy[.scrn]     display to use\n");
  64.     fprintf (stderr, 
  65.          "    -format [ 32 | 16 | 8 ]      property format\n");
  66.     fprintf (stderr, 
  67.          "    -query                       query Screen Color Characterization Data\n");
  68.     fprintf (stderr, 
  69.          "    -remove                      remove Screen Color Characterization Data\n");
  70.     fprintf (stderr, 
  71.          "    -color                       use color as def<ault\n");
  72. #ifdef GRAY
  73.     fprintf (stderr, 
  74.          "    -gray                        use gray-scale as default\n");
  75. #endif /* GRAY */
  76.     fprintf (stderr, 
  77.          "\n");
  78.     exit (1);
  79. }
  80.  
  81. static Bool optionmatch (opt, arg, minlen)
  82.     char *opt;
  83.     char *arg;
  84.     int minlen;
  85. {
  86.     int arglen;
  87.  
  88.     if (strcmp(opt, arg) == 0) {
  89.     return(True);
  90.     }
  91.  
  92.     if ((arglen = strlen(arg)) >= (int)strlen(opt) || arglen < minlen) {
  93.     return(False);
  94.     }
  95.  
  96.     if (strncmp (opt, arg, arglen) == 0) {
  97.     return(True);
  98.     }
  99.     
  100.     return(False);
  101. }
  102.  
  103. main (argc, argv)
  104.     int argc;
  105.     char **argv;
  106. {
  107.     Display *dpy;
  108.     int i;
  109.     char *displayname = NULL;
  110.     char *filename = NULL;
  111.     int query = 0;
  112.     int remove = 0;
  113.     int load = 0;
  114.     int color = -1;
  115.     int targetFormat = 32;
  116.  
  117.     ProgramName = argv[0];
  118.  
  119.     for (i = 1; i < argc; i++) {
  120.     char *arg = argv[i];
  121.  
  122.     if (arg[0] == '-') {
  123.         if (arg[1] == '\0') {
  124.         filename = NULL;
  125.         continue;
  126.         } else if (optionmatch ("-help", arg, 1)) {
  127.         Syntax ();
  128.         /* doesn't return */
  129.         } else if (optionmatch ("-display", arg, 1)) {
  130.         if (++i >= argc) Syntax ();
  131.         displayname = argv[i];
  132.         continue;
  133.         } else if (optionmatch ("-format", arg, 1)) {
  134.         if (++i >= argc) Syntax ();
  135.         targetFormat = atoi(argv[i]);
  136.         if (targetFormat != 32 && targetFormat != 16 &&
  137.             targetFormat != 8) Syntax();
  138.         continue;
  139.         } else if (optionmatch ("-query", arg, 1)) {
  140.         query = 1;
  141.         continue;
  142.         } else if (optionmatch ("-remove", arg, 1)) {
  143.         remove = 1;
  144.         continue;
  145.         } else if (optionmatch ("-color", arg, 1)) {
  146.         color = 1;
  147.         continue;
  148. #ifdef GRAY
  149.         } else if (optionmatch ("-gray", arg, 1)) {
  150.         color = 0;
  151.         continue;
  152. #endif /* GRAY */
  153.         }
  154.         Syntax ();
  155.     } else {
  156.         load = 1;
  157.         filename = arg;
  158.     }
  159.     }
  160.  
  161.     /* Open display  */ 
  162.     if (!(dpy = XOpenDisplay (displayname))) {
  163.       fprintf (stderr, "%s:  Can't open display '%s'\n",
  164.            ProgramName, XDisplayName(displayname));
  165.       exit (1);
  166.     }
  167.  
  168.     if (load && query) {
  169.     load = 0;
  170.     }
  171.     if (load && remove) {
  172.     load = 0;
  173.     }
  174.  
  175.     if (!query && !remove) {
  176.     LoadSCCData(dpy, DefaultScreen(dpy), filename, targetFormat);
  177.     }
  178.  
  179.     if (query) {
  180.     if (color != 0)
  181.         QuerySCCDataRGB(dpy, RootWindow(dpy, DefaultScreen(dpy)));
  182. #ifdef GRAY
  183.     if (color != 1)
  184.         QuerySCCDataGray(dpy, RootWindow(dpy, DefaultScreen(dpy)));
  185. #endif /* GRAY */
  186.     }
  187.  
  188.     if (remove) {
  189.     RemoveSCCData(dpy, RootWindow(dpy, DefaultScreen(dpy)), color);
  190.     }
  191.  
  192.     XCloseDisplay(dpy);
  193.     exit (0);
  194.     /*NOTREACHED*/
  195. }
  196.  
  197.  
  198. Atom
  199. ParseAtom (dpy, name, only_flag)
  200.     Display *dpy;
  201.     char    *name;
  202.     int     only_flag;
  203. {
  204.     return(XInternAtom(dpy, name, only_flag));
  205. }
  206.  
  207.  
  208. /*
  209.  *    NAME
  210.  *        PrintTableType0
  211.  *
  212.  *    SYNOPSIS
  213.  */
  214. static void
  215. PrintTableType0(format, pChar, pCount)
  216.     int      format;
  217.     char **pChar;
  218.     unsigned long *pCount;
  219. /*
  220.  *    DESCRIPTION
  221.  *
  222.  *    RETURNS
  223.  *        XcmsFailure if failed.
  224.  *        XcmsSuccess if succeeded.
  225.  *
  226.  */
  227. {
  228.     unsigned int nElements;
  229.     unsigned short hValue;
  230.     XcmsFloat fValue;
  231.  
  232.     nElements = _XcmsGetElement(format, pChar, pCount) + 1;
  233.     printf ("\t    length:%d\n", nElements);
  234.  
  235.     switch (format) {
  236.       case 8:
  237.     while (nElements--) {
  238.         /* 0xFFFF/0xFF = 0x101 */
  239.         hValue = _XcmsGetElement (format, pChar, pCount) * 0x101;
  240.         fValue = _XcmsGetElement (format, pChar, pCount)
  241.             / (XcmsFloat)255.0;
  242.         printf ("\t\t0x%x\t%8.5lf\n", hValue, fValue);
  243.     }
  244.     break;
  245.       case 16:
  246.     while (nElements--) {
  247.         hValue = (unsigned short)_XcmsGetElement (format, pChar, pCount);
  248.         fValue = _XcmsGetElement (format, pChar, pCount)
  249.             / (XcmsFloat)65535.0;
  250.         printf ("\t\t0x%x\t%8.5lf\n", hValue, fValue);
  251.     }
  252.     break;
  253.       case 32:
  254.     while (nElements--) {
  255.         hValue = (unsigned short)_XcmsGetElement (format, pChar, pCount);
  256.         fValue = _XcmsGetElement (format, pChar, pCount)
  257.             / (XcmsFloat)4294967295.0;
  258.         printf ("\t\t0x%x\t%8.5lf\n", hValue, fValue);
  259.     }
  260.     break;
  261.       default:
  262.     return;
  263.     }
  264. }
  265.  
  266.  
  267. /*
  268.  *    NAME
  269.  *        PrintTableType1
  270.  *
  271.  *    SYNOPSIS
  272.  */
  273. static void
  274. PrintTableType1(format, pChar, pCount)
  275.     int      format;
  276.     char **pChar;
  277.     unsigned long *pCount;
  278. /*
  279.  *    DESCRIPTION
  280.  *
  281.  *    RETURNS
  282.  *        XcmsFailure if failed.
  283.  *        XcmsSuccess if succeeded.
  284.  *
  285.  */
  286. {
  287.     int count;
  288.     unsigned int max_index;
  289.     unsigned short hValue;
  290.     XcmsFloat fValue;
  291.  
  292.     max_index = _XcmsGetElement(format, pChar, pCount);
  293.     printf ("\t    length:%d\n", max_index + 1);
  294.  
  295.     switch (format) {
  296.       case 8:
  297.     for (count = 0; count < max_index+1; count++) {
  298.         hValue = (count * 65535) / max_index;
  299.         fValue = _XcmsGetElement (format, pChar, pCount)
  300.             / (XcmsFloat)255.0;
  301.         printf ("\t\t0x%x\t%8.5lf\n", hValue, fValue);
  302.     }
  303.     break;
  304.       case 16:
  305.     for (count = 0; count < max_index+1; count++) {
  306.         hValue = (count * 65535) / max_index;
  307.         fValue = _XcmsGetElement (format, pChar, pCount)
  308.             / (XcmsFloat)65535.0;
  309.         printf ("\t\t0x%x\t%8.5lf\n", hValue, fValue);
  310.     }
  311.     break;
  312.       case 32:
  313.     for (count = 0; count < max_index+1; count++) {
  314.         hValue = (count * 65535) / max_index;
  315.         fValue = _XcmsGetElement (format, pChar, pCount)
  316.             / (XcmsFloat)4294967295.0;
  317.         printf ("\t\t0x%x\t%8.5lf\n", hValue, fValue);
  318.     }
  319.     break;
  320.       default:
  321.     return;
  322.     }
  323. }
  324.  
  325.  
  326. /*
  327.  *      NAME
  328.  *        QuerySCCData - Query for the SCC data on the root window
  329.  *
  330.  *      SYNOPSIS
  331.  */
  332. int
  333. QuerySCCDataRGB(dpy, root)
  334.     Display *dpy;
  335.     Window  root;
  336. /*
  337.  *      DESCRIPTION
  338.  *
  339.  *      RETURNS
  340.  *        None
  341.  */
  342. {
  343.     char *property_return, *pChar;
  344.     int  i, j;
  345.     int  count, format, cType, nTables;
  346.     unsigned long nitems, nbytes_return;
  347.     Atom MatricesAtom, CorrectAtom;
  348.     VisualID visualID;
  349.  
  350.     /*
  351.      * Get Matrices
  352.      */
  353.     MatricesAtom = ParseAtom (dpy, XDCCC_MATRIX_ATOM_NAME, True);
  354.     if (MatricesAtom != None) {
  355.     if (_XcmsGetProperty (dpy, root, MatricesAtom, &format, &nitems,
  356.               &nbytes_return, &property_return) == XcmsFailure) {
  357.         format = 0;
  358.     } else if (nitems != 18) {
  359.         printf ("Property %s had invalid length of %d\n",
  360.             XDCCC_MATRIX_ATOM_NAME, nitems);
  361.         if (property_return) {
  362.         XFree (property_return);
  363.         }
  364.         return;
  365.     }
  366.     } 
  367.     if (MatricesAtom == None || !format) {
  368.     printf ("Could not find property %s\n", XDCCC_MATRIX_ATOM_NAME);
  369.     } else if (format != 32) {
  370.     printf ("Data in property %s not in 32 bit format\n",
  371.         XDCCC_MATRIX_ATOM_NAME);
  372.     } else {
  373.     pChar = property_return;
  374.     printf ("Querying property %s\n", XDCCC_MATRIX_ATOM_NAME);
  375.     printf ("\tXYZtoRGB matrix :\n");
  376.     for (i = 0; i < 3; i++) {
  377.         printf ("\t");
  378.         for (j = 0; j < 3; j++) {
  379.         printf ("\t%8.5lf", 
  380.             (long)_XcmsGetElement(format, &pChar, &nitems)
  381.             / (XcmsFloat) XDCCC_NUMBER);
  382.         }
  383.         printf ("\n");
  384.     }
  385.     printf ("\tRGBtoXYZ matrix :\n");
  386.     for (i = 0; i < 3; i++) {
  387.         printf ("\t");
  388.         for (j = 0; j < 3; j++) {
  389.         printf ("\t%8.5lf", 
  390.             (long) _XcmsGetElement(format, &pChar, &nitems)
  391.             / (XcmsFloat) XDCCC_NUMBER);
  392.         }
  393.         printf ("\n");
  394.     }
  395.     XFree (property_return);
  396.     }
  397.  
  398.  
  399.     /*
  400.      * Get Intensity Tables
  401.      */
  402.     CorrectAtom = XInternAtom (dpy, XDCCC_CORRECT_ATOM_NAME, True);
  403.     if (CorrectAtom != None) {
  404.     if (_XcmsGetProperty (dpy, root, CorrectAtom, &format, &nitems,
  405.               &nbytes_return, &property_return) == XcmsFailure) {
  406.         format = 0;
  407.     } else if (nitems <= 0) {
  408.             printf ("Property %s had invalid length of %d\n",
  409.             XDCCC_CORRECT_ATOM_NAME, nitems);
  410.         if (property_return) {
  411.         XFree (property_return);
  412.         }
  413.         return;
  414.     }
  415.     }
  416.     if (CorrectAtom == None || !format) {
  417.     printf ("Could not find property %s\n", XDCCC_CORRECT_ATOM_NAME);
  418.     } else {
  419.     printf ("Querying property %s\n", XDCCC_CORRECT_ATOM_NAME);
  420.     pChar = property_return;
  421.  
  422.     while (nitems) {
  423.         switch (format) {
  424.           case 8:
  425.         /*
  426.          * Must have at least:
  427.          *        VisualID0
  428.          *        VisualID1
  429.          *        VisualID2
  430.          *        VisualID3
  431.          *        type
  432.          *        count
  433.          *        length
  434.          *        intensity1
  435.          *        intensity2
  436.          */
  437.         if (nitems < 9) {
  438.             goto IntensityTblError;
  439.         }
  440.         count = 3;
  441.         break;
  442.           case 16:
  443.         /*
  444.          * Must have at least:
  445.          *        VisualID0
  446.          *        VisualID3
  447.          *        type
  448.          *        count
  449.          *        length
  450.          *        intensity1
  451.          *        intensity2
  452.          */
  453.         if (nitems < 7) {
  454.             goto IntensityTblError;
  455.         }
  456.         count = 1;
  457.         break;
  458.           case 32:
  459.         /*
  460.          * Must have at least:
  461.          *        VisualID0
  462.          *        type
  463.          *        count
  464.          *        length
  465.          *        intensity1
  466.          *        intensity2
  467.          */
  468.         if (nitems < 6) {
  469.             goto IntensityTblError;
  470.         }
  471.         count = 0;
  472.         break;
  473.           default:
  474.         goto IntensityTblError;
  475.         break;
  476.         }
  477.  
  478.         /*
  479.          * Get VisualID
  480.          */
  481.         visualID = _XcmsGetElement(format, &pChar, &nitems);
  482.         while (count--) {
  483.         visualID = visualID << format;
  484.         visualID |= _XcmsGetElement(format, &pChar, &nitems);
  485.         }
  486.  
  487.         printf ("\tVisualID: %ld\n", visualID);
  488.         cType = (int)_XcmsGetElement(format, &pChar, &nitems);
  489.         printf ("\ttype: %d\n", cType);
  490.         nTables = (int)_XcmsGetElement(format, &pChar, &nitems);
  491.         printf ("\tcount: %d\n", nTables);
  492.  
  493.         switch (cType) {
  494.           case 0:
  495.         /* Red Table should always exist */
  496.         printf ("\tRed Conversion Table:\n");
  497.         PrintTableType0(format, &pChar, &nitems);
  498.         if (nTables > 1) {
  499.             printf ("\tGreen Conversion Table:\n");
  500.             PrintTableType0(format, &pChar, &nitems);
  501.             printf ("\tBlue Conversion Table:\n");
  502.             PrintTableType0(format, &pChar, &nitems);
  503.         }
  504.         break;
  505.           case 1:
  506.         /* Red Table should always exist */
  507.         printf ("\tRed Conversion Table:\n");
  508.         PrintTableType1(format, &pChar, &nitems);
  509.         if (nTables > 1) {
  510.             printf ("\tGreen Conversion Table:\n");
  511.             PrintTableType1(format, &pChar, &nitems);
  512.             printf ("\tBlue Conversion Table:\n");
  513.             PrintTableType1(format, &pChar, &nitems);
  514.         }
  515.             break;
  516.           default:
  517.         goto IntensityTblError;
  518.         }
  519.         XFree (property_return);
  520.     }    
  521.     }    
  522.     return;
  523.  
  524. IntensityTblError:
  525.     XFree (property_return);
  526.     printf("Fatal error in %s property\n", XDCCC_CORRECT_ATOM_NAME);
  527. }
  528.  
  529.  
  530. #ifdef GRAY
  531.  
  532. /*
  533.  *      NAME
  534.  *        QuerySCCDataGray - Query for the SCC data on the root window
  535.  *
  536.  *      SYNOPSIS
  537.  */
  538. int
  539. QuerySCCDataGray(dpy, root)
  540.     Display *dpy;
  541.     Window  root;
  542. /*
  543.  *      DESCRIPTION
  544.  *
  545.  *      RETURNS
  546.  *        None
  547.  */
  548. {
  549.     char *property_return, *pChar;
  550.     int  j;
  551.     int  count, format, cType;
  552.     unsigned long  nitems, nbytes_return;
  553.     Atom MatricesAtom, CorrectAtom;
  554.     VisualID visualID;
  555.  
  556.     MatricesAtom = ParseAtom (dpy, XDCCC_SCREENWHITEPT_ATOM_NAME, True);
  557.     if (MatricesAtom != None) {
  558.     if (_XcmsGetProperty (dpy, root, MatricesAtom, &format, &nitems,
  559.               &nbytes_return, &property_return)  == XcmsFailure) {
  560.         format = 0;
  561.     } else if (nitems != 3) {
  562.         printf ("Property %s had invalid length of %d\n",
  563.             XDCCC_SCREENWHITEPT_ATOM_NAME, nitems);
  564.         if (property_return) {
  565.         XFree (property_return);
  566.         }
  567.         return;
  568.     }
  569.     } 
  570.     if (MatricesAtom == None || !format) {
  571.     printf ("Could not find property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
  572.     } else {
  573.     pChar = property_return;
  574.     printf ("Querying property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
  575.     printf ("\tWhite Point XYZ :\n");
  576.     printf ("\t");
  577.     for (j = 0; j < 3; j++) {
  578.         printf ("\t%8.5lf", 
  579.             (long) _XcmsGetElement(format, &pChar, &nitems) / 
  580.             (XcmsFloat) XDCCC_NUMBER);
  581.     }
  582.     printf ("\n");
  583.     XFree (property_return);
  584.     }
  585.  
  586.     CorrectAtom = XInternAtom (dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True);
  587.     if (CorrectAtom != None) {
  588.     if (_XcmsGetProperty (dpy, root, CorrectAtom, &format, &nitems,
  589.               &nbytes_return, &property_return) == XcmsFailure) {
  590.         format = 0;
  591.     } else if (nitems <= 0) {
  592.             printf ("Property %s had invalid length of %d\n",
  593.             XDCCC_GRAY_CORRECT_ATOM_NAME, nitems);
  594.         if (property_return) {
  595.         XFree (property_return);
  596.         }
  597.         return;
  598.     }
  599.     }
  600.     if (CorrectAtom == None || !format) {
  601.     printf ("Could not find property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME);
  602.     } else {
  603.     printf ("Querying property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME);
  604.     pChar = property_return;
  605.  
  606.     while (nitems) {
  607.         switch (format) {
  608.           case 8:
  609.         /*
  610.          * Must have at least:
  611.          *        VisualID0
  612.          *        VisualID1
  613.          *        VisualID2
  614.          *        VisualID3
  615.          *        type
  616.          *        count
  617.          *        length
  618.          *        intensity1
  619.          *        intensity2
  620.          */
  621.         if (nitems < 9) {
  622.             goto IntensityTblError;
  623.         }
  624.         count = 3;
  625.         break;
  626.           case 16:
  627.         /*
  628.          * Must have at least:
  629.          *        VisualID0
  630.          *        VisualID3
  631.          *        type
  632.          *        count
  633.          *        length
  634.          *        intensity1
  635.          *        intensity2
  636.          */
  637.         if (nitems < 7) {
  638.             goto IntensityTblError;
  639.         }
  640.         count = 1;
  641.         break;
  642.           case 32:
  643.         /*
  644.          * Must have at least:
  645.          *        VisualID0
  646.          *        type
  647.          *        count
  648.          *        length
  649.          *        intensity1
  650.          *        intensity2
  651.          */
  652.         if (nitems < 6) {
  653.             goto IntensityTblError;
  654.         }
  655.         count = 0;
  656.         break;
  657.           default:
  658.         goto IntensityTblError;
  659.         break;
  660.         }
  661.  
  662.         /*
  663.          * Get VisualID
  664.          */
  665.         visualID = _XcmsGetElement(format, &pChar, &nitems);
  666.         while (count--) {
  667.         visualID = visualID << format;
  668.         visualID |= _XcmsGetElement(format, &pChar, &nitems);
  669.         }
  670.  
  671.         printf ("\tVisualID: %ld\n", visualID);
  672.         cType = (int)_XcmsGetElement(format, &pChar, &nitems);
  673.         printf ("\ttype: %d\n", cType);
  674.         printf ("\tGray Conversion Table:\n");
  675.         switch (cType) {
  676.           case 0:
  677.         PrintTableType0(format, &pChar, &nitems);
  678.         break;
  679.           case 1:
  680.         PrintTableType1(format, &pChar, &nitems);
  681.         break;
  682.           default:
  683.         goto IntensityTblError;
  684.         }
  685.     }    
  686.     XFree (property_return);
  687.     }    
  688.     return;
  689. IntensityTblError:
  690.     XFree (property_return);
  691.     printf("Fatal error in %s property\n", XDCCC_CORRECT_ATOM_NAME);
  692. }
  693. #endif /* GRAY */
  694.  
  695.  
  696. /*
  697.  *      NAME
  698.  *        RemoveSCCData - Remove for the SCC data on the root window
  699.  *
  700.  *      SYNOPSIS
  701.  */
  702. int
  703. RemoveSCCData(dpy, root, colorFlag)
  704.     Display *dpy;
  705.     Window  root;
  706.     int     colorFlag;
  707. /*
  708.  *      DESCRIPTION
  709.  *
  710.  *      RETURNS
  711.  *        None
  712.  */
  713. {
  714.     unsigned char *ret_prop;
  715.     unsigned long ret_len, ret_after;
  716.     int  ret_format;
  717.     Atom MatricesAtom, CorrectAtom, ret_atom;
  718.  
  719.     if (colorFlag != 0) {
  720.     MatricesAtom = ParseAtom (dpy, XDCCC_MATRIX_ATOM_NAME, True);
  721.     if (MatricesAtom != None) {
  722.         XGetWindowProperty (dpy, root, MatricesAtom, 0, 8192, False,
  723.             XA_INTEGER, &ret_atom, &ret_format, &ret_len, 
  724.             &ret_after, &ret_prop);
  725.     } 
  726.     if (MatricesAtom == None || !ret_format) {
  727.         printf ("Could not find property %s\n", XDCCC_MATRIX_ATOM_NAME);
  728.     } else {
  729.         printf ("Deleting property %s\n", XDCCC_MATRIX_ATOM_NAME);
  730.         XDeleteProperty (dpy, root, MatricesAtom);
  731.         XFree ((char *)ret_prop);
  732.     }
  733.  
  734.     CorrectAtom = XInternAtom (dpy, XDCCC_CORRECT_ATOM_NAME, True);
  735.     if (CorrectAtom != None) {
  736.         XGetWindowProperty (dpy, root, CorrectAtom, 0, 8192, False, 
  737.             XA_INTEGER, &ret_atom, &ret_format, &ret_len, 
  738.             &ret_after, &ret_prop);
  739.     }
  740.     if (CorrectAtom == None || !ret_format) {
  741.         printf ("Could not find property %s\n", XDCCC_CORRECT_ATOM_NAME);
  742.     } else {
  743.         printf ("Deleting property %s\n", XDCCC_CORRECT_ATOM_NAME);
  744.         XDeleteProperty (dpy, root, CorrectAtom);
  745.         XFree ((char *)ret_prop);
  746.     }
  747.     }
  748. #ifdef GRAY
  749.     if (colorFlag != 1) {
  750.     MatricesAtom = ParseAtom (dpy, XDCCC_SCREENWHITEPT_ATOM_NAME, True);
  751.     if (MatricesAtom != None) {
  752.         XGetWindowProperty (dpy, root, MatricesAtom, 0, 8192, False,
  753.             XA_INTEGER, &ret_atom, &ret_format, &ret_len, 
  754.             &ret_after, &ret_prop);
  755.     } 
  756.     if (MatricesAtom == None || !ret_format) {
  757.         printf ("Could not find property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
  758.     } else {
  759.         printf ("Deleting property %s\n", XDCCC_SCREENWHITEPT_ATOM_NAME);
  760.         XDeleteProperty (dpy, root, MatricesAtom);
  761.         XFree ((char *)ret_prop);
  762.     }
  763.  
  764.     CorrectAtom = XInternAtom (dpy, XDCCC_GRAY_CORRECT_ATOM_NAME, True);
  765.     if (CorrectAtom != None) {
  766.         XGetWindowProperty (dpy, root, CorrectAtom, 0, 8192, False, 
  767.             XA_INTEGER, &ret_atom, &ret_format, &ret_len, 
  768.             &ret_after, &ret_prop);
  769.     }
  770.     if (CorrectAtom == None || !ret_format) {
  771.         printf ("Could not find property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME);
  772.     } else {
  773.         printf ("Deleting property %s\n", XDCCC_GRAY_CORRECT_ATOM_NAME);
  774.         XDeleteProperty (dpy, root, CorrectAtom);
  775.         XFree ((char *)ret_prop);
  776.     }
  777.     }
  778. #endif /* GRAY */
  779. }
  780.  
  781. static unsigned long
  782. _XcmsGetElement (format, pValue, pCount) 
  783.     int             format;
  784.     char            **pValue;
  785.     unsigned long   *pCount;
  786. /*
  787.  *    DESCRIPTION
  788.  *        Get the next element from the property and return it.
  789.  *        Also increment the pointer the amount needed.
  790.  *
  791.  *    Returns
  792.  *        unsigned long
  793.  */
  794. {
  795.     unsigned long value;
  796.  
  797.     switch (format) {
  798.       case 32:
  799. #ifdef WORD64
  800.     value = ((unsigned long)(((unsigned char *)(*pValue))[0])) << 24 ||
  801.         ((unsigned long)(((unsigned char *)(*pValue))[1])) << 16 ||
  802.         ((unsigned long)(((unsigned char *)(*pValue))[2])) << 8 ||
  803.         ((unsigned long)(((unsigned char *)(*pValue))[0]));
  804. #else
  805.     value = *((unsigned long *)(*pValue));
  806. #endif
  807.     *pValue += 4;
  808.     *pCount -= 1;
  809.     break;
  810.       case 16:
  811. #ifdef WORD64
  812.     value = ((unsigned long)(((unsigned char *)(*pValue))[0])) << 8 ||
  813.         ((unsigned long)(((unsigned char *)(*pValue))[1]));
  814. #else
  815.     value = *((unsigned short *)(*pValue));
  816. #endif
  817.     *pValue += 2;
  818.     *pCount -= 1;
  819.     break;
  820.       case 8:
  821.     value = *((unsigned char *) (*pValue));
  822.     *pValue += 1;
  823.     *pCount -= 1;
  824.     break;
  825.       default:
  826.     value = 0;
  827.     break;
  828.     }
  829.     return(value);
  830. }
  831.  
  832.  
  833. /*
  834.  *    NAME
  835.  *        _XcmsGetProperty -- Determine the existance of a property
  836.  *
  837.  *    SYNOPSIS
  838.  */
  839. static int
  840. _XcmsGetProperty (pDpy, w, property, pFormat, pNItems, pNBytes, pValue) 
  841.     Display *pDpy;
  842.     Window  w;
  843.     Atom property;
  844.     int             *pFormat;
  845.     unsigned long   *pNItems;
  846.     unsigned long   *pNBytes;
  847.     char            **pValue;
  848. /*
  849.  *    DESCRIPTION
  850.  *
  851.  *    Returns
  852.  *        0 if property does not exist.
  853.  *        1 if property exists.
  854.  */
  855. {
  856.     char *prop_ret;
  857.     int format_ret;
  858.     long len = 6516;
  859.     unsigned long nitems_ret, after_ret;
  860.     Atom atom_ret;
  861.     
  862.     while (XGetWindowProperty (pDpy, w, property, 0, len, False, 
  863.                    XA_INTEGER, &atom_ret, &format_ret, 
  864.                    &nitems_ret, &after_ret, 
  865.                    (unsigned char **)&prop_ret)) {
  866.     if (after_ret > 0) {
  867.         len += nitems_ret * (format_ret >> 3);
  868.         XFree (prop_ret);
  869.     } else {
  870.         break;
  871.     }
  872.     }
  873.     if (format_ret == 0 || nitems_ret == 0) { 
  874.     /* the property does not exist or is of an unexpected type */
  875.     return(XcmsFailure);
  876.     }
  877.  
  878.     *pFormat = format_ret;
  879.     *pNItems = nitems_ret;
  880.     *pNBytes = nitems_ret * (format_ret >> 3);
  881.     *pValue = prop_ret;
  882.     return(XcmsSuccess);
  883. }
  884.