11ab64890Smrg/* 21ab64890Smrg 31ab64890SmrgCopyright 1985, 1998 The Open Group 41ab64890Smrg 51ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 61ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 71ab64890Smrgthe above copyright notice appear in all copies and that both that 81ab64890Smrgcopyright notice and this permission notice appear in supporting 91ab64890Smrgdocumentation. 101ab64890Smrg 111ab64890SmrgThe above copyright notice and this permission notice shall be included in 121ab64890Smrgall copies or substantial portions of the Software. 131ab64890Smrg 141ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 151ab64890SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 161ab64890SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 171ab64890SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 181ab64890SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 191ab64890SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 201ab64890Smrg 211ab64890SmrgExcept as contained in this notice, the name of The Open Group shall not be 221ab64890Smrgused in advertising or otherwise to promote the sale, use or other dealings 231ab64890Smrgin this Software without prior written authorization from The Open Group. 241ab64890Smrg 251ab64890Smrg*/ 261ab64890Smrg 271ab64890Smrg#ifdef HAVE_CONFIG_H 281ab64890Smrg#include <config.h> 291ab64890Smrg#endif 309c927599Smrg#include <limits.h> 311ab64890Smrg#include <stdio.h> 321ab64890Smrg#include "Xlibint.h" 331ab64890Smrg#include "Xcmsint.h" 341ab64890Smrg 351ab64890Smrg 361ab64890SmrgStatus 371ab64890SmrgXLookupColor ( 381ab64890Smrg register Display *dpy, 391ab64890Smrg Colormap cmap, 401ab64890Smrg _Xconst char *spec, 411ab64890Smrg XColor *def, 421ab64890Smrg XColor *scr) 431ab64890Smrg{ 4403ea5dc6Smrg register size_t n; 451ab64890Smrg xLookupColorReply reply; 461ab64890Smrg register xLookupColorReq *req; 471ab64890Smrg XcmsCCC ccc; 481ab64890Smrg XcmsColor cmsColor_exact; 491ab64890Smrg 5003ea5dc6Smrg if (spec == NULL) 5103ea5dc6Smrg return 0; 5203ea5dc6Smrg n = strlen (spec); 539c927599Smrg if (n >= USHRT_MAX) 549c927599Smrg return 0; 551ab64890Smrg#ifdef XCMS 561ab64890Smrg /* 571ab64890Smrg * Let's Attempt to use Xcms and i18n approach to Parse Color 581ab64890Smrg */ 591ab64890Smrg if ((ccc = XcmsCCCOfColormap(dpy, cmap)) != (XcmsCCC)NULL) { 601ab64890Smrg const char *tmpName = spec; 611ab64890Smrg 621ab64890Smrg switch (_XcmsResolveColorString(ccc, &tmpName, &cmsColor_exact, 631ab64890Smrg XcmsRGBFormat)) { 641ab64890Smrg case XcmsSuccess: 651ab64890Smrg case XcmsSuccessWithCompression: 661ab64890Smrg _XcmsRGB_to_XColor(&cmsColor_exact, def, 1); 671ab64890Smrg memcpy((char *)scr, (char *)def, sizeof(XColor)); 681ab64890Smrg _XUnresolveColor(ccc, scr); 691ab64890Smrg return(1); 701ab64890Smrg case XcmsFailure: 711ab64890Smrg case _XCMS_NEWNAME: 721ab64890Smrg /* 731ab64890Smrg * if the result was _XCMS_NEWNAME tmpName points to 741ab64890Smrg * a string in cmsColNm.c:pairs table, for example, 751ab64890Smrg * gray70 would become tekhvc:0.0/70.0/0.0 761ab64890Smrg */ 771ab64890Smrg break; 781ab64890Smrg } 791ab64890Smrg } 801ab64890Smrg#endif 811ab64890Smrg 821ab64890Smrg /* 831ab64890Smrg * Xcms and i18n methods failed, so lets pass it to the server 841ab64890Smrg * for parsing. 851ab64890Smrg */ 861ab64890Smrg LockDisplay(dpy); 871ab64890Smrg GetReq (LookupColor, req); 881ab64890Smrg req->cmap = cmap; 891ab64890Smrg req->nbytes = n; 901ab64890Smrg req->length += (n + 3) >> 2; 911ab64890Smrg Data (dpy, spec, (long)n); 921ab64890Smrg if (!_XReply (dpy, (xReply *) &reply, 0, xTrue)) { 931ab64890Smrg UnlockDisplay(dpy); 941ab64890Smrg SyncHandle(); 951ab64890Smrg return (0); 961ab64890Smrg } 971ab64890Smrg def->red = reply.exactRed; 981ab64890Smrg def->green = reply.exactGreen; 991ab64890Smrg def->blue = reply.exactBlue; 1001ab64890Smrg 1011ab64890Smrg scr->red = reply.screenRed; 1021ab64890Smrg scr->green = reply.screenGreen; 1031ab64890Smrg scr->blue = reply.screenBlue; 1041ab64890Smrg 1051ab64890Smrg UnlockDisplay(dpy); 1061ab64890Smrg SyncHandle(); 1071ab64890Smrg return (1); 1081ab64890Smrg} 109