2
* $Xorg: showrgb.c,v 1.4 2001/02/09 02:05:35 xorgcvs Exp $
3
* $XdotOrg: app/rgb/showrgb.c,v 1.5 2005/11/08 06:33:31 jkj Exp $
5
Copyright 1989, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
27
* Author: Jim Fulton, MIT X Consortium
30
/* $XFree86: xc/programs/rgb/showrgb.c,v 3.8 2001/12/14 20:01:04 dawes Exp $ */
41
#include <rpcsvc/dbm.h>
45
#define dbm_open(name,flags,mode) (!dbminit(name))
46
#define dbm_firstkey(db) (firstkey())
47
#define dbm_fetch(db,key) (fetch(key))
48
#define dbm_close(db) dbmclose()
50
#endif /* USE_RGB_TXT */
57
#include "rgb.h" /* off in server/include/ */
60
#include <X11/Xfuncs.h>
63
static void dumprgb(char *filename);
66
main (int argc, char *argv[])
68
char *dbname = RGB_DB;
70
ProgramName = argv[0];
90
rgb_dbm = dbm_open (filename, O_RDONLY, 0);
92
fprintf (stderr, "%s: unable to open rgb database \"%s\"\n",
93
ProgramName, filename);
98
#define dbm_nextkey(db) (nextkey(key)) /* need variable called key */
101
for (key = dbm_firstkey(rgb_dbm); key.dptr != NULL;
102
key = dbm_nextkey(rgb_dbm)) {
105
value = dbm_fetch(rgb_dbm, key);
108
unsigned short r, g, b;
109
memcpy( (char *)&rgb, value.dptr, sizeof rgb);
110
#define N(x) (((x) >> 8) & 0xff)
115
printf ("%3u %3u %3u\t\t", r, g, b);
116
fwrite (key.dptr, 1, key.dsize, stdout);
119
fprintf (stderr, "%s: no value found for key \"", ProgramName);
120
fwrite (key.dptr, 1, key.dsize, stderr);
121
fprintf (stderr, "\"\n");
128
#else /* USE_RGB_TXT */
138
int red, green, blue;
141
char *root = (char*)getenv("X11ROOT");
142
sprintf(line,"%s%s.txt",root,filename);
143
path = (char *)malloc(strlen(line) + 1);
146
path = (char *)malloc(strlen(filename) + 5);
147
strcpy(path, filename);
148
strcat(path, ".txt");
151
if (!(rgb = fopen(path, "r"))) {
152
fprintf (stderr, "%s: unable to open rgb database \"%s\"\n",
153
ProgramName, filename);
158
while(fgets(line, sizeof(line), rgb)) {
161
if (sscanf(line, "%d %d %d %[^\n]\n", &red, &green, &blue, name) == 4) {
163
if (sscanf(line, "%d %d %d %[^\n\r]\n", &red, &green, &blue, name) == 4) {
165
if (red >= 0 && red <= 0xff &&
166
green >= 0 && green <= 0xff &&
167
blue >= 0 && blue <= 0xff) {
168
printf ("%3u %3u %3u\t\t%s\n", red, green, blue, name);
170
fprintf(stderr, "%s: value for \"%s\" out of range: %s:%d\n",
171
ProgramName, name, path, lineno);
173
} else if (*line && *line != '!') {
174
fprintf(stderr, "%s: syntax error: %s:%d\n", ProgramName,
183
#endif /* USE_RGB_TXT */