[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / CONTRIB / fptags
1 #!/bin/sh
2
3 #fptags - Create an emacs tags file for functional programs
4
5 #Please send me a copy of any modifications you make.
6 #Denis Howe <dbh@doc.ic.ac.uk>
7 #0.00 20-Sep-1991 created
8 #0.01 09-Apr-1992 don't count ==, <=, >= as definition
9 #0.02 09-Feb-1994 fix bug in fix 0.01.  Add /=.
10
11 # partain: got it from wombat.doc.ic.ac.uk:pub
12
13 #The algorithm for spotting identifiers is crude to the point of
14 #vulgarity.  Any line containing an = is assumed to define an
15 #identifier.  If there are no non-white characters before the = then
16 #the definition is assumed to start on the previous line.  White
17 #characters are space, tab and > (for literate programs).  The =s in
18 #the relations ==, <=, >= and /= are temporarily transformed while
19 #searching for =s.
20
21 #The tags file is not in the format produced by ctags but rather,
22 #that produced by etags and used by GNU-Emacs's find-tag command.
23
24 #Does not tag constructors in sum data types.
25
26 #The tags file, TAGS, is created in the current directory.  It
27 #contains an entry for each argument file.  The entry begins with a
28 #line containing just ^L.  The next line contains the filename, a
29 #comma and the number of following bytes before the next ^L or EOF.
30 #Subsequent lines should give the location within the argument file of
31 #identifier definitions.  Each line contains a prefix of a line from
32 #the argument file, a ^?, the line number within the argument file, a
33 #comma and the position of the start of that line in the argument file
34 #(first character = 1).
35
36 [ -z "$1" ] && echo usage: $0 files && exit 1
37 exec > TAGS
38 tf=/tmp/fp$$
39 for f
40 do      echo "\f"
41         sed 's/==/\1d\1d/g
42         s/>=/>\1d/g
43         s/<=/<\1d/g
44         s|/=|/\1d|g' $f | awk '
45         /^[>    ]*=/{ print prevline "\7f" NR-1 "," prevpos; }
46         /[^>    ].*=/{ print $0 "\7f" NR "," pos; }
47         { prevline = $0; prevpos = pos; pos += length($0)+1; }
48         ' pos=1 | sed 's/[       )]*=.*\7f/\7f/
49         s/\1d/=/g' > $tf
50         echo -n $f,; echo `wc -c < $tf` #lose spaces
51         cat $tf
52 done
53 rm -f $tf