Commit f0888759 authored by ROOL's avatar ROOL 🤖
Browse files

This commit was manufactured by cvs2git to create tag 'RISC_OSLib-5_83-1'.

Sprout from master 2014-08-23 21:27:33 UTC Robert Sprowson <rsprowson@gitlab.riscosopen.org> 'Minor rlib cleanups'
Cherrypick from master 2011-10-28 14:23:50 UTC Ben Avison <bavison@gitlab.riscosopen.org> '  File handling improvements':
    c/scanf
parent dc7ea073
......@@ -635,22 +635,21 @@ static long int rd_string(FILE *p, va_list res, int flag, int field)
return charcount;
}
/* Can "%[blah]" match a zero-length string? No */
/* ISO9899 7.19.6.2 Matches a nonempty sequence of characters */
/* Ambiguity in Oct 86 ANSI draft: can "%[x]" match a zero-length string? */
/* p119 line 19 suggests no, p121 example suggests yes. Treat as yes here */
static long int rd_string_map(FILE *p, va_list res, int flag, int field,
unsigned int charmap[])
int charmap[])
{ long int charcount = -1; /* allow for always ungetc */
int ch; char *s = NULL;
if (!(flag & NOSTORE)) s = va_arg(res, char *);
ch = countgetc(p);
if (ch == EOF) return CVTEOF;
while (field > 0 && ch != EOF && (charmap[ch/32] & (1uL<<(ch%32))) != 0)
while (field > 0 && ch != EOF && (charmap[ch/32] & (1<<(ch%32))) != 0)
{ field--;
if (!(flag & NOSTORE)) *s++ = ch;
ch = countgetc(p);
}
__backspace(p); /* OK if ch == EOF */
if (charcount == 0) return CVTFAIL;
if (!(flag & NOSTORE)) *s = 0;
return charcount;
}
......@@ -784,13 +783,12 @@ case '%': { int field = 0, flag = 0;
case 'x':
case 'X': worked = rd_int(p, argv, flag | ALLOWSIGN, 16, field);
break;
case '[': { int negated = 0, i;
unsigned int charmap[8];
case '[': { int negated = 0, i, charmap[8];
if ((fch = *fmt++) == '^') negated = 1, fch = *fmt++;
for (i=0; i<8; i++) charmap[i] = 0;
/* the 'do' next allows special treatment of %[]})] */
do { if (fch==0) return cnt; /* %[... unterminated */
charmap[fch/32] |= 1u<<(fch%32);
charmap[fch/32] |= 1<<(fch%32);
} while ((fch = *fmt++) != ']');
if (negated) for (i=0; i<8; i++)
charmap[i] = ~charmap[i];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment