1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A* Phong Vo <kpv@research.att.com> * 1N/A***********************************************************************/ 1N/A * Glenn Fowler & Phong Vo 1N/A * common header and implementation for 1N/A * strtof strtod strtold _sfdscan 1N/A * strntof strntod strntold 1N/A * define these macros to instantiate an implementation: 1N/A * S2F_function the function name 1N/A * S2F_static <0:export =0:extern >0:static 1N/A * S2F_type 0:float 1:double 2:long.double 1N/A * S2F_qualifier 1 for optional [fFlL] qualifier suffix 1N/A * S2F_size 1 for interface with size_t second arg 1N/A * S2F_scan 1 for alternate interface with these arguments: 1N/A * int (*getchar)(void* handle, int flag) 1N/A * exactly one extra (*getchar)() is done, i.e., 1N/A * the caller must do the pushback 1N/A * flag==0 get next char 1N/A * flag==1 no number seen 1N/A * return 0 on error or EOF 1N/A * the default is _sfdscan for standalone sfio compatibility 1N/A register unsigned char* s = (
unsigned char*)
str;
1N/A register unsigned char* z = s +
size;
1N/A register unsigned char*
cv;
1N/A * radix char and thousands separator are locale specific 1N/A * skip initial blanks 1N/A if (c ==
'x' || c ==
'X')
1N/A * hex floating point -- easy 1N/A if (c ==
'p' || c ==
'P')
1N/A while (c >=
'0' && c <=
'9')
1N/A m = (m <<
3) + (m <<
1) + (c -
'0');
1N/A * consume the optional suffix 1N/A else if (c ==
'i' || c ==
'I')
1N/A if ((c =
GET(s)) !=
'n' && c !=
'N' ||
1N/A (c =
GET(s)) !=
'f' && c !=
'F')
1N/A if (((c) ==
'i' || c ==
'I') &&
1N/A ((c =
GET(s)) ==
'n' || c ==
'N') &&
1N/A ((c =
GET(s)) ==
'i' || c ==
'I') &&
1N/A ((c =
GET(s)) ==
't' || c ==
'T') &&
1N/A ((c =
GET(s)) ==
'y' || c ==
'Y'))
1N/A else if (c ==
'n' || c ==
'N')
1N/A if ((c =
GET(s)) !=
'a' && c !=
'A' ||
1N/A (c =
GET(s)) !=
'n' && c !=
'N')
1N/A else if (c <
'1' || c >
'9')
1N/A * consume the integral and fractional parts 1N/A if (c >=
'0' && c <=
'9')
1N/A n = (n <<
3) + (n <<
1) + (c -
'0');
1N/A * don't forget the last part 1N/A * consume the exponent 1N/A if (c ==
'e' || c ==
'E')
1N/A while (c >=
'0' && c <=
'9')
1N/A n = (n <<
3) + (n <<
1) + (c -
'0');
1N/A * consume the optional suffix 1N/A * adjust for at most one multiply per part 1N/A * and at most one divide overall