trunc \
unilbrk/ulc-width-linebreaks \
unistd \
+ unistr/u8-strlen \
unlocked-io \
vasprintf-posix \
vfprintf-posix \
Like the strings embedded in all "union value"s, the return
value is not null-terminated. */
-const char *
+const uint8_t *
case_str (const struct ccase *c, const struct variable *v)
{
size_t idx = var_get_case_index (v);
Like the strings embedded in all "union value"s, the return
value is not null-terminated. */
-const char *
+const uint8_t *
case_str_idx (const struct ccase *c, size_t idx)
{
assert (idx < c->proto->n_widths);
Like the strings embedded in all "union value"s, the return
value is not null-terminated. */
-char *
+uint8_t *
case_str_rw (struct ccase *c, const struct variable *v)
{
size_t idx = var_get_case_index (v);
Like the strings embedded in all "union value"s, the return
value is not null-terminated. */
-char *
+uint8_t *
case_str_rw_idx (struct ccase *c, size_t idx)
{
assert (idx < c->proto->n_widths);
double case_num (const struct ccase *, const struct variable *);
double case_num_idx (const struct ccase *, size_t idx);
-const char *case_str (const struct ccase *, const struct variable *);
-const char *case_str_idx (const struct ccase *, size_t idx);
-char *case_str_rw (struct ccase *, const struct variable *);
-char *case_str_rw_idx (struct ccase *, size_t idx);
+const uint8_t *case_str (const struct ccase *, const struct variable *);
+const uint8_t *case_str_idx (const struct ccase *, size_t idx);
+uint8_t *case_str_rw (struct ccase *, const struct variable *);
+uint8_t *case_str_rw_idx (struct ccase *, size_t idx);
int case_compare (const struct ccase *, const struct ccase *,
const struct variable *const *, size_t n_vars);
{
/* This is equivalent to buf_copy_rpad, except that we posibly
do a character set recoding in the middle. */
- char *dst = value_str_rw (i->output, i->width);
+ uint8_t *dst = value_str_rw (i->output, i->width);
size_t dst_size = i->width;
const char *src = ss_data (i->input);
size_t src_size = ss_length (i->input);
static bool
parse_AHEX (struct data_in *i)
{
- char *s = value_str_rw (i->output, i->width);
+ uint8_t *s = value_str_rw (i->output, i->width);
size_t j;
for (j = 0; ; j++)
Returns true if successful, false if MV has no more room for
missing values or if S is not an acceptable missing value. */
bool
-mv_add_str (struct missing_values *mv, const char s[])
+mv_add_str (struct missing_values *mv, const uint8_t s[])
{
union value v;
bool ok;
MV must be a set of string missing values.
S[] must contain exactly as many characters as MV's width. */
static bool
-is_str_user_missing (const struct missing_values *mv, const char s[])
+is_str_user_missing (const struct missing_values *mv, const uint8_t s[])
{
const union value *v = mv->values;
assert (mv->width > 0);
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 char s[],
+mv_is_str_missing (const struct missing_values *mv, const uint8_t s[],
enum mv_class class)
{
assert (mv->width > 0);
bool mv_is_value_missing (const struct missing_values *, const union value *,
enum mv_class);
bool mv_is_num_missing (const struct missing_values *, double, enum mv_class);
-bool mv_is_str_missing (const struct missing_values *, const char[],
+bool mv_is_str_missing (const struct missing_values *, const uint8_t[],
enum mv_class);
/* Initializing missing value sets. */
/* Adding and modifying discrete values. */
bool mv_add_value (struct missing_values *, const union value *);
-bool mv_add_str (struct missing_values *, const char[]);
+bool mv_add_str (struct missing_values *, const uint8_t[]);
bool mv_add_num (struct missing_values *, double);
void mv_pop_value (struct missing_values *, union value *);
bool mv_replace_value (struct missing_values *, const union value *, int idx);
*buf = '\0';
}
+
+/* Reads a string into BUF, which must have room for 256
+ characters.
+ Returns the number of bytes read.
+*/
+static size_t
+read_bytes (struct pfm_reader *r, uint8_t *buf)
+{
+ int n = read_int (r);
+ if (n < 0 || n > 255)
+ error (r, _("Bad string length %d."), n);
+
+ while (n-- > 0)
+ {
+ *buf++ = r->cc;
+ advance (r);
+ }
+ return n;
+}
+
+
+
/* Reads a string and returns a copy of it allocated from R's
pool. */
static char *
value_init (v, width);
if (width > 0)
{
- char string[256];
- read_string (r, string);
- value_copy_str_rpad (v, width, string, ' ');
+ uint8_t buf[256];
+ size_t n_bytes = read_bytes (r, buf);
+ value_copy_buf_rpad (v, width, buf, n_bytes, ' ');
}
else
v->f = read_float (r);
case_data_rw_idx (c, i)->f = read_float (r);
else
{
- char string[256];
- read_string (r, string);
- buf_copy_str_rpad (case_str_rw_idx (c, i), width, string, ' ');
+ uint8_t buf[256];
+ size_t n_bytes = read_bytes (r, buf);
+ u8_buf_copy_rpad (case_str_rw_idx (c, i), width, buf, n_bytes, ' ');
}
}
value_set_missing (&value, mv_width);
for (i = 0; i < missing_value_code; i++)
{
- char *s = value_str_rw (&value, mv_width);
+ uint8_t *s = value_str_rw (&value, mv_width);
read_bytes (r, s, 8);
mv_add_str (&mv, s);
}
struct label
{
- char raw_value[8]; /* Value as uninterpreted bytes. */
+ uint8_t raw_value[8]; /* Value as uninterpreted bytes. */
union value value; /* Value. */
char *label; /* Null-terminated label string. */
};
value_init_pool (subpool, &label->value, max_width);
if (var_is_alpha (var[0]))
- buf_copy_rpad (value_str_rw (&label->value, max_width), max_width,
+ u8_buf_copy_rpad (value_str_rw (&label->value, max_width), max_width,
label->raw_value, sizeof label->raw_value, ' ');
else
label->value.f = float_get_double (r->float_format, label->raw_value);
/* Read value. */
value_length = read_int (r);
if (value_length == width)
- read_string (r, value_str_rw (&value, width), width + 1);
+ read_bytes (r, value_str_rw (&value, width), width);
else
{
sys_warn (r, _("Ignoring long string value %zu for variable %s, "
static void read_error (struct casereader *, const struct sfm_reader *);
static bool read_case_number (struct sfm_reader *, double *);
-static bool read_case_string (struct sfm_reader *, char *, size_t);
+static bool read_case_string (struct sfm_reader *, uint8_t *, size_t);
static int read_opcode (struct sfm_reader *);
static bool read_compressed_number (struct sfm_reader *, double *);
-static bool read_compressed_string (struct sfm_reader *, char *);
-static bool read_whole_strings (struct sfm_reader *, char *, size_t);
+static bool read_compressed_string (struct sfm_reader *, uint8_t *);
+static bool read_whole_strings (struct sfm_reader *, uint8_t *, size_t);
static bool skip_whole_strings (struct sfm_reader *, size_t);
/* Reads and returns one case from READER's file. Returns a null
}
else
{
- char *s = value_str_rw (v, sv->var_width);
+ uint8_t *s = value_str_rw (v, sv->var_width);
if (!read_case_string (r, s + sv->offset, sv->segment_width))
goto eof;
if (!skip_whole_strings (r, ROUND_DOWN (sv->padding, 8)))
Returns true if successful, false if end of file is
reached immediately. */
static bool
-read_case_string (struct sfm_reader *r, char *s, size_t length)
+read_case_string (struct sfm_reader *r, uint8_t *s, size_t length)
{
size_t whole = ROUND_DOWN (length, 8);
size_t partial = length % 8;
if (partial)
{
- char bounce[8];
+ uint8_t bounce[8];
if (!read_whole_strings (r, bounce, sizeof bounce))
{
if (whole)
Returns true if successful, false if end of file is
reached immediately. */
static bool
-read_compressed_string (struct sfm_reader *r, char *dst)
+read_compressed_string (struct sfm_reader *r, uint8_t *dst)
{
switch (read_opcode (r))
{
Returns true if successful, false if end of file is
reached immediately. */
static bool
-read_whole_strings (struct sfm_reader *r, char *s, size_t length)
+read_whole_strings (struct sfm_reader *r, uint8_t *s, size_t length)
{
assert (length % 8 == 0);
if (!r->compressed)
static bool
skip_whole_strings (struct sfm_reader *r, size_t length)
{
- char buffer[1024];
+ uint8_t buffer[1024];
assert (length < sizeof buffer);
return read_whole_strings (r, buffer, length);
}
#include <libpspp/hash.h>
#include <libpspp/pool.h>
#include <libpspp/str.h>
+#include <gl/unistr.h>
#include "minmax.h"
#include "xalloc.h"
const union value *src, int src_width,
char pad)
{
- buf_copy_rpad (value_str_rw (dst, dst_width), dst_width,
+ u8_buf_copy_rpad (value_str_rw (dst, dst_width), dst_width,
value_str (src, src_width), src_width,
pad);
}
DST was initialized. Passing, e.g., a smaller value in order
to modify only a prefix of DST will not work in every case. */
void
-value_copy_str_rpad (union value *dst, int dst_width, const char *src,
+value_copy_str_rpad (union value *dst, int dst_width, const uint8_t *src,
char pad)
{
- value_copy_buf_rpad (dst, dst_width, src, strlen (src), pad);
+ value_copy_buf_rpad (dst, dst_width, src, u8_strlen (src), pad);
}
/* Copies the SRC_LEN bytes at SRC to string value DST with width
to modify only a prefix of DST will not work in every case. */
void
value_copy_buf_rpad (union value *dst, int dst_width,
- const char *src, size_t src_len, char pad)
+ const uint8_t *src, size_t src_len, char pad)
{
- buf_copy_rpad (value_str_rw (dst, dst_width), dst_width, src, src_len, pad);
+ u8_buf_copy_rpad (value_str_rw (dst, dst_width), dst_width, src, src_len, pad);
}
/* Sets V to the system-missing value for data of the given
return false;
else
{
- const char *str = value_str (value, old_width);
+ const uint8_t *str = value_str (value, old_width);
int i;
for (i = new_width; i < old_width; i++)
{
if (new_width > MAX_SHORT_STRING)
{
- char *new_long_string = pool_alloc_unaligned (pool, new_width);
+ uint8_t *new_long_string = pool_alloc_unaligned (pool, new_width);
memcpy (new_long_string, value_str (value, old_width), old_width);
value->long_string = new_long_string;
}
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
#include "xalloc.h"
\f
union value
{
double f;
- char short_string[MAX_SHORT_STRING];
- char *long_string;
+ uint8_t short_string[MAX_SHORT_STRING];
+ uint8_t *long_string;
};
static inline void value_init (union value *, int width);
static inline void value_destroy (union value *, int width);
static inline double value_num (const union value *);
-static inline const char *value_str (const union value *, int width);
-static inline char *value_str_rw (union value *, int width);
+static inline const uint8_t *value_str (const union value *, int width);
+static inline uint8_t *value_str_rw (union value *, int width);
int compare_values (const void *, const void *, const void *var);
unsigned hash_value (const void *, const void *var);
void value_copy_rpad (union value *, int dst_width,
const union value *, int src_width,
char pad);
-void value_copy_str_rpad (union value *, int dst_width, const char *,
+void value_copy_str_rpad (union value *, int dst_width, const uint8_t *,
char pad);
void value_copy_buf_rpad (union value *dst, int dst_width,
- const char *src, size_t src_len, char pad);
+ const uint8_t *src, size_t src_len, char pad);
void value_set_missing (union value *, int width);
int value_compare_3way (const union value *, const union value *, int width);
bool value_equal (const union value *, const union value *, int width);
It is important that WIDTH be the actual value that was passed
to value_init. Passing, e.g., a smaller value because only
that number of bytes will be accessed will not always work. */
-static inline const char *
+static inline const uint8_t *
value_str (const union value *v, int width)
{
assert (width > 0);
It is important that WIDTH be the actual value that was passed
to value_init. Passing, e.g., a smaller value because only
that number of bytes will be accessed will not always work. */
-static inline char *
+static inline uint8_t *
value_str_rw (union value *v, int width)
{
assert (width > 0);
S[] must contain exactly as many characters as V's width.
V must be a string variable. */
bool
-var_is_str_missing (const struct variable *v, const char s[],
+var_is_str_missing (const struct variable *v, const uint8_t s[],
enum mv_class class)
{
return mv_is_str_missing (&v->miss, s, class);
bool var_is_value_missing (const struct variable *, const union value *,
enum mv_class);
bool var_is_num_missing (const struct variable *, double, enum mv_class);
-bool var_is_str_missing (const struct variable *, const char[], enum mv_class);
+bool var_is_str_missing (const struct variable *, const uint8_t[], enum mv_class);
/* Value labels. */
const char *var_lookup_value_label (const struct variable *,
mv_init (&mv, MV_MAX_STRING);
while (!lex_match (lexer, ')'))
{
- char value[MV_MAX_STRING];
+ uint8_t value[MV_MAX_STRING];
size_t length;
if (!lex_force_string (lexer))
/* Returns the output mapping in TRNS for an input of VALUE with
the given WIDTH, or a null pointer if there is no mapping. */
static const struct map_out *
-find_src_string (struct recode_trns *trns, const char *value,
+find_src_string (struct recode_trns *trns, const uint8_t *value,
const struct variable *src_var)
{
struct mapping *m;
free ((char *) rel);
}
}
+
+
+\f
+
+/* Operations on uint8_t "strings" */
+
+/* Copies buffer SRC, of SRC_SIZE bytes, to DST, of DST_SIZE bytes.
+ DST is truncated to DST_SIZE bytes or padded on the right with
+ copies of PAD as needed. */
+void
+u8_buf_copy_rpad (uint8_t *dst, size_t dst_size,
+ const uint8_t *src, size_t src_size,
+ char pad)
+{
+ if (src_size >= dst_size)
+ memmove (dst, src, dst_size);
+ else
+ {
+ memmove (dst, src, src_size);
+ memset (&dst[src_size], pad, dst_size - src_size);
+ }
+}
#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <string.h>
/* calls relocate from gnulib on ST */
void ds_relocate (struct string *st);
+
+void u8_buf_copy_rpad (uint8_t *dst, size_t dst_size,
+ const uint8_t *src, size_t src_size,
+ char pad);
+
+
#endif /* str_h */
if (var != NULL)
{
int val_width = 1;
- char *val;
+ uint8_t *val;
result = xmalloc (sizeof (*result));
result->intr = var;