X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Ftests%2Ffloat-format.c;h=b2d5a1663f0808a8a6b9a6f09a3527eea61c3b24;hb=c75794cffb05769b71a346af8513a3e8dde55f94;hp=fab8d81653dfcabf0ad435455165794aaef3657d;hpb=480a0746507ce73d26f528b56dc3ed80195096e0;p=pspp
diff --git a/src/language/tests/float-format.c b/src/language/tests/float-format.c
index fab8d81653..b2d5a1663f 100644
--- a/src/language/tests/float-format.c
+++ b/src/language/tests/float-format.c
@@ -1,20 +1,18 @@
-/* PSPP - computes sample statistics.
+/* PSPP - a program for statistical analysis.
Copyright (C) 2006 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
@@ -42,14 +40,14 @@ struct fp
};
/* Associates a format name with its identifier. */
-struct assoc
+struct assoc
{
char name[4];
enum float_format format;
};
/* List of floating-point formats. */
-static const struct assoc fp_formats[] =
+static const struct assoc fp_formats[] =
{
{"ISL", FLOAT_IEEE_SINGLE_LE},
{"ISB", FLOAT_IEEE_SINGLE_BE},
@@ -68,12 +66,12 @@ static const size_t format_cnt = sizeof fp_formats / sizeof *fp_formats;
/* Parses a floating-point format name into *FORMAT,
and returns success. */
static bool
-parse_float_format (struct lexer *lexer, enum float_format *format)
+parse_float_format (struct lexer *lexer, enum float_format *format)
{
size_t i;
for (i = 0; i < format_cnt; i++)
- if (lex_match_id (lexer, fp_formats[i].name))
+ if (lex_match_id (lexer, fp_formats[i].name))
{
*format = fp_formats[i].format;
return true;
@@ -84,12 +82,12 @@ parse_float_format (struct lexer *lexer, enum float_format *format)
/* Returns the name for the given FORMAT. */
static const char *
-get_float_format_name (enum float_format format)
+get_float_format_name (enum float_format format)
{
size_t i;
for (i = 0; i < format_cnt; i++)
- if (fp_formats[i].format == format)
+ if (fp_formats[i].format == format)
return fp_formats[i].name;
NOT_REACHED ();
@@ -100,9 +98,9 @@ get_float_format_name (enum float_format format)
representation. Also supports ordinary floating-point numbers
written in decimal notation. Returns success. */
static bool
-parse_fp (struct lexer *lexer, struct fp *fp)
+parse_fp (struct lexer *lexer, struct fp *fp)
{
- if (lex_is_number (lexer))
+ if (lex_is_number (lexer))
{
double number = lex_number (lexer);
fp->format = FLOAT_NATIVE_DOUBLE;
@@ -112,32 +110,33 @@ parse_fp (struct lexer *lexer, struct fp *fp)
else if (lex_token (lexer) == T_ID)
{
size_t length;
-
+
if (!parse_float_format (lexer, &fp->format)
|| !lex_force_match (lexer, '(')
|| !lex_force_string (lexer))
return false;
length = ds_length (lex_tokstr (lexer));
- if (fp->format != FLOAT_HEX)
+ if (fp->format != FLOAT_HEX)
{
- if (length != float_get_size (fp->format))
+ if (length != float_get_size (fp->format))
{
- msg (SE, _("%d-byte string needed but %d-byte string supplied."),
- (int) float_get_size (fp->format), (int) length);
+ msg (SE, _("%zu-byte string needed but %zu-byte string "
+ "supplied."),
+ float_get_size (fp->format), length);
return false;
}
assert (length <= sizeof fp->data);
- memcpy (fp->data, ds_data (lex_tokstr (lexer)), length);
+ memcpy (fp->data, ds_data (lex_tokstr (lexer)), length);
}
- else
+ else
{
- if (length >= sizeof fp->data)
+ if (length >= sizeof fp->data)
{
msg (SE, _("Hexadecimal floating constant too long."));
return false;
}
- strncpy ((char *) fp->data, ds_cstr (lex_tokstr (lexer)), sizeof fp->data);
+ strncpy (CHAR_CAST_BUG (char *,fp->data), ds_cstr (lex_tokstr (lexer)), sizeof fp->data);
}
lex_get (lexer);
@@ -158,20 +157,20 @@ parse_fp (struct lexer *lexer, struct fp *fp)
must be be large enough to hold the output. */
static void
make_printable (enum float_format format, const void *src_, size_t src_size,
- char *dst, size_t dst_size)
+ char *dst, size_t dst_size)
{
assert (dst_size >= 2 * src_size + 1);
- if (format != FLOAT_HEX)
+ if (format != FLOAT_HEX)
{
const uint8_t *src = src_;
- while (src_size-- > 0)
+ while (src_size-- > 0)
{
sprintf (dst, "%02x", *src++);
dst += 2;
}
- *dst = '\0';
+ *dst = '\0';
}
- else
+ else
strncpy (dst, src_, src_size + 1);
}
@@ -182,7 +181,7 @@ make_printable (enum float_format format, const void *src_, size_t src_size,
returns true. */
static bool
mismatch (const struct fp *from, const struct fp *to, char *result,
- const char *conversion_type)
+ const char *conversion_type)
{
size_t to_size = float_get_size (to->format);
if (!memcmp (to->data, result, to_size))
@@ -212,15 +211,15 @@ mismatch (const struct fp *from, const struct fp *to, char *result,
/* Checks that converting FROM into the format of TO yields
exactly the data in TO. */
static bool
-verify_conversion (const struct fp *from, const struct fp *to)
+verify_conversion (const struct fp *from, const struct fp *to)
{
char tmp1[FP_MAX_SIZE], tmp2[FP_MAX_SIZE];
-
+
/* First try converting directly. */
float_convert (from->format, from->data, to->format, tmp1);
if (mismatch (from, to, tmp1, "Direct"))
return false;
-
+
/* Then convert via FLOAT_FP to prevent short-circuiting that
float_convert() does for some conversions (e.g. little<->big
endian for IEEE formats). */
@@ -228,13 +227,13 @@ verify_conversion (const struct fp *from, const struct fp *to)
float_convert (FLOAT_FP, tmp1, to->format, tmp2);
if (mismatch (from, to, tmp2, "Indirect"))
return false;
-
+
return true;
}
/* Executes the DEBUG FLOAT FORMAT command. */
int
-cmd_debug_float_format (struct lexer *lexer, struct dataset *ds UNUSED)
+cmd_debug_float_format (struct lexer *lexer, struct dataset *ds UNUSED)
{
struct fp fp[16];
size_t fp_cnt = 0;
@@ -243,7 +242,7 @@ cmd_debug_float_format (struct lexer *lexer, struct dataset *ds UNUSED)
for (;;)
{
- if (fp_cnt >= sizeof fp / sizeof *fp)
+ if (fp_cnt >= sizeof fp / sizeof *fp)
{
msg (SE, _("Too many values in single command."));
return CMD_FAILURE;
@@ -255,20 +254,20 @@ cmd_debug_float_format (struct lexer *lexer, struct dataset *ds UNUSED)
break;
else if (!lex_force_match (lexer, '='))
return CMD_FAILURE;
-
- if (fp_cnt == 1)
+
+ if (fp_cnt == 1)
{
if (lex_match (lexer, '='))
bijective = true;
else if (lex_match (lexer, T_GT))
bijective = false;
- else
+ else
{
lex_error (lexer, NULL);
return CMD_FAILURE;
}
}
- else
+ else
{
if ((bijective && !lex_force_match (lexer, '='))
|| (!bijective && !lex_force_match (lexer, T_GT)))
@@ -277,16 +276,16 @@ cmd_debug_float_format (struct lexer *lexer, struct dataset *ds UNUSED)
}
ok = true;
- if (bijective)
+ if (bijective)
{
size_t i, j;
for (i = 0; i < fp_cnt; i++)
for (j = 0; j < fp_cnt; j++)
- if (!verify_conversion (&fp[i], &fp[j]))
+ if (!verify_conversion (&fp[i], &fp[j]))
ok = false;
}
- else
+ else
{
size_t i;