2002-08-17 03:22:00 +02:00
|
|
|
/*
|
|
|
|
* general implementation of scanf used by scanf, sscanf, fscanf,
|
|
|
|
* _cscanf, wscanf, swscanf and fwscanf
|
|
|
|
*
|
|
|
|
* Copyright 1996,1998 Marcus Meissner
|
|
|
|
* Copyright 1996 Jukka Iivonen
|
2003-05-14 01:38:46 +02:00
|
|
|
* Copyright 1997,2000, 2003 Uwe Bonnes
|
2002-08-17 03:22:00 +02:00
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
* Copyright 2002 Daniel Gudbjartsson
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-08-17 03:22:00 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WIDE_SCANF
|
2020-11-27 14:16:49 +01:00
|
|
|
#define _CHAR_ wchar_t
|
2020-11-30 14:37:05 +01:00
|
|
|
#define _EOF_ WEOF
|
|
|
|
#define _EOF_RET (short)WEOF
|
2020-12-03 19:10:54 +01:00
|
|
|
#define _ISSPACE_(c) iswspace(c)
|
2004-01-06 21:38:37 +01:00
|
|
|
#define _WIDE2SUPPORTED_(c) c /* No conversion needed (wide to wide) */
|
|
|
|
#define _CHAR2SUPPORTED_(c) c /* FIXME: convert char to wide char */
|
2002-08-17 03:22:00 +02:00
|
|
|
#define _CHAR2DIGIT_(c, base) wchar2digit((c), (base))
|
2004-01-06 21:38:37 +01:00
|
|
|
#define _BITMAPSIZE_ 256*256
|
2002-08-17 03:22:00 +02:00
|
|
|
#else /* WIDE_SCANF */
|
|
|
|
#define _CHAR_ char
|
2020-11-30 14:37:09 +01:00
|
|
|
#define _EOF_ EOF
|
|
|
|
#define _EOF_RET EOF
|
2020-12-01 13:52:34 +01:00
|
|
|
#define _ISSPACE_(c) isspace(c)
|
2004-01-06 21:38:37 +01:00
|
|
|
#define _WIDE2SUPPORTED_(c) c /* FIXME: convert wide char to char */
|
|
|
|
#define _CHAR2SUPPORTED_(c) c /* No conversion needed (char to char) */
|
2002-08-17 03:22:00 +02:00
|
|
|
#define _CHAR2DIGIT_(c, base) char2digit((c), (base))
|
2004-01-06 21:38:37 +01:00
|
|
|
#define _BITMAPSIZE_ 256
|
2002-08-17 03:22:00 +02:00
|
|
|
#endif /* WIDE_SCANF */
|
|
|
|
|
|
|
|
#ifdef CONSOLE
|
2020-01-02 19:01:56 +01:00
|
|
|
#define _GETC_FUNC_(file) _getch()
|
|
|
|
#define _STRTOD_NAME_(func) console_ ## func
|
2003-10-10 02:00:19 +02:00
|
|
|
#define _GETC_(file) (consumed++, _getch())
|
|
|
|
#define _UNGETC_(nch, file) do { _ungetch(nch); consumed--; } while(0)
|
2020-12-03 19:11:20 +01:00
|
|
|
#define _LOCK_FILE_(file) _lock_file(MSVCRT_stdin)
|
|
|
|
#define _UNLOCK_FILE_(file) _unlock_file(MSVCRT_stdin)
|
2010-04-22 13:54:03 +02:00
|
|
|
#ifdef WIDE_SCANF
|
|
|
|
#ifdef SECURE
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vcwscanf_s_l(const wchar_t *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 13:54:03 +02:00
|
|
|
#else /* SECURE */
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vcwscanf_l(const wchar_t *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 13:54:03 +02:00
|
|
|
#endif /* SECURE */
|
|
|
|
#else /* WIDE_SCANF */
|
2010-04-22 17:55:27 +02:00
|
|
|
#ifdef SECURE
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vcscanf_s_l(const char *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#else /* SECURE */
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vcscanf_l(const char *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#endif /* SECURE */
|
2010-04-22 13:54:03 +02:00
|
|
|
#endif /* WIDE_SCANF */
|
2002-08-17 03:22:00 +02:00
|
|
|
#else
|
|
|
|
#ifdef STRING
|
2002-09-29 20:00:23 +02:00
|
|
|
#undef _EOF_
|
|
|
|
#define _EOF_ 0
|
2020-01-02 19:01:56 +01:00
|
|
|
#define _GETC_FUNC_(file) (*file++)
|
|
|
|
#ifdef WIDE_SCANF
|
|
|
|
#define _STRTOD_NAME_(func) wstr_ ## func
|
|
|
|
#else
|
|
|
|
#define _STRTOD_NAME_(func) str_ ## func
|
|
|
|
#endif
|
2011-04-05 17:06:58 +02:00
|
|
|
#ifdef STRING_LEN
|
2017-04-03 12:45:58 +02:00
|
|
|
#ifdef WIDE_SCANF
|
2020-01-03 19:42:07 +01:00
|
|
|
#define _GETC_(file) (consumed++, consumed>length ? '\0' : *file++)
|
2017-04-03 12:45:58 +02:00
|
|
|
#else /* WIDE_SCANF */
|
2020-01-03 19:42:07 +01:00
|
|
|
#define _GETC_(file) (consumed++, consumed>length ? '\0' : (unsigned char)*file++)
|
2017-04-03 12:45:58 +02:00
|
|
|
#endif /* WIDE_SCANF */
|
2011-04-05 17:06:58 +02:00
|
|
|
#define _UNGETC_(nch, file) do { file--; consumed--; } while(0)
|
2011-05-19 15:32:00 +02:00
|
|
|
#define _LOCK_FILE_(file) do {} while(0)
|
|
|
|
#define _UNLOCK_FILE_(file) do {} while(0)
|
2011-04-05 17:06:58 +02:00
|
|
|
#ifdef WIDE_SCANF
|
|
|
|
#ifdef SECURE
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vsnwscanf_s_l(const wchar_t *file, size_t length, const wchar_t *format, _locale_t locale, __ms_va_list ap)
|
2011-04-05 17:06:58 +02:00
|
|
|
#else /* SECURE */
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vsnwscanf_l(const wchar_t *file, size_t length, const wchar_t *format, _locale_t locale, __ms_va_list ap)
|
2011-04-05 17:06:58 +02:00
|
|
|
#endif /* SECURE */
|
|
|
|
#else /* WIDE_SCANF */
|
|
|
|
#ifdef SECURE
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vsnscanf_s_l(const char *file, size_t length, const char *format, _locale_t locale, __ms_va_list ap)
|
2011-04-05 17:06:58 +02:00
|
|
|
#else /* SECURE */
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vsnscanf_l(const char *file, size_t length, const char *format, _locale_t locale, __ms_va_list ap)
|
2011-04-05 17:06:58 +02:00
|
|
|
#endif /* SECURE */
|
|
|
|
#endif /* WIDE_SCANF */
|
|
|
|
#else /* STRING_LEN */
|
2017-04-03 12:45:58 +02:00
|
|
|
#ifdef WIDE_SCANF
|
2003-10-10 02:00:19 +02:00
|
|
|
#define _GETC_(file) (consumed++, *file++)
|
2017-04-03 12:45:58 +02:00
|
|
|
#else /* WIDE_SCANF */
|
2015-12-22 23:14:28 +01:00
|
|
|
#define _GETC_(file) (consumed++, (unsigned char)*file++)
|
2017-04-03 12:45:58 +02:00
|
|
|
#endif /* WIDE_SCANF */
|
2003-10-10 02:00:19 +02:00
|
|
|
#define _UNGETC_(nch, file) do { file--; consumed--; } while(0)
|
2011-05-19 15:32:00 +02:00
|
|
|
#define _LOCK_FILE_(file) do {} while(0)
|
|
|
|
#define _UNLOCK_FILE_(file) do {} while(0)
|
2002-08-17 03:22:00 +02:00
|
|
|
#ifdef WIDE_SCANF
|
2010-04-22 17:55:27 +02:00
|
|
|
#ifdef SECURE
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vswscanf_s_l(const wchar_t *file, const wchar_t *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#else /* SECURE */
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vswscanf_l(const wchar_t *file, const wchar_t *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#endif /* SECURE */
|
2002-08-17 03:22:00 +02:00
|
|
|
#else /* WIDE_SCANF */
|
2010-04-22 17:55:27 +02:00
|
|
|
#ifdef SECURE
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vsscanf_s_l(const char *file, const char *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#else /* SECURE */
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vsscanf_l(const char *file, const char *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#endif /* SECURE */
|
2002-08-17 03:22:00 +02:00
|
|
|
#endif /* WIDE_SCANF */
|
2011-04-05 17:06:58 +02:00
|
|
|
#endif /* STRING_LEN */
|
2002-08-17 03:22:00 +02:00
|
|
|
#else /* STRING */
|
|
|
|
#ifdef WIDE_SCANF
|
2020-12-03 19:11:20 +01:00
|
|
|
#define _GETC_FUNC_(file) fgetwc(file)
|
2020-01-02 19:01:56 +01:00
|
|
|
#define _STRTOD_NAME_(func) filew_ ## func
|
2020-12-03 19:11:20 +01:00
|
|
|
#define _GETC_(file) (consumed++, fgetwc(file))
|
|
|
|
#define _UNGETC_(nch, file) do { ungetwc(nch, file); consumed--; } while(0)
|
|
|
|
#define _LOCK_FILE_(file) _lock_file(file)
|
|
|
|
#define _UNLOCK_FILE_(file) _unlock_file(file)
|
2010-04-22 17:55:27 +02:00
|
|
|
#ifdef SECURE
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vfwscanf_s_l(FILE* file, const wchar_t *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#else /* SECURE */
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vfwscanf_l(FILE* file, const wchar_t *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#endif /* SECURE */
|
2002-08-17 03:22:00 +02:00
|
|
|
#else /* WIDE_SCANF */
|
2020-12-03 19:11:20 +01:00
|
|
|
#define _GETC_FUNC_(file) fgetc(file)
|
2020-01-02 19:01:56 +01:00
|
|
|
#define _STRTOD_NAME_(func) file_ ## func
|
2020-12-03 19:11:20 +01:00
|
|
|
#define _GETC_(file) (consumed++, fgetc(file))
|
|
|
|
#define _UNGETC_(nch, file) do { ungetc(nch, file); consumed--; } while(0)
|
|
|
|
#define _LOCK_FILE_(file) _lock_file(file)
|
|
|
|
#define _UNLOCK_FILE_(file) _unlock_file(file)
|
2010-04-22 17:55:27 +02:00
|
|
|
#ifdef SECURE
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vfscanf_s_l(FILE* file, const char *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#else /* SECURE */
|
2020-12-02 00:54:03 +01:00
|
|
|
#define _FUNCTION_ static int vfscanf_l(FILE* file, const char *format, _locale_t locale, __ms_va_list ap)
|
2010-04-22 17:55:27 +02:00
|
|
|
#endif /* SECURE */
|
2002-08-17 03:22:00 +02:00
|
|
|
#endif /* WIDE_SCANF */
|
|
|
|
#endif /* STRING */
|
|
|
|
#endif /* CONSOLE */
|
|
|
|
|
2020-01-02 19:01:56 +01:00
|
|
|
#if (!defined(SECURE) && !defined(STRING_LEN) && (!defined(CONSOLE) || !defined(WIDE_SCANF)))
|
|
|
|
struct _STRTOD_NAME_(strtod_scanf_ctx) {
|
2020-11-26 19:19:09 +01:00
|
|
|
pthreadlocinfo locinfo;
|
2020-01-02 19:01:56 +01:00
|
|
|
#ifdef STRING
|
|
|
|
const _CHAR_ *file;
|
|
|
|
#else
|
2020-12-01 13:51:39 +01:00
|
|
|
FILE *file;
|
2020-01-02 19:01:56 +01:00
|
|
|
#endif
|
|
|
|
int length;
|
|
|
|
int read;
|
2020-01-03 19:42:25 +01:00
|
|
|
int cur;
|
|
|
|
int unget;
|
|
|
|
BOOL err;
|
2020-01-02 19:01:56 +01:00
|
|
|
};
|
|
|
|
|
2020-11-27 14:16:49 +01:00
|
|
|
static wchar_t _STRTOD_NAME_(strtod_scanf_get)(void *ctx)
|
2020-01-02 19:01:56 +01:00
|
|
|
{
|
|
|
|
struct _STRTOD_NAME_(strtod_scanf_ctx) *context = ctx;
|
|
|
|
|
2020-01-03 19:42:25 +01:00
|
|
|
context->cur = _EOF_;
|
2020-11-30 14:37:05 +01:00
|
|
|
if (!context->length) return WEOF;
|
2020-01-03 19:42:25 +01:00
|
|
|
if (context->unget != _EOF_) {
|
|
|
|
context->cur = context->unget;
|
|
|
|
context->unget = _EOF_;
|
|
|
|
} else {
|
|
|
|
context->cur = _GETC_FUNC_(context->file);
|
2020-11-30 14:37:05 +01:00
|
|
|
if (context->cur == _EOF_) return WEOF;
|
2020-01-03 19:42:25 +01:00
|
|
|
}
|
2020-01-02 19:01:56 +01:00
|
|
|
|
|
|
|
if (context->length > 0) context->length--;
|
|
|
|
context->read++;
|
2020-01-03 19:42:25 +01:00
|
|
|
return context->cur;
|
2020-01-02 19:01:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void _STRTOD_NAME_(strtod_scanf_unget)(void *ctx)
|
|
|
|
{
|
|
|
|
struct _STRTOD_NAME_(strtod_scanf_ctx) *context = ctx;
|
|
|
|
|
|
|
|
if (context->length >= 0) context->length++;
|
|
|
|
context->read--;
|
2020-01-03 19:42:25 +01:00
|
|
|
if (context->unget != _EOF_ || context->cur == _EOF_) {
|
|
|
|
context->err = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
context->unget = context->cur;
|
2020-01-02 19:01:56 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-02-19 02:13:12 +01:00
|
|
|
_FUNCTION_ {
|
2020-11-26 19:19:09 +01:00
|
|
|
pthreadlocinfo locinfo;
|
2003-10-10 02:00:19 +02:00
|
|
|
int rd = 0, consumed = 0;
|
2002-08-17 03:22:00 +02:00
|
|
|
int nch;
|
|
|
|
if (!*format) return 0;
|
|
|
|
#ifndef WIDE_SCANF
|
|
|
|
#ifdef CONSOLE
|
2009-03-08 23:48:03 +01:00
|
|
|
TRACE("(%s):\n", debugstr_a(format));
|
2002-08-17 03:22:00 +02:00
|
|
|
#else /* CONSOLE */
|
|
|
|
#ifdef STRING
|
2010-04-26 12:33:58 +02:00
|
|
|
TRACE("%s (%s)\n", debugstr_a(file), debugstr_a(format));
|
2002-08-17 03:22:00 +02:00
|
|
|
#else /* STRING */
|
2004-02-24 02:09:39 +01:00
|
|
|
TRACE("%p (%s)\n", file, debugstr_a(format));
|
2002-08-17 03:22:00 +02:00
|
|
|
#endif /* STRING */
|
|
|
|
#endif /* CONSOLE */
|
|
|
|
#endif /* WIDE_SCANF */
|
2011-05-19 15:32:00 +02:00
|
|
|
_LOCK_FILE_(file);
|
|
|
|
|
2002-08-17 03:22:00 +02:00
|
|
|
nch = _GETC_(file);
|
2011-05-19 15:32:00 +02:00
|
|
|
if (nch == _EOF_) {
|
|
|
|
_UNLOCK_FILE_(file);
|
|
|
|
return _EOF_RET;
|
|
|
|
}
|
2003-01-11 22:06:02 +01:00
|
|
|
|
2010-04-22 13:48:49 +02:00
|
|
|
if(!locale)
|
2011-05-24 17:22:32 +02:00
|
|
|
locinfo = get_locinfo();
|
|
|
|
else
|
|
|
|
locinfo = locale->locinfo;
|
2010-04-22 13:48:49 +02:00
|
|
|
|
2002-08-17 03:22:00 +02:00
|
|
|
while (*format) {
|
|
|
|
/* a whitespace character in the format string causes scanf to read,
|
|
|
|
* but not store, all consecutive white-space characters in the input
|
|
|
|
* up to the next non-white-space character. One white space character
|
|
|
|
* in the input matches any number (including zero) and combination of
|
|
|
|
* white-space characters in the input. */
|
|
|
|
if (_ISSPACE_(*format)) {
|
|
|
|
/* skip whitespace */
|
|
|
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
|
|
|
nch = _GETC_(file);
|
|
|
|
}
|
|
|
|
/* a format specification causes scanf to read and convert characters
|
|
|
|
* in the input into values of a specified type. The value is assigned
|
|
|
|
* to an argument in the argument list. Format specifications have
|
|
|
|
* the form %[*][width][{h | l | I64 | L}]type */
|
2002-12-20 01:35:41 +01:00
|
|
|
else if (*format == '%') {
|
2002-08-17 03:22:00 +02:00
|
|
|
int st = 0; int suppress = 0; int width = 0;
|
2006-03-26 04:10:28 +02:00
|
|
|
int base;
|
2002-08-17 03:22:00 +02:00
|
|
|
int h_prefix = 0;
|
|
|
|
int l_prefix = 0;
|
|
|
|
int L_prefix = 0;
|
|
|
|
int w_prefix = 0;
|
|
|
|
int prefix_finished = 0;
|
2004-02-24 02:09:39 +01:00
|
|
|
int I64_prefix = 0;
|
2002-08-17 03:22:00 +02:00
|
|
|
format++;
|
|
|
|
/* look for leading asterisk, which means 'suppress assignment of
|
|
|
|
* this field'. */
|
2002-12-20 01:35:41 +01:00
|
|
|
if (*format=='*') {
|
2002-08-17 03:22:00 +02:00
|
|
|
format++;
|
|
|
|
suppress=1;
|
|
|
|
}
|
|
|
|
/* read prefix (if any) */
|
|
|
|
while (!prefix_finished) {
|
2019-12-06 15:57:09 +01:00
|
|
|
/* look for width specification */
|
2020-11-18 16:03:27 +01:00
|
|
|
while (*format >= '0' && *format <= '9') {
|
2019-12-06 15:57:09 +01:00
|
|
|
width *= 10;
|
|
|
|
width += *format++ - '0';
|
|
|
|
}
|
|
|
|
|
2002-08-17 03:22:00 +02:00
|
|
|
switch(*format) {
|
2012-04-16 16:32:57 +02:00
|
|
|
case 'h': h_prefix++; break;
|
|
|
|
case 'l':
|
|
|
|
if(*(format+1) == 'l') {
|
|
|
|
I64_prefix = 1;
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
l_prefix = 1;
|
|
|
|
break;
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'w': w_prefix = 1; break;
|
|
|
|
case 'L': L_prefix = 1; break;
|
|
|
|
case 'I':
|
|
|
|
if (*(format + 1) == '6' &&
|
|
|
|
*(format + 2) == '4') {
|
2004-02-24 02:09:39 +01:00
|
|
|
I64_prefix = 1;
|
2002-08-17 03:22:00 +02:00
|
|
|
format += 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prefix_finished = 1;
|
|
|
|
}
|
|
|
|
if (!prefix_finished) format++;
|
|
|
|
}
|
2019-12-06 15:57:09 +01:00
|
|
|
if (width==0) width=-1; /* no width spec seen */
|
2002-08-17 03:22:00 +02:00
|
|
|
/* read type */
|
|
|
|
switch(*format) {
|
2008-07-01 21:15:00 +02:00
|
|
|
case 'p':
|
|
|
|
case 'P': /* pointer. */
|
2009-04-06 20:58:10 +02:00
|
|
|
if (sizeof(void *) == sizeof(LONGLONG)) I64_prefix = 1;
|
|
|
|
/* fall through */
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'x':
|
|
|
|
case 'X': /* hexadecimal integer. */
|
2006-03-26 04:10:28 +02:00
|
|
|
base = 16;
|
2002-08-17 03:22:00 +02:00
|
|
|
goto number;
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'o': /* octal integer */
|
2006-03-26 04:10:28 +02:00
|
|
|
base = 8;
|
2002-08-17 03:22:00 +02:00
|
|
|
goto number;
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'u': /* unsigned decimal integer */
|
2006-03-26 04:10:28 +02:00
|
|
|
base = 10;
|
2002-08-17 03:22:00 +02:00
|
|
|
goto number;
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'd': /* signed decimal integer */
|
2006-03-26 04:10:28 +02:00
|
|
|
base = 10;
|
2002-08-17 03:22:00 +02:00
|
|
|
goto number;
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'i': /* generic integer */
|
2006-08-22 19:38:56 +02:00
|
|
|
base = 0;
|
2002-08-17 03:22:00 +02:00
|
|
|
number: {
|
|
|
|
/* read an integer */
|
2004-02-24 02:09:39 +01:00
|
|
|
ULONGLONG cur = 0;
|
2002-08-17 03:22:00 +02:00
|
|
|
int negative = 0;
|
|
|
|
int seendigit=0;
|
|
|
|
/* skip initial whitespace */
|
|
|
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
|
|
|
nch = _GETC_(file);
|
|
|
|
/* get sign */
|
2006-03-26 04:10:28 +02:00
|
|
|
if (nch == '-' || nch == '+') {
|
2002-12-20 01:35:41 +01:00
|
|
|
negative = (nch=='-');
|
2002-08-17 03:22:00 +02:00
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
|
|
|
}
|
|
|
|
/* look for leading indication of base */
|
2008-07-01 21:15:00 +02:00
|
|
|
if (width!=0 && nch == '0' && *format != 'p' && *format != 'P') {
|
2002-08-17 03:22:00 +02:00
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
|
|
|
seendigit=1;
|
2002-12-20 01:35:41 +01:00
|
|
|
if (width!=0 && (nch=='x' || nch=='X')) {
|
2002-08-17 03:22:00 +02:00
|
|
|
if (base==0)
|
|
|
|
base=16;
|
|
|
|
if (base==16) {
|
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
|
|
|
seendigit=0;
|
|
|
|
}
|
|
|
|
} else if (base==0)
|
|
|
|
base = 8;
|
|
|
|
}
|
2006-08-22 19:38:56 +02:00
|
|
|
/* format %i without indication of base */
|
|
|
|
if (base==0)
|
|
|
|
base = 10;
|
2002-08-17 03:22:00 +02:00
|
|
|
/* throw away leading zeros */
|
2002-12-20 01:35:41 +01:00
|
|
|
while (width!=0 && nch=='0') {
|
2002-08-17 03:22:00 +02:00
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
|
|
|
seendigit=1;
|
|
|
|
}
|
|
|
|
if (width!=0 && _CHAR2DIGIT_(nch, base)!=-1) {
|
|
|
|
cur = _CHAR2DIGIT_(nch, base);
|
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
|
|
|
seendigit=1;
|
|
|
|
}
|
|
|
|
/* read until no more digits */
|
2002-09-09 21:18:53 +02:00
|
|
|
while (width!=0 && (nch!=_EOF_) && _CHAR2DIGIT_(nch, base)!=-1) {
|
2002-08-17 03:22:00 +02:00
|
|
|
cur = cur*base + _CHAR2DIGIT_(nch, base);
|
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
|
|
|
seendigit=1;
|
|
|
|
}
|
|
|
|
/* okay, done! */
|
|
|
|
if (!seendigit) break; /* not a valid number */
|
|
|
|
st = 1;
|
|
|
|
if (!suppress) {
|
|
|
|
#define _SET_NUMBER_(type) *va_arg(ap, type*) = negative ? -cur : cur
|
2006-03-26 04:10:28 +02:00
|
|
|
if (I64_prefix) _SET_NUMBER_(LONGLONG);
|
2009-04-06 20:58:10 +02:00
|
|
|
else if (l_prefix) _SET_NUMBER_(LONG);
|
2012-04-16 16:32:57 +02:00
|
|
|
else if (h_prefix == 1) _SET_NUMBER_(short int);
|
2019-06-11 02:19:50 +02:00
|
|
|
#if _MSVCR_VER >= 140
|
|
|
|
else if (h_prefix == 2) _SET_NUMBER_(char);
|
|
|
|
#endif
|
2006-03-26 04:10:28 +02:00
|
|
|
else _SET_NUMBER_(int);
|
2002-08-17 03:22:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2012-11-01 15:27:29 +01:00
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
case 'f':
|
|
|
|
case 'g':
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'G': { /* read a float */
|
2020-01-02 19:01:56 +01:00
|
|
|
#ifdef CONSOLE
|
|
|
|
struct _STRTOD_NAME_(strtod_scanf_ctx) ctx = {locinfo, 0, width};
|
|
|
|
#else
|
|
|
|
struct _STRTOD_NAME_(strtod_scanf_ctx) ctx = {locinfo, file, width};
|
|
|
|
#endif
|
|
|
|
int negative = 0;
|
2020-07-23 15:38:28 +02:00
|
|
|
struct fpnum fp;
|
2020-01-02 19:01:56 +01:00
|
|
|
double cur;
|
2012-11-01 15:27:29 +01:00
|
|
|
|
2002-08-17 03:22:00 +02:00
|
|
|
/* skip initial whitespace */
|
|
|
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
|
|
|
nch = _GETC_(file);
|
2020-01-13 20:17:17 +01:00
|
|
|
if (nch == _EOF_)
|
|
|
|
break;
|
2020-01-03 19:42:25 +01:00
|
|
|
ctx.unget = nch;
|
2020-01-02 19:01:56 +01:00
|
|
|
#ifdef STRING
|
|
|
|
ctx.file = file;
|
|
|
|
#endif
|
|
|
|
#ifdef STRING_LEN
|
2020-01-03 19:42:25 +01:00
|
|
|
if(ctx.length > length-consumed+1) ctx.length = length-consumed+1;
|
2020-01-02 19:01:56 +01:00
|
|
|
#endif
|
2012-11-01 15:27:29 +01:00
|
|
|
|
2020-07-23 15:38:28 +02:00
|
|
|
fp = fpnum_parse(_STRTOD_NAME_(strtod_scanf_get),
|
2020-07-23 15:38:40 +02:00
|
|
|
_STRTOD_NAME_(strtod_scanf_unget), &ctx, locinfo, FALSE);
|
2020-07-23 15:38:28 +02:00
|
|
|
fpnum_double(&fp, &cur);
|
2020-01-03 19:42:25 +01:00
|
|
|
if(!rd && ctx.err) {
|
|
|
|
_UNLOCK_FILE_(file);
|
|
|
|
return _EOF_RET;
|
|
|
|
}
|
|
|
|
if(ctx.err || !ctx.read)
|
|
|
|
break;
|
2020-01-02 19:01:56 +01:00
|
|
|
consumed += ctx.read;
|
|
|
|
#ifdef STRING
|
|
|
|
file = ctx.file;
|
|
|
|
#endif
|
2020-01-03 19:42:25 +01:00
|
|
|
nch = ctx.cur;
|
2012-11-05 11:40:20 +01:00
|
|
|
|
2002-08-17 03:22:00 +02:00
|
|
|
st = 1;
|
|
|
|
if (!suppress) {
|
2015-02-18 00:03:50 +01:00
|
|
|
if (L_prefix || l_prefix) _SET_NUMBER_(double);
|
2012-11-01 15:27:29 +01:00
|
|
|
else _SET_NUMBER_(float);
|
|
|
|
}
|
2002-08-17 03:22:00 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-03-01 05:29:54 +01:00
|
|
|
/* According to msdn,
|
2002-08-17 03:22:00 +02:00
|
|
|
* '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
|
|
|
|
* this behaviour. 'h' forces reading char * but 'l' and 'w'
|
|
|
|
* force reading WCHAR. */
|
2002-12-20 01:35:41 +01:00
|
|
|
case 's':
|
2002-08-17 03:22:00 +02:00
|
|
|
if (w_prefix || l_prefix) goto widecharstring;
|
|
|
|
else if (h_prefix) goto charstring;
|
|
|
|
#ifdef WIDE_SCANF
|
|
|
|
else goto widecharstring;
|
|
|
|
#else /* WIDE_SCANF */
|
|
|
|
else goto charstring;
|
|
|
|
#endif /* WIDE_SCANF */
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'S':
|
2002-08-17 03:22:00 +02:00
|
|
|
if (w_prefix || l_prefix) goto widecharstring;
|
|
|
|
else if (h_prefix) goto charstring;
|
|
|
|
#ifdef WIDE_SCANF
|
|
|
|
else goto charstring;
|
|
|
|
#else /* WIDE_SCANF */
|
|
|
|
else goto widecharstring;
|
|
|
|
#endif /* WIDE_SCANF */
|
|
|
|
charstring: { /* read a word into a char */
|
2008-03-20 19:55:31 +01:00
|
|
|
char *sptr = suppress ? NULL : va_arg(ap, char*);
|
2010-04-22 17:55:27 +02:00
|
|
|
char *sptr_beg = sptr;
|
|
|
|
#ifdef SECURE
|
|
|
|
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned);
|
|
|
|
#else
|
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
#endif
|
2002-08-17 03:22:00 +02:00
|
|
|
/* skip initial whitespace */
|
|
|
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
|
|
|
nch = _GETC_(file);
|
|
|
|
/* read until whitespace */
|
|
|
|
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
|
2010-04-22 17:55:27 +02:00
|
|
|
if (!suppress) {
|
|
|
|
*sptr++ = _CHAR2SUPPORTED_(nch);
|
|
|
|
if(size>1) size--;
|
|
|
|
else {
|
2011-05-19 15:32:00 +02:00
|
|
|
_UNLOCK_FILE_(file);
|
2010-04-22 17:55:27 +02:00
|
|
|
*sptr_beg = 0;
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
}
|
2002-08-17 03:22:00 +02:00
|
|
|
st++;
|
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
|
|
|
}
|
2019-10-17 00:09:16 +02:00
|
|
|
/* if we have reached the EOF and output nothing then report EOF */
|
|
|
|
if (nch==_EOF_ && rd==0 && st==0) {
|
2019-11-13 22:52:51 +01:00
|
|
|
_UNLOCK_FILE_(file);
|
2019-10-17 00:09:16 +02:00
|
|
|
return _EOF_RET;
|
|
|
|
}
|
2002-08-17 03:22:00 +02:00
|
|
|
/* terminate */
|
2014-01-16 11:39:44 +01:00
|
|
|
if (st && !suppress) *sptr = 0;
|
2002-08-17 03:22:00 +02:00
|
|
|
}
|
|
|
|
break;
|
2002-12-19 05:21:30 +01:00
|
|
|
widecharstring: { /* read a word into a wchar_t* */
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t *sptr = suppress ? NULL : va_arg(ap, wchar_t*);
|
|
|
|
wchar_t *sptr_beg = sptr;
|
2010-04-22 17:55:27 +02:00
|
|
|
#ifdef SECURE
|
|
|
|
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned);
|
|
|
|
#else
|
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
#endif
|
2002-08-17 03:22:00 +02:00
|
|
|
/* skip initial whitespace */
|
|
|
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
|
|
|
nch = _GETC_(file);
|
|
|
|
/* read until whitespace */
|
|
|
|
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
|
2010-04-22 17:55:27 +02:00
|
|
|
if (!suppress) {
|
|
|
|
*sptr++ = _WIDE2SUPPORTED_(nch);
|
|
|
|
if(size>1) size--;
|
|
|
|
else {
|
2011-05-19 15:32:00 +02:00
|
|
|
_UNLOCK_FILE_(file);
|
2010-04-22 17:55:27 +02:00
|
|
|
*sptr_beg = 0;
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
}
|
2002-08-17 03:22:00 +02:00
|
|
|
st++;
|
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
|
|
|
}
|
2019-10-17 00:09:16 +02:00
|
|
|
#if _MSVCR_VER >= 80
|
|
|
|
/* if we have reached the EOF and output nothing then report EOF */
|
|
|
|
if (nch==_EOF_ && rd==0 && st==0) {
|
2019-11-13 22:52:51 +01:00
|
|
|
_UNLOCK_FILE_(file);
|
2019-10-17 00:09:16 +02:00
|
|
|
return _EOF_RET;
|
|
|
|
}
|
|
|
|
#endif
|
2002-08-17 03:22:00 +02:00
|
|
|
/* terminate */
|
2014-01-16 11:39:44 +01:00
|
|
|
if (st && !suppress) *sptr = 0;
|
2002-08-17 03:22:00 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* 'c' and 'C work analogously to 's' and 'S' as described
|
|
|
|
* above */
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'c':
|
2002-08-17 03:22:00 +02:00
|
|
|
if (w_prefix || l_prefix) goto widecharacter;
|
|
|
|
else if (h_prefix) goto character;
|
|
|
|
#ifdef WIDE_SCANF
|
|
|
|
else goto widecharacter;
|
|
|
|
#else /* WIDE_SCANF */
|
|
|
|
else goto character;
|
|
|
|
#endif /* WIDE_SCANF */
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'C':
|
2002-08-17 03:22:00 +02:00
|
|
|
if (w_prefix || l_prefix) goto widecharacter;
|
|
|
|
else if (h_prefix) goto character;
|
|
|
|
#ifdef WIDE_SCANF
|
|
|
|
else goto character;
|
|
|
|
#else /* WIDE_SCANF */
|
|
|
|
else goto widecharacter;
|
|
|
|
#endif /* WIDE_SCANF */
|
|
|
|
character: { /* read single character into char */
|
2008-03-20 19:55:31 +01:00
|
|
|
char *str = suppress ? NULL : va_arg(ap, char*);
|
2010-04-22 17:55:27 +02:00
|
|
|
char *pstr = str;
|
|
|
|
#ifdef SECURE
|
2017-12-01 12:29:08 +01:00
|
|
|
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned);
|
2010-04-22 17:55:27 +02:00
|
|
|
#else
|
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
#endif
|
2008-03-20 19:55:31 +01:00
|
|
|
if (width == -1) width = 1;
|
2010-04-22 17:55:27 +02:00
|
|
|
while (width && (nch != _EOF_))
|
2008-03-20 19:55:31 +01:00
|
|
|
{
|
2010-04-22 17:55:27 +02:00
|
|
|
if (!suppress) {
|
|
|
|
if(size) size--;
|
|
|
|
else {
|
2011-05-19 15:32:00 +02:00
|
|
|
_UNLOCK_FILE_(file);
|
2010-04-22 17:55:27 +02:00
|
|
|
*pstr = 0;
|
|
|
|
return rd;
|
|
|
|
}
|
2018-07-09 14:45:28 +02:00
|
|
|
*str++ = _CHAR2SUPPORTED_(nch);
|
2010-04-22 17:55:27 +02:00
|
|
|
}
|
2008-03-20 19:55:31 +01:00
|
|
|
st++;
|
|
|
|
width--;
|
2005-01-28 12:27:26 +01:00
|
|
|
nch = _GETC_(file);
|
|
|
|
}
|
|
|
|
}
|
2002-08-17 03:22:00 +02:00
|
|
|
break;
|
2005-01-28 12:27:26 +01:00
|
|
|
widecharacter: { /* read single character into a wchar_t */
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t *str = suppress ? NULL : va_arg(ap, wchar_t*);
|
|
|
|
wchar_t *pstr = str;
|
2010-04-22 17:55:27 +02:00
|
|
|
#ifdef SECURE
|
2017-12-01 12:29:08 +01:00
|
|
|
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned);
|
2010-04-22 17:55:27 +02:00
|
|
|
#else
|
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
#endif
|
2008-03-20 19:55:31 +01:00
|
|
|
if (width == -1) width = 1;
|
2010-04-22 17:55:27 +02:00
|
|
|
while (width && (nch != _EOF_))
|
2008-03-20 19:55:31 +01:00
|
|
|
{
|
2010-04-22 17:55:27 +02:00
|
|
|
if (!suppress) {
|
|
|
|
if(size) size--;
|
|
|
|
else {
|
2011-05-19 15:32:00 +02:00
|
|
|
_UNLOCK_FILE_(file);
|
2010-04-22 17:55:27 +02:00
|
|
|
*pstr = 0;
|
|
|
|
return rd;
|
|
|
|
}
|
2018-07-09 14:45:28 +02:00
|
|
|
*str++ = _WIDE2SUPPORTED_(nch);
|
2010-04-22 17:55:27 +02:00
|
|
|
}
|
2008-03-20 19:55:31 +01:00
|
|
|
st++;
|
|
|
|
width--;
|
2005-01-28 12:27:26 +01:00
|
|
|
nch = _GETC_(file);
|
|
|
|
}
|
2002-08-17 03:22:00 +02:00
|
|
|
}
|
|
|
|
break;
|
2002-12-20 01:35:41 +01:00
|
|
|
case 'n': {
|
2002-08-17 03:22:00 +02:00
|
|
|
if (!suppress) {
|
|
|
|
int*n = va_arg(ap, int*);
|
2007-01-17 05:14:27 +01:00
|
|
|
*n = consumed - 1;
|
2002-08-17 03:22:00 +02:00
|
|
|
}
|
2005-03-10 12:44:19 +01:00
|
|
|
/* This is an odd one: according to the standard,
|
|
|
|
* "Execution of a %n directive does not increment the
|
|
|
|
* assignment count returned at the completion of
|
|
|
|
* execution" even if it wasn't suppressed with the
|
|
|
|
* '*' flag. The Corrigendum to the standard seems
|
|
|
|
* to contradict this (comment out the assignment to
|
|
|
|
* 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;
|
2002-08-17 03:22:00 +02:00
|
|
|
}
|
|
|
|
break;
|
2002-12-20 01:35:41 +01:00
|
|
|
case '[': {
|
2002-10-15 04:20:07 +02:00
|
|
|
_CHAR_ *str = suppress ? NULL : va_arg(ap, _CHAR_*);
|
|
|
|
_CHAR_ *sptr = str;
|
|
|
|
RTL_BITMAP bitMask;
|
2004-08-23 20:52:54 +02:00
|
|
|
ULONG *Mask;
|
2002-10-15 04:20:07 +02:00
|
|
|
int invert = 0; /* Set if we are NOT to find the chars */
|
2010-04-22 17:55:27 +02:00
|
|
|
#ifdef SECURE
|
2017-12-01 12:29:08 +01:00
|
|
|
unsigned size = suppress ? UINT_MAX : va_arg(ap, unsigned);
|
2010-04-22 17:55:27 +02:00
|
|
|
#else
|
|
|
|
unsigned size = UINT_MAX;
|
|
|
|
#endif
|
2002-10-15 04:20:07 +02:00
|
|
|
|
|
|
|
/* Init our bitmap */
|
2004-01-06 21:38:37 +01:00
|
|
|
Mask = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8);
|
|
|
|
RtlInitializeBitMap(&bitMask, Mask, _BITMAPSIZE_);
|
2002-10-15 04:20:07 +02:00
|
|
|
|
|
|
|
/* Read the format */
|
|
|
|
format++;
|
|
|
|
if(*format == '^') {
|
|
|
|
invert = 1;
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
if(*format == ']') {
|
|
|
|
RtlSetBits(&bitMask, ']', 1);
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
while(*format && (*format != ']')) {
|
2008-03-01 05:29:54 +01:00
|
|
|
/* According to msdn:
|
2004-01-06 22:36:10 +01:00
|
|
|
* "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */
|
2020-11-02 16:00:07 +01:00
|
|
|
if(format[1] == '-' && format[2] && format[2] != ']') {
|
|
|
|
if (format[0] < format[2])
|
|
|
|
RtlSetBits(&bitMask, format[0], format[2] - format[0] + 1);
|
|
|
|
else
|
|
|
|
RtlSetBits(&bitMask, format[2], format[0] - format[2] + 1);
|
|
|
|
format += 2;
|
2004-01-06 22:36:10 +01:00
|
|
|
} else
|
|
|
|
RtlSetBits(&bitMask, *format, 1);
|
2002-10-15 04:20:07 +02:00
|
|
|
format++;
|
|
|
|
}
|
|
|
|
/* read until char is not suitable */
|
|
|
|
while ((width != 0) && (nch != _EOF_)) {
|
|
|
|
if(!invert) {
|
|
|
|
if(RtlAreBitsSet(&bitMask, nch, 1)) {
|
2004-01-06 21:38:37 +01:00
|
|
|
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
|
2002-10-15 04:20:07 +02:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if(RtlAreBitsClear(&bitMask, nch, 1)) {
|
2004-01-06 21:38:37 +01:00
|
|
|
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
|
2002-10-15 04:20:07 +02:00
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
st++;
|
|
|
|
nch = _GETC_(file);
|
|
|
|
if (width>0) width--;
|
2010-04-22 17:55:27 +02:00
|
|
|
if(size>1) size--;
|
|
|
|
else {
|
2011-05-19 15:32:00 +02:00
|
|
|
_UNLOCK_FILE_(file);
|
2010-04-22 17:55:27 +02:00
|
|
|
*str = 0;
|
2018-07-01 23:51:23 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, Mask);
|
2010-04-22 17:55:27 +02:00
|
|
|
return rd;
|
|
|
|
}
|
2002-10-15 04:20:07 +02:00
|
|
|
}
|
|
|
|
/* terminate */
|
|
|
|
if (!suppress) *sptr = 0;
|
|
|
|
HeapFree(GetProcessHeap(), 0, Mask);
|
|
|
|
}
|
|
|
|
break;
|
2002-12-20 01:35:41 +01:00
|
|
|
default:
|
2002-08-17 03:22:00 +02:00
|
|
|
/* From spec: "if a percent sign is followed by a character
|
|
|
|
* that has no meaning as a format-control character, that
|
|
|
|
* character and the following characters are treated as
|
|
|
|
* an ordinary sequence of characters, that is, a sequence
|
|
|
|
* of characters that must match the input. For example,
|
|
|
|
* to specify that a percent-sign character is to be input,
|
2002-12-20 01:35:41 +01:00
|
|
|
* use %%." */
|
|
|
|
while ((nch!=_EOF_) && _ISSPACE_(nch))
|
|
|
|
nch = _GETC_(file);
|
2017-04-03 12:45:58 +02:00
|
|
|
if ((_CHAR_)nch == *format) {
|
2002-12-20 01:35:41 +01:00
|
|
|
suppress = 1; /* whoops no field to be read */
|
|
|
|
st = 1; /* but we got what we expected */
|
|
|
|
nch = _GETC_(file);
|
|
|
|
}
|
|
|
|
break;
|
2002-08-17 03:22:00 +02:00
|
|
|
}
|
|
|
|
if (st && !suppress) rd++;
|
|
|
|
else if (!st) break;
|
|
|
|
}
|
|
|
|
/* a non-white-space character causes scanf to read, but not store,
|
|
|
|
* a matching non-white-space character. */
|
|
|
|
else {
|
|
|
|
/* check for character match */
|
2017-04-03 12:45:58 +02:00
|
|
|
if ((_CHAR_)nch == *format) {
|
2002-08-17 03:22:00 +02:00
|
|
|
nch = _GETC_(file);
|
|
|
|
} else break;
|
|
|
|
}
|
|
|
|
format++;
|
|
|
|
}
|
|
|
|
if (nch!=_EOF_) {
|
|
|
|
_UNGETC_(nch, file);
|
|
|
|
}
|
2011-05-19 15:32:00 +02:00
|
|
|
|
2002-08-17 03:22:00 +02:00
|
|
|
TRACE("returning %d\n", rd);
|
2011-05-19 15:32:00 +02:00
|
|
|
_UNLOCK_FILE_(file);
|
2002-08-17 03:22:00 +02:00
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef _CHAR_
|
|
|
|
#undef _EOF_
|
2003-01-11 23:50:15 +01:00
|
|
|
#undef _EOF_RET
|
2002-08-17 03:22:00 +02:00
|
|
|
#undef _ISSPACE_
|
2004-01-06 21:38:37 +01:00
|
|
|
#undef _CHAR2SUPPORTED_
|
|
|
|
#undef _WIDE2SUPPORTED_
|
2002-08-17 03:22:00 +02:00
|
|
|
#undef _CHAR2DIGIT_
|
2020-01-02 19:01:56 +01:00
|
|
|
#undef _GETC_FUNC_
|
|
|
|
#undef _STRTOD_NAME_
|
2002-08-17 03:22:00 +02:00
|
|
|
#undef _GETC_
|
|
|
|
#undef _UNGETC_
|
2011-05-19 15:32:00 +02:00
|
|
|
#undef _LOCK_FILE_
|
|
|
|
#undef _UNLOCK_FILE_
|
2002-08-17 03:22:00 +02:00
|
|
|
#undef _FUNCTION_
|
2004-01-06 21:38:37 +01:00
|
|
|
#undef _BITMAPSIZE_
|