+Mon Oct 24 21:24:15 2005 Ben Pfaff <blp@gnu.org>
+
+ Work to get rid of GCC 4.0 warnings, part 2.
+
+ In many files, change `unsigned char' to `char'. This often
+ requires adding casts to <ctype.h> functions.
+
+ * data-in.c: (parse_A) Use buf_copy_rpad().
+
+ * str.c: (str_copy_buf_trunc) New function.
+
+ * value-labels.c: (value_to_string) Fix mistaken use of strncpy(),
+ by rewriting.
+
Mon Oct 24 13:42:32 WST 2005 John Darrington <john@darrington.wattle.id.au>
Moved some definitions to make it easier to abstract a dictionary
const void *target,
algo_compare_func *compare, void *aux)
{
- const unsigned char *element = array;
+ const char *element = array;
while (count-- > 0)
{
const void *element,
algo_compare_func *compare, void *aux)
{
- const unsigned char *first = array;
+ const char *first = array;
size_t equal_cnt = 0;
while (count-- > 0)
count_if (const void *array, size_t count, size_t size,
algo_predicate_func *predicate, void *aux)
{
- const unsigned char *first = array;
+ const char *first = array;
size_t nonzero_cnt = 0;
while (count-- > 0)
size_t nonzero_cnt,
algo_predicate_func *predicate, void *aux)
{
- const unsigned char *first = array;
+ const char *first = array;
size_t idx;
assert (nonzero_cnt <= count);
void *result,
algo_predicate_func *predicate, void *aux)
{
- const unsigned char *input = array;
- const unsigned char *last = input + size * count;
- unsigned char *output = result;
+ const char *input = array;
+ const char *last = input + size * count;
+ char *output = result;
size_t nonzero_cnt = 0;
while (input < last)
void *element,
algo_compare_func *compare, void *aux)
{
- unsigned char *first = array;
- unsigned char *last = first + count * size;
- unsigned char *result;
+ char *first = array;
+ char *last = first + count * size;
+ char *result;
for (;;)
{
if (count != 0)
{
- const unsigned char *first = array;
+ const char *first = array;
int low = 0;
int high = count - 1;
while (low <= high)
{
int middle = (low + high) / 2;
- const unsigned char *element = first + middle * size;
+ const char *element = first + middle * size;
int cmp = compare (value, element, aux);
if (cmp > 0)
size_t size,
algo_compare_func *compare, void *aux)
{
- const unsigned char *first1 = array1;
- const unsigned char *first2 = array2;
+ const char *first1 = array1;
+ const char *first2 = array2;
size_t min_count = count1 < count2 ? count1 : count2;
while (min_count > 0)
is_sorted (const void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux)
{
- const unsigned char *first = array;
+ const char *first = array;
size_t idx;
for (idx = 0; idx + 1 < count; idx++)
void *result_,
algo_compare_func *compare, void *aux)
{
- const unsigned char *first1 = array1;
- const unsigned char *last1 = first1 + count1 * size;
- const unsigned char *first2 = array2;
- const unsigned char *last2 = first2 + count2 * size;
- unsigned char *result = result_;
+ const char *first1 = array1;
+ const char *last1 = first1 + count1 * size;
+ const char *first2 = array2;
+ const char *last2 = first2 + count2 * size;
+ char *result = result_;
size_t result_count = 0;
while (first1 != last1 && first2 != last2)
adjacent_find_equal (const void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux)
{
- const unsigned char *first = array;
- const unsigned char *last = first + count * size;
+ const char *first = array;
+ const char *last = first + count * size;
while (first < last && first + size < last)
{
push_heap (void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux)
{
- unsigned char *first = array;
+ char *first = array;
size_t i;
expensive_assert (count < 1 || is_heap (array, count - 1,
size, compare, aux));
for (i = count; i > 1; i /= 2)
{
- unsigned char *parent = first + (i / 2 - 1) * size;
- unsigned char *element = first + (i - 1) * size;
+ char *parent = first + (i / 2 - 1) * size;
+ char *element = first + (i - 1) * size;
if (compare (parent, element, aux) < 0)
SWAP (parent, element, size);
else
size_t idx,
algo_compare_func *compare, void *aux)
{
- unsigned char *first = array;
+ char *first = array;
for (;;)
{
pop_heap (void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux)
{
- unsigned char *first = array;
+ char *first = array;
expensive_assert (is_heap (array, count, size, compare, aux));
SWAP (first, first + (count - 1) * size, size);
sort_heap (void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux)
{
- unsigned char *first = array;
+ char *first = array;
size_t idx;
expensive_assert (is_heap (array, count, size, compare, aux));
is_heap (const void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux)
{
- const unsigned char *first = array;
+ const char *first = array;
size_t child;
for (child = 2; child <= count; child++)
}
-static unsigned char *s=0;
+static char *s;
static int
ascii_close_global (struct outp_class *this UNUSED)
{
/* ascii_close_page () and support routines. */
#define LINE_BUF_SIZE 1024
-static unsigned char *line_buf;
-static unsigned char *line_p;
+static char *line_buf;
+static char *line_p;
static inline int
commit_line_buf (struct outp_driver *this)
/* Writes CH into line_buf N times, or to THIS->output if line_buf
overflows. */
static inline void
-output_char (struct outp_driver *this, int n, int ch)
+output_char (struct outp_driver *this, int n, char ch)
{
if (LINE_BUF_SIZE - (line_p - line_buf) >= n)
{
}
if (n_passes > 1)
{
- unsigned char ch;
+ char ch;
return_carriage (this, n_chars);
n_chars = 0;
struct ascii_driver_ext *x = this->ext;
int nl_len, ff_len, total_len;
- unsigned char *cp;
+ char *cp;
int i;
assert (this->driver_open && this->page_open);
output_string (this, s, &s[total_len]);
if (line_p != line_buf && !commit_line_buf (this))
- {
- free(s);
- s=0;
return 0;
- }
this->page_open = 0;
return 1;
CASE_INLINE const union value *case_data (const struct ccase *, size_t idx);
CASE_INLINE double case_num (const struct ccase *, size_t idx);
-CASE_INLINE const unsigned char *case_str (const struct ccase *, size_t idx);
+CASE_INLINE const char *case_str (const struct ccase *, size_t idx);
CASE_INLINE union value *case_data_rw (struct ccase *, size_t idx);
return c->case_data->values[idx].f;
}
-static inline const unsigned char *
+static inline const char *
case_str (const struct ccase *c, size_t idx)
{
return c->case_data->values[idx].s;
static void
trim_whitespace (struct data_in *i)
{
- while (i->s < i->e && isspace (i->s[0]))
+ while (i->s < i->e && isspace ((unsigned char) i->s[0]))
i->s++;
- while (i->s < i->e && isspace (i->e[-1]))
+ while (i->s < i->e && isspace ((unsigned char) i->e[-1]))
i->e--;
}
exponent = 0;
for (; have_char (i); i->s++)
{
- if (isdigit (*i->s))
+ if (isdigit ((unsigned char) *i->s))
{
digit_cnt++;
/* Get the exponent specified after the `e' or `E'. */
long exp;
- if (isalpha (*i->s))
+ if (isalpha ((unsigned char) *i->s))
i->s++;
if (!parse_int (i, &exp))
{
static inline bool
parse_N (struct data_in *i)
{
- const unsigned char *cp;
+ const char *cp;
i->v->f = 0;
for (cp = i->s; cp < i->e; cp++)
{
- if (!isdigit (*cp))
+ if (!isdigit ((unsigned char) *cp))
{
dls_error (i, _("All characters in field must be digits."));
return false;
}
- i->v->f = i->v->f * 10.0 + *cp - '0';
+ i->v->f = i->v->f * 10.0 + (*cp - '0');
}
apply_implied_decimals (i);
parse_PIBHEX (struct data_in *i)
{
double n;
- const unsigned char *cp;
+ const char *cp;
trim_whitespace (i);
n = 0.0;
for (cp = i->s; cp < i->e; cp++)
{
- if (!isxdigit (*cp))
+ if (!isxdigit ((unsigned char) *cp))
{
dls_error (i, _("Unrecognized character in field."));
return false;
}
{
- const unsigned char *cp;
+ const char *cp;
for (cp = i->s; cp < i->e; cp++)
- if (!isxdigit (*cp))
+ if (!isxdigit ((unsigned char) *cp))
{
dls_error (i, _("Field must contain only hex digits."));
return false;
/* Copy digits into buf[1 ... len - 1] and terminate string. */
{
- const unsigned char *sp;
+ const char *sp;
char *dp;
for (sp = i->s, dp = buf + 1; sp < i->e - 1; sp++, dp++)
{
char *tail;
- i->v->f = strtod ((char *) buf, (char **) &tail);
- if ((unsigned char *) tail != i->e)
+ i->v->f = strtod (buf, &tail);
+ if (tail != i->e)
{
dls_error (i, _("Error in syntax of zoned decimal number."));
return false;
#ifndef WORDS_BIGENDIAN
char buf[64];
#endif
- const char *p;
+ const unsigned char *p;
unsigned char xor;
/* We want the data to be in big-endian format. If this is a
little-endian machine, reverse the byte order. */
#ifdef WORDS_BIGENDIAN
- p = i->s;
+ p = (const unsigned char *) i->s;
#else
memcpy (buf, i->s, i->e - i->s);
buf_reverse (buf, i->e - i->s);
- p = buf;
+ p = (const unsigned char *) buf;
#endif
/* If the value is negative, we need to logical-NOT each value
i->v->f = 0.0;
#if WORDS_BIGENDIAN
for (j = 0; j < i->e - i->s; j++)
- i->v->f = i->v->f * 256.0 + i->s[j];
+ i->v->f = i->v->f * 256.0 + (unsigned char) i->s[j];
#else
for (j = i->e - i->s - 1; j >= 0; j--)
- i->v->f = i->v->f * 256.0 + i->s[j];
+ i->v->f = i->v->f * 256.0 + (unsigned char) i->s[j];
#endif
apply_implied_decimals (i);
static inline bool
parse_P (struct data_in *i)
{
- const unsigned char *cp;
+ const char *cp;
i->v->f = 0.0;
for (cp = i->s; cp < i->e - 1; cp++)
{
- i->v->f = i->v->f * 10 + (*cp >> 4);
+ i->v->f = i->v->f * 10 + ((*cp >> 4) & 15);
i->v->f = i->v->f * 10 + (*cp & 15);
}
- i->v->f = i->v->f * 10 + (*cp >> 4);
+ i->v->f = i->v->f * 10 + ((*cp >> 4) & 15);
if ((*cp ^ (*cp >> 1)) & 0x10)
i->v->f = -i->v->f;
static inline bool
parse_PK (struct data_in *i)
{
- const unsigned char *cp;
+ const char *cp;
i->v->f = 0.0;
for (cp = i->s; cp < i->e; cp++)
{
- i->v->f = i->v->f * 10 + (*cp >> 4);
+ i->v->f = i->v->f * 10 + ((*cp >> 4) & 15);
i->v->f = i->v->f * 10 + (*cp & 15);
}
u;
memset (u.c, 0, sizeof u.c);
- memcpy (u.c, i->s, min ((int) sizeof (u.c), i->e - i->s));
+ memcpy (u.c, i->s, min (sizeof u.c, (size_t) (i->e - i->s)));
i->v->f = u.d;
return true;
static inline bool
parse_A (struct data_in *i)
{
- ptrdiff_t len = i->e - i->s;
-
- if (len >= i->format.w)
- memcpy (i->v->s, i->s, i->format.w);
- else
- {
- memcpy (i->v->s, i->s, len);
- memset (i->v->s + len, ' ', i->format.w - len);
- }
-
+ buf_copy_rpad (i->v->s, i->format.w, i->s, i->e - i->s);
return true;
}
}
{
- const unsigned char *cp;
+ const char *cp;
for (cp = i->s; cp < i->e; cp++)
- if (!isxdigit (*cp))
+ if (!isxdigit ((unsigned char) *cp))
{
dls_error (i, _("Field must contain only hex digits."));
return false;
force_have_char (i);
}
- if (!isdigit (*i->s))
+ if (!isdigit ((unsigned char) *i->s))
{
dls_error (i, _("Digit expected in field."));
return false;
*result = 0;
for (;;)
{
- *result = *result * 10 + *i->s++ - '0';
- if (!have_char (i) || !isdigit (*i->s))
+ *result = *result * 10 + (*i->s++ - '0');
+ if (!have_char (i) || !isdigit ((unsigned char) *i->s))
break;
}
bool delim = false;
while (have_char (i)
- && (*i->s == '-' || *i->s == '/' || isspace (*i->s)
+ && (*i->s == '-' || *i->s == '/' || isspace ((unsigned char) *i->s)
|| *i->s == '.' || *i->s == ','))
{
delim = true;
/* Consume alphabetic characters. */
name = i->s;
length = 0;
- while (have_char (i) && isalpha (*i->s))
+ while (have_char (i) && isalpha ((unsigned char) *i->s))
{
length++;
i->s++;
if (!force_have_char (i))
return false;
- if (isdigit (*i->s))
+ if (isdigit ((unsigned char) *i->s))
{
if (!parse_int (i, month))
return false;
parse_q_delimiter (struct data_in *i)
{
skip_whitespace (i);
- if (!have_char (i) || tolower (*i->s) != 'q')
+ if (!have_char (i) || tolower ((unsigned char) *i->s) != 'q')
{
dls_error (i, _("`Q' expected between quarter and year."));
return false;
{
skip_whitespace (i);
if (i->s + 1 >= i->e
- || tolower (i->s[0]) != 'w' || tolower (i->s[1]) != 'k')
+ || tolower ((unsigned char) i->s[0]) != 'w'
+ || tolower ((unsigned char) i->s[1]) != 'k')
{
dls_error (i, _("`WK' expected between week and year."));
return false;
{
bool delim = false;
- while (have_char (i) && (*i->s == ':' || *i->s == '.' || isspace (*i->s)))
+ while (have_char (i) && (*i->s == ':' || *i->s == '.'
+ || isspace ((unsigned char) *i->s)))
{
delim = true;
i->s++;
char *cp;
while (have_char (i)
- && (*i->s == ':' || *i->s == '.' || isspace (*i->s)))
+ && (*i->s == ':' || *i->s == '.' || isspace ((unsigned char) *i->s)))
{
delim = true;
i->s++;
}
- if (!delim || !isdigit (*i->s))
+ if (!delim || !isdigit ((unsigned char) *i->s))
{
*second = 0.0;
return true;
}
cp = buf;
- while (have_char (i) && isdigit (*i->s))
+ while (have_char (i) && isdigit ((unsigned char) *i->s))
*cp++ = *i->s++;
if (have_char (i) && *i->s == '.')
*cp++ = *i->s++;
- while (have_char (i) && isdigit (*i->s))
+ while (have_char (i) && isdigit ((unsigned char) *i->s))
*cp++ = *i->s++;
*cp = '\0';
if (fmt->cat & FCAT_BLANKS_SYSMIS)
{
- const unsigned char *cp;
+ const char *cp;
cp = i->s;
for (;;)
{
- if (!isspace (*cp))
+ if (!isspace ((unsigned char) *cp))
break;
if (++cp == i->e)
/* Information about parsing one data field. */
struct data_in
{
- const unsigned char *s; /* Source start. */
- const unsigned char *e; /* Source end. */
+ const char *s; /* Source start. */
+ const char *e; /* Source end. */
union value *v; /* Destination. */
static void
scan_badchars (char *line, int len)
{
- unsigned char *cp = line;
+ char *cp = line;
/* Same bad characters as Groff. */
static unsigned char badchars[32] =
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
- for (; len--; cp++)
- if (badchars[*cp >> 3] & (1 << (*cp & 7)))
- {
- font_msg (SE, _("Bad character \\%3o."), *cp);
- *cp = ' ';
- }
+ for (; len--; cp++)
+ {
+ int c = (unsigned char) *cp;
+ if (badchars[c >> 3] & (1 << (c & 7)))
+ {
+ font_msg (SE, _("Bad character \\%3o."), *cp);
+ *cp = ' ';
+ }
+ }
}
\f
/* Character name hashing. */
unsigned
hsh_hash_bytes (const void *buf_, size_t size)
{
- const unsigned char *buf = buf_;
+ const unsigned char *buf = (const unsigned char *) buf_;
unsigned hash;
assert (buf != NULL);
unsigned
hsh_hash_string (const char *s_)
{
- const unsigned char *s = s_;
+ const unsigned char *s = (const unsigned char *) s_;
unsigned hash;
assert (s != NULL);
unsigned
hsh_hash_case_string (const char *s_)
{
- const unsigned char *s = s_;
+ const unsigned char *s = (const unsigned char *) s_;
unsigned hash;
assert (s != NULL);
len--;
/* Check for and remove terminal dot. */
- if (len > 0 && s[len - 1] == get_endcmd() )
+ if (len > 0 && s[len - 1] == get_endcmd ())
{
dot = 1;
len--;
missing values. (Long string variables never accept missing
values.) */
bool
-mv_add_str (struct missing_values *mv, const unsigned char s[])
+mv_add_str (struct missing_values *mv, const char s[])
{
assert (mv->width > 0);
return mv_add_value (mv, (union value *) s);
NEW_WIDTH (inclusive) and OLD_WIDTH (exclusive),
false otherwise. */
static bool
-can_resize_string (const unsigned char *s, int old_width, int new_width)
+can_resize_string (const char *s, int old_width, int new_width)
{
int i;
MV must be a set of string missing values.
S[] must contain exactly as many characters as MV's width. */
bool
-mv_is_str_missing (const struct missing_values *mv,
- const unsigned char s[])
+mv_is_str_missing (const struct missing_values *mv, const char s[])
{
return mv_is_str_user_missing (mv, s);
}
S[] must contain exactly as many characters as MV's width. */
bool
mv_is_str_user_missing (const struct missing_values *mv,
- const unsigned char s[])
+ const char s[])
{
const union value *v = mv->values;
assert (mv->width > 0);
int mv_get_width (const struct missing_values *);
bool mv_add_value (struct missing_values *, const union value *);
-bool mv_add_str (struct missing_values *, const unsigned char[]);
+bool mv_add_str (struct missing_values *, const char[]);
bool mv_add_num (struct missing_values *, double);
bool mv_add_num_range (struct missing_values *, double low, double high);
/* Is a value system or user missing? */
bool mv_is_value_missing (const struct missing_values *, const union value *);
bool mv_is_num_missing (const struct missing_values *, double);
-bool mv_is_str_missing (const struct missing_values *, const unsigned char[]);
+bool mv_is_str_missing (const struct missing_values *, const char[]);
/* Is a value user missing? */
bool mv_is_value_user_missing (const struct missing_values *,
const union value *);
bool mv_is_num_user_missing (const struct missing_values *, double);
-bool mv_is_str_user_missing (const struct missing_values *,
- const unsigned char[]);
+bool mv_is_str_user_missing (const struct missing_values *, const char[]);
/* Is a value system missing? */
bool mv_is_value_system_missing (const struct missing_values *,
- const union value *);
+ const union value *);
#endif /* missing-values.h */
struct file_handle *fh; /* File handle. */
FILE *file; /* File stream. */
char cc; /* Current character. */
- unsigned char *trans; /* 256-byte character set translation table. */
-
+ char *trans; /* 256-byte character set translation table. */
int var_cnt; /* Number of variables. */
int weight_index; /* 0-based index of weight variable, or -1. */
int *widths; /* Variable widths, 0 for numeric. */
/* Reads a string and returns a copy of it allocated from R's
pool. */
-static unsigned char *
+static char *
read_pool_string (struct pfm_reader *r)
{
char string[256];
{
/* portable_to_local[PORTABLE] translates the given portable
character into the local character set. */
- static const unsigned char portable_to_local[256] =
+ static const char portable_to_local[256] =
{
" "
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ."
" "
};
- unsigned char *trans;
+ char *trans;
int i;
/* Read and ignore vanity splash strings. */
static void
read_version_data (struct pfm_reader *r, struct pfm_read_info *info)
{
+ static char empty_string[] = "";
char *date, *time, *product, *author, *subproduct;
int i;
error (r, "Unrecognized version code `%c'.", r->cc);
date = read_pool_string (r);
time = read_pool_string (r);
- product = match (r, '1') ? read_pool_string (r) : (unsigned char *) "";
- author = match (r, '2') ? read_pool_string (r) : (unsigned char *) "";
- subproduct
- = match (r, '3') ? read_pool_string (r) : (unsigned char *) "";
+ product = match (r, '1') ? read_pool_string (r) : empty_string;
+ author = match (r, '2') ? read_pool_string (r) : empty_string;
+ subproduct = match (r, '3') ? read_pool_string (r) : empty_string;
/* Validate file. */
if (strlen (date) != 8)
{
/* PORTME: Translation table from SPSS character code to this
computer's native character code (which is probably ASCII). */
- static const unsigned char spss2ascii[256] =
+ static const char spss2ascii[256] =
{
"0000000000000000000000000000000000000000000000000000000000000000"
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ."
const char *sp;
for (sp = string; *sp; sp++)
- switch (*(unsigned char *) sp)
+ switch (*sp)
{
case 'a':
case 'f':
*dp++ = '<';
for (sp = string; *sp && dp < &dest[256]; sp++)
{
- sprintf (dp, "%02x", *(unsigned char *) sp);
+ sprintf (dp, "%02x", (unsigned char) *sp);
dp += 2;
}
return stpcpy (dp, ">cvn");
dp = stpcpy (dp, "\\(");
else if (*sp == ')')
dp = stpcpy (dp, "\\)");
- else if (*sp < 32 || *((unsigned char *) sp) > 127)
+ else if (*sp < 32 || (unsigned char) *sp > 127)
dp = spprintf (dp, "\\%3o", *sp);
else
*dp++ = *sp;
if (TEST_BIT (literal_chars[ext->data], cp->ch))
*lp++ = cp->ch;
else
- switch (cp->ch)
+ switch ((char) cp->ch)
{
case '(':
lp = stpcpy (lp, "\\(");
else
{
for (i = mark; i < rcd->nmap; i++)
- rcd->map[i].t.c = (output.c?xstrdup (output.c):NULL);
+ rcd->map[i].t.c = output.c ? xstrdup (output.c) : NULL;
free (output.c);
}
}
}
}
if (dot)
- ds_putc (&output, get_endcmd() );
+ ds_putc (&output, get_endcmd ());
ds_destroy (&getl_buf);
getl_buf = output;
return (cmd.inc != STC_OFF );
}
-unsigned char
+char
get_endcmd(void)
{
return cmd.s_endcmd[0];
int get_nullline(void);
/* The character used to terminate commands. */
-unsigned char get_endcmd(void);
+char get_endcmd(void);
/* Approximate maximum amount of memory to use for cases, in
bytes. */
/* Swap bytes *A and *B. */
static inline void
-bswap (unsigned char *a, unsigned char *b)
+bswap (char *a, char *b)
{
- unsigned char t = *a;
+ char t = *a;
*a = *b;
*b = t;
}
static inline void
bswap_int32 (int32 *x_)
{
- unsigned char *x = (unsigned char *) x_;
+ char *x = (char *) x_;
bswap (x + 0, x + 3);
bswap (x + 1, x + 2);
}
static inline void
bswap_flt64 (flt64 *x_)
{
- unsigned char *x = (unsigned char *) x_;
+ char *x = (char *) x_;
bswap (x + 0, x + 7);
bswap (x + 1, x + 6);
bswap (x + 2, x + 5);
if (vv->type == NUMERIC)
mv_add_num (&vv->miss, mv[j]);
else
- mv_add_str (&vv->miss, (unsigned char *) &mv[j]);
+ mv_add_str (&vv->miss, (char *) &mv[j]);
}
else
{
{
struct label
{
- unsigned char raw_value[8]; /* Value as uninterpreted bytes. */
+ char raw_value[8]; /* Value as uninterpreted bytes. */
union value value; /* Value. */
char *label; /* Null-terminated label string. */
};
if (var[0]->type == ALPHA)
{
- const int copy_len = min (sizeof (label->raw_value),
- sizeof (label->label));
+ const int copy_len = min (sizeof label->raw_value,
+ sizeof label->label);
memcpy (label->value.s, label->raw_value, copy_len);
} else {
flt64 f;
*loc++ = vl->value.f;
*(unsigned char *) loc = len;
- memcpy (&((unsigned char *) loc)[1], vl->label, len);
- memset (&((unsigned char *) loc)[1 + len], ' ',
+ memcpy (&((char *) loc)[1], vl->label, len);
+ memset (&((char *) loc)[1 + len], ' ',
REM_RND_UP (len + 1, sizeof (flt64)));
loc += DIV_RND_UP (len + 1, sizeof (flt64));
}
void
buf_reverse (char *p, size_t nbytes)
{
- unsigned char *h = p, *t = &h[nbytes - 1];
- unsigned char temp;
+ char *h = p, *t = &h[nbytes - 1];
+ char temp;
nbytes /= 2;
while (nbytes--)
}
}
+/* Copies buffer SRC, of SRC_LEN bytes,
+ to DST, which is in a buffer DST_SIZE bytes long.
+ Truncates DST to DST_SIZE - 1 characters, if necessary. */
+void
+str_copy_buf_trunc (char *dst, size_t dst_size,
+ const char *src, size_t src_size)
+{
+ size_t dst_len;
+ assert (dst_size > 0);
+
+ dst_len = src_size < dst_size ? src_size : dst_size - 1;
+ memcpy (dst, src, dst_len);
+ dst[dst_len] = '\0';
+}
+
/* Converts each character in S to uppercase. */
void
str_uppercase (char *s)
int str_compare_rpad (const char *, const char *);
void str_copy_rpad (char *, size_t, const char *);
void str_copy_trunc (char *, size_t, const char *);
+void str_copy_buf_trunc (char *, size_t, const char *, size_t);
void str_uppercase (char *);
\f
/* Fixed-length strings. */
double f;
/* A short-string value. */
- unsigned char s[MAX_SHORT_STRING];
+ char s[MAX_SHORT_STRING];
/* Used by evaluate_expression() to return a string result.
As currently implemented, it's a pointer to a dynamic
Also used by the AGGREGATE procedure in handling string
values. */
- unsigned char *c;
+ char *c;
};
/* Maximum number of `union value's in a single number or string
else format it and return the formatted string
*/
const char *
-value_to_string(const union value *val, const struct variable *var)
+value_to_string (const union value *val, const struct variable *var)
{
- static char buf[100];
char *s;
- const struct val_labs *val_labs ;
- if ( !val || ! var )
- return 0;
-
- val_labs = var->val_labs;
-
-
- s = val_labs_find (val_labs, *val);
+ assert (val != NULL);
+ assert (var != NULL);
- if ( s )
- return s;
-
- if ( 0 == var->width )
- snprintf(buf,100,"%g",val->f);
- else
+ s = val_labs_find (var->val_labs, *val);
+ if (s == NULL)
{
- strncpy(buf,val->s,MAX_SHORT_STRING);
- strcat(buf,"\0");
+ static char buf[256];
+ if (var->width != 0)
+ str_copy_buf_trunc (buf, sizeof buf, val->s, var->width);
+ else
+ snprintf(buf, 100, "%g", val->f);
+ s = buf;
}
- return buf;
+
+ return s;
}