mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 21:12:59 +00:00
- Remove duplicated sscanf wrapper.
- Sync scanf.c / scanf.h with Wine. svn path=/trunk/; revision=33850
This commit is contained in:
parent
6857246d17
commit
683a6c4181
4 changed files with 297 additions and 373 deletions
|
@ -148,7 +148,6 @@
|
||||||
<file>itow.c</file>
|
<file>itow.c</file>
|
||||||
<file>mbstowcs_nt.c</file>
|
<file>mbstowcs_nt.c</file>
|
||||||
<file>splitp.c</file>
|
<file>splitp.c</file>
|
||||||
<file>sscanf.c</file>
|
|
||||||
<file>strtol.c</file>
|
<file>strtol.c</file>
|
||||||
<file>strtoul.c</file>
|
<file>strtoul.c</file>
|
||||||
<file>strtoull.c</file>
|
<file>strtoull.c</file>
|
||||||
|
@ -160,6 +159,10 @@
|
||||||
<file>wtol.c</file>
|
<file>wtol.c</file>
|
||||||
</directory>
|
</directory>
|
||||||
|
|
||||||
|
<directory name="wine">
|
||||||
|
<file>scanf.c</file>
|
||||||
|
</directory>
|
||||||
|
|
||||||
<directory name="wstring">
|
<directory name="wstring">
|
||||||
<file>wcsicmp.c</file>
|
<file>wcsicmp.c</file>
|
||||||
<file>wcslwr.c</file>
|
<file>wcslwr.c</file>
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
#include <precomp.h>
|
|
||||||
|
|
||||||
#include <wchar.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#define NDEBUG
|
|
||||||
#include <internal/debug.h>
|
|
||||||
|
|
||||||
#ifndef TRACE
|
|
||||||
#define TRACE DPRINT
|
|
||||||
#endif
|
|
||||||
#define WARN DPRINT1
|
|
||||||
|
|
||||||
|
|
||||||
#define EOF (-1)
|
|
||||||
|
|
||||||
/* helper function for *scanf. Returns the value of character c in the
|
|
||||||
* given base, or -1 if the given character is not a digit of the base.
|
|
||||||
*/
|
|
||||||
static int char2digit(char c, int base) {
|
|
||||||
if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
|
|
||||||
if (base<=10) return -1;
|
|
||||||
if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
|
|
||||||
if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* vsscanf */
|
|
||||||
#undef WIDE_SCANF
|
|
||||||
#undef CONSOLE
|
|
||||||
#define STRING 1
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define debugstr_a(x) x
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wine/scanf.h"
|
|
||||||
|
|
||||||
int sscanf(const char *str, const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list valist;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
va_start(valist, format);
|
|
||||||
res = vsscanf(str, format, valist);
|
|
||||||
va_end(valist);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*EOF */
|
|
|
@ -20,7 +20,7 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <precomp.h>
|
#include <precomp.h>
|
||||||
|
@ -149,7 +149,7 @@ int wscanf(const wchar_t *format, ...)
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* sscanf (MSVCRT.@)
|
* sscanf (MSVCRT.@)
|
||||||
*/
|
*/
|
||||||
int crt_sscanf(const char *str, const char *format, ...)
|
int sscanf(const char *str, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list valist;
|
va_list valist;
|
||||||
int res;
|
int res;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
* License along with this library; if not, write to the Free Software
|
* License along with this library; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef WIDE_SCANF
|
#ifdef WIDE_SCANF
|
||||||
|
@ -73,12 +73,6 @@
|
||||||
#endif /* STRING */
|
#endif /* STRING */
|
||||||
#endif /* CONSOLE */
|
#endif /* CONSOLE */
|
||||||
|
|
||||||
/*********************************************************************
|
|
||||||
* Implemented based on
|
|
||||||
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_format_specification_fields_.2d_.scanf_and_wscanf_functions.asp
|
|
||||||
* Extended by C. Scott Ananian <cananian@alumni.princeton.edu> to handle
|
|
||||||
* more types of format spec.
|
|
||||||
*/
|
|
||||||
_FUNCTION_ {
|
_FUNCTION_ {
|
||||||
int rd = 0, consumed = 0;
|
int rd = 0, consumed = 0;
|
||||||
int nch;
|
int nch;
|
||||||
|
@ -98,412 +92,389 @@ _FUNCTION_ {
|
||||||
if (nch == _EOF_) return _EOF_RET;
|
if (nch == _EOF_) return _EOF_RET;
|
||||||
|
|
||||||
while (*format) {
|
while (*format) {
|
||||||
/* a whitespace character in the format string causes scanf to read,
|
/* a whitespace character in the format string causes scanf to read,
|
||||||
* but not store, all consecutive white-space characters in the input
|
* but not store, all consecutive white-space characters in the input
|
||||||
* up to the next non-white-space character. One white space character
|
* up to the next non-white-space character. One white space character
|
||||||
* in the input matches any number (including zero) and combination of
|
* in the input matches any number (including zero) and combination of
|
||||||
* white-space characters in the input. */
|
* white-space characters in the input. */
|
||||||
if (_ISSPACE_(*format)) {
|
if (_ISSPACE_(*format)) {
|
||||||
/* skip whitespace */
|
/* skip whitespace */
|
||||||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
}
|
}
|
||||||
/* a format specification causes scanf to read and convert characters
|
/* a format specification causes scanf to read and convert characters
|
||||||
* in the input into values of a specified type. The value is assigned
|
* in the input into values of a specified type. The value is assigned
|
||||||
* to an argument in the argument list. Format specifications have
|
* to an argument in the argument list. Format specifications have
|
||||||
* the form %[*][width][{h | l | I64 | L}]type */
|
* the form %[*][width][{h | l | I64 | L}]type */
|
||||||
else if (*format == '%') {
|
else if (*format == '%') {
|
||||||
int st = 0; int suppress = 0; int width = 0;
|
int st = 0; int suppress = 0; int width = 0;
|
||||||
int base, number_signed;
|
int base;
|
||||||
int h_prefix = 0;
|
int h_prefix = 0;
|
||||||
int l_prefix = 0;
|
int l_prefix = 0;
|
||||||
int L_prefix = 0;
|
int L_prefix = 0;
|
||||||
int w_prefix = 0;
|
int w_prefix = 0;
|
||||||
int prefix_finished = 0;
|
int prefix_finished = 0;
|
||||||
int I64_prefix = 0;
|
int I64_prefix = 0;
|
||||||
format++;
|
format++;
|
||||||
/* look for leading asterisk, which means 'suppress assignment of
|
/* look for leading asterisk, which means 'suppress assignment of
|
||||||
* this field'. */
|
* this field'. */
|
||||||
if (*format=='*') {
|
if (*format=='*') {
|
||||||
format++;
|
format++;
|
||||||
suppress=1;
|
suppress=1;
|
||||||
}
|
}
|
||||||
/* look for width specification */
|
/* look for width specification */
|
||||||
while (_ISDIGIT_(*format)) {
|
while (_ISDIGIT_(*format)) {
|
||||||
width*=10;
|
width*=10;
|
||||||
width+=*format++ - '0';
|
width+=*format++ - '0';
|
||||||
}
|
}
|
||||||
if (width==0) width=-1; /* no width spec seen */
|
if (width==0) width=-1; /* no width spec seen */
|
||||||
/* read prefix (if any) */
|
/* read prefix (if any) */
|
||||||
while (!prefix_finished) {
|
while (!prefix_finished) {
|
||||||
switch(*format) {
|
switch(*format) {
|
||||||
case 'h': h_prefix = 1; break;
|
case 'h': h_prefix = 1; break;
|
||||||
case 'l': l_prefix = 1; break;
|
case 'l': l_prefix = 1; break;
|
||||||
case 'w': w_prefix = 1; break;
|
case 'w': w_prefix = 1; break;
|
||||||
case 'L': L_prefix = 1; break;
|
case 'L': L_prefix = 1; break;
|
||||||
case 'I':
|
case 'I':
|
||||||
if (*(format + 1) == '6' &&
|
if (*(format + 1) == '6' &&
|
||||||
*(format + 2) == '4') {
|
*(format + 2) == '4') {
|
||||||
I64_prefix = 1;
|
I64_prefix = 1;
|
||||||
format += 2;
|
format += 2;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
prefix_finished = 1;
|
prefix_finished = 1;
|
||||||
}
|
}
|
||||||
if (!prefix_finished) format++;
|
if (!prefix_finished) format++;
|
||||||
}
|
}
|
||||||
/* read type */
|
/* read type */
|
||||||
switch(*format) {
|
switch(*format) {
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'X': /* hexadecimal integer. */
|
case 'X': /* hexadecimal integer. */
|
||||||
base = 16; number_signed = 0;
|
base = 16;
|
||||||
goto number;
|
goto number;
|
||||||
case 'o': /* octal integer */
|
case 'o': /* octal integer */
|
||||||
base = 8; number_signed = 0;
|
base = 8;
|
||||||
goto number;
|
goto number;
|
||||||
case 'u': /* unsigned decimal integer */
|
case 'u': /* unsigned decimal integer */
|
||||||
base = 10; number_signed = 0;
|
base = 10;
|
||||||
goto number;
|
goto number;
|
||||||
case 'd': /* signed decimal integer */
|
case 'd': /* signed decimal integer */
|
||||||
base = 10; number_signed = 1;
|
base = 10;
|
||||||
goto number;
|
goto number;
|
||||||
case 'i': /* generic integer */
|
case 'i': /* generic integer */
|
||||||
base = 10; number_signed = 1;
|
base = 0;
|
||||||
number: {
|
number: {
|
||||||
/* read an integer */
|
/* read an integer */
|
||||||
ULONGLONG cur = 0;
|
ULONGLONG cur = 0;
|
||||||
int negative = 0;
|
int negative = 0;
|
||||||
int seendigit=0;
|
int seendigit=0;
|
||||||
/* skip initial whitespace */
|
/* skip initial whitespace */
|
||||||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
/* get sign */
|
/* get sign */
|
||||||
if (number_signed && (nch == '-' ||
|
if (nch == '-' || nch == '+') {
|
||||||
nch == '+')) {
|
negative = (nch=='-');
|
||||||
negative = (nch=='-');
|
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
}
|
}
|
||||||
/* look for leading indication of base */
|
/* look for leading indication of base */
|
||||||
if (width!=0 && nch == '0') {
|
if (width!=0 && nch == '0') {
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
seendigit=1;
|
seendigit=1;
|
||||||
if (width!=0 && (nch=='x' || nch=='X')) {
|
if (width!=0 && (nch=='x' || nch=='X')) {
|
||||||
if (base==0)
|
if (base==0)
|
||||||
base=16;
|
base=16;
|
||||||
if (base==16) {
|
if (base==16) {
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
seendigit=0;
|
seendigit=0;
|
||||||
}
|
}
|
||||||
} else if (base==0)
|
} else if (base==0)
|
||||||
base = 8;
|
base = 8;
|
||||||
}
|
}
|
||||||
/* throw away leading zeros */
|
/* format %i without indication of base */
|
||||||
while (width!=0 && nch=='0') {
|
if (base==0)
|
||||||
|
base = 10;
|
||||||
|
/* throw away leading zeros */
|
||||||
|
while (width!=0 && nch=='0') {
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
seendigit=1;
|
seendigit=1;
|
||||||
}
|
}
|
||||||
if (width!=0 && _CHAR2DIGIT_(nch, base)!=-1) {
|
if (width!=0 && _CHAR2DIGIT_(nch, base)!=-1) {
|
||||||
cur = _CHAR2DIGIT_(nch, base);
|
cur = _CHAR2DIGIT_(nch, base);
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
seendigit=1;
|
seendigit=1;
|
||||||
}
|
}
|
||||||
/* read until no more digits */
|
/* read until no more digits */
|
||||||
while (width!=0 && (nch!=_EOF_) && _CHAR2DIGIT_(nch, base)!=-1) {
|
while (width!=0 && (nch!=_EOF_) && _CHAR2DIGIT_(nch, base)!=-1) {
|
||||||
cur = cur*base + _CHAR2DIGIT_(nch, base);
|
cur = cur*base + _CHAR2DIGIT_(nch, base);
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
seendigit=1;
|
seendigit=1;
|
||||||
}
|
}
|
||||||
/* okay, done! */
|
/* okay, done! */
|
||||||
if (!seendigit) break; /* not a valid number */
|
if (!seendigit) break; /* not a valid number */
|
||||||
st = 1;
|
st = 1;
|
||||||
if (!suppress) {
|
if (!suppress) {
|
||||||
#define _SET_NUMBER_(type) *va_arg(ap, type*) = negative ? -cur : cur
|
#define _SET_NUMBER_(type) *va_arg(ap, type*) = negative ? -cur : cur
|
||||||
if (number_signed) {
|
if (I64_prefix) _SET_NUMBER_(LONGLONG);
|
||||||
if (I64_prefix) _SET_NUMBER_(LONGLONG);
|
else if (l_prefix) _SET_NUMBER_(long int);
|
||||||
else if (l_prefix) _SET_NUMBER_(long int);
|
else if (h_prefix) _SET_NUMBER_(short int);
|
||||||
else if (h_prefix) _SET_NUMBER_(short int);
|
else _SET_NUMBER_(int);
|
||||||
else _SET_NUMBER_(int);
|
}
|
||||||
} else {
|
|
||||||
if (negative) {
|
|
||||||
WARN("Dropping sign in reading a negative number into an unsigned value");
|
|
||||||
negative = 0;
|
|
||||||
}
|
|
||||||
if (I64_prefix) _SET_NUMBER_(ULONGLONG);
|
|
||||||
else if (l_prefix) _SET_NUMBER_(unsigned long int);
|
|
||||||
else if (h_prefix)
|
|
||||||
_SET_NUMBER_(unsigned short int);
|
|
||||||
else _SET_NUMBER_(unsigned int);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'f':
|
case 'f':
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G': { /* read a float */
|
case 'G': { /* read a float */
|
||||||
long double cur = 0;
|
long double cur = 0;
|
||||||
int negative = 0;
|
int negative = 0;
|
||||||
/* skip initial whitespace */
|
/* skip initial whitespace */
|
||||||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
/* get sign. */
|
/* get sign. */
|
||||||
if (nch == '-' || nch == '+') {
|
if (nch == '-' || nch == '+') {
|
||||||
negative = (nch=='-');
|
negative = (nch=='-');
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
if (width==0) break;
|
if (width==0) break;
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
}
|
}
|
||||||
/* get first digit. */
|
/* get first digit. */
|
||||||
if ('.' != nch) {
|
if ('.' != nch) {
|
||||||
if (!_ISDIGIT_(nch)) break;
|
if (!_ISDIGIT_(nch)) break;
|
||||||
cur = (nch - '0');
|
cur = (nch - '0');
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
/* read until no more digits */
|
/* read until no more digits */
|
||||||
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
|
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
|
||||||
cur = cur*10 + (nch - '0');
|
cur = cur*10 + (nch - '0');
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cur = 0; /* MaxPayneDemo Fix: .8 -> 0.8 */
|
cur = 0; /* MaxPayneDemo Fix: .8 -> 0.8 */
|
||||||
}
|
}
|
||||||
/* handle decimals */
|
/* handle decimals */
|
||||||
if (width!=0 && nch == '.') {
|
if (width!=0 && nch == '.') {
|
||||||
float dec = 1;
|
float dec = 1;
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
|
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
|
||||||
dec /= 10;
|
dec /= 10;
|
||||||
cur += dec * (nch - '0');
|
cur += dec * (nch - '0');
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* handle exponent */
|
/* handle exponent */
|
||||||
if (width!=0 && (nch == 'e' || nch == 'E')) {
|
if (width!=0 && (nch == 'e' || nch == 'E')) {
|
||||||
int exponent = 0, negexp = 0;
|
int exponent = 0, negexp = 0;
|
||||||
float expcnt;
|
float expcnt;
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
/* possible sign on the exponent */
|
/* possible sign on the exponent */
|
||||||
if (width!=0 && (nch=='+' || nch=='-')) {
|
if (width!=0 && (nch=='+' || nch=='-')) {
|
||||||
negexp = (nch=='-');
|
negexp = (nch=='-');
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
}
|
}
|
||||||
/* exponent digits */
|
/* exponent digits */
|
||||||
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
|
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
|
||||||
exponent *= 10;
|
exponent *= 10;
|
||||||
exponent += (nch - '0');
|
exponent += (nch - '0');
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
}
|
}
|
||||||
/* update 'cur' with this exponent. */
|
/* update 'cur' with this exponent. */
|
||||||
expcnt = negexp ? .1 : 10;
|
expcnt = negexp ? .1 : 10;
|
||||||
while (exponent!=0) {
|
while (exponent!=0) {
|
||||||
if (exponent&1)
|
if (exponent&1)
|
||||||
cur*=expcnt;
|
cur*=expcnt;
|
||||||
exponent/=2;
|
exponent/=2;
|
||||||
expcnt=expcnt*expcnt;
|
expcnt=expcnt*expcnt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
st = 1;
|
st = 1;
|
||||||
if (!suppress) {
|
if (!suppress) {
|
||||||
if (L_prefix) _SET_NUMBER_(long double);
|
if (L_prefix) _SET_NUMBER_(long double);
|
||||||
else if (l_prefix) _SET_NUMBER_(double);
|
else if (l_prefix) _SET_NUMBER_(double);
|
||||||
else _SET_NUMBER_(float);
|
else _SET_NUMBER_(float);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/* According to
|
/* According to msdn,
|
||||||
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_scanf_type_field_characters.asp
|
* 's' reads a character string in a call to fscanf
|
||||||
* 's' reads a character string in a call to fscanf
|
* and 'S' a wide character string and vice versa in a
|
||||||
* and 'S' a wide character string and vice versa in a
|
* call to fwscanf. The 'h', 'w' and 'l' prefixes override
|
||||||
* call to fwscanf. The 'h', 'w' and 'l' prefixes override
|
* this behaviour. 'h' forces reading char * but 'l' and 'w'
|
||||||
* this behaviour. 'h' forces reading char * but 'l' and 'w'
|
* force reading WCHAR. */
|
||||||
* force reading WCHAR. */
|
case 's':
|
||||||
case 's':
|
if (w_prefix || l_prefix) goto widecharstring;
|
||||||
if (w_prefix || l_prefix) goto widecharstring;
|
else if (h_prefix) goto charstring;
|
||||||
else if (h_prefix) goto charstring;
|
|
||||||
#ifdef WIDE_SCANF
|
#ifdef WIDE_SCANF
|
||||||
else goto widecharstring;
|
else goto widecharstring;
|
||||||
#else /* WIDE_SCANF */
|
#else /* WIDE_SCANF */
|
||||||
else goto charstring;
|
else goto charstring;
|
||||||
#endif /* WIDE_SCANF */
|
#endif /* WIDE_SCANF */
|
||||||
case 'S':
|
case 'S':
|
||||||
if (w_prefix || l_prefix) goto widecharstring;
|
if (w_prefix || l_prefix) goto widecharstring;
|
||||||
else if (h_prefix) goto charstring;
|
else if (h_prefix) goto charstring;
|
||||||
#ifdef WIDE_SCANF
|
#ifdef WIDE_SCANF
|
||||||
else goto charstring;
|
else goto charstring;
|
||||||
#else /* WIDE_SCANF */
|
#else /* WIDE_SCANF */
|
||||||
else goto widecharstring;
|
else goto widecharstring;
|
||||||
#endif /* WIDE_SCANF */
|
#endif /* WIDE_SCANF */
|
||||||
charstring: { /* read a word into a char */
|
charstring: { /* read a word into a char */
|
||||||
char*str = suppress ? NULL : va_arg(ap, char*);
|
char *sptr = suppress ? NULL : va_arg(ap, char*);
|
||||||
char*sptr = str;
|
|
||||||
/* skip initial whitespace */
|
/* skip initial whitespace */
|
||||||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
/* read until whitespace */
|
/* read until whitespace */
|
||||||
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
|
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
|
||||||
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
|
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
|
||||||
st++;
|
st++;
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
}
|
}
|
||||||
/* terminate */
|
/* terminate */
|
||||||
if (!suppress) *sptr = 0;
|
if (!suppress) *sptr = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
widecharstring: { /* read a word into a wchar_t* */
|
widecharstring: { /* read a word into a wchar_t* */
|
||||||
wchar_t*str =
|
wchar_t *sptr = suppress ? NULL : va_arg(ap, wchar_t*);
|
||||||
suppress ? NULL : va_arg(ap, wchar_t*);
|
|
||||||
wchar_t*sptr = str;
|
|
||||||
/* skip initial whitespace */
|
/* skip initial whitespace */
|
||||||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
/* read until whitespace */
|
/* read until whitespace */
|
||||||
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
|
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
|
||||||
if (!suppress) *sptr++ = _WIDE2SUPPORTED_(nch);
|
if (!suppress) *sptr++ = _WIDE2SUPPORTED_(nch);
|
||||||
st++;
|
st++;
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
}
|
}
|
||||||
/* terminate */
|
/* terminate */
|
||||||
if (!suppress) *sptr = 0;
|
if (!suppress) *sptr = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/* 'c' and 'C work analogously to 's' and 'S' as described
|
/* 'c' and 'C work analogously to 's' and 'S' as described
|
||||||
* above */
|
* above */
|
||||||
case 'c':
|
case 'c':
|
||||||
if (w_prefix || l_prefix) goto widecharacter;
|
if (w_prefix || l_prefix) goto widecharacter;
|
||||||
else if (h_prefix) goto character;
|
else if (h_prefix) goto character;
|
||||||
#ifdef WIDE_SCANF
|
#ifdef WIDE_SCANF
|
||||||
else goto widecharacter;
|
else goto widecharacter;
|
||||||
#else /* WIDE_SCANF */
|
#else /* WIDE_SCANF */
|
||||||
else goto character;
|
else goto character;
|
||||||
#endif /* WIDE_SCANF */
|
#endif /* WIDE_SCANF */
|
||||||
case 'C':
|
case 'C':
|
||||||
if (w_prefix || l_prefix) goto widecharacter;
|
if (w_prefix || l_prefix) goto widecharacter;
|
||||||
else if (h_prefix) goto character;
|
else if (h_prefix) goto character;
|
||||||
#ifdef WIDE_SCANF
|
#ifdef WIDE_SCANF
|
||||||
else goto character;
|
else goto character;
|
||||||
#else /* WIDE_SCANF */
|
#else /* WIDE_SCANF */
|
||||||
else goto widecharacter;
|
else goto widecharacter;
|
||||||
#endif /* WIDE_SCANF */
|
#endif /* WIDE_SCANF */
|
||||||
character: { /* read single character into char */
|
character: { /* read single character into char */
|
||||||
if (nch!=_EOF_) {
|
char *str = suppress ? NULL : va_arg(ap, char*);
|
||||||
if (!suppress) {
|
if (width == -1) width = 1;
|
||||||
char*c = va_arg(ap, char*);
|
while ((width != 0) && (nch != _EOF_))
|
||||||
*c = _CHAR2SUPPORTED_(nch);
|
{
|
||||||
}
|
if (!suppress) *str++ = _CHAR2SUPPORTED_(nch);
|
||||||
st = 1;
|
st++;
|
||||||
|
width--;
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
widecharacter: { /* read single character into a wchar_t */
|
widecharacter: { /* read single character into a wchar_t */
|
||||||
if (nch!=_EOF_) {
|
wchar_t *str = suppress ? NULL : va_arg(ap, wchar_t*);
|
||||||
if (!suppress) {
|
if (width == -1) width = 1;
|
||||||
wchar_t*c = va_arg(ap, wchar_t*);
|
while ((width != 0) && (nch != _EOF_))
|
||||||
*c = _WIDE2SUPPORTED_(nch);
|
{
|
||||||
}
|
if (!suppress) *str++ = _WIDE2SUPPORTED_(nch);
|
||||||
|
st++;
|
||||||
|
width--;
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
st = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'n': {
|
case 'n': {
|
||||||
if (!suppress) {
|
if (!suppress) {
|
||||||
int*n = va_arg(ap, int*);
|
int*n = va_arg(ap, int*);
|
||||||
|
*n = consumed - 1;
|
||||||
/*
|
}
|
||||||
*n = consumed - (nch!=_EOF_);
|
/* This is an odd one: according to the standard,
|
||||||
|
* "Execution of a %n directive does not increment the
|
||||||
FIXME: The above is the Wine version and it doesnt work in ros
|
* assignment count returned at the completion of
|
||||||
when %n is at end of input string (return one too many).
|
* execution" even if it wasn't suppressed with the
|
||||||
But does it fail in Wine too?? If so wine also needs fixin.
|
* '*' flag. The Corrigendum to the standard seems
|
||||||
-Gunnar
|
* to contradict this (comment out the assignment to
|
||||||
*/
|
* suppress below if you want to implement these
|
||||||
|
* alternate semantics) but the windows program I'm
|
||||||
*n = consumed - 1;
|
* looking at expects the behavior I've coded here
|
||||||
}
|
* (which happens to be what glibc does as well).
|
||||||
/* This is an odd one: according to the standard,
|
*/
|
||||||
* "Execution of a %n directive does not increment the
|
suppress = 1;
|
||||||
* assignment count returned at the completion of
|
st = 1;
|
||||||
* execution" even if it wasn't suppressed with the
|
}
|
||||||
* '*' flag. The Corrigendum to the standard seems
|
break;
|
||||||
* to contradict this (comment out the assignment to
|
case '[': {
|
||||||
* suppress below if you want to implement these
|
|
||||||
* alternate semantics) but the windows program I'm
|
|
||||||
* looking at expects the behavior I've coded here
|
|
||||||
* (which happens to be what glibc does as well).
|
|
||||||
*/
|
|
||||||
suppress = 1;
|
|
||||||
st = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case '[': {
|
|
||||||
_CHAR_ *str = suppress ? NULL : va_arg(ap, _CHAR_*);
|
_CHAR_ *str = suppress ? NULL : va_arg(ap, _CHAR_*);
|
||||||
_CHAR_ *sptr = str;
|
_CHAR_ *sptr = str;
|
||||||
RTL_BITMAP bitMask;
|
RTL_BITMAP bitMask;
|
||||||
ULONG *Mask;
|
ULONG *Mask;
|
||||||
int invert = 0; /* Set if we are NOT to find the chars */
|
int invert = 0; /* Set if we are NOT to find the chars */
|
||||||
|
|
||||||
/* Init our bitmap */
|
/* Init our bitmap */
|
||||||
#ifdef _LIBCNT_
|
#ifdef _LIBCNT_
|
||||||
Mask = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8);
|
Mask = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8);
|
||||||
#else
|
#else
|
||||||
Mask = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8);
|
Mask = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8);
|
||||||
#endif
|
#endif
|
||||||
RtlInitializeBitMap(&bitMask, Mask, _BITMAPSIZE_);
|
RtlInitializeBitMap(&bitMask, Mask, _BITMAPSIZE_);
|
||||||
|
|
||||||
/* Read the format */
|
/* Read the format */
|
||||||
format++;
|
format++;
|
||||||
if(*format == '^') {
|
if(*format == '^') {
|
||||||
invert = 1;
|
invert = 1;
|
||||||
format++;
|
format++;
|
||||||
}
|
}
|
||||||
if(*format == ']') {
|
if(*format == ']') {
|
||||||
RtlSetBits(&bitMask, ']', 1);
|
RtlSetBits(&bitMask, ']', 1);
|
||||||
format++;
|
format++;
|
||||||
}
|
}
|
||||||
while(*format && (*format != ']')) {
|
while(*format && (*format != ']')) {
|
||||||
/* According to:
|
/* According to msdn:
|
||||||
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_scanf_width_specification.asp
|
* "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */
|
||||||
* "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */
|
if((*format == '-') && (*(format + 1) != ']')) {
|
||||||
if((*format == '-') && (*(format + 1) != ']')) {
|
if ((*(format - 1)) < *(format + 1))
|
||||||
if ((*(format - 1)) < *(format + 1))
|
RtlSetBits(&bitMask, *(format - 1) +1 , *(format + 1) - *(format - 1));
|
||||||
RtlSetBits(&bitMask, *(format - 1) +1 , *(format + 1) - *(format - 1));
|
else
|
||||||
else
|
RtlSetBits(&bitMask, *(format + 1) , *(format - 1) - *(format + 1));
|
||||||
RtlSetBits(&bitMask, *(format + 1) , *(format - 1) - *(format + 1));
|
format++;
|
||||||
format++;
|
} else
|
||||||
} else
|
RtlSetBits(&bitMask, *format, 1);
|
||||||
RtlSetBits(&bitMask, *format, 1);
|
format++;
|
||||||
format++;
|
}
|
||||||
}
|
|
||||||
/* read until char is not suitable */
|
/* read until char is not suitable */
|
||||||
while ((width != 0) && (nch != _EOF_)) {
|
while ((width != 0) && (nch != _EOF_)) {
|
||||||
if(!invert) {
|
if(!invert) {
|
||||||
if(RtlAreBitsSet(&bitMask, nch, 1)) {
|
if(RtlAreBitsSet(&bitMask, nch, 1)) {
|
||||||
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
|
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
if(RtlAreBitsClear(&bitMask, nch, 1)) {
|
if(RtlAreBitsClear(&bitMask, nch, 1)) {
|
||||||
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
|
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
st++;
|
st++;
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (width>0) width--;
|
if (width>0) width--;
|
||||||
|
@ -511,20 +482,20 @@ _FUNCTION_ {
|
||||||
/* terminate */
|
/* terminate */
|
||||||
if (!suppress) *sptr = 0;
|
if (!suppress) *sptr = 0;
|
||||||
#ifdef _LIBCNT_
|
#ifdef _LIBCNT_
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, Mask);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, Mask);
|
||||||
#else
|
#else
|
||||||
HeapFree(GetProcessHeap(), 0, Mask);
|
HeapFree(GetProcessHeap(), 0, Mask);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* From spec: "if a percent sign is followed by a character
|
/* From spec: "if a percent sign is followed by a character
|
||||||
* that has no meaning as a format-control character, that
|
* that has no meaning as a format-control character, that
|
||||||
* character and the following characters are treated as
|
* character and the following characters are treated as
|
||||||
* an ordinary sequence of characters, that is, a sequence
|
* an ordinary sequence of characters, that is, a sequence
|
||||||
* of characters that must match the input. For example,
|
* of characters that must match the input. For example,
|
||||||
* to specify that a percent-sign character is to be input,
|
* to specify that a percent-sign character is to be input,
|
||||||
* use %%." */
|
* use %%." */
|
||||||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
if (nch==*format) {
|
if (nch==*format) {
|
||||||
|
@ -537,18 +508,18 @@ _FUNCTION_ {
|
||||||
if (st && !suppress) rd++;
|
if (st && !suppress) rd++;
|
||||||
else if (!st) break;
|
else if (!st) break;
|
||||||
}
|
}
|
||||||
/* a non-white-space character causes scanf to read, but not store,
|
/* a non-white-space character causes scanf to read, but not store,
|
||||||
* a matching non-white-space character. */
|
* a matching non-white-space character. */
|
||||||
else {
|
else {
|
||||||
/* check for character match */
|
/* check for character match */
|
||||||
if (nch == *format) {
|
if (nch == *format) {
|
||||||
nch = _GETC_(file);
|
nch = _GETC_(file);
|
||||||
} else break;
|
} else break;
|
||||||
}
|
}
|
||||||
format++;
|
format++;
|
||||||
}
|
}
|
||||||
if (nch!=_EOF_) {
|
if (nch!=_EOF_) {
|
||||||
_UNGETC_(nch, file);
|
_UNGETC_(nch, file);
|
||||||
}
|
}
|
||||||
TRACE("returning %d\n", rd);
|
TRACE("returning %d\n", rd);
|
||||||
return rd;
|
return rd;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue