:
#	START NEW ARIX SCCS HEADER
#
#	@(#) mktags: version 25.1 created on 11/27/91 at 15:00:46
#
#	Copyright (c) 1990 by Arix Corporation
#	All Rights Reserved
#
#	@(#)mktags	25.1	11/27/91 Copyright (c) 1990 by Arix Corporation
#
#	END NEW ARIX SCCS HEADER
#
#
# mktags -- make tags files that work regardless of the directory
#
#	usage:  mktags [machine_type]

PATH=/bin:/usr/bin; export PATH

if [ $# -lt 1 ]
then
	MACH=M68020
else
	MACH=$1
fi

ctags=/usr/local/bin/ctags
if [ ! -x $ctags ]
then
	ctags=/usr/lbin/ctags
	if [ ! -x $ctags ]
	then
		echo "mktags: can't locate public domain ctags!!!"
		exit 1
	fi
fi

/bin/rm -f tags io/tags os/tags os/$MACH/tags fs/s5/tags ml/tags cf/tags \
	fs/du/tags fs/s54k/tags nudnix/tags security/tags \
	sys/tags sys/*/tags mktags.err

err=/dev/null		# mktags.err

# let ctags do most of the hard work (public domain ctags will do typedefs too)

$ctags -t os/*.c os/$MACH/*.c io/*.c fs/s5/*.c 2> $err
mv tags tags1
$ctags -t fs/s54k/*.c fs/du/*.c nudnix/*.c security/*.c 2> $err
cat tags >> tags1
$ctags -t sys/[a-mA-M]*.h 2> $err
cat tags >> tags1
$ctags -t sys/[n-zN-Z]*.h 2> $err
cat tags >> tags1
$ctags -t sys/$MACH/*.h sys/M68k/*.h sys/fs/*.h 2> $err
cat tags1 >> tags
/bin/rm -f tags1

# use ed to truncate patterns and undo ctags's Mmain convention

echo '
1,$s/(.*$/(/
/^Mmain/s/Mm/m/
w
q' | ed tags >> $err 2>&1

# now use egrep and sed to include extra typedef, struct, and union stuff

t='	'				# a tab
wt='[ 	]*'				# match any white space
nwt='[^ 	]*'			# match all until white space
file="\([^:]*\)"			# match (and remember) filename
id='\([A-Z_a-z][0-9A-Z_a-z]*\)'		# match (and remember) identifier
nid='[^0-9A-Z_a-z]*'			# match until an identifier

p1="\|struct|s|^$file:\(${wt}typedef${wt}struct${wt}\)${id}.*$|\3$t\1$t/^\2\3|p"
p2="\|union|s|^$file:\(${wt}typedef${wt}union${wt}\)${id}.*$|\3$t\1$t/^\2\3|p"
p3="\|}|s|^$file:\(${wt}}${nid}\)${id}.*$|\3$t\1$t/^\2\3|p"
p4="\|struct|s|^$file:\(${wt}struct${wt}\)${id}\(${wt}{\).*$|\3$t\1$t/^\2\3\4|p"
p5="\|union|s|^$file:\(${wt}union${wt}\)${id}\(${wt}{\).*$|\3$t\1$t/^\2\3\4|p"

#
# break it up so it would also work on A1000
#
egrep -f :egrep.pats sys/[a-mA-M]*.h | \
	sed -n -e "$p1" -e "$p2" -e "$p3" -e "$p4" -e "$p5" >> tags
egrep -f :egrep.pats sys/[n-zN-Z]*.h | \
	sed -n -e "$p1" -e "$p2" -e "$p3" -e "$p4" -e "$p5" >> tags
egrep -f :egrep.pats sys/*/*.h | \
	sed -n -e "$p1" -e "$p2" -e "$p3" -e "$p4" -e "$p5" >> tags

# now more egrep and sed for the code in the ml directory

p1="\|:|s|^$file:\([A-Z_a-z][0-9%A-Z_a-z]*\):.*$|\2$t\1$t/^\2:|p"

egrep : ml/*.s `find ml/$MACH -name '*.s' -print` | sed -n -e "$p1" >> tags

sort -u +0 -1 tags -o tags		# sort 'em

# process tags with sed to do the relative pathnames for subdirectories

tb='[	]*'				# match any tabs
ntb='[^	]*'				# match all until a tab

sed -e "s/^\($ntb\)$tb\($ntb\)$tb\(.*\)$/\1$t..\/\2$t\3/" tags > io/tags
ln -f io/tags os/tags
ln -f io/tags sys/tags
ln -f io/tags ml/tags
ln -f io/tags cf/tags
ln -f io/tags nudnix/tags
ln -f io/tags security/tags

sed -e "s/^\($ntb\)$tb\($ntb\)$tb\(.*\)$/\1$t..\/..\/\2$t\3/" tags > fs/s5/tags
ln -f fs/s5/tags fs/du/tags
ln -f fs/s5/tags fs/s54k/tags
ln -f fs/s5/tags os/$MACH/tags
ln -f fs/s5/tags sys/fs/tags
