-
Notifications
You must be signed in to change notification settings - Fork 4
/
tcltags
executable file
·114 lines (96 loc) · 3.32 KB
/
tcltags
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/local/itcl/bin/tclsh7.4
# @(#) tcltags.tcl 1.1 21 Sep 1994 (C) SNI AG; MR STO SI 134, MR OI 2
#
# Make Emacs-style TAGS file for Tcl source.
# Tom Tromey <[email protected]> Mon Feb 15 1993
# $Id: tcltags,v 1.1.1.1 2009/03/31 14:11:52 cguirao Exp $
#
# tcltags is not part of GNU Emacs, but is distributed under the same
# terms (IE the GNU Public License). tcltags is really only useful
# with GNU Emacs anyway.
# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY. No author or distributor
# accepts responsibility to anyone for the consequences of using it
# or for whether it serves any particular purpose or works at all,
# unless he says so in writing. Refer to the GNU Emacs General Public
# License for full details.
# Everyone is granted permission to copy, modify and redistribute
# GNU Emacs, but only under the conditions described in the
# GNU Emacs General Public License. A copy of this license is
# supposed to have been given to you along with GNU Emacs so you
# can know your rights and responsibilities. It should be in a
# file named COPYING. Among other things, the copyright notice
# and this notice must be preserved on all copies.
# KNOWN BUGS:
# * Should support updating existing tags files, ctags format, etc.
# * Should integrate with etags program somehow.
# Configuration stuff:
set verbose 1
#
# "rexp" is an array of regular expressions. Each must have exactly one
# parenthesized subexpression, which should match the tag exactly.
# The array indices are unimportant. The regexp as a whole should
# match the line containing the tag, up to the tag but not past it.
#
# Bogus quoting gyrations because Tcl regexps interpret \t as
# "t" and not TAB.
set rexp(proc) "^proc\[\ \t\]+(\[^\ \t\]+)"
set rexp(method) "^\[\ \t\]+method\[\ \t\]+(\[^\ \t\]+)"
set rexp(itcl_class) "^itcl_class\[\ \t\]+(\[^\ \t\]+)"
set rexp(class) "^class\[\ \t\]+(\[^\ \t\]+)"
# Next two are for local Tcl procs, for example purposes only.
# I can't give out defvar and defoption, sorry.
# set rexp(defvar) "^defvar\[\ \t\]+(\[^\ \t\]+)"
# set rexp(defoption) "^defoption\[\ \t\]+(\[^\ \t\]+)"
#
# Figure out tags for one file.
#
proc tagify_file {file TAGS} {
global rexp verbose
if $verbose then {
puts stderr "Doing $file..." nonewline
}
set f [open $file r]
set where 0
set lineNo 0
while {[gets $f line] >= 0} {
foreach try [array names rexp] {
if [regexp $rexp($try) $line match tag] then {
if [info exists fileTags($tag)] then {
puts stderr "\n\tDuplicate tag $tag, ignoring"
} else {
set fileTags($tag) $match
append fileTags($tag) \177
append fileTags($tag) $lineNo,$where
append fileTags($tag) \n
}
break
}
}
incr where [string length $line]
incr lineNo
}
close $f
# Now sort list by tag, and create entry, but only if a tag was
# found.
set entry {}
if [string length [info locals fileTags]] then {
foreach tag [lsort [array names fileTags]] {
append entry $fileTags($tag)
}
}
# Write file part and then entry to TAGS file.
puts $TAGS \014
puts $TAGS $file,[string length $entry]
puts $TAGS $entry nonewline
if $verbose then {
puts stderr done
}
}
# Open output file
set TAGS [open TAGS w]
# Munge every file listed on the command line.
foreach file $argv {
tagify_file $file $TAGS
}
close $TAGS