From: Ben Pfaff Date: Fri, 8 Jan 2021 00:48:27 +0000 (-0800) Subject: spv: Encode and decode AHEX format in light binary members. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=4ba836f6913f91416dee16c6b543bd15ade476a0 spv: Encode and decode AHEX format in light binary members. --- diff --git a/doc/dev/spv-file-format.texi b/doc/dev/spv-file-format.texi index 666e8d4410..0aa53083b9 100644 --- a/doc/dev/spv-file-format.texi +++ b/doc/dev/spv-file-format.texi @@ -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 diff --git a/src/output/spv/spv-light-decoder.c b/src/output/spv/spv-light-decoder.c index d5c387d09e..620fdb0a29 100644 --- a/src/output/spv/spv-light-decoder.c +++ b/src/output/spv/spv-light-decoder.c @@ -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; diff --git a/src/output/spv/spv-writer.c b/src/output/spv/spv-writer.c index 19ea047afa..092558d832 100644 --- a/src/output/spv/spv-writer.c +++ b/src/output/spv/spv-writer.c @@ -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);