summaryrefslogtreecommitdiff
path: root/macros/plain/contrib/pdcmac/dtxtags
blob: 97c5949c6fcc954cc026218ff4b740154d7f933c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /bin/sh

# dtxtags -- getenerate a TAGS file for the DTX files
version="1.1 Time-stamp: <pdc 1995-04-06>"

# The grep line produces LINE:BYTE:PATTERN
#  the sed converts this to LINE:BYTE:PATTERN:TAG

tmp=${TMP-/tmp}/mktags$$
trap 'rm -f $tmp*' 0

me=`basename $0`
outfile=TAGS

touch $tmp
while test $# -gt 0; do
	case $1 in
	    --o*=*)
		outfile=`expr $1 : '.*=\(.*\)$'` ;;
	    -o|--o*)
		outfile=$2; shift ;;
	    -o*)
		outfile=`expr $1 : '-.\(.*\)$'` ;;
	    -h|--h*)
		cat <<@EOF
$me: construct an etags-style tags file from DTX files.

USAGE:
    $me [ --output=OUTFILE ] [ INFILE... ]
    $me --help | --version
@EOF
		exit 0 ;;
	    -V|--v*)
		echo This is $me $version
		exit 0 ;;
	    -*)
		echo >&2 $me: $1: not understood, try $me --help
		exit 2 ;;
	    *)
		i=$1
		echo >&2 $1:
		egrep -nb '^[	 ]\|[ 	]*\\([a-z]*def|new)' <$1 | 
		sed '
			s/\([ 	]*|\\[a-z]*\\[A-Za-z]*\).*$/\1/
			t finish
			s/\([ 	]*|\\[a-z]*\\.\).*$/\1/
			t finish
			s/\([ 	]*|\\[a-z]*[^a-z]\).*$/\1/
			: finish
			s/\([0-9]*\):\([0-9]*\):\(.*\)/\3\1,\2/
		' > $tmp.a
		wc $tmp.a
		echo '' >> $tmp
		echo $1,`wc -c <$tmp.a` >>$tmp
		cat $tmp.a >> $tmp 
		;;
	esac
	shift

done

mv 2>/dev/null $outfile $outfile.bak && 
echo >&2 backup written to $outfile.bak

mv $tmp $outfile 

exit 0