os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/strtoull.c
Update contrib.
4 * Source code for the "strtoull" library procedure.
6 * Copyright (c) 1988 The Regents of the University of California.
7 * Copyright (c) 1994 Sun Microsystems, Inc.
9 * See the file "license.terms" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 * RCS: @(#) $Id: strtoull.c,v 1.5 2002/02/24 02:53:25 dgp Exp $
20 * The table below is used to convert from ASCII digits to a
21 * numerical equivalent. It maps from '0' through 'z' to integers
22 * (100 for non-digit characters).
25 static char cvtIn[] = {
26 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* '0' - '9' */
27 100, 100, 100, 100, 100, 100, 100, /* punctuation */
28 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 'A' - 'Z' */
29 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30 30, 31, 32, 33, 34, 35,
31 100, 100, 100, 100, 100, 100, /* punctuation */
32 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 'a' - 'z' */
33 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
34 30, 31, 32, 33, 34, 35};
38 *----------------------------------------------------------------------
42 * Convert an ASCII string into an integer.
45 * The return value is the integer equivalent of string. If endPtr
46 * is non-NULL, then *endPtr is filled in with the character
47 * after the last one that was part of the integer. If string
48 * doesn't contain a valid integer value, then zero is returned
49 * and *endPtr is set to string.
54 *----------------------------------------------------------------------
57 #if TCL_WIDE_INT_IS_LONG
62 strtoull(string, endPtr, base)
63 CONST char *string; /* String of ASCII digits, possibly
64 * preceded by white space. For bases
65 * greater than 10, either lower- or
66 * upper-case digits may be used.
68 char **endPtr; /* Where to store address of terminating
69 * character, or NULL. */
70 int base; /* Base for conversion. Must be less
71 * than 37. If 0, then the base is chosen
72 * from the leading characters of string:
73 * "0x" means hex, "0" means octal, anything
77 register CONST char *p;
78 register Tcl_WideUInt result = 0;
79 register unsigned digit;
80 register Tcl_WideUInt shifted;
81 int anyDigits = 0, negative = 0;
84 * Skip any leading blanks.
88 while (isspace(UCHAR(*p))) { /* INTL: locale-dependent */
106 * If no base was provided, pick one from the leading characters
113 if (*p == 'x' || *p == 'X') {
119 * Must set anyDigits here, otherwise "0" produces a
129 } else if (base == 16) {
132 * Skip a leading "0x" from hex numbers.
135 if ((p[0] == '0') && (p[1] == 'x' || *p == 'X')) {
141 * Sorry this code is so messy, but speed seems important. Do
142 * different things for base 8, 10, 16, and other.
151 shifted = result << 3;
152 if ((shifted >> 3) != result) {
155 result = shifted + digit;
156 if ( result < shifted ) {
161 } else if (base == 10) {
167 shifted = 10 * result;
168 if ((shifted / 10) != result) {
171 result = shifted + digit;
172 if ( result < shifted ) {
177 } else if (base == 16) {
180 if (digit > ('z' - '0')) {
183 digit = cvtIn[digit];
187 shifted = result << 4;
188 if ((shifted >> 4) != result) {
191 result = shifted + digit;
192 if ( result < shifted ) {
197 } else if ( base >= 2 && base <= 36 ) {
200 if (digit > ('z' - '0')) {
203 digit = cvtIn[digit];
204 if (digit >= (unsigned) base) {
207 shifted = result * base;
208 if ((shifted/base) != result) {
211 result = shifted + digit;
212 if ( result < shifted ) {
220 * Negate if we found a '-' earlier.
224 result = (Tcl_WideUInt)(-((Tcl_WideInt)result));
228 * See if there were any digits at all.
236 *endPtr = (char *) p;
242 * On overflow generate the right output
250 if (digit > ('z' - '0')) {
253 digit = cvtIn[digit];
254 if (digit >= (unsigned) base) {
258 *endPtr = (char *) p;
260 return (Tcl_WideUInt)Tcl_LongAsWide(-1);