1
/* $Xorg: rgb.c,v 1.4 2001/02/09 02:05:35 xorgcvs Exp $ */
2
/* $XdotOrg: app/rgb/rgb.c,v 1.4 2005/11/08 06:33:31 jkj Exp $ */
5
Copyright 1985, 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
14
in all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
OTHER DEALINGS IN THE SOFTWARE.
24
Except as contained in this notice, the name of The Open Group shall
25
not be used in advertising or otherwise to promote the sale, use or
26
other dealings in this Software without prior written authorization
30
/* $XFree86: xc/programs/rgb/rgb.c,v 3.8tsi Exp $ */
33
/* reads from standard input lines of the form:
35
where red/green/blue are decimal values, and inserts them in a database.
46
#include <rpcsvc/dbm.h>
50
#define dbm_open(name,flags,mode) (!dbminit(name))
51
#define dbm_store(db,key,content,flags) (store(key,content))
52
#define dbm_close(db) dbmclose()
69
register char *s = strerror(errno);
94
ProgramName = argv[0];
101
strcpy (name, dbname);
102
strcat (name, ".dir");
103
fd = open (name, O_WRONLY|O_CREAT, 0666);
106
"%s: unable to create dbm file \"%s\" (error %d, %s)\n",
107
ProgramName, name, errno, strerror(errno));
112
strcpy (name, dbname);
113
strcat (name, ".pag");
114
fd = open (name, O_WRONLY|O_CREAT, 0666);
117
"%s: unable to create dbm file \"%s\" (error %d, %s)\n",
118
ProgramName, name, errno, strerror(errno));
123
rgb_dbm = dbm_open (dbname, O_RDWR|O_CREAT, 0666);
126
"%s: unable to open dbm database \"%s\" (error %d, %s)\n",
127
ProgramName, dbname, errno, strerror(errno));
132
content.dptr = (char *) &rgb;
133
content.dsize = sizeof (rgb);
135
while (fgets (line, sizeof (line), stdin)) {
139
items = sscanf (line, "%d %d %d %[^\n]\n", &red, &green, &blue, name);
141
fprintf (stderr, "syntax error on line %d\n", lineno);
145
if (red < 0 || red > 0xff ||
146
green < 0 || green > 0xff ||
147
blue < 0 || blue > 0xff) {
148
fprintf (stderr, "value for %s out of range\n", name);
153
for (i = 0; i < n; i++) {
154
if (isupper (name[i]))
155
name[i] = tolower (name[i]);
158
rgb.red = (red * 65535) / 255;
159
rgb.green = (green * 65535) / 255;
160
rgb.blue = (blue * 65535) / 255;
161
if (dbm_store (rgb_dbm, key, content, DBM_REPLACE)) {
162
fprintf (stderr, "%s: store of entry \"%s\" failed\n",