69 int inp, shift, base, width;
71 int fmt,
flags,
dot, n_assign, v, n, n_input;
83#define SFGETC(f,c) (((c) = getc(f)) < 0 ? c : (++n_input, c))
84#define SFUNGETC(f,c) do { \
91 n_assign = n_input = 0;
104 while ((fmt = *form++)) {
110 if (
SFGETC(f, inp) < 0 || inp == fmt)
119 if (
SFGETC(f, inp) != fmt) {
152 switch ((fmt = *form++)) {
169 n_str = (form - 1) - t_str;
175 n = ft->
extf(&argv, ft);
179 if ((t_str = argv.
s) && (n_str = (
int)ft->
size) < 0)
180 n_str = (ssize_t)strlen(t_str);
198 }
else if (*form ==
'*') {
203 if (ft->
extf(&argv, ft) < 0)
224 for (v = fmt -
'0';
gv_isdigit(*form); ++form)
225 v = v * 10 + (*form -
'0');
239 size = size * 10 + (n -
'0');
240 }
else if (*form ==
'*') {
244 FMTSET(ft, form,
'I',
sizeof(
int), 0, 0, 0, 0,
NULL, 0);
245 if (ft->
extf(&argv, ft) < 0)
254 flags &= ~SFFMT_TYPES;
263 flags &= ~SFFMT_TYPES;
306 argp =
FP_SET(argp, argn);
307 FMTSET(ft, form, fmt, size,
flags, width, 0, base, t_str, n_str);
308 v = ft->
extf(&argv, ft);
313 FMTGET(ft, form, fmt, size,
flags, width, n, base);
329 if (
sizeof(
long) >
sizeof(
int) &&
FMTCMP(size,
long,
long long))
330 *((
long *) value) = (long)n_input;
331 else if (
sizeof(
short) <
sizeof(int) &&
FMTCMP(size,
short,
long long))
332 *((
short *) value) = (
short)n_input;
333 else if (size ==
sizeof(
char))
334 *((
char *) value) = (
char)n_input;
336 *((
int *) value) = (int)n_input;
345 if (fmt ==
'c' || fmt ==
'[')
364 bool seen_dot =
false;
368 else if (inp ==
'.') {
373 }
else if (inp ==
'e' || inp ==
'E') {
377 if (--width <= 0 ||
SFGETC(f, inp) < 0 ||
378 (inp !=
'-' && inp !=
'+' && !
gv_isdigit(inp)))
381 }
else if (inp ==
'-' || inp ==
'+') {
388 }
while (--width > 0 &&
SFGETC(f, inp) >= 0);
392 argv.
d = strtod(accept,
NULL);
395 if (
FMTCMP(size,
double,
long double))
396 *((
double *) value) = argv.
d;
398 *((
float *) value) = (float) argv.
d;
408 if (inp ==
'-' || inp ==
'+') {
411 while (--width > 0 &&
SFGETC(f, inp) >= 0)
420 else if (fmt ==
'x' || fmt ==
'p')
422 else if (fmt ==
'i' && inp ==
'0') {
425 if (
SFGETC(f, inp) >= 0) {
426 if (inp ==
'x' || inp ==
'X')
443 if (inp ==
'0' && --width > 0) {
444 if (
SFGETC(f, inp) >= 0 &&
445 (inp ==
'x' || inp ==
'X') && --width > 0)
448 if (inp >= 0 && sp[inp] < 16)
450 }
else if (base == 10) {
451 if (inp <
'0' || inp >
'9') {
458 (argv.
lu << 3) + (argv.
lu << 1) + (inp -
'0');
459 }
while (--width > 0 &&
SFGETC(f, inp) >=
'0'
463 base = (int) argv.
lu;
469 SFGETC(f, inp) >= 0 && sp[inp] < base)
474 if (base < 2 || base >
SF_RADIX || sp[inp] >= base) {
480 if ((base & ~(base - 1)) == base) {
482 shift = base < 4 ? 1 : 2;
484 shift = base < 16 ? 3 : 4;
486 shift = base < 64 ? 5 : 6;
489 argv.
lu = (argv.
lu << shift) + sp[inp];
490 }
while (--width > 0 &&
491 SFGETC(f, inp) >= 0 && sp[inp] < base);
494 argv.
lu = (argv.
lu * base) + sp[inp];
495 }
while (--width > 0 &&
496 SFGETC(f, inp) >= 0 && sp[inp] < base);
507 *((
void **) value) = (
void *)(uintptr_t)argv.
lu;
508 }
else if (
sizeof(
long) >
sizeof(int) &&
FMTCMP(size,
long,
long long)) {
509 if (fmt ==
'd' || fmt ==
'i')
510 *((
long *) value) = (long) argv.
ll;
513 }
else if (
sizeof(
short) <
sizeof(
int) &&
FMTCMP(size,
short,
long long)) {
514 if (fmt ==
'd' || fmt ==
'i')
515 *((
short *) value) = (short) argv.
ll;
518 }
else if (size ==
sizeof(
char)) {
519 if (fmt ==
'd' || fmt ==
'i')
520 *((
char *) value) = (char) argv.
ll;
524 if (fmt ==
'd' || fmt ==
'i')
525 *((
int *) value) = (int) argv.
ll;
527 *((
unsigned*)value) = (unsigned)argv.
lu;
530 }
else if (fmt ==
's' || fmt ==
'c' || fmt ==
'[') {
534 argv.
s = (
char *) value;
545 if ((n += 1) <= size)
547 }
while (--width > 0 &&
SFGETC(f, inp) >= 0);
548 }
else if (fmt ==
'c') {
550 if ((n += 1) <= size)
552 }
while (--width > 0 &&
SFGETC(f, inp) >= 0);
554 bool accepted[UCHAR_MAX + 1];
555 form = (
const char*)
setclass((
const unsigned char*)form, accepted);
557 if (!accepted[inp]) {
565 if ((n += 1) <= size)
567 }
while (--width > 0 &&
SFGETC(f, inp) >= 0);
570 if (value && (n > 0 || fmt ==
'[')) {
572 if (fmt !=
'c' && size >= 0)
577 if (width > 0 && inp >= 0)
583 if (n_assign == 0 && inp < 0)
#define FMTGET(ft, frm, fv, sz, flgs, wid, pr, bs)
#define FMTSET(ft, frm, fv, sz, flgs, wid, pr, bs, ts, ns)