1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1999-08-13 05:45:20 +00:00
parent fcd020c830
commit 65a5162550
156 changed files with 21888 additions and 18301 deletions

View file

@ -1,36 +1,61 @@
/*
* Copyright (c) 1991, Larry Wall
/*
* Public domain dup2() lookalike
* by Curtis Jackson @ AT&T Technologies, Burlington, NC
* electronic address: burl!rcj
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
* dup2 performs the following functions:
*
* Check to make sure that fd1 is a valid open file descriptor.
* Check to see if fd2 is already open; if so, close it.
* Duplicate fd1 onto fd2; checking to make sure fd2 is a valid fd.
* Return fd2 if all went well; return BADEXIT otherwise.
*/
#include "defines.h"
#include "config.h"
#if defined(HAVE_FCNTL) && defined(F_DUPFD)
#if defined(HAVE_FCNTL)
# include <fcntl.h>
#endif
#if !defined(HAVE_FCNTL) || !defined(F_DUPFD)
# include <errno.h>
#endif
#define BADEXIT -1
int
dup2(oldfd,newfd)
int oldfd;
int newfd;
dup2(fd1, fd2)
int fd1, fd2;
{
#if defined(HAVE_FCNTL) && defined(F_DUPFD)
close(newfd);
return fcntl(oldfd, F_DUPFD, newfd);
if (fd1 != fd2) {
#ifdef F_GETFL
if (fcntl(fd1, F_GETFL) < 0)
return BADEXIT;
if (fcntl(fd2, F_GETFL) >= 0)
close(fd2);
#else
int fdtmp[256];
int fdx = 0;
int fd;
close(fd2);
#endif
if (fcntl(fd1, F_DUPFD, fd2) < 0)
return BADEXIT;
}
return fd2;
#else
extern int errno;
int i, fd, fds[256];
if (oldfd == newfd)
return 0;
close(newfd);
while ((fd = dup(oldfd)) != newfd) /* good enough for low fd's */
fdtmp[fdx++] = fd;
while (fdx > 0)
close(fdtmp[--fdx]);
return 0;
if (fd1 == fd2) return 0;
close(fd2);
for (i=0; i<256; i++) {
fd = fds[i] = dup(fd1);
if (fd == fd2) break;
}
while (i) {
close(fds[i--]);
}
if (fd == fd2) return 0;
errno = EMFILE;
return BADEXIT;
#endif
}

6
missing/finite.c Normal file
View file

@ -0,0 +1,6 @@
int
finite(n)
double n;
{
return !isnan(n) && !isinf(n);
}

199
missing/fnmatch.c Normal file
View file

@ -0,0 +1,199 @@
/*
* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Guido van Rossum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
#endif /* LIBC_SCCS and not lint */
/*
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
* Compares a filename or pathname to a pattern.
*/
#include "missing/fnmatch.h"
#include <string.h>
#define EOS '\0'
static char *rangematch();
int
fnmatch(pattern, string, flags)
char *pattern;
char *string;
int flags;
{
char *stringstart;
char c, test;
for (stringstart = string;;) {
switch (c = *pattern++) {
case EOS:
return (*string == EOS ? 0 : FNM_NOMATCH);
case '?':
if (*string == EOS) {
return (FNM_NOMATCH);
}
if (*string == '/' && (flags & FNM_PATHNAME)) {
return (FNM_NOMATCH);
}
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
return (FNM_NOMATCH);
}
++string;
break;
case '*':
c = *pattern;
/* Collapse multiple stars. */
while (c == '*') {
c = *++pattern;
}
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
return (FNM_NOMATCH);
}
/* Optimize for pattern with * at end or before /. */
if (c == EOS) {
if (flags & FNM_PATHNAME) {
return (strchr(string, '/') == NULL ? 0 : FNM_NOMATCH);
}
else {
return (0);
}
}
else if (c == '/' && flags & FNM_PATHNAME) {
if ((string = strchr(string, '/')) == NULL) {
return (FNM_NOMATCH);
}
break;
}
/* General case, use recursion. */
while ((test = *string) != EOS) {
if (!fnmatch(pattern, string, flags & ~FNM_PERIOD)) {
return (0);
}
if (test == '/' && flags & FNM_PATHNAME) {
break;
}
++string;
}
return (FNM_NOMATCH);
case '[':
if (*string == EOS) {
return (FNM_NOMATCH);
}
if (*string == '/' && flags & FNM_PATHNAME) {
return (FNM_NOMATCH);
}
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
return (FNM_NOMATCH);
}
if ((pattern = rangematch(pattern, *string, flags)) == NULL) {
return (FNM_NOMATCH);
}
++string;
break;
case '\\':
if (!(flags & FNM_NOESCAPE)) {
if ((c = *pattern++) == EOS) {
c = '\\';
--pattern;
}
}
/* FALLTHROUGH */
default:
if (c != *string) {
return (FNM_NOMATCH);
}
string++;
break;
}
/* NOTREACHED */
}
}
static char*
rangematch(pattern, test, flags)
char *pattern;
int test, flags;
{
int negate, ok;
char c, c2;
/*
* A bracket expression starting with an unquoted circumflex
* character produces unspecified results (IEEE 1003.2-1992,
* 3.13.2). This implementation treats it like '!', for
* consistency with the regular expression syntax.
* J.T. Conklin (conklin@ngai.kaleida.com)
*/
if ((negate = (*pattern == '!' || *pattern == '^'))) {
++pattern;
}
for (ok = 0; (c = *pattern++) != ']';) {
if (c == '\\' && !(flags & FNM_NOESCAPE)) {
c = *pattern++;
}
if (c == EOS) {
return (NULL);
}
if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS && c2 != ']') {
pattern += 2;
if (c2 == '\\' && !(flags & FNM_NOESCAPE)) {
c2 = *pattern++;
}
if (c2 == EOS) {
return (NULL);
}
if (c <= test && test <= c2) {
ok = 1;
}
}
else if (c == test) {
ok = 1;
}
}
return (ok == negate ? NULL : pattern);
}

57
missing/fnmatch.h Normal file
View file

@ -0,0 +1,57 @@
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)fnmatch.h 8.1 (Berkeley) 6/2/93
*/
/* This file has been modified by matz@netlab.co.jp */
#ifndef _FNMATCH_H_
#define _FNMATCH_H_
#ifdef __cplusplus
extern "C" {
#endif
#define FNM_NOMATCH 1 /* Match failed. */
#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
#define FNM_PERIOD 0x04 /* Period must be matched by period. */
int fnmatch();
#ifdef __cplusplus
}
#endif
#endif /* !_FNMATCH_H_ */

44
missing/isinf.c Normal file
View file

@ -0,0 +1,44 @@
#ifdef __osf__
#define _IEEE 1
#include <nan.h>
int
isinf(n)
double n;
{
if (IsNANorINF(n) && IsINF(n)) {
return 1;
} else {
return 0;
}
}
#else
#include "config.h"
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
static double zero() { return 0.0; }
static double one() { return 1.0; }
static double inf() { return one() / zero(); }
int
isinf(n)
double n;
{
static double pinf = 0.0;
static double ninf = 0.0;
if (pinf == 0.0) {
pinf = inf();
ninf = -pinf;
}
return memcmp(&n, &pinf, sizeof n) == 0
|| memcmp(&n, &ninf, sizeof n) == 0;
}
#endif

16
missing/isnan.c Normal file
View file

@ -0,0 +1,16 @@
static int double_ne();
int
isnan(n)
double n;
{
return double_ne(n, n);
}
static
int
double_ne(n1, n2)
double n1, n2;
{
return n1 != n2;
}

21
missing/memcmp.c Normal file
View file

@ -0,0 +1,21 @@
/*
* memcmp --- compare memories.
*
*/
int
memcmp(s1,s2,len)
char *s1;
char *s2;
register int len;
{
register unsigned char *a = (unsigned char*)s1;
register unsigned char *b = (unsigned char*)s2;
register int tmp;
while (len--) {
if (tmp = *a++ - *b++)
return tmp;
}
return 0;
}

111
missing/os2.c Normal file
View file

@ -0,0 +1,111 @@
#include "ruby.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <process.h>
#include <limits.h>
#include <errno.h>
#define INCL_DOS
#include <os2.h>
int
chown(char *path, int owner, int group)
{
return 0;
}
int
link(char *from, char *to)
{
return -1;
}
typedef char* CHARP;
int
do_spawn(cmd)
char *cmd;
{
register char **a;
register char *s;
char **argv;
char *shell, *sw, *cmd2;
int status;
if ((shell = getenv("RUBYSHELL")) != NULL && *shell != '\0') {
s = shell;
do
*s = isupper(*s) ? tolower(*s) : *s;
while (*++s);
if (strstr(shell, "cmd") || strstr(shell, "4os2"))
sw = "/c";
else
sw = "-c";
} else if ((shell = getenv("SHELL")) != NULL && *shell != '\0') {
s = shell;
do
*s = isupper(*s) ? tolower(*s) : *s;
while (*++s);
if (strstr(shell, "cmd") || strstr(shell, "4os2"))
sw = "/c";
else
sw = "-c";
} else if ((shell = getenv("COMSPEC")) != NULL && *shell != '\0') {
s = shell;
do
*s = isupper(*s) ? tolower(*s) : *s;
while (*++s);
if (strstr(shell, "cmd") || strstr(shell, "4os2"))
sw = "/c";
else
sw = "-c";
}
/* see if there are shell metacharacters in it */
/*SUPPRESS 530*/
/* for (s = cmd; *s && isalpha(*s); s++) ;
if (*s == '=')
goto doshell; */
for (s = cmd; *s; s++) {
if (*sw == '-' && *s != ' ' &&
!isalpha(*s) && index("$&*(){}[]'\";\\|?<>~`\n",*s)) {
if (*s == '\n' && !s[1]) {
*s = '\0';
break;
}
goto doshell;
} else if (*sw == '/' && *s != ' ' &&
!isalpha(*s) && index("^()<>|&\n",*s)) {
if (*s == '\n' && !s[1]) {
*s = '\0';
break;
}
doshell:
status = spawnlp(P_WAIT,shell,shell,sw,cmd,(char*)NULL);
return status;
}
}
argv = ALLOC_N(CHARP,(strlen(cmd) / 2 + 2));
cmd2 = ALLOC_N(char, (strlen(cmd) + 1));
strcpy(cmd2, cmd);
a = argv;
for (s = cmd2; *s;) {
while (*s && isspace(*s)) s++;
if (*s)
*(a++) = s;
while (*s && !isspace(*s)) s++;
if (*s)
*s++ = '\0';
}
*a = NULL;
if (argv[0]) {
if ((status = spawnvp(P_WAIT, argv[0], argv)) == -1) {
free(argv);
free(cmd2);
return -1;
}
}
free(cmd2);
free(argv);
return status;
}

View file

@ -1,6 +1,5 @@
#include <ctype.h>
#define min(a,b) (((a)>(b))?(b):(a))
int
strcasecmp(p1, p2)
char *p1, *p2;

45
missing/strchr.c Normal file
View file

@ -0,0 +1,45 @@
/*
* strchr --- search a string for a character
*
* We supply this routine for those systems that aren't standard yet.
*/
#include <stdio.h>
char *
strchr(str, c)
register const char *str, c;
{
if (c == '\0') {
/* thanks to Mike Brennan ... */
do {
if (*str == c)
return (char *) str;
} while (*str++);
} else {
for (; *str; str++)
if (*str == c)
return (char *) str;
}
return NULL;
}
/*
* strrchr --- find the last occurrence of a character in a string
*
* We supply this routine for those systems that aren't standard yet.
*/
char *
strrchr(str, c)
register const char *str, c;
{
register const char *save = NULL;
for (; *str; str++)
if (*str == c)
save = str;
return (char *) save;
}

View file

@ -45,6 +45,8 @@
* January 1996
*/
#include "config.h"
#ifndef GAWK
#include <stdio.h>
#include <ctype.h>
@ -92,23 +94,25 @@
#ifndef __STDC__
#define const /**/
extern void *malloc();
extern void *realloc();
extern void tzset();
extern char *strchr();
extern char *getenv();
static int weeknumber();
adddecl(static int iso8601wknum();)
#else
extern void *malloc(unsigned count);
extern void *realloc(void *ptr, unsigned count);
extern void tzset(void);
extern char *strchr(const char *str, int ch);
extern char *getenv(const char *v);
static int weeknumber(const struct tm *timeptr, int firstweekday);
adddecl(static int iso8601wknum(const struct tm *timeptr);)
#endif
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#else
extern void *malloc();
extern void *realloc();
extern char *getenv();
extern char *strchr();
#endif
#ifdef __GNUC__
#define inline __inline__
#else
@ -348,8 +352,8 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
strcpy(tbuf, ampm[1]);
break;
case 'S': /* second, 00 - 61 */
i = range(0, timeptr->tm_sec, 61);
case 'S': /* second, 00 - 60 */
i = range(0, timeptr->tm_sec, 60);
sprintf(tbuf, "%02d", i);
break;
@ -504,7 +508,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
#ifdef VMS_EXT
case 'v': /* date as dd-bbb-YYYY */
sprintf(tbuf, "%02d-%3.3s-%4d",
sprintf(tbuf, "%2d-%3.3s-%4d",
range(1, timeptr->tm_mday, 31),
months_a[range(0, timeptr->tm_mon, 11)],
timeptr->tm_year + 1900);
@ -562,7 +566,7 @@ strftime(char *s, size_t maxsize, const char *format, const struct tm *timeptr)
else
sprintf(tbuf, "%02d", y % 100);
break;
#endif ISO_DATE_EXT
#endif /* ISO_DATE_EXT */
default:
tbuf[0] = '%';
tbuf[1] = *format;
@ -826,7 +830,7 @@ static char *array[] =
"(%%M) minute (00..59) %M",
"(%%O) Locale extensions (ignored) %O",
"(%%R) time, 24-hour (%%H:%%M) %R",
"(%%S) second (00..61) %S",
"(%%S) second (00..60) %S",
"(%%T) time, 24-hour (%%H:%%M:%%S) %T",
"(%%U) week of year, Sunday as first day of week (00..53) %U",
"(%%V) week of year according to ISO 8601 %V",

18
missing/strncasecmp.c Normal file
View file

@ -0,0 +1,18 @@
#include <ctype.h>
int
strncasecmp(p1, p2, len)
char *p1;
char *p2;
int len;
{
for (; len != 0; len--, p1++, p2++) {
if (toupper(*p1) != toupper(*p2)) {
return toupper(*p1) - toupper(*p2);
}
if (*p1 == '\0') {
return 0;
}
}
return 0;
}

266
missing/strtod.c Normal file
View file

@ -0,0 +1,266 @@
/*
* strtod.c --
*
* Source code for the "strtod" library procedure.
*
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id$
*/
#include "config.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <ctype.h>
#include <errno.h>
extern int errno;
#ifndef __STDC__
# ifdef __GNUC__
# define const __const__
# else
# define const
# endif
#endif
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif
static int maxExponent = 511; /* Largest possible base 10 exponent. Any
* exponent larger than this will already
* produce underflow or overflow, so there's
* no need to worry about additional digits.
*/
static double powersOf10[] = { /* Table giving binary powers of 10. Entry */
10., /* is 10^2^i. Used to convert decimal */
100., /* exponents into floating-point numbers. */
1.0e4,
1.0e8,
1.0e16,
1.0e32,
1.0e64,
1.0e128,
1.0e256
};
/*
*----------------------------------------------------------------------
*
* strtod --
*
* This procedure converts a floating-point number from an ASCII
* decimal representation to internal double-precision format.
*
* Results:
* The return value is the double-precision floating-point
* representation of the characters in string. If endPtr isn't
* NULL, then *endPtr is filled in with the address of the
* next character after the last one that was part of the
* floating-point number.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
double
strtod(string, endPtr)
const char *string; /* A decimal ASCII floating-point number,
* optionally preceded by white space.
* Must have form "-I.FE-X", where I is the
* integer part of the mantissa, F is the
* fractional part of the mantissa, and X
* is the exponent. Either of the signs
* may be "+", "-", or omitted. Either I
* or F may be omitted, or both. The decimal
* point isn't necessary unless F is present.
* The "E" may actually be an "e". E and X
* may both be omitted (but not just one).
*/
char **endPtr; /* If non-NULL, store terminating character's
* address here. */
{
int sign, expSign = FALSE;
double fraction, dblExp, *d;
register const char *p;
register int c;
int exp = 0; /* Exponent read from "EX" field. */
int fracExp = 0; /* Exponent that derives from the fractional
* part. Under normal circumstatnces, it is
* the negative of the number of digits in F.
* However, if I is very long, the last digits
* of I get dropped (otherwise a long I with a
* large negative exponent could cause an
* unnecessary overflow on I alone). In this
* case, fracExp is incremented one for each
* dropped digit. */
int mantSize; /* Number of digits in mantissa. */
int decPt; /* Number of mantissa digits BEFORE decimal
* point. */
const char *pExp; /* Temporarily holds location of exponent
* in string. */
/*
* Strip off leading blanks and check for a sign.
*/
p = string;
while (isspace(*p)) {
p += 1;
}
if (*p == '-') {
sign = TRUE;
p += 1;
} else {
if (*p == '+') {
p += 1;
}
sign = FALSE;
}
/*
* Count the number of digits in the mantissa (including the decimal
* point), and also locate the decimal point.
*/
decPt = -1;
for (mantSize = 0; ; mantSize += 1)
{
c = *p;
if (!isdigit(c)) {
if ((c != '.') || (decPt >= 0)) {
break;
}
decPt = mantSize;
}
p += 1;
}
/*
* Now suck up the digits in the mantissa. Use two integers to
* collect 9 digits each (this is faster than using floating-point).
* If the mantissa has more than 18 digits, ignore the extras, since
* they can't affect the value anyway.
*/
pExp = p;
p -= mantSize;
if (decPt < 0) {
decPt = mantSize;
} else {
mantSize -= 1; /* One of the digits was the point. */
}
if (mantSize > 18) {
fracExp = decPt - 18;
mantSize = 18;
} else {
fracExp = decPt - mantSize;
}
if (mantSize == 0) {
fraction = 0.0;
p = string;
goto done;
} else {
int frac1, frac2;
frac1 = 0;
for ( ; mantSize > 9; mantSize -= 1)
{
c = *p;
p += 1;
if (c == '.') {
c = *p;
p += 1;
}
frac1 = 10*frac1 + (c - '0');
}
frac2 = 0;
for (; mantSize > 0; mantSize -= 1)
{
c = *p;
p += 1;
if (c == '.') {
c = *p;
p += 1;
}
frac2 = 10*frac2 + (c - '0');
}
fraction = (1.0e9 * frac1) + frac2;
}
/*
* Skim off the exponent.
*/
p = pExp;
if ((*p == 'E') || (*p == 'e')) {
p += 1;
if (*p == '-') {
expSign = TRUE;
p += 1;
} else {
if (*p == '+') {
p += 1;
}
expSign = FALSE;
}
while (isdigit(*p)) {
exp = exp * 10 + (*p - '0');
p += 1;
}
}
if (expSign) {
exp = fracExp - exp;
} else {
exp = fracExp + exp;
}
/*
* Generate a floating-point number that represents the exponent.
* Do this by processing the exponent one bit at a time to combine
* many powers of 2 of 10. Then combine the exponent with the
* fraction.
*/
if (exp < 0) {
expSign = TRUE;
exp = -exp;
} else {
expSign = FALSE;
}
if (exp > maxExponent) {
exp = maxExponent;
errno = ERANGE;
}
dblExp = 1.0;
for (d = powersOf10; exp != 0; exp >>= 1, d += 1) {
if (exp & 01) {
dblExp *= *d;
}
}
if (expSign) {
fraction /= dblExp;
} else {
fraction *= dblExp;
}
done:
if (endPtr != NULL) {
*endPtr = (char *) p;
}
if (sign) {
return -fraction;
}
return fraction;
}

1128
missing/vsnprintf.c Normal file

File diff suppressed because it is too large Load diff