mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 19:12:57 +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>mbstowcs_nt.c</file>
|
||||
<file>splitp.c</file>
|
||||
<file>sscanf.c</file>
|
||||
<file>strtol.c</file>
|
||||
<file>strtoul.c</file>
|
||||
<file>strtoull.c</file>
|
||||
|
@ -160,6 +159,10 @@
|
|||
<file>wtol.c</file>
|
||||
</directory>
|
||||
|
||||
<directory name="wine">
|
||||
<file>scanf.c</file>
|
||||
</directory>
|
||||
|
||||
<directory name="wstring">
|
||||
<file>wcsicmp.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
|
||||
* 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>
|
||||
|
@ -149,7 +149,7 @@ int wscanf(const wchar_t *format, ...)
|
|||
/*********************************************************************
|
||||
* sscanf (MSVCRT.@)
|
||||
*/
|
||||
int crt_sscanf(const char *str, const char *format, ...)
|
||||
int sscanf(const char *str, const char *format, ...)
|
||||
{
|
||||
va_list valist;
|
||||
int res;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* 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
|
||||
|
@ -73,12 +73,6 @@
|
|||
#endif /* STRING */
|
||||
#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_ {
|
||||
int rd = 0, consumed = 0;
|
||||
int nch;
|
||||
|
@ -114,7 +108,7 @@ _FUNCTION_ {
|
|||
* the form %[*][width][{h | l | I64 | L}]type */
|
||||
else if (*format == '%') {
|
||||
int st = 0; int suppress = 0; int width = 0;
|
||||
int base, number_signed;
|
||||
int base;
|
||||
int h_prefix = 0;
|
||||
int l_prefix = 0;
|
||||
int L_prefix = 0;
|
||||
|
@ -157,19 +151,19 @@ _FUNCTION_ {
|
|||
switch(*format) {
|
||||
case 'x':
|
||||
case 'X': /* hexadecimal integer. */
|
||||
base = 16; number_signed = 0;
|
||||
base = 16;
|
||||
goto number;
|
||||
case 'o': /* octal integer */
|
||||
base = 8; number_signed = 0;
|
||||
base = 8;
|
||||
goto number;
|
||||
case 'u': /* unsigned decimal integer */
|
||||
base = 10; number_signed = 0;
|
||||
base = 10;
|
||||
goto number;
|
||||
case 'd': /* signed decimal integer */
|
||||
base = 10; number_signed = 1;
|
||||
base = 10;
|
||||
goto number;
|
||||
case 'i': /* generic integer */
|
||||
base = 10; number_signed = 1;
|
||||
base = 0;
|
||||
number: {
|
||||
/* read an integer */
|
||||
ULONGLONG cur = 0;
|
||||
|
@ -179,8 +173,7 @@ _FUNCTION_ {
|
|||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||
nch = _GETC_(file);
|
||||
/* get sign */
|
||||
if (number_signed && (nch == '-' ||
|
||||
nch == '+')) {
|
||||
if (nch == '-' || nch == '+') {
|
||||
negative = (nch=='-');
|
||||
nch = _GETC_(file);
|
||||
if (width>0) width--;
|
||||
|
@ -201,6 +194,9 @@ _FUNCTION_ {
|
|||
} else if (base==0)
|
||||
base = 8;
|
||||
}
|
||||
/* format %i without indication of base */
|
||||
if (base==0)
|
||||
base = 10;
|
||||
/* throw away leading zeros */
|
||||
while (width!=0 && nch=='0') {
|
||||
nch = _GETC_(file);
|
||||
|
@ -225,22 +221,10 @@ _FUNCTION_ {
|
|||
st = 1;
|
||||
if (!suppress) {
|
||||
#define _SET_NUMBER_(type) *va_arg(ap, type*) = negative ? -cur : cur
|
||||
if (number_signed) {
|
||||
if (I64_prefix) _SET_NUMBER_(LONGLONG);
|
||||
else if (l_prefix) _SET_NUMBER_(long int);
|
||||
else if (h_prefix) _SET_NUMBER_(short 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;
|
||||
|
@ -324,8 +308,7 @@ _FUNCTION_ {
|
|||
}
|
||||
}
|
||||
break;
|
||||
/* According to
|
||||
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_scanf_type_field_characters.asp
|
||||
/* According to msdn,
|
||||
* 's' reads a character string in a call to fscanf
|
||||
* and 'S' a wide character string and vice versa in a
|
||||
* call to fwscanf. The 'h', 'w' and 'l' prefixes override
|
||||
|
@ -348,8 +331,7 @@ _FUNCTION_ {
|
|||
else goto widecharstring;
|
||||
#endif /* WIDE_SCANF */
|
||||
charstring: { /* read a word into a char */
|
||||
char*str = suppress ? NULL : va_arg(ap, char*);
|
||||
char*sptr = str;
|
||||
char *sptr = suppress ? NULL : va_arg(ap, char*);
|
||||
/* skip initial whitespace */
|
||||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||
nch = _GETC_(file);
|
||||
|
@ -365,9 +347,7 @@ _FUNCTION_ {
|
|||
}
|
||||
break;
|
||||
widecharstring: { /* read a word into a wchar_t* */
|
||||
wchar_t*str =
|
||||
suppress ? NULL : va_arg(ap, wchar_t*);
|
||||
wchar_t*sptr = str;
|
||||
wchar_t *sptr = suppress ? NULL : va_arg(ap, wchar_t*);
|
||||
/* skip initial whitespace */
|
||||
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
||||
nch = _GETC_(file);
|
||||
|
@ -401,40 +381,32 @@ _FUNCTION_ {
|
|||
else goto widecharacter;
|
||||
#endif /* WIDE_SCANF */
|
||||
character: { /* read single character into char */
|
||||
if (nch!=_EOF_) {
|
||||
if (!suppress) {
|
||||
char*c = va_arg(ap, char*);
|
||||
*c = _CHAR2SUPPORTED_(nch);
|
||||
}
|
||||
st = 1;
|
||||
char *str = suppress ? NULL : va_arg(ap, char*);
|
||||
if (width == -1) width = 1;
|
||||
while ((width != 0) && (nch != _EOF_))
|
||||
{
|
||||
if (!suppress) *str++ = _CHAR2SUPPORTED_(nch);
|
||||
st++;
|
||||
width--;
|
||||
nch = _GETC_(file);
|
||||
}
|
||||
}
|
||||
break;
|
||||
widecharacter: { /* read single character into a wchar_t */
|
||||
if (nch!=_EOF_) {
|
||||
if (!suppress) {
|
||||
wchar_t*c = va_arg(ap, wchar_t*);
|
||||
*c = _WIDE2SUPPORTED_(nch);
|
||||
}
|
||||
wchar_t *str = suppress ? NULL : va_arg(ap, wchar_t*);
|
||||
if (width == -1) width = 1;
|
||||
while ((width != 0) && (nch != _EOF_))
|
||||
{
|
||||
if (!suppress) *str++ = _WIDE2SUPPORTED_(nch);
|
||||
st++;
|
||||
width--;
|
||||
nch = _GETC_(file);
|
||||
st = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'n': {
|
||||
if (!suppress) {
|
||||
int*n = va_arg(ap, int*);
|
||||
|
||||
/*
|
||||
*n = consumed - (nch!=_EOF_);
|
||||
|
||||
FIXME: The above is the Wine version and it doesnt work in ros
|
||||
when %n is at end of input string (return one too many).
|
||||
But does it fail in Wine too?? If so wine also needs fixin.
|
||||
-Gunnar
|
||||
*/
|
||||
|
||||
*n = consumed - 1;
|
||||
}
|
||||
/* This is an odd one: according to the standard,
|
||||
|
@ -478,8 +450,7 @@ _FUNCTION_ {
|
|||
format++;
|
||||
}
|
||||
while(*format && (*format != ']')) {
|
||||
/* According to:
|
||||
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_scanf_width_specification.asp
|
||||
/* According to msdn:
|
||||
* "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */
|
||||
if((*format == '-') && (*(format + 1) != ']')) {
|
||||
if ((*(format - 1)) < *(format + 1))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue