#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'stdlib/strtod.c' <<'END_OF_FILE' X/* X * $Id: strtod.c,v 1.2 1992/05/22 17:59:16 thor Exp thor $ X * X * Module: strtod.c X * Original Author: Richard E. K. Neitzel X * Copywrited by the National Center for Atmospheric Research X * Date: $Date: 1992/05/22 17:59:16 $ X * X * revision history X * ---------------- X * $Log: strtod.c,v $ X * Revision 1.2 1992/05/22 17:59:16 thor X * Cosmetic changes. X * X * Revision 1.1 1992/05/22 16:34:34 thor X * Initial revision X * X * X * description: X * Convert a string to a double. If endptr is not null return X * the pointer to the character after the last converted character. X */ Xstatic char rcsid[] = "$Date: 1992/05/22 17:59:16 $ $RCSfile: strtod.c,v $ $Revision: 1.2 $"; X X#include "vxWorks.h" X#include "errno.h" X#include "ctype.h" X#include "stdlib.h" X#include "string.h" X#include "math.h" X#include "float.h" X Xdouble strtod(const char *ptr, char **endptr) X{ X FAST const char *s; X FAST short sign; X FAST unsigned char decimal = '.'; /* Decimal point. */ X double number; X int gotDecimal; /* Found a decimal point. */ X int foundDigit; /* Seen any digits. */ X long exponent; /* The exponent. */ X X if (ptr == NULL) /* What! */ X { X errno = EINVAL; X goto badconv; X } X X s = ptr; X X while (isspace(*s)) /* Eat whitespace. */ X s++; X X sign = *s == '-' ? -1 : 1; X X if (*s == '-' || *s == '+') X s++; X X number = 0.0; X gotDecimal = 0; X foundDigit = 0; X exponent = 0; X X for (;; s++) X { X if (isdigit (*s)) X { X foundDigit = 1; X X /* Make sure multiplication will not overflow. */ X if (number > DBL_MAX * 0.1) X exponent++; X else X number = (number * 10.0) + (*s - '0'); X X if (gotDecimal) X --exponent; X } X else if (!gotDecimal && (unsigned char)*s == decimal) X gotDecimal = 1; /* Found decimal point. */ X else X break; /* Done. */ X } X X if (!foundDigit) X goto badconv; X X if (tolower(*s) == 'e') X { X /* Get the exponent. */ X int save = errno; X char *end; X long exp; X X errno = 0; X s++; X X exp = strtol(s,&end,10); X X if (errno == ERANGE) /* The exponent overflowed. */ X { X if (endptr != NULL) X *endptr = end; X if (exp < 0) X goto underflow; X else X goto overflow; X } X else if (end == s) /* No exponent. */ X end = (char *)s - 1; X errno = save; X s = end; X exponent += exp; X } X X if (endptr != NULL) X *endptr = (char *)s; X X if (number == 0.0) X return 0.0; X X /* Multiply number by 10 to exponent, check for over/underflow. */ X if (exponent < 0) X { X if (number < DBL_MIN * pow(10.0,(double)-exponent)) X goto underflow; X } X else if (exponent > 0) X { X if (number > DBL_MAX * pow(10.0,(double)-exponent)) X goto overflow; X } X X number *= pow(10.0,(double)exponent); X X return(number * sign); X X overflow: X number = HUGE_VAL * sign; X if (endptr != NULL) X *endptr = (char *)ptr; X errno = ERANGE; X return(number); X X underflow: X errno = ERANGE; X X badconv: X if (endptr != NULL) X *endptr = (char *)ptr; X return(0.0); X} END_OF_FILE if test 3142 -ne `wc -c <'stdlib/strtod.c'`; then echo shar: \"'stdlib/strtod.c'\" unpacked with wrong size! fi # end of 'stdlib/strtod.c' fi if test -f 'stdlib/strtol.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'stdlib/strtol.c'\" else echo shar: Extracting \"'stdlib/strtol.c'\" \(3079 characters\) sed "s/^X//" >'stdlib/strtol.c' <<'END_OF_FILE' X/* X * $Id: strtol.c,v 1.2 1992/05/22 17:59:03 thor Exp thor $ X * X * Module: strtol.c X * Original Author: Richard E. K. Neitzel X * Copywrited by the National Center for Atmospheric Research X * Date: $Date: 1992/05/22 17:59:03 $ X * X * revision history X * ---------------- X * $Log: strtol.c,v $ X * Revision 1.2 1992/05/22 17:59:03 thor X * Cosmetic changes. X * X * Revision 1.1 1992/05/22 16:34:35 thor X * Initial revision X * X * X * description: X * Convert a string to a long. If endptr is not null return X * the pointer to the character after the last converted character. X */ Xstatic char rcsid[] = "$Date: 1992/05/22 17:59:03 $ $RCSfile: strtol.c,v $ $Revision: 1.2 $"; X X#include "vxWorks.h" X#include "ctype.h" X#include "limits.h" X#include "stddef.h" X#include "stdlib.h" X#include "errno.h" X X#ifndef STRTOUL Xlong strtol(const char *ptr, char **endptr, int base) X#else Xunsigned long strtoul (const char *ptr, char **endptr, int base) X#endif X{ X FAST char sign; X FAST unsigned long maxulong; X FAST unsigned long limit; X FAST unsigned long i; X FAST const char *s; X FAST unsigned long c; X FAST const char *save; X FAST int overflow; X X if (base < 0 || base == 1 || base > 36) X base = 10; X X s = ptr; X X while (isspace(*s)) /* Eat white space. */ X s++; X X if (*s == '\0') X goto badconv; X X if (*s == '-') X { X sign = -1; X ++s; X } X else if (*s == '+') X { X sign = 1; X ++s; X } X else X sign = 1; X X if (base == 16 && *s == '0' && tolower(s[1]) == 'x') X s += 2; /* Skip nonnumeric characters. */ X X /* If base isn't given, decide what it is. */ X if (base == 0) X if (*s == '0') X { X if (tolower(s[1]) == 'x') X { X s += 2; X base = 16; X } X else X base = 8; X } X else X base = 10; X X save = s; /* Save to check if we really do anything. */ X X maxulong = ULONG_MAX / (unsigned long)base; X limit = ULONG_MAX % (unsigned long)base; X X overflow = 0; X i = 0; X X for (c = (unsigned long)*s; c != 0; c = (unsigned long)*++s) X { X if (isdigit(c)) X c -= '0'; X else if (isalpha(c)) X c = toupper(c) - 'A' + 10; X else X break; X if (c >= base) X break; X if (i > maxulong || (i == maxulong && c > limit)) /* Check for */ X /* overflow. */ X overflow = 1; X else X { X i *= (unsigned long)base; X i += c; X } X } X X if (s == save) /* Did we really find a number? */ X goto badconv; X X if (endptr != NULL) X *endptr = (char *)s; X X#ifndef STRTOUL X /* Check for a value that is in the range of unsigned, but out of */ X /* the range of long. */ X if (i > (unsigned long)(sign > 0 ? LONG_MAX : - LONG_MAX)) X overflow = 1; X#endif X X if (overflow) X { X errno = ERANGE; X#ifdef STRTOUL X return(ULONG_MAX); X#else X return(sign > 0 ? LONG_MAX : LONG_MIN); X#endif X } X X return(i * sign); X X badconv: X if (endptr != NULL) X *endptr = (char *)ptr; X X return(0); X} END_OF_FILE if test 3079 -ne `wc -c <'stdlib/strtol.c'`; then echo shar: \"'stdlib/strtol.c'\" unpacked with wrong size! fi # end of 'stdlib/strtol.c' fi if test -f 'string/memchr.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'string/memchr.c'\" else echo shar: Extracting \"'string/memchr.c'\" \(2466 characters\) sed "s/^X//" >'string/memchr.c' <<'END_OF_FILE' X/* X * $Id: memchr.c,v 1.1 1992/05/21 19:00:18 thor Exp thor $ X * X * Module: memchr.c X * Original Author: Richard E. K. Neitzel X * Copywrited by the National Center for Atmospheric Research X * Date: $Date: 1992/05/21 19:00:18 $ X * X * revision history X * ---------------- X * $Log: memchr.c,v $ X * Revision 1.1 1992/05/21 19:00:18 thor X * Initial revision X * X * X * description: X * Find the first byte matching the pattern in the lower 8 bits X * of c. If found return a pointer to that location, else return NULL. X * X */ Xstatic char rcsid[] = "$Date: 1992/05/21 19:00:18 $ $RCSfile: memchr.c,v $ $Revision: 1.1 $"; X X#include "vxWorks.h" X#include "string.h" X Xvoid *memchr(FAST const void *s, FAST int c, FAST size_t n) X{ X if (n) /* Why bother? */ X { X if (n < sizeof(long) * 5) X { X FAST unsigned char *ptr = (unsigned char *)s; X X do X { X if (*ptr == (unsigned char)c) X return(ptr); X ptr++; X } while (--n); X } X else X { X FAST long i; X FAST long j; X FAST int rump; X FAST long *ptr = (long *)s; X X i = (long)ptr & 3; /* Align on longword. */ X X if (i) X { X FAST unsigned char *cptr = (unsigned char *)ptr; X X n -= i; X X do X { X if (*cptr == (unsigned char)c) X return(cptr); X cptr++; X } while (--i); X X ptr = (long *)cptr; X } X X i = c & 0xff; /* Make a big pattern. */ X X j = i; X X i <<= 8; X j |= i; X i <<= 8; X j |= i; X i <<= 8; X j |= i; X X i = j & 0xff; X X rump = n & 3; /* Odd bytes? */ X X n /= sizeof(long); X X while (n) X { X FAST long l = *ptr & j; X X /* If we had a hit we might have a match. We */ X /* test for this by walking through the */ X /* currently selected address. */ X if (l) X { X FAST unsigned char *cptr = (unsigned char *)ptr; X X if (*cptr == (unsigned char)i) X return(cptr); X X cptr++; X X if (*cptr == (unsigned char)i) X return(cptr); X X cptr++; X X if (*cptr == (unsigned char)i) X return(cptr); X X cptr++; X X if (*cptr == (unsigned char)i) X return(cptr); X } X ptr++; X --n; X } X X if (rump) /* Odd bytes? */ X { X FAST unsigned char *cptr = (unsigned char *)ptr; X X do X { X if (*cptr == (unsigned char)j) X return(cptr); X cptr++; X } while (--rump); X } X } X } X return(NULL); /* Failed. */ X} X X X X END_OF_FILE if test 2466 -ne `wc -c <'string/memchr.c'`; then echo shar: \"'string/memchr.c'\" unpacked with wrong size! fi # end of 'string/memchr.c' fi if test -f 'string/memcmp.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'string/memcmp.c'\" else echo shar: Extracting \"'string/memcmp.c'\" \(2446 characters\) sed "s/^X//" >'string/memcmp.c' <<'END_OF_FILE' X/* X * $Id: memcmp.c,v 1.2 1992/06/12 19:19:22 thor Exp thor $ X * X * Module: memcmp.c X * Original Author: Richard E. K. Neitzel X * Copywrited by the National Center for Atmospheric Research X * Date: $Date: 1992/06/12 19:19:22 $ X * X * revision history X * ---------------- X * $Log: memcmp.c,v $ X * Revision 1.2 1992/06/12 19:19:22 thor X * Removed USE_ANSI & added new workaround for gcc 2.* whining on types. X * X * Revision 1.1 1992/05/21 19:00:20 thor X * Initial revision X * X * X * description: X * Compare to areas of memory for n bytes. Return 0 if they are X * are equal, 1 if s1 is greater then s2 and -1 if s2 is greater then X * s1. X * X */ Xstatic char rcsid[] = "$Date: 1992/06/12 19:19:22 $ $RCSfile: memcmp.c,v $ $Revision: 1.2 $"; X X#include "vxWorks.h" X#include "string.h" X X#ifndef SIZET X#ifdef __GNUC__ X#define SIZET int X#else X#define SIZET size_t X#endif X#endif X Xint memcmp (FAST const void *s1, FAST const void *s2, FAST SIZET n) X{ X if (s1 == s2) /* Trivial. */ X return(0); X X if (n < sizeof(long) * 5) X { X FAST unsigned char *p1 = (unsigned char *)s1; X FAST unsigned char *p2 = (unsigned char *)s2; X X for (; n; --n, p1++, p2++) X { X if (*p1 > *p2) X return(1); X else if (*p1 < *p2) X return(-1); X } X } X else X { X FAST long *p1 = (long *)s1; X FAST long *p2 = (long *)s2; X FAST long i = (long)p1 & 3; /* Align on longword. */ X X if (i) X { X FAST unsigned char *c1 = (unsigned char *)p1; X FAST unsigned char *c2 = (unsigned char *)p2; X X n -= i; X X do X { X if (*c1 > *c2) X return(1); X else if (*c1 < *c2) X return(-1); X X c1++; X c2++; X } while (--i); X p1 = (long *)c1; X p2 = (long *)c2; X } X X i = n & 3; /* Odd bytes? */ X X n /= sizeof(long); X X while (n) X { X if (*p1 != *p2) X { X FAST unsigned char *c1 = (unsigned char *)p1; X FAST unsigned char *c2 = (unsigned char *)p2; X FAST int j = 4; X X do X { X if (*c1 > *c2) X return(1); X else if (*c1 < *c2) X return(-1); X X c1++; X c2++; X } while (--j); X X } X --n; X p1++; X p2++; X } X X if (i) /* Do odd bytes. */ X { X FAST unsigned char *c1 = (unsigned char *)p1; X FAST unsigned char *c2 = (unsigned char *)p2; X X do X { X if (*c1 > *c2) X return(1); X else if (*c1 < *c2) X return(-1); X X c1++; X c2++; X } while (--i); X } X } X return(0); X} END_OF_FILE if test 2446 -ne `wc -c <'string/memcmp.c'`; then echo shar: \"'string/memcmp.c'\" unpacked with wrong size! fi # end of 'string/memcmp.c' fi if test -f 'string/memcpy.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'string/memcpy.c'\" else echo shar: Extracting \"'string/memcpy.c'\" \(4048 characters\) sed "s/^X//" >'string/memcpy.c' <<'END_OF_FILE' X/* X * $Id: memcpy.c,v 1.2 1992/06/12 19:20:24 thor Exp thor $ X * X * Module: memcpy.c X * Original Author: Richard E. K. Neitzel X * Copywrited by the National Center for Atmospheric Research X * Date: $Date: 1992/06/12 19:20:24 $ X * X * revision history X * ---------------- X * $Log: memcpy.c,v $ X * Revision 1.2 1992/06/12 19:20:24 thor X * Removed USE_ANSI & added code to stop gcc whinging. X * X * Revision 1.1 1992/05/21 19:00:25 thor X * Initial revision X * X * X * description: X * Move data from s2 to s1 without clobbering anything if there X * is any overlap. X * X */ Xstatic char rcsid[] = "$Date: 1992/06/12 19:20:24 $ $RCSfile: memcpy.c,v $ $Revision: 1.2 $"; X X#include "vxWorks.h" X#include "string.h" X X#ifndef SIZET X#ifdef __GNUC__ X#define SIZET int X#else X#define SIZET size_t X#endif X#endif X Xvoid *memcpy(FAST void *s1, FAST const void *s2, FAST SIZET n) X{ X FAST unsigned long i1 = (unsigned long)s1; X FAST unsigned long i2 = (unsigned long)(s2 + n); /* Point end of area. */ X FAST void *save = s1; X X if (i2 > i1) /* Overlapping areas. */ X { X i1 += n; /* Point other's tail end. */ X X if (n <= sizeof(long) * 5) X { X FAST unsigned char *c1 = (unsigned char *)i1; X FAST unsigned char *c2 = (unsigned char *)i2; X X while (n) X { X *c1-- = *c2--; X --n; X } X return(save); X } X else X { X FAST long i; X FAST long *l1 = (long *)i1; X FAST long *l2 = (long *)i2; X X i = (long)s2 & 3; /* Align on longword. */ X X if (i) X { X FAST unsigned char *c1 = (unsigned char *)s1; X FAST unsigned char *c2 = (unsigned char *)s2; X X n -= i; X X do X { X *c1-- = *c2--; X } while (--i); X X l1 = (long *)c1; X l2 = (long *)c2; X } X X i = n & (sizeof(long) - 1); /* Any odd bytes? */ X X n /= sizeof(long); X#ifndef mc68040 X while (n > 10) X { X *l1-- = *l2--; X *l1-- = *l2--; X *l1-- = *l2--; X *l1-- = *l2--; X *l1-- = *l2--; X *l1-- = *l2--; X *l1-- = *l2--; X *l1-- = *l2--; X *l1-- = *l2--; X *l1-- = *l2--; X n -= 10; X } X X#else /* Use move16 to speed things up. */ X while (n > 16) X { X asm volatile("move16 %1,%0" : "=r" (l1) : "r" (l2)); X l1 -= 16; X l2 -= 16; X n -= 16; X } X X#endif /* mc68040 */ X while (n) X { X *l1-- = *l2--; X --n; X } X X if (i) /* Finish odd bytes. */ X { X FAST unsigned char *c1 = (unsigned char *)l1; X FAST unsigned char *c2 = (unsigned char *)l2; X X do X { X *c1-- = *c2--; X } while (--i); X } X } X } X else /* No overlap. */ X { X if (n <= sizeof(long) * 2) X { X FAST unsigned char *c1 = (unsigned char *)s1; X FAST unsigned char *c2 = (unsigned char *)s2; X X while (n) X { X *c1++ = *c2++; X --n; X } X return(save); X } X else X { X FAST long i; X FAST long *l1 = (long *)s1; X FAST long *l2 = (long *)s2; X X i = (long)l2 & 3; /* align on longword. */ X X if (i) X { X FAST unsigned char *c1 = (unsigned char *)l1; X FAST unsigned char *c2 = (unsigned char *)l2; X X n -= i; X X do X { X *c1++ = *c2++; X } while (--i); X X l1 = (long *)c1; X l2 = (long *)c2; X } X X i = n & (sizeof(long) - 1); /* Odd bytes? */ X X n /= sizeof(long); X X#ifndef mc68040 X while (n > 10) X { X *l1++ = *l2++; X *l1++ = *l2++; X *l1++ = *l2++; X *l1++ = *l2++; X *l1++ = *l2++; X *l1++ = *l2++; X *l1++ = *l2++; X *l1++ = *l2++; X *l1++ = *l2++; X *l1++ = *l2++; X n -= 10; X } X X#else X while (n > 16) X { X asm volatile("move16 %1,%0" : "=r" (l1) : "r" (l2)); X l1 -= 16; X l2 -= 16; X n -= 16; X } X X#endif /* mc68040 */ X while (n) X { X *l1++ = *l2++; X --n; X } X X if (i) /* Finish odd bytes. */ X { X FAST unsigned char *c1 = (unsigned char *)l1; X FAST unsigned char *c2 = (unsigned char *)l2; X X do X { X *c1++ = *c2++; X } while (--i); X } X } X } X return(save); X} END_OF_FILE if test 4048 -ne `wc -c <'string/memcpy.c'`; then echo shar: \"'string/memcpy.c'\" unpacked with wrong size! fi # end of 'string/memcpy.c' fi echo shar: End of archive 2 \(of 2\). cp /dev/null ark2isdone MISSING="" for I in 1 2 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked both archives. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0