📄 input.c
字号:
/* 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((wchar_t *)pointer, temp,
MB_CUR_MAX);
/* do nothing if mbtowc fails */
pointer = (wchar_t *)pointer + 1;
} else
#else /* _UNICODE */
if (fl_wchar_arg) {
*(wchar_t *)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 = (char *)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 *)pointer = L'\0';
else
*(char *)pointer = '\0';
} else /*NULL*/;
}
else
goto error_return;
break;
case 'i': /* could be d, o, or x */
comchr = 'd'; /* use as default */
case '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) {
#ifdef _UNICODE
if (L'x' == (ch = INC()) || L'X' == ch) {
#else /* _UNICODE */
if ('x' == ((char)(ch = INC())) || 'X' == (char)ch){
#endif /* _UNICODE */
ch = INC();
comchr = 'x';
} else {
++started;
if ('x' != comchr)
comchr = '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 'p':
/* force %hp to be treated as %p */
longone = 1;
case 'o':
case 'u':
case '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)
#ifdef _UNICODE
if (iswxdigit(ch)) {
#else /* _UNICODE */
if (isxdigit(ch)) {
#endif /* _UNICODE */
num64 = (num64 << 4);
ch = HEXTODEC(ch);
}
else
++done_flag;
#ifdef _UNICODE
else if (iswdigit(ch))
#else /* _UNICODE */
else if (isdigit(ch))
#endif /* _UNICODE */
if (_T('o') == comchr)
if (_T('8') > ch)
num64 = (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 ('x' == comchr || 'p' == comchr)
#ifdef _UNICODE
if (iswxdigit(ch)) {
#else /* _UNICODE */
if (isxdigit(ch)) {
#endif /* _UNICODE */
number = (number << 4);
ch = HEXTODEC(ch);
}
else
++done_flag;
#ifdef _UNICODE
else if (iswdigit(ch))
#else /* _UNICODE */
else if (isdigit(ch))
#endif /* _UNICODE */
if ('o' == comchr)
if (_T('8') > ch)
number = (number << 3);
else {
++done_flag;
}
else /* '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 ('F' == comchr) /* expected a ':' in long pointer */
started = 0;
if (started)
if (!suppress) {
++count;
assign_num:
if ( integer64 )
*(__int64 UNALIGNED *)pointer = (unsigned __int64)num64;
else if (longone)
*(long *)pointer = (unsigned long)number;
else
*(short *)pointer = (unsigned short)number;
} else /*NULL*/;
else
goto error_return;
break;
case 'n': /* char count, don't inc return value */
number = charcount;
goto assign_num; /* found in number code above */
case 'e':
case 'f':
case 'g': /* scan a float */
#ifndef _UNICODE
scanptr = floatstring;
if ('-' == ch) {
*scanptr++ = '-';
goto f_incwidth;
} else if ('+' == ch) {
f_incwidth:
--width;
ch = INC();
}
if (!widthset || width > CVTBUFSIZE) /* must watch width */
width = CVTBUFSIZE;
/* now get integral part */
while (isdigit(ch) && width--) {
++started;
*scanptr++ = (char)ch;
ch = INC();
}
/* now check for decimal */
if (*___decimal_point == (char)ch && width--) {
ch = INC();
*scanptr++ = *___decimal_point;
while (isdigit(ch) && width--) {
++started;
*scanptr++ = (char)ch;
ch = INC();
}
}
/* now check for exponent */
if (started && ('e' == (char)ch || 'E' == (char)ch) && width--) {
*scanptr++ = 'e';
if ('-' == (ch = INC())) {
*scanptr++ = '-';
goto f_incwidth2;
} else if ('+' == ch) {
f_incwidth2:
if (!width--)
++width;
else
ch = INC();
}
while (isdigit(ch) && width--) {
++started;
*scanptr++ = (char)ch;
ch = INC();
}
}
UN_INC(ch);
if (started)
if (!suppress) {
++count;
*scanptr = '\0';
_fassign( longone-1, pointer , floatstring);
} else /*NULL */;
else
goto error_return;
#else /* _UNICODE */
wptr = floatstring;
if (L'-' == ch) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -