From bug-octave-request at bevo dot che dot wisc dot edu Wed Nov 3 19:43:07 1999 Subject: Unidentified subject! From: "John W. Eaton" To: Vladimir Eltsov Cc: bug-octave at bevo dot che dot wisc dot edu Date: Wed, 3 Nov 1999 19:42:18 -0600 (CST) On 27-Oct-1999, Vladimir Eltsov wrote: | To: bug-octave at bevo dot che dot wisc dot edu | Cc: ve | Subject: fscanf makes stream unusable on matching failure | | Bug report for Octave 2.0.14 configured for i386-redhat-linux-gnu | | Description: | ----------- | | Manual mentions that on matching failure 'scanf returns immediately leaving | the first non-matching character as the next character to be read from the | stream'. Instead, stream is put in unusable state (see below). | | Repeat-By: | --------- | | > cat zzz | 1 2 3 uuu 4 | > octave | GNU Octave, version 2.0.14 (i386-redhat-linux-gnu). | Copyright (C) 1996, 1997, 1998, 1999 John W. Eaton. | This is free software with ABSOLUTELY NO WARRANTY. | For details, type `warranty'. | | octave:1> fi = fopen('zzz','r') | fi = 3 | octave:2> a = fscanf(fi,'%f',Inf) | a = | | 1 | 2 | 3 | | octave:3> feof(fi) | ans = 0 | octave:4> ferror(fi) | ans = | octave:5> ftell(fi) | ans = -1 | octave:6> fgetl(fi) | ans = -1 | octave:7> fclose(fi) | ans = 0 | | Results 1, 2, 3 and 7 are expected, but 4, 5 and 6 - not. Here is a patch for the 2.1.x sources. The changes required for the 2.0.x sources should not be too much different. With it, here is what I see: $ cat x 1 2 3 uuu 4 $ src/octave GNU Octave, version 2.1.19 (i686-pc-linux-gnu). Copyright (C) 1996, 1997, 1998 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. *** This is a development version of Octave. Development releases *** are provided for people who want to help test, debug, and improve *** Octave. *** *** If you want a stable, well-tested version of Octave, you should be *** using one of the stable releases (when this development release *** was made, the latest stable version was 2.0.14). octave:1> f = fopen ("x"); octave:2> fscanf (f, "%f", Inf) is.rdstate (): 2 is.rdstate (): 0 ans = 1 2 3 octave:3> feof (f) ans = 0 octave:4> ferror (f) ans = octave:5> ftell (f) ans = 6 octave:6> fgetl (f) ans = uuu 4 octave:7> fclose (f) ans = 0 Thanks, jwe Index: oct-stream.cc =================================================================== RCS file: /usr/local/cvsroot/octave/src/oct-stream.cc,v retrieving revision 1.33 diff -c -r1.33 oct-stream.cc *** oct-stream.cc 1999/09/10 05:17:49 1.33 --- oct-stream.cc 1999/11/04 01:40:13 *************** *** 1264,1269 **** --- 1264,1275 ---- final_nc = 1; } + // If it looks like we have a matching failure, then + // reset the failbit in the stream state. + + if (is.rdstate () & ios::failbit) + is.clear (is.rdstate () & (~ios::failbit)); + // XXX FIXME XXX -- is this the right thing to do? // What about other streams? if (name () == "stdin") *************** *** 1336,1345 **** if (! is) { ! error ("fscanf: read error"); ! // XXX FIXME XXX -- is this the right thing to do? if (name () == "stdin") { is.clear (); --- 1342,1357 ---- if (! is) { ! // If it looks like we have a matching failure, then ! // reset the failbit in the stream state. ! if (is.rdstate () & ios::failbit) ! is.clear (is.rdstate () & (~ios::failbit)); ! else ! error ("fscanf: read error"); + // XXX FIXME XXX -- is this the right thing to do? + // What about other streams? if (name () == "stdin") { is.clear (); --------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. To ensure that development continues, see www.che.wisc.edu/octave/giftform.html Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html ---------------------------------------------------------------------