Start anew
[git/jnareb-git.git] / share / vim / vim58 / tools / tcltags
blob9524152794de35a3758b660e83558e12c7e971d7
1 #!/bin/sh
2 # vim:ts=4:
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`
8 program_version="0.3"
9 program_author="Darren Hiebert"
10 author_email="darren@hiebert.com"
11 tmp_tagfile=/tmp/${program_name}.$$
13 usage="\
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)
17 -o alternative for -f
18 -u unsorted
19 --format=n specify tag file format (default=2)
20 --help print this help message
23 # defaults
25 append=0
26 format=2
27 sorted=1
28 tagfile=tags
29 filelist=
31 # read options
33 getparam()
35 if [ -n "$1" ]; then
36 # set variable to word passed in
37 echo "$2='$1'; opt="
38 else
39 # set variable to next word on command line
40 echo "$2="'$1'"; shift"
44 finished=0
45 while [ $# -gt 0 -a $finished -eq 0 ]
47 case "$1" in
48 --*)
49 opt=`echo "$1" | cut -c 3-`
50 shift
51 opt_name=`echo "$opt" | awk -F= '{print $1}'`
52 opt_value=`echo "$opt" | awk -F= '{print $2}'`
53 case "$opt_name" in
54 format) case "$opt_value" in
55 1|2) format=$opt_value;;
56 *) echo "--$opt: unsupported value" >&2; exit 1;;
57 esac
59 help) echo "$usage"; exit 0;;
60 *) echo "$opt_name: unsupported option" >&2; exit 1;;
61 esac
63 -*)
64 # chop off leading '-'
65 opt=`echo "$1" | cut -c 2-`
66 shift
67 while [ -n "$opt" ]
69 opt_char=`echo "$opt" | cut -c 1`
70 opt=`echo "$opt" | cut -c 2-`
71 case "$opt_char" in
72 a) append=1;;
73 u) sorted=0;;
74 o|f) eval `getparam "$opt" tagfile`;;
75 *) echo "$opt: unsupported option" >&2; exit 1;;
76 esac
77 done
79 *) filelist="$*"; break;;
80 esac
81 done
83 if [ -z "$filelist" ] ;then
84 echo "$usage" >&2; exit 1
87 # awk program for generating tags
89 ext_flags=""
90 ttype=""
91 if [ $format -eq 2 ] ;then
92 ext_flags=';\" %s'
93 ttype=", type"
95 awkprg='
96 function trim_comment(string) {
97 comment = index(string, "#")
98 if (comment != 0)
99 string = substr(string, 0, comment-1)
100 return string
102 function maketag(tagname, pattern, type, line_end) {
103 gsub(/\\/, "\\\\", pattern)
104 gsub(/\//, "\\/", pattern)
105 if (line_end)
106 terminator="$"
107 else
108 terminator=""
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
133 else
134 echo -ne "\
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 //
140 " > $tmp_tagfile
144 # generate tags
146 awk "$awkprg" $filelist >> $tmp_tagfile
148 if [ $sorted -eq 1 ] ;then
149 sort -u -o $tmp_tagfile $tmp_tagfile
152 if [ "$tagfile" = '-' ] ;then
153 cat $tmp_tagfile
154 else
155 cp $tmp_tagfile $tagfile
157 rm $tmp_tagfile
159 exit 0