File:  [LON-CAPA] / doc / help / usage.pl
Revision 1.3: download - view: text, annotated - select for diffs
Tue Sep 14 22:26:17 2004 UTC (20 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: version_2_6_X, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, version_1_3_X, version_1_3_3, version_1_3_2, version_1_3_1, version_1_3_0, version_1_2_99_1, version_1_2_99_0, HEAD
- item 3) in BUG#3451, can now generate a manual from al of the help files which currently aren't in a manual

#!/usr/bin/perl
use strict;

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

my ($usage,$build_unused) = (0,0);
&GetOptions( "usage"        => \$usage,
	     "build-unused" => \$build_unused);

sub get_all_files {
    my $dir="../../loncom/html/adm/help/tex/";
    opendir(DIR,$dir);
    my @files=sort {uc($a) cmp uc($b)} (readdir(DIR));
    my @realfiles;
    foreach my $file (@files) {
	if ($file eq '.' || $file eq '..' || $file eq 'CVS' ||
	    $file eq 'Latex_Footer.tex' || $file eq 'Latex_Header.tex') {next;}
	push(@realfiles,$file);
    }
    return @realfiles;
}

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 texxml_unused {
    my ($all,$usage)=@_;
    my %all;
     foreach my $file (@{ $all }) {$all{$file}='1';}
    foreach my $list (@{ $usage }) {
	foreach my $file (@{ $list }) {
	    if (exists($all{$file})) { 
		delete($all{$file});
	    }
	}
    }
    print("<texxml>\n");
    print("<title name=\"Unused files\" />\n");
    foreach my $file (sort {uc($a) cmp uc($b)} (keys(%all))) {
	print("<section name=\"$file\">\n");
	print("<file name=\"$file\">\n");
	print("</section>\n");
    }
    print("</texxml>\n");
}

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');

    if     ($usage) {
	&print_unused(\@all_files,[\@author_usage,\@course_usage,
				   \@developer_usage]);
    } elsif($build_unused) {
	&texxml_unused(\@all_files,[\@author_usage,\@course_usage,
				    \@developer_usage]);
    } else {
	print("Please specify either --usage or --build-unused\n");
    }
}

&main;

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