spv: Encode and decode AHEX format in light binary members.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 8 Jan 2021 00:48:27 +0000 (16:48 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 8 Jan 2021 00:48:39 +0000 (16:48 -0800)
doc/dev/spv-file-format.texi
src/output/spv/spv-light-decoder.c
src/output/spv/spv-writer.c

index 666e8d4410d2e3f3d39baca3e10a4effbd809ce0..0aa53083b95456eb63ef92298565bdee111416ea 100644 (file)
@@ -1736,8 +1736,9 @@ case, @code{id} is always the empty string; in the latter case,
 The string value @code{s}, intended to be presented to the user
 formatted according to @code{format}.  The format for a string is not
 too interesting, and the corpus contains many clearly invalid formats
-like A16.39 or A255.127 or A134.1, so readers should probably ignore
-the format entirely.
+like A16.39 or A255.127 or A134.1, so readers should probably entirely
+disregard the format.  PSPP only checks @code{format} to distinguish
+AHEX format.
 
 @code{s} is a value of variable @code{var-name} and has value label
 @code{value-label}.  @code{var-name} is never empty but
index d5c387d09e0e4164db730f68d8d74f03f9b68fe0..620fdb0a29d4543c557dbc2cdbda94f35cc63ed5 100644 (file)
@@ -321,6 +321,7 @@ decode_spvlb_value (const struct pivot_table *table,
       if (error)
         return NULL;
       out->string.s = xstrdup (in->type_04.s);
+      out->string.hex = (in->type_04.format >> 16) == fmt_to_io (FMT_AHEX);
       out->string.var_name = xstrdup (in->type_04.var_name);
       out->string.value_label = xstrdup_if_nonempty (in->type_04.value_label);
       break;
index 19ea047afab51cfbbf20a46e4f55548b0c114efa..092558d8321ce0d0ac1680b51e190ea58ff8ee47 100644 (file)
@@ -604,9 +604,11 @@ put_value (struct buf *buf, const struct pivot_value *value)
     case PIVOT_VALUE_STRING:
       put_byte (buf, 4);
       put_value_mod (buf, value, NULL);
-      put_format (buf,
-                  &(struct fmt_spec) { FMT_A, strlen (value->string.s), 0 },
-                  false);
+      size_t len = strlen (value->string.s);
+      if (value->string.hex)
+        put_format (buf, &(struct fmt_spec) { FMT_AHEX, len * 2, 0 }, false);
+      else
+        put_format (buf, &(struct fmt_spec) { FMT_A, len, 0 }, false);
       put_string (buf, value->string.value_label);
       put_string (buf, value->string.var_name);
       put_show_values (buf, value->string.show);