std/c/src/: Delete `stddebug`, use plain old `stderr`
[sunny256-utils.git] / create_imgindex
blob47b68358ec2018ab3ee224d58f2727cc1cf38371
1 #!/usr/bin/env perl
3 #=======================================================================
4 # create_imgindex
5 # File ID: e315d656-1cb0-11de-a0da-000475e441b9
6 # Create HTML page with collection of images
8 # Character set: UTF-8
9 # ©opyleft 2004– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'debug' => 0,
25 'generate' => 0,
26 'help' => 0,
27 'language' => "en",
28 'output-file' => "",
29 'title' => "",
30 'verbose' => 0,
31 'version' => 0,
35 our $progname = $0;
36 $progname =~ s/^.*\/(.*?)$/$1/;
37 our $VERSION = "0.00";
39 my $Author = txt_to_xml('Øyvind A. Holm <sunny@sunbase.org>'); # FIXME: Hardcoding
40 my $cmdline_str = txt_to_xml(join(" ", @ARGV));
42 Getopt::Long::Configure("bundling");
43 GetOptions(
45 "debug" => \$Opt{'debug'},
46 "generate|g" => \$Opt{'generate'},
47 "help|h" => \$Opt{'help'},
48 "language|l=s" => \$Opt{'language'},
49 "output-file|o=s" => \$Opt{'output-file'},
50 "title|t=s" => \$Opt{'title'},
51 "verbose|v+" => \$Opt{'verbose'},
52 "version" => \$Opt{'version'},
54 ) || die("$progname: Option error. Use -h for help.\n");
56 $Opt{'debug'} && ($Debug = 1);
57 $Opt{'help'} && usage(0);
58 if ($Opt{'version'}) {
59 print_version();
60 exit(0);
63 my $Title = txt_to_xml($Opt{'title'}) || die("$progname: -t/--title not specified\n");;
64 my $Outfile = txt_to_xml($Opt{'output-file'}) || die("$progname: -o/--output-file not specified\n");;
65 scalar(@ARGV) || die("$progname: No filenames specified\n");
67 my $is_svn_wc = -d ".svn/." ? 1 : 0;
69 for my $Dir (qw{4288x2848 2144x1424 1072x712 536x356 thumbs}) {
70 if (!-d "$Dir/.") {
71 mkdir($Dir) || die("$progname: $Dir: mkdir() error: $!\n");
72 $is_svn_wc && mysyst("svn", "add", $Dir);
74 if (!-e "$Dir/.htaccess") {
75 open(OutFP, ">$Dir/.htaccess") || die("$progname: $Dir/.htaccess: Cannot create file: $!\n");
76 chomp(my $file_id = `fileid -t htaccess $Dir/.htaccess`);
77 print(OutFP <<END);
78 $file_id
80 DirectoryIndex SpesialIndex.html
81 Options Indexes
82 IndexOptions FancyIndexing NameWidth=* DescriptionWidth=*
83 AddType text/plain;charset=UTF-8 txt
84 AddType text/html;charset=UTF-8 html
85 AddDefaultCharset UTF-8
86 END
87 close(OutFP);
88 if ($is_svn_wc) {
89 mysyst("svn", "add", "$Dir/.htaccess");
90 mysyst("keyw", "$Dir/.htaccess");
95 my @time_array = localtime(time);
96 my $Year = $time_array[5] + 1900;
98 my $files_str = "";
99 my %smsum = ();
100 my @files_found = ();
102 open(OutFP, ">", $Outfile) || die("$progname: $Outfile: Cannot create file: $!\n");
104 for my $t (@ARGV) {
105 if (-r $t) {
106 msg(0, "$t");
107 chomp($smsum{$t} = `smsum <$t`);
108 $files_str .= sprintf("<file> <name>%s</name> <smsum>%s</smsum> </file> ", txt_to_xml($t), $smsum{$t});
109 if ($Opt{'generate'}) {
110 mysyst("cp -Lp $t 4288x2848/$t");
111 mysyst("convert -resize 2144 4288x2848/$t 2144x1424/$t");
112 mysyst("convert -resize 1072 2144x1424/$t 1072x712/$t");
113 mysyst("convert -resize 536 1072x712/$t 536x356/$t");
114 mysyst("convert -resize 160 536x356/$t thumbs/$t");
116 push(@files_found, $t);
117 } else {
118 warn("$progname: $t: Cannot open file for read: $!\n");
122 chomp(my $uuid = `suuid -t create_imgindex --raw -c "<c_create_imgindex> <cmdline>$cmdline_str</cmdline> <filename>$Outfile</filename> $files_str</c_create_imgindex>"`)
123 || die("$progname: suuid error");
125 my $ignorefile = ".$uuid.ignore.tmp";
126 if ($is_svn_wc) {
127 if (open(TmpFP, ">", $ignorefile)) {
128 printf(TmpFP "%s\n", join("\n", @files_found));
129 close(TmpFP);
132 if ($Opt{'generate'}) {
133 for my $dir (qw{4288x2848 2144x1424 1072x712 536x356 thumbs}) {
134 if (chdir($dir)) {
135 mysyst("mkFiles");
136 if ($is_svn_wc) {
137 mysyst("svn add Files.smsum");
139 chdir("..");
140 } else {
141 warn("$progname: $dir: Cannot chdir(), mkFiles not executed: $!\n");
143 $is_svn_wc && mysyst("svn -F $ignorefile ps svn:ignore $dir");
146 $is_svn_wc && unlink($ignorefile);
148 print(OutFP <<END);
149 <?xml version="1.0" encoding="UTF-8"?>
150 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
151 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
152 <html xmlns="http://www.w3.org/1999/xhtml"
153 xml:lang="$Opt{'language'}" lang="$Opt{'language'}">
154 <!-- File ID: $uuid -->
155 <head>
156 <meta http-equiv="Content-Type"
157 content="text/html; charset=UTF-8" />
158 <title>$Title</title>
159 <style type="text/css">
160 <!--
161 body {
162 background-color: white;
163 color: black;
164 font-family: sans-serif;
166 a:link { color: blue; background-color: white; }
167 a:visited { color: maroon; background-color: white; }
168 a:active { color: fuchsia; background-color: white; }
169 h1 { text-align: center; font-size: 200%; font-weight: bold; }
170 h2 { text-align: center; font-size: 120%; font-weight: bold; }
171 table.main { margin: 0 auto; }
172 td.head { text-align: center; vertical-align: middle; }
173 td.dirtxt { text-align: left; vertical-align: middle; }
174 td.dirs {
175 text-align: center;
176 vertical-align: middle;
177 width: 25%;
179 td.image { text-align: center; vertical-align: middle; }
180 td.text {
181 text-align: center;
182 vertical-align: top;
183 font-size: 80%;
185 td.lefticon {
186 text-align: center;
187 vertical-align: middle;
188 font-size: 80%;
190 td.righticon {
191 text-align: center;
192 vertical-align: middle;
193 font-size: 80%;
195 td.footer {
196 text-align: center;
197 vertical-align: top;
198 width: 100%;
199 font-size: 100%;
202 </style>
203 <meta name="author" content="Øyvind A. Holm — sunny\@sunbase.org" />
204 <meta name="copyright" content="©$Year- Øyvind A. Holm" />
205 </head>
206 <body>
207 <table class="main" cellpadding="10" cellspacing="0" border="1">
208 <tr>
209 <td class="head" colspan="4">
210 <h1>$Title</h1>
211 <table width="100%">
212 <tr>
213 <td colspan="4" class="dirtxt">
214 <h2>Directories:</h2>
215 </td>
216 </tr>
217 <tr>
218 <td class="dirs">
219 <a href="4288x2848/">4288x2848/</a>
220 </td>
221 <td class="dirs">
222 <a href="2144x1424/">2144x1424/</a>
223 </td>
224 <td class="dirs">
225 <a href="1072x712/">1072x712/</a>
226 </td>
227 <td class="dirs">
228 <a href="536x356/">536x356/</a>
229 </td>
230 </tr>
231 </table>
232 </td>
233 </tr>
236 my ($Count, $create_td) = (0, 0);
238 for my $Curr (@ARGV) {
239 if (!$Count) {
240 print(OutFP " <tr>\n");
242 print(OutFP <<END);
243 <td>
244 <!-- $smsum{$Curr} -->
245 <table width="100%" cellpadding="2" cellspacing="0" border="0">
246 <tr>
247 <td class="image" colspan="2">
248 <img src="thumbs/$Curr" width="160" alt="$Curr" />
249 </td>
250 </tr>
251 <tr>
252 <td class="text">
253 [<a href="4288x2848/$Curr">4288x2848</a>]<br />
254 [<a href="1072x712/$Curr">1072x712</a>]
255 </td>
256 <td class="text">
257 [<a href="2144x1424/$Curr">2144x1424</a>]<br />
258 [<a href="536x356/$Curr">536x356</a>]
259 </td>
260 </tr>
261 <tr>
262 <td class="text" colspan="2">
263 <b>$Curr</b>
264 </td>
265 </tr>
266 </table>
267 </td>
269 $Count++;
270 if ($Count > 3) {
271 print(OutFP " </tr>\n");
272 $Count = 0;
273 $create_td = 1;
277 if ($Count) {
278 $create_td && printf(OutFP " <td colspan=\"%u\">\n </td>\n", 4-$Count);
279 print(OutFP " </tr>\n");
282 print(OutFP <<END);
283 <tr>
284 <td colspan="4">
285 <table cellpadding="5" cellspacing="0" border="0">
286 <tr>
287 <td class="lefticon">
288 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10.png" alt="Valid XHTML 1.0" width="88" height="31" style="border: 0;" /></a>
289 </td>
290 <td class="footer" colspan="2">
291 ©opyleft $Year- Øyvind A. Holm &lt;sunny\@sunbase.org&gt;<br />
292 License:
293 <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-Share Alike 3.0 Unported</a>
294 </td>
295 <td class="righticon">
296 <a href="http://jigsaw.w3.org/css-validator/check/referer"><img src="http://www.w3.org/Icons/valid-css.png" alt="Valid CSS" width="88" height="31" style="border: 0;" /></a>
297 </td>
298 </tr>
299 </table>
300 </td>
301 </tr>
302 </table>
303 </body>
304 </html>
307 close(OutFP);
309 sub mysyst {
310 # {{{
311 my @Args = @_;
312 my $system_txt = sprintf("system(\"%s\");", join("\", \"", @Args));
313 msg(1, "Executing '$system_txt'...");
314 system(@_);
315 # }}}
316 } # mysyst()
318 sub txt_to_xml {
319 # {{{
320 my $Txt = shift;
321 $Txt =~ s/&/&amp;/gs;
322 $Txt =~ s/</&lt;/gs;
323 $Txt =~ s/>/&gt;/gs;
324 return($Txt);
325 # }}}
326 } # txt_to_xml()
328 sub print_version {
329 # Print program version {{{
330 print("$progname v$VERSION\n");
331 # }}}
332 } # print_version()
334 sub usage {
335 # Send the help message to stdout {{{
336 my $Retval = shift;
338 if ($Opt{'verbose'}) {
339 print("\n");
340 print_version();
342 print(<<END);
344 Usage: $progname [options] -o OUTFILE -t TITLE [images ...]
346 Options:
348 -g, --generate
349 Generate resized images in subdirectory tree. Needs convert(1) from
350 the ImageMagick package.
351 -h, --help
352 Show this help.
353 -l X, --language X
354 Use language code X. Default: "en".
355 -o X, --output-file X
356 Store output in file X.
357 -t X, --title X
358 Use title and header X.
359 -v, --verbose
360 Increase level of verbosity. Can be repeated.
361 --version
362 Print version information.
363 --debug
364 Print debugging messages.
367 exit($Retval);
368 # }}}
369 } # usage()
371 sub msg {
372 # Print a status message to stderr based on verbosity level {{{
373 my ($verbose_level, $Txt) = @_;
375 if ($Opt{'verbose'} >= $verbose_level) {
376 print(STDERR "$progname: $Txt\n");
378 # }}}
379 } # msg()
381 sub D {
382 # Print a debugging message {{{
383 $Debug || return;
384 my @call_info = caller;
385 chomp(my $Txt = shift);
386 my $File = $call_info[1];
387 $File =~ s#\\#/#g;
388 $File =~ s#^.*/(.*?)$#$1#;
389 print(STDERR "$File:$call_info[2] $$ $Txt\n");
390 return("");
391 # }}}
392 } # D()
394 __END__
396 # Plain Old Documentation (POD) {{{
398 =pod
400 =head1 NAME
404 =head1 SYNOPSIS
406 [options] [file [files [...]]]
408 =head1 DESCRIPTION
412 =head1 OPTIONS
414 =over 4
416 =item B<-h>, B<--help>
418 Print a brief help summary.
420 =item B<-v>, B<--verbose>
422 Increase level of verbosity. Can be repeated.
424 =item B<--version>
426 Print version information.
428 =item B<--debug>
430 Print debugging messages.
432 =back
434 =head1 BUGS
438 =head1 AUTHOR
440 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
442 =head1 COPYRIGHT
444 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
445 This is free software; see the file F<COPYING> for legalese stuff.
447 =head1 LICENCE
449 This program is free software: you can redistribute it and/or modify it
450 under the terms of the GNU General Public License as published by the
451 Free Software Foundation, either version 2 of the License, or (at your
452 option) any later version.
454 This program is distributed in the hope that it will be useful, but
455 WITHOUT ANY WARRANTY; without even the implied warranty of
456 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
457 See the GNU General Public License for more details.
459 You should have received a copy of the GNU General Public License along
460 with this program.
461 If not, see L<http://www.gnu.org/licenses/>.
463 =head1 SEE ALSO
465 =cut
467 # }}}
469 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :