Mail Archives: djgpp-workers/2004/03/20/13:13:37
Hello.
First note that comp.std.c seems to agree with me:
<http://groups.google.se/groups?hl=sv&lr=&ie=UTF-8&threadm=4057500f%240%2496976%24cc7c7865%40news.luth.se&rnum=1&prev=/groups%3Fq%3Dsscanf%2Bsuppressed%2Bassignments%26hl%3Dsv%26lr%3D%26ie%3DUTF-8%26selm%3D4057500f%25240%252496976%2524cc7c7865%2540news.luth.se%26rnum%3D1>.
Here the patch:
Index: djgpp/src/libc/ansi/stdio/doscan.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/doscan.c,v
retrieving revision 1.15
diff -p -u -r1.15 doscan.c
--- djgpp/src/libc/ansi/stdio/doscan.c 23 Nov 2003 21:14:48 -0000 1.15
+++ djgpp/src/libc/ansi/stdio/doscan.c 20 Mar 2004 17:48:30 -0000
@@ -59,11 +59,13 @@ _doscan_low(FILE *iop, int (*scan_getc)(
register int ch;
int nmatch, len, ch1;
int *ptr, fileended, size;
+ int suppressed;
decimal = localeconv()->decimal_point[0];
nchars = 0;
nmatch = 0;
fileended = 0;
+ suppressed = 0;
for (;;) switch (ch = *fmt++) {
case '\0':
return (nmatch);
@@ -73,8 +75,9 @@ _doscan_low(FILE *iop, int (*scan_getc)(
ptr = 0;
if (ch != '*')
ptr = va_arg(argp, int *);
- else
+ else {
ch = *fmt++;
+ }
len = 0;
size = REGULAR;
while (isdigit(ch & 0xff)) {
@@ -168,11 +171,13 @@ _doscan_low(FILE *iop, int (*scan_getc)(
{
if (ptr)
nmatch++;
+ else
+ suppressed = 1;
}
else
{
- if (fileended)
- return(EOF);
+ if (fileended && !nmatch && !suppressed)
+ return(EOF);
return(nmatch);
}
break;
@@ -198,7 +203,7 @@ _doscan_low(FILE *iop, int (*scan_getc)(
if (ch1 != EOF) nchars++;
if (ch1 != ch) {
if (ch1==EOF)
- return(nmatch? nmatch: EOF);
+ return(nmatch||suppressed? nmatch: EOF);
scan_ungetc(ch1, iop);
nchars--;
return(nmatch);
Index: djgpp/tests/libc/ansi/stdio/sscanf3.c
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/stdio/sscanf3.c,v
retrieving revision 1.1
diff -p -u -r1.1 sscanf3.c
--- djgpp/tests/libc/ansi/stdio/sscanf3.c 23 Nov 2003 21:14:48 -0000 1.1
+++ djgpp/tests/libc/ansi/stdio/sscanf3.c 20 Mar 2004 17:48:32 -0000
@@ -18,28 +18,28 @@ sscanf_testcase_t sscanf_testcases[] = {
/* No assignment */
{ "", "%*[0123456789]%*c", EOF, "", "" },
{ "X", "%*[0123456789]%*c", 0, "", "" },
- { "1", "%*[0123456789]%*c", EOF, "", "" },
+ { "1", "%*[0123456789]%*c", 0, "", "" },
{ "1X2", "%*[0123456789]%*[0123456789]", 0, "", "" },
{ "1,2", "%*[0123456789],%*[0123456789]", 0, "", "" },
/* Assign first */
{ "", "%[0123456789]%*c", EOF, "", "" },
{ "X", "%[0123456789]%*c", 0, "", "" },
- { "1", "%[0123456789]%*c", EOF, "1", "" },
+ { "1", "%[0123456789]%*c", 1, "1", "" },
{ "1X2", "%[0123456789]%*[0123456789]", 1, "1", "" },
{ "1,2", "%[0123456789],%*[0123456789]", 1, "1", "" },
/* Assign second */
{ "", "%*[0123456789]%c", EOF, "", "" },
{ "X", "%*[0123456789]%c", 0, "", "" },
- { "1", "%*[0123456789]%c", EOF, "", "" },
+ { "1", "%*[0123456789]%c", 0, "", "" },
{ "1X2", "%*[0123456789]%[0123456789]", 0, "", "" },
{ "1,2", "%*[0123456789],%[0123456789]", 1, "2", "" },
/* Assign both */
{ "", "%[0123456789]%c", EOF, "", "" },
{ "X", "%[0123456789]%c", 0, "", "" },
- { "1", "%[0123456789]%c", EOF, "1", "" },
+ { "1", "%[0123456789]%c", 1, "1", "" },
{ "1X2", "%[0123456789]%[0123456789]", 1, "1", "" },
{ "1,2", "%[0123456789],%[0123456789]", 2, "1", "2" },
Right,
MartinS
- Raw text -