1#!/bin/csh -f
2#
3# Copyright (c) 1989 The Regents of the University of California.
4# All rights reserved.
5#
6# This code is derived from software contributed to Berkeley by
7# James A. Woods.
8#
9# %sccs.include.redist.sh%
10#
11#	@(#)updatedb.csh	4.13 (Berkeley) 10/10/90
12#
13
14set SRCHPATHS = "/"			# directories to be put in the database
15set LIBDIR = /usr/libexec		# for subprograms
16if (! $?TMPDIR) set TMPDIR = /var/tmp	# for temp files
17set FCODES = /var/db/locate.database	# the database
18
19set path = ( /bin /usr/bin )
20set bigrams = $TMPDIR/locate.bigrams.$$
21set filelist = $TMPDIR/locate.list.$$
22set errs = $TMPDIR/locate.errs.$$
23
24# Make a file list and compute common bigrams.
25# Alphabetize '/' before any other char with 'tr'.
26# If the system is very short of sort space, 'bigram' can be made
27# smarter to accumulate common bigrams directly without sorting
28# ('awk', with its associative memory capacity, can do this in several
29# lines, but is too slow, and runs out of string space on small machines).
30
31# only search locally
32# find ${SRCHPATHS} ! -fstype local -a -prune -o -print | \
33find ${SRCHPATHS} -print | \
34	tr '/' '\001' | \
35	(sort -f; echo $status > $errs) | tr '\001' '/' > $filelist
36
37$LIBDIR/locate.bigram < $filelist | \
38	(sort; echo $status >> $errs) | uniq -c | sort -nr | \
39	awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $bigrams
40
41# code the file list
42
43if { grep -s -v 0 $errs } then
44	printf 'locate: updatedb failed\n\n'
45else
46	$LIBDIR/locate.code $bigrams < $filelist > $FCODES
47	chmod 644 $FCODES
48	rm $bigrams $filelist $errs
49endif
50