[gamecode] Use a flag for format width

This ensures caller specified width always gets through to libc's
printf, even if the caller specifies 0. More importantly, * works
correctly.
This commit is contained in:
Bill Currie 2021-09-25 13:24:48 +09:00
parent 0df16fb210
commit 2119688b48

View file

@ -51,6 +51,7 @@
#define FMT_ADDBLANK (1<<4)
#define FMT_HEX (1<<5)
#define FMT_LONG (1<<6)
#define FMT_WIDTH (1<<7)
typedef struct fmt_item_s {
byte type;
@ -748,7 +749,7 @@ I_DoPrint (dstring_t *tmp, dstring_t *result, fmt_item_t *formatting)
qboolean doPrecision, doWidth;
doPrecision = -1 != current->precision;
doWidth = 0 != current->minFieldWidth;
doWidth = 0 != (current->flags & FMT_WIDTH);
dsprintf (tmp, "%%%s%s%s%s%s%s%s",
(current->flags & FMT_ALTFORM) ? "#" : "", // hash
@ -956,6 +957,7 @@ fmt_state_flags (fmt_state_t *state)
static void
fmt_state_var_field_width (fmt_state_t *state)
{
(*state->fi)->flags |= FMT_WIDTH;
(*state->fi)->minFieldWidth = P_INT (pr, state->fmt_count);
state->fmt_count++;
if (*++state->c == '.') {
@ -968,6 +970,7 @@ fmt_state_var_field_width (fmt_state_t *state)
static void
fmt_state_field_width (fmt_state_t *state)
{
(*state->fi)->flags |= FMT_WIDTH;
while (isdigit ((byte )*state->c)) {
(*state->fi)->minFieldWidth *= 10;
(*state->fi)->minFieldWidth += *state->c++ - '0';