From a613199816333c3eb2064482a80071bcee937fbe Mon Sep 17 00:00:00 2001 From: Karl Cunningham Date: Sat, 21 May 2005 17:43:55 +0000 Subject: [PATCH] latex2html now only rebuilds images when needed for make web and make html --- docs/developers/Makefile | 11 ++-- docs/developers/translate_images.pl | 79 +++++++++++++++++++++++------ docs/manual-fr/Makefile | 8 +-- docs/manual-fr/translate_images.pl | 79 +++++++++++++++++++++++------ docs/manual/Makefile | 8 +-- docs/manual/translate_images.pl | 79 +++++++++++++++++++++++------ 6 files changed, 205 insertions(+), 59 deletions(-) diff --git a/docs/developers/Makefile b/docs/developers/Makefile index f839a2db..3fbad0cc 100644 --- a/docs/developers/Makefile +++ b/docs/developers/Makefile @@ -118,10 +118,11 @@ html: devhtml: @echo "Making developers html" + ./translate_images.pl --from_meaningful_names developers.html @cp -fp ${IMAGES}/*.eps . latex2html -white -no_subdir -split 0 -toc_stars -white -notransparent \ developers >/dev/null - ./translate_images.pl developers.html + ./translate_images.pl --to_meaningful_names developers.html @rm -f *.eps *.gif *.jpg *.old @@ -131,7 +132,6 @@ web: @rm -rf bacula/* @cp -fp ${IMAGES}/*.eps . @rm -f next.eps next.png prev.eps prev.png up.eps up.png -# @cp -fp ${IMAGES}/*.eps ${IMAGES}/*.png *.txt bacula @cp -fp ${IMAGES}/*.eps *.txt bacula @rm -f bacula/next.eps bacula/next.png bacula/prev.eps bacula/prev.png bacula/up.eps bacula/up.png latex2html -split 4 -local_icons -t "Bacula User's Guide" -long_titles 4 \ @@ -144,14 +144,15 @@ web: devweb: @echo "Making developers web" @mkdir -p developers - @rm -f developers/* + ./translate_images.pl --from_meaningful_names developers/Developers_Guide.html + @rm -f developers/*.html @cp -fp ${IMAGES}/*.eps . @rm -f next.eps next.png prev.eps prev.png up.eps up.png - @cp -fp ${IMAGES}/*.eps ${IMAGES}/*.png developers/ + @cp -fp ${IMAGES}/*.eps developers/ @rm -f developers/next.eps developers/next.png developers/prev.eps developers/prev.png developers/up.eps developers/up.png latex2html -split 5 -local_icons -t "Developer's Guide" -long_titles 4 \ -contents_in_nav -toc_stars -white -notransparent developers >/dev/null - ./translate_images.pl developers/Developers_Guide.html + ./translate_images.pl --to_meaningful_names developers/Developers_Guide.html @cp -f developers/Developers_Guide.html developers/index.html @rm -f *.eps *.gif *.jpg developers/*.eps *.old diff --git a/docs/developers/translate_images.pl b/docs/developers/translate_images.pl index 5be523cf..c4e7bf2c 100755 --- a/docs/developers/translate_images.pl +++ b/docs/developers/translate_images.pl @@ -2,29 +2,58 @@ # use strict; +# Used to change the names of the image files generated by latex2html from imgxx.png +# to meaningful names. Provision is made to go either from or to the meaningful names. +# The meaningful names are obtained from a file called imagename_translations, which +# is generated by extensions to latex2html in the make_image_file subroutine in +# bacula.perl. + # Opens the file imagename_translations and reads the contents into a hash. +# The hash is creaed with the imgxx.png files as the key if processing TO +# meaningful filenames, and with the meaningful filenames as the key if +# processing FROM meaningful filenames. # Then opens the html file(s) indicated in the command-line arguments and # changes all image references according to the translations described in the # above file. Finally, it renames the image files. # # Original creation: 3-27-05 by Karl Cunningham. +# Modified 5-21-05 to go FROM and TO meaningful filenames. # my $TRANSFILE = "imagename_translations"; my $path; # Loads the contents of $TRANSFILE file into the hash referenced in the first -# argument. +# argument. The hash is loaded to translate old to new if $direction is 0, +# otherwise it is loaded to translate new to old. In this context, the +# 'old' filename is the meaningful name, and the 'new' filename is the +# imgxx.png filename. It is assumed that the old image is the one that +# latex2html has used as the source to create the imgxx.png filename. +# The filename extension is taken from the file sub read_transfile { - my $trans = shift; + my ($trans,$direction) = @_; + + if (!open IN,"<$path$TRANSFILE") { + print "WARNING: Cannot open image translation file $path$TRANSFILE for reading\n"; + print " Image filename translation aborted\n\n"; + exit 0; + } - open IN,"<$path$TRANSFILE" or die "Cannot open image translation file $path$TRANSFILE for reading\n"; while () { chomp; my ($new,$old) = split(/\001/); - # The filename extension of the new one must be made to be the old one. - my ($ext) = $new =~ /.*(\..*)$/; - $old =~ s/(.*)\..*$/$1$ext/; - $trans->{$new} = $old; + + # Old filenames will usually have a leading ./ which we don't need. + $old =~ s/^\.\///; + + # The filename extension of the old filename must be made to match + # the new filename because it indicates the encoding format of the image. + my ($ext) = $new =~ /(\.[^\.]*)$/; + $old =~ s/\.[^\.]*$/$ext/; + if ($direction == 0) { + $trans->{$new} = $old; + } else { + $trans->{$old} = $new; + } } close IN; } @@ -35,6 +64,9 @@ sub read_transfile { # the file contents are then written. No particular care is taken to ensure that the # file is not lost if a system failure occurs at an inopportune time. It is assumed # that the html files being processed here can be recreated on demand. +# +# Links to other files are added to the %filelist for processing. That way, +# all linked files will be processed (assuming they are local). sub translate_html { my ($filename,$trans,$filelist) = @_; my ($contents,$out,$this,$img,$dest); @@ -45,7 +77,12 @@ sub translate_html { $filename =~ /^(http|ftp|mailto)\:/ and return 0; $filename =~ s/^file\:\/\///; # Load the contents of the html file. - open IF,"<$path$filename" or die "Cannot open $path$filename for reading\n"; + if (!open IF,"<$path$filename") { + print "WARNING: Cannot open $path$filename for reading\n"; + print " Image Filename Translation aborted\n\n"; + exit 0; + } + while () { $contents .= $_; } @@ -74,7 +111,7 @@ sub translate_html { print OF $out; close OF; - # Now look for any links to other files. + # Now look for any links to other files and add them to the list of files to do. while ($out =~ /\<\s*A[^\>]*HREF=\"(.*?)\"/si) { $out = $'; $dest = $1; @@ -92,7 +129,7 @@ sub rename_images { foreach (keys(%$translate)) { $response = `mv -f $path$_ $path$translate->{$_} 2>&1`; - $response and die $response; + $response and print "ERROR from system $response\n"; } } @@ -104,8 +141,16 @@ sub rename_images { # any links to other files are added to the %filelist. A hash of processed # files is kept so we don't do any twice. +# The first argument must be either --to_meaningful_names or --from_meaningful_names + my (%translate,$search_regex,%filelist,%completed,$thisfile); -my $cnt; +my ($cnt,$direction); + +my $arg0 = shift(@ARGV); +$arg0 =~ /^(--to_meaningful_names|--from_meaningful_names)$/ or + die "ERROR: First argument must be either \'--to_meaningful_names\' or \'--from_meaningful_names\'\n"; + +$direction = ($arg0 eq '--to_meaningful_names') ? 0 : 1; (@ARGV) or die "ERROR: Filename(s) to process must be given as arguments\n"; @@ -114,13 +159,15 @@ my $tmp = $ARGV[0]; ($path) = $tmp =~ /(.*\/)/; $path = '' unless $path; -read_transfile(\%translate); +read_transfile(\%translate,$direction); foreach (@ARGV) { # Strip the path from the filename, and use it later on. - s/(.*\/)//; - $path = $1; - $path = '' unless $path; + if (s/(.*\/)//) { + $path = $1; + } else { + $path = ''; + } $filelist{$_} = ''; while ($thisfile = (keys(%filelist))[0]) { @@ -128,7 +175,7 @@ foreach (@ARGV) { delete($filelist{$thisfile}); $completed{$thisfile} = ''; } - print "translate_images.pl: $cnt images translated to meaningful names\n"; + print "translate_images.pl: $cnt image filenames translated ",($direction)?"from":"to"," meaningful names\n"; } rename_images(\%translate); diff --git a/docs/manual-fr/Makefile b/docs/manual-fr/Makefile index f781b7a2..d326db31 100644 --- a/docs/manual-fr/Makefile +++ b/docs/manual-fr/Makefile @@ -107,10 +107,11 @@ devpdfm: html: @echo "Making html" + ./translate_images.pl --from_meaningful_names bacula.html @cp -fp ${IMAGES}/*.eps . latex2html -white -no_subdir -split 0 -toc_stars -white -notransparent \ bacula >/dev/null - ./translate_images.pl bacula.html + ./translate_images.pl --to_meaningful_names bacula.html @rm -f *.eps *.gif *.jpg *.old devhtml: @@ -125,14 +126,15 @@ devhtml: web: @echo "Making web" @mkdir -p bacula - @rm -rf bacula/* + ./translate_images.pl --from_meaningful_names bacula/Bacula_Users_Guide.html + @rm -rf bacula/*.html @cp -fp ${IMAGES}/*.eps . @rm -f next.eps next.png prev.eps prev.png up.eps up.png @cp -fp ${IMAGES}/*.eps *.txt bacula @rm -f bacula/next.eps bacula/next.png bacula/prev.eps bacula/prev.png bacula/up.eps bacula/up.png latex2html -split 4 -local_icons -t "Bacula User's Guide" -long_titles 4 \ -toc_stars -contents_in_nav -white -notransparent bacula >/dev/null - ./translate_images.pl bacula/Bacula_Users_Guide.html + ./translate_images.pl --to_meaningful_names bacula/Bacula_Users_Guide.html @cp -f bacula/Bacula_Users_Guide.html bacula/index.html @rm -f *.eps *.gif *.jpg bacula/*.eps *.old diff --git a/docs/manual-fr/translate_images.pl b/docs/manual-fr/translate_images.pl index 5be523cf..c4e7bf2c 100755 --- a/docs/manual-fr/translate_images.pl +++ b/docs/manual-fr/translate_images.pl @@ -2,29 +2,58 @@ # use strict; +# Used to change the names of the image files generated by latex2html from imgxx.png +# to meaningful names. Provision is made to go either from or to the meaningful names. +# The meaningful names are obtained from a file called imagename_translations, which +# is generated by extensions to latex2html in the make_image_file subroutine in +# bacula.perl. + # Opens the file imagename_translations and reads the contents into a hash. +# The hash is creaed with the imgxx.png files as the key if processing TO +# meaningful filenames, and with the meaningful filenames as the key if +# processing FROM meaningful filenames. # Then opens the html file(s) indicated in the command-line arguments and # changes all image references according to the translations described in the # above file. Finally, it renames the image files. # # Original creation: 3-27-05 by Karl Cunningham. +# Modified 5-21-05 to go FROM and TO meaningful filenames. # my $TRANSFILE = "imagename_translations"; my $path; # Loads the contents of $TRANSFILE file into the hash referenced in the first -# argument. +# argument. The hash is loaded to translate old to new if $direction is 0, +# otherwise it is loaded to translate new to old. In this context, the +# 'old' filename is the meaningful name, and the 'new' filename is the +# imgxx.png filename. It is assumed that the old image is the one that +# latex2html has used as the source to create the imgxx.png filename. +# The filename extension is taken from the file sub read_transfile { - my $trans = shift; + my ($trans,$direction) = @_; + + if (!open IN,"<$path$TRANSFILE") { + print "WARNING: Cannot open image translation file $path$TRANSFILE for reading\n"; + print " Image filename translation aborted\n\n"; + exit 0; + } - open IN,"<$path$TRANSFILE" or die "Cannot open image translation file $path$TRANSFILE for reading\n"; while () { chomp; my ($new,$old) = split(/\001/); - # The filename extension of the new one must be made to be the old one. - my ($ext) = $new =~ /.*(\..*)$/; - $old =~ s/(.*)\..*$/$1$ext/; - $trans->{$new} = $old; + + # Old filenames will usually have a leading ./ which we don't need. + $old =~ s/^\.\///; + + # The filename extension of the old filename must be made to match + # the new filename because it indicates the encoding format of the image. + my ($ext) = $new =~ /(\.[^\.]*)$/; + $old =~ s/\.[^\.]*$/$ext/; + if ($direction == 0) { + $trans->{$new} = $old; + } else { + $trans->{$old} = $new; + } } close IN; } @@ -35,6 +64,9 @@ sub read_transfile { # the file contents are then written. No particular care is taken to ensure that the # file is not lost if a system failure occurs at an inopportune time. It is assumed # that the html files being processed here can be recreated on demand. +# +# Links to other files are added to the %filelist for processing. That way, +# all linked files will be processed (assuming they are local). sub translate_html { my ($filename,$trans,$filelist) = @_; my ($contents,$out,$this,$img,$dest); @@ -45,7 +77,12 @@ sub translate_html { $filename =~ /^(http|ftp|mailto)\:/ and return 0; $filename =~ s/^file\:\/\///; # Load the contents of the html file. - open IF,"<$path$filename" or die "Cannot open $path$filename for reading\n"; + if (!open IF,"<$path$filename") { + print "WARNING: Cannot open $path$filename for reading\n"; + print " Image Filename Translation aborted\n\n"; + exit 0; + } + while () { $contents .= $_; } @@ -74,7 +111,7 @@ sub translate_html { print OF $out; close OF; - # Now look for any links to other files. + # Now look for any links to other files and add them to the list of files to do. while ($out =~ /\<\s*A[^\>]*HREF=\"(.*?)\"/si) { $out = $'; $dest = $1; @@ -92,7 +129,7 @@ sub rename_images { foreach (keys(%$translate)) { $response = `mv -f $path$_ $path$translate->{$_} 2>&1`; - $response and die $response; + $response and print "ERROR from system $response\n"; } } @@ -104,8 +141,16 @@ sub rename_images { # any links to other files are added to the %filelist. A hash of processed # files is kept so we don't do any twice. +# The first argument must be either --to_meaningful_names or --from_meaningful_names + my (%translate,$search_regex,%filelist,%completed,$thisfile); -my $cnt; +my ($cnt,$direction); + +my $arg0 = shift(@ARGV); +$arg0 =~ /^(--to_meaningful_names|--from_meaningful_names)$/ or + die "ERROR: First argument must be either \'--to_meaningful_names\' or \'--from_meaningful_names\'\n"; + +$direction = ($arg0 eq '--to_meaningful_names') ? 0 : 1; (@ARGV) or die "ERROR: Filename(s) to process must be given as arguments\n"; @@ -114,13 +159,15 @@ my $tmp = $ARGV[0]; ($path) = $tmp =~ /(.*\/)/; $path = '' unless $path; -read_transfile(\%translate); +read_transfile(\%translate,$direction); foreach (@ARGV) { # Strip the path from the filename, and use it later on. - s/(.*\/)//; - $path = $1; - $path = '' unless $path; + if (s/(.*\/)//) { + $path = $1; + } else { + $path = ''; + } $filelist{$_} = ''; while ($thisfile = (keys(%filelist))[0]) { @@ -128,7 +175,7 @@ foreach (@ARGV) { delete($filelist{$thisfile}); $completed{$thisfile} = ''; } - print "translate_images.pl: $cnt images translated to meaningful names\n"; + print "translate_images.pl: $cnt image filenames translated ",($direction)?"from":"to"," meaningful names\n"; } rename_images(\%translate); diff --git a/docs/manual/Makefile b/docs/manual/Makefile index 1144a941..76f6ed00 100644 --- a/docs/manual/Makefile +++ b/docs/manual/Makefile @@ -112,10 +112,11 @@ devpdfm: html: @echo "Making html" + ./translate_images.pl --from_meaningful_names bacula.html @cp -fp ${IMAGES}/*.eps . latex2html -white -no_subdir -split 0 -toc_stars -white -notransparent \ bacula >/dev/null - ./translate_images.pl bacula.html + ./translate_images.pl --to_meaningful_names bacula.html @rm -f *.eps *.gif *.jpg devhtml: @@ -130,7 +131,8 @@ devhtml: web: @echo "Making web" @mkdir -p bacula - @rm -rf bacula/* + ./translate_images.pl --from_meaningful_names bacula/Bacula_Users_Guide.html + @rm -rf bacula/*.html @cp -fp ${IMAGES}/*.eps . @rm -f next.eps next.png prev.eps prev.png up.eps up.png # @cp -fp ${IMAGES}/*.eps ${IMAGES}/*.png *.txt bacula @@ -138,7 +140,7 @@ web: @rm -f bacula/next.eps bacula/next.png bacula/prev.eps bacula/prev.png bacula/up.eps bacula/up.png latex2html -split 4 -local_icons -t "Bacula User's Guide" -long_titles 4 \ -toc_stars -contents_in_nav -white -notransparent bacula >/dev/null - ./translate_images.pl bacula/Bacula_Users_Guide.html + ./translate_images.pl --to_meaningful_names bacula/Bacula_Users_Guide.html @cp -f bacula/Bacula_Users_Guide.html bacula/index.html @cp -f bacula/Bacula_Freque_Asked_Questi.html bacula/faq.html @rm -f *.eps *.gif *.jpg bacula/*.eps *.old diff --git a/docs/manual/translate_images.pl b/docs/manual/translate_images.pl index 5be523cf..c4e7bf2c 100755 --- a/docs/manual/translate_images.pl +++ b/docs/manual/translate_images.pl @@ -2,29 +2,58 @@ # use strict; +# Used to change the names of the image files generated by latex2html from imgxx.png +# to meaningful names. Provision is made to go either from or to the meaningful names. +# The meaningful names are obtained from a file called imagename_translations, which +# is generated by extensions to latex2html in the make_image_file subroutine in +# bacula.perl. + # Opens the file imagename_translations and reads the contents into a hash. +# The hash is creaed with the imgxx.png files as the key if processing TO +# meaningful filenames, and with the meaningful filenames as the key if +# processing FROM meaningful filenames. # Then opens the html file(s) indicated in the command-line arguments and # changes all image references according to the translations described in the # above file. Finally, it renames the image files. # # Original creation: 3-27-05 by Karl Cunningham. +# Modified 5-21-05 to go FROM and TO meaningful filenames. # my $TRANSFILE = "imagename_translations"; my $path; # Loads the contents of $TRANSFILE file into the hash referenced in the first -# argument. +# argument. The hash is loaded to translate old to new if $direction is 0, +# otherwise it is loaded to translate new to old. In this context, the +# 'old' filename is the meaningful name, and the 'new' filename is the +# imgxx.png filename. It is assumed that the old image is the one that +# latex2html has used as the source to create the imgxx.png filename. +# The filename extension is taken from the file sub read_transfile { - my $trans = shift; + my ($trans,$direction) = @_; + + if (!open IN,"<$path$TRANSFILE") { + print "WARNING: Cannot open image translation file $path$TRANSFILE for reading\n"; + print " Image filename translation aborted\n\n"; + exit 0; + } - open IN,"<$path$TRANSFILE" or die "Cannot open image translation file $path$TRANSFILE for reading\n"; while () { chomp; my ($new,$old) = split(/\001/); - # The filename extension of the new one must be made to be the old one. - my ($ext) = $new =~ /.*(\..*)$/; - $old =~ s/(.*)\..*$/$1$ext/; - $trans->{$new} = $old; + + # Old filenames will usually have a leading ./ which we don't need. + $old =~ s/^\.\///; + + # The filename extension of the old filename must be made to match + # the new filename because it indicates the encoding format of the image. + my ($ext) = $new =~ /(\.[^\.]*)$/; + $old =~ s/\.[^\.]*$/$ext/; + if ($direction == 0) { + $trans->{$new} = $old; + } else { + $trans->{$old} = $new; + } } close IN; } @@ -35,6 +64,9 @@ sub read_transfile { # the file contents are then written. No particular care is taken to ensure that the # file is not lost if a system failure occurs at an inopportune time. It is assumed # that the html files being processed here can be recreated on demand. +# +# Links to other files are added to the %filelist for processing. That way, +# all linked files will be processed (assuming they are local). sub translate_html { my ($filename,$trans,$filelist) = @_; my ($contents,$out,$this,$img,$dest); @@ -45,7 +77,12 @@ sub translate_html { $filename =~ /^(http|ftp|mailto)\:/ and return 0; $filename =~ s/^file\:\/\///; # Load the contents of the html file. - open IF,"<$path$filename" or die "Cannot open $path$filename for reading\n"; + if (!open IF,"<$path$filename") { + print "WARNING: Cannot open $path$filename for reading\n"; + print " Image Filename Translation aborted\n\n"; + exit 0; + } + while () { $contents .= $_; } @@ -74,7 +111,7 @@ sub translate_html { print OF $out; close OF; - # Now look for any links to other files. + # Now look for any links to other files and add them to the list of files to do. while ($out =~ /\<\s*A[^\>]*HREF=\"(.*?)\"/si) { $out = $'; $dest = $1; @@ -92,7 +129,7 @@ sub rename_images { foreach (keys(%$translate)) { $response = `mv -f $path$_ $path$translate->{$_} 2>&1`; - $response and die $response; + $response and print "ERROR from system $response\n"; } } @@ -104,8 +141,16 @@ sub rename_images { # any links to other files are added to the %filelist. A hash of processed # files is kept so we don't do any twice. +# The first argument must be either --to_meaningful_names or --from_meaningful_names + my (%translate,$search_regex,%filelist,%completed,$thisfile); -my $cnt; +my ($cnt,$direction); + +my $arg0 = shift(@ARGV); +$arg0 =~ /^(--to_meaningful_names|--from_meaningful_names)$/ or + die "ERROR: First argument must be either \'--to_meaningful_names\' or \'--from_meaningful_names\'\n"; + +$direction = ($arg0 eq '--to_meaningful_names') ? 0 : 1; (@ARGV) or die "ERROR: Filename(s) to process must be given as arguments\n"; @@ -114,13 +159,15 @@ my $tmp = $ARGV[0]; ($path) = $tmp =~ /(.*\/)/; $path = '' unless $path; -read_transfile(\%translate); +read_transfile(\%translate,$direction); foreach (@ARGV) { # Strip the path from the filename, and use it later on. - s/(.*\/)//; - $path = $1; - $path = '' unless $path; + if (s/(.*\/)//) { + $path = $1; + } else { + $path = ''; + } $filelist{$_} = ''; while ($thisfile = (keys(%filelist))[0]) { @@ -128,7 +175,7 @@ foreach (@ARGV) { delete($filelist{$thisfile}); $completed{$thisfile} = ''; } - print "translate_images.pl: $cnt images translated to meaningful names\n"; + print "translate_images.pl: $cnt image filenames translated ",($direction)?"from":"to"," meaningful names\n"; } rename_images(\%translate); -- 2.39.5