128 #ifndef NO_FLOATING_POINT
134 #ifndef NO_FLOATING_POINT
135 #define FLOATING_POINT
138 #ifdef FLOATING_POINT
145 #if defined WANT_IO_LONG_DBL && (LDBL_MANT_DIG > DBL_MANT_DIG)
147 extern _LONG_DOUBLE _strtold _PARAMS((
char *s,
char **sptr));
151 #if defined WANT_PRINTF_LONG_LONG && defined __GNUC__
157 #if ((MAXEXP+MAXFRACT+3) > MB_LEN_MAX)
158 # define BUF (MAXEXP+MAXFRACT+3)
160 # define BUF MB_LEN_MAX
165 #define MAX_LONG_LEN ((CHAR_BIT * sizeof (long) - 1) * 4 / 13 + 2)
179 #define SUPPRESS 0x10
190 #define NDIGITS 0x100
196 #define NZDIGITS 0x400
209 #define u_char unsigned char
212 #define u_long unsigned long
215 typedef unsigned long long u_long_long;
225 #define BufferEmpty (fp->_r <= 0 && __srefill(fp))
229 unsigned char buf_ungetc ;
230 int flag_buf_ungetc = 0 ;
231 #define buf_ungetc_empty 0
232 #define buf_ungetc_full 1
247 int __io_ungetc(
int c){
249 if (flag_buf_ungetc == 0){
250 flag_buf_ungetc = buf_ungetc_full;
252 buf_ungetc= (
unsigned char)c ;
258 if (flag_buf_ungetc == 0){
260 return __io_getchar();
265 flag_buf_ungetc = buf_ungetc_empty;
272 #endif // SMALL_SCANF
277 _DEFUN (vfscanf, (fp, fmt, ap),
278 register FILE *fp _AND
279 _CONST
char *fmt _AND
287 return __svfscanf_r (_REENT, fp, fmt, ap);
291 __svfscanf (fp, fmt0, ap)
296 return __svfscanf_r (_REENT, fp, fmt0, ap);
302 _DEFUN (_vfscanf_r, (data, fp, fmt, ap),
303 struct _reent *data _AND
304 register FILE *fp _AND
305 _CONST
char *fmt _AND
308 return __svfscanf_r (data, fp, fmt, ap);
327 __svfscanf_r (rptr, fp, fmt0, ap)
334 register char * bufread;
335 register u_char *fmt = (u_char *) fmt0;
338 register size_t width;
352 u_long (*ccfn) () = 0;
369 static _CONST
short basefix[17] =
370 {10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
379 memset (&state,
'\0',
sizeof (state));
380 nbytes = _mbtowc_r (rptr, &wc, fmt, MB_CUR_MAX, &state);
385 if (nbytes == 1 && isspace (wc))
390 if (BufferEmpty || !isspace (*fp->_p))
392 nread++, fp->_r--, fp->_p++;
395 if (!isspace (*fp->_p))
break;
397 *fp->_p = new_getchar();
421 for (n = 0; n < nbytes; ++n)
427 *fp->_p = new_getchar();
430 if (*fp->_p != *lptr)
437 *fp->_p = new_getchar();
479 width = width * 10 + c -
'0';
495 ccfn = (u_long (*)())_strtol_r;
501 ccfn = (u_long (*)())_strtol_r;
528 #ifdef FLOATING_POINT
548 fmt = __sccl (ccltab, fmt);
563 flags |= POINTER | PFXOK;
570 if (flags & SUPPRESS)
574 cp = va_arg (ap,
char *);
577 else if (flags & SHORT)
579 sp = va_arg (ap,
short *);
582 else if (flags & LONG)
584 lp = va_arg (ap,
long *);
588 else if (flags & LONGDBL)
590 llp = va_arg (ap,
long long*);
596 ip = va_arg (ap,
int *);
611 ccfn = (u_long (*)())_strtol_r;
623 *fp->_p = new_getchar();
631 if ((flags & NOSKIP) == 0)
633 while (isspace (*fp->_p))
643 *fp->_p = new_getchar();
665 if ((flags & SUPPRESS) == 0)
666 wcp = va_arg(ap,
wchar_t *);
679 memset((
void *)&state,
'\0',
sizeof(mbstate_t));
680 if ((mbslen = _mbrtowc_r(rptr, wcp, buf, n, &state))
685 *fp->_p = new_getchar();
689 if (mbslen == 0 && !(flags & SUPPRESS))
691 if (mbslen != (
size_t)-2)
695 if (!(flags & SUPPRESS))
708 if (!(flags & SUPPRESS))
711 else if (flags & SUPPRESS)
716 if ((n = fp->_r) < (
int)width)
729 *fp->_p = new_getchar();
740 *fp->_p = new_getchar();
752 size_t r = fread ((_PTR) va_arg (ap,
char *), 1, width, fp);
759 bufread=(_PTR)va_arg(ap,
char *);
761 for (r=0;r<width;r++){
764 *fp->_p = new_getchar();
776 if (flags & SUPPRESS)
779 while (ccltab[*fp->_p])
782 n++, fp->_r--, fp->_p++;
794 *fp->_p = new_getchar();
803 p0 = p = va_arg (ap,
char *);
804 while (ccltab[*fp->_p])
819 *fp->_p= new_getchar();
842 if ((flags & SUPPRESS) == 0)
843 wcp = va_arg(ap,
wchar_t *);
847 while (!isspace(*fp->_p) && width != 0)
855 memset((
void *)&state,
'\0',
sizeof(mbstate_t));
856 if ((mbslen = _mbrtowc_r(rptr, wcp, buf, n, &state))
860 *fp->_p = new_getchar();
866 if (mbslen != (
size_t)-2)
873 ungetc(buf[--n], fp);
875 __io_ungetc(buf[--n]);
883 if ((flags & SUPPRESS) == 0)
897 if (!(flags & SUPPRESS))
903 else if (flags & SUPPRESS)
906 while (!isspace (*fp->_p))
909 n++, fp->_r--, fp->_p++;
916 *fp->_p = new_getchar();
917 if (*fp->_p ==
'\0')
break;
925 p0 = p = va_arg (ap,
char *);
926 while (!isspace (*fp->_p))
937 *fp->_p = new_getchar();
938 if (*fp->_p ==
'\0')
break;
952 if (width == 0 || width >
sizeof (buf) - 1)
953 width =
sizeof (buf) - 1;
956 if (--width >
sizeof (buf) - 2)
957 width =
sizeof (buf) - 2;
960 flags |= SIGNOK | NDIGITS | NZDIGITS;
961 for (p = buf; width; width--)
985 if (flags & NZDIGITS)
986 flags &= ~(SIGNOK | NZDIGITS | NDIGITS);
988 flags &= ~(SIGNOK | PFXOK | NDIGITS);
999 base = basefix[base];
1000 flags &= ~(SIGNOK | PFXOK | NDIGITS);
1006 base = basefix[base];
1009 flags &= ~(SIGNOK | PFXOK | NDIGITS);
1028 flags &= ~(SIGNOK | PFXOK | NDIGITS);
1044 if (flags & PFXOK && p == buf + 1)
1071 *fp->_p = new_getchar();
1082 if (flags & NDIGITS)
1086 _CAST_VOID ungetc (*(u_char *)-- p, fp);
1088 _CAST_VOID __io_ungetc (*(u_char *)-- p);
1094 c = ((u_char *) p)[-1];
1095 if (c ==
'x' || c ==
'X')
1105 if ((flags & SUPPRESS) == 0)
1110 res = (*ccfn) (rptr, buf, (
char **)
NULL, base);
1111 if (flags & POINTER)
1112 *(va_arg (ap, _PTR *)) = (_PTR) (
unsigned _POINTER_INT) res;
1113 else if (flags & CHAR)
1115 cp = va_arg (ap,
char *);
1118 else if (flags & SHORT)
1120 sp = va_arg (ap,
short *);
1123 else if (flags & LONG)
1125 lp = va_arg (ap,
long *);
1128 #ifndef _NO_LONGLONG
1129 else if (flags & LONGDBL)
1132 if (ccfn == _strtoul_r)
1133 resll = _strtoull_r (rptr, buf, (
char **)
NULL, base);
1135 resll = _strtoll_r (rptr, buf, (
char **)
NULL, base);
1136 llp = va_arg (ap,
long long*);
1142 ip = va_arg (ap,
int *);
1150 #ifdef FLOATING_POINT
1158 long leading_zeroes = 0;
1159 long zeroes, exp_adjust;
1160 char *exp_start =
NULL;
1162 if (width == 0 || width >
sizeof (buf) - 1)
1163 width =
sizeof (buf) - 1;
1166 if (--width >
sizeof (buf) - 2)
1167 width =
sizeof (buf) - 2;
1170 flags |= SIGNOK | NDIGITS | DPTOK | EXPOK;
1173 for (p = buf; width; )
1184 if (flags & NDIGITS)
1200 flags &= ~(SIGNOK | NDIGITS);
1214 flags &= ~(SIGNOK | DPTOK);
1215 leading_zeroes = zeroes;
1222 if ((flags & (NDIGITS | EXPOK)) == EXPOK
1223 || ((flags & EXPOK) && zeroes))
1225 if (! (flags & DPTOK))
1227 exp_adjust = zeroes - leading_zeroes;
1231 (flags & ~(EXPOK | DPTOK)) |
1251 *fp->_p = new_getchar();
1252 if ( (47<*fp->_p<58) && (64<*fp->_p < 71) && (96<*fp->_p<103) ){
1268 if (flags & NDIGITS)
1277 ungetc (*(u_char *)-- p, fp);
1279 __io_ungetc(*(u_char *)-- p);
1289 c = *(u_char *)-- p;
1291 if (c !=
'e' && c !=
'E')
1294 _CAST_VOID ungetc (c, fp);
1296 _CAST_VOID __io_ungetc (c);
1298 c = *(u_char *)-- p;
1302 _CAST_VOID ungetc (c, fp);
1304 _CAST_VOID __io_ungetc (c);
1308 if ((flags & SUPPRESS) == 0)
1312 #define QUAD_RES res;
1314 long double qres = 0;
1315 #define QUAD_RES qres;
1320 if ((flags & (DPTOK | EXPOK)) == EXPOK)
1322 exp_adjust = zeroes - leading_zeroes;
1323 new_exp = -exp_adjust;
1326 else if (exp_adjust)
1327 new_exp = _strtol_r (rptr, (exp_start + 1),
NULL, 10) - exp_adjust;
1333 if (exp_start >= buf +
sizeof (buf) - MAX_LONG_LEN)
1334 exp_start = buf +
sizeof (buf) - MAX_LONG_LEN - 1;
1335 sprintf (exp_start,
"e%ld", new_exp);
1342 if (flags & LONGDBL)
1343 qres = _strtold (buf,
NULL);
1346 res = _strtod_r (rptr, buf,
NULL);
1349 dp = va_arg (ap,
double *);
1352 else if (flags & LONGDBL)
1354 ldp = va_arg (ap, _LONG_DOUBLE *);
1359 flp = va_arg (ap,
float *);
1371 return nassigned ? nassigned : -1;
1387 register u_char *fmt;
1389 register int c, n, v;
1401 for (n = 0; n < 256; n++)
1440 if (n ==
']' || n < c)