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

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;
                     32: 
1.2     ! bowersj2   33: my $dirprefix = "../../loncom/html/adm/help/";
1.1       bowersj2   34: 
                     35: # if the topic hash exists, kill it
                     36: unlink 'fragmentLabels.gdbm' if ( -e $dirprefix . 'fragmentTopics.gdbm' );
                     37: 
                     38: tie (my %fragmentLabels, 'GDBM_File', $dirprefix . 'fragmentLabels.gdbm', 1, 0);
                     39: my $error = 0;
                     40: 
                     41: chdir $dirprefix;
                     42: 
                     43: while (<*.tex>) 
                     44: {
                     45:     my $file;
                     46:     $file = $_;
                     47:     open F, $file;
                     48:     my $contents = join("\n", <F>);
                     49:     my $label;
                     50:     
                     51:     # Search for labels, of the form '\label{labelname}'
                     52:     foreach $label ( $contents =~ /\\label\{([^}]*)\}/g )
                     53:     {
                     54: 	if (exists $fragmentLabels{$label} )
                     55: 	{
                     56: 	    print "***ERROR: '$label' in both $fragmentLabels{$label} " .
                     57: 	          "and $file. \n";
                     58: 	    $error = 1;
                     59: 	}
                     60: 	$fragmentLabels{$label} = $file;
                     61:     }
                     62: }
                     63: 
                     64: if ($error == 0)
                     65: {
                     66:     print "There were no duplicate labels. Database rebuilt.\n";
                     67: }
                     68: else
                     69: {
                     70:     print "There were errors. You must correct the duplicate labels.\n";
                     71: }
                     72: 
                     73: untie %fragmentLabels;

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