File:  [LON-CAPA] / doc / help / usage.pl
Revision 1.2: download - view: text, annotated - select for diffs
Tue Sep 14 19:57:15 2004 UTC (19 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- addin which manual it is in

#!/usr/bin/perl
use strict;

use HTML::TokeParser;
use Getopt::Long;

my ($help) = (0,0,0);
&GetOptions( "help"     => \$help);

sub get_all_files {
    my $dir="../../loncom/html/adm/help/tex/";
    opendir(DIR,$dir);
    my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
    return @files;
}

sub get_usage {
    my ($which)=@_;
    my @files;
    my $p = HTML::TokeParser->new("$which.manual.texxml");
    while (my $token = $p->get_token()) {
	if ($token->[0] eq 'S' && $token->[1] eq 'file') {
	    push(@files,$token->[2]{'name'});
	}
    }
    return @files;
}

sub print_unused {
    my ($all,$usage)=@_;
    my %all;
    my %no_exist;
    foreach my $file (@{ $all }) {$all{$file}=[];}
    my @order=('author','course','developer');
    foreach my $list (@{ $usage }) {
	foreach my $file (@{ $list }) {
	    if (exists($all{$file})) { 
		push(@{$all{$file}},$order[0]);
	    } else {
		push(@{$no_exist{$file}},$order[0]);
	    }
	}
	shift(@order);
    }
    print("Usage count for existing Files:\n");
    foreach my $file (sort {uc($a) cmp uc($b)} (keys(%all))) {
	if (scalar(@{ $all{$file} }) ne 0) {
	    printf("%-50s: %s in %s\n",$file,scalar(@{$all{$file}}),
		   join(',',@{$all{$file}}));
	} else {
	    printf("%-50s: %s\n",$file,scalar(@{$all{$file}}));
	}
    }
    print("Usage count for nonexistint Files:\n");
    foreach my $file (sort {uc($a) cmp uc($b)} (keys(%no_exist))) {
	printf("%-50s: %s in %s\n",$file,scalar(@{$no_exist{$file}}),
	       join(',',@{$no_exist{$file}}));
    }
}

sub main {
    my @all_files=&get_all_files();
    my @author_usage=&get_usage('author');
    my @course_usage=&get_usage('course');
    my @developer_usage=&get_usage('developer');

    &print_unused(\@all_files,[\@author_usage,\@course_usage,
			       \@developer_usage]);
}

&main;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>