#	START NEW ARIX SCCS HEADER
#
#	@(#) mktags: version 25.1 created on 11/27/91 at 14:39:42
#
#	Copyright (c) 1990 by Arix Corporation
#	All Rights Reserved
#
#	ident	"@(#)mktags	25.1	11/27/91 Copyright (c) 1990 by Arix Corporation"
#
#	END NEW ARIX SCCS HEADER
#

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

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 head/tags

err=/dev/null		# mktags.err

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

$ctags -t *.c head/*.h 2> $err

# 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"

egrep -f :egrep.pats head/*.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 : *.s | 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 > head/tags
