File: diconvhist.c

package info (click to toggle)
diablo 1.13-1
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 804 kB
  • ctags: 875
  • sloc: ansic: 8,308; perl: 1,908; sh: 186; csh: 81; makefile: 67
file content (113 lines) | stat: -rw-r--r-- 2,118 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

/*
 * DICONVHIST.C		append an INN history file to a diablo dhistory
 *			file.  Used to prime a diablo history file during
 *			switchover from INN to diablo.  Priming MAY
 *			run in parallel to diablo operation.
 *
 * (c)Copyright 1997, Matthew Dillon, All Rights Reserved.  Refer to
 *    the COPYRIGHT file in the base directory of this distribution 
 *    for specific rights granted.
 */

#include "defs.h"

int
main(int ac, char **av)
{
    char buf[16384];
    int cnt = 0;
    int rep = 0;
    int enters = 0;
    int dups = 0;
    int ignores = 0;
    int lco = 0;
    int lskip = 0;
    int i;
    int fastOpt = 0;
    const char *innhName = NULL;
    uint32 gmt = time(NULL) / 60;
    FILE *fi;

    for (i = 1; i < ac; ++i) {
	char *ptr = av[i];

	if (*ptr != '-' || ptr[1] == 0) {
	    innhName = ptr;
	    continue;
	}
	ptr += 2;
	switch(ptr[-1]) {
	case 'f':
	    fastOpt = 1;
	    break;
	default:
	    break;
	}
    }

    if (innhName == NULL) {
	puts("diconvhistory [-f] innhistoryfile");
	exit(0);
    }

    if (strcmp(innhName, "-") == 0) {
	if ((fi = fdopen(dup(0), "r")) == NULL) {
	    perror("fdopen");
	    exit(1);
	}
    } else {
	if ((fi = fopen(innhName, "r")) == NULL) {
	    perror("fopen");
	    exit(1);
	}
    }

    HistoryOpen(NULL, 0);

    while (fgets(buf, sizeof(buf), fi) != NULL) {
	char *p = buf;

	if (lskip) {
	    --lskip;
	    ++rep;
	    ++dups;
	    ++cnt;
	    ++ignores;
	    continue;
	}

	if (p[0] != '<')
	    continue;
	while (*p && *p != '>')
	    ++p;
	if (*p != '>')
	    continue;
	p[1] = 0;
	if (HistoryLookup(buf, NULL, NULL, NULL) != 0) {
	    History h = { 0 };

	    h.hv = hhash(buf);
	    h.iter = (unsigned short)-1;
	    h.exp = (unsigned short)-1;
	    h.gmt = gmt;
	    HistoryAdd(buf, &h);
	    ++enters;
	    lco = 0;
	} else {
	    ++dups;
	    if (fastOpt && ++lco == 10) {
		lco = 9;
		lskip = 100;
	    }
	}
	++cnt;
	if (++rep >= 1000) {
	    rep = 0;
	    printf(" scan=%d add=%d dup=%d ignored=%d\n", cnt, enters, dups, ignores);
	}
    }
    printf(" scan=%d add=%d dup=%d ignored=%d\n", cnt, enters, dups, ignores);
    return(0);
}