check for \nEOF in im_csv2vips()

This commit is contained in:
John Cupitt 2010-03-07 14:54:12 +00:00
parent 6e1421b3b8
commit 273b2dc26f

View File

@ -60,17 +60,23 @@
#endif /*WITH_DMALLOC*/ #endif /*WITH_DMALLOC*/
/* Skip to the start of the next line (ie. read until we see a '\n'), return /* 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 * zero if we are at EOF.
* by EOF rather than \n. *
* Files can end with EOF or with \nEOF. Tricky!
*/ */
static int static int
skip_line( FILE *fp ) skip_line( FILE *fp )
{ {
int ch; int ch;
if( feof( fp ) ) /* Are we at a delayed EOF? See below.
*/
if( (ch = fgetc( fp )) == EOF )
return( 0 ); return( 0 );
ungetc( ch, fp );
/* If we hit EOF and no \n, wait until the next call to report EOF.
*/
while( (ch = fgetc( fp )) != '\n' && ch != EOF ) while( (ch = fgetc( fp )) != '\n' && ch != EOF )
; ;
@ -195,8 +201,10 @@ read_csv( FILE *fp, IMAGE *out,
"%s", _( "unable to seek" ) ); "%s", _( "unable to seek" ) );
return( -1 ); return( -1 );
} }
for( columns = 0; (ch = read_double( fp, whitemap, sepmap, for( columns = 0;
start_skip + 1, columns + 1, &d )) == 0; columns++ ) (ch = read_double( fp, whitemap, sepmap,
start_skip + 1, columns + 1, &d )) == 0;
columns++ )
; ;
fsetpos( fp, &pos ); fsetpos( fp, &pos );
@ -217,6 +225,8 @@ read_csv( FILE *fp, IMAGE *out,
for( lines = 0; skip_line( fp ); lines++ ) for( lines = 0; skip_line( fp ); lines++ )
; ;
fsetpos( fp, &pos ); fsetpos( fp, &pos );
printf( "detected %d lines after skip\n", lines );
} }
im_initdesc( out, columns, lines, 1, im_initdesc( out, columns, lines, 1,