File:
[LON-CAPA] /
doc /
help /
rebuildLabelHash.pl
Revision
1.11:
download - view:
text,
annotated -
select for diffs
Thu Jul 24 21:51:38 2008 UTC (16 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_9_X,
version_2_9_99_0,
version_2_9_1,
version_2_9_0,
version_2_8_X,
version_2_8_99_1,
version_2_8_99_0,
version_2_8_2,
version_2_8_1,
version_2_8_0,
version_2_7_X,
version_2_7_99_1,
version_2_7_99_0,
version_2_7_1,
version_2_7_0,
version_2_6_99_1,
version_2_10_0_RC1,
bz6209-base,
bz6209,
HEAD,
GCI_3,
GCI_2,
GCI_1
- Add entries for Domain Coordination Manual.
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: $error++;
110: print("***ERROR: ref $ref in $file doesn't exist in label hash. \n");
111: } else {
112: $found_ref++;
113: }
114: }
115: }
116:
117: use HTML::TokeParser;
118: foreach my $manual ('course.manual.texxml','author.manual.texxml','domain.manual.texxml') {
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:
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");
140: exit(-1);
141: }
142:
143:
144: untie(%fragmentLabels);
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>