1: /* Copyright 1985, Massachusetts Institute of Technology */
2:
3: /* reads from standard input lines of the form:
4: red green blue name
5: where red/green/blue are decimal values, and inserts them in a database.
6: */
7: #ifndef lint
8: static char *rcsid_rgb_c = "$Header: rgb.c,v 10.4 86/02/01 15:55:22 tony Rel $";
9: #endif
10:
11: #include <dbm.h>
12: #undef NULL
13: #include <stdio.h>
14: #include <sys/file.h>
15: #include <X/rgb.h>
16:
17: main(argc, argv)
18: int argc;
19: char **argv;
20: {
21: char *dbname;
22: char line[512];
23: int red, green, blue;
24: RGB rgb;
25: datum key, content;
26: char name[512];
27: int items;
28: int lineno;
29:
30: if (argc == 2)
31: dbname = argv[1];
32: else
33: dbname = RGB_DB;
34: strcpy (name, dbname);
35: strcat (name, ".dir");
36: close (open (name, O_WRONLY|O_CREAT, 0666));
37: strcpy (name, dbname);
38: strcat (name, ".pag");
39: close (open (name, O_WRONLY|O_CREAT, 0666));
40: if (dbminit (dbname))
41: exit (1);
42: key.dptr = name;
43: content.dptr = (char *) &rgb;
44: content.dsize = sizeof (rgb);
45: lineno = 0;
46: while (fgets (line, sizeof (line), stdin)) {
47: lineno++;
48: items = sscanf (line, "%d %d %d %[^\n]\n", &red, &green, &blue, name);
49: if (items != 4) {
50: fprintf (stderr, "syntax error on line %d\n", lineno);
51: fflush (stderr);
52: continue;
53: }
54: if (red < 0 || red > 0xff ||
55: green < 0 || green > 0xff ||
56: blue < 0 || blue > 0xff) {
57: fprintf (stderr, "value for %s out of range\n", name);
58: fflush (stderr);
59: continue;
60: }
61: key.dsize = strlen (name);
62: rgb.red = red << 8;
63: rgb.green = green << 8;
64: rgb.blue = blue << 8;
65: if (store (key, content)) {
66: fprintf (stderr, "store of %s failed\n", name);
67: fflush (stderr);
68: }
69: }
70: }
Defined functions
main
defined in line
17;
never used
Defined variables