X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fsys-file-writer.c;h=34f420e4a46e69c4a54a68cb64d3752952f4b9b9;hb=54b3aa8432383287c75b9baf954b7bf887126a0c;hp=33215241c2c98433d153802e7dca1c450c4ee67f;hpb=064e63444113026f99a518bf1ec77da5eb6b036b;p=pspp diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 33215241c2..34f420e4a4 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -41,6 +41,7 @@ #include "data/short-names.h" #include "data/value-labels.h" #include "data/variable.h" +#include "data/varset.h" #include "libpspp/float-format.h" #include "libpspp/i18n.h" #include "libpspp/integer-format.h" @@ -132,6 +133,7 @@ static void write_long_string_value_labels (struct sfm_writer *, static void write_long_string_missing_values (struct sfm_writer *, const struct dictionary *); +static void write_varsets (struct sfm_writer *, const struct dictionary *); static void write_mrsets (struct sfm_writer *, const struct dictionary *, bool pre_v14); @@ -275,6 +277,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, write_integer_info_record (w, d); write_float_info_record (w); + write_varsets (w, d); write_mrsets (w, d, true); write_variable_display_parameters (w, d); @@ -804,6 +807,49 @@ write_variable_attributes (struct sfm_writer *w, const struct dictionary *d) ds_destroy (&s); } +/* Write variable sets. */ +static void +write_varsets (struct sfm_writer *w, const struct dictionary *dict) +{ + const char *encoding = dict_get_encoding (dict); + + if (is_encoding_ebcdic_compatible (encoding)) + { + /* FIXME. */ + return; + } + + size_t n_varsets = dict_get_n_varsets (dict); + if (n_varsets == 0) + return; + + struct string s = DS_EMPTY_INITIALIZER; + for (size_t i = 0; i < n_varsets; i++) + { + const struct varset *varset = dict_get_varset (dict, i); + + char *name = recode_string (encoding, "UTF-8", varset->name, -1); + ds_put_format (&s, "%s= ", name); + free (name); + + for (size_t j = 0; j < varset->n_vars; j++) + { + if (j) + ds_put_byte (&s, ' '); + + const char *name_utf8 = var_get_name (varset->vars[j]); + char *name = recode_string (encoding, "UTF-8", name_utf8, -1); + ds_put_cstr (&s, name); + free (name); + } + ds_put_byte (&s, '\n'); + } + + if (!ds_is_empty (&s)) + write_string_record (w, ds_ss (&s), 5); + ds_destroy (&s); +} + /* Write multiple response sets. If PRE_V14 is true, writes sets supported by SPSS before release 14, otherwise writes sets supported only by later versions. */