BSD 4_3_Reno release
[unix-history] / usr / libexec / locate.updatedb
CommitLineData
1c15e888
C
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# Redistribution and use in source and binary forms are permitted
10# provided that the above copyright notice and this paragraph are
11# duplicated in all such forms and that any documentation,
12# advertising materials, and other materials related to such
13# distribution and use acknowledge that the software was developed
14# by the University of California, Berkeley. The name of the
15# University may not be used to endorse or promote products derived
16# from this software without specific prior written permission.
17# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
19# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20#
21# @(#)updatedb.csh 4.12 (Berkeley) 3/11/90
22#
23set SRCHPATHS = "/" # directories to be put in the database
24set LIBDIR = /usr/libexec # for subprograms
25if (! $?TMPDIR) set TMPDIR = /var/tmp # for temp files
26set FCODES = /var/db/locate.database # the database
27
28set path = ( /bin /usr/bin )
29set bigrams = $TMPDIR/f.bigrams$$
30set filelist = $TMPDIR/f.list$$
31set errs = $TMPDIR/f.errs$$
32
33# Make a file list and compute common bigrams.
34# Alphabetize '/' before any other char with 'tr'.
35# If the system is very short of sort space, 'bigram' can be made
36# smarter to accumulate common bigrams directly without sorting
37# ('awk', with its associative memory capacity, can do this in several
38# lines, but is too slow, and runs out of string space on small machines).
39
40find ${SRCHPATHS} -print | tr '/' '\001' | \
41 (sort -f; echo $status > $errs) | \
42 tr '\001' '/' >$filelist
43$LIBDIR/locate.bigram <$filelist | \
44 (sort; echo $status >> $errs) | uniq -c | sort -nr | \
45 awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $bigrams
46
47# code the file list
48
49if { grep -s -v 0 $errs } then
50 printf 'locate: updatedb failed\n\n'
51else
52 $LIBDIR/locate.code $bigrams < $filelist > $FCODES
53 chmod 644 $FCODES
54 rm $bigrams $filelist $errs
55endif