[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r23639 - in Extractor/src: common plugins/old
From: |
gnunet |
Subject: |
[GNUnet-SVN] r23639 - in Extractor/src: common plugins/old |
Date: |
Tue, 4 Sep 2012 19:51:56 +0200 |
Author: grothoff
Date: 2012-09-04 19:51:56 +0200 (Tue, 04 Sep 2012)
New Revision: 23639
Added:
Extractor/src/plugins/old/convert_numeric.c
Extractor/src/plugins/old/convert_numeric.h
Extractor/src/plugins/old/pack.c
Extractor/src/plugins/old/pack.h
Removed:
Extractor/src/common/convert_numeric.c
Extractor/src/common/convert_numeric.h
Extractor/src/common/pack.c
Extractor/src/common/pack.h
Modified:
Extractor/src/common/Makefile.am
Extractor/src/common/le_architecture.h
Log:
-removing dead code from common lib and API
Modified: Extractor/src/common/Makefile.am
===================================================================
--- Extractor/src/common/Makefile.am 2012-09-04 17:43:53 UTC (rev 23638)
+++ Extractor/src/common/Makefile.am 2012-09-04 17:51:56 UTC (rev 23639)
@@ -7,18 +7,13 @@
libextractor_common.la
libextractor_common_la_LDFLAGS = \
- $(LE_LIB_LDFLAGS)
+ $(LE_LIB_LDFLAGS) \
+ -version-info 1:0:0
libextractor_common_la_LIBADD = \
$(LTLIBICONV) -lz
libextractor_common_la_SOURCES = \
le_architecture.h \
- unzip.c \
- unzip.h \
- pack.c \
- pack.h \
- convert.c \
- convert.h \
- convert_numeric.c \
- convert_numeric.h
+ unzip.c unzip.h \
+ convert.c convert.h
Deleted: Extractor/src/common/convert_numeric.c
===================================================================
--- Extractor/src/common/convert_numeric.c 2012-09-04 17:43:53 UTC (rev
23638)
+++ Extractor/src/common/convert_numeric.c 2012-09-04 17:51:56 UTC (rev
23639)
@@ -1,631 +0,0 @@
-/* IEEE floating point support routines, for GDB, the GNU Debugger.
- Copyright 1991, 1994, 1999, 2000, 2003, 2005, 2006
- Free Software Foundation, Inc.
-
-This file is part of GDB.
-
-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, write to the Free Software
-Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
USA. */
-
-/* This is needed to pick up the NAN macro on some systems. */
-/* #define _GNU_SOURCE */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <math.h>
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-/* On some platforms, <float.h> provides DBL_QNAN. */
-#ifdef STDC_HEADERS
-#include <float.h>
-#endif
-
-/*#include "ansidecl.h"*/
-/*#include "libiberty.h"*/
-#include "convert_numeric.h"
-
-#ifndef INFINITY
-#ifdef HUGE_VAL
-#define INFINITY HUGE_VAL
-#else
-#define INFINITY (1.0 / 0.0)
-#endif
-#endif
-
-#ifndef NAN
-#ifdef DBL_QNAN
-#define NAN DBL_QNAN
-#else
-#define NAN (0.0 / 0.0)
-#endif
-#endif
-
-static unsigned long get_field (const unsigned char *,
- enum EXTRACTOR_floatformat_byteorders,
- unsigned int,
- unsigned int,
- unsigned int);
-static int floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt,
- const void *from);
-
-static int
-floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt
/*ATTRIBUTE_UNUSED*/,
- const void *from /*ATTRIBUTE_UNUSED*/)
-{
- return 1;
-}
-
-/* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
- going to bother with trying to muck around with whether it is defined in
- a system header, what we do if not, etc. */
-#define FLOATFORMAT_CHAR_BIT 8
-
-/* floatformats for IEEE single and double, big and little endian. */
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big =
-{
- floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23,
- floatformat_intbit_no,
- "floatformat_ieee_single_big",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_little =
-{
- floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23,
- floatformat_intbit_no,
- "floatformat_ieee_single_little",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big =
-{
- floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52,
- floatformat_intbit_no,
- "floatformat_ieee_double_big",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little =
-{
- floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52,
- floatformat_intbit_no,
- "floatformat_ieee_double_little",
- floatformat_always_valid
-};
-
-/* floatformat for IEEE double, little endian byte order, with big endian word
- ordering, as on the ARM. */
-
-const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_double_littlebyte_bigword =
-{
- floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52,
- floatformat_intbit_no,
- "floatformat_ieee_double_littlebyte_bigword",
- floatformat_always_valid
-};
-
-/* floatformat for VAX. Not quite IEEE, but close enough. */
-
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f =
-{
- floatformat_vax, 32, 0, 1, 8, 129, 0, 9, 23,
- floatformat_intbit_no,
- "floatformat_vax_f",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d =
-{
- floatformat_vax, 64, 0, 1, 8, 129, 0, 9, 55,
- floatformat_intbit_no,
- "floatformat_vax_d",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g =
-{
- floatformat_vax, 64, 0, 1, 11, 1025, 0, 12, 52,
- floatformat_intbit_no,
- "floatformat_vax_g",
- floatformat_always_valid
-};
-
-static int floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat
*fmt,
- const void *from);
-
-static int
-floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const
void *from)
-{
- /* In the i387 double-extended format, if the exponent is all ones,
- then the integer bit must be set. If the exponent is neither 0
- nor ~0, the intbit must also be set. Only if the exponent is
- zero can it be zero, and then it must be zero. */
- unsigned long exponent, int_bit;
- const unsigned char *ufrom = (const unsigned char *) from;
-
- exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
- fmt->exp_start, fmt->exp_len);
- int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
- fmt->man_start, 1);
-
- if ((exponent == 0) != (int_bit == 0))
- return 0;
- else
- return 1;
-}
-
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext =
-{
- floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
- floatformat_intbit_yes,
- "floatformat_i387_ext",
- floatformat_i387_ext_is_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext =
-{
- /* Note that the bits from 16 to 31 are unused. */
- floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64,
- floatformat_intbit_yes,
- "floatformat_m68881_ext",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext =
-{
- /* Note that the bits from 0 to 15 are unused. */
- floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64,
- floatformat_intbit_yes,
- "floatformat_i960_ext",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext =
-{
- floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
- floatformat_intbit_yes,
- "floatformat_m88110_ext",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext =
-{
- /* Harris uses raw format 128 bytes long, but the number is just an ieee
- double, and the last 64 bits are wasted. */
- floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52,
- floatformat_intbit_no,
- "floatformat_m88110_ext_harris",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big =
-{
- /* Bits 1 to 16 are unused. */
- floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
- floatformat_intbit_yes,
- "floatformat_arm_ext_big",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_arm_ext_littlebyte_bigword =
-{
- /* Bits 1 to 16 are unused. */
- floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
- floatformat_intbit_yes,
- "floatformat_arm_ext_littlebyte_bigword",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big =
-{
- floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
- floatformat_intbit_yes,
- "floatformat_ia64_spill_big",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_little =
-{
- floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
- floatformat_intbit_yes,
- "floatformat_ia64_spill_little",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big =
-{
- floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
- floatformat_intbit_no,
- "floatformat_ia64_quad_big",
- floatformat_always_valid
-};
-const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little =
-{
- floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
- floatformat_intbit_no,
- "floatformat_ia64_quad_little",
- floatformat_always_valid
-};
-
-
-#ifndef min
-#define min(a, b) ((a) < (b) ? (a) : (b))
-#endif
-
-/* Extract a field which starts at START and is LEN bits long. DATA and
- TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
-static unsigned long
-get_field (const unsigned char *data, enum EXTRACTOR_floatformat_byteorders
order,
- unsigned int total_len, unsigned int start, unsigned int len)
-{
- unsigned long result = 0;
- unsigned int cur_byte;
- int lo_bit, hi_bit, cur_bitshift = 0;
- int nextbyte = (order == floatformat_little) ? 1 : -1;
-
- /* Start is in big-endian bit order! Fix that first. */
- start = total_len - (start + len);
-
- /* Start at the least significant part of the field. */
- if (order == floatformat_little)
- cur_byte = start / FLOATFORMAT_CHAR_BIT;
- else
- cur_byte = (total_len - start - 1) / FLOATFORMAT_CHAR_BIT;
-
- lo_bit = start % FLOATFORMAT_CHAR_BIT;
- hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT);
-
- do
- {
- unsigned int shifted = *(data + cur_byte) >> lo_bit;
- unsigned int bits = hi_bit - lo_bit;
- unsigned int mask = (1 << bits) - 1;
- result |= (shifted & mask) << cur_bitshift;
- len -= bits;
- cur_bitshift += bits;
- cur_byte += nextbyte;
- lo_bit = 0;
- hi_bit = min (len, FLOATFORMAT_CHAR_BIT);
- }
- while (len != 0);
-
- return result;
-}
-
-/* Convert from FMT to a double.
- FROM is the address of the extended float.
- Store the double in *TO. */
-
-void
-EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat
*fmt,
- const void *from, double *to)
-{
- const unsigned char *ufrom = (const unsigned char *) from;
- double dto;
- long exponent;
- unsigned long mant;
- unsigned int mant_bits, mant_off;
- int mant_bits_left;
- int special_exponent; /* It's a NaN, denorm or zero */
-
- exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
- fmt->exp_start, fmt->exp_len);
-
- /* If the exponent indicates a NaN, we don't have information to
- decide what to do. So we handle it like IEEE, except that we
- don't try to preserve the type of NaN. FIXME. */
- if ((unsigned long) exponent == fmt->exp_nan)
- {
- int nan;
-
- mant_off = fmt->man_start;
- mant_bits_left = fmt->man_len;
- nan = 0;
- while (mant_bits_left > 0)
- {
- mant_bits = min (mant_bits_left, 32);
-
- if (get_field (ufrom, fmt->byteorder, fmt->totalsize,
- mant_off, mant_bits) != 0)
- {
- /* This is a NaN. */
- nan = 1;
- break;
- }
-
- mant_off += mant_bits;
- mant_bits_left -= mant_bits;
- }
-
- /* On certain systems (such as GNU/Linux), the use of the
- INFINITY macro below may generate a warning that can not be
- silenced due to a bug in GCC (PR preprocessor/11931). The
- preprocessor fails to recognise the __extension__ keyword in
- conjunction with the GNU/C99 extension for hexadecimal
- floating point constants and will issue a warning when
- compiling with -pedantic. */
- if (nan)
- dto = NAN;
- else
- dto = INFINITY;
-
- if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start,
1))
- dto = -dto;
-
- *to = dto;
-
- return;
- }
-
- mant_bits_left = fmt->man_len;
- mant_off = fmt->man_start;
- dto = 0.0;
-
- special_exponent = (exponent == 0) || ((unsigned long) exponent ==
fmt->exp_nan);
-
- /* Don't bias zero's, denorms or NaNs. */
- if (!special_exponent)
- exponent -= fmt->exp_bias;
-
- /* Build the result algebraically. Might go infinite, underflow, etc;
- who cares. */
-
- /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
- increment the exponent by one to account for the integer bit. */
-
- if (!special_exponent)
- {
- if (fmt->intbit == floatformat_intbit_no)
- dto = ldexp (1.0, exponent);
- else
- exponent++;
- }
-
- while (mant_bits_left > 0)
- {
- mant_bits = min (mant_bits_left, 32);
-
- mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
- mant_off, mant_bits);
-
- /* Handle denormalized numbers. FIXME: What should we do for
- non-IEEE formats? */
- if (special_exponent && exponent == 0 && mant != 0)
- dto += ldexp ((double)mant,
- (- fmt->exp_bias
- - mant_bits
- - (mant_off - fmt->man_start)
- + 1));
- else
- dto += ldexp ((double)mant, exponent - mant_bits);
- if (exponent != 0)
- exponent -= mant_bits;
- mant_off += mant_bits;
- mant_bits_left -= mant_bits;
- }
-
- /* Negate it if negative. */
- if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
- dto = -dto;
- *to = dto;
-}
-
-static void put_field (unsigned char *, enum EXTRACTOR_floatformat_byteorders,
- unsigned int,
- unsigned int,
- unsigned int,
- unsigned long);
-
-/* Set a field which starts at START and is LEN bits long. DATA and
- TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
-static void
-put_field (unsigned char *data, enum EXTRACTOR_floatformat_byteorders order,
- unsigned int total_len, unsigned int start, unsigned int len,
- unsigned long stuff_to_put)
-{
- unsigned int cur_byte;
- int lo_bit, hi_bit;
- int nextbyte = (order == floatformat_little) ? 1 : -1;
-
- /* Start is in big-endian bit order! Fix that first. */
- start = total_len - (start + len);
-
- /* Start at the least significant part of the field. */
- if (order == floatformat_little)
- cur_byte = start / FLOATFORMAT_CHAR_BIT;
- else
- cur_byte = (total_len - start - 1) / FLOATFORMAT_CHAR_BIT;
-
- lo_bit = start % FLOATFORMAT_CHAR_BIT;
- hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT);
-
- do
- {
- unsigned char *byte_ptr = data + cur_byte;
- unsigned int bits = hi_bit - lo_bit;
- unsigned int mask = ((1 << bits) - 1) << lo_bit;
- *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask);
- stuff_to_put >>= bits;
- len -= bits;
- cur_byte += nextbyte;
- lo_bit = 0;
- hi_bit = min (len, FLOATFORMAT_CHAR_BIT);
- }
- while (len != 0);
-}
-
-/* The converse: convert the double *FROM to an extended float
- and store where TO points. Neither FROM nor TO have any alignment
- restrictions. */
-
-void
-EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat
*fmt,
- const double *from, void *to)
-{
- double dfrom;
- int exponent;
- double mant;
- unsigned int mant_bits, mant_off;
- int mant_bits_left;
- unsigned char *uto = (unsigned char *) to;
-
- dfrom = *from;
- memset (uto, 0, fmt->totalsize / FLOATFORMAT_CHAR_BIT);
-
- /* If negative, set the sign bit. */
- if (dfrom < 0)
- {
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
- dfrom = -dfrom;
- }
-
- if (dfrom == 0)
- {
- /* 0.0. */
- return;
- }
-
- if (dfrom != dfrom)
- {
- /* NaN. */
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
- fmt->exp_len, fmt->exp_nan);
- /* Be sure it's not infinity, but NaN value is irrelevant. */
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
- 32, 1);
- return;
- }
-
- if (dfrom + dfrom == dfrom)
- {
- /* This can only happen for an infinite value (or zero, which we
- already handled above). */
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
- fmt->exp_len, fmt->exp_nan);
- return;
- }
-
- mant = frexp (dfrom, &exponent);
- if (exponent + fmt->exp_bias - 1 > 0)
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
- fmt->exp_len, exponent + fmt->exp_bias - 1);
- else
- {
- /* Handle a denormalized number. FIXME: What should we do for
- non-IEEE formats? */
- put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
- fmt->exp_len, 0);
- mant = ldexp (mant, exponent + fmt->exp_bias - 1);
- }
-
- mant_bits_left = fmt->man_len;
- mant_off = fmt->man_start;
- while (mant_bits_left > 0)
- {
- unsigned long mant_long;
- mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
-
- mant *= 4294967296.0;
- mant_long = (unsigned long)mant;
- mant -= mant_long;
-
- /* If the integer bit is implicit, and we are not creating a
- denormalized number, then we need to discard it. */
- if ((unsigned int) mant_bits_left == fmt->man_len
- && fmt->intbit == floatformat_intbit_no
- && exponent + fmt->exp_bias - 1 > 0)
- {
- mant_long &= 0x7fffffff;
- mant_bits -= 1;
- }
- else if (mant_bits < 32)
- {
- /* The bits we want are in the most significant MANT_BITS bits of
- mant_long. Move them to the least significant. */
- mant_long >>= 32 - mant_bits;
- }
-
- put_field (uto, fmt->byteorder, fmt->totalsize,
- mant_off, mant_bits, mant_long);
- mant_off += mant_bits;
- mant_bits_left -= mant_bits;
- }
-}
-
-/* Return non-zero iff the data at FROM is a valid number in format FMT. */
-
-int
-EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat
*fmt, const void *from)
-{
- return fmt->is_valid (fmt, from);
-}
-
-
-#ifdef IEEE_DEBUG
-
-#include <stdio.h>
-
-/* This is to be run on a host which uses IEEE floating point. */
-
-void
-ieee_test (double n)
-{
- double result;
-
- floatformat_to_double (&floatformat_ieee_double_little, &n, &result);
- if ((n != result && (! isnan (n) || ! isnan (result)))
- || (n < 0 && result >= 0)
- || (n >= 0 && result < 0))
- printf ("Differ(to): %.20g -> %.20g\n", n, result);
-
- floatformat_from_double (&floatformat_ieee_double_little, &n, &result);
- if ((n != result && (! isnan (n) || ! isnan (result)))
- || (n < 0 && result >= 0)
- || (n >= 0 && result < 0))
- printf ("Differ(from): %.20g -> %.20g\n", n, result);
-
-#if 0
- {
- char exten[16];
-
- floatformat_from_double (&floatformat_m68881_ext, &n, exten);
- floatformat_to_double (&floatformat_m68881_ext, exten, &result);
- if (n != result)
- printf ("Differ(to+from): %.20g -> %.20g\n", n, result);
- }
-#endif
-
-#if IEEE_DEBUG > 1
- /* This is to be run on a host which uses 68881 format. */
- {
- long double ex = *(long double *)exten;
- if (ex != n)
- printf ("Differ(from vs. extended): %.20g\n", n);
- }
-#endif
-}
-
-int
-main (void)
-{
- ieee_test (0.0);
- ieee_test (0.5);
- ieee_test (256.0);
- ieee_test (0.12345);
- ieee_test (234235.78907234);
- ieee_test (-512.0);
- ieee_test (-0.004321);
- ieee_test (1.2E-70);
- ieee_test (1.2E-316);
- ieee_test (4.9406564584124654E-324);
- ieee_test (- 4.9406564584124654E-324);
- ieee_test (- 0.0);
- ieee_test (- INFINITY);
- ieee_test (- NAN);
- ieee_test (INFINITY);
- ieee_test (NAN);
- return 0;
-}
-#endif
Deleted: Extractor/src/common/convert_numeric.h
===================================================================
--- Extractor/src/common/convert_numeric.h 2012-09-04 17:43:53 UTC (rev
23638)
+++ Extractor/src/common/convert_numeric.h 2012-09-04 17:51:56 UTC (rev
23639)
@@ -1,140 +0,0 @@
-/* IEEE floating point support declarations, for GDB, the GNU Debugger.
- Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005
- Free Software Foundation, Inc.
-
-This file is part of GDB.
-
-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, write to the Free Software
-Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
USA. */
-
-#if !defined (FLOATFORMAT_H)
-#define FLOATFORMAT_H 1
-
-/*#include "ansidecl.h"*/
-
-/* A floatformat consists of a sign bit, an exponent and a mantissa. Once the
- bytes are concatenated according to the byteorder flag, then each of those
- fields is contiguous. We number the bits with 0 being the most significant
- (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field
- contains with the *_start and *_len fields. */
-
-/* What is the order of the bytes? */
-
-enum EXTRACTOR_floatformat_byteorders {
- /* Standard little endian byte order.
- EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */
- floatformat_little,
-
- /* Standard big endian byte order.
- EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */
- floatformat_big,
-
- /* Little endian byte order but big endian word order.
- EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */
- floatformat_littlebyte_bigword,
-
- /* VAX byte order. Little endian byte order with 16-bit words. The
- following example is an illustration of the byte order only; VAX
- doesn't have a fully IEEE compliant floating-point format.
- EX: 1.2345678e10 => 80 c5 00 00 06 42 e0 fe */
- floatformat_vax
-};
-
-enum EXTRACTOR_floatformat_intbit { floatformat_intbit_yes,
floatformat_intbit_no };
-
-struct EXTRACTOR_floatformat
-{
- enum EXTRACTOR_floatformat_byteorders byteorder;
- unsigned int totalsize; /* Total size of number in bits */
-
- /* Sign bit is always one bit long. 1 means negative, 0 means positive. */
- unsigned int sign_start;
-
- unsigned int exp_start;
- unsigned int exp_len;
- /* Bias added to a "true" exponent to form the biased exponent. It
- is intentionally signed as, otherwize, -exp_bias can turn into a
- very large number (e.g., given the exp_bias of 0x3fff and a 64
- bit long, the equation (long)(1 - exp_bias) evaluates to
- 4294950914) instead of -16382). */
- int exp_bias;
- /* Exponent value which indicates NaN. This is the actual value stored in
- the float, not adjusted by the exp_bias. This usually consists of all
- one bits. */
- unsigned int exp_nan;
-
- unsigned int man_start;
- unsigned int man_len;
-
- /* Is the integer bit explicit or implicit? */
- enum EXTRACTOR_floatformat_intbit intbit;
-
- /* Internal name for debugging. */
- const char *name;
-
- /* Validator method. */
- int (*is_valid) (const struct EXTRACTOR_floatformat *fmt, const void *from);
-};
-
-/* floatformats for IEEE single and double, big and little endian. */
-
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_single_big;
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_single_little;
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_double_big;
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_double_little;
-
-/* floatformat for ARM IEEE double, little endian bytes and big endian words */
-
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_double_littlebyte_bigword;
-
-/* floatformats for VAX. */
-
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f;
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d;
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g;
-
-/* floatformats for various extendeds. */
-
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext;
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext;
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext;
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext;
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_m88110_harris_ext;
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big;
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_arm_ext_littlebyte_bigword;
-/* IA-64 Floating Point register spilt into memory. */
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big;
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ia64_spill_little;
-extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big;
-extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ia64_quad_little;
-
-/* Convert from FMT to a double.
- FROM is the address of the extended float.
- Store the double in *TO. */
-
-extern void
-EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *,
const void *, double *);
-
-/* The converse: convert the double *FROM to FMT
- and store where TO points. */
-
-extern void
-EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat
*, const double *, void *);
-
-/* Return non-zero iff the data at FROM is a valid number in format FMT. */
-
-extern int
-EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat
*fmt, const void *from);
-
-#endif /* defined (FLOATFORMAT_H) */
Modified: Extractor/src/common/le_architecture.h
===================================================================
--- Extractor/src/common/le_architecture.h 2012-09-04 17:43:53 UTC (rev
23638)
+++ Extractor/src/common/le_architecture.h 2012-09-04 17:51:56 UTC (rev
23639)
@@ -101,25 +101,7 @@
*/
#define LE_PACKED __attribute__((packed))
-/**
- * gcc-ism to get gcc bitfield layout when compiling with -mms-bitfields
- */
-#ifdef __MINGW32__
-#define LE_GCC_STRUCT_LAYOUT __attribute__((gcc_struct))
-#else
-#define LE_GCC_STRUCT_LAYOUT
-#endif
-/**
- * gcc-ism to document unused arguments
- */
-#define LE_UNUSED __attribute__((unused))
-
-/**
- * gcc-ism to document functions that don't return
- */
-#define LE_NORETURN __attribute__((noreturn))
-
#if MINGW
#if __GNUC__ > 3
/**
Deleted: Extractor/src/common/pack.c
===================================================================
--- Extractor/src/common/pack.c 2012-09-04 17:43:53 UTC (rev 23638)
+++ Extractor/src/common/pack.c 2012-09-04 17:51:56 UTC (rev 23639)
@@ -1,345 +0,0 @@
-/*
-Catlib Copyright Notice
-
-The author of this software is Christopher Adam Telfer
-Copyright (c) 1998, 1999, 2000, 2001, 2002
-by Christopher Adam Telfer. All Rights Reserved.
-
-Permission to use, copy, modify, and distribute this software for any
-purpose without fee is hereby granted, provided that the above copyright
-notice, this paragraph, and the following two paragraphs appear in all
-copies, modifications, and distributions.
-
-IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
-ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
-THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
-ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO
-OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
-MODIFICATIONS.
-
-*/
-
-#include "platform.h"
-#include "pack.h"
-
-#if !(defined(_WIN32) && defined(cbNDRContext))
-typedef unsigned char byte;
-#endif
-typedef unsigned short half;
-typedef unsigned int word;
-typedef signed char sbyte;
-typedef signed short shalf;
-typedef signed int sword;
-
-
-
-int
-EXTRACTOR_common_cat_unpack (const void *buf,
- const char *fmt,
- ...)
-{
- va_list ap;
- word maxlen, len, *wordp;
- void *arr;
- byte *bp, *bytep, *newbuf;
- half *halfp;
- long long *ll;
- sbyte *sbytep;
- shalf *shalfp;
- sword *swordp;
- int npacked;
- unsigned int nreps, i, isnonprefixed = 1; /* used for 'a' types only */
- struct cat_bvec *cbvp;
- char *cp;
-
- bp = (byte *) buf;
- npacked = 0;
-
- va_start (ap, fmt);
-
- while (*fmt)
- {
- nreps = 1;
-
- if (isdigit ( (unsigned char) *fmt))
- {
- /* We use cp instead of format to keep the 'const' qualifier of fmt
*/
- nreps = strtoul (fmt, &cp, 0);
- fmt = cp;
- if (*fmt == 'a')
- isnonprefixed = 0;
- }
-
- switch (*fmt)
- {
- case 'B':
- case 'b':
- bytep = va_arg (ap, byte *);
- for (i = 0; i < nreps; ++i)
- {
- *bytep = *bp++;
- ++bytep;
- npacked += 1;
- }
- break;
-
-
-
- case 'h':
- halfp = va_arg (ap, half *);
- for (i = 0; i < nreps; ++i)
- {
- *halfp = *bp++;
- *halfp |= *bp++ << 8;
- ++halfp;
- npacked += 2;
- }
- break;
-
- case 'H':
- halfp = va_arg (ap, half *);
- for (i = 0; i < nreps; ++i)
- {
- *halfp = *bp++ << 8;
- *halfp |= *bp++;
- ++halfp;
- npacked += 2;
- }
- break;
-
-
- case 'w':
- wordp = va_arg (ap, word *);
- for (i = 0; i < nreps; ++i)
- {
- *wordp = *bp++;
- *wordp |= *bp++ << 8;
- *wordp |= *bp++ << 16;
- *wordp |= *bp++ << 24;
- ++wordp;
- npacked += 4;
- }
- break;
-
- case 'x':
- ll = va_arg (ap, long long *);
- for (i = 0; i < nreps; ++i)
- {
- *ll = ((long long) *bp++);
- *ll |= ((long long) *bp++) << 8;
- *ll |= ((long long) *bp++) << 16;
- *ll |= ((long long) *bp++) << 24;
- *ll |= ((long long) *bp++) << 32;
- *ll |= ((long long) *bp++) << 40;
- *ll |= ((long long) *bp++) << 48;
- *ll |= ((long long) *bp++) << 56;
- ++ll;
- npacked += 8;
- }
- break;
-
- case 'W':
- wordp = va_arg (ap, word *);
- for (i = 0; i < nreps; ++i)
- {
- *wordp = *bp++ << 24;
- *wordp |= *bp++ << 16;
- *wordp |= *bp++ << 8;
- *wordp |= *bp++;
- ++wordp;
- npacked += 4;
- }
- break;
-
- case 'X':
- ll = va_arg (ap, long long *);
- for (i = 0; i < nreps; ++i)
- {
- *ll = ((long long) *bp++) << 56;
- *ll |= ((long long) *bp++) << 48;
- *ll |= ((long long) *bp++) << 40;
- *ll |= ((long long) *bp++) << 32;
- *ll |= ((long long) *bp++) << 24;
- *ll |= ((long long) *bp++) << 18;
- *ll |= ((long long) *bp++) << 8;
- *ll |= ((long long) *bp++);
- ++ll;
- npacked += 8;
- }
- break;
-
-
- case 'A':
- if (isnonprefixed)
- {
- maxlen = va_arg (ap, word);
- arr = va_arg (ap, void *);
-
- len = *bp++ << 24;
- len |= *bp++ << 16;
- len |= *bp++ << 8;
- len |= *bp++;
-
- if (len > maxlen)
- {
- va_end (ap);
- return -1;
- }
-
- memmove (arr, bp, len);
- bp += len;
-
- npacked += len;
- }
- else
- {
- cbvp = va_arg (ap, struct cat_bvec *);
- for (i = 0; i < nreps; ++i)
- {
- maxlen = cbvp->len;
- arr = cbvp->data;
-
- len = *bp++ << 24;
- len |= *bp++ << 16;
- len |= *bp++ << 8;
- len |= *bp++;
-
- if (len > maxlen)
- return -1;
-
- memmove (arr, bp, len);
- cbvp->len = len;
- bp += len;
-
- ++cbvp;
- npacked += len;
- }
- isnonprefixed = 1;
- }
- break;
-
- case 'C':
- case 'c':
- sbytep = va_arg (ap, sbyte *);
- for (i = 0; i < nreps; ++i)
- {
- *sbytep = *bp++;
-
- if ((sizeof (sbyte) > 1) && (*sbytep & 0x80))
- *sbytep |= (~0) << ((sizeof (sbyte) - 1) * 8);
-
- ++sbytep;
- npacked += 1;
- }
- break;
-
-
- case 's':
- shalfp = va_arg (ap, shalf *);
- for (i = 0; i < nreps; ++i)
- {
- *shalfp = *bp++;
- *shalfp |= *bp++ << 8;
-
- if ((sizeof (shalf) > 2) && (*shalfp & 0x8000))
- *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8);
-
- ++shalfp;
- npacked += 2;
- }
- break;
-
- case 'S':
- shalfp = va_arg (ap, shalf *);
- for (i = 0; i < nreps; ++i)
- {
- *shalfp = *bp++ << 8;
- *shalfp |= *bp++;
-
- if ((sizeof (shalf) > 2) && (*shalfp & 0x8000))
- *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8);
-
- ++shalfp;
- npacked += 2;
- }
- break;
-
- case 'l':
- swordp = va_arg (ap, sword *);
- for (i = 0; i < nreps; ++i)
- {
- *swordp = *bp++;
- *swordp |= *bp++ << 8;
- *swordp |= *bp++ << 16;
- *swordp |= *bp++ << 24;
-
- if ((sizeof (swordp) > 4) && (*swordp & 0x80000000))
- *swordp |= (~0) << ((sizeof (sword) - 4) * 8);
-
- ++swordp;
- npacked += 4;
- }
- break;
-
- case 'L':
- swordp = va_arg (ap, sword *);
- for (i = 0; i < nreps; ++i)
- {
- *swordp = *bp++ << 24;
- *swordp |= *bp++ << 16;
- *swordp |= *bp++ << 8;
- *swordp |= *bp++;
-
- if ((sizeof (swordp) > 4) && (*swordp & 0x80000000))
- *swordp |= (~0) << ((sizeof (sword) - 4) * 8);
-
- ++swordp;
- npacked += 4;
- }
- break;
-
- case 'P':
- cbvp = va_arg (ap, struct cat_bvec *);
- for (i = 0; i < nreps; ++i)
- {
- len = *bp++ << 24;
- len |= *bp++ << 16;
- len |= *bp++ << 8;
- len |= *bp++;
-
- newbuf = (byte *) malloc (len);
-
- if (!newbuf)
- {
- int j;
- for (j = 0; j < i; j++)
- free (cbvp[i].data);
- va_end (ap);
- return -1;
- }
-
- memmove (newbuf, bp, len);
- cbvp[i].data = newbuf;
- cbvp[i].len = len;
-
- bp += len;
- npacked += len;
- }
- break;
-
- default:
- va_end (ap);
- return -1;
- }
-
- ++fmt;
- }
-
- va_end (ap);
- return 0;
-}
Deleted: Extractor/src/common/pack.h
===================================================================
--- Extractor/src/common/pack.h 2012-09-04 17:43:53 UTC (rev 23638)
+++ Extractor/src/common/pack.h 2012-09-04 17:51:56 UTC (rev 23639)
@@ -1,62 +0,0 @@
-/*
-Catlib Copyright Notice
-
-The author of this software is Christopher Adam Telfer
-Copyright (c) 1998, 1999, 2000, 2001, 2002
-by Christopher Adam Telfer. All Rights Reserved.
-
-Permission to use, copy, modify, and distribute this software for any
-purpose without fee is hereby granted, provided that the above copyright
-notice, this paragraph, and the following two paragraphs appear in all
-copies, modifications, and distributions.
-
-IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
-SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
-ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
-THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
-ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO
-OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
-MODIFICATIONS.
-
-
-*/
-
-#ifndef __CAT_PACK_H
-#define __CAT_PACK_H
-
-/*
- "bhwAcslPBHWCSL"
-
- Small letters: do not convert (not implemented for arrays and P)
- Captial letters: convert from network byte order to host byte order
-
- b - byte
- h - half-word
- w - word
- a - array (32-byte unsigned long + that many bytes)
- c - signed 8 bit value
- s - signed 16 bit value
- l - signed 32 bit value
- x - signed 64 bit value
- p - (unpack only) value is a pointer to a pointer. Generate the buffer
- to hold the data.
- */
-int
-EXTRACTOR_common_cat_unpack(const void * buf,
- const char *fmt,
- ...);
-
-struct cat_bvec
-{
- unsigned long len;
- void * data;
-};
-
-
-#endif /* __CAT_PACK_H */
-
-
Copied: Extractor/src/plugins/old/convert_numeric.c (from rev 23633,
Extractor/src/common/convert_numeric.c)
===================================================================
--- Extractor/src/plugins/old/convert_numeric.c (rev 0)
+++ Extractor/src/plugins/old/convert_numeric.c 2012-09-04 17:51:56 UTC (rev
23639)
@@ -0,0 +1,631 @@
+/* IEEE floating point support routines, for GDB, the GNU Debugger.
+ Copyright 1991, 1994, 1999, 2000, 2003, 2005, 2006
+ Free Software Foundation, Inc.
+
+This file is part of GDB.
+
+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, write to the Free Software
+Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
USA. */
+
+/* This is needed to pick up the NAN macro on some systems. */
+/* #define _GNU_SOURCE */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <math.h>
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+/* On some platforms, <float.h> provides DBL_QNAN. */
+#ifdef STDC_HEADERS
+#include <float.h>
+#endif
+
+/*#include "ansidecl.h"*/
+/*#include "libiberty.h"*/
+#include "convert_numeric.h"
+
+#ifndef INFINITY
+#ifdef HUGE_VAL
+#define INFINITY HUGE_VAL
+#else
+#define INFINITY (1.0 / 0.0)
+#endif
+#endif
+
+#ifndef NAN
+#ifdef DBL_QNAN
+#define NAN DBL_QNAN
+#else
+#define NAN (0.0 / 0.0)
+#endif
+#endif
+
+static unsigned long get_field (const unsigned char *,
+ enum EXTRACTOR_floatformat_byteorders,
+ unsigned int,
+ unsigned int,
+ unsigned int);
+static int floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt,
+ const void *from);
+
+static int
+floatformat_always_valid (const struct EXTRACTOR_floatformat *fmt
/*ATTRIBUTE_UNUSED*/,
+ const void *from /*ATTRIBUTE_UNUSED*/)
+{
+ return 1;
+}
+
+/* The odds that CHAR_BIT will be anything but 8 are low enough that I'm not
+ going to bother with trying to muck around with whether it is defined in
+ a system header, what we do if not, etc. */
+#define FLOATFORMAT_CHAR_BIT 8
+
+/* floatformats for IEEE single and double, big and little endian. */
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_big =
+{
+ floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23,
+ floatformat_intbit_no,
+ "floatformat_ieee_single_big",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_single_little =
+{
+ floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23,
+ floatformat_intbit_no,
+ "floatformat_ieee_single_little",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_big =
+{
+ floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52,
+ floatformat_intbit_no,
+ "floatformat_ieee_double_big",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ieee_double_little =
+{
+ floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52,
+ floatformat_intbit_no,
+ "floatformat_ieee_double_little",
+ floatformat_always_valid
+};
+
+/* floatformat for IEEE double, little endian byte order, with big endian word
+ ordering, as on the ARM. */
+
+const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_double_littlebyte_bigword =
+{
+ floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52,
+ floatformat_intbit_no,
+ "floatformat_ieee_double_littlebyte_bigword",
+ floatformat_always_valid
+};
+
+/* floatformat for VAX. Not quite IEEE, but close enough. */
+
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f =
+{
+ floatformat_vax, 32, 0, 1, 8, 129, 0, 9, 23,
+ floatformat_intbit_no,
+ "floatformat_vax_f",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d =
+{
+ floatformat_vax, 64, 0, 1, 8, 129, 0, 9, 55,
+ floatformat_intbit_no,
+ "floatformat_vax_d",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g =
+{
+ floatformat_vax, 64, 0, 1, 11, 1025, 0, 12, 52,
+ floatformat_intbit_no,
+ "floatformat_vax_g",
+ floatformat_always_valid
+};
+
+static int floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat
*fmt,
+ const void *from);
+
+static int
+floatformat_i387_ext_is_valid (const struct EXTRACTOR_floatformat *fmt, const
void *from)
+{
+ /* In the i387 double-extended format, if the exponent is all ones,
+ then the integer bit must be set. If the exponent is neither 0
+ nor ~0, the intbit must also be set. Only if the exponent is
+ zero can it be zero, and then it must be zero. */
+ unsigned long exponent, int_bit;
+ const unsigned char *ufrom = (const unsigned char *) from;
+
+ exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ fmt->exp_start, fmt->exp_len);
+ int_bit = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ fmt->man_start, 1);
+
+ if ((exponent == 0) != (int_bit == 0))
+ return 0;
+ else
+ return 1;
+}
+
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext =
+{
+ floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
+ floatformat_intbit_yes,
+ "floatformat_i387_ext",
+ floatformat_i387_ext_is_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext =
+{
+ /* Note that the bits from 16 to 31 are unused. */
+ floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64,
+ floatformat_intbit_yes,
+ "floatformat_m68881_ext",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext =
+{
+ /* Note that the bits from 0 to 15 are unused. */
+ floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64,
+ floatformat_intbit_yes,
+ "floatformat_i960_ext",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext =
+{
+ floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64,
+ floatformat_intbit_yes,
+ "floatformat_m88110_ext",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_harris_ext =
+{
+ /* Harris uses raw format 128 bytes long, but the number is just an ieee
+ double, and the last 64 bits are wasted. */
+ floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52,
+ floatformat_intbit_no,
+ "floatformat_m88110_ext_harris",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big =
+{
+ /* Bits 1 to 16 are unused. */
+ floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
+ floatformat_intbit_yes,
+ "floatformat_arm_ext_big",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_arm_ext_littlebyte_bigword =
+{
+ /* Bits 1 to 16 are unused. */
+ floatformat_littlebyte_bigword, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64,
+ floatformat_intbit_yes,
+ "floatformat_arm_ext_littlebyte_bigword",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big =
+{
+ floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
+ floatformat_intbit_yes,
+ "floatformat_ia64_spill_big",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_little =
+{
+ floatformat_little, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
+ floatformat_intbit_yes,
+ "floatformat_ia64_spill_little",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big =
+{
+ floatformat_big, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
+ floatformat_intbit_no,
+ "floatformat_ia64_quad_big",
+ floatformat_always_valid
+};
+const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_little =
+{
+ floatformat_little, 128, 0, 1, 15, 16383, 0x7fff, 16, 112,
+ floatformat_intbit_no,
+ "floatformat_ia64_quad_little",
+ floatformat_always_valid
+};
+
+
+#ifndef min
+#define min(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+/* Extract a field which starts at START and is LEN bits long. DATA and
+ TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
+static unsigned long
+get_field (const unsigned char *data, enum EXTRACTOR_floatformat_byteorders
order,
+ unsigned int total_len, unsigned int start, unsigned int len)
+{
+ unsigned long result = 0;
+ unsigned int cur_byte;
+ int lo_bit, hi_bit, cur_bitshift = 0;
+ int nextbyte = (order == floatformat_little) ? 1 : -1;
+
+ /* Start is in big-endian bit order! Fix that first. */
+ start = total_len - (start + len);
+
+ /* Start at the least significant part of the field. */
+ if (order == floatformat_little)
+ cur_byte = start / FLOATFORMAT_CHAR_BIT;
+ else
+ cur_byte = (total_len - start - 1) / FLOATFORMAT_CHAR_BIT;
+
+ lo_bit = start % FLOATFORMAT_CHAR_BIT;
+ hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT);
+
+ do
+ {
+ unsigned int shifted = *(data + cur_byte) >> lo_bit;
+ unsigned int bits = hi_bit - lo_bit;
+ unsigned int mask = (1 << bits) - 1;
+ result |= (shifted & mask) << cur_bitshift;
+ len -= bits;
+ cur_bitshift += bits;
+ cur_byte += nextbyte;
+ lo_bit = 0;
+ hi_bit = min (len, FLOATFORMAT_CHAR_BIT);
+ }
+ while (len != 0);
+
+ return result;
+}
+
+/* Convert from FMT to a double.
+ FROM is the address of the extended float.
+ Store the double in *TO. */
+
+void
+EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat
*fmt,
+ const void *from, double *to)
+{
+ const unsigned char *ufrom = (const unsigned char *) from;
+ double dto;
+ long exponent;
+ unsigned long mant;
+ unsigned int mant_bits, mant_off;
+ int mant_bits_left;
+ int special_exponent; /* It's a NaN, denorm or zero */
+
+ exponent = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ fmt->exp_start, fmt->exp_len);
+
+ /* If the exponent indicates a NaN, we don't have information to
+ decide what to do. So we handle it like IEEE, except that we
+ don't try to preserve the type of NaN. FIXME. */
+ if ((unsigned long) exponent == fmt->exp_nan)
+ {
+ int nan;
+
+ mant_off = fmt->man_start;
+ mant_bits_left = fmt->man_len;
+ nan = 0;
+ while (mant_bits_left > 0)
+ {
+ mant_bits = min (mant_bits_left, 32);
+
+ if (get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits) != 0)
+ {
+ /* This is a NaN. */
+ nan = 1;
+ break;
+ }
+
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+ }
+
+ /* On certain systems (such as GNU/Linux), the use of the
+ INFINITY macro below may generate a warning that can not be
+ silenced due to a bug in GCC (PR preprocessor/11931). The
+ preprocessor fails to recognise the __extension__ keyword in
+ conjunction with the GNU/C99 extension for hexadecimal
+ floating point constants and will issue a warning when
+ compiling with -pedantic. */
+ if (nan)
+ dto = NAN;
+ else
+ dto = INFINITY;
+
+ if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start,
1))
+ dto = -dto;
+
+ *to = dto;
+
+ return;
+ }
+
+ mant_bits_left = fmt->man_len;
+ mant_off = fmt->man_start;
+ dto = 0.0;
+
+ special_exponent = (exponent == 0) || ((unsigned long) exponent ==
fmt->exp_nan);
+
+ /* Don't bias zero's, denorms or NaNs. */
+ if (!special_exponent)
+ exponent -= fmt->exp_bias;
+
+ /* Build the result algebraically. Might go infinite, underflow, etc;
+ who cares. */
+
+ /* If this format uses a hidden bit, explicitly add it in now. Otherwise,
+ increment the exponent by one to account for the integer bit. */
+
+ if (!special_exponent)
+ {
+ if (fmt->intbit == floatformat_intbit_no)
+ dto = ldexp (1.0, exponent);
+ else
+ exponent++;
+ }
+
+ while (mant_bits_left > 0)
+ {
+ mant_bits = min (mant_bits_left, 32);
+
+ mant = get_field (ufrom, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits);
+
+ /* Handle denormalized numbers. FIXME: What should we do for
+ non-IEEE formats? */
+ if (special_exponent && exponent == 0 && mant != 0)
+ dto += ldexp ((double)mant,
+ (- fmt->exp_bias
+ - mant_bits
+ - (mant_off - fmt->man_start)
+ + 1));
+ else
+ dto += ldexp ((double)mant, exponent - mant_bits);
+ if (exponent != 0)
+ exponent -= mant_bits;
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+ }
+
+ /* Negate it if negative. */
+ if (get_field (ufrom, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1))
+ dto = -dto;
+ *to = dto;
+}
+
+static void put_field (unsigned char *, enum EXTRACTOR_floatformat_byteorders,
+ unsigned int,
+ unsigned int,
+ unsigned int,
+ unsigned long);
+
+/* Set a field which starts at START and is LEN bits long. DATA and
+ TOTAL_LEN are the thing we are extracting it from, in byteorder ORDER. */
+static void
+put_field (unsigned char *data, enum EXTRACTOR_floatformat_byteorders order,
+ unsigned int total_len, unsigned int start, unsigned int len,
+ unsigned long stuff_to_put)
+{
+ unsigned int cur_byte;
+ int lo_bit, hi_bit;
+ int nextbyte = (order == floatformat_little) ? 1 : -1;
+
+ /* Start is in big-endian bit order! Fix that first. */
+ start = total_len - (start + len);
+
+ /* Start at the least significant part of the field. */
+ if (order == floatformat_little)
+ cur_byte = start / FLOATFORMAT_CHAR_BIT;
+ else
+ cur_byte = (total_len - start - 1) / FLOATFORMAT_CHAR_BIT;
+
+ lo_bit = start % FLOATFORMAT_CHAR_BIT;
+ hi_bit = min (lo_bit + len, FLOATFORMAT_CHAR_BIT);
+
+ do
+ {
+ unsigned char *byte_ptr = data + cur_byte;
+ unsigned int bits = hi_bit - lo_bit;
+ unsigned int mask = ((1 << bits) - 1) << lo_bit;
+ *byte_ptr = (*byte_ptr & ~mask) | ((stuff_to_put << lo_bit) & mask);
+ stuff_to_put >>= bits;
+ len -= bits;
+ cur_byte += nextbyte;
+ lo_bit = 0;
+ hi_bit = min (len, FLOATFORMAT_CHAR_BIT);
+ }
+ while (len != 0);
+}
+
+/* The converse: convert the double *FROM to an extended float
+ and store where TO points. Neither FROM nor TO have any alignment
+ restrictions. */
+
+void
+EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat
*fmt,
+ const double *from, void *to)
+{
+ double dfrom;
+ int exponent;
+ double mant;
+ unsigned int mant_bits, mant_off;
+ int mant_bits_left;
+ unsigned char *uto = (unsigned char *) to;
+
+ dfrom = *from;
+ memset (uto, 0, fmt->totalsize / FLOATFORMAT_CHAR_BIT);
+
+ /* If negative, set the sign bit. */
+ if (dfrom < 0)
+ {
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->sign_start, 1, 1);
+ dfrom = -dfrom;
+ }
+
+ if (dfrom == 0)
+ {
+ /* 0.0. */
+ return;
+ }
+
+ if (dfrom != dfrom)
+ {
+ /* NaN. */
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
+ fmt->exp_len, fmt->exp_nan);
+ /* Be sure it's not infinity, but NaN value is irrelevant. */
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->man_start,
+ 32, 1);
+ return;
+ }
+
+ if (dfrom + dfrom == dfrom)
+ {
+ /* This can only happen for an infinite value (or zero, which we
+ already handled above). */
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
+ fmt->exp_len, fmt->exp_nan);
+ return;
+ }
+
+ mant = frexp (dfrom, &exponent);
+ if (exponent + fmt->exp_bias - 1 > 0)
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
+ fmt->exp_len, exponent + fmt->exp_bias - 1);
+ else
+ {
+ /* Handle a denormalized number. FIXME: What should we do for
+ non-IEEE formats? */
+ put_field (uto, fmt->byteorder, fmt->totalsize, fmt->exp_start,
+ fmt->exp_len, 0);
+ mant = ldexp (mant, exponent + fmt->exp_bias - 1);
+ }
+
+ mant_bits_left = fmt->man_len;
+ mant_off = fmt->man_start;
+ while (mant_bits_left > 0)
+ {
+ unsigned long mant_long;
+ mant_bits = mant_bits_left < 32 ? mant_bits_left : 32;
+
+ mant *= 4294967296.0;
+ mant_long = (unsigned long)mant;
+ mant -= mant_long;
+
+ /* If the integer bit is implicit, and we are not creating a
+ denormalized number, then we need to discard it. */
+ if ((unsigned int) mant_bits_left == fmt->man_len
+ && fmt->intbit == floatformat_intbit_no
+ && exponent + fmt->exp_bias - 1 > 0)
+ {
+ mant_long &= 0x7fffffff;
+ mant_bits -= 1;
+ }
+ else if (mant_bits < 32)
+ {
+ /* The bits we want are in the most significant MANT_BITS bits of
+ mant_long. Move them to the least significant. */
+ mant_long >>= 32 - mant_bits;
+ }
+
+ put_field (uto, fmt->byteorder, fmt->totalsize,
+ mant_off, mant_bits, mant_long);
+ mant_off += mant_bits;
+ mant_bits_left -= mant_bits;
+ }
+}
+
+/* Return non-zero iff the data at FROM is a valid number in format FMT. */
+
+int
+EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat
*fmt, const void *from)
+{
+ return fmt->is_valid (fmt, from);
+}
+
+
+#ifdef IEEE_DEBUG
+
+#include <stdio.h>
+
+/* This is to be run on a host which uses IEEE floating point. */
+
+void
+ieee_test (double n)
+{
+ double result;
+
+ floatformat_to_double (&floatformat_ieee_double_little, &n, &result);
+ if ((n != result && (! isnan (n) || ! isnan (result)))
+ || (n < 0 && result >= 0)
+ || (n >= 0 && result < 0))
+ printf ("Differ(to): %.20g -> %.20g\n", n, result);
+
+ floatformat_from_double (&floatformat_ieee_double_little, &n, &result);
+ if ((n != result && (! isnan (n) || ! isnan (result)))
+ || (n < 0 && result >= 0)
+ || (n >= 0 && result < 0))
+ printf ("Differ(from): %.20g -> %.20g\n", n, result);
+
+#if 0
+ {
+ char exten[16];
+
+ floatformat_from_double (&floatformat_m68881_ext, &n, exten);
+ floatformat_to_double (&floatformat_m68881_ext, exten, &result);
+ if (n != result)
+ printf ("Differ(to+from): %.20g -> %.20g\n", n, result);
+ }
+#endif
+
+#if IEEE_DEBUG > 1
+ /* This is to be run on a host which uses 68881 format. */
+ {
+ long double ex = *(long double *)exten;
+ if (ex != n)
+ printf ("Differ(from vs. extended): %.20g\n", n);
+ }
+#endif
+}
+
+int
+main (void)
+{
+ ieee_test (0.0);
+ ieee_test (0.5);
+ ieee_test (256.0);
+ ieee_test (0.12345);
+ ieee_test (234235.78907234);
+ ieee_test (-512.0);
+ ieee_test (-0.004321);
+ ieee_test (1.2E-70);
+ ieee_test (1.2E-316);
+ ieee_test (4.9406564584124654E-324);
+ ieee_test (- 4.9406564584124654E-324);
+ ieee_test (- 0.0);
+ ieee_test (- INFINITY);
+ ieee_test (- NAN);
+ ieee_test (INFINITY);
+ ieee_test (NAN);
+ return 0;
+}
+#endif
Copied: Extractor/src/plugins/old/convert_numeric.h (from rev 23633,
Extractor/src/common/convert_numeric.h)
===================================================================
--- Extractor/src/plugins/old/convert_numeric.h (rev 0)
+++ Extractor/src/plugins/old/convert_numeric.h 2012-09-04 17:51:56 UTC (rev
23639)
@@ -0,0 +1,140 @@
+/* IEEE floating point support declarations, for GDB, the GNU Debugger.
+ Copyright 1991, 1994, 1995, 1997, 2000, 2003, 2005
+ Free Software Foundation, Inc.
+
+This file is part of GDB.
+
+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, write to the Free Software
+Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
USA. */
+
+#if !defined (FLOATFORMAT_H)
+#define FLOATFORMAT_H 1
+
+/*#include "ansidecl.h"*/
+
+/* A floatformat consists of a sign bit, an exponent and a mantissa. Once the
+ bytes are concatenated according to the byteorder flag, then each of those
+ fields is contiguous. We number the bits with 0 being the most significant
+ (i.e. BITS_BIG_ENDIAN type numbering), and specify which bits each field
+ contains with the *_start and *_len fields. */
+
+/* What is the order of the bytes? */
+
+enum EXTRACTOR_floatformat_byteorders {
+ /* Standard little endian byte order.
+ EX: 1.2345678e10 => 00 00 80 c5 e0 fe 06 42 */
+ floatformat_little,
+
+ /* Standard big endian byte order.
+ EX: 1.2345678e10 => 42 06 fe e0 c5 80 00 00 */
+ floatformat_big,
+
+ /* Little endian byte order but big endian word order.
+ EX: 1.2345678e10 => e0 fe 06 42 00 00 80 c5 */
+ floatformat_littlebyte_bigword,
+
+ /* VAX byte order. Little endian byte order with 16-bit words. The
+ following example is an illustration of the byte order only; VAX
+ doesn't have a fully IEEE compliant floating-point format.
+ EX: 1.2345678e10 => 80 c5 00 00 06 42 e0 fe */
+ floatformat_vax
+};
+
+enum EXTRACTOR_floatformat_intbit { floatformat_intbit_yes,
floatformat_intbit_no };
+
+struct EXTRACTOR_floatformat
+{
+ enum EXTRACTOR_floatformat_byteorders byteorder;
+ unsigned int totalsize; /* Total size of number in bits */
+
+ /* Sign bit is always one bit long. 1 means negative, 0 means positive. */
+ unsigned int sign_start;
+
+ unsigned int exp_start;
+ unsigned int exp_len;
+ /* Bias added to a "true" exponent to form the biased exponent. It
+ is intentionally signed as, otherwize, -exp_bias can turn into a
+ very large number (e.g., given the exp_bias of 0x3fff and a 64
+ bit long, the equation (long)(1 - exp_bias) evaluates to
+ 4294950914) instead of -16382). */
+ int exp_bias;
+ /* Exponent value which indicates NaN. This is the actual value stored in
+ the float, not adjusted by the exp_bias. This usually consists of all
+ one bits. */
+ unsigned int exp_nan;
+
+ unsigned int man_start;
+ unsigned int man_len;
+
+ /* Is the integer bit explicit or implicit? */
+ enum EXTRACTOR_floatformat_intbit intbit;
+
+ /* Internal name for debugging. */
+ const char *name;
+
+ /* Validator method. */
+ int (*is_valid) (const struct EXTRACTOR_floatformat *fmt, const void *from);
+};
+
+/* floatformats for IEEE single and double, big and little endian. */
+
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_single_big;
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_single_little;
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_double_big;
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_double_little;
+
+/* floatformat for ARM IEEE double, little endian bytes and big endian words */
+
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ieee_double_littlebyte_bigword;
+
+/* floatformats for VAX. */
+
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_f;
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_d;
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_vax_g;
+
+/* floatformats for various extendeds. */
+
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i387_ext;
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m68881_ext;
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_i960_ext;
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_m88110_ext;
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_m88110_harris_ext;
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_arm_ext_big;
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_arm_ext_littlebyte_bigword;
+/* IA-64 Floating Point register spilt into memory. */
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_spill_big;
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ia64_spill_little;
+extern const struct EXTRACTOR_floatformat EXTRACTOR_floatformat_ia64_quad_big;
+extern const struct EXTRACTOR_floatformat
EXTRACTOR_floatformat_ia64_quad_little;
+
+/* Convert from FMT to a double.
+ FROM is the address of the extended float.
+ Store the double in *TO. */
+
+extern void
+EXTRACTOR_common_floatformat_to_double (const struct EXTRACTOR_floatformat *,
const void *, double *);
+
+/* The converse: convert the double *FROM to FMT
+ and store where TO points. */
+
+extern void
+EXTRACTOR_common_floatformat_from_double (const struct EXTRACTOR_floatformat
*, const double *, void *);
+
+/* Return non-zero iff the data at FROM is a valid number in format FMT. */
+
+extern int
+EXTRACTOR_common_floatformat_is_valid (const struct EXTRACTOR_floatformat
*fmt, const void *from);
+
+#endif /* defined (FLOATFORMAT_H) */
Copied: Extractor/src/plugins/old/pack.c (from rev 23633,
Extractor/src/common/pack.c)
===================================================================
--- Extractor/src/plugins/old/pack.c (rev 0)
+++ Extractor/src/plugins/old/pack.c 2012-09-04 17:51:56 UTC (rev 23639)
@@ -0,0 +1,345 @@
+/*
+Catlib Copyright Notice
+
+The author of this software is Christopher Adam Telfer
+Copyright (c) 1998, 1999, 2000, 2001, 2002
+by Christopher Adam Telfer. All Rights Reserved.
+
+Permission to use, copy, modify, and distribute this software for any
+purpose without fee is hereby granted, provided that the above copyright
+notice, this paragraph, and the following two paragraphs appear in all
+copies, modifications, and distributions.
+
+IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
+ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO
+OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+MODIFICATIONS.
+
+*/
+
+#include "platform.h"
+#include "pack.h"
+
+#if !(defined(_WIN32) && defined(cbNDRContext))
+typedef unsigned char byte;
+#endif
+typedef unsigned short half;
+typedef unsigned int word;
+typedef signed char sbyte;
+typedef signed short shalf;
+typedef signed int sword;
+
+
+
+int
+EXTRACTOR_common_cat_unpack (const void *buf,
+ const char *fmt,
+ ...)
+{
+ va_list ap;
+ word maxlen, len, *wordp;
+ void *arr;
+ byte *bp, *bytep, *newbuf;
+ half *halfp;
+ long long *ll;
+ sbyte *sbytep;
+ shalf *shalfp;
+ sword *swordp;
+ int npacked;
+ unsigned int nreps, i, isnonprefixed = 1; /* used for 'a' types only */
+ struct cat_bvec *cbvp;
+ char *cp;
+
+ bp = (byte *) buf;
+ npacked = 0;
+
+ va_start (ap, fmt);
+
+ while (*fmt)
+ {
+ nreps = 1;
+
+ if (isdigit ( (unsigned char) *fmt))
+ {
+ /* We use cp instead of format to keep the 'const' qualifier of fmt
*/
+ nreps = strtoul (fmt, &cp, 0);
+ fmt = cp;
+ if (*fmt == 'a')
+ isnonprefixed = 0;
+ }
+
+ switch (*fmt)
+ {
+ case 'B':
+ case 'b':
+ bytep = va_arg (ap, byte *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *bytep = *bp++;
+ ++bytep;
+ npacked += 1;
+ }
+ break;
+
+
+
+ case 'h':
+ halfp = va_arg (ap, half *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *halfp = *bp++;
+ *halfp |= *bp++ << 8;
+ ++halfp;
+ npacked += 2;
+ }
+ break;
+
+ case 'H':
+ halfp = va_arg (ap, half *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *halfp = *bp++ << 8;
+ *halfp |= *bp++;
+ ++halfp;
+ npacked += 2;
+ }
+ break;
+
+
+ case 'w':
+ wordp = va_arg (ap, word *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *wordp = *bp++;
+ *wordp |= *bp++ << 8;
+ *wordp |= *bp++ << 16;
+ *wordp |= *bp++ << 24;
+ ++wordp;
+ npacked += 4;
+ }
+ break;
+
+ case 'x':
+ ll = va_arg (ap, long long *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *ll = ((long long) *bp++);
+ *ll |= ((long long) *bp++) << 8;
+ *ll |= ((long long) *bp++) << 16;
+ *ll |= ((long long) *bp++) << 24;
+ *ll |= ((long long) *bp++) << 32;
+ *ll |= ((long long) *bp++) << 40;
+ *ll |= ((long long) *bp++) << 48;
+ *ll |= ((long long) *bp++) << 56;
+ ++ll;
+ npacked += 8;
+ }
+ break;
+
+ case 'W':
+ wordp = va_arg (ap, word *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *wordp = *bp++ << 24;
+ *wordp |= *bp++ << 16;
+ *wordp |= *bp++ << 8;
+ *wordp |= *bp++;
+ ++wordp;
+ npacked += 4;
+ }
+ break;
+
+ case 'X':
+ ll = va_arg (ap, long long *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *ll = ((long long) *bp++) << 56;
+ *ll |= ((long long) *bp++) << 48;
+ *ll |= ((long long) *bp++) << 40;
+ *ll |= ((long long) *bp++) << 32;
+ *ll |= ((long long) *bp++) << 24;
+ *ll |= ((long long) *bp++) << 18;
+ *ll |= ((long long) *bp++) << 8;
+ *ll |= ((long long) *bp++);
+ ++ll;
+ npacked += 8;
+ }
+ break;
+
+
+ case 'A':
+ if (isnonprefixed)
+ {
+ maxlen = va_arg (ap, word);
+ arr = va_arg (ap, void *);
+
+ len = *bp++ << 24;
+ len |= *bp++ << 16;
+ len |= *bp++ << 8;
+ len |= *bp++;
+
+ if (len > maxlen)
+ {
+ va_end (ap);
+ return -1;
+ }
+
+ memmove (arr, bp, len);
+ bp += len;
+
+ npacked += len;
+ }
+ else
+ {
+ cbvp = va_arg (ap, struct cat_bvec *);
+ for (i = 0; i < nreps; ++i)
+ {
+ maxlen = cbvp->len;
+ arr = cbvp->data;
+
+ len = *bp++ << 24;
+ len |= *bp++ << 16;
+ len |= *bp++ << 8;
+ len |= *bp++;
+
+ if (len > maxlen)
+ return -1;
+
+ memmove (arr, bp, len);
+ cbvp->len = len;
+ bp += len;
+
+ ++cbvp;
+ npacked += len;
+ }
+ isnonprefixed = 1;
+ }
+ break;
+
+ case 'C':
+ case 'c':
+ sbytep = va_arg (ap, sbyte *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *sbytep = *bp++;
+
+ if ((sizeof (sbyte) > 1) && (*sbytep & 0x80))
+ *sbytep |= (~0) << ((sizeof (sbyte) - 1) * 8);
+
+ ++sbytep;
+ npacked += 1;
+ }
+ break;
+
+
+ case 's':
+ shalfp = va_arg (ap, shalf *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *shalfp = *bp++;
+ *shalfp |= *bp++ << 8;
+
+ if ((sizeof (shalf) > 2) && (*shalfp & 0x8000))
+ *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8);
+
+ ++shalfp;
+ npacked += 2;
+ }
+ break;
+
+ case 'S':
+ shalfp = va_arg (ap, shalf *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *shalfp = *bp++ << 8;
+ *shalfp |= *bp++;
+
+ if ((sizeof (shalf) > 2) && (*shalfp & 0x8000))
+ *shalfp |= (~0) << ((sizeof (shalf) - 2) * 8);
+
+ ++shalfp;
+ npacked += 2;
+ }
+ break;
+
+ case 'l':
+ swordp = va_arg (ap, sword *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *swordp = *bp++;
+ *swordp |= *bp++ << 8;
+ *swordp |= *bp++ << 16;
+ *swordp |= *bp++ << 24;
+
+ if ((sizeof (swordp) > 4) && (*swordp & 0x80000000))
+ *swordp |= (~0) << ((sizeof (sword) - 4) * 8);
+
+ ++swordp;
+ npacked += 4;
+ }
+ break;
+
+ case 'L':
+ swordp = va_arg (ap, sword *);
+ for (i = 0; i < nreps; ++i)
+ {
+ *swordp = *bp++ << 24;
+ *swordp |= *bp++ << 16;
+ *swordp |= *bp++ << 8;
+ *swordp |= *bp++;
+
+ if ((sizeof (swordp) > 4) && (*swordp & 0x80000000))
+ *swordp |= (~0) << ((sizeof (sword) - 4) * 8);
+
+ ++swordp;
+ npacked += 4;
+ }
+ break;
+
+ case 'P':
+ cbvp = va_arg (ap, struct cat_bvec *);
+ for (i = 0; i < nreps; ++i)
+ {
+ len = *bp++ << 24;
+ len |= *bp++ << 16;
+ len |= *bp++ << 8;
+ len |= *bp++;
+
+ newbuf = (byte *) malloc (len);
+
+ if (!newbuf)
+ {
+ int j;
+ for (j = 0; j < i; j++)
+ free (cbvp[i].data);
+ va_end (ap);
+ return -1;
+ }
+
+ memmove (newbuf, bp, len);
+ cbvp[i].data = newbuf;
+ cbvp[i].len = len;
+
+ bp += len;
+ npacked += len;
+ }
+ break;
+
+ default:
+ va_end (ap);
+ return -1;
+ }
+
+ ++fmt;
+ }
+
+ va_end (ap);
+ return 0;
+}
Copied: Extractor/src/plugins/old/pack.h (from rev 23633,
Extractor/src/common/pack.h)
===================================================================
--- Extractor/src/plugins/old/pack.h (rev 0)
+++ Extractor/src/plugins/old/pack.h 2012-09-04 17:51:56 UTC (rev 23639)
@@ -0,0 +1,62 @@
+/*
+Catlib Copyright Notice
+
+The author of this software is Christopher Adam Telfer
+Copyright (c) 1998, 1999, 2000, 2001, 2002
+by Christopher Adam Telfer. All Rights Reserved.
+
+Permission to use, copy, modify, and distribute this software for any
+purpose without fee is hereby granted, provided that the above copyright
+notice, this paragraph, and the following two paragraphs appear in all
+copies, modifications, and distributions.
+
+IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
+SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
+ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
+THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF
+ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". THE AUTHOR HAS NO
+OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+MODIFICATIONS.
+
+
+*/
+
+#ifndef __CAT_PACK_H
+#define __CAT_PACK_H
+
+/*
+ "bhwAcslPBHWCSL"
+
+ Small letters: do not convert (not implemented for arrays and P)
+ Captial letters: convert from network byte order to host byte order
+
+ b - byte
+ h - half-word
+ w - word
+ a - array (32-byte unsigned long + that many bytes)
+ c - signed 8 bit value
+ s - signed 16 bit value
+ l - signed 32 bit value
+ x - signed 64 bit value
+ p - (unpack only) value is a pointer to a pointer. Generate the buffer
+ to hold the data.
+ */
+int
+EXTRACTOR_common_cat_unpack(const void * buf,
+ const char *fmt,
+ ...);
+
+struct cat_bvec
+{
+ unsigned long len;
+ void * data;
+};
+
+
+#endif /* __CAT_PACK_H */
+
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r23639 - in Extractor/src: common plugins/old,
gnunet <=