[R-gregmisc-users] SF.net SVN: r-gregmisc: [1204] trunk/SASxport/src
Brought to you by:
warnes
From: <wa...@us...> - 2007-11-01 06:15:17
|
Revision: 1204 http://r-gregmisc.svn.sourceforge.net/r-gregmisc/?rev=1204&view=rev Author: warnes Date: 2007-10-31 23:15:13 -0700 (Wed, 31 Oct 2007) Log Message: ----------- Copy code from foreign for lookup.xport() and read.xport(), extend lookup.xport() to show information about SAS format and iformat Modified Paths: -------------- trunk/SASxport/src/ieee2ibm.c trunk/SASxport/src/init.c Added Paths: ----------- trunk/SASxport/src/swap_bytes.h Modified: trunk/SASxport/src/ieee2ibm.c =================================================================== --- trunk/SASxport/src/ieee2ibm.c 2007-11-01 06:14:22 UTC (rev 1203) +++ trunk/SASxport/src/ieee2ibm.c 2007-11-01 06:15:13 UTC (rev 1204) @@ -43,6 +43,9 @@ void ieee2ibm(register unsigned char *out, register const unsigned char *in, int count) { + static char numeric_NA[8] = {0x2e,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + /* * IBM Format. * 7-bit exponent, base 16. @@ -61,7 +64,7 @@ signbit = (left & 0x80000000) >> 24; if( exp == 0 || exp == 0x7FF ) { -ibm_undef: *out++ = 0; /* IBM zero. No NAN */ + *out++ = 0; /* IBM zero. No NAN */ *out++ = 0; *out++ = 0; *out++ = 0; @@ -79,9 +82,10 @@ exp /= 4; /* excess 32, base 16 */ exp += (64-32+1); /* excess 64, base 16, plus fudge */ if( (exp & ~0xFF) != 0 ) { - //WARNING("ntohd: IBM exponent overflow"); - fprintf(stderr,"ntohd: IBM exponent overflow\n"); - goto ibm_undef; + warning("IBM exponent overflow, generating NA\n"); + memcpy(out, numeric_NA, 8); + out+= 8; + continue; } if( fix ) { Modified: trunk/SASxport/src/init.c =================================================================== --- trunk/SASxport/src/init.c 2007-11-01 06:14:22 UTC (rev 1203) +++ trunk/SASxport/src/init.c 2007-11-01 06:15:13 UTC (rev 1204) @@ -55,9 +55,14 @@ { NULL, NULL, 0} }; +SEXP xport_info(SEXP xportFile); +SEXP xport_read(SEXP xportFile, SEXP xportInfo); + #define CALLDEF(name, n) {#name, (DL_FUNC) &name, n} static const R_CallMethodDef CallEntries[] = { - CALLDEF(getRawBuffer, 0), + CALLDEF(getRawBuffer, 0), + CALLDEF(xport_info, 1), + CALLDEF(xport_read, 2), {NULL, NULL, 0} }; Added: trunk/SASxport/src/swap_bytes.h =================================================================== --- trunk/SASxport/src/swap_bytes.h (rev 0) +++ trunk/SASxport/src/swap_bytes.h 2007-11-01 06:15:13 UTC (rev 1204) @@ -0,0 +1,172 @@ +/* src/swap_bytes.h. Generated by configure. */ +/* + * + * Reverse bytes in 2, 4 and 8 byte objects + * + * Copyright 2000-2000 Saikat DebRoy <sa...@st...> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, a copy is available at + * http://www.r-project.org/Licenses/ + */ + +#ifndef SWAP_BYTES_H +#define SWAP_BYTES_H + +/* #undef HAVE_GLIBC_BSWAP */ + +#ifdef HAVE_GLIBC_BSWAP /* use gnu bswap macros */ + +#include <byteswap.h> + +#define swap_bytes_16(from, to) do { (to) = bswap_16(from); } while (0) + +#define swap_bytes_32(from, to) do { (to) = bswap_32(from); } while (0) + +#if defined __GNUC__ && __GNUC__ >= 2 + +#define swap_bytes_double(from, to) \ +do { \ + union { \ + unsigned long long int u64; \ + double d; \ + } __from, __to; \ + __from.d = (from); \ + __to.u64 = bswap_64(__from.u64); \ + (to) = __to.d; \ +} while (0) + +#else + +#define swap_bytes_double(from, to) \ +do { \ + union { \ + unsigned int u32[2]; \ + double d; \ + } __from, __to; \ + __from.d = (from); \ + swap_bytes_32(__from.u32[1], __to.u32[0]); \ + swap_bytes_32(__from.u32[0], __to.u32[1]); \ + (to) = __to.d; \ +} while (0) + +#endif + +#else /* use reasonable portable definitions */ + +#define swap_bytes_16(from, to) \ +do { \ + unsigned short __from16 = (from); \ + (to) = ((((__from16) >> 8) & 0xff) | (((__from16) & 0xff) << 8)); \ +} while (0) + +#define swap_bytes_32(from, to) \ +do { \ + unsigned int __from32 = (from); \ + (to) = (((__from32 & 0xff000000) >> 24) | \ + ((__from32 & 0x00ff0000) >> 8) | \ + ((__from32 & 0x0000ff00) << 8) | \ + ((__from32 & 0x000000ff) << 24)); \ +} while (0) + +#define swap_bytes_double(from, to) \ +do { \ + union { \ + unsigned int u32[2]; \ + double d; \ + } __from, __to; \ + __from.d = (from); \ + swap_bytes_32(__from.u32[1], __to.u32[0]); \ + swap_bytes_32(__from.u32[0], __to.u32[1]); \ + (to) = __to.d; \ +} while (0) +#endif /* HAVE_GLIBC_BSWAP */ + +#define swap_bytes_ushort(from, to) swap_bytes_16(from, to) + +#define reverse_ushort(x) swap_bytes_16(x, x) + +#define swap_bytes_short(from, to) \ +do { \ + union { \ + unsigned short u16; \ + short s16; \ + } __from, __to; \ + __from.s16 = (from); \ + swap_bytes_16(__from.u16, __to.u16); \ + (to) = __to.s16; \ +} while (0) + +#define reverse_short(x) \ +do { \ + union { \ + unsigned short u16; \ + short s16; \ + } __from, __to; \ + __from.s16 = (x); \ + swap_bytes_16(__from.u16, __to.u16); \ + (x) = __to.s16; \ +} while(0) + +#define swap_bytes_uint(from, to) swap_bytes_32(from, to) + +#define reverse_uint(x) swap_bytes_32(x, x) + +#define swap_bytes_int(from, to) \ +do { \ + union { \ + unsigned int u32; \ + int s32; \ + } __from, __to; \ + __from.s32 = (from); \ + swap_bytes_32(__from.u32, __to.u32); \ + (to) = __to.s32; \ +} while(0) + +#define reverse_int(x) \ +do { \ + union { \ + unsigned int u32; \ + int s32; \ + } __from, __to; \ + __from.s32 = (x); \ + swap_bytes_32(__from.u32, __to.u32); \ + (x) = __to.s32; \ +} while(0) + +#define swap_bytes_float(from, to) \ +do { \ + union { \ + unsigned int u32; \ + float f; \ + } __from, __to; \ + __from.f = (from); \ + swap_bytes_32(__from.u32, __to.u32); \ + (to) = __to.f; \ +} while(0) + +#define reverse_float(x) \ +do { \ + union { \ + unsigned int u32; \ + float f; \ + } __from, __to; \ + __from.f = (x); \ + swap_bytes_32(__from.u32, __to.u32); \ + (x) = __to.f; \ +} while(0) + +#define reverse_double(x) swap_bytes_double(x, x) + +#endif /* SWAP_BYTES_H */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |