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