[Getdata-commits] SF.net SVN: getdata:[740] trunk/getdata
Scientific Database Format
Brought to you by:
ketiltrout
|
From: <ket...@us...> - 2012-07-10 18:01:27
|
Revision: 740
http://getdata.svn.sourceforge.net/getdata/?rev=740&view=rev
Author: ketiltrout
Date: 2012-07-10 18:01:15 +0000 (Tue, 10 Jul 2012)
Log Message:
-----------
Improve posixiness of gd_strtod; fix pointer arithmetic in symlink negotiation.
Modified Paths:
--------------
trunk/getdata/ChangeLog
trunk/getdata/src/common.c
trunk/getdata/src/compat.c
trunk/getdata/test/Makefile.am
Modified: trunk/getdata/ChangeLog
===================================================================
--- trunk/getdata/ChangeLog 2012-07-05 01:59:30 UTC (rev 739)
+++ trunk/getdata/ChangeLog 2012-07-10 18:01:15 UTC (rev 740)
@@ -1,3 +1,9 @@
+2012-07-10 D. V. Wiebe <ge...@ke...> svn:740
+ * src/common.c (_GD_CanonicalPath): Fix pointer arithmetic
+
+ * src/compat.c (gd_strtod): Drop octal (not in POSIX); handle hex floating
+ point; don't zero errno.
+
2012-07-04 D. V. Wiebe <ge...@ke...> svn:737
GetData-0.8.0 released.
Modified: trunk/getdata/src/common.c
===================================================================
--- trunk/getdata/src/common.c 2012-07-05 01:59:30 UTC (rev 739)
+++ trunk/getdata/src/common.c 2012-07-10 18:01:15 UTC (rev 740)
@@ -1191,7 +1191,7 @@
for (rptr = res + res_len - 1; *rptr != GD_DIRSEP; --rptr)
;
*(rptr + 1) = '\0';
- res_len = res - rptr + 1;
+ res_len = (rptr - res) + 1;
}
/* now make a new work buffer of "target/remaining", asusming
Modified: trunk/getdata/src/compat.c
===================================================================
--- trunk/getdata/src/compat.c 2012-07-05 01:59:30 UTC (rev 739)
+++ trunk/getdata/src/compat.c 2012-07-10 18:01:15 UTC (rev 740)
@@ -328,17 +328,13 @@
double gd_strtod(const char *nptr, char **endptr)
{
const char *ptr = nptr;
- double r;
- long int li;
+ double r = 0;
int sign = 0;
dtrace("\"%s\", %p", nptr, endptr);
/* the basic problem here is that MSVCRT's strtod() doesn't properly covert
- * octal or hexadecimal numbers, nor does it do the special values "INF" and
- * "NAN. So, we have to check for those first. For the first two, we then
- * run it through strtol instead (which does do octal and hex fine in the
- * MSVCRT) and then cast back to double. For the other two we're on our own.
+ * hexadecimal numbers, nor does it do the special values "INF" and "NAN".
*/
/* skip sign */
@@ -348,23 +344,47 @@
ptr++;
}
- /* check for octal "0[0-7]..." or hex ("0[Xx][0-9A-Fa-f]...") */
- if (*ptr == '0') {
- switch (*(ptr + 1)) {
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case 'x':
- case 'X':
- li = strtol(nptr, endptr, 0);
- dreturn("%li", li);
- return (double)li;
+ /* check for hex, either integer or floating point */
+ if (*ptr == '0' && (*(ptr + 1) | 0x20) == 'x') {
+ double fact = 1.;
+ /* we store the mantissa in r */
+ for (ptr += 2; *ptr; ++ptr) {
+ if ((*ptr >= '0' && *ptr <= '9') ||
+ ((*ptr | 0x20) >= 'a' && (*ptr | 0x20) <= 'f'))
+ {
+ if (fact == 1.)
+ r *= 16;
+ else if (fact == 0.)
+ fact = 1./16;
+ else
+ fact /= 16;
+
+ if (*ptr >= '0' && *ptr <= '9')
+ r += fact * (*ptr - '0');
+ else
+ r += fact * ((*ptr | 0x20) - 'a' + 10);
+ } else if (*ptr == '.' && fact == 1.)
+ fact = 0.;
+ else if ((*ptr | 0x20) == 'p') {
+ /* use strtol to get exponent, which is in decimal */
+ long exp = strtol(ptr + 1, endptr, 10);
+ r *= pow(2., exp);
+
+ /* to avoid setting it again */
+ endptr = NULL;
+ break;
+ } else
+ break;
}
+
+ if (endptr)
+ *endptr = (char*)ptr;
+
+ if (sign)
+ r = -r;
+
+ dreturn("%g (%c)", r, endptr ? **endptr : '-');
+ return r;
} else if ((*ptr | 0x20) == 'n') {
if (((*(ptr + 1) | 0x20) == 'a') && ((*(ptr + 2) | 0x20) == 'n')) {
/* an IEEE-754 double-precision quiet NaN:
@@ -384,12 +404,12 @@
} nan_punning = {{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }};
if (endptr) {
- *endptr = ptr += 3;
+ *endptr = (char*)(ptr += 3);
/* a NaN may end with something in parentheses */
if (*ptr == '(') {
while (*++ptr) {
if (*ptr == ')') {
- *endptr = ptr + 1;
+ *endptr = (char*)(ptr + 1);
break;
}
}
@@ -398,7 +418,6 @@
/* return NaN */
dreturn("%g (%c)", nan_punning.d, endptr ? **endptr : '-');
- errno = 0;
return nan_punning.d;
}
} else if ((*ptr | 0x20) == 'i') {
@@ -424,7 +443,7 @@
}};
if (endptr) {
- *endptr = ptr += 3;
+ *endptr = (char*)(ptr += 3);
/* INF may also be INFINITY, disregarding case */
if (
((*ptr | 0x20) == 'i') &&
@@ -439,7 +458,6 @@
/* return signed infinity */
dreturn("%g (%c)", inf_punning.d, endptr ? **endptr : '-');
- errno = 0;
return inf_punning.d;
}
}
Modified: trunk/getdata/test/Makefile.am
===================================================================
--- trunk/getdata/test/Makefile.am 2012-07-05 01:59:30 UTC (rev 739)
+++ trunk/getdata/test/Makefile.am 2012-07-10 18:01:15 UTC (rev 740)
@@ -146,7 +146,7 @@
entry_mplex entry_mplex_scalar entry_multiply entry_phase \
entry_phase_scalar entry_polynom entry_polynom_scalar entry_raw \
entry_raw_scalar entry_raw_scalar_code entry_raw_scalar_type \
- entry_recip entry_scalar_repr entry_type entry_type_alias \
+ entry_scalar_repr entry_recip entry_type entry_type_alias \
entry_window entry_window_scalar
EOF_TESTS=eof eof_index eof_lincom eof_phase
@@ -250,11 +250,12 @@
parse_alias_missing parse_badline parse_bit parse_bit4 \
parse_bit_bitnum parse_bit_bitsize parse_bit_ncols \
parse_bit_numbits parse_bit_scalar parse_carray parse_carray_long \
- parse_const parse_const_ncols parse_divide parse_duplicate \
- parse_duplicate_ignore parse_endian_bad parse_endian_big \
- parse_endian_force parse_endian_little parse_endian_slash \
- parse_eol parse_foffs parse_foffs_include parse_foffs_slash \
- parse_hidden parse_hidden_field parse_hidden_meta parse_include \
+ parse_const parse_const_complex parse_const_ncols parse_divide \
+ parse_double parse_duplicate parse_duplicate_ignore \
+ parse_endian_bad parse_endian_big parse_endian_force \
+ parse_endian_little parse_endian_slash parse_eol parse_foffs \
+ parse_foffs_include parse_foffs_slash parse_hidden \
+ parse_hidden_field parse_hidden_meta parse_include \
parse_include_absolute parse_include_absrel parse_include_loop \
parse_include_nonexistent parse_include_prefix \
parse_include_prefix_dup parse_include_preprefix \
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|