📄 xscanf.c
字号:
fch = *fmt++;
for (i = 0; i < SETSIZE; i++)
set[i] = 0;
if (fch == ']') { /* close bracket first in list*/
setbit (set, ']');
fch = *fmt & 0xff;
fmt++;
}
for (;fch != NUL && fch != ']'; fch = *fmt++ & 0xFF)
setbit(set, fch);
if (fch == NUL)
format = FMT_EOF;
if (iscomplement)
for (i = 0; i < SETSIZE; i++)
set[i] ^= 0xFF;
clrbit(set, NUL); /* NUL is always terminator */
}
break;
#endif /* EXCLUDE_FORMAT_IO_BRAKT_FMT */
} /* End of small switch */
break;
default:
format = FMT_LITERAL;
break;
} /* End of large switch */
if (width == 0)
switch (format) {
#ifdef EXCLUDE_FORMAT_IO_CHAR_FMT
/* No code inserted here */
#else
case FMT_CHAR:
width = 1;
break;
#endif /* EXCLUDE_FORMAT_IO_CHAR_FMT */
#if defined(EXCLUDE_FORMAT_IO_STR_FMT) && \
defined(EXCLUDE_FORMAT_IO_HEX_FMT) && \
defined(EXCLUDE_FORMAT_IO_UNS_FMT) && \
defined(EXCLUDE_FORMAT_IO_OCT_FMT) && \
defined(EXCLUDE_FORMAT_IO_DEC_FMT) && \
defined(EXCLUDE_FORMAT_IO_INT_FMT) && \
defined(EXCLUDE_FORMAT_IO_BRAKT_FMT) && \
defined(EXCLUDE_FORMAT_IO_PNT_FMT)
/* No code inserted here */
#else
case FMT_STRING:
case FMT_INT:
case FMT_CHARSET:
width = MAXWIDTH;
break;
#endif /* EXCLUDE_FORMAT_IO_STR_FMT && .... */
#ifdef EXCLUDE_FORMAT_IO_FLOAT_FMT
/* No code inserted here */
#else
case FMT_FLOAT:
width = SETSIZE - 1;
break;
#endif /* EXCLUDE_FORMAT_IO_FLOAT_FMT */
}
if (format_flag[format] & FIF_SKIP_WS) {
if (in == EMPTY)
if (EOF != (in = (*getcfn)(param)))
++inputCnt;
while (isspace(in))
if (EOF != (in = (*getcfn)(param)))
++inputCnt;
else
break;
}
if (format_flag[format] & FIF_NEED_CHAR && in == EMPTY)
if (EOF != (in = (*getcfn)(param)))
++inputCnt;
pvar = format_flag[format] & FIF_ASSIGNS && ASSGN_EXP (isassigned)
? va_arg(parglist, char *)
: NULL;
switch (format) {
case FMT_LITERAL:
if (in == fch)
in = EMPTY;
else
format = FMT_LITNOMATCH;
break;
#ifdef EXCLUDE_FORMAT_IO_CHAR_FMT
/* No code inserted here */
#else
case FMT_CHAR:
while (in != EOF) {
ismatch = 1;
if (ASSGN_EXP (isassigned))
*pvar++ = in;
getNext;
if (in == EMPTY)
break;
}
break;
#endif /* EXCLUDE_FORMAT_IO_CHAR_FMT */
#ifdef EXCLUDE_FORMAT_IO_STR_FMT
/* No code inserted here */
#else
case FMT_STRING:
while (in != EOF && !isspace(in)) {
ismatch = 1;
if (ASSGN_EXP (isassigned))
*pvar++ = in;
getNext;
if (in == EMPTY)
break;
}
if (ismatch && ASSGN_EXP (isassigned)) /* Terminate string */
*pvar = NUL;
break;
#endif /* EXCLUDE_FORMAT_IO_STR_FMT */
#ifdef EXCLUDE_FORMAT_IO_BRAKT_FMT
/* No code inserted here */
#else
case FMT_CHARSET:
while (in != EOF && isset(set, in)) {
ismatch = 1;
if (ASSGN_EXP (isassigned))
*pvar++ = in;
getNext;
if (in == EMPTY)
break;
}
if (ismatch && ASSGN_EXP (isassigned)) /* Terminate string */
*pvar = NUL;
break;
#endif /* EXCLUDE_FORMAT_IO_BRAKT_FMT */
#if defined(EXCLUDE_FORMAT_IO_HEX_FMT) && \
defined(EXCLUDE_FORMAT_IO_UNS_FMT) && \
defined(EXCLUDE_FORMAT_IO_OCT_FMT) && \
defined(EXCLUDE_FORMAT_IO_DEC_FMT) && \
defined(EXCLUDE_FORMAT_IO_INT_FMT) && \
defined(EXCLUDE_FORMAT_IO_PNT_FMT)
/* No code inserted here */
#else
case FMT_INT:
{
int isminus = 0; /* Check for negative number */
long num = 0;
if (in == '+' || in == '-') {
isminus = in == '-';
getNext;
}
if (0) ; /* allow following conditional compilation */
#ifdef EXCLUDE_FORMAT_IO_INT_FMT
/* No code inserted here */
#else
else if (base == 0) { /* Handle %i format */
if (in != '0') { /* Check for 0 prefix */
base = 10;
isdigitfn = isdigit;
}
else {
getNext;
if ((in == 'x') || (in == 'X')) { /* Hex */
base = 16;
isdigitfn = isxdigit;
getNext;
}
else {
base = 8; /* Octal */
isdigitfn = isodigit;
}
}
}
#endif /* EXCLUDE_FORMAT_IO_INT_FMT */
#if defined(EXCLUDE_FORMAT_IO_HEX_FMT) && defined(EXCLUDE_FORMAT_IO_PNT_FMT)
/* No code inserted here */
#else
else if (base == 16) {
if (in == '0') { /* look for "0x" */
getNext;
if ((in == 'x') || (in == 'X')) {/* peel off "0x" */
getNext;
}
else if (!((*isdigitfn)(in))) { /* ends with zero */
goto hexZero;
}
}
}
#endif /* EXCLUDE_FORMAT_IO_HEX_FMT && .... */
if (width > 0 && (*isdigitfn)(in)) { /* Convert str to # */
do {
if (BASE_10_EXP (base == 10)) /* for speed */
num = (num << 3) + num + num + chtol(in);
else if (BASE_16_EXP (base == 16))
num = (num << 4) + chtol(in);
else if (BASE_8_EXP (1))
num = (num << 3) + chtol(in);
getNext;
} while ((*isdigitfn)(in));
hexZero:
ismatch = 1;
if (ASSGN_EXP (isassigned)) {
if (isminus)
num = -num;
if (PNT_EXP(ispointer)) /* handle %p first */
* (void **) pvar = (void *) num;
else if (OPT_h_EXP (size == 'h'))
* (short *) pvar = (short) num;
else if (OPT_l_EXP (size == 'l'))
* (long *) pvar = num;
else
* (int *) pvar = (int) num;
}
}
}
break;
#endif /* EXCLUDE_FORMAT_IO_HEX_FMT && .... */
#ifdef EXCLUDE_FORMAT_IO_NUMB_FMT
/* No code inserted here */
#else
case FMT_INPUTCNT:
if (ASSGN_EXP (isassigned)) {
if (OPT_h_EXP (size == 'h'))
* (short *) pvar = (short) computeCount;
else if (OPT_l_EXP (size == 'l'))
* (long *) pvar = (long) computeCount;
else
* (int *) pvar = (int) computeCount;
}
break;
#endif /* EXCLUDE_FORMAT_IO_NUMB_FMT */
#ifdef EXCLUDE_FORMAT_IO_FLOAT_FMT
/* No code inserted here */
#else
case FMT_FLOAT:
{
char *pc = set;
int numberp = 0;
if (in == '+' || in == '-') {
*pc++ = in;
getNext;
}
if (width > 0)
while (isdigit(in)) {
*pc++ = in;
numberp = 1;
getNext;
}
if (width > 0 && in == '.') {
*pc++ = in;
numberp = 1;
getNext;
}
if (width > 0)
while (isdigit(in)) {
*pc++ = in;
numberp = 1;
getNext;
}
if (width > 0 && numberp && (in == 'e' || in == 'E')) {
*pc++ = in;
numberp = 0; /* must have #'s after "e" */
getNext;
if (width > 0 && (in == '+' || in == '-')) {
*pc++ = in;
getNext;
}
if (width > 0)
while (isdigit(in)) {
numberp = 1; /* have valid float again */
*pc++ = in;
getNext;
}
}
*pc = NUL;
if (numberp) {
ismatch = 1;
if (ASSGN_EXP (isassigned))
_sfef(pvar, set,
OPT_l_EXP (size == 'l') ||
OPT_L_EXP (size == 'L'));
}
}
break; /* end of FMT_FLOAT */
#endif /* EXCLUDE_FORMAT_IO_FLOAT_FMT */
} /* end of switch */
if (ismatch && ASSGN_EXP (isassigned))
nmatch++;
else if ((!ismatch) && (format != FMT_WS) &&
(format != FMT_LITERAL) && NUMB_EXP(format != FMT_INPUTCNT))
break; /* Stop scan of no match */
} /* end of while loop */
if (in != EOF && in != EMPTY && ungetcfn != (int (*)()) NULL)
(*ungetcfn)(in, param);
if ((in == EOF) && (!nmatch) && ((format==FMT_LITNOMATCH) || start_convrt))
return EOF; /* Input error -- no conversion */
return nmatch;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -