#ifndef _LOCATE_STATISTIC_
#define _LOCATE_STATISTIC_
void
statistic (fp, path_fcodes)
FILE *fp;
char *path_fcodes;
{
register int lines, chars, size, big, zwerg;
register u_char *p, *s;
register int c;
int count, umlaut;
u_char bigram1[NBG], bigram2[NBG], path[MAXPATHLEN];
for (c = 0, p = bigram1, s = bigram2; c < NBG; c++) {
p[c] = check_bigram_char(getc(fp));
s[c] = check_bigram_char(getc(fp));
}
lines = chars = big = zwerg = umlaut = 0;
size = NBG + NBG;
for (c = getc(fp), count = 0; c != EOF; size++) {
if (c == SWITCH) {
count += getwf(fp) - OFFSET;
size += sizeof(int);
zwerg++;
} else
count += c - OFFSET;
for (p = path + count; (c = getc(fp)) > SWITCH; size++)
if (c < PARITY) {
if (c == UMLAUT) {
c = getc(fp);
size++;
umlaut++;
}
p++;
} else {
big++;
p += 2;
}
p++;
lines++;
chars += (p - path);
}
(void)printf("\nDatabase: %s\n", path_fcodes);
(void)printf("Compression: Front: %2.2f%%, ",
(size + big - (2 * NBG)) / (chars / (float)100));
(void)printf("Bigram: %2.2f%%, ", (size - big) / (size / (float)100));
(void)printf("Total: %2.2f%%\n",
(size - (2 * NBG)) / (chars / (float)100));
(void)printf("Filenames: %d, ", lines);
(void)printf("Characters: %d, ", chars);
(void)printf("Database size: %d\n", size);
(void)printf("Bigram characters: %d, ", big);
(void)printf("Integers: %d, ", zwerg);
(void)printf("8-Bit characters: %d\n", umlaut);
}
#endif
extern char separator;
void
#ifdef FF_MMAP
#ifdef FF_ICASE
fastfind_mmap_icase
#else
fastfind_mmap
#endif
(pathpart, paddr, len, database)
char *pathpart;
caddr_t paddr;
int len;
char *database;
#else
#ifdef FF_ICASE
fastfind_icase
#else
fastfind
#endif
(fp, pathpart, database)
FILE *fp;
char *pathpart;
char *database;
#endif
{
register u_char *p, *s, *patend, *q, *foundchar;
register int c, cc;
int count, found, globflag;
u_char *cutoff;
u_char bigram1[NBG], bigram2[NBG], path[MAXPATHLEN];
#ifdef FF_ICASE
u_char table[UCHAR_MAX + 1];
tolower_word(pathpart);
#endif
#ifdef FF_MMAP
if (len < (2*NBG))
errx(1, "database too small: %s", database);
for (c = 0, p = bigram1, s = bigram2; c < NBG; c++, len-= 2) {
p[c] = check_bigram_char(*paddr++);
s[c] = check_bigram_char(*paddr++);
}
#else
for (c = 0, p = bigram1, s = bigram2; c < NBG; c++) {
p[c] = check_bigram_char(getc(fp));
s[c] = check_bigram_char(getc(fp));
}
#endif
for (p = pathpart; *p != '\0'; p++)
if (index(LOCATE_REG, *p) != NULL)
break;
if (*p == '\0')
globflag = 0;
else
globflag = 1;
p = pathpart;
patend = patprep(p);
cc = *patend;
#ifdef FF_ICASE
for (c = 0; c < UCHAR_MAX + 1; c++)
table[c] = 0;
table[TOLOWER(*patend)] = 1;
table[toupper(*patend)] = 1;
#endif
found = count = 0;
foundchar = 0;
#ifdef FF_MMAP
c = (u_char)*paddr++; len--;
for (; len > 0; ) {
#else
c = getc(fp);
for (; c != EOF; ) {
#endif
if (c == SWITCH) {
#ifdef FF_MMAP
count += getwm(paddr) - OFFSET;
len -= INTSIZE; paddr += INTSIZE;
#else
count += getwf(fp) - OFFSET;
#endif
} else {
count += c - OFFSET;
}
p = path + count;
foundchar = p - 1;
#ifdef FF_MMAP
for (; len > 0;) {
c = (u_char)*paddr++;
len--;
#else
for (;;) {
c = getc(fp);
#endif
if (c < PARITY) {
if (c <= UMLAUT) {
if (c == UMLAUT) {
#ifdef FF_MMAP
c = (u_char)*paddr++;
len--;
#else
c = getc(fp);
#endif
} else
break;
}
#ifdef FF_ICASE
if (table[c])
#else
if (c == cc)
#endif
foundchar = p;
*p++ = c;
}
else {
TO7BIT(c);
#ifndef FF_ICASE
if (bigram1[c] == cc ||
bigram2[c] == cc)
#else
if (table[bigram1[c]] ||
table[bigram2[c]])
#endif
foundchar = p + 1;
*p++ = bigram1[c];
*p++ = bigram2[c];
}
}
if (found) {
cutoff = path;
*p-- = '\0';
foundchar = p;
} else if (foundchar >= path + count) {
*p-- = '\0';
cutoff = path + count;
} else
continue;
found = 0;
for (s = foundchar; s >= cutoff; s--) {
if (*s == cc
#ifdef FF_ICASE
|| TOLOWER(*s) == cc
#endif
) {
for (p = patend - 1, q = s - 1; *p != '\0';
p--, q--)
if (*q != *p
#ifdef FF_ICASE
&& TOLOWER(*q) != *p
#endif
)
break;
if (*p == '\0') {
found = 1;
if (!globflag ||
#ifndef FF_ICASE
!fnmatch(pathpart, path, 0))
#else
!fnmatch(pathpart, path,
FNM_CASEFOLD))
#endif
{
if (f_silent)
counter++;
else if (f_limit) {
counter++;
if (f_limit >= counter)
(void)printf("%s%c",path,separator);
else
errx(0, "[show only %d lines]", counter - 1);
} else
(void)printf("%s%c",path,separator);
}
break;
}
}
}
}
}