summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-09-29 16:03:17 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-09-29 16:03:17 +0000
commit5c125bf1d5b74a47550aac080282e84dae075e88 (patch)
tree325fb9abf5287545b04870564369b7a9af9af539 /usr.bin
parent24d23a0ab357d395842c7fefd34f389734832a57 (diff)
knf
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/locate/bigram/locate.bigram.c18
-rw-r--r--usr.bin/locate/code/locate.code.c36
-rw-r--r--usr.bin/locate/locate/fastfind.c33
-rw-r--r--usr.bin/locate/locate/locate.c175
-rw-r--r--usr.bin/locate/locate/locate.h4
-rw-r--r--usr.bin/locate/locate/updatedb.sh6
6 files changed, 133 insertions, 139 deletions
diff --git a/usr.bin/locate/bigram/locate.bigram.c b/usr.bin/locate/bigram/locate.bigram.c
index 79848e3e86f..b741b29ccb3 100644
--- a/usr.bin/locate/bigram/locate.bigram.c
+++ b/usr.bin/locate/bigram/locate.bigram.c
@@ -1,5 +1,5 @@
/*
- * $OpenBSD: locate.bigram.c,v 1.9 2003/07/10 00:06:51 david Exp $
+ * $OpenBSD: locate.bigram.c,v 1.10 2003/09/29 16:03:16 deraadt Exp $
*
* Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
* Copyright (c) 1989, 1993
@@ -32,7 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: locate.bigram.c,v 1.9 2003/07/10 00:06:51 david Exp $
+ * $Id: locate.bigram.c,v 1.10 2003/09/29 16:03:16 deraadt Exp $
*/
#ifndef lint
@@ -41,7 +41,7 @@ static char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#else
-static char rcsid[] = "$OpenBSD: locate.bigram.c,v 1.9 2003/07/10 00:06:51 david Exp $";
+static char rcsid[] = "$OpenBSD: locate.bigram.c,v 1.10 2003/09/29 16:03:16 deraadt Exp $";
#endif
#endif /* not lint */
@@ -50,7 +50,7 @@ static char sccsid[] = "@(#)locate.bigram.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
/*
- * bigram < sorted_file_names | sort -nr |
+ * bigram < sorted_file_names | sort -nr |
* awk 'NR <= 128 { printf $2 }' > bigrams
*
* List bigrams for 'updatedb' script.
@@ -69,13 +69,13 @@ u_int bigram[UCHAR_MAX + 1][UCHAR_MAX + 1];
int
main(void)
{
- u_char *cp;
+ u_char *cp;
u_char *oldpath = buf1, *path = buf2;
u_int i, j;
- while (fgets(path, sizeof(buf2), stdin) != NULL) {
+ while (fgets(path, sizeof(buf2), stdin) != NULL) {
- /*
+ /*
* We don't need remove newline character '\n'.
* '\n' is less than ASCII_MIN and will be later
* ignored at output.
@@ -93,14 +93,14 @@ main(void)
}
/* swap pointers */
- if (path == buf1) {
+ if (path == buf1) {
path = buf2;
oldpath = buf1;
} else {
path = buf1;
oldpath = buf2;
}
- }
+ }
/* output, boundary check */
for (i = ASCII_MIN; i <= ASCII_MAX; i++)
diff --git a/usr.bin/locate/code/locate.code.c b/usr.bin/locate/code/locate.code.c
index 8f7d9fcf98d..1d8bd0ce3b2 100644
--- a/usr.bin/locate/code/locate.code.c
+++ b/usr.bin/locate/code/locate.code.c
@@ -1,5 +1,5 @@
/*
- * $OpenBSD: locate.code.c,v 1.11 2003/07/07 21:36:16 deraadt Exp $
+ * $OpenBSD: locate.code.c,v 1.12 2003/09/29 16:03:16 deraadt Exp $
*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -31,7 +31,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: locate.code.c,v 1.11 2003/07/07 21:36:16 deraadt Exp $
+ * $Id: locate.code.c,v 1.12 2003/09/29 16:03:16 deraadt Exp $
*/
#ifndef lint
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)locate.code.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: locate.code.c,v 1.11 2003/07/07 21:36:16 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: locate.code.c,v 1.12 2003/09/29 16:03:16 deraadt Exp $";
#endif
#endif /* not lint */
@@ -78,17 +78,17 @@ static char rcsid[] = "$OpenBSD: locate.code.c,v 1.11 2003/07/07 21:36:16 deraad
* 128-255 bigram codes (128 most common, as determined by 'updatedb')
* 32-127 single character (printable) ascii residue (ie, literal)
*
- * The locate database store any character except newline ('\n')
+ * The locate database store any character except newline ('\n')
* and NUL ('\0'). The 8-bit character support don't wast extra
* space until you have characters in file names less than 32
* or greather than 127.
- *
+ *
*
* SEE ALSO: updatedb.sh, ../bigram/locate.bigram.c
*
* AUTHOR: James A. Woods, Informatics General Corp.,
* NASA Ames Research Center, 10/82
- * 8-bit file names characters:
+ * 8-bit file names characters:
* Wolfram Schneider, Berlin September 1996
*/
@@ -102,7 +102,7 @@ static char rcsid[] = "$OpenBSD: locate.code.c,v 1.11 2003/07/07 21:36:16 deraad
#define BGBUFSIZE (NBG * 2) /* size of bigram buffer */
-u_char buf1[MAXPATHLEN] = " ";
+u_char buf1[MAXPATHLEN] = " ";
u_char buf2[MAXPATHLEN];
u_char bigrams[BGBUFSIZE + 1] = { 0 };
@@ -132,7 +132,7 @@ main(int argc, char *argv[])
int i, j;
while ((ch = getopt(argc, argv, "")) != -1)
- switch(ch) {
+ switch (ch) {
default:
usage();
}
@@ -155,11 +155,11 @@ main(int argc, char *argv[])
#ifdef LOOKUP
/* init lookup table */
for (i = 0; i < UCHAR_MAX + 1; i++)
- for (j = 0; j < UCHAR_MAX + 1; j++)
+ for (j = 0; j < UCHAR_MAX + 1; j++)
big[i][j] = (bg_t)-1;
for (cp = bigrams, i = 0; *cp != '\0'; i += 2, cp += 2)
- big[(u_char)*cp][(u_char)*(cp + 1)] = (bg_t)i;
+ big[(u_char)*cp][(u_char)*(cp + 1)] = (bg_t)i;
#endif /* LOOKUP */
@@ -202,30 +202,26 @@ main(int argc, char *argv[])
if ((code = BGINDEX(cp)) != (bg_t)-1) {
/*
* print *one* as bigram
- * Found, so mark byte with
- * parity bit.
+ * Found, so mark byte with
+ * parity bit.
*/
if (putchar((code / 2) | PARITY) == EOF)
err(1, "stdout");
cp += 2;
- }
-
- else {
+ } else {
for (i = 0; i < 2; i++) {
if (*cp == '\0')
break;
/* print umlauts in file names */
- if (*cp < ASCII_MIN ||
+ if (*cp < ASCII_MIN ||
*cp > ASCII_MAX) {
if (putchar(UMLAUT) == EOF ||
putchar(*cp++) == EOF)
err(1, "stdout");
- }
-
- else {
+ } else {
/* normal character */
- if(putchar(*cp++) == EOF)
+ if (putchar(*cp++) == EOF)
err(1, "stdout");
}
}
diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c
index d555cf46541..dd6007e1192 100644
--- a/usr.bin/locate/locate/fastfind.c
+++ b/usr.bin/locate/locate/fastfind.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fastfind.c,v 1.7 2003/06/03 02:56:10 millert Exp $ */
+/* $OpenBSD: fastfind.c,v 1.8 2003/09/29 16:03:16 deraadt Exp $ */
/*
* Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
@@ -32,13 +32,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: fastfind.c,v 1.7 2003/06/03 02:56:10 millert Exp $
+ * $Id: fastfind.c,v 1.8 2003/09/29 16:03:16 deraadt Exp $
*/
#ifndef _LOCATE_STATISTIC_
#define _LOCATE_STATISTIC_
-void
+void
statistic (fp, path_fcodes)
FILE *fp; /* open database */
char *path_fcodes; /* for error message */
@@ -64,7 +64,7 @@ statistic (fp, path_fcodes)
zwerg++;
} else
count += c - OFFSET;
-
+
for (p = path + count; (c = getc(fp)) > SWITCH; size++)
if (c < PARITY) {
if (c == UMLAUT) {
@@ -86,10 +86,10 @@ statistic (fp, path_fcodes)
(void)printf("\nDatabase: %s\n", path_fcodes);
(void)printf("Compression: Front: %2.2f%%, ",
- (float)(100 * (size + big - (2 * NBG))) / chars);
+ (float)(100 * (size + big - (2 * NBG))) / chars);
(void)printf("Bigram: %2.2f%%, ", (float)(100 * (size - big)) / size);
- (void)printf("Total: %2.2f%%\n",
- (float)(100 * (size - (2 * NBG))) / chars);
+ (void)printf("Total: %2.2f%%\n",
+ (float)(100 * (size - (2 * NBG))) / chars);
(void)printf("Filenames: %d, ", lines);
(void)printf("Characters: %d, ", chars);
(void)printf("Database size: %d\n", size);
@@ -154,7 +154,7 @@ fastfind
(void)fprintf(stderr, "database too small: %s\n", database);
exit(1);
}
-
+
for (c = 0, p = bigram1, s = bigram2; c < NBG; c++, len-= 2) {
p[c] = check_bigram_char(*paddr++);
s[c] = check_bigram_char(*paddr++);
@@ -217,8 +217,8 @@ fastfind
for (;;) {
#ifdef FF_MMAP
- c = (u_char)*paddr++;
- len--;
+ c = (u_char)*paddr++;
+ len--;
#else
c = getc(fp);
#endif /* FF_MMAP */
@@ -239,7 +239,7 @@ fastfind
#else
c = getc(fp);
#endif /* FF_MMAP */
-
+
} else
break; /* SWITCH */
}
@@ -250,8 +250,7 @@ fastfind
#endif /* FF_ICASE */
foundchar = p;
*p++ = c;
- }
- else {
+ } else {
/* bigrams are parity-marked */
TO7BIT(c);
@@ -269,15 +268,15 @@ fastfind
*p++ = bigram2[c];
}
}
-
- if (found) { /* previous line matched */
+
+ if (found) { /* previous line matched */
cutoff = path;
*p-- = '\0';
foundchar = p;
} else if (foundchar >= path + count) { /* a char matched */
*p-- = '\0';
cutoff = path + count;
- } else /* nothing to do */
+ } else /* nothing to do */
continue;
found = 0;
@@ -288,7 +287,7 @@ fastfind
#endif /* FF_ICASE */
) { /* fast first char check */
for (p = patend - 1, q = s - 1; *p != '\0';
- p--, q--)
+ p--, q--)
if (*q != *p
#ifdef FF_ICASE
&& TOLOWER(*q) != *p
diff --git a/usr.bin/locate/locate/locate.c b/usr.bin/locate/locate/locate.c
index 5f0361c1838..21d1e047cac 100644
--- a/usr.bin/locate/locate/locate.c
+++ b/usr.bin/locate/locate/locate.c
@@ -1,5 +1,5 @@
/*
- * $OpenBSD: locate.c,v 1.16 2003/07/07 21:36:16 deraadt Exp $
+ * $OpenBSD: locate.c,v 1.17 2003/09/29 16:03:16 deraadt Exp $
*
* Copyright (c) 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
* Copyright (c) 1989, 1993
@@ -32,7 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: locate.c,v 1.16 2003/07/07 21:36:16 deraadt Exp $
+ * $Id: locate.c,v 1.17 2003/09/29 16:03:16 deraadt Exp $
*/
#ifndef lint
@@ -46,7 +46,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)locate.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: locate.c,v 1.16 2003/07/07 21:36:16 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: locate.c,v 1.17 2003/09/29 16:03:16 deraadt Exp $";
#endif
#endif /* not lint */
@@ -144,86 +144,86 @@ extern int optind;
int
main(int argc, char *argv[])
{
- int ch;
- char **dbv = NULL;
+ int ch;
+ char **dbv = NULL;
#ifdef MMAP
- f_mmap = 1; /* mmap is default */
+ f_mmap = 1; /* mmap is default */
#endif
(void) setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "Scd:il:ms")) != -1)
- switch(ch) {
- case 'S': /* statistic lines */
- f_statistic = 1;
- break;
- case 'l': /* limit number of output lines, 0 == infinite */
- f_limit = atoi(optarg);
- break;
- case 'd': /* database */
- dbv = colon(dbv, optarg, _PATH_FCODES);
- break;
- case 'i': /* ignore case */
- f_icase = 1;
- break;
- case 'm': /* mmap */
+ while ((ch = getopt(argc, argv, "Scd:il:ms")) != -1)
+ switch (ch) {
+ case 'S': /* statistic lines */
+ f_statistic = 1;
+ break;
+ case 'l': /* limit number of output lines, 0 == infinite */
+ f_limit = atoi(optarg);
+ break;
+ case 'd': /* database */
+ dbv = colon(dbv, optarg, _PATH_FCODES);
+ break;
+ case 'i': /* ignore case */
+ f_icase = 1;
+ break;
+ case 'm': /* mmap */
#ifdef MMAP
- f_mmap = 1;
+ f_mmap = 1;
#else
(void)fprintf(stderr, "mmap(2) not implemented\n");
#endif
- break;
- case 's': /* stdio lib */
- f_mmap = 0;
- break;
- case 'c': /* suppress output, show only count of matches */
- f_silent = 1;
- break;
- default:
- usage();
- }
- argv += optind;
- argc -= optind;
-
- /* to few arguments */
- if (argc < 1 && !(f_statistic))
- usage();
-
- /* no (valid) database as argument */
- if (dbv == NULL || *dbv == NULL) {
- /* try to read database from environment */
- if ((path_fcodes = getenv("LOCATE_PATH")) == NULL ||
- *path_fcodes == '\0')
- /* use default database */
- dbv = colon(dbv, _PATH_FCODES, _PATH_FCODES);
- else /* $LOCATE_PATH */
- dbv = colon(dbv, path_fcodes, _PATH_FCODES);
- }
-
- if (f_icase && UCHAR_MAX < 4096) /* init tolower lookup table */
- for (ch = 0; ch < UCHAR_MAX + 1; ch++)
- myctype[ch] = tolower(ch);
-
- /* foreach database ... */
- while((path_fcodes = *dbv) != NULL) {
- dbv++;
-
- if (!strcmp(path_fcodes, "-"))
- f_stdin = 1;
+ break;
+ case 's': /* stdio lib */
+ f_mmap = 0;
+ break;
+ case 'c': /* suppress output, show only count of matches */
+ f_silent = 1;
+ break;
+ default:
+ usage();
+ }
+ argv += optind;
+ argc -= optind;
+
+ /* to few arguments */
+ if (argc < 1 && !(f_statistic))
+ usage();
+
+ /* no (valid) database as argument */
+ if (dbv == NULL || *dbv == NULL) {
+ /* try to read database from environment */
+ if ((path_fcodes = getenv("LOCATE_PATH")) == NULL ||
+ *path_fcodes == '\0')
+ /* use default database */
+ dbv = colon(dbv, _PATH_FCODES, _PATH_FCODES);
+ else /* $LOCATE_PATH */
+ dbv = colon(dbv, path_fcodes, _PATH_FCODES);
+ }
+
+ if (f_icase && UCHAR_MAX < 4096) /* init tolower lookup table */
+ for (ch = 0; ch < UCHAR_MAX + 1; ch++)
+ myctype[ch] = tolower(ch);
+
+ /* foreach database ... */
+ while ((path_fcodes = *dbv) != NULL) {
+ dbv++;
+
+ if (!strcmp(path_fcodes, "-"))
+ f_stdin = 1;
else
f_stdin = 0;
#ifndef MMAP
f_mmap = 0; /* be paranoid */
#endif
- if (!f_mmap || f_stdin || f_statistic)
+ if (!f_mmap || f_stdin || f_statistic)
search_fopen(path_fcodes, argv);
- else
+ else
search_mmap(path_fcodes, argv);
- }
+ }
- if (f_silent)
- print_matches(counter);
- exit(0);
+ if (f_silent)
+ print_matches(counter);
+ exit(0);
}
@@ -232,19 +232,19 @@ search_fopen(char *db, char **s)
{
FILE *fp;
#ifdef DEBUG
- long t0;
+ long t0;
#endif
-
+
/* can only read stdin once */
- if (f_stdin) {
+ if (f_stdin) {
fp = stdin;
if (*(s+1) != NULL) {
- (void)fprintf(stderr,
- "read database from stdin, use only");
+ (void)fprintf(stderr,
+ "read database from stdin, use only");
(void)fprintf(stderr, " `%s' as pattern\n", *s);
*(s+1) = NULL;
}
- }
+ }
else if ((fp = fopen(path_fcodes, "r")) == NULL)
err(1, "`%s'", path_fcodes);
@@ -256,7 +256,7 @@ search_fopen(char *db, char **s)
}
/* foreach search string ... */
- while(*s != NULL) {
+ while (*s != NULL) {
#ifdef DEBUG
t0 = cputime();
#endif
@@ -272,29 +272,28 @@ search_fopen(char *db, char **s)
(void)fprintf(stderr, "fastfind %ld ms\n", cputime () - t0);
#endif
s++;
- }
+ }
(void)fclose(fp);
-}
+}
#ifdef MMAP
void
search_mmap(char *db, char **s)
{
- struct stat sb;
- int fd;
- caddr_t p;
- off_t len;
+ struct stat sb;
+ int fd;
+ caddr_t p;
+ off_t len;
#ifdef DEBUG
- long t0;
+ long t0;
#endif
if ((fd = open(path_fcodes, O_RDONLY)) == -1 ||
fstat(fd, &sb) == -1)
err(1, "`%s'", path_fcodes);
len = sb.st_size;
- if ((p = mmap((caddr_t)0, (size_t)len,
- PROT_READ, MAP_SHARED,
- fd, (off_t)0)) == MAP_FAILED)
+ if ((p = mmap((caddr_t)0, (size_t)len, PROT_READ, MAP_SHARED,
+ fd, (off_t)0)) == MAP_FAILED)
err(1, "mmap ``%s''", path_fcodes);
/* foreach search string ... */
@@ -314,7 +313,7 @@ search_mmap(char *db, char **s)
if (munmap(p, (size_t)len) == -1)
warn("munmap %s", path_fcodes);
-
+
(void)close(fd);
}
#endif /* MMAP */
@@ -333,11 +332,11 @@ cputime(void)
void
usage(void)
{
- (void)fprintf(stderr, "usage: locate [-Scims] [-l limit] ");
+ (void)fprintf(stderr, "usage: locate [-Scims] [-l limit] ");
(void)fprintf(stderr, "[-d database] pattern ...\n");
- (void)fprintf(stderr, "default database: `%s' or $LOCATE_PATH\n",
- _PATH_FCODES);
- exit(1);
+ (void)fprintf(stderr, "default database: `%s' or $LOCATE_PATH\n",
+ _PATH_FCODES);
+ exit(1);
}
diff --git a/usr.bin/locate/locate/locate.h b/usr.bin/locate/locate/locate.h
index d819092cd23..60a7bc3b95a 100644
--- a/usr.bin/locate/locate/locate.h
+++ b/usr.bin/locate/locate/locate.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: locate.h,v 1.9 2003/06/03 02:56:10 millert Exp $ */
+/* $OpenBSD: locate.h,v 1.10 2003/09/29 16:03:16 deraadt Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -46,7 +46,7 @@
#undef CHAR_MAX
#define CHAR_MAX 127
/* 128-255 bigram codes (128 most common, as determined by 'updatedb') */
-#define BIGRAM_MIN (UCHAR_MAX - CHAR_MAX)
+#define BIGRAM_MIN (UCHAR_MAX - CHAR_MAX)
#define BIGRAM_MAX UCHAR_MAX
/* 32-127 single character (printable) ascii residue (ie, literal) */
diff --git a/usr.bin/locate/locate/updatedb.sh b/usr.bin/locate/locate/updatedb.sh
index 03b05d55dc1..55291dccc02 100644
--- a/usr.bin/locate/locate/updatedb.sh
+++ b/usr.bin/locate/locate/updatedb.sh
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $OpenBSD: updatedb.sh,v 1.10 1997/12/13 20:06:14 deraadt Exp $
+# $OpenBSD: updatedb.sh,v 1.11 2003/09/29 16:03:16 deraadt Exp $
#
# Copyright (c) September 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
# All rights reserved.
@@ -28,7 +28,7 @@
#
# updatedb - update locate database for local mounted filesystems
#
-# $Id: updatedb.sh,v 1.10 1997/12/13 20:06:14 deraadt Exp $
+# $Id: updatedb.sh,v 1.11 2003/09/29 16:03:16 deraadt Exp $
LOCATE_CONFIG="/etc/locate.rc"
if [ -f "$LOCATE_CONFIG" -a -r "$LOCATE_CONFIG" ]; then
@@ -95,7 +95,7 @@ esac
tmp=`mktemp ${TMPDIR=/tmp}/_updatedb.XXXXXXXXXX` || exit 1
trap 'rm -rf $tmp' 0 1 2 3 5 10 15
-
+
# search locally
# echo $find $SEARCHPATHS $excludes -or -print && exit
if $find $SEARCHPATHS $excludes -or -print 2>/dev/null |