Annotation of doc/help/rebuildLabelHash.pl, revision 1.11
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.10 albertel 34: my $path = '../../../../../doc/help';
1.3 bowersj2 35: # I had to chdir, because neither glob nor bsd_glob accept globs
36: # with ".." in them... sucky.
1.7 albertel 37: chdir("../../loncom/html/adm/help/");
1.1 bowersj2 38:
39: # if the topic hash exists, kill it
1.7 albertel 40: unlink('fragmentLabels.gdbm') if ( -e 'fragmentLabels.gdbm' );
41: print("Wiped old fragmentLabels.gdbm.\n");
1.1 bowersj2 42:
1.6 albertel 43: tie (my %fragmentLabels, 'GDBM_File', 'fragmentLabels.gdbm', &GDBM_WRCREAT(), 0660);
1.1 bowersj2 44: my $error = 0;
45:
1.7 albertel 46: chdir("tex");
1.1 bowersj2 47:
1.7 albertel 48: foreach my $file ( glob("*.tex") ) {
49: open(F, $file);
50: if ( index($file, "/") != "/" ) {
1.3 bowersj2 51: $file = substr($file, index($file, "/") + 1);
52: }
1.1 bowersj2 53: my $contents = join("\n", <F>);
1.7 albertel 54:
55: my $found=0;
56: my $found_me=0;
1.1 bowersj2 57: # Search for labels, of the form '\label{labelname}'
1.8 albertel 58: foreach my $label ( $contents =~ /\\label\{([^\}]*)\}/g ) {
1.7 albertel 59: $found = 1;
60: if ($file eq "$label.tex") {
61: $found_me = 1;
62: }
1.8 albertel 63: if (exists($fragmentLabels{$label}) ) {
1.7 albertel 64: print("***ERROR: '$label' in both $fragmentLabels{$label} " .
65: "and $file. \n");
66: $error++;
1.1 bowersj2 67: }
68: $fragmentLabels{$label} = $file;
69: }
1.7 albertel 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: }
1.1 bowersj2 79: }
80:
1.7 albertel 81: if ($error == 0) {
82: print("There were no duplicate labels. Database rebuilt.\n");
83: } else {
1.8 albertel 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") ) {
1.10 albertel 90: open(my $fh , '<', $file);
1.8 albertel 91: if ( index($file, "/") != "/" ) {
92: $file = substr($file, index($file, "/") + 1);
93: }
1.9 albertel 94: my $contents;
1.10 albertel 95: foreach my $line (<$fh>) {
1.9 albertel 96: next if ($line =~ /^%/);
97: $contents .= $line;
98: }
1.8 albertel 99: my $label;
100:
101:
1.10 albertel 102: # Search for references, of the form '\ref{labelname}', and whether
103: # we have logged the associated \label before
1.8 albertel 104: foreach my $ref ( $contents =~ /\\ref\{([^\}]*)\}/g ) {
105: if (!exists($fragmentLabels{$ref})
106: && $ref ne 'course.manual.access.hlp'
1.11 ! raeburn 107: && $ref ne 'author.manual.access.hlp'
! 108: && $ref ne 'domain.manual.access.hlp') {
1.8 albertel 109: $error++;
110: print("***ERROR: ref $ref in $file doesn't exist in label hash. \n");
111: } else {
112: $found_ref++;
113: }
114: }
115: }
116:
1.10 albertel 117: use HTML::TokeParser;
1.11 ! raeburn 118: foreach my $manual ('course.manual.texxml','author.manual.texxml','domain.manual.texxml') {
1.10 albertel 119: my $p = HTML::TokeParser->new($path.'/'.$manual);
120: if (!-e $path.'/'.$manual) {
121: $error++;
122: print("***ERROR: can't find manual $manual \n");
123: }
124: while (my $token = $p->get_token()) {
125: if ($token->[0] eq 'S' && $token->[1] eq 'file') {
126: my $ref = $token->[2]{'name'};
127: $ref =~ s/\.tex//;
128: if (!exists($fragmentLabels{$ref})) {
129: $error++;
130: print("***ERROR: ref $ref in $manual doesn't exist in label hash. \n");
131: }
132: }
133: }
134: }
135:
1.8 albertel 136: if ($error == 0) {
137: print("There were no dangling references. $found_ref were checked.\n");
138: } else {
139: print("There were $error errors. You must correct the dangling references.\n");
1.7 albertel 140: exit(-1);
1.1 bowersj2 141: }
142:
1.8 albertel 143:
1.7 albertel 144: untie(%fragmentLabels);
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>