SCP: Add formatting support for signed t_value (t_svalue).

PV_LEFTSIGN - left justified signed value
PV_RCOMMASIGN - right, space filled, Comma separated every 3 treat as signed
This commit is contained in:
Mark Pizzolato 2018-04-30 21:35:20 -07:00
parent f2f4bfa8fb
commit b4ca9174fd
2 changed files with 14 additions and 0 deletions

12
scp.c
View file

@ -9782,9 +9782,15 @@ t_stat sprint_val (char *buffer, t_value val, uint32 radix,
{
#define MAX_WIDTH ((int) ((CHAR_BIT * sizeof (t_value) * 4 + 3)/3))
t_value owtest, wtest;
t_bool negative = FALSE;
int32 d, digit, ndigits, commas = 0;
char dbuf[MAX_WIDTH + 1];
if (((format == PV_LEFTSIGN) || (format == PV_RCOMMASIGN)) &&
(0 > (t_svalue)val)) {
val = (t_value)(-((t_svalue)val));
negative = TRUE;
}
for (d = 0; d < MAX_WIDTH; d++)
dbuf[d] = (format == PV_RZRO)? '0': ' ';
dbuf[MAX_WIDTH] = 0;
@ -9795,11 +9801,15 @@ do {
val = val / radix;
dbuf[d] = (char)((digit <= 9)? '0' + digit: 'A' + (digit - 10));
} while ((d > 0) && (val != 0));
if (negative && (format == PV_LEFTSIGN))
dbuf[--d] = '-';
switch (format) {
case PV_LEFT:
case PV_LEFTSIGN:
break;
case PV_RCOMMA:
case PV_RCOMMASIGN:
for (digit = 0; digit < MAX_WIDTH; digit++)
if (dbuf[digit] != ' ')
break;
@ -9810,6 +9820,8 @@ switch (format) {
for (digit=1; digit<=commas; digit++)
dbuf[MAX_WIDTH - (digit * 4)] = ',';
d = d - commas;
if (negative && (format == PV_RCOMMASIGN))
dbuf[--d] = '-';
if (width > MAX_WIDTH) {
if (!buffer)
return width;

View file

@ -418,6 +418,8 @@ typedef uint32 t_addr;
#define PV_RSPC 1 /* right, space fill */
#define PV_RCOMMA 2 /* right, space fill. Comma separate every 3 */
#define PV_LEFT 3 /* left justify */
#define PV_RCOMMASIGN 6 /* right, space fill. Comma separate every 3 treat as signed */
#define PV_LEFTSIGN 7 /* left justify treat as signed */
/* Default timing parameters */