3 ##Convert an Emacs-style TAGS file to a standard ctags file.
4 ##Runs in a single pass over the TAGS file and keeps the first
5 ##tag entry found, and the file name and line number the tag can
7 ##Then it opens all relevant files and builds the regular expression
9 ##Run over a few test files and compared with a real ctags file shows
10 ##only extra tags in the translated file, which probably won't hurt
17 my ($tag,$line_no,$line);
24 ##Grab next line and parse it for the filename
32 ##Figure out how many records in this line and
33 ##extract the tag name and the line that it is found on
36 ($tag,$line_no) = /\x7F(\w+)\x01(\d+)/;
38 ##Take only the first entry per tag
39 next if defined($tags{$tag});
40 $tags{$tag}{FILE} = $filename;
41 $tags{$tag}{LINE_NO} = $line_no;
45 ($tag,$line_no) = /(\w+)\s*\x7F(\d+),/;
47 ##Take only the first entry per tag
48 next if defined($tags{$tag});
49 $tags{$tag}{FILE} = $filename;
50 $tags{$tag}{LINE_NO} = $line_no;
54 foreach $filename (keys %files) {
55 open FILE, $filename or die "Couldn't open $filename: $!\n";
59 foreach $tag ( keys %tags ) {
60 next unless $filename eq $tags{$tag}{FILE};
61 $line = $lines[$tags{$tag}{LINE_NO}-1];
62 if (length($line) >= 50) {
63 $line = substr($line,0,50);
69 $tags{$tag}{LINE} = join '', '/^',$line,'/';
73 foreach $tag ( sort keys %tags ) {
74 print "$tag\t$tags{$tag}{FILE}\t$tags{$tag}{LINE}\n";