📄 input.c
字号:
if (_T('c') != comchr && LEFT_BRACKET != comchr)
ch = EAT_WHITE();
else
ch = INC();
if (!widthset || width) {
switch(comchr) {
case _T('c'):
/* case _T('C'): */
if (!widthset) {
++widthset;
++width;
}
if (widechar>0)
fl_wchar_arg++;
scanptr = cbrackset;
--reject; /* set reject to 255 */
goto scanit2;
case _T('s'):
/* case _T('S'): */
if (widechar>0)
fl_wchar_arg++;
scanptr = sbrackset;
--reject; /* set reject to 255 */
goto scanit2;
case LEFT_BRACKET : /* scanset */
if (widechar>0)
fl_wchar_arg++;
scanptr = (_TCHAR *)(++format);
if (_T('^') == *scanptr) {
++scanptr;
--reject; /* set reject to 255 */
}
scanit2:
#ifdef _UNICODE
memset(table, 0, ASCII*256);
#else /* _UNICODE */
memset(table, 0, ASCII);
#endif /* _UNICODE */
if (LEFT_BRACKET == comchr)
if (_T(']') == *scanptr) {
prevchar = _T(']');
++scanptr;
table[ _T(']') >> 3] = 1 << (_T(']') & 7);
}
while (_T(']') != *scanptr) {
rngch = *scanptr++;
if (_T('-') != rngch ||
!prevchar || /* first char */
_T(']') == *scanptr) /* last char */
table[(prevchar = rngch) >> 3] |= 1 << (rngch & 7);
else { /* handle a-z type set */
rngch = *scanptr++; /* get end of range */
if (prevchar < rngch) /* %[a-z] */
last = rngch;
else { /* %[z-a] */
last = prevchar;
prevchar = rngch;
}
for (rngch = prevchar; rngch <= last; ++rngch)
table[rngch >> 3] |= 1 << (rngch & 7);
prevchar = 0;
}
}
if (!*scanptr)
goto error_return; /* trunc'd format string */
/* scanset completed. Now read string */
if (LEFT_BRACKET == comchr)
format = scanptr;
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);
while ( !widthset || width-- ) {
ch = INC();
if (
#ifndef _UNICODE
#ifndef CPRFLAG
(EOF != ch) &&
#endif /* CPRFLAG */
((table[ch >> 3] ^ reject) & (1 << (ch & 7)))
#else /* _UNICODE */
(WEOF != ch) &&
/* ((ch>>3 >= ASCII) ? reject : */
((table[ch >> 3] ^ reject) &
(1 << (ch & 7))) /* ) */
#endif /* _UNICODE */
) {
if (!suppress) {
#ifndef _UNICODE
if (fl_wchar_arg) {
char temp[2];
temp[0] = (char) ch;
if (isleadbyte(ch))
temp[1] = (char) INC();
mbtowc(&wctemp, temp, MB_CUR_MAX);
*(wchar_t UNALIGNED *)pointer =
wctemp;
/* do nothing if mbtowc fails */
pointer = (wchar_t *)pointer + 1;
} else
#else /* _UNICODE */
if (fl_wchar_arg) {
*(wchar_t UNALIGNED *)pointer = ch;
pointer = (wchar_t *)pointer + 1;
} else
#endif /* _UNICODE */
{
#ifndef _UNICODE
*(char *)pointer = (char)ch;
pointer = (char *)pointer + 1;
#else /* _UNICODE */
int temp;
/* convert wide to multibyte */
temp = wctomb((char *)pointer, ch);
/* do nothing if wctomb fails */
pointer = (char *)pointer + temp;
#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 */
if (start != pointer) {
if (!suppress) {
++count;
if ('c' != comchr) /* null-terminate strings */
if (fl_wchar_arg)
*(wchar_t UNALIGNED *)pointer = L'\0';
else
*(char *)pointer = '\0';
} 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();
comchr = _T('x');
} else {
++started;
if (_T('x') != comchr)
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;
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 _INTEGRAL_MAX_BITS >= 64
if ( integer64 ) {
while (!done_flag) {
if (_T('x') == 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 {
#endif /* _INTEGRAL_MAX_BITS >= 64 */
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
UN_INC(ch);
} /* end of WHILE loop */
if (negative)
number = (unsigned long)(-(long)number);
#if _INTEGRAL_MAX_BITS >= 64
}
#endif /* _INTEGRAL_MAX_BITS >= 64 */
if (_T('F')==comchr) /* expected ':' in long pointer */
started = 0;
if (started)
if (!suppress) {
++count;
assign_num:
#if _INTEGRAL_MAX_BITS >= 64
if ( integer64 )
*(__int64 UNALIGNED *)pointer = (unsigned __int64)num64;
else
#endif /* _INTEGRAL_MAX_BITS >= 64 */
if (longone)
*(long UNALIGNED *)pointer = (unsigned long)number;
else
*(short UNALIGNED *)pointer = (unsigned short)number;
} else /*NULL*/;
else
goto error_return;
break;
case _T('n') : /* char count, don't inc return value */
number = charcount;
if(!suppress)
goto assign_num; /* found in number code above */
break;
case _T('e') :
/* case _T('E') : */
case _T('f') :
case _T('g') : /* scan a float */
/* case _T('G') : */
#ifndef _UNICODE
scanptr = floatstring;
if (_T('-') == ch) {
*scanptr++ = _T('-');
goto f_incwidth;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -