1115565Sschweikh#!/bin/sh
21590Srgrimes#
31590Srgrimes# Copyright (c) 1980, 1993
41590Srgrimes#	The Regents of the University of California.  All rights reserved.
51590Srgrimes#
61590Srgrimes# Redistribution and use in source and binary forms, with or without
71590Srgrimes# modification, are permitted provided that the following conditions
81590Srgrimes# are met:
91590Srgrimes# 1. Redistributions of source code must retain the above copyright
101590Srgrimes#    notice, this list of conditions and the following disclaimer.
111590Srgrimes# 2. Redistributions in binary form must reproduce the above copyright
121590Srgrimes#    notice, this list of conditions and the following disclaimer in the
131590Srgrimes#    documentation and/or other materials provided with the distribution.
141590Srgrimes# 4. Neither the name of the University nor the names of its contributors
151590Srgrimes#    may be used to endorse or promote products derived from this software
161590Srgrimes#    without specific prior written permission.
171590Srgrimes#
181590Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
191590Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
201590Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
211590Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
221590Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
231590Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
241590Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
251590Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
261590Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
271590Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
281590Srgrimes# SUCH DAMAGE.
291590Srgrimes#
301590Srgrimes#       @(#)vgrind.sh	8.1 (Berkeley) 6/6/93
311590Srgrimes#
32103905Sache# $FreeBSD$
33103905Sache#
341590Srgrimes
35115565Sschweikhvoptions=""
36115565Sschweikhoptions=""
37115565Sschweikhfiles=""
38115565Sschweikhf=""
39115565Sschweikhhead=""
40115565Sschweikhvf="/usr/libexec/vfontedpr"
41115565Sschweikhtm="/usr/share/tmac"
42115565Sschweikhpostproc="psroff"
431590Srgrimes
44115565Sschweikh# Parse args
45115565Sschweikhwhile test $# -gt 0; do
46115565Sschweikh	case $1 in
47115565Sschweikh	-f)
48115565Sschweikh		f="filter"
49115565Sschweikh		options="$options -f"
50115565Sschweikh	;;
51115565Sschweikh	-t)
52115565Sschweikh		voptions="$voptions -t"
53115565Sschweikh	;;
54115565Sschweikh	-o*)
55115565Sschweikh		voptions="$voptions $1"
56115565Sschweikh	;;
57115565Sschweikh	-W)
58115565Sschweikh		voptions="$voptions -W"
59115565Sschweikh	;;
60115565Sschweikh	-d)
61115565Sschweikh		if test $# -lt 2; then
62115565Sschweikh			echo "$0: option $1 must have argument" >&2
63115565Sschweikh			exit 1
64115565Sschweikh		fi
65115565Sschweikh		options="$options $1 $2"
66115565Sschweikh		shift
67115565Sschweikh	;;
68115565Sschweikh	-h)
69115565Sschweikh		if test $# -lt 2; then
70115565Sschweikh			echo "$0: option $1 must have argument" >&2
71115565Sschweikh			exit 1
72115565Sschweikh		fi
73115565Sschweikh		head="$2"
74115565Sschweikh		shift
75115565Sschweikh	;;
76115565Sschweikh	-p)
77115565Sschweikh		if test $# -lt 2; then
78115565Sschweikh			echo "$0: option $1 must have argument" >&2
79115565Sschweikh			exit 1
80115565Sschweikh		fi
81115565Sschweikh		postproc="$2"
82115565Sschweikh		shift
83115565Sschweikh	;;
84115565Sschweikh	-*)
85115565Sschweikh		options="$options $1"
86115565Sschweikh	;;
87115565Sschweikh	*)
88115565Sschweikh		files="$files $1"
89115565Sschweikh	;;
90115565Sschweikh	esac
911590Srgrimes	shift
92115565Sschweikhdone
931590Srgrimes
94115565Sschweikhif test -r index; then
95115565Sschweikh	echo > nindex
96115565Sschweikh	for i in $files; do
97115565Sschweikh		#       make up a sed delete command for filenames
98115565Sschweikh		#       being careful about slashes.
99115565Sschweikh		echo "? $i ?d" | sed -e "s:/:\\/:g" -e "s:?:/:g" >> nindex
100115565Sschweikh	done
101115565Sschweikh	sed -f nindex index > xindex
102115565Sschweikh	if test "x$f" = xfilter; then
103115565Sschweikh		if test "x$head" != x; then
104115565Sschweikh			$vf $options -h "$head" $files
105115565Sschweikh		else
106115565Sschweikh			$vf $options $files
107115565Sschweikh		fi | cat $tm/tmac.vgrind -
1081590Srgrimes	else
109115565Sschweikh		if test "x$head" != x; then
110115565Sschweikh			$vf $options -h "$head" $files
111115565Sschweikh		else
112115565Sschweikh			$vf $options $files
113115565Sschweikh		fi | sh -c "$postproc -rx1 $voptions -i -mvgrind 2>> xindex"
114115565Sschweikh	fi
115115565Sschweikh	sort -df -k 1,2 xindex > index
116115565Sschweikh	rm nindex xindex
1171590Srgrimeselse
118115565Sschweikh	if test "x$f" = xfilter; then
119115565Sschweikh		if test "x$head" != x; then
120115565Sschweikh			$vf $options -h "$head" $files
121115565Sschweikh		else
122115565Sschweikh			$vf $options $files
123115565Sschweikh		fi | cat $tm/tmac.vgrind -
1241590Srgrimes	else
125115565Sschweikh		if test "x$head" != x; then
126115565Sschweikh			$vf $options -h "$head" $files
127115565Sschweikh		else
128115565Sschweikh			$vf $options $files
129115565Sschweikh		fi | $postproc -i $voptions -mvgrind
130115565Sschweikh	fi
131115565Sschweikhfi
132