/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
static const struct casewriter_class sys_file_casewriter_class;
static void write_header (struct sfm_writer *, const struct dictionary *);
-static void write_variable (struct sfm_writer *, const struct variable *, const struct dictionary *);
-static void write_value_labels (struct sfm_writer *,
- struct variable *, int idx, const struct dictionary *);
+static void write_variable (struct sfm_writer *, const struct variable *);
+static void write_value_labels (struct sfm_writer *, struct variable *,
+ int idx);
static void write_integer_info_record (struct sfm_writer *);
static void write_float_info_record (struct sfm_writer *);
/* Write basic variable info. */
short_names_assign (d);
for (i = 0; i < dict_get_var_cnt (d); i++)
- write_variable (w, dict_get_var (d, i), d);
+ write_variable (w, dict_get_var (d, i));
/* Write out value labels. */
idx = 0;
{
struct variable *v = dict_get_var (d, i);
- write_value_labels (w, v, idx, d);
+ write_value_labels (w, v, idx);
idx += sfm_width_to_octs (var_get_width (v));
}
/* Write the variable record(s) for variable V to system file
W. */
static void
-write_variable (struct sfm_writer *w, const struct variable *v, const struct dictionary *dict)
+write_variable (struct sfm_writer *w, const struct variable *v)
{
int width = var_get_width (v);
int segment_cnt = sfm_width_to_segments (width);
/* Value label. */
if (var_has_label (v))
{
- char *label = recode_string (dict_get_encoding (dict), UTF8, var_get_label (v), -1);
+ char *label = recode_string (var_get_encoding (v), UTF8, var_get_label (v), -1);
size_t label_len = MIN (strlen (label), 255);
size_t padded_len = ROUND_UP (label_len, 4);
write_int (w, label_len);
Value labels for long string variables are written separately,
by write_long_string_value_labels. */
static void
-write_value_labels (struct sfm_writer *w, struct variable *v, int idx, const struct dictionary *dict)
+write_value_labels (struct sfm_writer *w, struct variable *v, int idx)
{
const struct val_labs *val_labs;
const struct val_lab **labels;
for (i = 0; i < n_labels; i++)
{
const struct val_lab *vl = labels[i];
- char *label = recode_string (dict_get_encoding (dict), UTF8, val_lab_get_label (vl), -1);
+ char *label = recode_string (var_get_encoding (v), UTF8, val_lab_get_label (vl), -1);
uint8_t len = MIN (strlen (label), 255);
write_value (w, val_lab_get_value (vl), var_get_width (v));
struct string *str)
{
const char *name = var_lookup_value_label (v, value);
- const struct dictionary *dict = var_get_vardict (v)->dict;
if (name == NULL)
{
- char *s = data_out (value, dict_get_encoding (dict), &v->print);
+ char *s = data_out (value, var_get_encoding (v), &v->print);
ds_put_cstr (str, s);
free (s);
}
return attrset_count (&v->attributes) > 0;
}
\f
+/* Returns the encoding of values of variable VAR. (This is actually a
+ property of the dictionary.) Returns null if no specific encoding has been
+ set. */
+const char *
+var_get_encoding (const struct variable *var)
+{
+ return var_has_vardict (var) ? dict_get_encoding (var->vardict.dict) : NULL;
+}
+\f
/* Returns V's vardict structure. */
const struct vardict_info *
var_get_vardict (const struct variable *v)
/* Perform data_out for case CC, variable V, appending to STRING */
static void
-data_out_g_string (GString *string, const struct dictionary *dict,
- const struct variable *v,
+data_out_g_string (GString *string, const struct variable *v,
const struct ccase *cc)
{
const struct fmt_spec *fs = var_get_print_format (v);
const union value *val = case_data (cc, v);
- char *s = data_out (val, dict_get_encoding (dict), fs);
+ char *s = data_out (val, var_get_encoding (v), fs);
g_string_append (string, s);
for (c = 0 ; c < var_cnt ; ++c)
{
const struct variable *v = dict_get_var (clip_dict, c);
- data_out_g_string (string, clip_dict, v, cc);
+ data_out_g_string (string, v, cc);
if ( c < val_cnt - 1 )
g_string_append (string, "\t");
}
{
const struct variable *v = dict_get_var (clip_dict, c);
g_string_append (string, "<td>");
- data_out_g_string (string, clip_dict, v, cc);
+ data_out_g_string (string, v, cc);
g_string_append (string, "</td>\n");
}