summaryrefslogtreecommitdiff
path: root/support/splint/scripts/cslist.pl
blob: 2954e23e0323045088afe9b0c0f09e7d482155ed (plain)
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
#!/usr/bin/perl

# Copyright 2012-2022, Alexander Shibakov
# This file is part of SPLinT
#
# SPLinT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SPLinT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SPLinT.  If not, see <http://www.gnu.org/licenses/>.

use Getopt::Long;
use Pod::Usage;

my $man = 0;
my $help = 0;

#Getopt::Long::Configure ("bundling"); # to allow -abc to set a, b, and c

GetOptions ("help|?" => \$help, 
             man => \$man,
    ) or pod2usage(2);

pod2usage(-exitval => 0, -verbose => 1) if $help;
pod2usage(-exitval => 0, -verbose => 2) if $man;

for ($i = 0; $i <= $#ARGV; $i++) {

    open FILE, "<$ARGV[$i]" or die "Cannot open file $ARGV[$i]!\n";
    $filename = $ARGV[$i];

    while(<FILE>) {

        $text = $_;
        
        while( $text =~ /(\\newcount|\\newtoks|\\newdimen|\\newif|\\let|\\([exg]|char|toks|count)?def)\w*(\\[a-zA-Z@]+)/g ) {

            $cs = $3;
	    push @all, $cs;

	    if ( defined $secse{$cs}->{$filename} ) { $secse{$cs}->{$filename}++; }
	    else { $secse{$cs}->{$filename} = 1; };
	    
	}
	
    }
}
#print keys %secse;
@alphsecs = sort keys %secse;

foreach $ocs (@alphsecs) {

    print "$ocs \% ". ref $secse{$osc};
    @fnames = sort keys %{$secse{$ocs}};
    foreach $fname (@fnames) { 
	print " $fname ($secse{$ocs}->{$fname} occurence";
        if ( $secse{$ocs}->{$fname} > 1 ) {print "s";}   
        print ")"; 
    }
    print "\n";
}

print "\n";
$i = $#alphsecs;
$i++;
print "total sequences: $i\n";

__END__

=head1 CSLIST

cslist.pl - output a list of all control sequences in the input files.

=head1 SYNOPSIS

cslist.pl [options] input_files


 Options:
   --help|-h|-?      brief help message
   --man|-m          full documentation

=head1 OPTIONS

=over 8

=item B<--help>

Print a brief help message and exit.

=item B<--man>

Print the manual page and exit.

=back

=head1 DESCRIPTION

B<cslist.pl> will read the given <input_files>, and produce a list of all the
B<TeX> control sequences defined in those files (a contorl sequence is considered
I<defined> in a file B<foo.tex> if one of B<\def>, B<\let>, B<\new...>, or similar
preceeds it in B<foo.tex>. 

=cut