Annotation of doc/help/rebuildLabelHash.pl, revision 1.8

1.1       bowersj2    1: #!/usr/bin/perl
                      2: 
1.2       bowersj2    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: 
1.1       bowersj2   30: use strict;
                     31: use GDBM_File;
1.3       bowersj2   32: use File::Spec;
1.1       bowersj2   33: 
1.3       bowersj2   34: # I had to chdir, because neither glob nor bsd_glob accept globs
                     35: # with ".." in them... sucky.
1.7       albertel   36: chdir("../../loncom/html/adm/help/");
1.1       bowersj2   37: 
                     38: # if the topic hash exists, kill it
1.7       albertel   39: unlink('fragmentLabels.gdbm') if ( -e 'fragmentLabels.gdbm' );
                     40: print("Wiped old fragmentLabels.gdbm.\n");
1.1       bowersj2   41: 
1.6       albertel   42: tie (my %fragmentLabels, 'GDBM_File', 'fragmentLabels.gdbm', &GDBM_WRCREAT(), 0660);
1.1       bowersj2   43: my $error = 0;
                     44: 
1.7       albertel   45: chdir("tex");
1.1       bowersj2   46: 
1.7       albertel   47: foreach my $file ( glob("*.tex") ) {
                     48:     open(F, $file);
                     49:     if ( index($file, "/") != "/" ) {
1.3       bowersj2   50: 	$file = substr($file, index($file, "/") + 1);
                     51:     } 
1.1       bowersj2   52:     my $contents = join("\n", <F>);
1.7       albertel   53: 
                     54:     my $found=0;
                     55:     my $found_me=0;
1.1       bowersj2   56:     # Search for labels, of the form '\label{labelname}'
1.8     ! albertel   57:     foreach my $label ( $contents =~ /\\label\{([^\}]*)\}/g ) {
1.7       albertel   58: 	$found = 1;
                     59: 	if ($file eq "$label.tex") {
                     60: 	    $found_me = 1;
                     61: 	}
1.8     ! albertel   62: 	if (exists($fragmentLabels{$label}) ) {
1.7       albertel   63: 	    print("***ERROR: '$label' in both $fragmentLabels{$label} " .
                     64: 		  "and $file. \n");
                     65: 	    $error++;
1.1       bowersj2   66: 	}
                     67: 	$fragmentLabels{$label} = $file;
                     68:     }
1.7       albertel   69:     if (!$found) {
                     70: 	$error++;
                     71: 	print("***ERROR: no labels in '$file'. \n");
                     72:     }
                     73:     if (!$found_me) {
                     74: 	$error++;
                     75: 	my ($needed_label) = ($file =~ m/(.*)\.tex/);
                     76: 	print("***ERROR: no labels for $needed_label in '$file'. \n");
                     77:     }
1.1       bowersj2   78: }
                     79: 
1.7       albertel   80: if ($error == 0) {
                     81:     print("There were no duplicate labels. Database rebuilt.\n");
                     82: } else {
1.8     ! albertel   83:     print("There were $error errors. You must correct the labels.\n");
        !            84:     exit(-1);
        !            85: }
        !            86: 
        !            87: my $found_ref=0;
        !            88: foreach my $file ( glob("*.tex") ) {
        !            89:     open(F, $file);
        !            90:     if ( index($file, "/") != "/" ) {
        !            91: 	$file = substr($file, index($file, "/") + 1);
        !            92:     } 
        !            93:     my $contents = join("\n", <F>);
        !            94:     my $label;
        !            95: 
        !            96: 
        !            97:     # Search for labels, of the form '\label{labelname}'
        !            98:     foreach my $ref ( $contents =~ /\\ref\{([^\}]*)\}/g ) {
        !            99: 	if (!exists($fragmentLabels{$ref})
        !           100: 	    && $ref ne 'course.manual.access.hlp'
        !           101: 	    && $ref ne 'author.manual.access.hlp') {
        !           102: 	    $error++;
        !           103: 	    print("***ERROR: ref $ref in $file doesn't exist in label hash. \n");
        !           104: 	} else {
        !           105: 	    $found_ref++;
        !           106: 	}
        !           107:     }
        !           108: }
        !           109: 
        !           110: if ($error == 0) {
        !           111:     print("There were no dangling references. $found_ref were checked.\n");
        !           112: } else {
        !           113:     print("There were $error errors. You must correct the dangling references.\n");
1.7       albertel  114:     exit(-1);
1.1       bowersj2  115: }
                    116: 
1.8     ! albertel  117: 
1.7       albertel  118: untie(%fragmentLabels);

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