X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Finteger-format.c;h=c248e0ff042b8c765ebe5724d3aa82d7e278a76c;hb=81579d9e9f994fb2908f50af41c3eb033d216e58;hp=1d0a4cfc89c9e27debae25c7a56963985a02ec45;hpb=480a0746507ce73d26f528b56dc3ed80195096e0;p=pspp-builds.git diff --git a/src/libpspp/integer-format.c b/src/libpspp/integer-format.c index 1d0a4cfc..c248e0ff 100644 --- a/src/libpspp/integer-format.c +++ b/src/libpspp/integer-format.c @@ -1,30 +1,28 @@ -/* PSPP - computes sample statistics. - Copyright (C) 2006 Free Software Foundation, Inc. +/* PSPP - a program for statistical analysis. + Copyright (C) 2006, 2010, 2011 Free Software Foundation, Inc. - 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 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 3 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. + 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. */ + along with this program. If not, see . */ #include -#include +#include "libpspp/integer-format.h" #include /* Returns true if FORMAT is a valid integer format. */ static inline bool -is_integer_format (enum integer_format format) +is_integer_format (enum integer_format format) { return (format == INTEGER_MSB_FIRST || format == INTEGER_LSB_FIRST @@ -34,11 +32,11 @@ is_integer_format (enum integer_format format) /* Converts the CNT bytes in INTEGER from SRC integer_format to DST integer_format. */ void -integer_convert (enum integer_format src, const void *from, +integer_convert (enum integer_format src, const void *from, enum integer_format dst, void *to, size_t cnt) { - if (src != dst) + if (src != dst) integer_put (integer_get (src, from, cnt), dst, to, cnt); else if (from != to) memcpy (to, from, cnt); @@ -52,11 +50,11 @@ integer_get (enum integer_format format, const void *from_, size_t cnt) const uint8_t *from = from_; uint64_t value = 0; size_t i; - + assert (is_integer_format (format)); - assert (cnt < 8); + assert (cnt <= 8); - switch (format) + switch (format) { case INTEGER_MSB_FIRST: for (i = 0; i < cnt; i++) @@ -89,14 +87,14 @@ integer_put (uint64_t value, enum integer_format format, void *to_, size_t cnt) assert (cnt < 8); value <<= 8 * (8 - cnt); - - switch (format) + + switch (format) { case INTEGER_MSB_FIRST: - for (i = 0; i < cnt; i++) + for (i = 0; i < cnt; i++) { to[i] = value >> 56; - value <<= 8; + value <<= 8; } break; case INTEGER_LSB_FIRST: @@ -107,10 +105,10 @@ integer_put (uint64_t value, enum integer_format format, void *to_, size_t cnt) } break; case INTEGER_VAX: - for (i = 0; i < (cnt & ~1); i++) + for (i = 0; i < (cnt & ~1); i++) { to[i ^ 1] = value >> 56; - value <<= 8; + value <<= 8; } if (cnt & 1) to[cnt - 1] = value >> 56; @@ -121,7 +119,7 @@ integer_put (uint64_t value, enum integer_format format, void *to_, size_t cnt) /* Returns true if bytes with index IDX1 and IDX2 in VALUE differ in value. */ static inline bool -bytes_differ (uint64_t value, unsigned int idx1, unsigned int idx2) +bytes_differ (uint64_t value, unsigned int idx1, unsigned int idx2) { uint8_t byte1 = value >> (idx1 * 8); uint8_t byte2 = value >> (idx2 * 8); @@ -138,7 +136,7 @@ integer_identify (uint64_t expected_value, const void *integer, size_t length, { /* Odd-length integers are confusing. */ assert (length % 2 == 0); - + /* LENGTH must be greater than 2 because VAX format is equivalent to little-endian for 2-byte integers. */ assert (length > 2);