File:
[LON-CAPA] /
doc /
help /
rebuildLabelHash.pl
Revision
1.10:
download - view:
text,
annotated -
select for diffs
Fri Aug 24 23:50:28 2007 UTC (17 years, 1 month ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_6_X,
version_2_6_99_0,
version_2_6_3,
version_2_6_2,
version_2_6_1,
version_2_6_0,
version_2_5_X,
version_2_5_99_1,
version_2_5_99_0,
version_2_5_2,
version_2_5_1,
HEAD
- validate the manual <file refs
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: $error++;
109: print("***ERROR: ref $ref in $file doesn't exist in label hash. \n");
110: } else {
111: $found_ref++;
112: }
113: }
114: }
115:
116: use HTML::TokeParser;
117: foreach my $manual ('course.manual.texxml','author.manual.texxml') {
118: my $p = HTML::TokeParser->new($path.'/'.$manual);
119: if (!-e $path.'/'.$manual) {
120: $error++;
121: print("***ERROR: can't find manual $manual \n");
122: }
123: while (my $token = $p->get_token()) {
124: if ($token->[0] eq 'S' && $token->[1] eq 'file') {
125: my $ref = $token->[2]{'name'};
126: $ref =~ s/\.tex//;
127: if (!exists($fragmentLabels{$ref})) {
128: $error++;
129: print("***ERROR: ref $ref in $manual doesn't exist in label hash. \n");
130: }
131: }
132: }
133: }
134:
135: if ($error == 0) {
136: print("There were no dangling references. $found_ref were checked.\n");
137: } else {
138: print("There were $error errors. You must correct the dangling references.\n");
139: exit(-1);
140: }
141:
142:
143: untie(%fragmentLabels);
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>