From: hpa Date: Fri, 22 Aug 2003 17:37:44 +0000 (+0000) Subject: ppmtolss16: handle header comments X-Git-Tag: syslinux-3.11~530 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=76254ab3475431424b0bac42d402a846d6e3f815;p=platform%2Fupstream%2Fsyslinux.git ppmtolss16: handle header comments --- diff --git a/NEWS b/NEWS index ad58642..cc01ca0 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,10 @@ Changes in 2.06: boot failure, depending on the length of the kernel. * ISOLINUX: Fix problem that would occationally cause a boot failure, depending on the length of directories. + * SYSLINUX: Win32 installer now flushes buffers. + * ppmtolss16: Try to be compliant with the PPM spec; + actually process comments in the header and odd + alignments of the various parameters. Changes in 2.05: * PXELINUX: Add a default query based on the hardware address diff --git a/ppmtolss16 b/ppmtolss16 index b654df9..1f4e1a9 100755 --- a/ppmtolss16 +++ b/ppmtolss16 @@ -35,8 +35,7 @@ ## ## At the start of row, the "previous pixel" is assumed to be zero. ## -## BUG: This program does not handle comments in the header, nor -## "plain" ppm format. +## BUG: This program does not handle "plain" ppm format. ## ## Usage: ## @@ -46,12 +45,49 @@ ## the color #rrggbb (hex) should be assigned index i (decimal) ## + +use IO::Handle; + eval { use bytes; }; eval { binmode STDIN; }; eval { binmode STDOUT; }; $magic = 0x1413f33d; +# Get a token from the PPM header. Ignore comments and leading +# and trailing whitespace, as is required by the spec. +# This routine eats exactly one character of trailing whitespace, +# unless it is a comment (in which case it eats the comment up +# to and including the end of line.) +sub get_token() { + my($token, $ch); + my($ch); + + do { + $ch = getc(STDIN); + return undef if ( !defined($ch) ); # EOF + if ( $ch eq '#' ) { + do { + $ch = getc(STDIN); + return undef if ( !defined($ch) ); + } while ( $ch ne "\n" ); + } + } while ( $ch =~ /^[ \t\n\v\f\r]$/ ); + + $token = $ch; + while ( 1 ) { + $ch = getc(STDIN); + last if ( $ch =~ /^[ \t\n\v\f\r\#]$/ ); + $token .= $ch; + } + if ( $ch eq '#' ) { + do { + $ch = getc(STDIN); + } while ( defined($ch) && $ch ne "\n" ); + } + return $token; +} + sub rgbconvert($$) { my($rgb,$maxmult) = @_; my($r,$g,$b); @@ -105,22 +141,23 @@ foreach $arg ( @ARGV ) { $force_index{$rgb} = $i; } -$form = ; -die "$0: stdin is not a raw PPM file" if ( $form ne "P6\n" ); -$sizes = ; -chomp $sizes; -if ( $sizes !~ /^([0-9]+)\s+([0-9]+)\s*$/ ) { +$form = get_token(); +die "$0: stdin is not a raw PPM file" if ( $form ne 'P6' ); + +$xsize = get_token(); +$ysize = get_token(); +if ( $xsize !~ /^([0-9]+)$/ || $ysize !~ /^([0-9]+)$/ ) { die "$0: Input format error 1\n"; } -$xsize = $1 + 0; -$ysize = $2 + 0; -$maxcol = ; -$maxmult = 64/($maxcol+1); # Equal buckets conversion +$xsize += 0; $ysize += 0; # Convert to number + +$maxcol = get_token(); chomp $maxcol; -if ( $maxcol !~ /^([0-9]+)\s*$/ ) { +if ( $maxcol !~ /^([0-9]+)$/ ) { die "$0: Input format error 2\n"; } -$maxcol = $1 + 0; +$maxcol += 0; +$maxmult = 64/($maxcol+1); # Equal buckets conversion @data = ();