📄 input.c
字号:
UN_INC(ch);
} /* end of WHILE loop */
if (negative)
number = (unsigned long)(-(long)number);
}
if (_T('F')==comchr) /* expected ':' in long pointer */
started = 0;
if (started)
if (!suppress) {
++count;
assign_num:
if ( integer64 )
*(__int64 UNALIGNED *)pointer = (unsigned __int64)num64;
else
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') : */
nFloatStrUsed=0;
if (_T('-') == ch) {
pFloatStr[nFloatStrUsed++] = _T('-');
goto f_incwidth;
} else if (_T('+') == ch) {
f_incwidth:
--width;
ch = INC();
}
if (!widthset) /* must watch width */
width = -1;
/* now get integral part */
while (_ISDIGIT(ch) && width--) {
++started;
pFloatStr[nFloatStrUsed++] = (char)ch;
if (__check_float_string(nFloatStrUsed,
&nFloatStrSz,
&pFloatStr,
floatstring,
&malloc_FloatStrFlag
)==FALSE) {
goto error_return;
}
ch = INC();
}
#ifdef _UNICODE
decimal=*_INTRN_LOCALE_CONV(_loc_update)->_W_decimal_point;
#else /* _UNICODE */
decimal=*_INTRN_LOCALE_CONV(_loc_update)->decimal_point;
#endif /* _UNICODE */
/* now check for decimal */
if (decimal == (char)ch && width--) {
ch = INC();
pFloatStr[nFloatStrUsed++] = decimal;
if (__check_float_string(nFloatStrUsed,
&nFloatStrSz,
&pFloatStr,
floatstring,
&malloc_FloatStrFlag
)==FALSE) {
goto error_return;
}
while (_ISDIGIT(ch) && width--) {
++started;
pFloatStr[nFloatStrUsed++] = (_TCHAR)ch;
if (__check_float_string(nFloatStrUsed,
&nFloatStrSz,
&pFloatStr,
floatstring,
&malloc_FloatStrFlag
)==FALSE) {
goto error_return;
}
ch = INC();
}
}
/* now check for exponent */
if (started && (_T('e') == ch || _T('E') == ch) && width--) {
pFloatStr[nFloatStrUsed++] = _T('e');
if (__check_float_string(nFloatStrUsed,
&nFloatStrSz,
&pFloatStr,
floatstring,
&malloc_FloatStrFlag
)==FALSE) {
goto error_return;
}
if (_T('-') == (ch = INC())) {
pFloatStr[nFloatStrUsed++] = _T('-');
if (__check_float_string(nFloatStrUsed,
&nFloatStrSz,
&pFloatStr,
floatstring,
&malloc_FloatStrFlag
)==FALSE) {
goto error_return;
}
goto f_incwidth2;
} else if (_T('+') == ch) {
f_incwidth2:
if (!width--)
++width;
else
ch = INC();
}
while (_ISDIGIT(ch) && width--) {
++started;
pFloatStr[nFloatStrUsed++] = (_TCHAR)ch;
if (__check_float_string(nFloatStrUsed,
&nFloatStrSz,
&pFloatStr,
floatstring,
&malloc_FloatStrFlag
)==FALSE) {
goto error_return;
}
ch = INC();
}
}
UN_INC(ch);
if (started)
if (!suppress) {
++count;
pFloatStr[nFloatStrUsed]= _T('\0');
#ifdef _UNICODE
{
/* convert floatstring to char string */
/* and do the conversion */
size_t cfslength;
char *cfloatstring;
/*
* Basically the code below assumes that the MULTI BYTE
* Characters are at max 2 bytes. This is true for CRT
* because currently we don't support UTF8.
*/
cfslength =(size_t)(nFloatStrSz+1)*sizeof(wchar_t);
if ((cfloatstring = (char *)_malloc_crt (cfslength)) == NULL)
goto error_return;
_ERRCHECK_EINVAL_ERANGE(wcstombs_s (NULL, cfloatstring, cfslength, pFloatStr, cfslength - 1));
_FASSIGN( longone-1, (char*)pointer , cfloatstring, (char)decimal, _loc_update.GetLocaleT());
_free_crt (cfloatstring);
}
#else /* _UNICODE */
_FASSIGN( longone-1, (char*)pointer , pFloatStr, (char)decimal, _loc_update.GetLocaleT());
#endif /* _UNICODE */
} else /*NULL */;
else
goto error_return;
break;
default: /* either found '%' or something else */
if ((int)*format != (int)ch) {
UN_INC(ch);
#ifdef _SECURE_SCANF
/* error_return ASSERT's if format_error is true */
format_error = TRUE;
#endif /* _SECURE_SCANF */
goto error_return;
}
else
match--; /* % found, compensate for inc below */
if (!suppress)
arglist = arglistsave;
} /* SWITCH */
match++; /* matched a format field - set flag */
} /* WHILE (width) */
else { /* zero-width field in format string */
UN_INC(ch); /* check for input error */
goto error_return;
}
++format; /* skip to next char */
} else /* ('%' != *format) */
{
if (_T('%') == *format && _T('%') == *(format + 1))
{
format++;
}
if ((int)*format++ != (int)(ch = INC()))
{
UN_INC(ch);
goto error_return;
}
#ifndef _UNICODE
if (isleadbyte((unsigned char)ch))
{
int ch2;
if ((int)*format++ != (ch2=INC()))
{
UN_INC(ch2);
UN_INC(ch);
goto error_return;
}
--charcount; /* only count as one character read */
}
#endif /* _UNICODE */
}
#ifndef CPRFLAG
if ( (_TEOF == ch) && ((*format != _T('%')) || (*(format + 1) != _T('n'))) )
break;
#endif /* CPRFLAG */
} /* WHILE (*format) */
error_return:
#if ALLOC_TABLE
if (malloc_flag == 1)
{
_free_crt(table);
}
#endif /* ALLOC_TABLE */
if (malloc_FloatStrFlag == 1)
{
_free_crt(pFloatStr);
}
#ifndef CPRFLAG
if (_TEOF == ch)
/* If any fields were matched or assigned, return count */
return ( (count || match) ? count : EOF);
else
#endif /* CPRFLAG */
#ifdef _SECURE_SCANF
if(format_error == TRUE) {
_VALIDATE_RETURN( ("Invalid Input Format",0), EINVAL, count);
}
#endif /* _SECURE_SCANF */
return count;
}
/* _hextodec() returns a value of 0-15 and expects a char 0-9, a-f, A-F */
/* _inc() is the one place where we put the actual getc code. */
/* _whiteout() returns the first non-blank character, as defined by isspace() */
static _TINT __cdecl _hextodec ( _TCHAR chr)
{
return _ISDIGIT(chr) ? chr : (chr & ~(_T('a') - _T('A'))) - _T('A') + 10 + _T('0');
}
#ifdef CPRFLAG
static _TINT __cdecl _inc(void)
{
return (_gettche_nolock());
}
static void __cdecl _un_inc(_TINT chr)
{
if (_TEOF != chr) {
_ungettch_nolock(chr);
}
}
static _TINT __cdecl _whiteout(REG1 int* counter)
{
REG2 _TINT ch;
do
{
++*counter;
ch = _inc();
if (ch == _TEOF)
{
break;
}
}
while(_istspace((_TUCHAR)ch));
return ch;
}
#else /* CPRFLAG */
static _TINT __cdecl _inc(FILE* fileptr)
{
return (_gettc_nolock(fileptr));
}
static void __cdecl _un_inc(_TINT chr, FILE* fileptr)
{
if (_TEOF != chr) {
_ungettc_nolock(chr,fileptr);
}
}
static _TINT __cdecl _whiteout(int* counter, FILE* fileptr)
{
_TINT ch;
do
{
++*counter;
ch = _inc(fileptr);
if (ch == _TEOF)
{
break;
}
}
while(_istspace((_TUCHAR)ch));
return ch;
}
#endif /* CPRFLAG */
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -