Changeset 24601

Show
Ignore:
Timestamp:
15.09.2011 18:28:42 (8 years ago)
Author:
ak19
Message:

Dr Bainbridge suggested corrections to commits of revision 24600: 1. gs-magick.pl: close call on Pipe only if successfully opened. 2. Command_status always needs to be shifted and turned into its signed value for display in convertutil.pm. 3. giget calls to imagemagick more eficient: doesn't call identify twice, but just once since the exit code and output to STDOUT can both be inspected after just one call. Moreover, exit code needed to be tested for equality against 0, not whether it is greater than 0, so no shifting and converting to signed value required.

Location:
main/trunk/greenstone2
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/bin/script/gs-magick.pl

    r24600 r24601  
    128128    #my $result = `$magick_cmd`; # This way will trap STDOUT into local variable 
    129129 
     130    my $result = ""; 
    130131    if (!open(PIN, "$magick_cmd |")) { 
    131132    print STDERR "*** Can't run $magick_cmd. Error was: $!"; 
     133    } else { 
     134    while (defined (my $imagick_output_line = <PIN>)) { 
     135        $result = $result.$imagick_output_line; 
     136    } 
     137    close(PIN); 
    132138    } 
    133     my $result = ""; 
    134     while (defined (my $imagick_output_line = <PIN>)) { 
    135     $result = $result.$imagick_output_line; 
    136     } 
    137     close(PIN); 
    138139    
    139140    # Perl Special Variables http://www.kichwa.com/quik_ref/spec_variables.html 
  • main/trunk/greenstone2/perllib/convertutil.pm

    r24600 r24601  
    176176        $had_error = 1; 
    177177         
    178         # for imagemagick commands that go via gs-magick.pl, need to shift exit code by 8 and then  
    179         # convert to its signed value to get the actual exit code that imagemagick had emitted. 
    180         my $signed_cmd_status = $command_status; 
    181         $signed_cmd_status >>= 8; 
    182         $signed_cmd_status = (($signed_cmd_status & 0x80) ? -(0x100 - ($signed_cmd_status & 0xFF)) : $signed_cmd_status);    
    183  
    184         print $outhandle "Error: processing command failed.  Exit status $command_status (signed value: $signed_cmd_status)\n"; 
     178        # for commands that go via an intermediate layer (like commands to imagemagick go  
     179        # through gs-magick.pl), need to shift exit code by 8 and then convert to its  
     180        # signed value to get the actual exit code that imagemagick had emitted. 
     181        $command_status >>= 8; 
     182        $command_status = (($command_status & 0x80) ? -(0x100 - ($command_status & 0xFF)) : $command_status);    
     183 
     184        print $outhandle "Error: processing command failed.  Exit status $command_status\n"; 
    185185 
    186186        if ($verbosity >= 3) { 
  • main/trunk/greenstone2/perllib/giget.pm

    r24600 r24601  
    152152        } 
    153153        else { 
     154        my $command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$output_fname\" 2>&1"; 
     155        my $result = `$command`; 
     156         
     157        my $status = $?; 
    154158        # need to shift the $? exit code returned by system() by 8 bits and 
    155159        # then convert it to a signed value to work out whether it is indeed > 0 
    156         my $status = system("\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$output_fname\""); 
    157         $status >>= 8; 
    158         $status = (($status & 0x80) ? -(0x100 - ($status & 0xFF)) : $status); 
    159  
    160         if($status > 0 ) { 
     160        #$status >>= 8; 
     161        #$status = (($status & 0x80) ? -(0x100 - ($status & 0xFF)) : $status); 
     162        #if($status > 0 ) { 
     163        if($status != 0 ) {  
    161164            print STDERR "**** NOT JPEG: output_fname \n"; 
    162165            unlink $output_fname; 
    163166        }  
    164167        else { 
    165             my $command = "\"".&util::get_perl_exec()."\" -S gs-magick.pl identify \"$output_fname\" 2>&1"; 
    166             my $result = `$command`; 
    167168             
    168169            my $type =   'unknown';