3 # Generates a tag file for TCL code. Slow, but gets the job done.
5 # Written by Darren Hiebert <darren@hiebert.com>
7 program_name
=`basename $0`
9 program_author
="Darren Hiebert"
10 author_email
="darren@hiebert.com"
11 tmp_tagfile
=/tmp
/${program_name}.$$
14 Usage: $program_name [-au] [-{f|o} tagfile] [--format=n] file(s)
15 -a append to current tag file
16 -f tagfile specify output tag file name (default=tags)
19 --format=n specify tag file format (default=2)
20 --help print this help message
36 # set variable to word passed in
39 # set variable to next word on command line
40 echo "$2="'$1'"; shift"
45 while [ $# -gt 0 -a $finished -eq 0 ]
49 opt
=`echo "$1" | cut -c 3-`
51 opt_name
=`echo "$opt" | awk -F= '{print $1}'`
52 opt_value
=`echo "$opt" | awk -F= '{print $2}'`
54 format
) case "$opt_value" in
55 1|
2) format
=$opt_value;;
56 *) echo "--$opt: unsupported value" >&2; exit 1;;
59 help) echo "$usage"; exit 0;;
60 *) echo "$opt_name: unsupported option" >&2; exit 1;;
64 # chop off leading '-'
65 opt
=`echo "$1" | cut -c 2-`
69 opt_char
=`echo "$opt" | cut -c 1`
70 opt
=`echo "$opt" | cut -c 2-`
74 o|f
) eval `getparam "$opt" tagfile`;;
75 *) echo "$opt: unsupported option" >&2; exit 1;;
79 *) filelist
="$*"; break;;
83 if [ -z "$filelist" ] ;then
84 echo "$usage" >&2; exit 1
87 # awk program for generating tags
91 if [ $format -eq 2 ] ;then
96 function trim_comment(string) {
97 comment = index(string, "#")
99 string = substr(string, 0, comment-1)
102 function maketag(tagname, pattern, type, line_end) {
103 gsub(/\\/, "\\\\", pattern)
104 gsub(/\//, "\\/", pattern)
109 printf("%s\t%s\t/^%s%s/'"$ext_flags"'\n", \
110 tagname, FILENAME, pattern, terminator'"$ttype"')
112 $1 == "proc" && $3 ~ /^{/ {
113 pattern = substr($0, 0, index($0, "{"))
114 maketag($2, pattern, "f", 0)
116 /^set[ \t]/ && $2 !~ /\(/ {
117 pattern = substr($0, 0, index($0, $2) + length($2))
118 maketag($2, pattern, "v", 0)
120 /^array[ \t]*set[ \t]/ && $3 !~ /\(/ {
121 pattern = substr($0, 0, index($0, $3) + length($3))
122 maketag($3, pattern, "v", 0)
125 # add or correct the pseudo tags
127 if [ "$tagfile" != "-" ] ;then
128 if [ $append -eq 1 ]; then
129 # ensure existing sort flag is correct
130 sed -e "/^!_TAG_FILE_SORTED/s/ [01] / $sorted /" \
131 -e "/^!_TAG_FILE_FORMAT/s/ 1 / $format /" \
132 $tagfile > $tmp_tagfile
135 !_TAG_FILE_FORMAT $format /extended format; --format=1 will not append ;\" to lines/
136 !_TAG_FILE_SORTED $sorted /0=unsorted, 1=sorted/
137 !_TAG_PROGRAM_AUTHOR $program_author /$author_email/
138 !_TAG_PROGRAM_NAME $program_name //
139 !_TAG_PROGRAM_VERSION $program_version //
146 awk "$awkprg" $filelist >> $tmp_tagfile
148 if [ $sorted -eq 1 ] ;then
149 sort -u -o $tmp_tagfile $tmp_tagfile
152 if [ "$tagfile" = '-' ] ;then
155 cp $tmp_tagfile $tagfile