+
+static void
+write_long_string_value_labels (struct sfm_writer *w,
+ const struct dictionary *dict)
+{
+ size_t n_vars = dict_get_var_cnt (dict);
+ size_t size, i;
+ off_t start UNUSED;
+
+ /* Figure out the size in advance. */
+ size = 0;
+ for (i = 0; i < n_vars; i++)
+ {
+ struct variable *var = dict_get_var (dict, i);
+ const struct val_labs *val_labs = var_get_value_labels (var);
+ int width = var_get_width (var);
+ const struct val_lab *val_lab;
+
+ if (val_labs_count (val_labs) == 0 || width < 9)
+ continue;
+
+ size += 12 + strlen (var_get_name (var));
+ for (val_lab = val_labs_first (val_labs); val_lab != NULL;
+ val_lab = val_labs_next (val_labs, val_lab))
+ size += 8 + width + strlen (val_lab_get_label (val_lab));
+ }
+ if (size == 0)
+ return;
+
+ write_int (w, 7); /* Record type. */
+ write_int (w, 21); /* Record subtype */
+ write_int (w, 1); /* Data item (byte) size. */
+ write_int (w, size); /* Number of data items. */
+
+ start = ftello (w->file);
+ for (i = 0; i < n_vars; i++)
+ {
+ struct variable *var = dict_get_var (dict, i);
+ const struct val_labs *val_labs = var_get_value_labels (var);
+ const char *var_name = var_get_name (var);
+ int width = var_get_width (var);
+ const struct val_lab *val_lab;
+
+ if (val_labs_count (val_labs) == 0 || width < 9)
+ continue;
+
+ write_int (w, strlen (var_name));
+ write_bytes (w, var_name, strlen (var_name));
+ write_int (w, width);
+ write_int (w, val_labs_count (val_labs));
+ for (val_lab = val_labs_first (val_labs); val_lab != NULL;
+ val_lab = val_labs_next (val_labs, val_lab))
+ {
+ const char *label = val_lab_get_label (val_lab);
+ size_t label_length = strlen (label);
+
+ write_int (w, width);
+ write_bytes (w, value_str (val_lab_get_value (val_lab), width),
+ width);
+ write_int (w, label_length);
+ write_bytes (w, label, label_length);
+ }
+ }
+ assert (ftello (w->file) == start + size);
+}
+
+static void
+write_encoding_record (struct sfm_writer *w,
+ const struct dictionary *d)
+{
+ const char *enc = dict_get_encoding (d);
+
+ if ( NULL == enc)
+ return;
+
+ write_int (w, 7); /* Record type. */
+ write_int (w, 20); /* Record subtype. */
+ write_int (w, 1); /* Data item (char) size. */
+ write_int (w, strlen (enc)); /* Number of data items. */
+ write_string (w, enc, strlen (enc));
+}
+
+