Annotation of researchv10dc/cmd/netnews/cvt/cvt.hist.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Program to convert history file to dbm file.  The old 3 field
                      3:  * history file is still kept there, because we need it for expire
                      4:  * and for a human readable copy.  But we keep a dbm hashed copy
                      5:  * around by message ID so we can answer the yes/no question "have
                      6:  * we already seen this message".  The content is the ftell offset
                      7:  * into the real history file when we get the article - you can't
                      8:  * really do much with this because the file gets compacted.
                      9:  */
                     10: 
                     11: #include <stdio.h>
                     12: 
                     13: typedef struct {
                     14:        char *dptr;
                     15:        int dsize;
                     16: } datum;
                     17: 
                     18: FILE *fd;
                     19: 
                     20: char namebuf[BUFSIZ];
                     21: char lb[BUFSIZ];
                     22: 
                     23: char *index();
                     24: 
                     25: main(argc, argv)
                     26: char **argv;
                     27: {
                     28:        register char *p, *q;
                     29:        long fpos;
                     30:        datum lhs, rhs;
                     31:        int rv;
                     32: 
                     33:        if (argc != 2 ) {
                     34:                fprintf(stderr, "Usage: cvt.hist /usr/lib/news\n");
                     35:                exit(1);
                     36:        }
                     37: 
                     38:        umask(0);
                     39:        sprintf(namebuf, "%s/history.dir", argv[1]);
                     40:        close(creat(namebuf, 0666));
                     41:        sprintf(namebuf, "%s/history.pag", argv[1]);
                     42:        close(creat(namebuf, 0666));
                     43:        sprintf(namebuf, "%s/history", argv[1]);
                     44: 
                     45:        fd = fopen(namebuf, "r");
                     46:        if (fd == NULL) {
                     47:                perror(namebuf);
                     48:                exit(2);
                     49:        }
                     50: 
                     51:        dbminit(namebuf);
                     52:        while (fpos=ftell(fd), fgets(lb, BUFSIZ, fd) != NULL) {
                     53:                p = index(lb, '\t');
                     54:                if (p)
                     55:                        *p = 0;
                     56:                lhs.dptr = lb;
                     57:                lhs.dsize = strlen(lb) + 1;
                     58:                rhs.dptr = (char *) &fpos;
                     59:                rhs.dsize = sizeof fpos;
                     60:                rv = store(lhs, rhs);
                     61:                if (rv < 0)
                     62:                        fprintf(stderr, "store(%s) failed\n", lb);
                     63:        }
                     64:        exit(0);
                     65: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.