From c10bff4da438d2785409636677223cec18347647 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 29 May 2017 19:41:54 -0700 Subject: [PATCH] Minor improvements. --- dump.c | 123 +++++++++++++++++++++++++------------------ spv-file-format.texi | 27 +++++----- 2 files changed, 85 insertions(+), 65 deletions(-) diff --git a/dump.c b/dump.c index 991dd366b4..3e30ce10f2 100644 --- a/dump.c +++ b/dump.c @@ -195,6 +195,15 @@ match_byte_assert(uint8_t b, const char *where) } #define match_byte_assert(b) match_byte_assert(b, WHERE) +static bool +get_bool(void) +{ + if (match_byte(0)) + return false; + match_byte_assert(1); + return true; +} + static void newline(FILE *stream, int pos) { @@ -357,26 +366,27 @@ hex_dump(int ofs, int n) static char * dump_counted_string(void) { - char *s = NULL; int inner_end = get_end(); + if (pos == inner_end) + return NULL; + + if (match_u32(5)) + { + match_u32_assert(0); + match_byte_assert(0x58); + } + else + match_u32_assert(0); + + char *s = NULL; + if (match_byte(0x31)) + s = get_string(); + else + match_byte_assert(0x58); if (pos != inner_end) { - if (match_u32(5)) - { - match_u32_assert(0); - match_byte_assert(0x58); - } - else - match_u32_assert(0); - if (match_byte(0x31)) - s = get_string(); - else - match_byte_assert(0x58); - if (pos != inner_end) - { - fprintf(stderr, "inner end discrepancy\n"); - exit(1); - } + fprintf(stderr, "inner end discrepancy\n"); + exit(1); } return s; } @@ -384,8 +394,18 @@ dump_counted_string(void) static void dump_style(FILE *stream) { - for (int i = 0; i < 4; i++) - printf (" %d", get_byte()); + if (match_byte(0x58)) + return; + + match_byte_assert(0x31); + if (get_bool()) + printf (" bold=\"yes\""); + if (get_bool()) + printf (" italic=\"yes\""); + if (get_bool()) + printf (" underline=\"yes\""); + if (!get_bool()) + printf (" show=\"no\""); char *fg = get_string(); /* foreground */ char *bg = get_string(); /* background */ char *font = get_string(); /* font */ @@ -394,6 +414,35 @@ dump_style(FILE *stream) fg, bg, font, size); } +static void +dump_style2(FILE *stream) +{ + if (match_byte(0x58)) + return; + + match_byte_assert(0x31); + uint32_t halign = get_u32(); + printf (" halign=\"%s\"", + halign == 0 ? "center" + : halign == 2 ? "left" + : halign == 4 ? "right" + : halign == 6 ? "decimal" + : halign == 0xffffffad ? "mixed" + : ""); + int valign = get_u32(); + printf (" valign=\"%s\"", + valign == 0 ? "center" + : valign == 1 ? "top" + : valign == 3 ? "bottom" + : ""); + printf (" offset=\"%gpt\"", get_double()); + int l = get_u16(); + int r = get_u16(); + int t = get_u16(); + int b = get_u16(); + printf (" margins=\"%d %d %d %d\"", l, r, t, b); +} + static char * dump_nested_string(FILE *stream) { @@ -405,10 +454,7 @@ dump_nested_string(FILE *stream) s = dump_counted_string(); if (s) fprintf(stream, " \"%s\"", s); - if (match_byte(0x31)) - dump_style(stream); - else - match_byte_assert(0x58); + dump_style(stream); match_byte_assert(0x58); if (pos != outer_end) { @@ -466,35 +512,8 @@ dump_value_modifier(FILE *stream) if (template) fprintf(stream, " template=\"%s\"", template); - if (match_byte(0x31)) - dump_style(stream); - else - match_byte_assert(0x58); - if (match_byte(0x31)) - { - uint32_t halign = get_u32(); - printf (" halign=\"%s\"", - halign == 0 ? "center" - : halign == 2 ? "left" - : halign == 4 ? "right" - : halign == 6 ? "decimal" - : halign == 0xffffffad ? "mixed" - : ""); - int valign = get_u32(); - printf (" valign=\"%s\"", - valign == 0 ? "center" - : valign == 1 ? "top" - : valign == 3 ? "bottom" - : ""); - printf (" %g", get_double()); - int l = get_u16(); - int r = get_u16(); - int t = get_u16(); - int b = get_u16(); - printf (" margins=\"%d %d %d %d\"", l, r, t, b); - } - else - match_byte_assert(0x58); + dump_style(stream); + dump_style2(stream); if (pos != outer_end) { fprintf(stderr, "outer end discrepancy\n"); diff --git a/spv-file-format.texi b/spv-file-format.texi index 09e620e9ae..6e7480ba12 100644 --- a/spv-file-format.texi +++ b/spv-file-format.texi @@ -1261,24 +1261,22 @@ A ValueMod can specify special modifications to a Value. ValueMod @result{} 31 i0 (i0 @math{|} i1 string[@t{subscript}]) v1(00 (i1 @math{|} i2) 00 00 int 00 00) - v3(count(FormatString Style ValueModUnknown)) + v3(count(FormatString + (31 Style | 58) + (31 Style2 | 58))) @math{|} 31 int[@t{n-refs}] int16*[@t{n-refs}] Format @math{|} 58 +Format @result{} 00 00 count(FormatString Style 58) +FormatString @result{} count((count((i0 58)?) (58 @math{|} 31 string))?) + Style @result{} - 58 - @math{|} 31 - bool[@t{bold}] bool[@t{italic}] bool[@t{underline}] bool + bool[@t{bold}] bool[@t{italic}] bool[@t{underline}] bool[@t{show}] string[@t{fgcolor}] string[@t{bgcolor}] string[@t{typeface}] byte[@t{size}] -Format @result{} 00 00 count(FormatString Style 58) - -FormatString @result{} count((i0 (58 @math{|} 31 string))?) - -ValueModUnknown @result{} - 58 - @math{|} 31 int[@t{halign}] int[@t{valign}] double[@t{offset}] +Style2 @result{} + int[@t{halign}] int[@t{valign}] double[@t{offset}] int16[@t{left-margin}] int16[@t{right-margin}] int16[@t{top-margin}] int16[@t{bottom-margin}] @end format @@ -1300,8 +1298,11 @@ syntax explained previously. It appears to be an English-language version of the localized format string in the Value in which the Format is nested. -The Style, if present, changes the style for this individual Value. -The @code{size} is a font size in units of 1/96 inch. +Style and Style2, if present, change the style for this individual +Value. @code{bold}, @code{italic}, and @code{underline} control the +particular style. @code{fgcolor} and @code{bgcolor} are strings, such +as @code{#ffffff}. The @code{size} is a font size in units of 1/96 +inch. @code{halign} is 0 for center, 2 for left, 4 for right, 6 for decimal, 0xffffffad for mixed. For decimal alignment, @code{offset} is the -- 2.30.2