📄 input.c
字号:
}
if (!*scanptr)
goto error_return; /* trunc'd format string */
/* scanset completed. Now read string */
if (LEFT_BRACKET == comchr)
format = scanptr;
scanit:
start = pointer;
/*
* execute the format directive. that is, scan input
* characters until the directive is fulfilled, eof
* is reached, or a non-matching character is
* encountered.
*
* it is important not to get the next character
* unless that character needs to be tested! other-
* wise, reads from line-buffered devices (e.g.,
* scanf()) would require an extra, spurious, newline
* if the first newline completes the current format
* directive.
*/
UN_INC(ch);
#ifdef _SECURE_SCANF
/* One element is needed for '\0' for %s & %[ */
if(comchr != _T('c')) {
--array_width;
}
#endif /* _SECURE_SCANF */
while ( !widthset || width-- ) {
ch = INC();
if (
#ifndef CPRFLAG
(_TEOF != ch) &&
#endif /* CPRFLAG */
// char conditions
( ( comchr == _T('c')) ||
// string conditions !isspace()
( ( comchr == _T('s') &&
(!(ch >= _T('\t') && ch <= _T('\r')) &&
ch != _T(' ')))) ||
// BRACKET conditions
( (comchr == LEFT_BRACKET) &&
((table[ch >> 3] ^ reject) & (1 << (ch & 7)))
)
)
)
{
if (!suppress) {
#ifdef _SECURE_SCANF
if(!array_width) {
/* We have exhausted the user's buffer */
enomem = 1;
break;
}
#endif /* _SECURE_SCANF */
#ifndef _UNICODE
if (fl_wchar_arg) {
char temp[2];
temp[0] = (char) ch;
if (isleadbyte((unsigned char)ch))
{
temp[1] = (char) INC();
}
wctemp = L'?';
#ifdef _SAFECRT_IMPL
mbtowc(&wctemp, temp, MB_CUR_MAX);
#else /* _SAFECRT_IMPL */
_mbtowc_l(&wctemp,
temp,
_loc_update.GetLocaleT()->locinfo->mb_cur_max,
_loc_update.GetLocaleT());
#endif /* _SAFECRT_IMPL */
*(wchar_t UNALIGNED *)pointer = wctemp;
/* just copy L'?' if mbtowc fails, errno is set by mbtowc */
pointer = (wchar_t *)pointer + 1;
#ifdef _SECURE_SCANF
--array_width;
#endif /* _SECURE_SCANF */
} else
#else /* _UNICODE */
if (fl_wchar_arg) {
*(wchar_t UNALIGNED *)pointer = ch;
pointer = (wchar_t *)pointer + 1;
#ifdef _SECURE_SCANF
--array_width;
#endif /* _SECURE_SCANF */
} else
#endif /* _UNICODE */
{
#ifndef _UNICODE
*(char *)pointer = (char)ch;
pointer = (char *)pointer + 1;
#ifdef _SECURE_SCANF
--array_width;
#endif /* _SECURE_SCANF */
#else /* _UNICODE */
int temp = 0;
#ifndef _SECURE_SCANF
/* convert wide to multibyte */
if (_ERRCHECK_EINVAL_ERANGE(wctomb_s(&temp, (char *)pointer, MB_LEN_MAX, ch)) == 0)
{
/* do nothing if wctomb fails, errno will be set to EILSEQ */
pointer = (char *)pointer + temp;
}
#else /* _SECURE_SCANF */
/* convert wide to multibyte */
#ifdef _SAFECRT_IMPL
if (array_width >= ((size_t)MB_CUR_MAX))
{
_BEGIN_SECURE_CRT_DEPRECATION_DISABLE
temp = wctomb((char *)pointer, ch);
_END_SECURE_CRT_DEPRECATION_DISABLE
}
else
{
char tmpbuf[MB_LEN_MAX];
_BEGIN_SECURE_CRT_DEPRECATION_DISABLE
temp = wctomb(tmpbuf, ch);
_END_SECURE_CRT_DEPRECATION_DISABLE
if (temp > 0 && ((size_t)temp) > array_width)
{
/* We have exhausted the user's buffer */
enomem = 1;
break;
}
memcpy(pointer, tmpbuf, temp);
}
#else /* _SAFECRT_IMPL */
if(wctomb_s(&temp,(char *)pointer, array_width, ch) == ERANGE) {
/* We have exhausted the user's buffer */
enomem = 1;
break;
}
#endif /* _SAFECRT_IMPL */
if (temp > 0)
{
/* do nothing if wctomb fails, errno will be set to EILSEQ */
pointer = (char *)pointer + temp;
array_width -= temp;
}
#endif /* _SECURE_SCANF */
#endif /* _UNICODE */
}
} /* suppress */
else {
/* just indicate a match */
start = (_TCHAR *)start + 1;
}
}
else {
UN_INC(ch);
break;
}
}
/* make sure something has been matched and, if
assignment is not suppressed, null-terminate
output string if comchr != c */
#ifdef _SECURE_SCANF
if(enomem) {
errno = ENOMEM;
/* In case of error, blank out the input buffer */
if (fl_wchar_arg)
{
_RESET_STRING(((wchar_t UNALIGNED *)start), original_array_width);
}
else
{
_RESET_STRING(((char *)start), original_array_width);
}
goto error_return;
}
#endif /* _SECURE_SCANF */
if (start != pointer) {
if (!suppress) {
++count;
if ('c' != comchr) /* null-terminate strings */
if (fl_wchar_arg)
{
*(wchar_t UNALIGNED *)pointer = L'\0';
#ifdef _SECURE_SCANF
_FILL_STRING(((wchar_t UNALIGNED *)start), original_array_width,
((wchar_t UNALIGNED *)pointer - (wchar_t UNALIGNED *)start + 1))
#endif /* _SECURE_SCANF */
}
else
{
*(char *)pointer = '\0';
#ifdef _SECURE_SCANF
_FILL_STRING(((char *)start), original_array_width,
((char *)pointer - (char *)start + 1))
#endif /* _SECURE_SCANF */
}
} else /*NULL*/;
}
else
goto error_return;
break;
case _T('i') : /* could be d, o, or x */
comchr = _T('d'); /* use as default */
case _T('x'):
if (_T('-') == ch) {
++negative;
goto x_incwidth;
} else if (_T('+') == ch) {
x_incwidth:
if (!--width && widthset)
++done_flag;
else
ch = INC();
}
if (_T('0') == ch) {
if (_T('x') == (_TCHAR)(ch = INC()) || _T('X') == (_TCHAR)ch) {
ch = INC();
if (widthset) {
width -= 2;
if (width < 1)
++done_flag;
}
comchr = _T('x');
} else {
++started;
if (_T('x') != comchr) {
if (widthset && !--width)
++done_flag;
comchr = _T('o');
}
else {
/* scanning a hex number that starts */
/* with a 0. push back the character */
/* currently in ch and restore the 0 */
UN_INC(ch);
ch = _T('0');
}
}
}
goto getnum;
/* NOTREACHED */
case _T('p') :
/* force %hp to be treated as %p */
longone = 1;
#ifdef _WIN64
/* force %p to be 64 bit in WIN64 */
++integer64;
num64 = 0;
#endif /* _WIN64 */
case _T('o') :
case _T('u') :
case _T('d') :
if (_T('-') == ch) {
++negative;
goto d_incwidth;
} else if (_T('+') == ch) {
d_incwidth:
if (!--width && widthset)
++done_flag;
else
ch = INC();
}
getnum:
if ( integer64 ) {
while (!done_flag) {
if (_T('x') == comchr || _T('p') == comchr)
if (_ISXDIGIT(ch)) {
num64 <<= 4;
ch = _hextodec(ch);
}
else
++done_flag;
else if (_ISDIGIT(ch))
if (_T('o') == comchr)
if (_T('8') > ch)
num64 <<= 3;
else {
++done_flag;
}
else /* _T('d') == comchr */
num64 = MUL10(num64);
else
++done_flag;
if (!done_flag) {
++started;
num64 += ch - _T('0');
if (widthset && !--width)
++done_flag;
else
ch = INC();
} else
UN_INC(ch);
} /* end of WHILE loop */
if (negative)
num64 = (unsigned __int64 )(-(__int64)num64);
}
else {
while (!done_flag) {
if (_T('x') == comchr || _T('p') == comchr)
if (_ISXDIGIT(ch)) {
number = (number << 4);
ch = _hextodec(ch);
}
else
++done_flag;
else if (_ISDIGIT(ch))
if (_T('o') == comchr)
if (_T('8') > ch)
number = (number << 3);
else {
++done_flag;
}
else /* _T('d') == comchr */
number = MUL10(number);
else
++done_flag;
if (!done_flag) {
++started;
number += ch - _T('0');
if (widthset && !--width)
++done_flag;
else
ch = INC();
} else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -