1 |
#!/usr/bin/perl -w |
2 |
|
3 |
#VARIABLES |
4 |
$DEBUG=1; |
5 |
$BUILDALLFILES=0; |
6 |
|
7 |
#DIRECTORIES (ABSOLUTE PATHS) |
8 |
$targetdir = "/u/httpd/html/devel/sealion/"; # Web site location |
9 |
$homedir = "/u/httpd/html/devel/buildweb/"; # This code dir |
10 |
$latexroot = $homedir."latex/"; # LaTeX pages |
11 |
$vdbroot = $homedir."vdb/"; # VDB pages |
12 |
$templatedir = $homedir."templates/"; # Conversion templates |
13 |
$pfilesdir = $homedir."program_files/"; # Program/config files |
14 |
|
15 |
# PROCESS COMMAND LINE ARGUMENTS |
16 |
foreach $_ (@ARGV) { |
17 |
if (/--targetdir=(.*)/) {$targetdir=endslash($1); |
18 |
print "Setting targetdir = $targetdir\n";}; |
19 |
if (/--homedir=(.*)/) {$homedir=endslash($1); |
20 |
print "Setting homedir = $homedir\n";}; |
21 |
if (/--latexroot=(.*)/) {$latexroot=endslash($1); |
22 |
print "Setting latexroot = $latexroot\n";}; |
23 |
if (/--vdbroot=(.*)/) {$vdbroot=endslash($1); |
24 |
print "Setting vdbroot = $vdbroot\n";}; |
25 |
if (/--templatedir=(.*)/) {$templatedir=endslash($1); |
26 |
print "Setting templatedir = $templatedir\n";}; |
27 |
if (/--pfilesdir=(.*)/) {$pfilesdir=endslash($1); |
28 |
print "Setting pfilesdir = $pfilesdir\n";}; |
29 |
} |
30 |
|
31 |
#DIRECTORIS WITHIN WEB SITE |
32 |
$webbase = "../"; |
33 |
$latek2htmldir = "online_documents/"; |
34 |
$coderefdir = "code_reference/"; |
35 |
$vdbtargetdir = "code_reference/vdb"; |
36 |
|
37 |
#File names |
38 |
$toc2url = "< ".$pfilesdir."toc2url.txt"; |
39 |
$toc2pattern = "< ".$pfilesdir."toc2pattern.txt"; |
40 |
$template2url = "< ".$pfilesdir."template2url.txt"; |
41 |
$template2pattern = "< ".$pfilesdir."template2pattern.txt"; |
42 |
|
43 |
|
44 |
#FILES TO COPY AND FORMAT FROM PAOC SERVER |
45 |
#These files are brought over via FTP |
46 |
$frontpage = "home_page/frontpage.html"; |
47 |
$subspage = "code_reference/subroutine.html"; |
48 |
$paramspage = "code_reference/parameters.html"; |
49 |
$sourcepage = "code_reference/sourcefiles.html"; |
50 |
$varspage = "code_reference/variabledictionary.html"; |
51 |
@paocfiles = ($frontpage, $subspage, $paramspage, $sourcepage, $varspage); |
52 |
|
53 |
#GLOB WEB FILES TO BE FORMATTED |
54 |
#directory containing all the latek generated html |
55 |
@htmlfiles = ($targetdir . $latek2htmldir . "manual.html"); |
56 |
@htmlfiles = (@htmlfiles, glob($targetdir . $latek2htmldir . "node*.html")); |
57 |
if ($BUILDALLFILES) { |
58 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "*.htm")); |
59 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/*.htm")); |
60 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/*.html")); |
61 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/diags/inc/*.html")); |
62 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/diags/src/*.html")); |
63 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/eesupp/inc/*.html")); |
64 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/eesupp/src/*.html")); |
65 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/model/inc/*.html")); |
66 |
@htmlfiles = (@htmlfiles, glob($targetdir . $coderefdir. "code/model/src/*.html")); |
67 |
} |
68 |
|
69 |
|
70 |
#TEMPLATE TOC PREPROCESSING |
71 |
#read in template formatting and mapping files |
72 |
open(TOC2URL,$toc2url) || die("can't open $toc2url"); |
73 |
@toc2urllist = parsepatternfile(<TOC2URL>); |
74 |
|
75 |
open(TOC2PATTERN,$toc2pattern) || die("can't open $toc2pattern"); |
76 |
@toc2patternlist = parsepatternfile(<TOC2PATTERN>); |
77 |
|
78 |
#TEMPLATE SUBSTITUTION FILES |
79 |
open(TEMPLATE2URL,$template2url) || die("can't open $template2url"); |
80 |
@template2urllist = parsetemplatefile(<TEMPLATE2URL>); |
81 |
|
82 |
open(TEMPLATE2PATTERN,$template2pattern) || die("can't open $template2pattern"); |
83 |
@template2patternlist = parsetemplatefile(<TEMPLATE2PATTERN>); |
84 |
|
85 |
#FIND TEMPLATE FILES |
86 |
#Find all template files from template2url.txt and template2pattern.txt. |
87 |
#The template files are even entries in @template2patternlist and |
88 |
#@template2urllist. This is the list of templates that are actually used. |
89 |
for ($i=0;$i<$#template2patternlist; $i=$i+2){ |
90 |
@templatefiles = (@templatefiles,$template2patternlist[$i]); |
91 |
} |
92 |
for ($i=0;$i<$#template2urllist; $i=$i+2){ |
93 |
@templatefiles = (@templatefiles,$template2urllist[$i]); |
94 |
} |
95 |
|
96 |
#FIND SINGLE FILE NAMES FROM REGEXP |
97 |
#Find html file that corresponds to each REGEXP for TOC entries |
98 |
#loop through patterns |
99 |
for ($i=1;$i <= $#toc2patternlist; $i=$i+2){ |
100 |
|
101 |
$pattern = $toc2patternlist[$i]; |
102 |
$notfound = 1; |
103 |
$j=0; |
104 |
|
105 |
while (($j < $#htmlfiles) && ($notfound)) { |
106 |
open(THISHTML,$htmlfiles[$j]) || die("can't open $htmlfiles[$j]"); |
107 |
|
108 |
while (<THISHTML>) { |
109 |
if (/$pattern/){ |
110 |
#$htmlfiles[$j] =~ /.*\/(.*\.html)/; |
111 |
#print "$1\n"; |
112 |
$htmlfiles[$j] =~ /(node\d+\.html)/; |
113 |
$toc2patternlist[$i] = "$webbase" . "$latek2htmldir" . $1; |
114 |
$notfound = 0; |
115 |
last; |
116 |
} # check for pattern match |
117 |
} # loop through lines in html file |
118 |
|
119 |
$j++; |
120 |
close THISHTML; |
121 |
|
122 |
} #loop through htmlfiles |
123 |
|
124 |
#ANY INCORRECT REGEXP WILL NOT HAVE BEEN REPLACED BY FILE NAMES. |
125 |
#CHECK FOR EXTRA SPACES BETWEEN NUMBER AND TITLE AND AT END OF TITLE |
126 |
if ($DEBUG) { |
127 |
print "$toc2patternlist[$i-1], $toc2patternlist[$i]\n"; |
128 |
} |
129 |
|
130 |
} #loop through REGEXP |
131 |
|
132 |
@tocreplace = (@toc2patternlist, @toc2urllist); |
133 |
|
134 |
#PREFORMAT FRONTPAGE AND OTHER HTML FILES FROM PAOC SERVER |
135 |
|
136 |
for ($thispaocfile=0; $thispaocfile<$#paocfiles; $thispaocfile++) { |
137 |
if ($DEBUG) {print "Preformatting paocfile $paocfiles[$thispaocfile]\n";} |
138 |
open(THISHANDLE,"$targetdir"."$paocfiles[$thispaocfile]") || die "couldn't open " . "$targetdir"."$paocfiles[$thispaocfile]"; |
139 |
@thisfile = <THISHANDLE>; |
140 |
for ($thisreplace=0; $thisreplace<$#tocreplace; $thisreplace=$thisreplace+2) { |
141 |
foreach (@thisfile) { |
142 |
s/$tocreplace[$thisreplace]/$tocreplace[$thisreplace+1]/; |
143 |
} |
144 |
} |
145 |
close THISHANDLE; |
146 |
open(THISHANDLE, "> " . "$targetdir"."$paocfiles[$thispaocfile]") || die "couldn't open " . "$targetdir"."$paocfiles[$thispaocfile]"; |
147 |
print THISHANDLE @thisfile; |
148 |
close THISHANDLE; |
149 |
} |
150 |
|
151 |
#LOOP THROUGH TEMPLATES |
152 |
### added by AJA: create a flag to indicate whether file has been associated |
153 |
# with a template (1 = no and 0 = yes) |
154 |
$thisfile=0; |
155 |
while ($thisfile < $#htmlfiles) { |
156 |
$htmlfileassociated[$thisfile]=1; |
157 |
$thisfile++; |
158 |
} # loop through file |
159 |
### end addition by AJA |
160 |
for ($thistemplate=0; $thistemplate <= $#templatefiles; $thistemplate++) { |
161 |
if ($DEBUG) {print "Preformatting template $templatefiles[$thistemplate]\n";} |
162 |
open(THISHANDLE, $templatedir . $templatefiles[$thistemplate]) || |
163 |
die "couldn't open " . $templatedir . $templatefiles[$thistemplate]; |
164 |
@thisfile = <THISHANDLE>; |
165 |
|
166 |
#PREFORMAT TEMPLATES |
167 |
for ($thisreplace=0; $thisreplace<$#tocreplace; $thisreplace=$thisreplace+2) { |
168 |
foreach (@thisfile) { |
169 |
s/$tocreplace[$thisreplace]/$tocreplace[$thisreplace+1]/; |
170 |
} |
171 |
} |
172 |
|
173 |
close THISHANDLE; |
174 |
|
175 |
#FIND ALL HTML FILES THAT USE THIS TEMPLATE |
176 |
@subfiles = (); |
177 |
|
178 |
#... FROM URL |
179 |
for ($thisurl=0;$thisurl < $#template2urllist; $thisurl=$thisurl+2){ |
180 |
if ($template2urllist[$thisurl] eq $templatefiles[$thistemplate]) { |
181 |
@subfiles = (@subfiles, glob("$targetdir" . "$template2urllist[$thisurl+1]")); |
182 |
} |
183 |
} |
184 |
#... HTML FILES FROM PATTERN |
185 |
for ($thispattern=0;$thispattern < $#template2patternlist; $thispattern=$thispattern+2){ |
186 |
if ($template2patternlist[$thispattern] eq $templatefiles[$thistemplate]) { |
187 |
|
188 |
$pattern = $template2patternlist[$thispattern+1]; |
189 |
$thisfile=0; |
190 |
while ($thisfile < $#htmlfiles) { |
191 |
open(THISHTML,$htmlfiles[$thisfile]) || die("can't open $htmlfiles[$thisfile]"); |
192 |
while (<THISHTML>) { |
193 |
if (/$pattern/ && $htmlfileassociated[$thisfile]){ |
194 |
@subfiles = (@subfiles, $htmlfiles[$thisfile]); |
195 |
$htmlfileassociated[$thisfile]=0; |
196 |
} # check for pattern match |
197 |
} # loop through lines in html file |
198 |
$thisfile++; |
199 |
close THISHTML; |
200 |
} # loop through file |
201 |
|
202 |
} # check if pattern for this template |
203 |
|
204 |
} #for each html file |
205 |
|
206 |
if ($DEBUG) { |
207 |
print "Template $templatefiles[$thistemplate] is used by these html files :\n"; |
208 |
#print (join("\n",@subfiles) . "\n"); |
209 |
} |
210 |
|
211 |
@pretitle=(); |
212 |
@title2content=(); |
213 |
@postcontent=(); |
214 |
foreach (@thisfile){ |
215 |
if ($#title2content == -1) { |
216 |
if (/(.*)_TITLE_(.*)/i) { |
217 |
@pretitle = (@pretitle, $1); |
218 |
@title2content = ("$2"); |
219 |
} else { |
220 |
@pretitle = (@pretitle, "$_"); |
221 |
} |
222 |
} elsif ($#postcontent == -1) { |
223 |
if (/(.*)_CONTENT_(.*)/i) { |
224 |
@title2content = (@title2content, "$1"); |
225 |
@postcontent = (@postcontent, "$2"); |
226 |
} else { |
227 |
@title2content = (@title2content, "$_"); |
228 |
} |
229 |
} else { |
230 |
@postcontent = (@postcontent, "$_"); |
231 |
} |
232 |
} |
233 |
|
234 |
#OPEN SUBFILES, EXTRACT TITLE AND BODY, PLUG INTO TEMPLATE |
235 |
for ($thissubindx=0; $thissubindx<= $#subfiles; $thissubindx++){ |
236 |
|
237 |
#we're overwriting each file as we go |
238 |
$savefile = $subfiles[$thissubindx]; |
239 |
|
240 |
if ($DEBUG) {print "$savefile\n";} |
241 |
open (SUBHANDLE, $subfiles[$thissubindx]) || die "Can't open $subfiles[$thissubindx]"; |
242 |
@thissubfile = <SUBHANDLE>; |
243 |
close SUBHANDLE; |
244 |
$thisline = 0; |
245 |
while ($thisline <= $#thissubfile){ |
246 |
if ($thissubfile[$thisline] =~ /<TITLE>(.*)<\/TITLE>/i) { |
247 |
$thistitle = $1; |
248 |
last; |
249 |
} |
250 |
$thisline++; |
251 |
} |
252 |
$thistitle = "no title"; |
253 |
@thiscontent = (); |
254 |
$working=1; |
255 |
$multiple=0; #title spans multiple lines |
256 |
foreach (@thissubfile){ |
257 |
if ($thistitle eq "no title") { |
258 |
if (/<TITLE>(.*)/i) { |
259 |
$thistitle = $1; |
260 |
if (/<TITLE>(.*)<\/TITLE>/i) { |
261 |
$thistitle = $1; |
262 |
} else { |
263 |
$thistitle=chomp($thistitle); |
264 |
$multiple=1; |
265 |
} |
266 |
} |
267 |
} elsif ($multiple) { |
268 |
if (/(.*)<\/TITLE>/i) { |
269 |
$thistitle = $thistitle . " " . $1; |
270 |
$multiple=0; |
271 |
} else { |
272 |
$thistitle = $thistitle . chomp($_); |
273 |
} |
274 |
} elsif ($#thiscontent == -1) { |
275 |
if (/.*<BODY.*?>(.*)/i) { |
276 |
@thiscontent = ("$1"); |
277 |
} |
278 |
} elsif ($working){ |
279 |
if (/(.*)<\/BODY>.*/i) { |
280 |
@thiscontent = (@thiscontent, "$1"); |
281 |
$working=0; |
282 |
} else { |
283 |
@thiscontent = (@thiscontent, "$_"); |
284 |
} |
285 |
} |
286 |
} |
287 |
|
288 |
#SAVE THE FORMATTED HTML FILE |
289 |
open(THISHANDLE, "> " . $savefile) || die "couldn't open " . $savefile; |
290 |
print THISHANDLE @pretitle; |
291 |
print THISHANDLE "$thistitle"; |
292 |
print THISHANDLE @title2content; |
293 |
print THISHANDLE @thiscontent; |
294 |
print THISHANDLE @postcontent; |
295 |
close THISHANDLE; |
296 |
|
297 |
} #for each html file |
298 |
|
299 |
}# for each template |
300 |
|
301 |
|
302 |
#SUBROUTINES# |
303 |
#-----------# |
304 |
sub parsepatternfile { |
305 |
my(@filecontents) = @_; |
306 |
@patternlist=(); |
307 |
foreach (@filecontents) { |
308 |
#if it starts with a # then skip it |
309 |
unless (/^#/) { |
310 |
#print $_; |
311 |
#find the string that starts and ends with _ |
312 |
#skip following whitespace and find the remaining string |
313 |
if (/(_.+?_)\s*(.*)/) { |
314 |
@patternlist = (@patternlist, $1, $2); |
315 |
} |
316 |
} |
317 |
} |
318 |
|
319 |
return @patternlist; |
320 |
} |
321 |
|
322 |
sub parsetemplatefile { |
323 |
my(@filecontents) = @_; |
324 |
@templatelist=(); |
325 |
foreach (@filecontents) { |
326 |
#if it starts with a # then skip it |
327 |
unless (/^#/) { |
328 |
#print $_; |
329 |
#find the string that starts and ends with _ |
330 |
#skip following whitespace and find the remaining string |
331 |
if (/^(\S+)\s*(.*)/) { |
332 |
@templatelist = (@templatelist, $1, $2); |
333 |
} |
334 |
} |
335 |
} |
336 |
|
337 |
return @templatelist; |
338 |
} |
339 |
|
340 |
sub endslash { |
341 |
local($thispath) = $_[0]; |
342 |
if (chop ne "/") { $thispath=$thispath."/"; }; |
343 |
return $thispath; |
344 |
} |