+ struct attrset attrs;
+
+ attrset_clone (&attrs, var_get_attributes (v));
+
+ add_role_attribute (var_get_role (v), &attrs);
+ if (n_attrsets++)
+ ds_put_byte (&s, '/');
+ ds_put_format (&s, "%s:", var_get_name (v));
+ put_attrset (&s, &attrs);
+ attrset_destroy (&attrs);
+ }
+ if (n_attrsets)
+ write_utf8_record (w, dict_get_encoding (d), &s, 18);
+ 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. */
+static void
+write_mrsets (struct sfm_writer *w, const struct dictionary *dict,
+ bool pre_v14)
+{
+ const char *encoding = dict_get_encoding (dict);
+ struct string s = DS_EMPTY_INITIALIZER;
+ size_t n_mrsets;
+ size_t i;
+
+ if (is_encoding_ebcdic_compatible (encoding))
+ {
+ /* FIXME. */
+ return;
+ }
+
+ n_mrsets = dict_get_n_mrsets (dict);
+ if (n_mrsets == 0)
+ return;
+
+ for (i = 0; i < n_mrsets; i++)
+ {
+ const struct mrset *mrset = dict_get_mrset (dict, i);
+ char *name;
+ size_t j;
+
+ if ((mrset->type != MRSET_MD || mrset->cat_source != MRSET_COUNTEDVALUES)
+ != pre_v14)
+ continue;
+
+ name = recode_string (encoding, "UTF-8", mrset->name, -1);
+ ds_put_format (&s, "%s=", name);
+ free (name);
+
+ if (mrset->type == MRSET_MD)
+ {
+ char *counted;
+
+ if (mrset->cat_source == MRSET_COUNTEDVALUES)
+ ds_put_format (&s, "E %d ", mrset->label_from_var_label ? 11 : 1);
+ else
+ ds_put_byte (&s, 'D');
+
+ if (mrset->width == 0)
+ counted = xasprintf ("%.0f", mrset->counted.f);
+ else
+ counted = xmemdup0 (mrset->counted.s, mrset->width);
+ ds_put_format (&s, "%zu %s", strlen (counted), counted);
+ free (counted);
+ }
+ else
+ ds_put_byte (&s, 'C');
+ ds_put_byte (&s, ' ');
+
+ if (mrset->label && !mrset->label_from_var_label)