vgrind.sh revision 115565
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# 3. All advertising materials mentioning features or use of this software
151590Srgrimes#    must display the following acknowledgement:
161590Srgrimes#	This product includes software developed by the University of
171590Srgrimes#	California, Berkeley and its contributors.
181590Srgrimes# 4. Neither the name of the University nor the names of its contributors
191590Srgrimes#    may be used to endorse or promote products derived from this software
201590Srgrimes#    without specific prior written permission.
211590Srgrimes#
221590Srgrimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231590Srgrimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241590Srgrimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251590Srgrimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261590Srgrimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271590Srgrimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281590Srgrimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291590Srgrimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301590Srgrimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311590Srgrimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321590Srgrimes# SUCH DAMAGE.
331590Srgrimes#
341590Srgrimes#       @(#)vgrind.sh	8.1 (Berkeley) 6/6/93
351590Srgrimes#
36103905Sache# $FreeBSD: head/usr.bin/vgrind/vgrind.sh 115565 2003-05-31 21:02:50Z schweikh $
37103905Sache#
381590Srgrimes
39115565Sschweikhvoptions=""
40115565Sschweikhoptions=""
41115565Sschweikhfiles=""
42115565Sschweikhf=""
43115565Sschweikhhead=""
44115565Sschweikhvf="/usr/libexec/vfontedpr"
45115565Sschweikhtm="/usr/share/tmac"
46115565Sschweikhpostproc="psroff"
471590Srgrimes
48115565Sschweikh# Parse args
49115565Sschweikhwhile test $# -gt 0; do
50115565Sschweikh	case $1 in
51115565Sschweikh	-f)
52115565Sschweikh		f="filter"
53115565Sschweikh		options="$options -f"
54115565Sschweikh	;;
55115565Sschweikh	-t)
56115565Sschweikh		voptions="$voptions -t"
57115565Sschweikh	;;
58115565Sschweikh	-o*)
59115565Sschweikh		voptions="$voptions $1"
60115565Sschweikh	;;
61115565Sschweikh	-W)
62115565Sschweikh		voptions="$voptions -W"
63115565Sschweikh	;;
64115565Sschweikh	-d)
65115565Sschweikh		if test $# -lt 2; then
66115565Sschweikh			echo "$0: option $1 must have argument" >&2
67115565Sschweikh			exit 1
68115565Sschweikh		fi
69115565Sschweikh		options="$options $1 $2"
70115565Sschweikh		shift
71115565Sschweikh	;;
72115565Sschweikh	-h)
73115565Sschweikh		if test $# -lt 2; then
74115565Sschweikh			echo "$0: option $1 must have argument" >&2
75115565Sschweikh			exit 1
76115565Sschweikh		fi
77115565Sschweikh		head="$2"
78115565Sschweikh		shift
79115565Sschweikh	;;
80115565Sschweikh	-p)
81115565Sschweikh		if test $# -lt 2; then
82115565Sschweikh			echo "$0: option $1 must have argument" >&2
83115565Sschweikh			exit 1
84115565Sschweikh		fi
85115565Sschweikh		postproc="$2"
86115565Sschweikh		shift
87115565Sschweikh	;;
88115565Sschweikh	-*)
89115565Sschweikh		options="$options $1"
90115565Sschweikh	;;
91115565Sschweikh	*)
92115565Sschweikh		files="$files $1"
93115565Sschweikh	;;
94115565Sschweikh	esac
951590Srgrimes	shift
96115565Sschweikhdone
971590Srgrimes
98115565Sschweikhif test -r index; then
99115565Sschweikh	echo > nindex
100115565Sschweikh	for i in $files; do
101115565Sschweikh		#       make up a sed delete command for filenames
102115565Sschweikh		#       being careful about slashes.
103115565Sschweikh		echo "? $i ?d" | sed -e "s:/:\\/:g" -e "s:?:/:g" >> nindex
104115565Sschweikh	done
105115565Sschweikh	sed -f nindex index > xindex
106115565Sschweikh	if test "x$f" = xfilter; then
107115565Sschweikh		if test "x$head" != x; then
108115565Sschweikh			$vf $options -h "$head" $files
109115565Sschweikh		else
110115565Sschweikh			$vf $options $files
111115565Sschweikh		fi | cat $tm/tmac.vgrind -
1121590Srgrimes	else
113115565Sschweikh		if test "x$head" != x; then
114115565Sschweikh			$vf $options -h "$head" $files
115115565Sschweikh		else
116115565Sschweikh			$vf $options $files
117115565Sschweikh		fi | sh -c "$postproc -rx1 $voptions -i -mvgrind 2>> xindex"
118115565Sschweikh	fi
119115565Sschweikh	sort -df -k 1,2 xindex > index
120115565Sschweikh	rm nindex xindex
1211590Srgrimeselse
122115565Sschweikh	if test "x$f" = xfilter; then
123115565Sschweikh		if test "x$head" != x; then
124115565Sschweikh			$vf $options -h "$head" $files
125115565Sschweikh		else
126115565Sschweikh			$vf $options $files
127115565Sschweikh		fi | cat $tm/tmac.vgrind -
1281590Srgrimes	else
129115565Sschweikh		if test "x$head" != x; then
130115565Sschweikh			$vf $options -h "$head" $files
131115565Sschweikh		else
132115565Sschweikh			$vf $options $files
133115565Sschweikh		fi | $postproc -i $voptions -mvgrind
134115565Sschweikh	fi
135115565Sschweikhfi
136