File:  [LON-CAPA] / doc / help / rebuildLabelHash.pl
Revision 1.12: download - view: text, annotated - select for diffs
Thu Jan 6 18:11:42 2011 UTC (13 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, HEAD, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
- Prevent errors being reported about missing files in the label hash during the build
  process.

    1: #!/usr/bin/perl
    2: 
    3: # The LearningOnline Network with CAPA
    4: # Perl script to rebuild the topic->tex file hash
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # 7-16-2002 Jeremy Bowers
   29: 
   30: use strict;
   31: use GDBM_File;
   32: use File::Spec;
   33: 
   34: my $path = '../../../../../doc/help';
   35: # I had to chdir, because neither glob nor bsd_glob accept globs
   36: # with ".." in them... sucky.
   37: chdir("../../loncom/html/adm/help/");
   38: 
   39: # if the topic hash exists, kill it
   40: unlink('fragmentLabels.gdbm') if ( -e 'fragmentLabels.gdbm' );
   41: print("Wiped old fragmentLabels.gdbm.\n");
   42: 
   43: tie (my %fragmentLabels, 'GDBM_File', 'fragmentLabels.gdbm', &GDBM_WRCREAT(), 0660);
   44: my $error = 0;
   45: 
   46: chdir("tex");
   47: 
   48: foreach my $file ( glob("*.tex") ) {
   49:     open(F, $file);
   50:     if ( index($file, "/") != "/" ) {
   51: 	$file = substr($file, index($file, "/") + 1);
   52:     } 
   53:     my $contents = join("\n", <F>);
   54: 
   55:     my $found=0;
   56:     my $found_me=0;
   57:     # Search for labels, of the form '\label{labelname}'
   58:     foreach my $label ( $contents =~ /\\label\{([^\}]*)\}/g ) {
   59: 	$found = 1;
   60: 	if ($file eq "$label.tex") {
   61: 	    $found_me = 1;
   62: 	}
   63: 	if (exists($fragmentLabels{$label}) ) {
   64: 	    print("***ERROR: '$label' in both $fragmentLabels{$label} " .
   65: 		  "and $file. \n");
   66: 	    $error++;
   67: 	}
   68: 	$fragmentLabels{$label} = $file;
   69:     }
   70:     if (!$found) {
   71: 	$error++;
   72: 	print("***ERROR: no labels in '$file'. \n");
   73:     }
   74:     if (!$found_me) {
   75: 	$error++;
   76: 	my ($needed_label) = ($file =~ m/(.*)\.tex/);
   77: 	print("***ERROR: no labels for $needed_label in '$file'. \n");
   78:     }
   79: }
   80: 
   81: if ($error == 0) {
   82:     print("There were no duplicate labels. Database rebuilt.\n");
   83: } else {
   84:     print("There were $error errors. You must correct the labels.\n");
   85:     exit(-1);
   86: }
   87: 
   88: my $found_ref=0;
   89: foreach my $file ( glob("*.tex") ) {
   90:     open(my $fh , '<', $file);
   91:     if ( index($file, "/") != "/" ) {
   92: 	$file = substr($file, index($file, "/") + 1);
   93:     } 
   94:     my $contents;
   95:     foreach my $line (<$fh>) {
   96: 	next if ($line =~ /^%/);
   97: 	$contents .= $line;
   98:     }
   99:     my $label;
  100: 
  101: 
  102:     # Search for references, of the form '\ref{labelname}', and whether
  103:     # we have logged the associated \label before
  104:     foreach my $ref ( $contents =~ /\\ref\{([^\}]*)\}/g ) {
  105: 	if (!exists($fragmentLabels{$ref})
  106: 	    && $ref ne 'course.manual.access.hlp'
  107: 	    && $ref ne 'author.manual.access.hlp'
  108:             && $ref ne 'domain.manual.access.hlp'
  109:             && $ref ne 'course.manual.pdf'
  110:             && $ref ne 'author.manual.pdf'
  111:             && $ref ne 'domain.manual.pdf') {
  112: 	    $error++;
  113: 	    print("***ERROR: ref $ref in $file doesn't exist in label hash. \n");
  114: 	} else {
  115: 	    $found_ref++;
  116: 	}
  117:     }
  118: }
  119: 
  120: use HTML::TokeParser;
  121: foreach my $manual ('course.manual.texxml','author.manual.texxml','domain.manual.texxml') {
  122:     my $p = HTML::TokeParser->new($path.'/'.$manual);
  123:     if (!-e $path.'/'.$manual) {
  124: 	$error++;
  125: 	print("***ERROR: can't find manual $manual \n");
  126:     }
  127:     while (my $token = $p->get_token()) {
  128: 	if ($token->[0] eq 'S' && $token->[1] eq 'file') {
  129: 	    my $ref = $token->[2]{'name'};
  130: 	    $ref =~ s/\.tex//;
  131: 	    if (!exists($fragmentLabels{$ref})) {
  132: 		$error++;
  133: 		print("***ERROR: ref $ref in $manual doesn't exist in label hash. \n");
  134: 	    }
  135: 	}
  136:     }
  137: }
  138: 
  139: if ($error == 0) {
  140:     print("There were no dangling references. $found_ref were checked.\n");
  141: } else {
  142:     print("There were $error errors. You must correct the dangling references.\n");
  143:     exit(-1);
  144: }
  145: 
  146: 
  147: untie(%fragmentLabels);

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