1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 ******************************************************************/
48 #ifdef HAVE_DIX_CONFIG_H
49 #include <dix-config.h>
52 #define USE_RGB_BUILTIN 1
56 #include <X11/keysym.h>
60 OsToLower (unsigned char a
)
62 if ((a
>= XK_A
) && (a
<= XK_Z
))
63 return a
+ (XK_a
- XK_A
);
64 else if ((a
>= XK_Agrave
) && (a
<= XK_Odiaeresis
))
65 return a
+ (XK_agrave
- XK_Agrave
);
66 else if ((a
>= XK_Ooblique
) && (a
<= XK_Thorn
))
67 return a
+ (XK_oslash
- XK_Ooblique
);
73 OsStrCaseCmp (const unsigned char *s1
, const unsigned char *s2
, int l2
)
79 c1
= OsToLower (*s1
++);
83 c2
= OsToLower (*s2
++);
93 typedef struct _builtinColor
{
102 #define NUM_BUILTIN_COLORS (sizeof (BuiltinColors) / sizeof (BuiltinColors[0]))
111 OsLookupColor(int screen
,
114 unsigned short *pred
,
115 unsigned short *pgreen
,
116 unsigned short *pblue
)
118 const BuiltinColor
*c
;
119 unsigned char *name
= (unsigned char *) s_name
;
124 high
= NUM_BUILTIN_COLORS
- 1;
127 mid
= (low
+ high
) / 2;
128 c
= &BuiltinColors
[mid
];
129 r
= OsStrCaseCmp (&BuiltinColorNames
[c
->name
], name
, len
);
132 *pred
= c
->red
* 0x101;
133 *pgreen
= c
->green
* 0x101;
134 *pblue
= c
->blue
* 0x101;
148 * This file builds the server's internal database mapping color names to
149 * RGB tuples by reading in an rgb.txt file. This is still slightly foolish,
150 * rgb.txt hasn't changed in years, we should really include a precompiled
151 * version into the server.
160 typedef struct _dbEntry
* dbEntryPtr
;
161 typedef struct _dbEntry
{
164 unsigned short green
;
166 char name
[1]; /* some compilers complain if [0] */
169 extern void CopyISOLatin1Lowered(
170 unsigned char * /*dest*/,
171 unsigned char * /*source*/,
174 static dbEntryPtr hashTab
[HASHSIZE
];
177 lookup(char *name
, int len
, Bool create
)
179 unsigned int h
= 0, g
;
180 dbEntryPtr entry
, *prev
= NULL
;
183 if (!(name
= (char*)ALLOCATE_LOCAL(len
+1))) return NULL
;
184 CopyISOLatin1Lowered((unsigned char *)name
, (unsigned char *)str
, len
);
187 for(str
= name
; *str
; str
++) {
189 if ((g
= h
) & 0xf0000000) h
^= (g
>> 24);
194 if ( (entry
= hashTab
[h
]) )
196 for( ; entry
; prev
= (dbEntryPtr
*)entry
, entry
= entry
->link
)
197 if (! strcmp(name
, entry
->name
) ) break;
200 prev
= &(hashTab
[h
]);
202 if (!entry
&& create
&& (entry
= (dbEntryPtr
)xalloc(sizeof(dbEntry
) +len
)))
206 strcpy( entry
->name
, name
);
209 DEALLOCATE_LOCAL(name
);
221 int red
, green
, blue
, lineno
= 0;
224 static Bool was_here
= FALSE
;
228 path
= (char*)ALLOCATE_LOCAL(strlen(rgbPath
) +5);
229 strcpy(path
, rgbPath
);
230 strcat(path
, ".txt");
231 if (!(rgb
= fopen(path
, "r")))
233 ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath
);
234 DEALLOCATE_LOCAL(path
);
238 while(fgets(line
, sizeof(line
), rgb
))
241 if (sscanf(line
,"%d %d %d %[^\n]\n", &red
, &green
, &blue
, name
) == 4)
243 if (red
>= 0 && red
<= 0xff &&
244 green
>= 0 && green
<= 0xff &&
245 blue
>= 0 && blue
<= 0xff)
247 if ((entry
= lookup(name
, strlen(name
), TRUE
)))
249 entry
->red
= (red
* 65535) / 255;
250 entry
->green
= (green
* 65535) / 255;
251 entry
->blue
= (blue
* 65535) / 255;
255 ErrorF("Value out of range: %s:%d\n", path
, lineno
);
257 else if (*line
&& *line
!= '#' && *line
!= '!')
258 ErrorF("Syntax Error: %s:%d\n", path
, lineno
);
262 DEALLOCATE_LOCAL(path
);
270 OsLookupColor(int screen
, char *name
, unsigned int len
,
271 unsigned short *pred
, unsigned short *pgreen
, unsigned short *pblue
)
275 if ((entry
= lookup(name
, len
, FALSE
)))
278 *pgreen
= entry
->green
;
279 *pblue
= entry
->blue
;
286 #endif /* USE_RGB_BUILTIN */