1 |
/* Copyright (c) 2002,2004 Joerg Wunsch |
/* Copyright (c) 2002,2004,2005 Joerg Wunsch |
2 |
All rights reserved. |
All rights reserved. |
3 |
|
|
4 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
104 |
} a; |
} a; |
105 |
char c; /* holds a char from the format string */ |
char c; /* holds a char from the format string */ |
106 |
uint8_t base; |
uint8_t base; |
107 |
int nconvs, i, j, olen; |
int nconvs, rv, i, j, olen; |
108 |
#if SCANF_LEVEL > SCANF_MIN |
#if SCANF_LEVEL > SCANF_MIN |
109 |
int8_t width; |
int8_t width; |
110 |
#endif |
#endif |
117 |
flags = 0; |
flags = 0; |
118 |
nconvs = 0; |
nconvs = 0; |
119 |
i = 0; |
i = 0; |
120 |
|
rv = EOF; |
121 |
olen = stream->len = 0; |
olen = stream->len = 0; |
122 |
#if SCANF_LEVEL >= SCANF_FLT |
#if SCANF_LEVEL >= SCANF_FLT |
123 |
buf = 0; |
buf = 0; |
546 |
#if SCANF_LEVEL >= SCANF_FLT |
#if SCANF_LEVEL >= SCANF_FLT |
547 |
nextconv: |
nextconv: |
548 |
#endif |
#endif |
549 |
flags = 0; |
if (stream->len > olen) { |
550 |
if (stream->len > olen) |
#if SCANF_LEVEL >= SCANF_STD |
551 |
nconvs++; |
if (!(flags & FLSTAR)) |
552 |
else if (c != 'n' || i == EOF) |
#endif |
553 |
|
nconvs++; |
554 |
|
rv = 0; |
555 |
|
} else if (c != 'n' || i == EOF) |
556 |
/* |
/* |
557 |
* If one conversion failed completely, |
* If one conversion failed completely, |
558 |
* punt. |
* punt. |
559 |
*/ |
*/ |
560 |
goto leave; |
goto leave; |
561 |
|
flags = 0; |
562 |
} else if (c == '%') { |
} else if (c == '%') { |
563 |
flags = FLHASPERCENT; |
flags = FLHASPERCENT; |
564 |
base = 10; |
base = 10; |
589 |
* or end-of-file), adjust the total number of conversions |
* or end-of-file), adjust the total number of conversions |
590 |
* done if at least one char could be read from the stream. |
* done if at least one char could be read from the stream. |
591 |
*/ |
*/ |
592 |
if ((flags & FLHASPERCENT) && stream->len > olen) |
if ((flags & FLHASPERCENT) && stream->len > olen) { |
593 |
nconvs++; |
#if SCANF_LEVEL >= SCANF_STD |
594 |
|
if (!(flags & FLSTAR)) |
595 |
|
#endif |
596 |
|
nconvs++; |
597 |
|
rv = 0; |
598 |
|
} |
599 |
|
|
600 |
|
#if SCANF_LEVEL >= SCANF_FLT |
601 |
|
free(buf); |
602 |
|
#endif |
603 |
/* |
/* |
604 |
* If an error occurs before the first successful conversion, |
* If an error occurs before the first successful conversion, |
605 |
* we ought to return EOF. Before getting here, all |
* we ought to return EOF. Before getting here, all |
606 |
* conversions maintain the last character read from the |
* conversions maintain the last character read from the |
607 |
* stream (or EOF) within variable `i'. |
* stream (or EOF) within variable `i'. |
608 |
*/ |
*/ |
609 |
if (nconvs == 0 && i == EOF) |
if (i == EOF && nconvs == 0) |
610 |
nconvs = EOF; |
return rv; |
611 |
|
|
|
#if SCANF_LEVEL >= SCANF_FLT |
|
|
free(buf); |
|
|
#endif |
|
612 |
return nconvs; |
return nconvs; |
613 |
} |
} |