diff options
author | wosch <wosch@FreeBSD.org> | 1996-08-22 18:46:13 +0000 |
---|---|---|
committer | wosch <wosch@FreeBSD.org> | 1996-08-22 18:46:13 +0000 |
commit | 1647af0a74903fc3f24ba1c8dff768245ba03cae (patch) | |
tree | 72d248c17a7252aeec5a920535090abe27057f50 /usr.bin/locate/bigram | |
parent | 654c394b55bf04b2f525ade4403d26976414c59c (diff) | |
download | FreeBSD-src-1647af0a74903fc3f24ba1c8dff768245ba03cae.zip FreeBSD-src-1647af0a74903fc3f24ba1c8dff768245ba03cae.tar.gz |
code cleanup
Diffstat (limited to 'usr.bin/locate/bigram')
-rw-r--r-- | usr.bin/locate/bigram/locate.bigram.c | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/usr.bin/locate/bigram/locate.bigram.c b/usr.bin/locate/bigram/locate.bigram.c index dc95399..5b83a3b 100644 --- a/usr.bin/locate/bigram/locate.bigram.c +++ b/usr.bin/locate/bigram/locate.bigram.c @@ -32,6 +32,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id$ */ #ifndef lint @@ -45,7 +47,8 @@ static char sccsid[] = "@(#)locate.bigram.c 8.1 (Berkeley) 6/6/93"; #endif /* not lint */ /* - * bigram < text > bigrams + * bigram < sorted_file_names | sort -nr | + * awk 'NR <= 128 { printf $2 }' > bigrams * * List bigrams for 'updatedb' script. * Use 'code' to encode a file using this output. @@ -58,21 +61,16 @@ static char sccsid[] = "@(#)locate.bigram.c 8.1 (Berkeley) 6/6/93"; u_char buf1[MAXPATHLEN] = " "; u_char buf2[MAXPATHLEN]; -unsigned int bigram[UCHAR_MAX][UCHAR_MAX]; - +u_int bigram[UCHAR_MAX][UCHAR_MAX]; -void main ( ) +int +main(void) { register u_char *cp; register u_char *oldpath = buf1, *path = buf2; - register int i, j; + register u_int i, j; - /* init bigram buffer */ - for (i = 0; i < UCHAR_MAX; i++) - for (j = 0; j < UCHAR_MAX; j++) - bigram[i][j] = 0; - - while ( fgets ( path, sizeof(buf2), stdin ) != NULL ) { + while (fgets(path, sizeof(buf2), stdin) != NULL) { /* skip empty lines */ if (*path == '\n') @@ -88,30 +86,29 @@ void main ( ) *cp = '?'; } - /* skip longest common prefix */ - for (cp = path; *cp == *oldpath && *cp; cp++, oldpath++); + for (cp = path; *cp == *oldpath && *cp != NULL; cp++, oldpath++); - /* - * output post-residue bigrams only - */ - - /* check later for boundary */ - while ( *cp != NULL && *(cp + 1) != NULL ) { + while (*cp != NULL && *(cp+1) != NULL) { bigram[*cp][*(cp+1)]++; cp += 2; } - if ( path == buf1 ) /* swap pointers */ - path = buf2, oldpath = buf1; - else - path = buf1, oldpath = buf2; + /* swap pointers */ + if (path == buf1) { + path = buf2; + oldpath = buf1; + } else { + path = buf1; + oldpath = buf2; + } } - /* output, boundary check */ + /* output, (paranoid) boundary check */ for (i = ASCII_MIN; i <= ASCII_MAX; i++) for (j = ASCII_MIN; j <= ASCII_MAX; j++) if (bigram[i][j] != 0) - fprintf(stdout, "%4d %c%c\n", - bigram[i][j], i, j); + printf("%4u %c%c\n", bigram[i][j], i, j); + + exit(0); } |