Debian Codegraph @

scripts/perl/web/mkindex.pl

raw
1 #!/usr/bin/perl
2
3 #
4 # adapted from a script by Bob Hain, 11/30/99
5 #
6
7 #
8 # default values
9 #
10
11 $outfile = "new.index.html";
12
13
14 #
15 # process arguments
16 #
17
18 $use_large = 1;
19 while ( $arg = shift @ARGV ) {
20 if ( $arg eq "--large" ) {
21 $use_large = 1;
22 }
23 if ( $arg eq "--outfile" ) {
24 $outfile = shift @ARGV;
25 }
26 }
27
28
29 #
30 # Generate all images
31 #
32
33 $src = "Source";
34 $ldir = "Large";
35 $sdir = "Small";
36 $mdir = "Movies";
37
38 $columns = 2;
39
40 $swidth = 320;
41 $sheight = 233;
42
43 $lwidth = 1024;
44 $lheight = 768;
45
46
47 #
48 # Make sure directories exist
49 #
50
51 if ( ! -e $ldir ) {
52 mkdir $ldir, 0755;
53 }
54
55 if ( ! -e $sdir ) {
56 mkdir $sdir, 0755;
57 }
58
59 # return 1 if file1 is newer than rile2
60 sub is_newer {
61 my($file1, $file2) = @_;
62 # print " - $file1 - $file2 - \n";
63
64 ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime1,
65 $ctime, $blksize, $blocks) = stat($file1);
66 ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime2,
67 $ctime, $blksize, $blocks) = stat($file2);
68
69 if ( $mtime1 > $mtime2 ) {
70 return 1;
71 } else {
72 return 0;
73 }
74 }
75
76
77 #
78 # Make images (both large and small)
79 #
80
81 @FILES = `ls $src/*.jpg $src/*.JPG $src/*.png`;
82
83 foreach $file ( @FILES ) {
84 chop $file;
85 $file =~ s/$src\///;
86
87 if ( is_newer( "$src/$file", "$ldir/$file" ) || ! -e "$ldir/$file" ) {
88 print "Updating $ldir/$file\n";
89 system("cp -f $src/$file $ldir");
90 system("mogrify -geometry \'$lwidth" . "X" .
91 "$lheight>\' -interlace LINE -quality 80 $ldir/$file");
92 }
93
94 if ( is_newer( "$ldir/$file", "$sdir/$file" ) || ! -e "$sdir/$file" ) {
95 print "Updating $sdir/$file\n";
96 system("cp -f $ldir/$file $sdir");
97 system("mogrify -geometry \'$swidth" . "X" .
98 "$sheight>\' -interlace LINE -quality 80 $sdir/$file");
99 }
100 }
101
102
103 #
104 # Check for large and small images to remove
105 #
106
107 @FILES = `ls $ldir`;
108 foreach $file ( @FILES ) {
109 chop($file);
110 # print "$file\n";
111 if ( ! -f "$src/$file" ) {
112 print "No matching src file - deleting large image $file ...\n";
113 unlink( "$ldir/$file" );
114 }
115 }
116
117 @FILES = `ls $sdir`;
118 foreach $file ( @FILES ) {
119 chop($file);
120 if ( ! -f "$src/$file" ) {
121 print "No matching src file - deleting small image $file ...\n";
122 unlink( "$sdir/$file" );
123 }
124 }
125
126
127 #
128 # Build image list (for next/previous/first/last links)
129 #
130
131 open( MASTER, "<master.idx" );
132
133 @imagelist = ();
134
135 while ( <MASTER> ) {
136 chop;
137 if ( m/\.jpg$/ || m/\.JPG$/ || m/\.png$/ ) {
138 push @imagelist, $_;
139 } else {
140 # just ignore everything else
141 }
142 }
143
144 close( MASTER );
145
146
147 #
148 # Prepair $link subdirectory
149 #
150
151 $link = "Link";
152 system("rm -rf $link");
153 mkdir $link, 0755;
154
155
156 #
157 # Assemble index.html
158 #
159
160 $dir = `pwd`;
161 chop($dir);
162 $title = `basename $dir`;
163 chop($title);
164
165 open( MASTER, "<master.idx" );
166 open( OUT, ">$outfile" );
167
168 $j = 1;
169 $in_table = 0;
170
171 while ( <MASTER> ) {
172 chop;
173 if ( m/^#/ ) {
174 # ignore comments
175 } elsif ( m/\.txt$/ ) {
176 # insert text
177
178 if ( $in_table ) {
179 $in_table = 0;
180 print OUT "</TR>\n";
181 print OUT "</TABLE>\n";
182 }
183
184 $file = $_;
185 open( IN, "<$src/$file" );
186 while ( <IN> ) {
187 print OUT $_;
188 }
189 close( IN );
190 print OUT "<P>\n";
191 $j = 1;
192 $in_table = 0;
193 } elsif ( m/\.jpg$/ || m/\.JPG$/ || m/\.png$/ ) {
194 # insert image in 3 wide tables
195
196 $in_table = 1;
197 $file = $_;
198
199 $i = `basename $file`;
200 chop($i);
201
202 if ( $j == 1 ) {
203 print OUT "<!-- Begin Row -->\n";
204 print OUT "<TABLE ALIGN=CENTER>\n";
205 print OUT "<TR VALIGN=TOP>\n";
206 }
207
208 if ( $i =~ m/\.jpg$/ ) {
209 $linkname = `basename $i .jpg`;
210 } elsif ( $i =~ m/\.JPG$/ ) {
211 $linkname = `basename $i .JPG`;
212 } elsif ($i =~ m/\.png$/ ) {
213 $linkname = `basename $i .png`;
214 }
215 chop($linkname);
216
217 $thumbinfo = `identify $sdir/$i`;
218 ($name, $type, $geom, $junk) = split(/\s+/, $thumbinfo, 4);
219 ($twidth, $theight) = split(/x/, $geom);
220 $theight =~ s/\+.*$//;
221
222 # print OUT "<TD WIDTH=220 HEIGHT=160>\n";
223 print OUT "<TD WIDTH=$twidth HEIGHT=$sheight>\n";
224
225 print OUT "<A HREF=\"$link/$linkname.html\">";
226 print OUT "<IMG WIDTH=$twidth HEIGHT=$theight SRC=\"$sdir/$i\" ALT=\"$linkname\">";
227 print OUT "</A><BR>\n";
228
229 if ( -f "$src/$linkname.txt" ) {
230 print OUT "<FONT SIZE=-1 id=\"fgfs\">\n";
231 open( IN, "<$src/$linkname.txt" );
232 while ( <IN> ) {
233 print OUT $_;
234 }
235 close( IN );
236 print OUT "</FONT>\n";
237 } else {
238 print OUT "<FONT SIZE=-1 id=\"fgfs\">\n";
239 print OUT "$linkname\n";
240 print OUT "</FONT>\n";
241 }
242
243 print OUT "</TD>\n";
244
245 if ( $j == $columns ) {
246 $in_table = 0;
247 print OUT "</TR>\n";
248 print OUT "</TABLE>\n";
249 }
250
251 if ( ++$j > $columns ) {
252 $j = 1;
253 }
254 } elsif ( m/\.AVI$/ || m/\.mpg$/ || m/\.mov$/ ) {
255 # insert image in 3 wide tables
256
257 $in_table = 1;
258 $file = $_;
259
260 $i = `basename $file`;
261 chop($i);
262
263 if ( $j == 1 ) {
264 print OUT "<!-- Begin Row -->\n";
265 print OUT "<TABLE ALIGN=CENTER>\n";
266 print OUT "<TR VALIGN=TOP>\n";
267 }
268
269 if ( $i =~ m/\.AVI$/ ) {
270 $linkname = `basename $i .AVI`;
271 } elsif ( $i =~ m/\.mpg$/ ) {
272 $linkname = `basename $i .mpg`;
273 } elsif ( $i =~ m/\.mov$/ ) {
274 $linkname = `basename $i .mov`;
275 } else {
276 die "unknown movie type\n";
277 }
278 chop($linkname);
279 # print OUT "<TD WIDTH=220 HEIGHT=160>\n";
280 print OUT "<TD WIDTH=$swidth HEIGHT=$sheight>\n";
281
282 $thumbinfo = `identify $mdir/$linkname.jpg`;
283 ($name, $type, $geom, $junk) = split(/\s+/, $thumbinfo, 4);
284 $geom =~ s/\+.*//;
285 ($twidth, $theight) = split(/x/, $geom);
286 print "movie thumb geom = $geom $twidth $theight\n";
287
288 print OUT "<A HREF=\"$mdir/$i\">";
289 if ( -f "$mdir/$linkname.jpg" ) {
290 print OUT "<IMG WIDTH=$twidth HEIGHT=$theight SRC=\"$mdir/$linkname.jpg\" ALT=\"$linkname\">";
291 } else {
292 print OUT "$linkname";
293 }
294 print OUT "</A>\n";
295
296 if ( -f "$mdir/$linkname.txt" ) {
297 print OUT "<BR>\n";
298 print OUT "<FONT SIZE=-1 id=\"fgfs\">\n";
299 open( IN, "<$mdir/$linkname.txt" );
300 while ( <IN> ) {
301 print OUT $_;
302 }
303 close( IN );
304 print OUT "</FONT>\n";
305 } else {
306 print OUT "<BR>\n";
307 print OUT "<FONT SIZE=-1 id=\"fgfs\">\n";
308 print OUT "$linkname\n";
309 print OUT "</FONT>\n";
310 }
311
312 print OUT "</TD>\n";
313
314 if ( $j == $columns ) {
315 $in_table = 0;
316 print OUT "</TR>\n";
317 print OUT "</TABLE>\n";
318 }
319
320 if ( ++$j > $columns ) {
321 $j = 1;
322 }
323 } else {
324 # just pass along the rest as is
325
326 $j = 1;
327
328 if ( $in_table ) {
329 $in_table = 0;
330 print OUT "</TR>\n";
331 print OUT "</TABLE>\n";
332 }
333 print OUT "$_\n";
334 }
335 }
336
337
338 #
339 # Generate Links
340 #
341
342 # @FILES = `ls $src/*.jpg $src/*.JPG $src/*.png`;
343
344 $first = $imagelist[0];
345 if ( $first =~ m/\.jpg$/ ) {
346 # print " ext = jpg\n";
347 $firstname = `basename $first .jpg`;
348 } elsif ( $first =~ m/\.JPG$/ ) {
349 # print " ext = JPG\n";
350 $firstname = `basename $first .JPG`;
351 } else {
352 # print " ext = png\n";
353 $firstname = `basename $first .png`;
354 }
355 chop($firstname);
356
357 $last = $imagelist[$#imagelist];
358 if ( $last =~ m/\.jpg$/ ) {
359 # print " ext = jpg\n";
360 $lastname = `basename $last .jpg`;
361 } elsif ( $last =~ m/\.JPG$/ ) {
362 # print " ext = JPG\n";
363 $lastname = `basename $last .JPG`;
364 } else {
365 # print " ext = png\n";
366 $lastname = `basename $last .png`;
367 }
368 chop($lastname);
369
370 for ($i = 0; $i <= $#imagelist; $i++) {
371 $file = $imagelist[$i];
372 # print "'$file'\n";
373
374 if ( $i > 0 ) {
375 $prev = $imagelist[$i - 1];
376 } else {
377 $prev = "null";
378 }
379
380 if ( $i < $#imagelist ) {
381 $next = $imagelist[$i + 1];
382 } else {
383 $next = "null";
384 }
385
386 if ( $file =~ m/\.jpg$/ ) {
387 $linkname = `basename $file .jpg`;
388 $ext = "jpg";
389 } elsif ( $file =~ m/\.JPG$/ ) {
390 $linkname = `basename $file .JPG`;
391 $ext = "JPG";
392 } else {
393 $linkname = `basename $file .png`;
394 $ext = "png";
395 }
396 chop($linkname);
397 $nice_name = $linkname;
398 $nice_name =~ s/\_/ /g;
399
400 if ( $prev =~ m/\.jpg$/ ) {
401 # print " ext = jpg\n";
402 $prevname = `basename $prev .jpg`;
403 } elsif ( $prev =~ m/\.JPG$/ ) {
404 # print " ext = JPG\n";
405 $prevname = `basename $prev .JPG`;
406 } else {
407 # print " ext = png\n";
408 $prevname = `basename $prev .png`;
409 }
410 chop($prevname);
411
412 if ( $next =~ m/\.jpg$/ ) {
413 $nextname = `basename $next .jpg`;
414 } elsif ( $next =~ m/\.JPG$/ ) {
415 $nextname = `basename $next .JPG`;
416 } else {
417 $nextname = `basename $next .png`;
418 }
419 chop($nextname);
420
421 $outfile = "$link/$linkname.html";
422
423 open( OUT, ">$outfile" );
424 print OUT <<EOF;
425
426 <HTML>
427
428 <HEAD>
429 <TITLE>$linkname.$ext</TITLE>
430 </HEAD>
431
432 <!-- <BODY BGCOLOR="#000000" ALINK="#000000" VLINK="#000000" LINK="#000000" TEXT="#FFFFFF"> -->
433 <BODY>
434
435 <A HREF="$firstname.html">[First]</A>
436 EOF
437
438 if ( $prevname ne "null" ) {
439 print OUT "<A HREF=\"$prevname.html\">[Previous]</A>\n";
440 } else {
441 print OUT "[Previous]\n";
442 }
443
444 if ( $nextname ne "null" ) {
445 print OUT "<A HREF=\"$nextname.html\">[Next]</A>\n";
446 } else {
447 print OUT "[Next]\n";
448 }
449
450 print OUT <<EOF;
451 <A HREF="$lastname.html">[Last]</A>
452
453 <TABLE ALIGN=CENTER>
454 <TR>
455 <TD ALIGN=CENTER>
456 <FONT SIZE=+1>
457 $nice_name
458 </FONT>
459 </TD>
460 </TR>
461
462 <TR>
463 <TD ALIGN=CENTER>
464 <FONT SIZE=-1>
465 EOF
466
467 if ( -f "$src/$linkname.txt" ) {
468 # print OUT "<BR>\n";
469 open( IN, "<$src/$linkname.txt" );
470 while ( <IN> ) {
471 print OUT $_;
472 }
473 close( IN );
474 }
475
476 print OUT <<EOF;
477 </FONT>
478 </TD>
479 </TR>
480
481 </TABLE>
482
483 Click on the image for the full size version.
484
485 <TABLE ALIGN=CENTER>
486 <TR>
487 <TD ALIGN=CENTER>
488 <A HREF="../$src/$linkname.$ext">
489 EOF
490
491 if ( $use_large ) {
492 print OUT " <IMG SRC=\"../$ldir/$linkname.$ext\">\n";
493 } else {
494 print OUT " <IMG SRC=\"../$src/$linkname.$ext\">\n";
495 }
496
497 print OUT <<EOF;
498 </TD>
499 </A>
500 </TR>
501 </TABLE>
502
503 </BODY>
504 </HTML>
505 EOF
506
507 close( OUT );
508 }
509