im_csv2vips() allows lines ending in EOF

This commit is contained in:
John Cupitt 2010-03-01 16:30:56 +00:00
parent 2fa3d6b3da
commit 22045aafaf
2 changed files with 13 additions and 3 deletions

View File

@ -17,6 +17,7 @@
- vipsthumbnail has selectable interpolators, optional sharpen - vipsthumbnail has selectable interpolators, optional sharpen
- moved a lot of stuff (eg. im_iscomplex()) from deprecated to - moved a lot of stuff (eg. im_iscomplex()) from deprecated to
almostdeprecated to avoid breakage almostdeprecated to avoid breakage
- im_csv2vips(): allow lines that end with EOF rather than \n
- im_vips2tiff has a bigtiff option - im_vips2tiff has a bigtiff option
15/1/10 started 7.21.1 15/1/10 started 7.21.1

View File

@ -11,6 +11,8 @@
* - added im_csv2vips_header() * - added im_csv2vips_header()
* 4/2/10 * 4/2/10
* - gtkdoc * - gtkdoc
* 1/3/10
* - allow lines that end with EOF rather than \n
*/ */
/* /*
@ -57,15 +59,22 @@
#include <dmalloc.h> #include <dmalloc.h>
#endif /*WITH_DMALLOC*/ #endif /*WITH_DMALLOC*/
/* Skip to the start of the next line (ie. read until we see a '\n'), return
* zero if we are at EOF. Don't forget to allow for lines that are terminated
* by EOF rather than \n.
*/
static int static int
skip_line( FILE *fp ) skip_line( FILE *fp )
{ {
int ch; int ch;
if( feof( fp ) )
return( 0 );
while( (ch = fgetc( fp )) != '\n' && ch != EOF ) while( (ch = fgetc( fp )) != '\n' && ch != EOF )
; ;
return( ch ); return( -1 );
} }
static int static int
@ -172,7 +181,7 @@ read_csv( FILE *fp, IMAGE *out,
/* Skip first few lines. /* Skip first few lines.
*/ */
for( i = 0; i < start_skip; i++ ) for( i = 0; i < start_skip; i++ )
if( skip_line( fp ) == EOF ) { if( !skip_line( fp ) ) {
im_error( "im_csv2vips", im_error( "im_csv2vips",
"%s", _( "end of file while skipping start" ) ); "%s", _( "end of file while skipping start" ) );
return( -1 ); return( -1 );
@ -205,7 +214,7 @@ read_csv( FILE *fp, IMAGE *out,
*/ */
if( lines == -1 ) { if( lines == -1 ) {
fgetpos( fp, &pos ); fgetpos( fp, &pos );
for( lines = 0; skip_line( fp ) != EOF; lines++ ) for( lines = 0; skip_line( fp ); lines++ )
; ;
fsetpos( fp, &pos ); fsetpos( fp, &pos );
} }