Mail Archives: djgpp/1992/07/20/04:03:01
Eric Backus writes:
> > When you open a file in binary mode, fscanf does not work correctly.
> > It doesn't consider '\r' as whitespace, so it fails on files with
> > the usal MSDOS "\r\n" end of line. The following patch should help.
> > If you want to try it, please let me know, whether it worked or not.
>
> According to the ANSI C definition of fscanf(), "white space" in the
> input stream consists of any combination of: space, tab, newline,
> vertical tab, formfeed, and carriage return. Those are ASCII
> characters 0x20, 0x09, 0x0a, 0x0b, 0x0c, and 0x0d.
>
> So, it appears that we still need to add cases for vertical tab ('\v')
> and formfeed ('\f').
Thanks to Eric. Now all the cases Eric mentioned should work.
Dieter
Dieter Buerssner (B\"ur\ss{}ner) -- buers AT dg1 DOT chemie DOT uni-konstanz DOT de
Universitaet Konstanz -- Fakultaet Chemie -- Postfach 5560
7750 Konstanz -- Germany -- +49-7531-882021
*** /djgpp/libsrc/c/io/doscan.c Tue Apr 7 22:45:26 1992
--- doscan.c Sun Jul 19 20:05:08 1992
***************
*** 22,28 ****
static char _sctab[256] = {
0,0,0,0,0,0,0,0,
! 0,SPC,SPC,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
SPC,0,0,0,0,0,0,0,
--- 22,29 ----
static char _sctab[256] = {
0,0,0,0,0,0,0,0,
! /* \t \n \v \f \r */
! 0,SPC,SPC,SPC,SPC,SPC,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
SPC,0,0,0,0,0,0,0,
***************
*** 80,87 ****
case ' ':
case '\n':
! case '\t':
! while ((ch1 = getc(iop))==' ' || ch1=='\t' || ch1=='\n')
;
if (ch1 != EOF)
ungetc(ch1, iop);
--- 81,91 ----
case ' ':
case '\n':
! case '\t':
! case '\r':
! case '\f':
! case '\v':
! while (((ch1 = getc(iop)) != EOF) && (_sctab[ch1] & SPC))
;
if (ch1 != EOF)
ungetc(ch1, iop);
***************
*** 126,132 ****
np = numbuf;
expseen = 0;
negflg = 0;
! while ((c = getc(iop))==' ' || c=='\t' || c=='\n');
if (c=='-') {
negflg++;
*np++ = c;
--- 130,137 ----
np = numbuf;
expseen = 0;
negflg = 0;
! while (((c = getc(iop)) != EOF) && (_sctab[c] & SPC))
! ;
if (c=='-') {
negflg++;
*np++ = c;
- Raw text -