xref: /freebsd/usr.bin/vgrind/vgrind.sh (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
1b6a42c89SJens Schweikhardt#!/bin/sh
29b50d902SRodney W. Grimes#
3*8a16b7a1SPedro F. Giffuni# SPDX-License-Identifier: BSD-3-Clause
4*8a16b7a1SPedro F. Giffuni#
59b50d902SRodney W. Grimes# Copyright (c) 1980, 1993
69b50d902SRodney W. Grimes#	The Regents of the University of California.  All rights reserved.
79b50d902SRodney W. Grimes#
89b50d902SRodney W. Grimes# Redistribution and use in source and binary forms, with or without
99b50d902SRodney W. Grimes# modification, are permitted provided that the following conditions
109b50d902SRodney W. Grimes# are met:
119b50d902SRodney W. Grimes# 1. Redistributions of source code must retain the above copyright
129b50d902SRodney W. Grimes#    notice, this list of conditions and the following disclaimer.
139b50d902SRodney W. Grimes# 2. Redistributions in binary form must reproduce the above copyright
149b50d902SRodney W. Grimes#    notice, this list of conditions and the following disclaimer in the
159b50d902SRodney W. Grimes#    documentation and/or other materials provided with the distribution.
16fbbd9655SWarner Losh# 3. Neither the name of the University nor the names of its contributors
179b50d902SRodney W. Grimes#    may be used to endorse or promote products derived from this software
189b50d902SRodney W. Grimes#    without specific prior written permission.
199b50d902SRodney W. Grimes#
209b50d902SRodney W. Grimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
219b50d902SRodney W. Grimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
229b50d902SRodney W. Grimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
239b50d902SRodney W. Grimes# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
249b50d902SRodney W. Grimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
259b50d902SRodney W. Grimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
269b50d902SRodney W. Grimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
279b50d902SRodney W. Grimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
289b50d902SRodney W. Grimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
299b50d902SRodney W. Grimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
309b50d902SRodney W. Grimes# SUCH DAMAGE.
319b50d902SRodney W. Grimes
32b6a42c89SJens Schweikhardtvoptions=""
33b6a42c89SJens Schweikhardtoptions=""
34b6a42c89SJens Schweikhardtfiles=""
35b6a42c89SJens Schweikhardtf=""
36b6a42c89SJens Schweikhardthead=""
37b6a42c89SJens Schweikhardtvf="/usr/libexec/vfontedpr"
38b6a42c89SJens Schweikhardttm="/usr/share/tmac"
39b6a42c89SJens Schweikhardtpostproc="psroff"
409b50d902SRodney W. Grimes
41b6a42c89SJens Schweikhardt# Parse args
42b6a42c89SJens Schweikhardtwhile test $# -gt 0; do
43b6a42c89SJens Schweikhardt	case $1 in
44b6a42c89SJens Schweikhardt	-f)
45b6a42c89SJens Schweikhardt		f="filter"
46b6a42c89SJens Schweikhardt		options="$options -f"
47b6a42c89SJens Schweikhardt	;;
48b6a42c89SJens Schweikhardt	-t)
49b6a42c89SJens Schweikhardt		voptions="$voptions -t"
50b6a42c89SJens Schweikhardt	;;
51b6a42c89SJens Schweikhardt	-o*)
52b6a42c89SJens Schweikhardt		voptions="$voptions $1"
53b6a42c89SJens Schweikhardt	;;
54b6a42c89SJens Schweikhardt	-W)
55b6a42c89SJens Schweikhardt		voptions="$voptions -W"
56b6a42c89SJens Schweikhardt	;;
57b6a42c89SJens Schweikhardt	-d)
58b6a42c89SJens Schweikhardt		if test $# -lt 2; then
59b6a42c89SJens Schweikhardt			echo "$0: option $1 must have argument" >&2
60b6a42c89SJens Schweikhardt			exit 1
61b6a42c89SJens Schweikhardt		fi
62b6a42c89SJens Schweikhardt		options="$options $1 $2"
639b50d902SRodney W. Grimes		shift
64b6a42c89SJens Schweikhardt	;;
65b6a42c89SJens Schweikhardt	-h)
66b6a42c89SJens Schweikhardt		if test $# -lt 2; then
67b6a42c89SJens Schweikhardt			echo "$0: option $1 must have argument" >&2
68b6a42c89SJens Schweikhardt			exit 1
69b6a42c89SJens Schweikhardt		fi
70b6a42c89SJens Schweikhardt		head="$2"
71b6a42c89SJens Schweikhardt		shift
72b6a42c89SJens Schweikhardt	;;
73b6a42c89SJens Schweikhardt	-p)
74b6a42c89SJens Schweikhardt		if test $# -lt 2; then
75b6a42c89SJens Schweikhardt			echo "$0: option $1 must have argument" >&2
76b6a42c89SJens Schweikhardt			exit 1
77b6a42c89SJens Schweikhardt		fi
78b6a42c89SJens Schweikhardt		postproc="$2"
79b6a42c89SJens Schweikhardt		shift
80b6a42c89SJens Schweikhardt	;;
81b6a42c89SJens Schweikhardt	-*)
82b6a42c89SJens Schweikhardt		options="$options $1"
83b6a42c89SJens Schweikhardt	;;
84b6a42c89SJens Schweikhardt	*)
85b6a42c89SJens Schweikhardt		files="$files $1"
86b6a42c89SJens Schweikhardt	;;
87b6a42c89SJens Schweikhardt	esac
88b6a42c89SJens Schweikhardt	shift
89b6a42c89SJens Schweikhardtdone
909b50d902SRodney W. Grimes
91b6a42c89SJens Schweikhardtif test -r index; then
929b50d902SRodney W. Grimes	echo > nindex
93b6a42c89SJens Schweikhardt	for i in $files; do
949b50d902SRodney W. Grimes		#       make up a sed delete command for filenames
959b50d902SRodney W. Grimes		#       being careful about slashes.
969b50d902SRodney W. Grimes		echo "? $i ?d" | sed -e "s:/:\\/:g" -e "s:?:/:g" >> nindex
97b6a42c89SJens Schweikhardt	done
989b50d902SRodney W. Grimes	sed -f nindex index > xindex
99b6a42c89SJens Schweikhardt	if test "x$f" = xfilter; then
100b6a42c89SJens Schweikhardt		if test "x$head" != x; then
101b6a42c89SJens Schweikhardt			$vf $options -h "$head" $files
1029b50d902SRodney W. Grimes		else
103b6a42c89SJens Schweikhardt			$vf $options $files
104b6a42c89SJens Schweikhardt		fi | cat $tm/tmac.vgrind -
1059b50d902SRodney W. Grimes	else
106b6a42c89SJens Schweikhardt		if test "x$head" != x; then
107b6a42c89SJens Schweikhardt			$vf $options -h "$head" $files
1089b50d902SRodney W. Grimes		else
109b6a42c89SJens Schweikhardt			$vf $options $files
110b6a42c89SJens Schweikhardt		fi | sh -c "$postproc -rx1 $voptions -i -mvgrind 2>> xindex"
111b6a42c89SJens Schweikhardt	fi
11273be6d69SAndrey A. Chernov	sort -df -k 1,2 xindex > index
1139b50d902SRodney W. Grimes	rm nindex xindex
1149b50d902SRodney W. Grimeselse
115b6a42c89SJens Schweikhardt	if test "x$f" = xfilter; then
116b6a42c89SJens Schweikhardt		if test "x$head" != x; then
117b6a42c89SJens Schweikhardt			$vf $options -h "$head" $files
1189b50d902SRodney W. Grimes		else
119b6a42c89SJens Schweikhardt			$vf $options $files
120b6a42c89SJens Schweikhardt		fi | cat $tm/tmac.vgrind -
1219b50d902SRodney W. Grimes	else
122b6a42c89SJens Schweikhardt		if test "x$head" != x; then
123b6a42c89SJens Schweikhardt			$vf $options -h "$head" $files
1249b50d902SRodney W. Grimes		else
125b6a42c89SJens Schweikhardt			$vf $options $files
126b6a42c89SJens Schweikhardt		fi | $postproc -i $voptions -mvgrind
127b6a42c89SJens Schweikhardt	fi
128b6a42c89SJens Schweikhardtfi
129