117592Swosch#!/bin/sh
217592Swosch#
317849Swosch# Copyright (c) September 1995 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
417849Swosch# All rights reserved.
517592Swosch#
617849Swosch# Redistribution and use in source and binary forms, with or without
717849Swosch# modification, are permitted provided that the following conditions
817849Swosch# are met:
917849Swosch# 1. Redistributions of source code must retain the above copyright
1017849Swosch#    notice, this list of conditions and the following disclaimer.
1117849Swosch# 2. Redistributions in binary form must reproduce the above copyright
1217849Swosch#    notice, this list of conditions and the following disclaimer in the
1317849Swosch#    documentation and/or other materials provided with the distribution.
1417849Swosch#
1517849Swosch# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1617849Swosch# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717849Swosch# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1817849Swosch# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1917849Swosch# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2017849Swosch# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2117849Swosch# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2217849Swosch# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2317849Swosch# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2417849Swosch# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2517849Swosch# SUCH DAMAGE.
2617849Swosch#
2717592Swosch# concatdb - concatenate locate databases
2817592Swosch# 
2917592Swosch# usage: concatdb database1 ... databaseN > newdb
3017592Swosch#
3117592Swosch# Sequence of databases is important.
3217592Swosch#
3350477Speter# $FreeBSD$
3417592Swosch
3517592Swosch# The directory containing locate subprograms
3634312Swosch: ${LIBEXECDIR:=/usr/libexec}; export LIBEXECDIR
3717592Swosch
3817592SwoschPATH=$LIBEXECDIR:/bin:/usr/bin:$PATH; export PATH
3917592Swosch
4017592Swoschumask 077			# protect temp files
4117592Swosch
4234313Swosch: ${TMPDIR:=/var/tmp}; export TMPDIR;
4334313Swoschtest -d "$TMPDIR" || TMPDIR=/var/tmp
4417592Swosch
4517592Swosch# utilities to built locate database
4634312Swosch: ${bigram:=locate.bigram}
4734312Swosch: ${code:=locate.code}
4834312Swosch: ${sort:=sort}
4934312Swosch: ${locate:=locate}
5017592Swosch
5117592Swosch
5217592Swoschcase $# in 
5317592Swosch        [01]) 	echo 'usage: concatdb databases1 ... databaseN > newdb'
5417592Swosch		exit 1
5517592Swosch		;;
5617592Swoschesac
5717592Swosch
5817592Swosch
5955835Skrisbigrams=`mktemp ${TMPDIR=/tmp}/_bigrams.XXXXXXXXXX` || exit 1
6017592Swoschtrap 'rm -f $bigrams' 0 1 2 3 5 10 15
6117592Swosch
6217592Swoschfor db 
6317592Swoschdo
6417592Swosch       $locate -d $db /
6517592Swoschdone | $bigram | $sort -nr | awk 'NR <= 128 { printf $2 }' > $bigrams
6617592Swosch
6717592Swoschfor db
6817592Swoschdo
6917592Swosch	$locate -d $db /
7017592Swoschdone | $code $bigrams
71