diff --git a/usr.bin/locate/locate/Makefile b/usr.bin/locate/locate/Makefile --- a/usr.bin/locate/locate/Makefile +++ b/usr.bin/locate/locate/Makefile @@ -3,7 +3,7 @@ CONFS= locate.rc PROG= locate -SRCS= util.c locate.c +SRCS= util.c statistic.c locate.c CFLAGS+= -I${.CURDIR} -DMMAP SCRIPTS=updatedb.sh mklocatedb.sh concatdb.sh MAN= locate.1 locate.updatedb.8 diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c --- a/usr.bin/locate/locate/fastfind.c +++ b/usr.bin/locate/locate/fastfind.c @@ -36,87 +36,6 @@ */ -#ifndef _LOCATE_STATISTIC_ -#define _LOCATE_STATISTIC_ - -void -statistic (fp, path_fcodes) - FILE *fp; /* open database */ - char *path_fcodes; /* for error message */ -{ - long lines, chars, size, size_nbg, big, zwerg, umlaut; - u_char *p, *s; - int c; - int count, longest_path; - int error = 0; - u_char bigram1[NBG], bigram2[NBG], path[LOCATE_PATH_MAX]; - - 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 = longest_path = 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; - - if (count < 0 || count >= LOCATE_PATH_MAX) { - /* stop on error and display the statstics anyway */ - warnx("corrupted database: %s %d", path_fcodes, count); - error = 1; - break; - } - - for (p = path + count; (c = getc(fp)) > SWITCH; size++) - if (c < PARITY) { - if (c == UMLAUT) { - c = getc(fp); - size++; - umlaut++; - } - p++; - } else { - /* bigram char */ - big++; - p += 2; - } - - p++; - lines++; - chars += (p - path); - if ((p - path) > longest_path) - longest_path = p - path; - } - - /* size without bigram db */ - size_nbg = size - (2 * NBG); - - (void)printf("\nDatabase: %s\n", path_fcodes); - (void)printf("Compression: Front: %2.2f%%, ", chars > 0 ? (size_nbg + big) / (chars / (float)100) : 0); - (void)printf("Bigram: %2.2f%%, ", big > 0 ? (size_nbg - big) / (size_nbg / (float)100) : 0); - /* incl. bigram db overhead */ - (void)printf("Total: %2.2f%%\n", chars > 0 ? size / (chars / (float)100) : 0); - (void)printf("Filenames: %ld, ", lines); - (void)printf("Characters: %ld, ", chars); - (void)printf("Database size: %ld\n", size); - (void)printf("Bigram characters: %ld, ", big); - (void)printf("Integers: %ld, ", zwerg); - (void)printf("8-Bit characters: %ld\n", umlaut); - printf("Longest path: %d\n", longest_path > 0 ? longest_path - 1 : 0); - - /* non zero exit on corrupt database */ - if (error) - exit(error); -} -#endif /* _LOCATE_STATISTIC_ */ - extern char separator; void diff --git a/usr.bin/locate/locate/locate.c b/usr.bin/locate/locate/locate.c --- a/usr.bin/locate/locate/locate.c +++ b/usr.bin/locate/locate/locate.c @@ -85,6 +85,7 @@ #include #include #include +#include #ifdef MMAP # include @@ -109,7 +110,7 @@ u_char myctype[UCHAR_MAX + 1]; void usage(void); -void statistic(FILE *, char *); +void statistic(FILE *, char *, int); void fastfind(FILE *, char *, char *); void fastfind_icase(FILE *, char *, char *); void fastfind_mmap(char *, caddr_t, off_t, char *); @@ -230,8 +231,8 @@ /* can only read stdin once */ if (f_stdin) { fp = stdin; - if (*(s+1) != NULL) { - warnx("read database from stdin, use only `%s' as pattern", *s); + if (!f_statistic && *(s+1) != NULL) { + warnx("read database from stdin, use only first argument `%s' as pattern", *s); *(s+1) = NULL; } } @@ -240,7 +241,7 @@ /* count only chars or lines */ if (f_statistic) { - statistic(fp, db); + statistic(fp, db, f_statistic++); (void)fclose(fp); return; } @@ -315,8 +316,6 @@ /* load fastfind functions */ - -/* statistic */ /* fastfind_mmap, fastfind_mmap_icase */ #ifdef MMAP #undef FF_MMAP