3 Copyright 1985, 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
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
30 /* reads from standard input lines of the form:
32 where red/green/blue are decimal values, and inserts them in a database.
41 #define dbm_open(name,flags,mode) (!dbminit(name))
42 #define dbm_store(db,key,content,flags) (store(key,content))
43 #define dbm_close(db) dbmclose()
55 static char *ProgramName;
58 main(int argc, char **argv)
76 ProgramName = argv[0];
83 strcpy (name, dbname);
84 strcat (name, ".dir");
85 fd = open (name, O_WRONLY|O_CREAT, 0666);
88 "%s: unable to create dbm file \"%s\" (error %d, %s)\n",
89 ProgramName, name, errno, strerror(errno));
94 strcpy (name, dbname);
95 strcat (name, ".pag");
96 fd = open (name, O_WRONLY|O_CREAT, 0666);
99 "%s: unable to create dbm file \"%s\" (error %d, %s)\n",
100 ProgramName, name, errno, strerror(errno));
105 rgb_dbm = dbm_open (dbname, O_RDWR|O_CREAT, 0666);
108 "%s: unable to open dbm database \"%s\" (error %d, %s)\n",
109 ProgramName, dbname, errno, strerror(errno));
114 content.dptr = (char *) &rgb;
115 content.dsize = sizeof (rgb);
117 while (fgets (line, sizeof (line), stdin)) {
121 items = sscanf (line, "%d %d %d %[^\n]\n", &red, &green, &blue, name);
123 fprintf (stderr, "syntax error on line %d\n", lineno);
127 if (red < 0 || red > 0xff ||
128 green < 0 || green > 0xff ||
129 blue < 0 || blue > 0xff) {
130 fprintf (stderr, "value for %s out of range\n", name);
135 for (i = 0; i < n; i++) {
136 if (isupper (name[i]))
137 name[i] = tolower (name[i]);
140 rgb.red = (red * 65535) / 255;
141 rgb.green = (green * 65535) / 255;
142 rgb.blue = (blue * 65535) / 255;
143 if (dbm_store (rgb_dbm, key, content, DBM_REPLACE)) {
144 fprintf (stderr, "%s: store of entry \"%s\" failed\n",