: mktags -- make tags files that work regardless of the directory

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

/bin/rm -f tags 

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

ctags=~nelson/bin/ctags
$ctags -t */*.[csh] 2>/dev/null

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

echo '
1,$s/(.*$/(/
/^Mmain/s/Mm/m/
w
q' | ed tags >> /dev/null 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 ~nelson/bin/:egrep.pats */*.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
