+Mon Dec 4 22:20:17 2006 Ben Pfaff <blp@gnu.org>
+
+ Start converting struct variable to an opaque. In this phase, we
+ add a bunch of setter and getter functions and convert most of the
+ PSPP code to use them. The resulting changes are pervasive but
+ mostly trivial, and only the notable changes are logged.
+
+ * format.c (fmt_equal): New function.
+
+ * variable.c (var_type_is_valid): New function.
+ (measure_is_valid) Moved here, from format.c.
+ (alignment_is_valid) Moved here, from format.c.
+ (var_get_name) New function.
+ (var_set_name) New function.
+ (width_to_type) New function.
+ (var_get_type) New function.
+ (var_get_width) New function.
+ (var_set_width) New function.
+ (var_is_numeric) New function.
+ (var_is_alpha) New function.
+ (var_is_short_string) New function.
+ (var_is_long_string) New function.
+ (var_is_very_long_string) New function.
+ (var_get_missing_values) New function.
+ (var_set_missing_values) New function.
+ (var_clear_missing_values) New function.
+ (var_has_missing_values) New function.
+ (var_is_value_missing) New function.
+ (var_is_num_missing) New function.
+ (var_is_str_missing) New function.
+ (var_is_value_user_missing) New function.
+ (var_is_num_user_missing) New function.
+ (var_is_str_user_missing) New function.
+ (var_is_value_system_missing) New function.
+ (var_get_print_format) New function.
+ (var_set_print_format) New function.
+ (var_get_write_format) New function.
+ (var_set_write_format) New function.
+ (var_set_both_formats) New function.
+ (var_get_label) New function.
+ (var_set_label) New function.
+ (var_clear_label) New function.
+ (var_has_label) New function.
+ (var_get_measure) New function.
+ (var_set_measure) New function.
+ (var_get_display_width) New function.
+ (var_set_display_width) New function.
+ (var_get_alignment) New function.
+ (var_set_alignment) New function.
+ (var_get_value_cnt) New function.
+ (var_get_leave) New function.
+ (var_get_short_name) New function.
+
+ * variable.h: (struct variable) Removed "type" and "nv" members;
+ they are now computed from "width" where needed.
+
Mon Dec 4 21:38:40 2006 Ben Pfaff <blp@gnu.org>
* missing-values.c (mv_resize): Don't write beyond end of the
const struct variable *va = *vap;
const struct variable *vb = *vbp;
- assert (va->type == vb->type);
- assert (va->width == vb->width);
+ assert (var_get_width (va) == var_get_width (vb));
- if (va->width == 0)
+ if (var_get_width (va) == 0)
{
double af = case_num (ca, va->fv);
double bf = case_num (cb, vb->fv);
{
const char *as = case_str (ca, va->fv);
const char *bs = case_str (cb, vb->fv);
- int cmp = memcmp (as, bs, va->width);
+ int cmp = memcmp (as, bs, var_get_width (va));
if (cmp != 0)
return cmp;
return true;
if ( filter->exclude_user_missing &&
- mv_is_value_user_missing (&var->miss, val) )
+ var_is_value_user_missing (var, val) )
return true;
return false;
{
candidate = v->obs_vals->vals + i;
assert (candidate != NULL);
- if (!compare_values (candidate, val, v->width))
+ if (!compare_values (candidate, val, var_get_width (v)))
{
return i;
}
{
struct cat_vals *cv;
- if (v->type == ALPHA)
+ if (var_is_alpha (v))
{
assert (val != NULL);
assert (v != NULL);
for (i = 0; i < s->var_cnt; i++)
{
struct variable *sv = s->var[i];
- struct variable *dv = dict_clone_var_assert (d, sv, sv->name);
- var_set_short_name (dv, sv->short_name);
+ struct variable *dv = dict_clone_var_assert (d, sv, var_get_name (sv));
+ var_set_short_name (dv, var_get_short_name (sv));
}
d->next_value_idx = s->next_value_idx;
{
d->split = xnmalloc (d->split_cnt, sizeof *d->split);
for (i = 0; i < d->split_cnt; i++)
- d->split[i] = dict_lookup_var_assert (d, s->split[i]->name);
+ d->split[i] = dict_lookup_var_assert (d, var_get_name (s->split[i]));
}
if (s->weight != NULL)
- d->weight = dict_lookup_var_assert (d, s->weight->name);
+ d->weight = dict_lookup_var_assert (d, var_get_name (s->weight));
if (s->filter != NULL)
- d->filter = dict_lookup_var_assert (d, s->filter->name);
+ d->filter = dict_lookup_var_assert (d, var_get_name (s->filter));
d->case_limit = s->case_limit;
dict_set_label (d, dict_get_label (s));
struct variable *v = d->var[i];
var_clear_aux (v);
val_labs_destroy (v->val_labs);
+ var_clear_label (v);
free (v->label);
free (v);
}
count = 0;
for (i = 0; i < d->var_cnt; i++)
- if (!(exclude_classes & (1u << dict_class_from_id (d->var[i]->name))))
- count++;
-
+ {
+ enum dict_class class = dict_class_from_id (var_get_name (d->var[i]));
+ if (!(exclude_classes & (1u << class)))
+ count++;
+ }
+
*vars = xnmalloc (count, sizeof **vars);
*cnt = 0;
- for (i = 0; i < d->var_cnt; i++)
- if (!(exclude_classes & (1u << dict_class_from_id (d->var[i]->name))))
- (*vars)[(*cnt)++] = d->var[i];
+ for (i = 0; i < d->var_cnt; i++)
+ {
+ enum dict_class class = dict_class_from_id (var_get_name (d->var[i]));
+ if (!(exclude_classes & (1u << class)))
+ (*vars)[(*cnt)++] = d->var[i];
+ }
assert (*cnt == count);
}
/* Allocate and initialize variable. */
v = xmalloc (sizeof *v);
- str_copy_trunc (v->name, sizeof v->name, name);
- v->type = width == 0 ? NUMERIC : ALPHA;
+ var_set_name (v, name);
v->width = width;
v->fv = d->next_value_idx;
- v->nv = width == 0 ? 1 : DIV_RND_UP (width, MAX_SHORT_STRING);
- v->leave = dict_class_from_id (v->name) == DC_SCRATCH;
+ v->leave = dict_class_from_id (var_get_name (v)) == DC_SCRATCH;
v->index = d->var_cnt;
mv_init (&v->miss, width);
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
{
v->print = fmt_for_output (FMT_F, 8, 2);
v->alignment = ALIGN_RIGHT;
}
else
{
- v->print = fmt_for_output (FMT_A, v->width, 0);
+ v->print = fmt_for_output (FMT_A, var_get_width (v), 0);
v->alignment = ALIGN_LEFT;
v->display_width = 8;
v->measure = MEASURE_NOMINAL;
}
v->write = v->print;
- v->val_labs = val_labs_create (v->width);
+ v->val_labs = val_labs_create (var_get_width (v));
v->label = NULL;
var_clear_short_name (v);
v->aux = NULL;
d->var_cnt++;
hsh_force_insert (d->name_tab, v);
- d->next_value_idx += v->nv;
+ d->next_value_idx += var_get_value_cnt (v);
return v;
}
assert (strlen (name) >= 1);
assert (strlen (name) <= LONG_NAME_LEN);
- nv = dict_create_var (d, name, ov->width);
+ nv = dict_create_var (d, name, var_get_width (ov));
if (nv == NULL)
return NULL;
short_name[] is intentionally not copied, because there is
no reason to give a new variable with potentially a new name
the same short name. */
- nv->leave = ov->leave;
- mv_copy (&nv->miss, &ov->miss);
- nv->print = ov->print;
- nv->write = ov->write;
+ nv->leave = var_get_leave (ov);
+ var_set_missing_values (nv, var_get_missing_values (ov));
+ var_set_print_format (nv, var_get_print_format (ov));
+ var_set_write_format (nv, var_get_write_format (ov));
val_labs_destroy (nv->val_labs);
nv->val_labs = val_labs_copy (ov->val_labs);
- if (ov->label != NULL)
- nv->label = xstrdup (ov->label);
- nv->measure = ov->measure;
- nv->display_width = ov->display_width;
- nv->alignment = ov->alignment;
+ var_set_label (nv, var_get_label (ov));
+ var_set_measure (nv, var_get_measure (ov));
+ var_set_display_width (nv, var_get_display_width (ov));
+ var_set_alignment (nv, var_get_alignment (ov));
return nv;
}
assert (d != NULL);
for (i = 0; i < d->var_cnt; )
- if (dict_class_from_id (d->var[i]->name) == DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (d->var[i])) == DC_SCRATCH)
dict_delete_var (d, d->var[i]);
else
i++;
assert (new_name != NULL);
assert (var_is_plausible_name (new_name, false));
assert (dict_contains_var (d, v));
- assert (!compare_var_names (v->name, new_name, NULL)
+ assert (!compare_var_names (var_get_name (v), new_name, NULL)
|| dict_lookup_var (d, new_name) == NULL);
hsh_force_delete (d->name_tab, v);
- str_copy_trunc (v->name, sizeof v->name, new_name);
+ var_set_name (v, new_name);
hsh_force_insert (d->name_tab, v);
if (get_algorithm () == ENHANCED)
assert (d->var[vars[i]->index] == vars[i]);
assert (var_is_plausible_name (new_names[i], false));
hsh_force_delete (d->name_tab, vars[i]);
- old_names[i] = xstrdup (vars[i]->name);
- strcpy (vars[i]->name, new_names[i]);
+ old_names[i] = xstrdup (var_get_name (vars[i]));
+ var_set_name (vars[i], new_names[i]);
}
/* Add the renamed variables back into the name hash,
for (i = 0; i < count; i++)
{
- strcpy (vars[i]->name, old_names[i]);
+ var_set_name (vars[i], old_names[i]);
hsh_force_insert (d->name_tab, vars[i]);
}
else
{
double w = case_num (c, d->weight->fv);
- if (w < 0.0 || mv_is_num_missing (&d->weight->miss, w))
+ if (w < 0.0 || var_is_num_missing (d->weight, w))
w = 0.0;
if ( w == 0.0 && *warn_on_invalid ) {
*warn_on_invalid = false;
{
assert (d != NULL);
assert (v == NULL || dict_contains_var (d, v));
- assert (v == NULL || v->type == NUMERIC);
+ assert (v == NULL || var_is_numeric (v));
d->weight = v;
}
{
struct variable *v = d->var[i];
- if (dict_class_from_id (v->name) != DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (v)) != DC_SCRATCH)
{
v->fv = d->next_value_idx;
- d->next_value_idx += v->nv;
+ d->next_value_idx += var_get_value_cnt (v);
i++;
}
else
cnt = 0;
for (i = 0; i < d->var_cnt; i++)
- if (dict_class_from_id (d->var[i]->name) != DC_SCRATCH)
- cnt += d->var[i]->nv;
+ if (dict_class_from_id (var_get_name (d->var[i])) != DC_SCRATCH)
+ cnt += var_get_value_cnt (d->var[i]);
return cnt;
}
{
struct variable *v = d->var[i];
- if (dict_class_from_id (v->name) != DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (v)) != DC_SCRATCH)
{
idx_to_fv[i] = next_value_idx;
- next_value_idx += v->nv;
+ next_value_idx += var_get_value_cnt (v);
}
else
idx_to_fv[i] = -1;
struct variable *v = dict_get_var (d, i);
if (v->fv != case_idx)
return true;
- case_idx += v->nv;
+ case_idx += var_get_value_cnt (v);
}
return false;
}
{
struct variable *v = d->var[i];
- if (dict_class_from_id (v->name) == DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (v)) == DC_SCRATCH)
continue;
if (map != NULL && map->src_idx + map->cnt == v->fv)
- map->cnt += v->nv;
+ map->cnt += var_get_value_cnt (v);
else
{
if (compactor->map_cnt == map_allocated)
map = &compactor->maps[compactor->map_cnt++];
map->src_idx = v->fv;
map->dst_idx = value_idx;
- map->cnt = v->nv;
+ map->cnt = var_get_value_cnt (v);
}
- value_idx += v->nv;
+ value_idx += var_get_value_cnt (v);
}
return compactor;
for (i = 0; i < d->var_cnt; i++)
{
struct variable *v = d->var[i];
- if (strlen (v->name) <= SHORT_NAME_LEN)
- var_set_short_name (v, v->name);
- else if (dict_lookup_var (d, v->short_name) != NULL)
+ const char *short_name = var_get_short_name (v);
+ if (strlen (var_get_name (v)) <= SHORT_NAME_LEN)
+ var_set_short_name (v, var_get_name (v));
+ else if (short_name != NULL && dict_lookup_var (d, short_name) != NULL)
var_clear_short_name (v);
}
for (i = 0; i < d->var_cnt; i++)
{
struct variable *v = d->var[i];
- if (v->short_name[0] && hsh_insert (short_names, v->short_name) != NULL)
+ const char *name = var_get_short_name (v);
+ if (name != NULL && hsh_insert (short_names, (char *) name) != NULL)
var_clear_short_name (v);
}
for (i = 0; i < d->var_cnt; i++)
{
struct variable *v = d->var[i];
- if (v->short_name[0] == '\0')
+ const char *name = var_get_short_name (v);
+ if (name == NULL)
{
- int sfx;
-
- /* Form initial short_name. */
- var_set_short_name (v, v->name);
+ /* Form initial short_name from the variable name, then
+ try _A, _B, ... _AA, _AB, etc., if needed.*/
+ int trial = 0;
+ do
+ {
+ if (trial == 0)
+ var_set_short_name (v, var_get_name (v));
+ else
+ var_set_short_name_suffix (v, var_get_name (v), trial - 1);
- /* Try _A, _B, ... _AA, _AB, etc., if needed. */
- for (sfx = 0; hsh_insert (short_names, v->short_name) != NULL; sfx++)
- var_set_short_name_suffix (v, v->name, sfx);
+ trial++;
+ }
+ while (hsh_insert (short_names, (char *) var_get_short_name (v))
+ != NULL);
}
}
"%s%d", fmt_name (f->type), f->w);
return buffer;
}
+
+/* Returns true if A and B are identical formats,
+ false otherwise. */
+bool
+fmt_equal (const struct fmt_spec *a, const struct fmt_spec *b)
+{
+ return a->type == b->type && a->w == b->w && a->d == b->d;
+}
\f
/* Describes a display format. */
struct fmt_desc
init_style (FMT_CCE, "", "", decimal, grouping);
}
\f
-/* Returns true if M is a valid variable measurement level,
- false otherwise. */
-bool
-measure_is_valid (enum measure m)
-{
- return m > 0 && m < n_MEASURES;
-}
-
-/* Returns true if A is a valid alignment,
- false otherwise. */
-bool
-alignment_is_valid (enum alignment a)
-{
- return a < n_ALIGN;
-}
-\f
/* Returns the struct fmt_desc for the given format TYPE. */
static const struct fmt_desc *
get_fmt_desc (enum fmt_type type)
struct fmt_spec fmt_for_input (enum fmt_type, int w, int d) PURE_FUNCTION;
struct fmt_spec fmt_for_output (enum fmt_type, int w, int d) PURE_FUNCTION;
struct fmt_spec fmt_for_output_from_input (const struct fmt_spec *);
+struct fmt_spec fmt_default_for_width (int var_width);
/* Verifying formats. */
bool fmt_check (const struct fmt_spec *, bool for_input);
bool fmt_check_input (const struct fmt_spec *);
bool fmt_check_output (const struct fmt_spec *);
bool fmt_check_type_compat (const struct fmt_spec *, int var_type);
-bool fmt_check_width_compat (const struct fmt_spec *, int width);
+bool fmt_check_width_compat (const struct fmt_spec *, int var_width);
/* Working with formats. */
int fmt_var_width (const struct fmt_spec *);
char *fmt_to_string (const struct fmt_spec *, char s[FMT_STRING_LEN_MAX + 1]);
+bool fmt_equal (const struct fmt_spec *, const struct fmt_spec *);
/* Format types. */
const char *fmt_name (enum fmt_type) PURE_FUNCTION;
int fmt_grouping_char (enum fmt_type);
void fmt_set_decimal (char);
-\f
-/* Alignment of data for display. */
-enum alignment
- {
- ALIGN_LEFT = 0,
- ALIGN_RIGHT = 1,
- ALIGN_CENTRE = 2,
- n_ALIGN
- };
-
-/* How data is measured. */
-enum measure
- {
- MEASURE_NOMINAL=1,
- MEASURE_ORDINAL=2,
- MEASURE_SCALE=3,
- n_MEASURES
- };
-
-bool measure_is_valid(enum measure m);
-bool alignment_is_valid(enum alignment a);
#endif /* format.h */
mv_is_value_system_missing (const struct missing_values *mv,
const union value *v)
{
- return mv->width == 0 ? v->f == SYSMIS : false;
+ return mv->width == 0 && v->f == SYSMIS;
}
bool mv_is_resizable (struct missing_values *, int width);
void mv_resize (struct missing_values *, int width);
-typedef bool is_missing_func (const struct missing_values *,
- const union value *);
+typedef bool mv_is_missing_func (const struct missing_values *,
+ const union value *);
/* Is a value system or user missing? */
bool mv_is_value_missing (const struct missing_values *, const union value *);
/* Translates a format specification read from portable file R as
the three integers INTS into a normal format specifier FORMAT,
checking that the format is appropriate for variable V. */
-static void
+static struct fmt_spec
convert_format (struct pfm_reader *r, const int portable_format[3],
- struct fmt_spec *format, struct variable *v)
+ struct variable *v)
{
+ struct fmt_spec format;
bool ok;
- if (!fmt_from_io (portable_format[0], &format->type))
+ if (!fmt_from_io (portable_format[0], &format.type))
error (r, _("%s: Bad format specifier byte (%d)."),
- v->name, portable_format[0]);
- format->w = portable_format[1];
- format->d = portable_format[2];
+ var_get_name (v), portable_format[0]);
+ format.w = portable_format[1];
+ format.d = portable_format[2];
msg_disable ();
- ok = fmt_check_output (format) && fmt_check_width_compat (format, v->width);
+ ok = (fmt_check_output (&format)
+ && fmt_check_width_compat (&format, var_get_width (v)));
msg_enable ();
if (!ok)
{
char fmt_string[FMT_STRING_LEN_MAX + 1];
error (r, _("%s variable %s has invalid format specifier %s."),
- v->type == NUMERIC ? _("Numeric") : _("String"),
- v->name, fmt_to_string (format, fmt_string));
+ var_is_numeric (v) ? _("Numeric") : _("String"),
+ var_get_name (v), fmt_to_string (&format, fmt_string));
+ format = fmt_default_for_width (var_get_width (v));
}
+
+ return format;
}
static union value parse_value (struct pfm_reader *, struct variable *);
char name[256];
int fmt[6];
struct variable *v;
+ struct missing_values miss;
+ struct fmt_spec print, write;
int j;
if (!match (r, '7'))
if (v == NULL)
error (r, _("Duplicate variable name %s."), name);
- convert_format (r, &fmt[0], &v->print, v);
- convert_format (r, &fmt[3], &v->write, v);
+ print = convert_format (r, &fmt[0], v);
+ write = convert_format (r, &fmt[3], v);
+ var_set_print_format (v, &print);
+ var_set_write_format (v, &write);
/* Range missing values. */
+ mv_init (&miss, var_get_width (v));
if (match (r, 'B'))
{
double x = read_float (r);
double y = read_float (r);
- mv_add_num_range (&v->miss, x, y);
+ mv_add_num_range (&miss, x, y);
}
else if (match (r, 'A'))
- mv_add_num_range (&v->miss, read_float (r), HIGHEST);
+ mv_add_num_range (&miss, read_float (r), HIGHEST);
else if (match (r, '9'))
- mv_add_num_range (&v->miss, LOWEST, read_float (r));
+ mv_add_num_range (&miss, LOWEST, read_float (r));
/* Single missing values. */
while (match (r, '8'))
{
union value value = parse_value (r, v);
- mv_add_value (&v->miss, &value);
+ mv_add_value (&miss, &value);
}
+ var_set_missing_values (v, &miss);
+
if (match (r, 'C'))
{
char label[256];
read_string (r, label);
- v->label = xstrdup (label);
+ var_set_label (v, label);
}
}
{
union value v;
- if (vv->type == ALPHA)
+ if (var_is_alpha (vv))
{
char string[256];
read_string (r, string);
if (v[i] == NULL)
error (r, _("Unknown variable %s while parsing value labels."), name);
- if (v[0]->width != v[i]->width)
+ if (var_get_width (v[0]) != var_get_width (v[i]))
error (r, _("Cannot assign value labels to %s and %s, which "
"have different variable types or widths."),
- v[0]->name, v[i]->name);
+ var_get_name (v[0]), var_get_name (v[i]));
}
n_labels = read_int (r);
if (!val_labs_replace (var->val_labs, val, label))
continue;
- if (var->type == NUMERIC)
+ if (var_is_numeric (var))
error (r, _("Duplicate label for value %g for variable %s."),
- val.f, var->name);
+ val.f, var_get_name (var));
else
error (r, _("Duplicate label for value `%.*s' for variable %s."),
- var->width, val.s, var->name);
+ var_get_width (var), val.s, var_get_name (var));
}
}
}
{
const struct variable *dv = dict_get_var (dict, i);
struct pfm_var *pv = &w->vars[i];
- pv->width = dv->width;
+ pv->width = var_get_width (dv);
pv->fv = dv->fv;
}
/* Write format F to file H. */
static void
-write_format (struct pfm_writer *w, struct fmt_spec *f)
+write_format (struct pfm_writer *w, const struct fmt_spec *f)
{
write_int (w, fmt_to_io (f->type));
write_int (w, f->w);
static void
write_value (struct pfm_writer *w, union value *v, struct variable *vv)
{
- if (vv->type == NUMERIC)
+ if (var_is_numeric (vv))
write_float (w, v->f);
else
{
- write_int (w, vv->width);
- buf_write (w, v->s, vv->width);
+ write_int (w, var_get_width (vv));
+ buf_write (w, v->s, var_get_width (vv));
}
}
struct missing_values mv;
buf_write (w, "7", 1);
- write_int (w, v->width);
- write_string (w, v->short_name);
- write_format (w, &v->print);
- write_format (w, &v->write);
+ write_int (w, var_get_width (v));
+ write_string (w, var_get_short_name (v));
+ write_format (w, var_get_print_format (v));
+ write_format (w, var_get_write_format (v));
/* Write missing values. */
- mv_copy (&mv, &v->miss);
+ mv_copy (&mv, var_get_missing_values (v));
while (mv_has_range (&mv))
{
double x, y;
write_value (w, &value, v);
}
- if (v->label)
+ if (var_get_label (v) != NULL)
{
buf_write (w, "C", 1);
- write_string (w, v->label);
+ write_string (w, var_get_label (v));
}
}
}
buf_write (w, "D", 1);
write_int (w, 1);
- write_string (w, v->short_name);
+ write_string (w, var_get_short_name (v));
write_int (w, val_labs_count (v->val_labs));
for (vl = val_labs_first_sorted (v->val_labs, &j); vl != NULL;
struct variable *v = dict_get_var (dict, i);
union value *value = case_data_rw (trns_case, v->fv);
- if (v->type == NUMERIC)
- value->f = v->leave ? 0.0 : SYSMIS;
+ if (var_is_numeric (v))
+ value->f = var_get_leave (v) ? 0.0 : SYSMIS;
else
- memset (value->s, ' ', v->width);
+ memset (value->s, ' ', var_get_width (v));
}
}
for (i = 0; i < var_cnt; i++)
{
struct variable *v = dict_get_var (ds->dict, i);
- if (!v->leave)
+ if (!var_get_leave (v))
{
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
case_data_rw (c, v->fv)->f = SYSMIS;
else
- memset (case_data_rw (c, v->fv)->s, ' ', v->width);
+ memset (case_data_rw (c, v->fv)->s, ' ', var_get_width (v));
}
}
}
{
struct variable *filter_var = filter_var_;
double f = case_num (c, filter_var->fv);
- return (f != 0.0 && !mv_is_num_missing (&filter_var->miss, f)
+ return (f != 0.0 && !var_is_num_missing (filter_var, f)
? TRNS_CONTINUE : TRNS_DROP_CASE);
}
lose ((ME,
_("%s: Weighting variable may not be a continuation of "
"a long string variable."), fh_get_file_name (fh)));
- else if (weight_var->type == ALPHA)
+ else if (var_is_alpha (weight_var))
lose ((ME, _("%s: Weighting variable may not be a string variable."),
fh_get_file_name (fh)));
v = dict_get_var(*dict, i);
- v->measure = params.measure;
- v->display_width = params.width;
- v->alignment = params.align;
+ var_set_measure (v, params.measure);
+ var_set_display_width (v, params.width);
+ var_set_alignment (v, params.align);
}
}
break;
}
l = length;
- if ( v->width > EFFECTIVE_LONG_STRING_LENGTH )
+ if ( var_get_width (v) > EFFECTIVE_LONG_STRING_LENGTH )
l -= EFFECTIVE_LONG_STRING_LENGTH;
else
- l -= v->width;
+ l -= var_get_width (v);
idx = v->index;
while ( l > 0 )
struct variable *v_next;
v_next = dict_get_var(*dict, idx + 1);
- if ( v_next->width > EFFECTIVE_LONG_STRING_LENGTH )
+ if ( var_get_width (v_next) > EFFECTIVE_LONG_STRING_LENGTH )
l -= EFFECTIVE_LONG_STRING_LENGTH;
else
- l -= v_next->width;
+ l -= var_get_width (v_next);
dict_delete_var(*dict, v_next);
}
assert ( length > MAX_LONG_STRING );
- v->width = length;
- v->print.w = v->width;
- v->write.w = v->width;
- v->nv = DIV_RND_UP (length, MAX_SHORT_STRING);
+ var_set_width (v, length);
}
eq_seen = false;
memset(name, 0, SHORT_NAME_LEN+1);
{
struct variable *v = dict_get_var (*dict, i);
struct sfm_var *sv = &r->vars[i];
- sv->width = v->width;
+ sv->width = var_get_width (v);
sv->fv = v->fv;
}
}
char name[SHORT_NAME_LEN + 1];
int nv;
int j;
+ struct fmt_spec print, write;
+
assertive_buf_read (r, &sv, sizeof sv, 0);
fh_get_file_name (r->fh), name));
/* Set the short name the same as the long name */
- var_set_short_name (vv, vv->name);
+ var_set_short_name (vv, var_get_name (vv));
/* Case reading data. */
nv = sv.type == 0 ? 1 : DIV_RND_UP (sv.type, sizeof (flt64));
if (len < 0 || len > 255)
lose ((ME, _("%s: Variable %s indicates variable label of invalid "
"length %d."),
- fh_get_file_name (r->fh), vv->name, len));
+ fh_get_file_name (r->fh), var_get_name (vv), len));
if ( len != 0 )
{
/* Read label into variable structure. */
- vv->label = buf_read (r, NULL, ROUND_UP (len, sizeof (int32_t)), len + 1);
- if (vv->label == NULL)
- goto error;
- vv->label[len] = '\0';
+ char label[256];
+ assertive_buf_read (r, label, ROUND_UP (len, sizeof (int32_t)),
+ 0);
+ label[len] = '\0';
+ var_set_label (vv, label);
}
}
{
flt64 mv[3];
int mv_cnt = abs (sv.n_missing_values);
+ struct missing_values miss;
- if (vv->width > MAX_SHORT_STRING)
+ if (var_get_width (vv) > MAX_SHORT_STRING)
lose ((ME, _("%s: Long string variable %s may not have missing "
"values."),
- fh_get_file_name (r->fh), vv->name));
+ fh_get_file_name (r->fh), var_get_name (vv)));
+ mv_init (&miss, var_get_width (vv));
assertive_buf_read (r, mv, sizeof *mv * mv_cnt, 0);
- if (r->reverse_endian && vv->type == NUMERIC)
+ if (r->reverse_endian && var_is_numeric (vv))
for (j = 0; j < mv_cnt; j++)
bswap_flt64 (&mv[j]);
if (sv.n_missing_values > 0)
{
for (j = 0; j < sv.n_missing_values; j++)
- if (vv->type == NUMERIC)
- mv_add_num (&vv->miss, mv[j]);
+ if (var_is_numeric (vv))
+ mv_add_num (&miss, mv[j]);
else
- mv_add_str (&vv->miss, (char *) &mv[j]);
+ mv_add_str (&miss, (char *) &mv[j]);
}
else
{
- if (vv->type == ALPHA)
+ if (var_is_alpha (vv))
lose ((ME, _("%s: String variable %s may not have missing "
"values specified as a range."),
- fh_get_file_name (r->fh), vv->name));
+ fh_get_file_name (r->fh), var_get_name (vv)));
if (mv[0] == r->lowest)
- mv_add_num_range (&vv->miss, LOWEST, mv[1]);
+ mv_add_num_range (&miss, LOWEST, mv[1]);
else if (mv[1] == r->highest)
- mv_add_num_range (&vv->miss, mv[0], HIGHEST);
+ mv_add_num_range (&miss, mv[0], HIGHEST);
else
- mv_add_num_range (&vv->miss, mv[0], mv[1]);
+ mv_add_num_range (&miss, mv[0], mv[1]);
if (sv.n_missing_values == -3)
- mv_add_num (&vv->miss, mv[2]);
+ mv_add_num (&miss, mv[2]);
}
+ var_set_missing_values (vv, &miss);
}
- if (!parse_format_spec (r, sv.print, &vv->print, vv)
- || !parse_format_spec (r, sv.write, &vv->write, vv))
+ if (!parse_format_spec (r, sv.print, &print, vv)
+ || !parse_format_spec (r, sv.write, &write, vv))
goto error;
+
+ var_set_print_format (vv, &print);
+ var_set_write_format (vv, &write);
}
/* Some consistency checks. */
f->w = (s >> 8) & 0xff;
f->d = s & 0xff;
- if ((v->type == ALPHA) ^ (fmt_is_string (f->type) != 0))
+ if (var_is_alpha (v) != fmt_is_string (f->type))
lose ((ME, _("%s: %s variable %s has %s format specifier %s."),
fh_get_file_name (r->fh),
- v->type == ALPHA ? _("String") : _("Numeric"),
- v->name,
+ var_is_alpha (v) ? _("String") : _("Numeric"),
+ var_get_name (v),
fmt_is_string (f->type) ? _("string") : _("numeric"),
fmt_name (f->type)));
msg_disable ();
- ok = fmt_check_output (f) && fmt_check_width_compat (f, v->width);
+ ok = fmt_check_output (f) && fmt_check_width_compat (f, var_get_width (v));
msg_enable ();
if (!ok)
{
char fmt_string[FMT_STRING_LEN_MAX + 1];
msg (ME, _("%s variable %s has invalid format specifier %s."),
- v->type == NUMERIC ? _("Numeric") : _("String"),
- v->name, fmt_to_string (f, fmt_string));
- *f = (v->type == NUMERIC
+ var_is_numeric (v) ? _("Numeric") : _("String"),
+ var_get_name (v), fmt_to_string (f, fmt_string));
+ *f = (var_is_numeric (v)
? fmt_for_output (FMT_F, 8, 2)
- : fmt_for_output (FMT_A, v->width, 0));
+ : fmt_for_output (FMT_A, var_get_width (v), 0));
}
return 1;
"refers to a continuation of a string variable, not to "
"an actual variable."),
fh_get_file_name (r->fh), var_idx));
- if (v->type == ALPHA && v->width > MAX_SHORT_STRING)
+ if (var_is_long_string (v))
lose ((ME, _("%s: Value labels are not allowed on long string "
"variables (%s)."),
- fh_get_file_name (r->fh), v->name));
+ fh_get_file_name (r->fh), var_get_name (v)));
/* Add it to the list of variables. */
var[i] = v;
/* Type check the variables. */
for (i = 1; i < n_vars; i++)
- if (var[i]->type != var[0]->type)
+ if (var_get_type (var[i]) != var_get_type (var[0]))
lose ((ME, _("%s: Variables associated with value label are not all of "
"identical type. Variable %s has %s type, but variable "
"%s has %s type."),
fh_get_file_name (r->fh),
- var[0]->name, var[0]->type == ALPHA ? _("string") : _("numeric"),
- var[i]->name, var[i]->type == ALPHA ? _("string") : _("numeric")));
+ var_get_name (var[0]),
+ var_is_alpha (var[0]) ? _("string") : _("numeric"),
+ var_get_name (var[i]),
+ var_is_alpha (var[i]) ? _("string") : _("numeric")));
/* Fill in labels[].value, now that we know the desired type. */
for (i = 0; i < n_labels; i++)
{
struct label *label = labels + i;
- if (var[0]->type == ALPHA)
+ if (var_is_alpha (var[0]))
{
const int copy_len = MIN (sizeof label->raw_value,
sizeof label->label);
if (!val_labs_replace (v->val_labs, label->value, label->label))
continue;
- if (var[0]->type == NUMERIC)
+ if (var_is_numeric (var[0]))
msg (MW, _("%s: File contains duplicate label for value %g for "
"variable %s."),
- fh_get_file_name (r->fh), label->value.f, v->name);
+ fh_get_file_name (r->fh), label->value.f, var_get_name (v));
else
msg (MW, _("%s: File contains duplicate label for value `%.*s' "
"for variable %s."),
- fh_get_file_name (r->fh), v->width, label->value.s, v->name);
+ fh_get_file_name (r->fh), var_get_width (v),
+ label->value.s, var_get_name (v));
}
}
var_flt64_cnt (const struct variable *v)
{
assert(sizeof(flt64) == MAX_SHORT_STRING);
- return width_to_bytes(v->width) / MAX_SHORT_STRING ;
+ return width_to_bytes(var_get_width (v)) / MAX_SHORT_STRING ;
}
static inline int
var_flt64_cnt_nom (const struct variable *v)
{
- return v->type == NUMERIC ? 1 : DIV_RND_UP (v->width, sizeof (flt64));
+ return (var_is_numeric (v)
+ ? 1 : DIV_RND_UP (var_get_width (v), sizeof (flt64)));
}
{
const struct variable *dv = dict_get_var (d, i);
struct sfm_var *sv = &w->vars[i];
- sv->width = dv->width;
+ sv->width = var_get_width (dv);
/* spss compatibility nonsense */
- if ( dv->width > MAX_LONG_STRING )
+ if ( var_is_very_long_string (dv) )
w->has_vls = true;
sv->fv = dv->fv;
{
int count = 0;
const struct variable *v = dict_get_var(d, i);
- int wcount = v->width;
+ int wcount = var_get_width (v);
do {
struct variable var_cont = *v;
- if ( v->type == ALPHA)
+ if ( var_is_alpha (v))
{
if ( 0 != count )
{
- mv_init(&var_cont.miss, 0);
- strcpy(var_cont.short_name,
- cont_var_name(v->short_name, count));
- var_cont.label = NULL;
+ var_clear_missing_values (&var_cont);
+ var_set_short_name (&var_cont,
+ cont_var_name (var_get_short_name (v),
+ count));
+ var_clear_label (&var_cont);
w->var_cnt_vls++;
}
count++;
if ( wcount > MAX_LONG_STRING )
{
- var_cont.width = MAX_LONG_STRING;
+ var_set_width (&var_cont, MAX_LONG_STRING);
wcount -= EFFECTIVE_LONG_STRING_LENGTH;
}
else
{
- var_cont.width = wcount;
- wcount -= var_cont.width;
+ var_set_width (&var_cont, wcount);
+ wcount -= var_get_width (&var_cont);
}
-
- var_cont.write.w = var_cont.width;
- var_cont.print.w = var_cont.width;
}
write_variable (w, &var_cont);
struct missing_values mv;
flt64 m[3]; /* Missing value values. */
int nm; /* Number of missing values, possibly negative. */
+ const char *label = var_get_label (v);
sv.rec_type = 2;
- sv.type = MIN(v->width, MAX_LONG_STRING);
- sv.has_var_label = (v->label != NULL);
+ sv.type = MIN(var_get_width (v), MAX_LONG_STRING);
+ sv.has_var_label = label != NULL;
- mv_copy (&mv, &v->miss);
+ mv_copy (&mv, var_get_missing_values (v));
nm = 0;
if (mv_has_range (&mv))
{
{
union value value;
mv_pop_value (&mv, &value);
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
m[nm] = value.f;
else
- buf_copy_rpad ((char *) &m[nm], sizeof m[nm], value.s, v->width);
+ buf_copy_rpad ((char *) &m[nm], sizeof m[nm], value.s,
+ var_get_width (v));
nm++;
}
- if (mv_has_range (&v->miss))
+ if (mv_has_range (var_get_missing_values (v)))
nm = -nm;
sv.n_missing_values = nm;
- write_format_spec (&v->print, &sv.print);
- write_format_spec (&v->write, &sv.write);
- buf_copy_str_rpad (sv.name, sizeof sv.name, v->short_name);
+ write_format_spec (var_get_print_format (v), &sv.print);
+ write_format_spec (var_get_write_format (v), &sv.write);
+ buf_copy_str_rpad (sv.name, sizeof sv.name, var_get_short_name (v));
buf_write (w, &sv, sizeof sv);
- if (v->label)
+ if (label != NULL)
{
struct label
{
int ext_len;
- l.label_len = MIN (strlen (v->label), 255);
+ l.label_len = MIN (strlen (label), 255);
ext_len = ROUND_UP (l.label_len, sizeof l.label_len);
- memcpy (l.label, v->label, l.label_len);
+ memcpy (l.label, label, l.label_len);
memset (&l.label[l.label_len], ' ', ext_len - l.label_len);
buf_write (w, &l, offsetof (struct label, label) + ext_len);
if (nm)
buf_write (w, m, sizeof *m * abs (nm));
- if (v->type == ALPHA && v->width > (int) sizeof (flt64))
+ if (var_is_alpha (v) && var_get_width (v) > (int) sizeof (flt64))
{
int i;
int pad_count;
memset (&sv.write, 0, sizeof sv.write);
memset (&sv.name, 0, sizeof sv.name);
- pad_count = DIV_RND_UP (MIN(v->width, MAX_LONG_STRING),
+ pad_count = DIV_RND_UP (MIN(var_get_width (v), MAX_LONG_STRING),
(int) sizeof (flt64)) - 1;
for (i = 0; i < pad_count; i++)
buf_write (w, &sv, sizeof sv);
v = dict_get_var(dict, i);
- params.measure = v->measure;
- params.width = v->display_width;
- params.align = v->alignment;
+ params.measure = var_get_measure (v);
+ params.width = var_get_display_width (v);
+ params.align = var_get_alignment (v);
buf_write (w, ¶ms, sizeof(params));
- if ( v->width > MAX_LONG_STRING )
+ if (var_is_long_string (v))
{
- int wcount = v->width - EFFECTIVE_LONG_STRING_LENGTH ;
+ int wcount = var_get_width (v) - EFFECTIVE_LONG_STRING_LENGTH ;
while (wcount > 0)
{
{
const struct variable *v = dict_get_var (dict, i);
- if ( v->width <= MAX_LONG_STRING )
+ if ( var_get_width (v) <= MAX_LONG_STRING )
continue;
- ds_put_format (&vls_length_map, "%s=%05d", v->short_name, v->width);
+ ds_put_format (&vls_length_map, "%s=%05d",
+ var_get_short_name (v), var_get_width (v));
ds_put_char (&vls_length_map, '\0');
ds_put_char (&vls_length_map, '\t');
}
if (i)
ds_put_char (&long_name_map, '\t');
- ds_put_format (&long_name_map, "%s=%s", v->short_name, v->name);
+ ds_put_format (&long_name_map, "%s=%s",
+ var_get_short_name (v), var_get_name (v));
}
lv_hdr.rec_type = 7;
if (s == NULL)
{
static char buf[MAX_STRING + 1];
- data_out (val, &var->print, buf);
- buf[var->print.w] = '\0';
+ const struct fmt_spec *print = var_get_print_format (var);
+ data_out (val, print, buf);
+ buf[print->w] = '\0';
s = buf;
}
#include "gettext.h"
#define _(msgid) gettext (msgid)
+/* Returns true if VAR_TYPE is a valid variable type. */
+bool
+var_type_is_valid (enum var_type var_type)
+{
+ return var_type == NUMERIC || var_type == ALPHA;
+}
+
/* Returns an adjective describing the given variable TYPE,
suitable for use in phrases like "numeric variable". */
const char *
{
return type == NUMERIC ? _("number") : _("string");
}
+\f
+/* Returns true if M is a valid variable measurement level,
+ false otherwise. */
+bool
+measure_is_valid (enum measure m)
+{
+ return m == MEASURE_NOMINAL || m == MEASURE_ORDINAL || m == MEASURE_SCALE;
+}
+/* Returns true if A is a valid alignment,
+ false otherwise. */
+bool
+alignment_is_valid (enum alignment a)
+{
+ return a == ALIGN_LEFT || a == ALIGN_RIGHT || a == ALIGN_CENTRE;
+}
+\f
/* Assign auxiliary data AUX to variable V, which must not
already have auxiliary data. Before V's auxiliary data is
cleared, AUX_DTOR(V) will be called. */
return id_hash;
}
+\f
+/* Return variable V's name. */
+const char *
+var_get_name (const struct variable *v)
+{
+ return v->name;
+}
+/* Sets V's name to NAME. */
+void
+var_set_name (struct variable *v, const char *name)
+{
+ assert (name[0] != '\0');
+ assert (lex_id_to_token (ss_cstr (name)) == T_ID);
+ str_copy_trunc (v->name, sizeof v->name, name);
+}
-\f
/* Returns true if NAME is an acceptable name for a variable,
false otherwise. If ISSUE_ERROR is true, issues an
explanatory error message on failure. */
const struct variable *a = a_;
const struct variable *b = b_;
- return strcasecmp (a->name, b->name);
+ return strcasecmp (var_get_name (a), var_get_name (b));
}
/* A hsh_hash_func that hashes variable V based on its name. */
{
const struct variable *v = v_;
- return hsh_hash_case_string (v->name);
+ return hsh_hash_case_string (var_get_name (v));
}
/* A hsh_compare_func that orders pointers to variables A and B
struct variable *const *a = a_;
struct variable *const *b = b_;
- return strcasecmp ((*a)->name, (*b)->name);
+ return strcasecmp (var_get_name (*a), var_get_name (*b));
}
/* A hsh_hash_func that hashes pointer to variable V based on its
{
struct variable *const *v = v_;
- return hsh_hash_case_string ((*v)->name);
+ return hsh_hash_case_string (var_get_name (*v));
+}
+\f
+/* Returns the type of a variable with the given WIDTH. */
+static enum var_type
+width_to_type (int width)
+{
+ return width == 0 ? NUMERIC : ALPHA;
+}
+
+/* Returns the type of variable V. */
+enum var_type
+var_get_type (const struct variable *v)
+{
+ return width_to_type (v->width);
+}
+
+/* Returns the width of variable V. */
+int
+var_get_width (const struct variable *v)
+{
+ return v->width;
+}
+
+/* Sets the width of V to WIDTH. */
+void
+var_set_width (struct variable *v, int new_width)
+{
+ enum var_type new_type = width_to_type (new_width);
+
+ if (mv_is_resizable (&v->miss, new_width))
+ mv_resize (&v->miss, new_width);
+ else
+ mv_init (&v->miss, new_width);
+
+ if (v->val_labs != NULL)
+ {
+ if (val_labs_can_set_width (v->val_labs, new_width))
+ val_labs_set_width (v->val_labs, new_width);
+ else
+ {
+ val_labs_destroy (v->val_labs);
+ v->val_labs = NULL;
+ }
+ }
+
+ if (var_get_type (v) != new_type)
+ {
+ v->print = (new_type == NUMERIC
+ ? fmt_for_output (FMT_F, 8, 2)
+ : fmt_for_output (FMT_A, new_width, 0));
+ v->write = v->print;
+ }
+ else if (new_type == ALPHA)
+ {
+ v->print.w = v->print.type == FMT_AHEX ? new_width * 2 : new_width;
+ v->write.w = v->write.type == FMT_AHEX ? new_width * 2 : new_width;
+ }
+
+ v->width = new_width;
+}
+
+/* Returns true if variable V is numeric, false otherwise. */
+bool
+var_is_numeric (const struct variable *v)
+{
+ return var_get_type (v) == NUMERIC;
+}
+
+/* Returns true if variable V is a string variable, false
+ otherwise. */
+bool
+var_is_alpha (const struct variable *v)
+{
+ return var_get_type (v) == ALPHA;
+}
+
+/* Returns true if variable V is a short string variable, false
+ otherwise. */
+bool
+var_is_short_string (const struct variable *v)
+{
+ return v->width > 0 && v->width <= MAX_SHORT_STRING;
+}
+
+/* Returns true if variable V is a long string variable, false
+ otherwise. */
+bool
+var_is_long_string (const struct variable *v)
+{
+ return v->width > MAX_SHORT_STRING;
+}
+
+/* Returns true if variable V is a very long string variable,
+ false otherwise. */
+bool
+var_is_very_long_string (const struct variable *v)
+{
+ return v->width > MAX_LONG_STRING;
+}
+
+/* Returns variable V's missing values. */
+const struct missing_values *
+var_get_missing_values (const struct variable *v)
+{
+ return &v->miss;
+}
+
+/* Sets variable V's missing values to MISS, which must be of the
+ correct width. */
+void
+var_set_missing_values (struct variable *v, const struct missing_values *miss)
+{
+ if (miss != NULL)
+ {
+ assert (v->width == mv_get_width (miss));
+ mv_copy (&v->miss, miss);
+ }
+ else
+ mv_init (&v->miss, v->width);
+}
+
+/* Sets variable V to have no user-missing values. */
+void
+var_clear_missing_values (struct variable *v)
+{
+ var_set_missing_values (v, NULL);
+}
+
+/* Returns true if V has any user-missing values,
+ false otherwise. */
+bool
+var_has_missing_values (const struct variable *v)
+{
+ return !mv_is_empty (&v->miss);
+}
+
+/* Returns true if VALUE is system missing or user-missing value
+ for V, false otherwise. */
+bool
+var_is_value_missing (const struct variable *v, const union value *value)
+{
+ return mv_is_value_missing (&v->miss, value);
+}
+
+/* Returns true if D is system missing or a missing value in V,
+ false otherwise.
+ V must be a numeric variable. */
+bool
+var_is_num_missing (const struct variable *v, double d)
+{
+ return mv_is_num_missing (&v->miss, d);
+}
+
+/* Returns true if S[] is a missing value for V, false otherwise.
+ 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[])
+{
+ return mv_is_str_missing (&v->miss, s);
+}
+
+/* Returns true if VALUE is a missing value for V, false
+ otherwise. */
+bool
+var_is_value_user_missing (const struct variable *v, const union value *value)
+{
+ return mv_is_value_user_missing (&v->miss, value);
+}
+
+/* Returns true if D is a user-missing value for V, false
+ otherwise. V must be a numeric variable. */
+bool
+var_is_num_user_missing (const struct variable *v, double d)
+{
+ return mv_is_num_user_missing (&v->miss, d);
+}
+
+/* Returns true if S[] is a missing value for V, false otherwise.
+ V must be a string variable.
+ S[] must contain exactly as many characters as V's width. */
+bool
+var_is_str_user_missing (const struct variable *v, const char s[])
+{
+ return mv_is_str_user_missing (&v->miss, s);
+}
+
+/* Returns true if V is a numeric variable and VALUE is the
+ system missing value. */
+bool
+var_is_value_system_missing (const struct variable *v,
+ const union value *value)
+{
+ return mv_is_value_system_missing (&v->miss, value);
+}
+\f
+/* Print and write formats. */
+
+/* Returns V's print format specification. */
+const struct fmt_spec *
+var_get_print_format (const struct variable *v)
+{
+ return &v->print;
+}
+
+/* Sets V's print format specification to PRINT, which must be a
+ valid format specification for outputting a variable of V's
+ width. */
+void
+var_set_print_format (struct variable *v, const struct fmt_spec *print)
+{
+ assert (fmt_check_width_compat (print, v->width));
+ v->print = *print;
+}
+
+/* Returns V's write format specification. */
+const struct fmt_spec *
+var_get_write_format (const struct variable *v)
+{
+ return &v->write;
+}
+
+/* Sets V's write format specification to WRITE, which must be a
+ valid format specification for outputting a variable of V's
+ width. */
+void
+var_set_write_format (struct variable *v, const struct fmt_spec *write)
+{
+ assert (fmt_check_width_compat (write, v->width));
+ v->write = *write;
+}
+
+/* Sets V's print and write format specifications to FORMAT,
+ which must be a valid format specification for outputting a
+ variable of V's width. */
+void
+var_set_both_formats (struct variable *v, const struct fmt_spec *format)
+{
+ var_set_print_format (v, format);
+ var_set_write_format (v, format);
+}
+\f
+/* Returns V's variable label, or a null pointer if it has none. */
+const char *
+var_get_label (const struct variable *v)
+{
+ return v->label;
+}
+
+/* Sets V's variable label to LABEL, stripping off leading and
+ trailing white space and truncating to 255 characters.
+ If LABEL is a null pointer or if LABEL is an empty string
+ (after stripping white space), then V's variable label (if
+ any) is removed. */
+void
+var_set_label (struct variable *v, const char *label)
+{
+ free (v->label);
+ v->label = NULL;
+
+ if (label != NULL)
+ {
+ struct substring s = ss_cstr (label);
+ ss_trim (&s, ss_cstr (CC_SPACES));
+ ss_truncate (&s, 255);
+ if (!ss_is_empty (s))
+ v->label = ss_xstrdup (s);
+ }
+}
+
+/* Removes any variable label from V. */
+void
+var_clear_label (struct variable *v)
+{
+ var_set_label (v, NULL);
+}
+
+/* Returns true if V has a variable V,
+ false otherwise. */
+bool
+var_has_label (const struct variable *v)
+{
+ return v->label != NULL;
}
\f
+/* Returns V's measurement level. */
+enum measure
+var_get_measure (const struct variable *v)
+{
+ return v->measure;
+}
+
+/* Sets V's measurement level to MEASURE. */
+void
+var_set_measure (struct variable *v, enum measure measure)
+{
+ assert (measure_is_valid (measure));
+ v->measure = measure;
+}
+
+/* Returns V's display width, which applies only to GUIs. */
+int
+var_get_display_width (const struct variable *v)
+{
+ return v->display_width;
+}
+
+/* Sets V's display width to DISPLAY_WIDTH. */
+void
+var_set_display_width (struct variable *v, int display_width)
+{
+ v->display_width = display_width;
+}
+
+/* Returns V's display alignment, which applies only to GUIs. */
+enum alignment
+var_get_alignment (const struct variable *v)
+{
+ return v->alignment;
+}
+
+/* Sets V's display alignment to ALIGNMENT. */
+void
+var_set_alignment (struct variable *v, enum alignment alignment)
+{
+ assert (alignment_is_valid (alignment));
+ v->alignment = alignment;
+}
+\f
+/* Returns the number of "union value"s need to store a value of
+ variable V. */
+size_t
+var_get_value_cnt (const struct variable *v)
+{
+ return v->width == 0 ? 1 : DIV_RND_UP (v->width, MAX_SHORT_STRING);
+}
+
+/* Return whether variable V's values should be preserved from
+ case to case. */
+bool
+var_get_leave (const struct variable *v)
+{
+ return v->leave;
+}
+\f
+/* Returns V's short name, if it has one, or a null pointer
+ otherwise.
+
+ Short names are used only for system and portable file input
+ and output. They are upper-case only, not necessarily unique,
+ and limited to SHORT_NAME_LEN characters (plus a null
+ terminator). Any variable may have no short name, indicated
+ by returning a null pointer. */
+const char *
+var_get_short_name (const struct variable *v)
+{
+ return v->short_name[0] != '\0' ? v->short_name : NULL;
+}
+
/* Sets V's short_name to SHORT_NAME, truncating it to
SHORT_NAME_LEN characters and converting it to uppercase in
- the process. */
+ the process. Specifying a null pointer for SHORT_NAME clears
+ the variable's short name. */
void
var_set_short_name (struct variable *v, const char *short_name)
{
assert (v != NULL);
- assert (short_name[0] == '\0' || var_is_plausible_name (short_name, false));
-
- str_copy_trunc (v->short_name, sizeof v->short_name, short_name);
- str_uppercase (v->short_name);
+ assert (short_name == NULL || var_is_plausible_name (short_name, false));
+
+ if (short_name != NULL)
+ {
+ str_copy_trunc (v->short_name, sizeof v->short_name, short_name);
+ str_uppercase (v->short_name);
+ }
+ else
+ v->short_name[0] = '\0';
}
/* Clears V's short name. */
/* Sets V's short name to BASE, followed by a suffix of the form
_A, _B, _C, ..., _AA, _AB, etc. according to the value of
- SUFFIX. Truncates BASE as necessary to fit. */
+ SUFFIX_NUMBER. Truncates BASE as necessary to fit. */
void
-var_set_short_name_suffix (struct variable *v, const char *base, int suffix)
+var_set_short_name_suffix (struct variable *v, const char *base,
+ int suffix_number)
{
- char string[SHORT_NAME_LEN + 1];
+ char suffix[SHORT_NAME_LEN + 1];
+ char short_name[SHORT_NAME_LEN + 1];
char *start, *end;
int len, ofs;
assert (v != NULL);
- assert (suffix >= 0);
- assert (strlen (v->short_name) > 0);
+ assert (suffix_number >= 0);
/* Set base name. */
var_set_short_name (v, base);
- /* Compose suffix_string. */
- start = end = string + sizeof string - 1;
+ /* Compose suffix. */
+ start = end = suffix + sizeof suffix - 1;
*end = '\0';
do
{
- *--start = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[suffix % 26];
- if (start <= string + 1)
+ *--start = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[suffix_number % 26];
+ if (start <= suffix + 1)
msg (SE, _("Variable suffix too large."));
- suffix /= 26;
+ suffix_number /= 26;
}
- while (suffix > 0);
+ while (suffix_number > 0);
*--start = '_';
- /* Append suffix_string to V's short name. */
+ /* Append suffix to V's short name. */
+ str_copy_trunc (short_name, sizeof short_name, base);
len = end - start;
- if (len + strlen (v->short_name) > SHORT_NAME_LEN)
+ if (len + strlen (short_name) > SHORT_NAME_LEN)
ofs = SHORT_NAME_LEN - len;
else
- ofs = strlen (v->short_name);
- strcpy (v->short_name + ofs, start);
+ ofs = strlen (short_name);
+ strcpy (short_name + ofs, start);
+
+ /* Set name. */
+ var_set_short_name (v, short_name);
}
ALPHA /* A string variable. */
};
+bool var_type_is_valid (enum var_type);
const char *var_type_adj (enum var_type);
const char *var_type_noun (enum var_type);
+/* Alignment of data for display. */
+enum alignment
+ {
+ ALIGN_LEFT = 0,
+ ALIGN_RIGHT = 1,
+ ALIGN_CENTRE = 2,
+ n_ALIGN
+ };
+
+bool alignment_is_valid (enum alignment);
+
+/* How data is measured. */
+enum measure
+ {
+ MEASURE_NOMINAL = 1,
+ MEASURE_ORDINAL = 2,
+ MEASURE_SCALE = 3,
+ n_MEASURES
+ };
+
+bool measure_is_valid (enum measure);
+
/* Maximum lengths of short and long variable names.
Most operations support long variable names,
but some file formats are limited to short names. */
{
/* Dictionary information. */
char name[LONG_NAME_LEN + 1]; /* Variable name. Mixed case. */
- enum var_type type; /* NUMERIC or ALPHA. */
- int width; /* Size of string variables in chars. */
+ int width; /* 0 for numeric, otherwise string width. */
struct missing_values miss; /* Missing values. */
struct fmt_spec print; /* Default format for PRINT. */
struct fmt_spec write; /* Default format for WRITE. */
struct val_labs *val_labs; /* Value labels. */
char *label; /* Variable label. */
+
+ /* GUI information. */
enum measure measure; /* Nominal, ordinal, or continuous. */
int display_width; /* Width of data editor column. */
enum alignment alignment; /* Alignment of data in GUI. */
/* Case information. */
- int fv, nv; /* Index into `value's, number of values. */
+ int fv; /* Index into `value's. */
bool leave; /* Leave value from case to case? */
/* Data for use by containing dictionary. */
};
/* Variable names. */
+const char *var_get_name (const struct variable *);
+void var_set_name (struct variable *, const char *);
bool var_is_valid_name (const char *, bool issue_error);
bool var_is_plausible_name (const char *name, bool issue_error);
int compare_var_names (const void *, const void *, const void *);
unsigned hash_var_name (const void *, const void *);
+/* Variable types and widths. */
+enum var_type var_get_type (const struct variable *);
+int var_get_width (const struct variable *);
+void var_set_width (struct variable *, int width);
+bool var_is_numeric (const struct variable *);
+bool var_is_alpha (const struct variable *);
+bool var_is_short_string (const struct variable *);
+bool var_is_long_string (const struct variable *);
+bool var_is_very_long_string (const struct variable *);
+
+/* Variables' missing values. */
+const struct missing_values *var_get_missing_values (const struct variable *);
+void var_set_missing_values (struct variable *, const struct missing_values *);
+void var_clear_missing_values (struct variable *);
+bool var_has_missing_values (const struct variable *);
+
+typedef bool var_is_missing_func (const struct variable *,
+ const union value *);
+bool var_is_value_missing (const struct variable *, const union value *);
+bool var_is_num_missing (const struct variable *, double);
+bool var_is_str_missing (const struct variable *, const char[]);
+bool var_is_value_user_missing (const struct variable *,
+ const union value *);
+bool var_is_num_user_missing (const struct variable *, double);
+bool var_is_str_user_missing (const struct variable *, const char[]);
+bool var_is_value_system_missing (const struct variable *,
+ const union value *);
+
+/* Print and write formats. */
+const struct fmt_spec *var_get_print_format (const struct variable *);
+void var_set_print_format (struct variable *, const struct fmt_spec *);
+const struct fmt_spec *var_get_write_format (const struct variable *);
+void var_set_write_format (struct variable *, const struct fmt_spec *);
+void var_set_both_formats (struct variable *, const struct fmt_spec *);
+
+/* Variable labels. */
+const char *var_get_label (const struct variable *);
+void var_set_label (struct variable *, const char *);
+void var_clear_label (struct variable *);
+bool var_has_label (const struct variable *);
+
+/* GUI information. */
+enum measure var_get_measure (const struct variable *);
+void var_set_measure (struct variable *, enum measure);
+
+int var_get_display_width (const struct variable *);
+void var_set_display_width (struct variable *, int display_width);
+
+enum alignment var_get_alignment (const struct variable *);
+void var_set_alignment (struct variable *, enum alignment);
+
+/* Variable location in cases. */
+size_t var_get_value_cnt (const struct variable *);
+
+/* Whether variables' values should be preserved from case to
+ case. */
+bool var_get_leave (const struct variable *);
+
/* Short names. */
+const char *var_get_short_name (const struct variable *);
void var_set_short_name (struct variable *, const char *);
void var_set_short_name_suffix (struct variable *, const char *, int suffix);
void var_clear_short_name (struct variable *);
{
/* Success. */
struct fmt_spec output = fmt_for_output_from_input (f);
- v->print = output;
- v->write = output;
+ var_set_both_formats (v, &output);
}
else
{
}
v = dict_lookup_var_assert (dict, name);
- if ((width != 0) != (v->width != 0))
+ if ((width != 0) != (var_get_width (v) != 0))
{
msg (SE, _("There is already a variable %s of a "
"different type."),
name);
return false;
}
- if (width != 0 && width != v->width)
+ if (width != 0 && width != var_get_width (v))
{
msg (SE, _("There is already a string variable %s of a "
"different width."), name);
spec->fv = v->fv;
spec->record = record;
spec->first_column = column;
- strcpy (spec->name, v->name);
+ strcpy (spec->name, var_get_name (v));
ll_push_tail (&dls->specs, &spec->ll);
column += f->w;
msg (SE, _("%s is a duplicate variable name."), name[i]);
return 0;
}
- v->print = v->write = output;
+ var_set_both_formats (v, &output);
spec = pool_alloc (dls->pool, sizeof *spec);
spec->input = input;
spec->fv = v->fv;
- strcpy (spec->name, v->name);
+ strcpy (spec->name, var_get_name (v));
ll_push_tail (&dls->specs, &spec->ll);
}
}
"a variable named %s. To rename variables with "
"overlapping names, use a single RENAME subcommand "
"such as \"/RENAME (A=B)(B=C)(C=A)\", or equivalently, "
- "\"/RENAME (A B C=B C A)\"."), v->name, lex_tokid (lexer), lex_tokid (lexer));
+ "\"/RENAME (A B C=B C A)\"."),
+ var_get_name (v), lex_tokid (lexer), lex_tokid (lexer));
return 0;
}
for (i = 0; i < mtf.by_cnt; i++)
{
- iter->by[i] = dict_lookup_var (iter->dict, by[i]->name);
+ iter->by[i] = dict_lookup_var (iter->dict,
+ var_get_name (by[i]));
if (iter->by[i] == NULL)
{
msg (SE, _("File %s lacks BY variable %s."),
iter->handle ? fh_get_name (iter->handle) : "*",
- by[i]->name);
+ var_get_name (by[i]));
free (by);
goto error;
}
for (i = 0; i < dict_get_var_cnt (d); i++)
{
struct variable *v = dict_get_var (d, i);
- struct variable *mv = dict_lookup_var (mtf.dict, v->name);
+ struct variable *mv = dict_lookup_var (mtf.dict, var_get_name (v));
if (mv != NULL)
set_master (v, mv);
}
for (iter = mtf.head; iter != NULL; iter = iter->next)
if (iter->in_name != NULL)
{
+ struct fmt_spec format = fmt_for_output (FMT_F, 1, 0);
iter->in_var = dict_create_var (mtf.dict, iter->in_name, 0);
if (iter->in_var == NULL)
{
msg (SE, _("IN variable name %s duplicates an "
"existing variable name."),
- iter->in_var->name);
+ var_get_name (iter->in_var));
goto error;
}
- iter->in_var->print = iter->in_var->write
- = fmt_for_output (FMT_F, 1, 0);
+ var_set_both_formats (iter->in_var, &format);
}
/* MATCH FILES performs an n-way merge on all its input files.
x ^= 1;
s = buf[x];
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
strcpy (s, "numeric");
else
- {
- assert (v->type == ALPHA);
- sprintf (s, "string with width %d", v->width);
- }
+ sprintf (s, "string with width %d", var_get_width (v));
return s;
}
{
union value *out = case_data_rw (&mtf->mtf_case, mv->fv);
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
out->f = SYSMIS;
else
- memset (out->s, ' ', v->width);
+ memset (out->s, ' ', var_get_width (v));
}
}
union value *out = case_data_rw (&mtf->mtf_case, mv->fv);
mtf->seq_nums[mv->index] = mtf->seq_num;
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
out->f = case_num (record, v->fv);
else
- memcpy (out->s, case_str (record, v->fv), v->width);
+ memcpy (out->s, case_str (record, v->fv),
+ var_get_width (v));
}
}
if (iter->in_var != NULL)
union value *out = case_data_rw (&mtf->mtf_case, mv->fv);
mtf->seq_nums[mv->index] = mtf->seq_num;
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
out->f = SYSMIS;
else
- memset (out->s, ' ', v->width);
+ memset (out->s, ' ', var_get_width (v));
}
}
if (iter->in_var != NULL)
for (i = 0; i < dict_get_var_cnt (d); i++)
{
struct variable *dv = dict_get_var (d, i);
- struct variable *mv = dict_lookup_var (m, dv->name);
+ struct variable *mv = dict_lookup_var (m, var_get_name (dv));
- if (dict_class_from_id (dv->name) == DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (dv)) == DC_SCRATCH)
continue;
if (mv != NULL)
{
- if (mv->width != dv->width)
+ if (var_get_width (mv) != var_get_width (dv))
{
msg (SE, _("Variable %s in file %s (%s) has different "
"type or width from the same variable in "
"earlier file (%s)."),
- dv->name, fh_get_name (f->handle),
+ var_get_name (dv), fh_get_name (f->handle),
var_type_description (dv), var_type_description (mv));
return 0;
}
- if (dv->width == mv->width)
+ if (var_get_width (dv) == var_get_width (mv))
{
if (val_labs_count (dv->val_labs)
&& !val_labs_count (mv->val_labs))
val_labs_destroy (mv->val_labs);
mv->val_labs = val_labs_copy (dv->val_labs);
}
- if (!mv_is_empty (&dv->miss) && mv_is_empty (&mv->miss))
- mv_copy (&mv->miss, &dv->miss);
+ if (var_has_missing_values (dv) && !var_has_missing_values (mv))
+ var_set_missing_values (mv, var_get_missing_values (dv));
}
- if (dv->label && !mv->label)
- mv->label = xstrdup (dv->label);
+ if (var_get_label (dv) && !var_get_label (mv))
+ var_set_label (mv, var_get_label (dv));
}
else
- mv = dict_clone_var_assert (m, dv, dv->name);
+ mv = dict_clone_var_assert (m, dv, var_get_name (dv));
}
return 1;
for (i = 0; i < var_cnt; i++)
{
struct variable *v = dict_get_var (d, i);
+ size_t value_cnt = var_get_value_cnt (v);
int *src_fv = (int *) var_detach_aux (v);
size_t idx;
if (v->fv != *src_fv)
identity_map = 0;
- for (idx = 0; idx < v->nv; idx++)
+ for (idx = 0; idx < value_cnt; idx++)
{
int src_idx = *src_fv + idx;
int dst_idx = v->fv + idx;
for (i = 0; i < dict_get_var_cnt (dataset_dict (ds)); i++)
{
struct variable *var = dict_get_var (dataset_dict (ds), i);
+ size_t value_cnt = var_get_value_cnt (var);
enum value_init_type value_init;
size_t j;
- value_init = var->type == NUMERIC ? INP_NUMERIC : INP_STRING;
- value_init |= var->leave ? INP_INIT_ONCE : INP_REINIT;
+ value_init = var_is_numeric (var) ? INP_NUMERIC : INP_STRING;
+ value_init |= var_get_leave (var) ? INP_INIT_ONCE : INP_REINIT;
- for (j = 0; j < var->nv; j++)
+ for (j = 0; j < value_cnt; j++)
inp->init[j + var->fv] = value_init;
}
for (i = 0; i < inp->init_cnt; i++)
if (cmd.numbering == LST_NUMBERED)
{
/* Initialize the case-number variable. */
- strcpy (casenum_var.name, "Case#");
- casenum_var.type = NUMERIC;
+ int width = cmd.last == LONG_MAX ? 5 : intlog10 (cmd.last);
+ struct fmt_spec format = fmt_for_output (FMT_F, width, 0);
+ var_set_name (&casenum_var, "Case#");
+ casenum_var.width = 0;
casenum_var.fv = -1;
- casenum_var.print = fmt_for_output (FMT_F,
- (cmd.last == LONG_MAX
- ? 5 : intlog10 (cmd.last)), 0);
+ var_set_both_formats (&casenum_var, &format);
/* Add the weight variable at the beginning of the variable list. */
cmd.n_variables++;
for (i = 0; i < cmd.n_variables; i++)
fprintf (x->file, " <TH><EM>%s</EM></TH>\n",
- cmd.v_variables[i]->name);
+ var_get_name (cmd.v_variables[i]));
}
fputs (" </TR>\n", x->file);
for (i = x = 0; i < prc->n_vertical; i++)
{
struct variable *v = cmd.v_variables[i];
+ const char *name = var_get_name (v);
+ size_t name_len = strlen (name);
+ const struct fmt_spec *print = var_get_print_format (v);
size_t j;
- memset (&prc->header[prc->header_rows - 1][x], '-', v->print.w);
- x += v->print.w - 1;
- for (j = 0; j < strlen (v->name); j++)
- prc->header[strlen (v->name) - j - 1][x] = v->name[j];
+ memset (&prc->header[prc->header_rows - 1][x], '-', print->w);
+ x += print->w - 1;
+ for (j = 0; j < name_len; j++)
+ prc->header[name_len - j - 1][x] = name[j];
x += 2;
}
for (; i < cmd.n_variables; i++)
{
struct variable *v = cmd.v_variables[i];
+ const char *name = var_get_name (v);
+ size_t name_len = strlen (name);
+ const struct fmt_spec *print = var_get_print_format (v);
memset (&prc->header[prc->header_rows - 1][x], '-',
- MAX (v->print.w, (int) strlen (v->name)));
- if ((int) strlen (v->name) < v->print.w)
- x += v->print.w - strlen (v->name);
- memcpy (&prc->header[0][x], v->name, strlen (v->name));
- x += strlen (v->name) + 1;
+ MAX (print->w, (int) name_len));
+ if ((int) name_len < print->w)
+ x += print->w - name_len;
+ memcpy (&prc->header[0][x], name, name_len);
+ x += name_len + 1;
}
/* Add null bytes. */
entry:
{
- int var_width = cmd.v_variables[index]->print.w;
+ int var_width = var_get_print_format (cmd.v_variables[index])->w;
if (width + var_width > max_width && width != 0)
{
width = 0;
{
char varname[LONG_NAME_LEN + 2];
snprintf (varname, sizeof varname,
- " %s", cmd.v_variables[index]->name);
+ " %s", var_get_name (cmd.v_variables[index]));
write_varname (d, varname, leader_width);
}
}
for (width = cmd.n_variables - 1, column = 0; column < cmd.n_variables; column++)
{
struct variable *v = cmd.v_variables[column];
- width += MAX (v->print.w, (int) strlen (v->name));
+ int fmt_width = var_get_print_format (v)->w;
+ int name_len = strlen (var_get_name (v));
+ width += MAX (fmt_width, name_len);
}
if (width <= max_width)
{
column++)
{
struct variable *v = cmd.v_variables[column];
- width += v->print.w;
- if (strlen (v->name) > height)
- height = strlen (v->name);
+ int fmt_width = var_get_print_format (v)->w;
+ size_t name_len = strlen (var_get_name (v));
+ width += fmt_width;
+ if (name_len > height)
+ height = name_len;
}
/* If it fit then we need to determine how many labels can be
for (column = cmd.n_variables; column-- != 0; )
{
struct variable *v = cmd.v_variables[column];
- int trial_width = (width - v->print.w
- + MAX (v->print.w, (int) strlen (v->name)));
-
+ int name_len = strlen (var_get_name (v));
+ int fmt_width = var_get_print_format (v)->w;
+ int trial_width = width - fmt_width + MAX (fmt_width, name_len);
if (trial_width > max_width)
{
prc->n_vertical = column + 1;
/* Finally determine the length of the headers. */
for (prc->header_rows = 0, column = 0;
column < prc->n_vertical;
- column++)
- prc->header_rows = MAX (prc->header_rows,
- strlen (cmd.v_variables[column]->name));
+ column++)
+ {
+ struct variable *var = cmd.v_variables[column];
+ size_t name_len = strlen (var_get_name (var));
+ prc->header_rows = MAX (prc->header_rows, name_len);
+ }
prc->header_rows++;
continue;
}
if (!prc->header_rows)
{
- ds_put_format(&line_buffer, "%8s: ", cmd.v_variables[0]->name);
+ ds_put_format(&line_buffer, "%8s: ",
+ var_get_name (cmd.v_variables[0]));
}
for (column = 0; column < cmd.n_variables; column++)
{
struct variable *v = cmd.v_variables[column];
+ const struct fmt_spec *print = var_get_print_format (v);
int width;
- if (prc->type == 0 && column >= prc->n_vertical)
- width = MAX ((int) strlen (v->name), v->print.w);
+ if (prc->type == 0 && column >= prc->n_vertical)
+ {
+ int name_len = strlen (var_get_name (v));
+ width = MAX (name_len, print->w);
+ }
else
- width = v->print.w;
+ width = print->w;
if (width + ds_length(&line_buffer) > max_width &&
ds_length(&line_buffer) != 0)
ds_clear(&line_buffer);
if (!prc->header_rows)
- {
- ds_put_format (&line_buffer, "%8s: ", v->name);
- }
+ ds_put_format (&line_buffer, "%8s: ", var_get_name (v));
}
- if (width > v->print.w)
- {
- ds_put_char_multiple(&line_buffer, ' ', width - v->print.w);
- }
+ if (width > print->w)
+ ds_put_char_multiple(&line_buffer, ' ', width - print->w);
- if (fmt_is_string (v->print.type) || v->fv != -1)
+ if (fmt_is_string (print->type) || v->fv != -1)
{
- data_out (case_data (c, v->fv), &v->print,
- ds_put_uninit (&line_buffer, v->print.w));
+ data_out (case_data (c, v->fv), print,
+ ds_put_uninit (&line_buffer, print->w));
}
else
{
union value case_idx_value;
case_idx_value.f = case_idx;
- data_out (&case_idx_value, &v->print,
- ds_put_uninit (&line_buffer,v->print.w));
+ data_out (&case_idx_value, print,
+ ds_put_uninit (&line_buffer,print->w));
}
ds_put_char(&line_buffer, ' ');
for (column = 0; column < cmd.n_variables; column++)
{
struct variable *v = cmd.v_variables[column];
+ const struct fmt_spec *print = var_get_print_format (v);
char buf[256];
- if (fmt_is_string (v->print.type) || v->fv != -1)
- data_out (case_data (c, v->fv), &v->print, buf);
+ if (fmt_is_string (print->type) || v->fv != -1)
+ data_out (case_data (c, v->fv), print, buf);
else
{
union value case_idx_value;
case_idx_value.f = case_idx;
- data_out (&case_idx_value, &v->print, buf);
+ data_out (&case_idx_value, print, buf);
}
fputs (" <TD>", x->file);
- html_put_cell_contents (d, TAB_FIX, ss_buffer (buf, v->print.w));
+ html_put_cell_contents (d, TAB_FIX, ss_buffer (buf, print->w));
fputs ("</TD>\n", x->file);
}
int type = mv->var_type;
assert (type >= 0 && type < MXD_COUNT);
- v->print = v->write = fmt_tab[type];
+ var_set_both_formats (v, &fmt_tab[type]);
if (type == MXD_CONTINUOUS)
mx->n_continuous++;
if (token.type != MNUM)
{
msg (SE, _("expecting value for %s %s"),
- dict_get_var (nr->dict, j)->name,
+ var_get_name (dict_get_var (nr->dict, j)),
context (mx->reader));
return 0;
}
{
msg (SE, _("Expecting value %g for %s."),
nr->split_values[i],
- dict_get_split_vars (nr->dict)[i]->name);
+ var_get_name (dict_get_split_vars (nr->dict)[i]));
return false;
}
}
{
msg (SE, _("Syntax error expecting value %g for %s %s."),
nr->factor_values[i + mx->n_factors * cell],
- mx->factors[i]->name, context (mx->reader));
+ var_get_name (mx->factors[i]), context (mx->reader));
return false;
}
}
}
if (type == 1)
buf_copy_str_rpad (case_data_rw (c, mx->varname_->fv)->s, 8,
- dict_get_var (dict,
- mx->first_continuous + i)->name);
+ var_get_name (
+ dict_get_var (dict, mx->first_continuous + i)));
if (!write_case (wc_data))
return false;
}
if (token.type != MNUM)
{
msg (SE, _("Syntax error expecting value for %s %s."),
- dict_get_var (wr->dict, mx->first_continuous + j)->name,
+ var_get_name (dict_get_var (wr->dict,
+ mx->first_continuous + j)),
context (mx->reader));
return false;
}
for (i = 0; i < var_cnt; i++)
{
struct variable *v = vars[i];
- formats[i] = which_formats == PRINT ? v->print : v->write;
+ formats[i] = (which_formats == PRINT
+ ? *var_get_print_format (v)
+ : *var_get_write_format (v));
}
add_space = which_formats == PRINT;
}
struct prt_out_spec *spec;
var = vars[var_idx++];
- if (!fmt_check_width_compat (f, var->width))
+ if (!fmt_check_width_compat (f, var_get_width (var)))
return false;
spec = pool_alloc (trns->pool, sizeof *spec);
filled with spaces, instead of using the normal format
that usually contains a period. */
spec->sysmis_as_spaces = (which_formats == WRITE
- && var->type == NUMERIC
+ && var_is_numeric (var)
&& (fmt_get_category (spec->format.type)
!= FMT_CAT_BINARY));
width = ds_length (&spec->string);
break;
case PRT_VAR:
- tab_text (t, 0, row, TAB_LEFT, spec->var->name);
+ tab_text (t, 0, row, TAB_LEFT, var_get_name (spec->var));
tab_text (t, 3, row, TAB_LEFT | TAB_FIX,
fmt_to_string (&spec->format, fmt_string));
width = spec->format.w;
for (i = 0; i < dict_get_var_cnt (dict); i++)
{
struct variable *s = dict_get_var (dict, i);
- struct variable *t = dict_lookup_var (dataset_dict (ds), s->name);
+ struct variable *t = dict_lookup_var (dataset_dict (ds),
+ var_get_name (s));
if (t == NULL)
continue;
n_matched++;
- if (s->type != t->type)
+ if (var_get_type (s) != var_get_type (t))
{
msg (SW, _("Variable %s is %s in target file, but %s in "
"source file."),
- s->name,
- t->type == ALPHA ? _("string") : _("numeric"),
- s->type == ALPHA ? _("string") : _("numeric"));
+ var_get_name (s),
+ var_is_alpha (t) ? _("string") : _("numeric"),
+ var_is_alpha (s) ? _("string") : _("numeric"));
continue;
}
- if (s->label && strcspn (s->label, " ") != strlen (s->label))
- {
- free (t->label);
- t->label = s->label;
- s->label = NULL;
- }
-
- if (val_labs_count (s->val_labs) && t->width > MAX_SHORT_STRING)
+ if (var_get_label (s))
+ {
+ const char *label = var_get_label (s);
+ if (strcspn (label, " ") != strlen (label))
+ var_set_label (t, label);
+ }
+
+ if (val_labs_count (s->val_labs) && var_is_long_string (t))
msg (SW, _("Cannot add value labels from source file to "
"long string variable %s."),
- s->name);
+ var_get_name (s));
else if (val_labs_count (s->val_labs))
{
- if (val_labs_can_set_width (s->val_labs, t->width))
+ if (val_labs_can_set_width (s->val_labs, var_get_width (t)))
{
val_labs_destroy (t->val_labs);
t->val_labs = s->val_labs;
- val_labs_set_width (t->val_labs, t->width);
- s->val_labs = val_labs_create (s->width);
+ val_labs_set_width (t->val_labs, var_get_width (t));
+ s->val_labs = val_labs_create (var_get_width (s));
}
}
- if (!mv_is_empty (&s->miss) && t->width > MAX_SHORT_STRING)
- msg (SW, _("Cannot apply missing values from source file to "
- "long string variable %s."),
- s->name);
- else if (!mv_is_empty (&s->miss))
- {
- if (mv_is_resizable (&s->miss, t->width))
+ if (var_has_missing_values (s))
+ {
+ if (!var_is_long_string (t))
{
- mv_copy (&t->miss, &s->miss);
- mv_resize (&t->miss, t->width);
+ struct missing_values miss;
+ mv_copy (&miss, var_get_missing_values (s));
+ if (mv_is_resizable (&miss, var_get_width (t)))
+ {
+ mv_resize (&miss, var_get_width (t));
+ var_set_missing_values (t, &miss);
+ }
}
- }
+ else
+ msg (SW, _("Cannot apply missing values from source file to "
+ "long string variable %s."),
+ var_get_name (s));
+ }
- if (s->type == NUMERIC)
+ if (var_is_numeric (s))
{
- t->print = s->print;
- t->write = s->write;
+ var_set_print_format (t, var_get_print_format (s));
+ var_set_write_format (t, var_get_write_format (s));
}
}
if (dict_get_weight (dict) != NULL)
{
struct variable *new_weight
- = dict_lookup_var (dataset_dict (ds), dict_get_weight (dict)->name);
+ = dict_lookup_var (dataset_dict (ds),
+ var_get_name (dict_get_weight (dict)));
if (new_weight != NULL)
dict_set_weight (dataset_dict (ds), new_weight);
if (!parse_variables (lexer, dataset_dict (ds), &v, &cv, PV_NUMERIC))
return CMD_FAILURE;
- type = v[0]->type;
+ type = var_get_type (v[0]);
if (!lex_match (lexer, '('))
{
for (i = 0; i < cv; i++)
{
if (which & FORMATS_PRINT)
- v[i]->print = f;
+ var_set_print_format (v[i], &f);
if (which & FORMATS_WRITE)
- v[i]->write = f;
+ var_set_write_format (v[i], &f);
}
free (v);
v = NULL;
}
for (i = 0; i < nv; i++)
- mv_init (&v[i]->miss, v[i]->width);
+ var_clear_missing_values (v[i]);
if (!lex_match (lexer, ')'))
{
struct missing_values mv;
for (i = 0; i < nv; i++)
- if (v[i]->type != v[0]->type)
+ if (var_get_type (v[i]) != var_get_type (v[0]))
{
- const struct variable *n = v[0]->type == NUMERIC ? v[0] : v[i];
- const struct variable *s = v[0]->type == NUMERIC ? v[i] : v[0];
+ const struct variable *n = var_is_numeric (v[0]) ? v[0] : v[i];
+ const struct variable *s = var_is_numeric (v[0]) ? v[i] : v[0];
msg (SE, _("Cannot mix numeric variables (e.g. %s) and "
"string variables (e.g. %s) within a single list."),
- n->name, s->name);
+ var_get_name (n), var_get_name (s));
goto done;
}
- if (v[0]->type == NUMERIC)
+ if (var_is_numeric (v[0]))
{
mv_init (&mv, 0);
while (!lex_match (lexer, ')'))
{
+ enum fmt_type type = var_get_print_format (v[0])->type;
double x, y;
bool ok;
- if (!parse_num_range (lexer, &x, &y, &v[0]->print.type))
+ if (!parse_num_range (lexer, &x, &y, &type))
goto done;
ok = (x == y
for (i = 0; i < nv; i++)
{
- if (!mv_is_resizable (&mv, v[i]->width))
+ if (!mv_is_resizable (&mv, var_get_width (v[i])))
{
msg (SE, _("Missing values provided are too long to assign "
"to variable of width %d."),
- v[i]->width);
+ var_get_width (v[i]));
deferred_errors = true;
}
else
{
- mv_copy (&v[i]->miss, &mv);
- mv_resize (&v[i]->miss, v[i]->width);
+ struct missing_values tmp;
+ mv_copy (&tmp, &mv);
+ mv_resize (&tmp, var_get_width (v[i]));
+ var_set_missing_values (v[i], &tmp);
}
}
}
if (ordering->positional)
result = a->index < b->index ? -1 : a->index > b->index;
else
- result = strcasecmp (a->name, b->name);
+ result = strcasecmp (var_get_name (a), var_get_name (b));
if (!ordering->forward)
result = -result;
return result;
for (i = 0; i < keep_cnt; i++)
{
var_renaming[i].var = keep_vars[i];
- strcpy (var_renaming[i].new_name, keep_vars[i]->name);
+ strcpy (var_renaming[i].new_name, var_get_name (keep_vars[i]));
}
/* Rename variables in var_renaming array. */
still exist, but we can still look them up by name. */
rename_old_names = xnmalloc (vm->rename_cnt, sizeof *rename_old_names);
for (i = 0; i < vm->rename_cnt; i++)
- rename_old_names[i] = xstrdup (vm->rename_vars[i]->name);
+ rename_old_names[i] = xstrdup (var_get_name (vm->rename_vars[i]));
/* Reorder and delete variables. */
dict_reorder_vars (d, vm->reorder_vars, vm->reorder_cnt);
else
{
if (f.type != -1)
- new_var->print = new_var->write = f;
+ var_set_both_formats (new_var, &f);
}
}
if (!new_var)
msg (SE, _("There is already a variable named %s."), v[i]);
else
- new_var->print = new_var->write = f;
+ var_set_both_formats (new_var, &f);
}
/* Clean up. */
struct variable *v = split[i];
char temp_buf[80];
const char *val_lab;
+ const struct fmt_spec *print = var_get_print_format (v);
- assert (v->type == NUMERIC || v->type == ALPHA);
- tab_text (t, 0, i + 1, TAB_LEFT | TAT_PRINTF, "%s", v->name);
+ tab_text (t, 0, i + 1, TAB_LEFT | TAT_PRINTF, "%s", var_get_name (v));
- data_out (case_data (c, v->fv), &v->print, temp_buf);
-
- temp_buf[v->print.w] = 0;
- tab_text (t, 1, i + 1, TAT_PRINTF, "%.*s", v->print.w, temp_buf);
+ data_out (case_data (c, v->fv), print, temp_buf);
+ temp_buf[print->w] = 0;
+
+ tab_text (t, 1, i + 1, TAT_PRINTF, "%.*s", print->w, temp_buf);
val_lab = val_labs_find (v->val_labs, *case_data (c, v->fv));
if (val_lab)
{
struct variable *weight_var = dict_get_weight (d);
tab_text (t, 1, 7, TAB_LEFT,
- weight_var != NULL ? weight_var->name : _("Not weighted."));
+ (weight_var != NULL
+ ? var_get_name (weight_var) : _("Not weighted.")));
}
tab_text (t, 0, 8, TAB_LEFT, _("Mode:"));
tab_text (t, 1, 8, TAB_LEFT | TAT_PRINTF,
{
size_t i, m;
for (i = 0, m = n; i < n; i++)
- if (dict_class_from_id (vl[i]->name) != DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (vl[i])) != DC_SCRATCH)
{
vl[i] = NULL;
m--;
r = describe_variable (v, t, r, as);
} else {
- tab_text (t, 0, r, TAB_LEFT, v->name);
- if (as == AS_LABELS)
- tab_joint_text (t, 1, r, 2, r, TAB_LEFT,
- v->label == NULL ? "(no label)" : v->label);
+ tab_text (t, 0, r, TAB_LEFT, var_get_name (v));
+ if (as == AS_LABELS)
+ {
+ const char *label = var_get_label (v);
+ tab_joint_text (t, 1, r, 2, r, TAB_LEFT,
+ label != NULL ? "(no label)" : label);
+ }
if (as != AS_NAMES)
{
tab_text (t, pc, r, TAT_PRINTF, "%d", v->index + 1);
static int
describe_variable (struct variable *v, struct tab_table *t, int r, int as)
{
+ const struct fmt_spec *print = var_get_print_format (v);
+ const struct fmt_spec *write = var_get_write_format (v);
+
/* Put the name, var label, and position into the first row. */
- tab_text (t, 0, r, TAB_LEFT, v->name);
+ tab_text (t, 0, r, TAB_LEFT, var_get_name (v));
tab_text (t, 3, r, TAT_PRINTF, "%d", v->index + 1);
- if (as == AS_DICTIONARY && v->label)
+ if (as == AS_DICTIONARY && var_has_label (v))
{
- tab_joint_text (t, 1, r, 2, r, TAB_LEFT, v->label);
+ tab_joint_text (t, 1, r, 2, r, TAB_LEFT, var_get_label (v));
r++;
}
/* Print/write format, or print and write formats. */
- if (v->print.type == v->write.type
- && v->print.w == v->write.w
- && v->print.d == v->write.d)
+ if (fmt_equal (print, write))
{
char str[FMT_STRING_LEN_MAX + 1];
tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, _("Format: %s"),
- fmt_to_string (&v->print, str));
+ fmt_to_string (print, str));
r++;
}
else
{
char str[FMT_STRING_LEN_MAX + 1];
tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF,
- _("Print Format: %s"), fmt_to_string (&v->print, str));
+ _("Print Format: %s"), fmt_to_string (print, str));
r++;
tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF,
- _("Write Format: %s"), fmt_to_string (&v->write, str));
+ _("Write Format: %s"), fmt_to_string (write, str));
r++;
}
/* Missing values if any. */
- if (!mv_is_empty (&v->miss))
+ if (var_has_missing_values (v))
{
char buf[128];
char *cp;
int cnt = 0;
cp = stpcpy (buf, _("Missing Values: "));
- mv_copy (&mv, &v->miss);
+
+ mv_copy (&mv, var_get_missing_values (v));
if (mv_has_range (&mv))
{
double x, y;
mv_pop_value (&mv, &value);
if (cnt++ > 0)
cp += sprintf (cp, "; ");
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
cp += sprintf (cp, "%g", value.f);
else
{
*cp++ = '"';
- memcpy (cp, value.s, v->width);
- cp += v->width;
+ memcpy (cp, value.s, var_get_width (v));
+ cp += var_get_width (v);
*cp++ = '"';
*cp = '\0';
}
{
char buf[128];
- if (v->type == ALPHA)
+ if (var_is_alpha (v))
{
- memcpy (buf, vl->value.s, v->width);
- buf[v->width] = 0;
+ memcpy (buf, vl->value.s, var_get_width (v));
+ buf[var_get_width (v)] = 0;
}
else
sprintf (buf, "%g", vl->value.f);
{
struct variable *vp = vars[i];
- if (vp->type == ALPHA && vp->width > MAX_SHORT_STRING)
+ if (var_is_long_string (vp))
{
msg (SE, _("It is not possible to assign value labels to long "
- "string variables such as %s."), vp->name);
+ "string variables such as %s."), var_get_name (vp));
return 0;
}
}
size_t i;
/* Set value. */
- if (vars[0]->type == ALPHA)
+ if (var_is_alpha (vars[0]))
{
if (lex_token (lexer) != T_STRING)
{
return CMD_FAILURE;
}
- for( i = 0 ; i < nv ; ++i )
- v[i]->alignment = align;
-
+ for( i = 0 ; i < nv ; ++i )
+ var_set_alignment (v[i], align);
while (lex_token (lexer) == '/')
lex_get (lexer);
}
for( i = 0 ; i < nv ; ++i )
- v[i]->display_width = lex_tokval (lexer);
+ var_set_display_width (v[i], lex_integer (lexer));
while (lex_token (lexer) == '/')
lex_get (lexer);
}
for( i = 0 ; i < nv ; ++i )
- v[i]->measure = level ;
+ var_set_measure (v[i], level);
while (lex_token (lexer) == '/')
ds_truncate (&label, 255);
}
for (i = 0; i < nv; i++)
- {
- if (v[i]->label)
- free (v[i]->label);
- v[i]->label = ds_xstrdup (&label);
- }
+ var_set_label (v[i], ds_cstr (&label));
ds_destroy (&label);
lex_get (lexer);
const char *
var_to_string(const struct variable *var)
{
+ const char *label;
+
if ( !var )
return 0;
- return ( var->label ? var->label : var->name);
+ label = var_get_label (var);
+ return label ? label : var_get_name (var);
}
v = parse_variable (lexer, dict);
if (!v)
return CMD_CASCADING_FAILURE;
- if (v->type == ALPHA)
+ if (var_is_alpha (v))
{
msg (SE, _("The weighting variable must be numeric."));
return CMD_CASCADING_FAILURE;
}
- if (dict_class_from_id (v->name) == DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (v)) == DC_SCRATCH)
{
msg (SE, _("The weighting variable may not be scratch."));
return CMD_CASCADING_FAILURE;
case_data_rw (c, v->fv)->f = lex_tokval (lexer);
else
memcpy (case_data_rw (c, v->fv)->s, ds_data (lex_tokstr (lexer)),
- v->width);
+ var_get_width (v));
lex_get (lexer);
if (!lex_force_match (lexer, ')'))
}
break;
case OP_variable:
- fprintf (stderr, "v<%s>", op->variable->name);
+ fprintf (stderr, "v<%s>", var_get_name (op->variable));
break;
case OP_vector:
fprintf (stderr, "vec<%s>", op->vector->name);
{
const struct variable *var = v->var[(int) idx - 1];
double value = case_num (c, var->fv);
- return !mv_is_num_user_missing (&var->miss, value) ? value : SYSMIS;
+ return !var_is_num_user_missing (var, value) ? value : SYSMIS;
}
else
{
if (idx >= 1 && idx <= v->cnt)
{
struct variable *var = v->var[(int) idx - 1];
- return copy_string (e, case_str (c, var->fv), var->width);
+ return copy_string (e, case_str (c, var->fv), var_get_width (var));
}
else
{
num_var v;
{
double d = case_num (c, v->fv);
- return !mv_is_num_user_missing (&v->miss, d) ? d : SYSMIS;
+ return !var_is_num_user_missing (v, d) ? d : SYSMIS;
}
no_opt string operator STR_VAR ()
expression e;
str_var v;
{
- struct substring s = alloc_string (e, v->width);
- memcpy (s.string, case_str (c, v->fv), v->width);
+ struct substring s = alloc_string (e, var_get_width (v));
+ memcpy (s.string, case_str (c, v->fv), var_get_width (v));
return s;
}
if (c != NULL)
{
double x = case_num (c, v->fv);
- return !mv_is_num_user_missing (&v->miss, x) ? x : SYSMIS;
+ return !var_is_num_user_missing (v, x) ? x : SYSMIS;
}
else
return SYSMIS;
if (c != NULL)
{
double x = case_num (c, v->fv);
- return !mv_is_num_user_missing (&v->miss, x) ? x : SYSMIS;
+ return !var_is_num_user_missing (v, x) ? x : SYSMIS;
}
else
return SYSMIS;
{
struct ccase *c = lagged_case (ds, n_before);
if (c != NULL)
- return copy_string (e, case_str (c, v->fv), v->width);
+ return copy_string (e, case_str (c, v->fv), var_get_width (v));
else
return empty_string;
}
{
struct ccase *c = lagged_case (ds, 1);
if (c != NULL)
- return copy_string (e, case_str (c, v->fv), v->width);
+ return copy_string (e, case_str (c, v->fv), var_get_width (v));
else
return empty_string;
}
|| !lex_match (lexer, ')'))
return NULL;
- return expr_allocate_binary (e, (vector->var[0]->type == NUMERIC
+ return expr_allocate_binary (e, (var_is_numeric (vector->var[0])
? OP_VEC_ELEM_NUM : OP_VEC_ELEM_STR),
element, expr_allocate_vector (e, vector));
}
expr_allocate_variable (struct expression *e, struct variable *v)
{
union any_node *n = pool_alloc (e->expr_pool, sizeof n->variable);
- n->type = v->type == NUMERIC ? OP_num_var : OP_str_var;
+ n->type = var_is_numeric (v) ? OP_num_var : OP_str_var;
n->variable.v = v;
return n;
}
allocate_unary_variable (struct expression *e, struct variable *v)
{
assert (v != NULL);
- return expr_allocate_unary (e, v->type == NUMERIC ? OP_NUM_VAR : OP_STR_VAR,
+ return expr_allocate_unary (e, var_is_numeric (v) ? OP_NUM_VAR : OP_STR_VAR,
expr_allocate_variable (e, v));
}
if (!parse_vs_variable_idx (lexer, vs, idx))
return false;
- *class = dict_class_from_id (var_set_get_var (vs, *idx)->name);
+ *class = dict_class_from_id (var_get_name (var_set_get_var (vs, *idx)));
return true;
}
const struct var_set *vs, size_t idx)
{
struct variable *add = var_set_get_var (vs, idx);
+ const char *add_name = var_get_name (add);
- if ((pv_opts & PV_NUMERIC) && add->type != NUMERIC)
+ if ((pv_opts & PV_NUMERIC) && !var_is_numeric (add))
msg (SW, _("%s is not a numeric variable. It will not be "
- "included in the variable list."), add->name);
- else if ((pv_opts & PV_STRING) && add->type != ALPHA)
+ "included in the variable list."), add_name);
+ else if ((pv_opts & PV_STRING) && !var_is_alpha (add))
msg (SE, _("%s is not a string variable. It will not be "
- "included in the variable list."), add->name);
+ "included in the variable list."), add_name);
else if ((pv_opts & PV_NO_SCRATCH)
- && dict_class_from_id (add->name) == DC_SCRATCH)
+ && dict_class_from_id (add_name) == DC_SCRATCH)
msg (SE, _("Scratch variables (such as %s) are not allowed "
- "here."), add->name);
- else if ((pv_opts & PV_SAME_TYPE) && *nv && add->type != (*v)[0]->type)
+ "here."), add_name);
+ else if ((pv_opts & PV_SAME_TYPE) && *nv
+ && var_get_type (add) != var_get_type ((*v)[0]))
msg (SE, _("%s and %s are not the same type. All variables in "
"this variable list must be of the same type. %s "
"will be omitted from list."),
- (*v)[0]->name, add->name, add->name);
+ var_get_name ((*v)[0]), add_name, add_name);
else if ((pv_opts & PV_NO_DUPLICATE) && included[idx])
- msg (SE, _("Variable %s appears twice in variable list."), add->name);
+ msg (SE, _("Variable %s appears twice in variable list."), add_name);
else if ((pv_opts & PV_DUPLICATE) || !included[idx])
{
if (*nv >= *mv)
size_t i;
for (i = first_idx; i <= last_idx; i++)
- if (dict_class_from_id (var_set_get_var (vs, i)->name) == class)
+ if (dict_class_from_id (var_get_name (var_set_get_var (vs, i))) == class)
add_variable (v, nv, mv, included, pv_opts, vs, i);
}
if (last_idx < first_idx)
{
+ const char *first_name = var_get_name (first_var);
+ const char *last_name = var_get_name (last_var);
msg (SE, _("%s TO %s is not valid syntax since %s "
"precedes %s in the dictionary."),
- first_var->name, last_var->name,
- first_var->name, last_var->name);
+ first_name, last_name, first_name, last_name);
goto fail;
}
"the same variable dictionaries, of either "
"ordinary, scratch, or system variables. "
"%s is a %s variable, whereas %s is %s."),
- first_var->name, dict_class_to_name (class),
- last_var->name, dict_class_to_name (last_class));
+ var_get_name (first_var), dict_class_to_name (class),
+ var_get_name (last_var),
+ dict_class_to_name (last_class));
goto fail;
}
goto fail;
*names = xnrealloc (*names, *nnames + nv, sizeof **names);
for (i = 0; i < nv; i++)
- (*names)[*nnames + i] = xstrdup (v[i]->name);
+ (*names)[*nnames + i] = xstrdup (var_get_name (v[i]));
free (v);
*nnames += nv;
}
+Mon Dec 4 22:33:46 2006 Ben Pfaff <blp@gnu.org>
+
+ * crosstabs.q (insert_summary): Use var_to_string for labeling.
+ (output_pivot_table) Ditto.
+ (submit) Ditto.
+
+ * frequencies.q (setup_z_trns): Ditto.
+ (dump_full) Ditto.
+ (dump_condensed) Ditto.
+ (dump_statistics) Ditto.
+
+
Sun Nov 5 08:31:42 WST 2006 John Darrington <john@darrington.wattle.id.au>
* t-test.q, oneway.q: Changed to use the new casefilter structure.
for (i = 0; i < agr.break_var_cnt; i++)
dict_clone_var_assert (agr.dict, agr.break_vars[i],
- agr.break_vars[i]->name);
+ var_get_name (agr.break_vars[i]));
/* BREAK must follow the options. */
break;
lex_get (lexer);
- if (type != src[0]->type)
+ if (type != var_get_type (src[0]))
{
msg (SE, _("Arguments to %s must be of same type as "
"source variables."),
if ((func_index == PIN || func_index == POUT
|| func_index == FIN || func_index == FOUT)
- && ((src[0]->type == NUMERIC && arg[0].f > arg[1].f)
- || (src[0]->type == ALPHA
- && str_compare_rpad (arg[0].c, arg[1].c) > 0)))
+ && (var_is_numeric (src[0])
+ ? arg[0].f > arg[1].f
+ : str_compare_rpad (arg[0].c, arg[1].c) > 0))
{
union agr_argument t = arg[0];
arg[0] = arg[1];
{
v->src = src[i];
- if (src[i]->type == ALPHA)
+ if (var_is_alpha (src[i]))
{
v->function |= FSTRING;
- v->string = xmalloc (src[i]->width);
+ v->string = xmalloc (var_get_width (src[i]));
}
if (function->alpha_type == ALPHA)
destvar = dict_clone_var (agr->dict, v->src, dest[i]);
else
{
- assert (v->src->type == NUMERIC
+ assert (var_is_numeric (v->src)
|| function->alpha_type == NUMERIC);
destvar = dict_create_var (agr->dict, dest[i], 0);
if (destvar != NULL)
f = fmt_for_output (FMT_F, 8, 2);
else
f = function->format;
- destvar->print = destvar->write = f;
+ var_set_both_formats (destvar, &f);
}
}
} else {
f = fmt_for_output (FMT_F, 8, 2);
else
f = function->format;
- destvar->print = destvar->write = f;
+ var_set_both_formats (destvar, &f);
}
if (!destvar)
free (dest[i]);
if (dest_label[i])
- {
- destvar->label = dest_label[i];
- dest_label[i] = NULL;
- }
+ var_set_label (destvar, dest_label[i]);
v->dest = destvar;
}
{
int j;
- if (v->src->type == NUMERIC)
+ if (var_is_numeric (v->src))
for (j = 0; j < function->n_args; j++)
v->arg[j].f = arg[j].f;
else
}
}
- if (src != NULL && src[0]->type == ALPHA)
+ if (src != NULL && var_is_alpha (src[0]))
for (i = 0; i < function->n_args; i++)
{
free (arg[i].c);
free (dest_label);
free (arg[0].c);
free (arg[1].c);
- if (src && n_src && src[0]->type == ALPHA)
+ if (src && n_src && var_is_alpha (src[0]))
for (i = 0; i < function->n_args; i++)
{
free (arg[i].c);
if (iter->src)
{
const union value *v = case_data (input, iter->src->fv);
+ int src_width = var_get_width (iter->src);
- if ((!iter->include_missing
- && mv_is_value_missing (&iter->src->miss, v))
- || (iter->include_missing && iter->src->type == NUMERIC
- && v->f == SYSMIS))
+ if (iter->include_missing
+ ? var_is_numeric (iter->src) && v->f == SYSMIS
+ : var_is_value_missing (iter->src, v))
{
switch (iter->function)
{
iter->int1 = 1;
break;
case MAX | FSTRING:
- if (memcmp (iter->string, v->s, iter->src->width) < 0)
- memcpy (iter->string, v->s, iter->src->width);
+ if (memcmp (iter->string, v->s, src_width) < 0)
+ memcpy (iter->string, v->s, src_width);
iter->int1 = 1;
break;
case MIN:
iter->int1 = 1;
break;
case MIN | FSTRING:
- if (memcmp (iter->string, v->s, iter->src->width) > 0)
- memcpy (iter->string, v->s, iter->src->width);
+ if (memcmp (iter->string, v->s, src_width) > 0)
+ memcpy (iter->string, v->s, src_width);
iter->int1 = 1;
break;
case FGT:
break;
case FGT | FSTRING:
case PGT | FSTRING:
- if (memcmp (iter->arg[0].c, v->s, iter->src->width) < 0)
+ if (memcmp (iter->arg[0].c, v->s, src_width) < 0)
iter->dbl[0] += weight;
iter->dbl[1] += weight;
break;
break;
case FLT | FSTRING:
case PLT | FSTRING:
- if (memcmp (iter->arg[0].c, v->s, iter->src->width) > 0)
+ if (memcmp (iter->arg[0].c, v->s, src_width) > 0)
iter->dbl[0] += weight;
iter->dbl[1] += weight;
break;
break;
case FIN | FSTRING:
case PIN | FSTRING:
- if (memcmp (iter->arg[0].c, v->s, iter->src->width) <= 0
- && memcmp (iter->arg[1].c, v->s, iter->src->width) >= 0)
+ if (memcmp (iter->arg[0].c, v->s, src_width) <= 0
+ && memcmp (iter->arg[1].c, v->s, src_width) >= 0)
iter->dbl[0] += weight;
iter->dbl[1] += weight;
break;
break;
case FOUT | FSTRING:
case POUT | FSTRING:
- if (memcmp (iter->arg[0].c, v->s, iter->src->width) > 0
- || memcmp (iter->arg[1].c, v->s, iter->src->width) < 0)
+ if (memcmp (iter->arg[0].c, v->s, src_width) > 0
+ || memcmp (iter->arg[1].c, v->s, src_width) < 0)
iter->dbl[0] += weight;
iter->dbl[1] += weight;
break;
case FIRST | FSTRING:
if (iter->int1 == 0)
{
- memcpy (iter->string, v->s, iter->src->width);
+ memcpy (iter->string, v->s, src_width);
iter->int1 = 1;
}
break;
iter->int1 = 1;
break;
case LAST | FSTRING:
- memcpy (iter->string, v->s, iter->src->width);
+ memcpy (iter->string, v->s, src_width);
iter->int1 = 1;
break;
case NMISS:
for (i = 0; i < agr->break_var_cnt; i++)
{
struct variable *v = agr->break_vars[i];
+ size_t value_cnt = var_get_value_cnt (v);
memcpy (case_data_rw (output, value_idx),
case_data (&agr->break_case, v->fv),
- sizeof (union value) * v->nv);
- value_idx += v->nv;
+ sizeof (union value) * value_cnt);
+ value_idx += value_cnt;
}
}
&& (i->function & FUNC) != N && (i->function & FUNC) != NU
&& (i->function & FUNC) != NMISS && (i->function & FUNC) != NUMISS)
{
- if (i->dest->type == ALPHA)
- memset (v->s, ' ', i->dest->width);
+ if (var_is_alpha (i->dest))
+ memset (v->s, ' ', var_get_width (i->dest));
else
v->f = SYSMIS;
continue;
case MAX | FSTRING:
case MIN | FSTRING:
if (i->int1)
- memcpy (v->s, i->string, i->dest->width);
+ memcpy (v->s, i->string, var_get_width (i->dest));
else
- memset (v->s, ' ', i->dest->width);
+ memset (v->s, ' ', var_get_width (i->dest));
break;
case FGT:
case FGT | FSTRING:
case FIRST | FSTRING:
case LAST | FSTRING:
if (i->int1)
- memcpy (v->s, i->string, i->dest->width);
+ memcpy (v->s, i->string, var_get_width (i->dest));
else
- memset (v->s, ' ', i->dest->width);
+ memset (v->s, ' ', var_get_width (i->dest));
break;
case N_NO_VARS:
v->f = i->dbl[0];
iter->dbl[0] = DBL_MAX;
break;
case MIN | FSTRING:
- memset (iter->string, 255, iter->src->width);
+ memset (iter->string, 255, var_get_width (iter->src));
break;
case MAX:
iter->dbl[0] = -DBL_MAX;
break;
case MAX | FSTRING:
- memset (iter->string, 0, iter->src->width);
+ memset (iter->string, 0, var_get_width (iter->src));
break;
case SD:
if (iter->moments == NULL)
arc.dst_vars = xnmalloc (arc.var_cnt, sizeof *arc.dst_vars);
arc.src_values = xnmalloc (arc.var_cnt, sizeof *arc.src_values);
for (i = 0; i < dst_cnt; i++)
- if (arc.src_vars[i]->type == ALPHA)
+ if (var_is_alpha (arc.src_vars[i]))
arc.src_values[i] = hsh_create (10, compare_alpha_value,
hash_alpha_value, NULL, arc.src_vars[i]);
else
spec->src = arc->src_vars[i];
spec->dest = arc->dst_vars[i];
- if (arc->src_vars[i]->type == ALPHA)
+ if (var_is_alpha (arc->src_vars[i]))
spec->items = hsh_create (2 * count, compare_alpha_value,
hash_alpha_value, NULL, arc->src_vars[i]);
else
struct arc_item *item = pool_alloc (trns->pool, sizeof *item);
union arc_value *vp = *p;
- if (arc->src_vars[i]->type == NUMERIC)
+ if (var_is_numeric (arc->src_vars[i]))
item->from.f = vp->f;
else
item->from.c = pool_clone (trns->pool, vp->c,
- arc->src_vars[i]->width);
+ var_get_width (arc->src_vars[i]));
item->to = arc->direction == ASCENDING ? j + 1 : count - j;
hsh_force_insert (spec->items, item);
}
struct arc_item *item;
union arc_value v;
- if (spec->src->type == NUMERIC)
+ if (var_is_numeric (spec->src))
v.f = case_num (c, spec->src->fv);
else
v.c = (char *) case_str (c, spec->src->fv);
const union arc_value *b = b_;
const struct variable *v = v_;
- return memcmp (a->c, b->c, v->width);
+ return memcmp (a->c, b->c, var_get_width (v));
}
static unsigned
const union arc_value *a = a_;
const struct variable *v = v_;
- return hsh_hash_bytes (a->c, v->width);
+ return hsh_hash_bytes (a->c, var_get_width (v));
}
static int
{
union arc_value v, *vp, **vpp;
- if (arc->src_vars[i]->type == NUMERIC)
+ if (var_is_numeric (arc->src_vars[i]))
v.f = case_num (c, arc->src_vars[i]->fv);
else
v.c = (char *) case_str (c, arc->src_vars[i]->fv);
if (*vpp == NULL)
{
vp = pool_alloc (arc->src_values_pool, sizeof *vp);
- if (arc->src_vars[i]->type == NUMERIC)
+ if (var_is_numeric (arc->src_vars[i]))
vp->f = v.f;
else
vp->c = pool_clone (arc->src_values_pool,
- v.c, arc->src_vars[i]->width);
+ v.c, var_get_width (arc->src_vars[i]));
*vpp = vp;
}
}
for (j = 0; j < x->nvar; j++)
{
const union value *v = case_data (c, x->vars[j]->fv);
- const struct missing_values *mv = &x->vars[j]->miss;
- if ((cmd.miss == CRS_TABLE && mv_is_value_missing (mv, v))
+ if ((cmd.miss == CRS_TABLE && var_is_value_missing (x->vars[j], v))
|| (cmd.miss == CRS_INCLUDE
- && mv_is_value_system_missing (mv, v)))
+ && var_is_value_system_missing (x->vars[j], v)))
{
x->missing += weight;
goto next_crosstab;
}
- if (x->vars[j]->type == NUMERIC)
+ if (var_is_numeric (x->vars[j]))
te->values[j].f = case_num (c, x->vars[j]->fv);
else
{
memcpy (te->values[j].s, case_str (c, x->vars[j]->fv),
- x->vars[j]->width);
+ var_get_width (x->vars[j]));
/* Necessary in order to simplify comparisons. */
- memset (&te->values[j].s[x->vars[j]->width], 0,
- sizeof (union value) - x->vars[j]->width);
+ memset (&te->values[j].s[var_get_width (x->vars[j])], 0,
+ sizeof (union value) - var_get_width (x->vars[j]));
}
}
}
/* Note that the first test also rules out SYSMIS. */
if ((value < vr->min || value >= vr->max)
- || (cmd.miss == CRS_TABLE
- && mv_is_num_user_missing (&v->miss, value)))
+ || (cmd.miss == CRS_TABLE && var_is_num_user_missing (v, value)))
{
x->missing += weight;
goto next_crosstab;
int i;
for (i = x->nvar - 1; i >= 0; i--)
- if (x->vars[i]->type == NUMERIC)
+ if (var_is_numeric (x->vars[i]))
{
const double diffnum = a->values[i].f - b->values[i].f;
if (diffnum < 0)
return 1;
}
else
- {
- assert (x->vars[i]->type == ALPHA);
- {
- const int diffstr = strncmp (a->values[i].s, b->values[i].s,
- x->vars[i]->width);
- if (diffstr)
- return diffstr;
- }
- }
+ {
+ const int diffstr = strncmp (a->values[i].s, b->values[i].s,
+ var_get_width (x->vars[i]));
+ if (diffstr)
+ return diffstr;
+ }
}
return 0;
if (i > 0)
cp = stpcpy (cp, " * ");
- cp = stpcpy (cp,
- x->vars[i]->label ? x->vars[i]->label : x->vars[i]->name);
+ cp = stpcpy (cp, var_to_string (x->vars[i]));
}
tab_text (t, 0, 0, TAB_LEFT, buf);
/* First header line. */
tab_joint_text (table, nvar - 1, 0, (nvar - 1) + (n_cols - 1), 0,
- TAB_CENTER | TAT_TITLE, x->vars[COL_VAR]->name);
+ TAB_CENTER | TAT_TITLE, var_get_name (x->vars[COL_VAR]));
tab_hline (table, TAL_1, nvar - 1, nvar + n_cols - 2, 1);
for (i = 2; i < nvar; i++)
tab_joint_text (table, nvar - i - 1, 0, nvar - i - 1, 1,
- TAB_RIGHT | TAT_TITLE,
- (x->vars[i]->label
- ? x->vars[i]->label : x->vars[i]->name));
+ TAB_RIGHT | TAT_TITLE, var_to_string (x->vars[i]));
tab_text (table, nvar - 2, 1, TAB_RIGHT | TAT_TITLE,
- x->vars[ROW_VAR]->name);
+ var_get_name (x->vars[ROW_VAR]));
for (i = 0; i < n_cols; i++)
table_value_missing (table, nvar + i - 1, 1, TAB_RIGHT, &cols[i],
x->vars[COL_VAR]);
{
if (i)
cp = stpcpy (cp, " by ");
- cp = stpcpy (cp, x->vars[i]->name);
+ cp = stpcpy (cp, var_get_name (x->vars[i]));
}
else
{
cp = spprintf (cp, "%s by %s for",
- x->vars[0]->name, x->vars[1]->name);
+ var_get_name (x->vars[0]),
+ var_get_name (x->vars[1]));
for (i = 2; i < nvar; i++)
{
char buf[64], *bufp;
if (i > 2)
*cp++ = ',';
*cp++ = ' ';
- cp = stpcpy (cp, x->vars[i]->name);
+ cp = stpcpy (cp, var_get_name (x->vars[i]));
*cp++ = '=';
- format_short (buf, &x->vars[i]->print, &(*pb)->values[i]);
+ format_short (buf, var_get_print_format (x->vars[i]),
+ &(*pb)->values[i]);
for (bufp = buf; isspace ((unsigned char) *bufp); bufp++)
;
cp = stpcpy (cp, bufp);
int r;
for (r = 0; r < n_rows; r++)
- if (mv_is_num_user_missing (&x->vars[ROW_VAR]->miss, rows[r].f))
+ if (var_is_num_user_missing (x->vars[ROW_VAR], rows[r].f))
{
int c;
int c;
for (c = 0; c < n_cols; c++)
- if (mv_is_num_user_missing (&x->vars[COL_VAR]->miss, cols[c].f))
+ if (var_is_num_user_missing (x->vars[COL_VAR], cols[c].f))
{
int r;
if (t != table)
for (i = 2; i < nvar; i++)
tab_text (t, nvar - i - 1, 0, TAB_RIGHT | TAT_TITLE,
- x->vars[i]->label ? x->vars[i]->label : x->vars[i]->name);
+ var_to_string (x->vars[i]));
tab_box (t, TAL_2, TAL_2, -1, -1, 0, 0, tab_nc (t) - 1, tab_nr (t) - 1);
tab_box (t, -1, -1, -1, TAL_1, tab_l (t), tab_t (t) - 1, tab_nc (t) - 1,
tab_nr (t) - 1);
if (mode == GENERAL)
{
- int width = v->width;
+ int width = var_get_width (v);
int i;
*values = xnmalloc (entry_cnt, sizeof **values);
const union value *v, const struct variable *var)
{
struct substring s;
+ const struct fmt_spec *print = var_get_print_format (var);
const char *label = val_labs_find (var->val_labs, *v);
if (label)
return;
}
- s.string = tab_alloc (table, var->print.w);
- format_short (s.string, &var->print, v);
+ s.string = tab_alloc (table, print->w);
+ format_short (s.string, print, v);
s.length = strlen (s.string);
- if (cmd.miss == CRS_REPORT && mv_is_num_user_missing (&var->miss, v->f))
+ if (cmd.miss == CRS_REPORT && var_is_num_user_missing (var, v->f))
s.string[s.length++] = 'M';
while (s.length && *s.string == ' ')
{
bool mark_missing = false;
double expected_value = row_tot[r] * col_tot[c] / W;
if (cmd.miss == CRS_REPORT
- && (mv_is_num_user_missing (&x->vars[COL_VAR]->miss, cols[c].f)
- || mv_is_num_user_missing (&x->vars[ROW_VAR]->miss,
- rows[r].f)))
+ && (var_is_num_user_missing (x->vars[COL_VAR], cols[c].f)
+ || var_is_num_user_missing (x->vars[ROW_VAR], rows[r].f)))
mark_missing = true;
for (i = 0; i < num_cells; i++)
{
bool mark_missing = false;
if (cmd.miss == CRS_REPORT
- && mv_is_num_user_missing (&x->vars[ROW_VAR]->miss, rows[r].f))
+ && var_is_num_user_missing (x->vars[ROW_VAR], rows[r].f))
mark_missing = true;
for (i = 0; i < num_cells; i++)
int i;
if (cmd.miss == CRS_REPORT && c < n_cols
- && mv_is_num_user_missing (&x->vars[COL_VAR]->miss, cols[c].f))
+ && var_is_num_user_missing (x->vars[COL_VAR], cols[c].f))
mark_missing = true;
for (i = 0; i < num_cells; i++)
switch (i)
{
case 0:
- if (x->vars[COL_VAR]->type == NUMERIC)
+ if (var_is_numeric (x->vars[COL_VAR]))
sprintf (buf, _("Odds Ratio for %s (%g / %g)"),
- x->vars[COL_VAR]->name, c[0].f, c[1].f);
+ var_get_name (x->vars[COL_VAR]), c[0].f, c[1].f);
else
sprintf (buf, _("Odds Ratio for %s (%.*s / %.*s)"),
- x->vars[COL_VAR]->name,
- x->vars[COL_VAR]->width, c[0].s,
- x->vars[COL_VAR]->width, c[1].s);
+ var_get_name (x->vars[COL_VAR]),
+ var_get_width (x->vars[COL_VAR]), c[0].s,
+ var_get_width (x->vars[COL_VAR]), c[1].s);
break;
case 1:
case 2:
- if (x->vars[ROW_VAR]->type == NUMERIC)
+ if (var_is_numeric (x->vars[ROW_VAR]))
sprintf (buf, _("For cohort %s = %g"),
- x->vars[ROW_VAR]->name, rows[i - 1].f);
+ var_get_name (x->vars[ROW_VAR]), rows[i - 1].f);
else
sprintf (buf, _("For cohort %s = %.*s"),
- x->vars[ROW_VAR]->name,
- x->vars[ROW_VAR]->width, rows[i - 1].s);
+ var_get_name (x->vars[ROW_VAR]),
+ var_get_width (x->vars[ROW_VAR]), rows[i - 1].s);
break;
}
for (; j < 3; j++)
{
- char *string;
+ const char *string;
int k = last[j] = stats_lookup[j][i];
if (k == 0)
string = NULL;
else if (k == 1)
- string = x->vars[0]->name;
+ string = var_get_name (x->vars[0]);
else
- string = x->vars[1]->name;
+ string = var_get_name (x->vars[1]);
tab_text (direct, j, 0, TAB_LEFT | TAT_PRINTF,
gettext (stats_names[j][k]), string);
}
/* Calculate Mantel-Haenszel. */
- if (x->vars[ROW_VAR]->type == NUMERIC && x->vars[COL_VAR]->type == NUMERIC)
+ if (var_is_numeric (x->vars[ROW_VAR]) && var_is_numeric (x->vars[COL_VAR]))
{
double r, ase_0, ase_1;
calc_r ((double *) rows, (double *) cols, &r, &ase_0, &ase_1);
if (dsc->vars[i].z_name[0] == 0)
{
if (!generate_z_varname (dict, dsc, dsc->vars[i].z_name,
- dsc->vars[i].v->name, &gen_cnt))
+ var_get_name (dsc->vars[i].v),
+ &gen_cnt))
goto error;
z_cnt++;
}
for (i = 0, y = 1; i < dsc->var_cnt; i++)
if (dsc->vars[i].z_name[0] != '\0')
{
- tab_text (t, 0, y, TAB_LEFT, dsc->vars[i].v->name);
+ tab_text (t, 0, y, TAB_LEFT, var_get_name (dsc->vars[i].v));
tab_text (t, 1, y++, TAB_LEFT, dsc->vars[i].z_name);
}
}
double score = case_num (c, (*vars)->fv);
if ( score == SYSMIS
|| (!t->include_user_missing
- && mv_is_num_user_missing (&(*vars)->miss, score)))
+ && var_is_num_user_missing (*vars, score)))
{
all_sysmis = 1;
break;
if (z->mean == SYSMIS || z->std_dev == SYSMIS
|| all_sysmis || input == SYSMIS
|| (!t->include_user_missing
- && mv_is_num_user_missing (&z->v->miss, input)))
+ && var_is_num_user_missing (z->v, input)))
*output = SYSMIS;
else
*output = (input - z->mean) / z->std_dev;
if (dv->z_name[0] != '\0')
{
struct dsc_z_score *z;
- char *cp;
struct variable *dst_var;
dst_var = dict_create_var_assert (dataset_dict (ds), dv->z_name, 0);
- if (dv->v->label)
- {
- dst_var->label = xmalloc (strlen (dv->v->label) + 12);
- cp = stpcpy (dst_var->label, _("Z-score of "));
- strcpy (cp, dv->v->label);
- }
- else
- {
- dst_var->label = xmalloc (strlen (dv->v->name) + 12);
- cp = stpcpy (dst_var->label, _("Z-score of "));
- strcpy (cp, dv->v->name);
- }
+ var_set_label (dst_var, xasprintf (_("Z-score of %s"),
+ var_to_string (dv->v)));
z = &t->z_scores[cnt++];
z->src_idx = dv->v->fv;
if (dsc->missing_type != DSC_LISTWISE
&& (x == SYSMIS
|| (!dsc->include_user_missing
- && mv_is_num_user_missing (&dv->v->miss, x))))
+ && var_is_num_user_missing (dv->v, x))))
{
dv->missing += weight;
continue;
if (dsc->missing_type != DSC_LISTWISE
&& (x == SYSMIS
|| (!dsc->include_user_missing
- && mv_is_num_user_missing (&dv->v->miss, x))))
+ && var_is_num_user_missing (dv->v, x))))
continue;
if (dv->moments != NULL)
if (x == SYSMIS
|| (!dsc->include_user_missing
- && mv_is_num_user_missing (&dv->v->miss, x)))
+ && var_is_num_user_missing (dv->v, x)))
return true;
}
return false;
size_t j;
nc = 0;
- tab_text (t, nc++, i + 1, TAB_LEFT, dv->v->name);
+ tab_text (t, nc++, i + 1, TAB_LEFT, var_get_name (dv->v));
tab_text (t, nc++, i + 1, TAT_PRINTF, "%g", dv->valid);
if (dsc->format == DSC_SERIAL)
tab_text (t, nc++, i + 1, TAT_PRINTF, "%g", dv->missing);
int result;
if (dsc->sort_by_stat == DSC_NAME)
- result = strcasecmp (a->v->name, b->v->name);
+ result = strcasecmp (var_get_name (a->v), var_get_name (b->v));
else
{
double as = a->stats[dsc->sort_by_stat];
/* Function to use for testing for missing values */
-static is_missing_func *value_is_missing;
+static var_is_missing_func *value_is_missing;
/* PERCENTILES */
/* If /MISSING=INCLUDE is set, then user missing values are ignored */
if (cmd.incl == XMN_INCLUDE )
- value_is_missing = mv_is_value_system_missing;
+ value_is_missing = var_is_value_system_missing;
else
- value_is_missing = mv_is_value_missing;
+ value_is_missing = var_is_value_missing;
if ( cmd.st_n == SYSMIS )
cmd.st_n = 5;
const struct variable *var = dependent_vars[v];
const union value *val = case_data (c, var->fv);
- if ( value_is_missing (&var->miss, val) || case_missing )
+ if ( value_is_missing (var, val) || case_missing )
val = 0;
metrics_calc ( & (*foo)->m[v], val, weight, case_no);
const struct variable *var = dependent_vars[v];
const union value *val = case_data (&c, var->fv);
- if ( value_is_missing (&var->miss, val))
+ if ( value_is_missing (var, val))
case_missing = 1;
}
const struct variable *var = dependent_vars[v];
const union value *val = case_data (&c, var->fv);
- if ( value_is_missing (&var->miss, val) || case_missing )
+ if ( value_is_missing (var, val) || case_missing )
val = 0;
metrics_calc (&totals[v], val, weight, case_no);
static union value prev;
if ( 0 != compare_values (&prev, & (*fs)->id[0],
- fctr->indep_var[0]->width))
+ var_get_width (fctr->indep_var[0])))
{
tab_text (tbl,
1,
if ( 0 != compare_values (&prev, & (*fs)->id[0],
- fctr->indep_var[0]->width))
+ var_get_width (fctr->indep_var[0])))
{
if ( count > 0 )
if ( 0 != compare_values (&prev, & (*fs)->id[0],
- fctr->indep_var[0]->width))
+ var_get_width (fctr->indep_var[0])))
{
if ( count > 0 )
if ( 0 != compare_values (&prev, & (*fs)->id[0],
- fctr->indep_var[0]->width))
+ var_get_width (fctr->indep_var[0])))
{
if ( count > 0 )
/* Write variable names as first case. */
for (i = 0; i < flip->var_cnt; i++)
buf_copy_str_rpad (flip->output_buf[i].s, MAX_SHORT_STRING,
- flip->var[i]->name);
+ var_get_name (flip->var[i]));
if (fwrite (flip->output_buf, sizeof *flip->output_buf,
flip->var_cnt, flip->file) != (size_t) flip->var_cnt)
{
{
struct varname *v = pool_alloc (flip->pool, sizeof *v);
v->next = NULL;
- if (flip->new_names->type == NUMERIC)
+ if (var_is_numeric (flip->new_names))
{
double f = case_num (c, flip->idx_to_fv[flip->new_names->index]);
}
else
{
- int width = MIN (flip->new_names->width, MAX_SHORT_STRING);
+ int width = MIN (var_get_width (flip->new_names), MAX_SHORT_STRING);
memcpy (v->name, case_str (c, flip->idx_to_fv[flip->new_names->index]),
width);
v->name[width] = 0;
{
double out;
- if (flip->var[i]->type == NUMERIC)
+ if (var_is_numeric (flip->var[i]))
out = case_num (c, flip->idx_to_fv[flip->var[i]->index]);
else
out = SYSMIS;
hsh_hash_func *hash;
hsh_compare_func *compare;
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
{
hash = hash_value_numeric;
compare = compare_value_numeric_a;
const struct freq *f = f_;
const struct variable *v = v_;
- return !mv_is_value_missing (&v->miss, f->v);
+ return !var_is_value_missing (v, f->v);
}
/* Summarizes the frequency table data for variable V. */
ft = &get_var_freqs (v)->tab;
assert (ft->mode == FRQM_GENERAL);
- compare = get_freq_comparator (cmd.sort, v->type);
+ compare = get_freq_comparator (cmd.sort, var_get_type (v));
/* Extract data from hash table. */
count = hsh_count (ft->data);
if (v->aux != NULL)
{
msg (SE, _("Variable %s specified multiple times on VARIABLES "
- "subcommand."), v->name);
+ "subcommand."), var_get_name (v));
return 0;
}
- if (mode == FRQM_INTEGER && v->type != NUMERIC)
+ if (mode == FRQM_INTEGER && !var_is_numeric (v))
{
msg (SE, _("Integer mode specified, but %s is not a numeric "
- "variable."), v->name);
+ "variable."), var_get_name (v));
return 0;
}
vf->tab.vector = NULL;
vf->n_groups = 0;
vf->groups = NULL;
- vf->width = v->width;
- vf->print = v->print;
+ vf->width = var_get_width (v);
+ vf->print = *var_get_print_format (v);
if (vf->width > MAX_SHORT_STRING && get_algorithm () == COMPATIBLE)
{
+ enum fmt_type type = var_get_print_format (v)->type;
vf->width = MAX_SHORT_STRING;
- vf->print.w = MAX_SHORT_STRING * (v->print.type == FMT_AHEX ? 2 : 1);
+ vf->print.w = MAX_SHORT_STRING * (type == FMT_AHEX ? 2 : 1);
}
}
return 1;
for (i = 0; i < n; i++)
if (v[i]->aux == NULL)
msg (SE, _("Variables %s specified on GROUPED but not on "
- "VARIABLES."), v[i]->name);
+ "VARIABLES."), var_get_name (v[i]));
else
{
struct var_freqs *vf = get_var_freqs (v[i]);
if (vf->groups != NULL)
msg (SE, _("Variables %s specified multiple times on GROUPED "
- "subcommand."), v[i]->name);
+ "subcommand."), var_get_name (v[i]));
else
{
vf->n_groups = nl;
tab_float (t, 2 + lab, r, TAB_NONE, 100.0, 5, 1);
tab_float (t, 3 + lab, r, TAB_NONE, 100.0, 5, 1);
- tab_title (t, "%s: %s", v->name, v->label ? v->label : "");
+ tab_title (t, "%s", var_to_string (v));
tab_submit (t);
-
}
/* Sets the widths of all the columns and heights of all the rows in
cmd.spaces == FRQ_SINGLE ? -1 : TAL_GAP, TAL_1,
0, 0, 3, r - 1);
tab_hline (t, TAL_2, 0, 3, 2);
- tab_title (t, "%s: %s", v->name, v->label ? v->label : "");
+ tab_title (t, "%s", var_to_string (v));
tab_columns (t, SOM_COL_DOWN, 1);
tab_submit (t);
}
if ( implicit_50th && n_percentiles > 0 )
--n_percentiles;
- if (v->type == ALPHA)
+ if (var_is_alpha (v))
return;
ft = &get_var_freqs (v)->tab;
if (ft->n_valid == 0)
{
msg (SW, _("No valid data for variable %s; statistics not displayed."),
- v->name);
+ var_get_name (v));
return;
}
calc_stats (v, stat_value);
tab_columns (t, SOM_COL_DOWN, 1);
if (show_varname)
- {
- if (v->label)
- tab_title (t, "%s: %s", v->name, v->label);
- else
- tab_title (t, "%s", v->name);
- }
+ tab_title (t, "%s", var_to_string (v));
else
tab_flags (t, SOMF_NO_TITLE);
/* Find out the extremes of the x value */
for ( frq = hsh_first(fh, &hi); frq != 0; frq = hsh_next(fh, &hi) )
{
- if ( mv_is_value_missing(&var->miss, frq->v))
+ if ( var_is_value_missing(var, frq->v))
continue;
if ( frq->v[0].f < x_min ) x_min = frq->v[0].f ;
(hsh_compare_func *) compare_group,
(hsh_hash_func *) hash_group,
(hsh_free_func *) free_group,
- (void *) indep_var->width );
+ (void *) var_get_width (indep_var) );
totals->sum=0;
(hsh_compare_func *) compare_values,
(hsh_hash_func *) hash_value,
0,
- (void *) indep_var->width );
+ (void *) var_get_width (indep_var) );
precalc(cmd);
/* Function to use for testing for missing values */
-static is_missing_func *value_is_missing;
+static mv_is_missing_func *value_is_missing;
static struct rank_spec *rank_specs;
static size_t n_rank_specs;
for (g = 0 ; g < n_group_vars ; ++g )
{
if ( g > 0 ) ds_put_cstr (&group_var_str, " ");
- ds_put_cstr (&group_var_str, group_vars[g]->name);
+ ds_put_cstr (&group_var_str, var_get_name (group_vars[g]));
}
ds_put_format (&label, _("%s of %s by %s"), function_name[f],
- src_var->name, ds_cstr (&group_var_str));
+ var_get_name (src_var), ds_cstr (&group_var_str));
ds_destroy (&group_var_str);
}
else
- ds_put_format (&label,_("%s of %s"), function_name[f], src_var->name);
+ ds_put_format (&label, _("%s of %s"),
+ function_name[f], var_get_name (src_var));
- dest_var->label = strdup (ds_cstr (&label) );
+ var_set_label (dest_var, ds_cstr (&label));
ds_destroy (&label);
}
{
struct variable *v = dict_get_split_vars (dataset_dict (ds))[i];
criteria.crits[i].fv = v->fv;
- criteria.crits[i].width = v->width;
+ criteria.crits[i].width = var_get_width (v);
criteria.crits[i].dir = SRT_ASCEND;
}
for (i = 0; i < n_group_vars; i++)
{
criteria.crits[i + n_splits].fv = group_vars[i]->fv;
- criteria.crits[i + n_splits].width = group_vars[i]->width;
+ criteria.crits[i + n_splits].width = var_get_width (group_vars[i]);
criteria.crits[i + n_splits].dir = SRT_ASCEND;
}
for (i = 0 ; i < sc->crit_cnt ; ++i )
out = rank_sorted_casefile (sorted_cf, &criteria,
dataset_dict (ds),
rank_specs, n_rank_specs,
- i, &src_vars[i]->miss) ;
+ i, var_get_missing_values (src_vars[i]));
if ( NULL == out )
{
result = false ;
if ( NULL == var )
{
- snprintf(name, SHORT_NAME_LEN + 1, "%c%s",
- function_name[f][0], src_var->name);
+ snprintf (name, SHORT_NAME_LEN + 1, "%c%s",
+ function_name[f][0], var_get_name (src_var));
var = dict_create_var(dict, name, 0);
}
return NULL;
}
- var->write = var->print = dest_format[f];
+ var_set_both_formats (var, &dest_format[f]);
return var;
}
ds_init_empty (&varlist);
for ( g = 0 ; g < n_group_vars ; ++g )
{
- ds_put_cstr (&varlist, group_vars[g]->name);
+ ds_put_cstr (&varlist, var_get_name (group_vars[g]));
if ( g < n_group_vars - 1)
ds_put_cstr (&varlist, " ");
rank_specs[i].rfunc == PROPORTION )
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s using %s BY %s)"),
- src_vars[v]->name,
- rank_specs[i].destvars[v]->name,
+ var_get_name (src_vars[v]),
+ var_get_name (rank_specs[i].destvars[v]),
function_name[rank_specs[i].rfunc],
- src_vars[v]->name,
+ var_get_name (src_vars[v]),
fraction_name(),
ds_cstr (&varlist)
);
else
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s BY %s)"),
- src_vars[v]->name,
- rank_specs[i].destvars[v]->name,
+ var_get_name (src_vars[v]),
+ var_get_name (rank_specs[i].destvars[v]),
function_name[rank_specs[i].rfunc],
- src_vars[v]->name,
+ var_get_name (src_vars[v]),
ds_cstr (&varlist)
);
ds_destroy (&varlist);
rank_specs[i].rfunc == PROPORTION )
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s using %s)"),
- src_vars[v]->name,
- rank_specs[i].destvars[v]->name,
+ var_get_name (src_vars[v]),
+ var_get_name (rank_specs[i].destvars[v]),
function_name[rank_specs[i].rfunc],
- src_vars[v]->name,
+ var_get_name (src_vars[v]),
fraction_name()
);
else
tab_output_text (TAT_PRINTF,
_("%s into %s(%s of %s)"),
- src_vars[v]->name,
- rank_specs[i].destvars[v]->name,
+ var_get_name (src_vars[v]),
+ var_get_name (rank_specs[i].destvars[v]),
function_name[rank_specs[i].rfunc],
- src_vars[v]->name
+ var_get_name (src_vars[v])
);
}
}
label = var_to_string (v);
/* Do not overwrite the variable's name. */
strncpy (tmp, label, MAX_STRING);
- if (v->type == ALPHA)
+ if (var_is_alpha (v))
{
/*
Append the value associated with this coefficient.
{
coeff = c->coeff[i];
v = pspp_coeff_get_var (coeff, 0);
- if (v->type == ALPHA)
+ if (var_is_alpha (v))
{
if (!reg_inserted (v, varlist, n_vars))
{
fprintf (fp, "struct pspp_reg_categorical_variable %s;\n\t",
- v->name);
+ var_get_name (v));
varlist[n_vars] = (struct variable *) v;
n_vars++;
}
n_vars);
for (i = 0; i < n_vars - 1; i++)
{
- fprintf (fp, "&%s,\n\t\t", varlist[i]->name);
+ fprintf (fp, "&%s,\n\t\t", var_get_name (varlist[i]));
}
- fprintf (fp, "&%s};\n\t", varlist[i]->name);
+ fprintf (fp, "&%s};\n\t", var_get_name (varlist[i]));
for (i = 0; i < n_vars; i++)
{
coeff = c->coeff[i];
- fprintf (fp, "%s.name = \"%s\";\n\t", varlist[i]->name,
- varlist[i]->name);
- fprintf (fp, "%s.n_vals = %d;\n\t", varlist[i]->name,
+ fprintf (fp, "%s.name = \"%s\";\n\t",
+ var_get_name (varlist[i]),
+ var_get_name (varlist[i]));
+ fprintf (fp, "%s.n_vals = %d;\n\t",
+ var_get_name (varlist[i]),
varlist[i]->obs_vals->n_categories);
for (j = 0; j < varlist[i]->obs_vals->n_categories; j++)
{
val = cat_subscript_to_value ((const size_t) j, varlist[i]);
- fprintf (fp, "%s.values[%d] = \"%s\";\n\t", varlist[i]->name, j,
+ fprintf (fp, "%s.values[%d] = \"%s\";\n\t",
+ var_get_name (varlist[i]), j,
value_to_string (val, varlist[i]));
}
}
{
coeff = c->coeff[i];
v = pspp_coeff_get_var (coeff, 0);
- fprintf (fp, "\"%s\",\n\t\t", v->name);
+ fprintf (fp, "\"%s\",\n\t\t", var_get_name (v));
}
coeff = c->coeff[i];
v = pspp_coeff_get_var (coeff, 0);
- fprintf (fp, "\"%s\"};\n\t", v->name);
+ fprintf (fp, "\"%s\"};\n\t", var_get_name (v));
}
static void
reg_print_getvar (FILE * fp, pspp_linreg_cache * c)
for (i = 1; i < c->n_coeffs; i++)
{
v = pspp_coeff_get_var (c->coeff[i], 0);
- if (v->type == ALPHA)
- {
- return 1;
- }
+ if (var_is_alpha (v))
+ return 1;
}
return 0;
}
val = case_data (&c, v->fv);
cat_value_update (v, val);
- if (mv_is_value_missing (&v->miss, val))
+ if (var_is_value_missing (v, val))
{
if (!is_missing_case[row])
{
{
indep_vars[j] = v_variables[i];
j++;
- if (v_variables[i]->type == ALPHA)
+ if (var_is_alpha (v_variables[i]))
{
/* Make a place to hold the binary vectors
corresponding to this variable's values. */
for (i = 0; i < cmd.n_dependent; i++)
{
- if (cmd.v_dependent[i]->type != NUMERIC)
+ if (!var_is_numeric (cmd.v_dependent[i]))
{
msg (SE, gettext ("Dependent variable must be numeric."));
pspp_reg_rc = CMD_FAILURE;
*/
if (!is_depvar (i, cmd.v_dependent[k]))
{
- if (v_variables[i]->type == ALPHA)
+ if (var_is_alpha (v_variables[i]))
{
design_matrix_set_categorical (X, row,
v_variables[i], val);
}
- else if (v_variables[i]->type == NUMERIC)
+ else
{
design_matrix_set_numeric (X, row, v_variables[i],
val);
{
struct sort_criterion *c = &criteria->crits[prev_var_cnt];
c->fv = (*vars)[prev_var_cnt]->fv;
- c->width = (*vars)[prev_var_cnt]->width;
+ c->width = var_get_width ((*vars)[prev_var_cnt]);
c->dir = direction;
}
}
return 0;
}
- if (indep_var->type == T_STRING && indep_var->width > MAX_SHORT_STRING)
+ if (var_is_long_string (indep_var))
{
msg (SE, _("Long string variable %s is not valid here."),
- indep_var->name);
+ var_get_name (indep_var));
return 0;
}
if (!lex_match (lexer, '('))
{
- if (indep_var->type == NUMERIC)
+ if (var_is_numeric (indep_var))
{
gp.v.g_value[0].f = 1;
gp.v.g_value[1].f = 2;
}
}
- if (!parse_value (lexer, &gp.v.g_value[0], indep_var->type))
+ if (!parse_value (lexer, &gp.v.g_value[0], var_get_type (indep_var)))
return 0;
lex_match (lexer, ',');
if (lex_match (lexer, ')'))
{
- if (indep_var->type != NUMERIC)
+ if (var_is_alpha (indep_var))
{
-
msg (SE, _("When applying GROUPS to a string variable, two "
"values must be specified."));
return 0;
return 1;
}
- if (!parse_value (lexer, &gp.v.g_value[1], indep_var->type))
+ if (!parse_value (lexer, &gp.v.g_value[1], var_get_type (indep_var)))
return 0;
n_group_values = 2;
ssbox_base_init(this, hsize,vsize);
tab_vline (this->t, TAL_GAP, 1, 0,vsize - 1);
tab_title (this->t, _("Group Statistics"));
- tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, indep_var->name);
+ tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, var_get_name (indep_var));
tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("N"));
tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
char prefix[2][3]={"",""};
- if ( indep_var->type == NUMERIC )
+ if ( var_is_numeric (indep_var) )
{
val_lab0 = val_labs_find( indep_var->val_labs,gp.v.g_value[0]);
val_lab1 = val_labs_find( indep_var->val_labs,gp.v.g_value[1]);
struct hsh_table *grp_hash = group_proc_get (var)->group_hash;
int count=0;
- tab_text (ssb->t, 0, i*2+1, TAB_LEFT, cmd->v_variables[i]->name);
+ tab_text (ssb->t, 0, i*2+1, TAB_LEFT,
+ var_get_name (cmd->v_variables[i]));
if (val_lab0)
tab_text (ssb->t, 1, i*2+1, TAB_LEFT | TAT_PRINTF,
/* Titles */
- tab_text (ssb->t, 1, i*2+j+1, TAB_LEFT, pairs[i].v[j]->name);
+ tab_text (ssb->t, 1, i*2+j+1, TAB_LEFT,
+ var_get_name (pairs[i].v[j]));
/* Values */
tab_float (ssb->t,2, i*2+j+1, TAB_RIGHT, pairs[i].mean[j], 8, 2);
{
struct group_statistics *gs = &group_proc_get (cmd->v_variables[i])->ugs;
- tab_text (ssb->t, 0, i+1, TAB_LEFT, cmd->v_variables[i]->name);
+ tab_text (ssb->t, 0, i+1, TAB_LEFT, var_get_name (cmd->v_variables[i]));
tab_float (ssb->t,1, i+1, TAB_RIGHT, gs->n, 2, 0);
tab_float (ssb->t,2, i+1, TAB_RIGHT, gs->mean, 8, 2);
tab_float (ssb->t,3, i+1, TAB_RIGHT, gs->std_dev, 8, 2);
assert(gs1);
- tab_text (self->t, 0, i*2+3, TAB_LEFT, cmd->v_variables[i]->name);
+ tab_text (self->t, 0, i*2+3, TAB_LEFT, var_get_name (cmd->v_variables[i]));
tab_text (self->t, 1, i*2+3, TAB_LEFT, _("Equal variances assumed"));
tab_text (trb->t, 0, i+3, TAB_LEFT | TAT_PRINTF, _("Pair %d"),i);
tab_text (trb->t, 1, i+3, TAB_LEFT | TAT_PRINTF, "%s - %s",
- pairs[i].v[0]->name, pairs[i].v[1]->name);
+ var_get_name (pairs[i].v[0]),
+ var_get_name (pairs[i].v[1]));
tab_float(trb->t, 2, i+3, TAB_RIGHT, pairs[i].mean_diff, 8, 4);
struct group_statistics *gs = &group_proc_get (cmd->v_variables[i])->ugs;
- tab_text (trb->t, 0, i+3, TAB_LEFT, cmd->v_variables[i]->name);
+ tab_text (trb->t, 0, i+3, TAB_LEFT, var_get_name (cmd->v_variables[i]));
t = (gs->mean - cmd->n_testval[0] ) * sqrt(gs->n) / gs->std_dev ;
_("Pair %d"), i);
tab_text(table, 1,i+1, TAB_LEFT | TAT_TITLE | TAT_PRINTF,
- _("%s & %s"), pairs[i].v[0]->name, pairs[i].v[1]->name);
+ _("%s & %s"),
+ var_get_name (pairs[i].v[0]),
+ var_get_name (pairs[i].v[1]));
/* row data */
/* There's always 2 groups for a T - TEST */
ttpr->n_groups = 2;
- gp.indep_width = indep_var->width;
+ gp.indep_width = var_get_width (indep_var);
ttpr->group_hash = hsh_create(2,
(hsh_compare_func *) compare_group_binary,
if (var == NULL)
msg (SN, _("WEIGHT is off."));
else
- msg (SN, _("WEIGHT is variable %s."), var->name);
+ msg (SN, _("WEIGHT is variable %s."), var_get_name (var));
}
static void
vr = compute->vector->var[rindx - 1];
expr_evaluate_str (compute->rvalue, c, case_num,
- case_data_rw (c, vr->fv)->s, vr->width);
+ case_data_rw (c, vr->fv)->s, var_get_width (vr));
}
return TRNS_CONTINUE;
lvalue_get_type (const struct lvalue *lvalue)
{
return (lvalue->variable != NULL
- ? lvalue->variable->type
- : lvalue->vector->var[0]->type);
+ ? var_get_type (lvalue->variable)
+ : var_get_type (lvalue->vector->var[0]));
}
/* Returns true if LVALUE has a vector as its target. */
{
compute->variable = lvalue->variable;
compute->fv = compute->variable->fv;
- compute->width = compute->variable->width;
+ compute->width = var_get_width (compute->variable);
/* Goofy behavior, but compatible: Turn off LEAVE. */
- if (dict_class_from_id (compute->variable->name) != DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (compute->variable)) != DC_SCRATCH)
compute->variable->leave = false;
/* Prevent lvalue_destroy from deleting variable. */
dv->var = dict_lookup_var (dataset_dict (ds), lex_tokid (lexer));
if (dv->var != NULL)
{
- if (dv->var->type == ALPHA)
+ if (var_is_alpha (dv->var))
{
msg (SE, _("Destination cannot be a string variable."));
goto fail;
goto fail;
crit->value_cnt = 0;
- if (crit->vars[0]->type == NUMERIC)
+ if (var_is_numeric (crit->vars[0]))
ok = parse_numeric_criteria (lexer, trns->pool, crit);
else
ok = parse_string_criteria (lexer, trns->pool, crit);
size_t i;
for (i = 0; i < crit->var_cnt; i++)
- if (crit->vars[i]->width > len)
- len = crit->vars[i]->width;
+ if (var_get_width (crit->vars[i]) > len)
+ len = var_get_width (crit->vars[i]);
crit->values.str = NULL;
for (;;)
if (x == SYSMIS)
counter += crit->count_system_missing;
else if (crit->count_user_missing
- && mv_is_num_user_missing (&crit->vars[i]->miss, x))
+ && var_is_num_user_missing (crit->vars[i], x))
counter++;
else
{
char **v;
for (v = crit->values.str; v < crit->values.str + crit->value_cnt; v++)
if (!memcmp (case_str (c, crit->vars[i]->fv), *v,
- crit->vars[i]->width))
+ var_get_width (crit->vars[i])))
{
counter++;
break;
counter = 0;
for (crit = dv->crit; crit; crit = crit->next)
- if (crit->vars[0]->type == NUMERIC)
+ if (var_is_numeric (crit->vars[0]))
counter += count_numeric (crit, c);
else
counter += count_string (crit, c);
PV_SAME_TYPE))
return false;
pool_register (trns->pool, free, trns->src_vars);
- trns->src_type = trns->src_vars[0]->type;
+ trns->src_type = var_get_type (trns->src_vars[0]);
return true;
}
size_t i;
/* Find length of longest source variable. */
- max_src_width = trns->src_vars[0]->width;
+ max_src_width = var_get_width (trns->src_vars[0]);
for (i = 1; i < trns->var_cnt; i++)
{
- size_t var_width = trns->src_vars[i]->width;
+ size_t var_width = var_get_width (trns->src_vars[i]);
if (var_width > max_src_width)
max_src_width = var_width;
}
for (i = 0; i < trns->var_cnt; i++)
{
struct variable *v = trns->dst_vars[i];
- if (v != NULL && v->type != trns->dst_type)
+ if (v != NULL && var_get_type (v) != trns->dst_type)
{
msg (SE, _("Type mismatch. Cannot store %s data in "
"%s variable %s."),
trns->dst_type == ALPHA ? _("string") : _("numeric"),
- v->type == ALPHA ? _("string") : _("numeric"),
- v->name);
+ var_is_alpha (v) ? _("string") : _("numeric"),
+ var_get_name (v));
return false;
}
}
for (i = 0; i < trns->var_cnt; i++)
{
struct variable *v = trns->dst_vars[i];
- if (v->width > max_dst_width)
- max_dst_width = v->width;
+ if (var_get_width (v) > max_dst_width)
+ max_dst_width = var_get_width (v);
}
for (i = 0; i < trns->map_cnt; i++)
*var = dict_lookup_var (dict, name);
if (*var == NULL)
*var = dict_create_var_assert (dict, name, 0);
- assert ((*var)->type == trns->dst_type);
+ assert (var_get_type (*var) == trns->dst_type);
}
}
\f
match = value == in->x.f;
break;
case MAP_MISSING:
- match = mv_is_num_user_missing (&v->miss, value);
+ match = var_is_num_user_missing (v, value);
break;
case MAP_RANGE:
match = value >= in->x.f && value <= in->y.f;
if (trns->src_type == NUMERIC)
out = find_src_numeric (trns, src_data->f, src_var);
else
- out = find_src_string (trns, src_data->s, src_var->width);
+ out = find_src_string (trns, src_data->s, var_get_width (src_var));
if (trns->dst_type == NUMERIC)
{
if (out != NULL)
{
if (!out->copy_input)
- memcpy (dst_data->s, out->value.c, dst_var->width);
+ memcpy (dst_data->s, out->value.c, var_get_width (dst_var));
else if (trns->src_vars != trns->dst_vars)
- buf_copy_rpad (dst_data->s, dst_var->width,
- src_data->s, src_var->width);
+ buf_copy_rpad (dst_data->s, var_get_width (dst_var),
+ src_data->s, var_get_width (src_var));
}
else if (trns->src_vars != trns->dst_vars)
- memset (dst_data->s, ' ', dst_var->width);
+ memset (dst_data->s, ' ', var_get_width (dst_var));
}
}
if (!v)
return CMD_FAILURE;
- if (v->type == ALPHA)
+ if (var_is_alpha (v))
{
msg (SE, _("The filter variable must be numeric."));
return CMD_FAILURE;
}
- if (dict_class_from_id (v->name) == DC_SCRATCH)
+ if (dict_class_from_id (var_get_name (v)) == DC_SCRATCH)
{
msg (SE, _("The filter variable may not be scratch."));
return CMD_FAILURE;
c[i]->v_info->v =
(const struct variable *) design_matrix_col_to_var (X, i);
- if (c[i]->v_info->v->type == ALPHA)
+ if (var_is_alpha (c[i]->v_info->v))
{
size_t k;
k = design_matrix_var_to_column (X, c[i]->v_info->v);
{
return NULL;
}
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
{
return NULL;
}
{
return NULL;
}
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
{
return result;
}
*/
while (tmp->index != v->index && i < c->n_coeffs
&& compare_values (pspp_coeff_get_value (result, tmp),
- val, v->width))
+ val, var_get_width (v)))
{ /* FIX THIS */
i++;
result = c->coeff[i];
(dm->vars + i)->v = v; /* Allows us to look up the variable from
the design matrix. */
(dm->vars + i)->first_column = n_cols;
- if (v->type == NUMERIC)
+ if (var_is_numeric (v))
{
(dm->vars + i)->last_column = n_cols;
n_cols++;
}
- else if (v->type == ALPHA)
+ else if (var_is_alpha (v))
{
assert (v->obs_vals != NULL);
(dm->vars + i)->last_column =
size_t lc;
double entry;
- assert (var->type == ALPHA);
+ assert (var_is_alpha (var));
fc = design_matrix_var_to_column (dm, var);
lc = dm_var_to_last_column (dm, var);
assert (lc != DM_COLUMN_NOT_FOUND);
{
size_t col;
- assert (var->type == NUMERIC);
+ assert (var_is_numeric (var));
col = design_matrix_var_to_column ((const struct design_matrix *) dm, var);
assert (col != DM_COLUMN_NOT_FOUND);
gsl_matrix_set (dm->m, row, col, val->f);
{
found[i] = coe;
tmp = pspp_coeff_get_est (coe);
- if (predictors[j]->type == NUMERIC)
+ if (var_is_numeric (predictors[j]))
{
tmp *= vals[j]->f;
}
if ( old_size == new_size )
return ;
- pv->v->nv = new_size;
-
dict_compact_values(d->dict);
fv = psppire_variable_get_fv(pv);
if ( !text)
return FALSE;
- if ( 0 == strcmp(pv->v->name, text))
+ if ( 0 == strcmp(var_get_name (pv->v), text))
return FALSE;
if ( ! psppire_dict_check_name(pv->dict, text, TRUE) )
g_return_val_if_fail(pv->dict, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- pv->v->display_width = columns;
+ var_set_display_width (pv->v, columns);
psppire_dict_var_changed(pv->dict, pv->v->index);
g_return_val_if_fail(pv->dict, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- g_free(pv->v->label);
- pv->v->label = g_strdup(label);
+ var_set_label (pv->v, label);
psppire_dict_var_changed(pv->dict, pv->v->index);
g_return_val_if_fail(pv->dict, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- fmt = pv->v->write;
-
+ fmt = *var_get_write_format (pv->v);
fmt.d = decimals;
return psppire_variable_set_format(pv, &fmt);
g_return_val_if_fail(pv->dict, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- fmt = pv->v->write;
-
+ fmt = *var_get_write_format (pv->v);
fmt.w = width;
- if ( pv->v->type == ALPHA )
+ if (var_is_alpha (pv->v))
{
gint old_var_cnt , new_var_cnt ;
- if ( pv->v->width == 0 )
+ if ( var_get_width (pv->v) == 0 )
old_var_cnt = 1;
else
- old_var_cnt = DIV_RND_UP(pv->v->width, MAX_SHORT_STRING);
+ old_var_cnt = DIV_RND_UP(var_get_width (pv->v), MAX_SHORT_STRING);
new_var_cnt = DIV_RND_UP(width, MAX_SHORT_STRING);
- pv->v->width = width;
+ pv->v->width = width;
psppire_dict_resize_variable(pv->dict, pv,
old_var_cnt, new_var_cnt);
g_return_val_if_fail(pv->dict, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- pv->v->type = type;
-
- if ( pv->v->width == 0 )
+ if ( var_get_width (pv->v) )
old_var_cnt = 1;
else
- old_var_cnt = DIV_RND_UP(pv->v->width, MAX_SHORT_STRING);
+ old_var_cnt = DIV_RND_UP (var_get_width (pv->v), MAX_SHORT_STRING);
if ( type == NUMERIC )
pv->v->width = 0;
+ else if (var_get_width (pv->v))
+ pv->v->width = 1;
- if ( pv->v->width == 0 )
+ if ( var_get_width (pv->v) == 0 )
new_var_cnt = 1;
else
- new_var_cnt = DIV_RND_UP(pv->v->width, MAX_SHORT_STRING);
+ new_var_cnt = DIV_RND_UP (var_get_width (pv->v), MAX_SHORT_STRING);
psppire_dict_resize_variable(pv->dict, pv,
old_var_cnt, new_var_cnt);
msg_disable ();
if ( fmt_check_output(fmt)
- && fmt_check_type_compat (fmt, pv->v->type)
- && fmt_check_width_compat (fmt, pv->v->width))
+ && fmt_check_type_compat (fmt, var_get_type (pv->v))
+ && fmt_check_width_compat (fmt, var_get_width (pv->v)))
{
msg_enable ();
- pv->v->write = pv->v->print = *fmt;
+ var_set_both_formats (pv->v, fmt);
psppire_dict_var_changed(pv->dict, pv->v->index);
return TRUE;
}
g_return_val_if_fail(pv->dict, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- mv_copy(&pv->v->miss, miss);
+ var_set_missing_values (pv->v, miss);
psppire_dict_var_changed(pv->dict, pv->v->index);
return TRUE;
g_return_val_if_fail(pv, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- pv->v->write = fmt;
+ var_set_write_format (pv->v, &fmt);
psppire_dict_var_changed(pv->dict, pv->v->index);
return TRUE;
g_return_val_if_fail(pv, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- pv->v->print = fmt;
+ var_set_print_format (pv->v, &fmt);
psppire_dict_var_changed(pv->dict, pv->v->index);
return TRUE;
g_return_val_if_fail(pv->dict, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- pv->v->alignment = align;
+ var_set_alignment (pv->v, align);
psppire_dict_var_changed(pv->dict, pv->v->index);
return TRUE;
g_return_val_if_fail(pv->dict, FALSE);
g_return_val_if_fail(pv->v, FALSE);
- pv->v->measure = measure + 1;
+ var_set_measure (pv->v, measure + 1);
psppire_dict_var_changed(pv->dict, pv->v->index);
return TRUE;
g_return_val_if_fail(pv, NULL);
g_return_val_if_fail(pv->v, NULL);
-
- return &pv->v->write;
+ return var_get_write_format (pv->v);
}
g_return_val_if_fail(pv, NULL);
g_return_val_if_fail(pv->v, NULL);
- return pv->v->name;
+ return var_get_name (pv->v);
}
g_return_val_if_fail(pv, -1);
g_return_val_if_fail(pv->v, -1);
- return pv->v->display_width;
+ return var_get_display_width (pv->v);
}
g_return_val_if_fail(pv, NULL);
g_return_val_if_fail(pv->v, NULL);
- return pv->v->label;
+ return var_get_label (pv->v);
}
g_return_val_if_fail(pv, NULL);
g_return_val_if_fail(pv->v, NULL);
- return &pv->v->miss;
+ return var_get_missing_values (pv->v);
}
g_return_val_if_fail(pv, -1);
g_return_val_if_fail(pv->v, -1);
- return pv->v->alignment;
+ return var_get_alignment (pv->v);
}
g_return_val_if_fail(pv, -1);
g_return_val_if_fail(pv->v, -1);
- return pv->v->measure - 1;
+ return var_get_measure (pv->v) - 1;
}
gint
g_return_val_if_fail(pv, -1);
g_return_val_if_fail(pv->v, -1);
- return pv->v->type;
+ return var_get_type (pv->v);
}
g_return_val_if_fail(pv, -1);
g_return_val_if_fail(pv->v, -1);
- return pv->v->width;
+ return var_get_width (pv->v);
}
|SEX |A1 |
|X |F8.0 |
+--------+------+
-2.1 FREQUENCIES. X:
+2.1 FREQUENCIES. X
+-----------+--------+---------+--------+--------+--------+
| | | | | Valid | Cum |
|Value Label| Value |Frequency| Percent| Percent| Percent|
#========#=======#=========#======#========#=======#========#========#========#========#========#======#=======#=======#=========#
|AVAR # 730| 0|31.515| .405| 10.937| 119.608| 2.411| .181| 1.345| .090|76.000| 18.000| 94.000|23006.000|
+--------#-------+---------+------+--------+-------+--------+--------+--------+--------+--------+------+-------+-------+---------+
-3.1 FREQUENCIES. AVAR:
+3.1 FREQUENCIES. AVAR
+--------+--------+---+---+
| | | |Cum|
| Value | Freq |Pct|Pct|
activity="compare output $i"
perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
diff -b $TEMPDIR/pspp.list - <<EOF
-1.1 FREQUENCIES. X:
+1.1 FREQUENCIES. X
+-----------+--------+---------+--------+--------+--------+
| | | | | Valid | Cum |
|Value Label| Value |Frequency| Percent| Percent| Percent|
activity="compare output $i"
perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
diff -b $TEMPDIR/pspp.list - <<EOF
-1.1 FREQUENCIES. X:
+1.1 FREQUENCIES. X
+-----------+--------+---------+--------+--------+--------+
| | | | | Valid | Cum |
|Value Label| Value |Frequency| Percent| Percent| Percent|
activity="compare output $i"
perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
diff -b $TEMPDIR/pspp.list - <<EOF
-1.1 FREQUENCIES. X:
+1.1 FREQUENCIES. X
+-----------+--------+---------+--------+--------+--------+
| | | | | Valid | Cum |
|Value Label| Value |Frequency| Percent| Percent| Percent|
activity="compare output $i"
perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
diff -b $TEMPDIR/pspp.list - <<EOF
-1.1 FREQUENCIES. X:
+1.1 FREQUENCIES. X
+-----------+--------+---------+--------+--------+--------+
| | | | | Valid | Cum |
|Value Label| Value |Frequency| Percent| Percent| Percent|
activity="compare output $i"
perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
diff -b $TEMPDIR/pspp.list - <<EOF
-1.1 FREQUENCIES. X:
+1.1 FREQUENCIES. X
+-----------+--------+---------+--------+--------+--------+
| | | | | Valid | Cum |
|Value Label| Value |Frequency| Percent| Percent| Percent|