From 85176ef10a795dc2ab50aa9ca8a4e0849bf58f2a Mon Sep 17 00:00:00 2001 From: Rangi <35663410+Rangi42@users.noreply.github.com> Date: Fri, 29 Aug 2025 14:23:49 -0400 Subject: [PATCH] Fix `q` format spec (#1811) --- man/rgbasm.5 | 9 ++++++++- src/asm/format.cpp | 6 +++--- test/asm/invalid-format.asm | 2 +- test/asm/invalid-format.err | 4 +++- test/asm/invalid-format.out | 2 +- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/man/rgbasm.5 b/man/rgbasm.5 index bb4ee85b..a2ab7e83 100644 --- a/man/rgbasm.5 +++ b/man/rgbasm.5 @@ -196,12 +196,19 @@ If specified, pads right-aligned numbers with zeros instead of spaces. If specified, pads the value to this width, right-aligned with spaces by default. .It Ql Ta May be .Ql \&. -followed by one or more +followed by zero or more .Ql 0 \[en] .Ql 9 . If specified, prints this many fractional digits of a fixed-point number. Defaults to 5 digits, maximum 255 digits. +(A +.Ql \&. +followed by zero +.Ql 0 +\[en] +.Ql 9 +prints zero fractional digits.) .It Ql Ta May be .Ql q followed by one or more diff --git a/src/asm/format.cpp b/src/asm/format.cpp index ecea78f5..74223b0f 100644 --- a/src/asm/format.cpp +++ b/src/asm/format.cpp @@ -77,9 +77,9 @@ void FormatSpec::useCharacter(int c) { } return; - // width + // frac case '.': - if (state > FORMAT_WIDTH) { + if (state >= FORMAT_FRAC) { break; } state = FORMAT_FRAC; @@ -88,7 +88,7 @@ void FormatSpec::useCharacter(int c) { // prec case 'q': - if (state > FORMAT_PREC) { + if (state >= FORMAT_PREC) { break; } state = FORMAT_PREC; diff --git a/test/asm/invalid-format.asm b/test/asm/invalid-format.asm index 98f31c34..335879ee 100644 --- a/test/asm/invalid-format.asm +++ b/test/asm/invalid-format.asm @@ -2,7 +2,7 @@ println STRFMT("%+d %++d", 42, 42) println STRFMT("%#x %##x", 42, 42) println STRFMT("%-4d %--4d", 42, 42) println STRFMT("%.f %..f", 42.0, 42.0) -println STRFMT("%qf %q.16f", 42.0, 42.0) +println STRFMT("%qf %q.16f %qq16f", 42.0, 42.0, 42.0) DEF N = 42 println "{5d:N} {5d5:N}" diff --git a/test/asm/invalid-format.err b/test/asm/invalid-format.err index d2efb4f6..3a63fb62 100644 --- a/test/asm/invalid-format.err +++ b/test/asm/invalid-format.err @@ -10,6 +10,8 @@ error: Fixed-point constant precision 0 invalid, defaulting to 16 at invalid-format.asm(5) error: STRFMT: Invalid format spec for argument 2 at invalid-format.asm(5) +error: STRFMT: Invalid format spec for argument 3 + at invalid-format.asm(5) error: Invalid format spec "5d5" at invalid-format.asm(8) error: Invalid format spec "xx" @@ -28,4 +30,4 @@ error: Formatting type 'd' with fractional width at invalid-format.asm(17) error: Formatting type 'd' with fractional precision at invalid-format.asm(18) -Assembly aborted with 15 errors! +Assembly aborted with 16 errors! diff --git a/test/asm/invalid-format.out b/test/asm/invalid-format.out index 8ab38603..005108f7 100644 --- a/test/asm/invalid-format.out +++ b/test/asm/invalid-format.out @@ -2,7 +2,7 @@ $2a %x 42 %4d 42 %f -42.00000 %16f +42.00000 %16f %16f 42 42 2a 2a hello