+static void
+read_character_encoding (struct sfm_reader *r, size_t size, size_t count)
+{
+ long long int posn = ftello (r->file);
+ char *encoding = xcalloc (size, count + 1);
+ read_string (r, encoding, count + 1);
+
+ printf ("%08llx: Character Encoding: %s\n", posn, encoding);
+}
+
+static void
+read_long_string_value_labels (struct sfm_reader *r, size_t size, size_t count)
+{
+ long long int start = ftello (r->file);
+
+ printf ("%08llx: long string value labels\n", start);
+ while (ftello (r->file) - start < size * count)
+ {
+ long long posn = ftello (r->file);
+ char var_name[ID_MAX_LEN + 1];
+ int var_name_len;
+ int n_values;
+ int width;
+ int i;
+
+ /* Read variable name. */
+ var_name_len = read_int (r);
+ if (var_name_len > ID_MAX_LEN)
+ sys_error (r, _("Variable name length in long string value label "
+ "record (%d) exceeds %d-byte limit."),
+ var_name_len, ID_MAX_LEN);
+ read_string (r, var_name, var_name_len + 1);
+
+ /* Read width, number of values. */
+ width = read_int (r);
+ n_values = read_int (r);
+
+ printf ("\t%08llx: %s, width %d, %d values\n",
+ posn, var_name, width, n_values);
+
+ /* Read values. */
+ for (i = 0; i < n_values; i++)
+ {
+ char *value;
+ int value_length;
+
+ char *label;
+ int label_length;
+
+ posn = ftello (r->file);
+
+ /* Read value. */
+ value_length = read_int (r);
+ value = xmalloc (value_length + 1);
+ read_string (r, value, value_length + 1);
+
+ /* Read label. */
+ label_length = read_int (r);
+ label = xmalloc (label_length + 1);
+ read_string (r, label, label_length + 1);
+
+ printf ("\t\t%08llx: \"%s\" (%d bytes) => \"%s\" (%d bytes)\n",
+ posn, value, value_length, label, label_length);
+
+ free (value);
+ free (label);
+ }
+ }
+}
+
+static void
+hex_dump (size_t offset, const void *buffer_, size_t buffer_size)
+{
+ const uint8_t *buffer = buffer_;
+
+ while (buffer_size > 0)
+ {
+ size_t n = MIN (buffer_size, 16);
+ size_t i;
+
+ printf ("%04zx", offset);
+ for (i = 0; i < 16; i++)
+ {
+ if (i < n)
+ printf ("%c%02x", i == 8 ? '-' : ' ', buffer[i]);
+ else
+ printf (" ");
+ }
+
+ printf (" |");
+ for (i = 0; i < 16; i++)
+ {
+ unsigned char c = i < n ? buffer[i] : ' ';
+ putchar (isprint (c) ? c : '.');
+ }
+ printf ("|\n");
+
+ offset += n;
+ buffer += n;
+ buffer_size -= n;
+ }
+}
+
+/* Reads and prints any type 7 record that we don't understand. */
+static void
+read_unknown_extension (struct sfm_reader *r, size_t size, size_t count)
+{
+ unsigned char *buffer;
+ size_t i;
+
+ if (size == 0 || count > 65536 / size)
+ skip_bytes (r, size * count);
+ else if (size != 1)
+ {
+ buffer = xmalloc (size);
+ for (i = 0; i < count; i++)
+ {
+ read_bytes (r, buffer, size);
+ hex_dump (i * size, buffer, size);
+ }
+ free (buffer);
+ }
+ else
+ {
+ buffer = xmalloc (count);
+ read_bytes (r, buffer, count);
+ if (memchr (buffer, 0, count) == 0)
+ for (i = 0; i < count; i++)
+ {
+ unsigned char c = buffer[i];
+
+ if (c == '\\')
+ printf ("\\\\");
+ else if (c == '\n' || isprint (c))
+ putchar (c);
+ else
+ printf ("\\%02x", c);
+ }
+ else
+ hex_dump (0, buffer, count);
+ free (buffer);
+ }
+}
+