278N/A/*
943N/A * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved.
278N/A *
278N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
919N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
919N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
278N/A */
278N/A
278N/A
278N/A#include <stdlib.h>
278N/A#include <string.h>
278N/A
278N/A#include <X11/Xlib.h>
278N/A#include <X11/Xatom.h>
278N/A#include <X11/Xmu/XmuSolaris.h>
278N/A
278N/A#if defined(DEBUG)
278N/A#include <stdio.h>
278N/A#endif
278N/A
278N/A#define INIT_LIST_SIZE 100
278N/A
278N/A/*
278N/A * Get's next pair of integers from a string
278N/A */
278N/Astatic VisualID
278N/AgetNextEntry(char **pp)
278N/A{
278N/A char *newP;
278N/A VisualID entry;
278N/A
278N/A entry = strtoul(*pp, &newP, 0);
278N/A if (newP == *pp) {
278N/A return 0;
278N/A }
278N/A *pp = newP;
278N/A
278N/A return entry;
278N/A}
278N/A
278N/A/*
278N/A * Build a list of VisualIds that are equivalant to vidIn
278N/A *
278N/A * The format of the property string is a sequence of lists of
278N/A * integers separated by a newline.
278N/A * The first entry in each is the number of elements in the list.
278N/A * The list of ids follows.
278N/A */
278N/Astatic VisualID *
278N/AbuildList(char *string, VisualID vidIn, VisualID *pOriginalList)
278N/A{
278N/A VisualID *pList;
278N/A char *p = string;
278N/A int num;
278N/A
278N/A#ifdef DEBUG
278N/A (void) memset(pOriginalList, 0, sizeof(VisualID)*INIT_LIST_SIZE);
278N/A#endif
278N/A
278N/A while (num = strtoul(p, &p, 0)) {
278N/A int foundIt = 0;
278N/A int i;
278N/A if ((num + 1) > INIT_LIST_SIZE) {
278N/A pList = (VisualID *) malloc((num + 1) * sizeof(VisualID));
278N/A if (pList == NULL)
278N/A return NULL;
278N/A } else {
278N/A pList = pOriginalList;
278N/A }
278N/A for (i=0; i < num; i++) {
278N/A /* Build the list of VisualIDs equivalent to v */
278N/A VisualID vid;
278N/A if (vid = getNextEntry(&p)) {
278N/A pList[i] = vid;
278N/A if (vid == vidIn)
278N/A foundIt = 1;
278N/A } else {
278N/A /* string is formatted wrong */
278N/A#ifdef DEBUG
278N/A fprintf(stderr, "property string is formatted wrong: %s\n",
278N/A string);
278N/A#endif
278N/A break;
278N/A }
278N/A }
278N/A#ifdef DEBUG
278N/A if (*p != '\n')
278N/A fprintf(stderr, "property string is missing a newline: %s\n",
278N/A string);
278N/A#endif
278N/A if (foundIt) {
278N/A /* terminate the list */
278N/A pList[num] = 0;
278N/A break;
278N/A }
278N/A if (pList != pOriginalList)
278N/A free(pList);
278N/A pList = NULL;
278N/A }
278N/A
278N/A return pList;
278N/A}
278N/A
278N/A
278N/Astatic int
278N/AsearchList(VisualID *pList, VisualID v)
278N/A{
278N/A int i;
278N/A for (i=0; pList[i] != 0; i++) {
278N/A if (pList[i] == v)
278N/A return 1;
278N/A }
278N/A return 0;
278N/A}
278N/A
278N/Astatic Bool
278N/AareEquiv(char *pPropString, VisualID v1, VisualID v2)
278N/A{
278N/A VisualID list[INIT_LIST_SIZE];
278N/A VisualID *pList;
278N/A Bool foundMatch = False;
278N/A
278N/A /*
278N/A * Build a list of VisualIDS which are equivalent to v1
278N/A * using the array list if it fits.
278N/A */
278N/A pList = buildList(pPropString, v1, list);
278N/A if (pList == NULL)
278N/A return False;
278N/A
278N/A /* now see if v2 is in the list */
278N/A if (searchList(pList, v2)) {
278N/A foundMatch = True;
278N/A }
278N/A
278N/A if (pList != list)
278N/A free(pList);
278N/A
278N/A return foundMatch;
278N/A}
278N/A
278N/A#define SUN_CMAP_EQUIV_ATOM_NAME "_SUN_CMAP_EQUIV"
278N/A
278N/ABool
278N/AXSolarisCheckColormapEquivalence(Display *dpy, int screen_number,
278N/A Visual *pVis1, Visual* pVis2)
278N/A{
278N/A Atom theAtom;
278N/A Atom actualType;
278N/A int actualFormat;
278N/A unsigned long nitems;
278N/A unsigned long bytesAfter;
278N/A char *prop;
278N/A
278N/A theAtom = XInternAtom(dpy, SUN_CMAP_EQUIV_ATOM_NAME, True);
278N/A if (theAtom == None)
278N/A return False;
278N/A
278N/A if (!XGetWindowProperty(dpy, XRootWindow(dpy, screen_number), theAtom,
278N/A 0, 8192, False, XA_STRING, &actualType,
278N/A &actualFormat, &nitems, &bytesAfter,
278N/A (unsigned char **)&prop)) {
278N/A if (prop != NULL) {
278N/A Bool ret = areEquiv(prop, pVis1->visualid, pVis2->visualid);
278N/A XFree(prop);
278N/A return ret;
278N/A }
278N/A }
278N/A
278N/A return False;
278N/A}