- /* Value label variable record. */
- write_int (w, 4); /* Record type. */
- write_int (w, 1); /* Number of variables. */
- write_int (w, idx + 1); /* Variable's dictionary index. */
+ for (i = 0; i < n_sets; i++)
+ {
+ const struct label_set *set = sets[i];
+ const struct val_labs *val_labs = set->val_labs;
+ size_t n_labels = val_labs_count (val_labs);
+ int width = val_labs_get_width (val_labs);
+ const struct val_lab **labels;
+ size_t j;
+
+ /* Value label record. */
+ write_int (w, 3); /* Record type. */
+ write_int (w, n_labels);
+ labels = val_labs_sorted (val_labs);
+ for (j = 0; j < n_labels; j++)
+ {
+ const struct val_lab *vl = labels[j];
+ char *label = recode_string (dict_get_encoding (d), UTF8,
+ val_lab_get_escaped_label (vl), -1);
+ uint8_t len = MIN (strlen (label), 255);
+
+ write_value (w, val_lab_get_value (vl), width);
+ write_bytes (w, &len, 1);
+ write_bytes (w, label, len);
+ write_zeros (w, REM_RND_UP (len + 1, 8));
+ free (label);
+ }
+ free (labels);
+
+ /* Value label variable record. */
+ write_int (w, 4); /* Record type. */
+ write_int (w, set->n_indexes);
+ for (j = 0; j < set->n_indexes; j++)
+ write_int (w, set->indexes[j] + 1);
+ }
+
+ for (i = 0; i < n_sets; i++)
+ {
+ struct label_set *set = sets[i];
+
+ free (set->indexes);
+ free (set);
+ }
+ free (sets);
+ hmap_destroy (&same_sets);