]> git.sur5r.net Git - bacula/docs/blobdiff - docs/manual/translate_images.pl
Final changes
[bacula/docs] / docs / manual / translate_images.pl
index c7225118df6e8e5ca1cd2f0d8658b601a3961011..69395fe48f2e76977cc0d4332ba8edfc983fd77e 100755 (executable)
@@ -30,34 +30,34 @@ my $path;
 #  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,$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;
-       }
-
-       while (<IN>) {
-               chomp;
-               my ($new,$old) = split(/\001/);
-
-               # 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;
+        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;
+        }
+
+        while (<IN>) {
+                chomp;
+                my ($new,$old) = split(/\001/);
+
+                # 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;
 }
-       
+        
 # Translates the image names in the file given as the first argument, according to 
 #  the translations in the hash that is given as the second argument.
 #  The file contents are read in entirely into a string, the string is processed, and
@@ -68,73 +68,73 @@ sub read_transfile {
 # 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);
-       my $cnt = 0;
-
-       # If the filename is an external link ignore it.  And drop any file:// from
-       #  the filename.
-       $filename =~ /^(http|ftp|mailto)\:/ and return 0;
-       $filename =~ s/^file\:\/\///;
-       # Load the contents of the html file.
-       if (!open IF,"<$path$filename") {
-               print "WARNING:  Cannot open $path$filename for reading\n";
-               print "  Image Filename Translation aborted\n\n";
-               exit 0;
-       }
-
-       while (<IF>) {
-               $contents .= $_;
-       }
-       close IF;
-
-       # Now do the translation...
-       #  First, search for an image filename.
-       while ($contents =~ /\<\s*IMG[^\>]*SRC=\"/si) {
-               $contents = $';
-               $out .= $` . $&;
-               
-               # The next thing is an image name.  Get it and translate it.
-               $contents =~ /^(.*?)\"/s;
-               $contents = $';
-               $this = $&;
-               $img = $1;
-               # If the image is in our list of ones to be translated, do it
-               #  and feed the result to the output.
-               $cnt += $this =~ s/$img/$trans->{$img}/ if (defined($trans->{$img}));
-               $out .= $this;
-       }
-       $out .= $contents;
-
-       # Now send the translated text to the html file, overwriting what's there.
-       open OF,">$path$filename" or die "Cannot open $path$filename for writing\n";
-       print OF $out;
-       close OF;
-
-       # 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;
-               # Drop an # and anything after it.
-               $dest =~ s/\#.*//;
-               $filelist->{$dest} = '' if $dest;
-       }
-       return $cnt;
+        my ($filename,$trans,$filelist) = @_;
+        my ($contents,$out,$this,$img,$dest);
+        my $cnt = 0;
+
+        # If the filename is an external link ignore it.  And drop any file:// from
+        #  the filename.
+        $filename =~ /^(http|ftp|mailto)\:/ and return 0;
+        $filename =~ s/^file\:\/\///;
+        # Load the contents of the html file.
+        if (!open IF,"<$path$filename") {
+                print "WARNING:  Cannot open $path$filename for reading\n";
+                print "  Image Filename Translation aborted\n\n";
+                exit 0;
+        }
+
+        while (<IF>) {
+                $contents .= $_;
+        }
+        close IF;
+
+        # Now do the translation...
+        #  First, search for an image filename.
+        while ($contents =~ /\<\s*IMG[^\>]*SRC=\"/si) {
+                $contents = $';
+                $out .= $` . $&;
+                
+                # The next thing is an image name.  Get it and translate it.
+                $contents =~ /^(.*?)\"/s;
+                $contents = $';
+                $this = $&;
+                $img = $1;
+                # If the image is in our list of ones to be translated, do it
+                #  and feed the result to the output.
+                $cnt += $this =~ s/$img/$trans->{$img}/ if (defined($trans->{$img}));
+                $out .= $this;
+        }
+        $out .= $contents;
+
+        # Now send the translated text to the html file, overwriting what's there.
+        open OF,">$path$filename" or die "Cannot open $path$filename for writing\n";
+        print OF $out;
+        close OF;
+
+        # 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;
+                # Drop an # and anything after it.
+                $dest =~ s/\#.*//;
+                $filelist->{$dest} = '' if $dest;
+        }
+        return $cnt;
 }
-       
+        
 # REnames the image files spefified in the %translate hash.
 sub rename_images {
-       my $translate = shift;
-       my ($response);
-
-       foreach (keys(%$translate)) {
-               if (! $translate->{$_}) {
-                       print "    WARNING: No destination Filename for $_\n";
-               } else {
-                       $response = `mv -f $path$_ $path$translate->{$_} 2>&1`;
-                       $response and print "ERROR from system    $response\n";
-               }
-       }
+        my $translate = shift;
+        my ($response);
+
+        foreach (keys(%$translate)) {
+                if (! $translate->{$_}) {
+                        print "    WARNING: No destination Filename for $_\n";
+                } else {
+                        $response = `mv -f $path$_ $path$translate->{$_} 2>&1`;
+                        $response and print "ERROR from system    $response\n";
+                }
+        }
 }
 
 #################################################
@@ -152,7 +152,7 @@ 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";
+        die "ERROR: First argument must be either \'--to_meaningful_names\' or \'--from_meaningful_names\'\n";
 
 $direction = ($arg0 eq '--to_meaningful_names') ? 0 : 1;
 
@@ -166,20 +166,20 @@ $path = '' unless $path;
 read_transfile(\%translate,$direction);
 
 foreach (@ARGV) {
-       # Strip the path from the filename, and use it later on.
-       if (s/(.*\/)//) {
-               $path = $1;
-       } else {
-               $path = '';
-       }
-       $filelist{$_} = '';
-
-       while ($thisfile = (keys(%filelist))[0]) {
-               $cnt += translate_html($thisfile,\%translate,\%filelist) if (!exists($completed{$thisfile}));
-               delete($filelist{$thisfile});
-               $completed{$thisfile} = '';
-       }
-       print "translate_images.pl: $cnt image filenames translated ",($direction)?"from":"to"," meaningful names\n";
+        # Strip the path from the filename, and use it later on.
+        if (s/(.*\/)//) {
+                $path = $1;
+        } else {
+                $path = '';
+        }
+        $filelist{$_} = '';
+
+        while ($thisfile = (keys(%filelist))[0]) {
+                $cnt += translate_html($thisfile,\%translate,\%filelist) if (!exists($completed{$thisfile}));
+                delete($filelist{$thisfile});
+                $completed{$thisfile} = '';
+        }
+        print "translate_images.pl: $cnt image filenames translated ",($direction)?"from":"to"," meaningful names\n";
 }
 
 rename_images(\%translate);