Debian Codegraph @

debian/helpztags

raw
1 #!/usr/bin/perl
2 #
3 # helpztags generates tags for Vim helpfiles, for both .txt and .txt.gz files
4 # Author: Jakub Turski <[email protected]>
5 # Artur R. Czechowski <[email protected]>
6 # Version: 0.4
7
8 # Please use following command for generate a manual file:
9 # pod2man -c "User Commands" -s 1 -q none -r "vim 6.2" -d "September 2003" helpztags helpztags.1
10
11 =head1 NAME
12
13 helpztags - generate the help tags file for directory
14
15 =head1 SYNOPSIS
16
17 helpztags F<DIRS>...
18
19 =head1 DESCRIPTION
20
21 F<helpztags> scans given directories for F<*.txt> and F<*.txt.gz> files.
22 Each file is scanned for tags used in F<vim> help files. For each directory
23 proper F<tags> file is generated.
24
25 There should be at least one directory given. In other case program exits
26 with error.
27
28 =head1 AUTHORS
29
30 Written by Jakub Turski and Artur R. Czechowski based on idea
31 contained in C<vim> sources for its C<:helptags command>.
32
33 =head1 REPORTING BUGS
34
35 Please use a Debian C<reportbug> command or procedure described at
36 C<http://bugs.debian.org/>.
37
38 =head1 SEE ALSO
39
40 Read C<:help helptags> in F<vim> for detailed information about helptags.
41
42 =cut
43
44 use strict;
45 use warnings;
46 use File::Glob ':globally';
47 use POSIX qw(getcwd);
48
49 die "Error: no directories given. Check manpage for details.\n" unless @ARGV;
50
51 my $startdir=getcwd();
52 my %tags;
53
54 foreach my $dir (@ARGV) {
55 chdir $dir or next;
56 print "Processing ".$dir."\n";
57 foreach my $file (<*.{gz,txt,??x}>) {
58 next unless $file =~ m/^[\w.-]+\.(?:txt|([[:alpha:]]{2})x)(?:.gz)?$/;
59 my $suffix = '';
60 if ($1) {
61 $suffix = "-$1";
62 }
63 my $open = ($file =~ /\.gz$/) ? open(GZ, '-|', 'zcat', $file) : open(GZ, $file);
64 if (!$open) {
65 chdir $startdir;
66 next;
67 }
68 while (<GZ>) {
69 # From vim73/src/ex_cmds.c, helptags_one, lines 6443-6445
70 #
71 # Only accept a *tag* when it consists of valid
72 # characters, there is white space before it and is
73 # followed by a white character or end-of-line.
74 while (/(?:(?<=^)|(?<=\s))\*([^*\s|]+?)\*(?:(?=\s)|(?=$))/g) {
75 $tags{"tags$suffix"}{$1}=$file;
76 }
77 }
78 close(GZ);
79 }
80 while (my ($tagfile, $tags) = each %tags) {
81 next unless %{$tags};
82 open(TAGSFILE, '>', $tagfile) || die "Error: Cannot open $dir/$tagfile for writing.\n";
83 foreach my $tag (sort keys %{$tags}) {
84 print TAGSFILE "$tag\t$tags->{$tag}\t/*";
85 $tag =~ s/\\/\\\\/g;
86 $tag =~ s@/@\/@g;
87 print TAGSFILE "$tag*\n";
88 }
89 close TAGSFILE;
90 }
91 chdir $startdir;
92 }