|
|
1.1 ! root 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 11.2 87/07/20 11:46:36 toddb Exp $"; ! 9: #endif ! 10: ! 11: #include <dbm.h> ! 12: #undef NULL ! 13: #include <stdio.h> ! 14: #include <sys/file.h> ! 15: #include "rgb.h" ! 16: #include "site.h" ! 17: ! 18: main(argc, argv) ! 19: int argc; ! 20: char **argv; ! 21: { ! 22: char *dbname; ! 23: char line[512]; ! 24: int red, green, blue; ! 25: RGB rgb; ! 26: datum key, content; ! 27: char name[512]; ! 28: int items; ! 29: int lineno; ! 30: ! 31: if (argc == 2) ! 32: dbname = argv[1]; ! 33: else ! 34: dbname = RGB_DB; ! 35: strcpy (name, dbname); ! 36: strcat (name, ".dir"); ! 37: close (open (name, O_WRONLY|O_CREAT, 0666)); ! 38: strcpy (name, dbname); ! 39: strcat (name, ".pag"); ! 40: close (open (name, O_WRONLY|O_CREAT, 0666)); ! 41: if (dbminit (dbname)) ! 42: exit (1); ! 43: key.dptr = name; ! 44: content.dptr = (char *) &rgb; ! 45: content.dsize = sizeof (rgb); ! 46: lineno = 0; ! 47: while (fgets (line, sizeof (line), stdin)) { ! 48: lineno++; ! 49: items = sscanf (line, "%d %d %d %[^\n]\n", &red, &green, &blue, name); ! 50: if (items != 4) { ! 51: fprintf (stderr, "syntax error on line %d\n", lineno); ! 52: fflush (stderr); ! 53: continue; ! 54: } ! 55: if (red < 0 || red > 0xff || ! 56: green < 0 || green > 0xff || ! 57: blue < 0 || blue > 0xff) { ! 58: fprintf (stderr, "value for %s out of range\n", name); ! 59: fflush (stderr); ! 60: continue; ! 61: } ! 62: key.dsize = strlen (name); ! 63: rgb.red = red << 8; ! 64: rgb.green = green << 8; ! 65: rgb.blue = blue << 8; ! 66: if (store (key, content)) { ! 67: fprintf (stderr, "store of %s failed\n", name); ! 68: fflush (stderr); ! 69: } ! 70: } ! 71: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.