+
+ /* The last chunk is an outer envelope that contains two inner envelopes.
+ The second inner envelope has some interesting data like the encoding and
+ the locale. */
+ int outer_end = get_end();
+ if (version == 3)
+ {
+ /* First inner envelope: byte*33 int[n] int*[n]. */
+ int inner_len = get_u32();
+ int inner_end = pos + inner_len;
+ int array_start = pos + 33;
+ match_byte_assert(0);
+ pos++; /* 0, 1, 10 seen. */
+ get_bool();
+
+ /* 0=en 1=de 2=es 3=it 5=ko 6=pl 8=zh-tw 10=pt_BR 11=fr */
+ printf("lang=%d ", get_byte());
+
+ printf ("variable_mode=%d\n", get_byte());
+ printf ("value_mode=%d\n", get_byte());
+ if (!match_u64(0))
+ match_u64_assert(UINT64_MAX);
+ match_u32_assert(0);
+ match_u32_assert(0);
+ match_u32_assert(0);
+ match_u32_assert(0);
+ match_byte_assert(0);
+ get_bool();
+ match_byte_assert(1);
+ pos = array_start;
+
+ assert(get_end() == inner_end);
+ printf("<heights>");
+ int n_heights = get_u32();
+ for (int i = 0; i < n_heights; i++)
+ {
+ if (i)
+ putchar(' ');
+ printf("%d", get_u32());
+ }
+ printf("</heights>\n");
+
+ int n_style_map = get_u32();
+ for (int i = 0; i < n_style_map; i++)
+ {
+ uint64_t cell = get_u64();
+ int style = get_u16();
+ printf("<style-map cell=\"%llu\" style=\"%d\"/>\n", cell, style);
+ }
+
+ int n_styles = get_u32();
+ for (int i = 0; i < n_styles; i++)
+ {
+ printf("<cell-style index=\"%d\"", i);
+ dump_style(stdout);
+ dump_style2(stdout);
+ printf("/>\n");
+ }
+
+ pos = get_end();
+ assert(pos == inner_end);
+
+ /* Second inner envelope. */
+ assert(get_end() == outer_end);
+
+ match_byte_assert(1);
+ match_byte_assert(0);
+ if (!match_byte(3) && !match_byte(4))
+ match_byte_assert(5);
+ match_byte_assert(0);
+ match_byte_assert(0);
+ match_byte_assert(0);
+
+ printf("<command>%s</command>\n", get_string());
+ printf("<command-local>%s</command-local>\n", get_string());
+ printf("<language>%s</language>\n", get_string());
+ printf("<charset>%s</charset>\n", get_string());
+ printf("<locale>%s</locale>\n", get_string());
+
+ get_bool();
+ get_bool();
+ get_bool();
+ get_bool();
+
+ printf("<epoch2>%d</epoch2>\n", get_u32());
+
+ if (match_byte('.'))
+ {
+ if (!match_byte(',') && !match_byte('\''))
+ match_byte_assert(' ');
+ }
+ else
+ {
+ match_byte_assert(',');
+ if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
+ match_byte_assert(0);
+ }
+
+ printf ("small: %g\n", get_double());
+
+ match_byte_assert(1);
+ if (outer_end - pos > 6)
+ {
+ /* There might be a pair of strings representing a dataset and
+ datafile name, or there might be a set of custom currency strings.
+ The custom currency strings start with a pair of integers, so we
+ can distinguish these from a string by checking for a null byte; a
+ small 32-bit integer will always contain a null and a text string
+ never will. */
+ int save_pos = pos;
+ int len = get_u32();
+ bool has_dataset = !memchr(&data[pos], '\0', len);
+ pos = save_pos;
+
+ if (has_dataset)
+ {
+ printf("<dataset>%s</dataset>\n", get_string());
+ printf("<datafile>%s</datafile>\n", get_string());
+
+ match_u32_assert(0);
+
+ time_t date = get_u32();
+ struct tm tm = *localtime(&date);
+ char s[128];
+ strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S %z", &tm);
+ printf("<date>%s</date>\n", s);
+
+ match_u32_assert(0);
+ }
+ }
+
+ if (match_u32(5))
+ {
+ for (int i = 0; i < 5; i++)
+ printf("<CC%c>%s</CC%c>\n", 'A' + i, get_string(), 'A' + i);
+ }
+ else
+ match_u32_assert(0);
+
+ match_byte_assert('.');
+ get_bool();
+
+ if (pos < outer_end)
+ {
+ get_u32();
+ match_u32_assert(0);
+ }
+ assert(pos == outer_end);
+
+ pos = outer_end;
+ }
+ else if (outer_end != pos)
+ {
+ pos += 14;
+ printf("<command>%s</command>\n", get_string());
+ printf("<command-local>%s</command-local>\n", get_string());
+ printf("<language>%s</command>\n", get_string());
+ printf("<charset>%s</charset>\n", get_string());
+ printf("<locale>%s</locale>\n", get_string());
+ get_bool();
+ match_byte_assert(0);
+ get_bool();
+ get_bool();
+
+ printf("<epoch2>%d</epoch2>\n", get_u32());
+ int decimal = data[pos];
+ int grouping = data[pos + 1];
+ if (match_byte('.'))
+ {
+ if (!match_byte(',') && !match_byte('\''))
+ match_byte_assert(' ');
+ }
+ else
+ {
+ match_byte_assert(',');
+ if (!match_byte('.') && !match_byte(' ') && !match_byte(','))
+ match_byte_assert(0);
+ }
+ printf("<format decimal=\"%c\"", decimal);
+ if (grouping)
+ printf(" grouping=\"%c\"", grouping);
+ printf("\"/>\n");
+ if (match_u32(5))
+ {
+ for (int i = 0; i < 5; i++)
+ printf("<CC%c>%s</CC%c>\n", 'A' + i, get_string(), 'A' + i);
+ }
+ else
+ match_u32_assert(0);
+
+ match_byte_assert('.');
+ get_bool();
+
+ assert(pos == outer_end);
+ pos = outer_end;
+ }