Make dc(1) buildable.

This commit is contained in:
Jung-uk Kim 2018-09-19 07:08:27 +00:00
parent 9c40dcbe5f
commit ee4526c085
2 changed files with 20 additions and 18 deletions

View File

@ -594,7 +594,7 @@ set_scale(void)
warnx("scale must be a nonnegative number");
else {
scale = get_ulong(n);
if (scale != BN_MASK2 && scale <= UINT_MAX)
if (scale != ULONG_MAX && scale <= UINT_MAX)
bmachine.scale = (u_int)scale;
else
warnx("scale too large");
@ -622,7 +622,7 @@ set_obase(void)
n = pop_number();
if (n != NULL) {
base = get_ulong(n);
if (base != BN_MASK2 && base > 1 && base <= UINT_MAX)
if (base != ULONG_MAX && base > 1 && base <= UINT_MAX)
bmachine.obase = (u_int)base;
else
warnx("output base must be a number greater than 1");
@ -649,7 +649,7 @@ set_ibase(void)
n = pop_number();
if (n != NULL) {
base = get_ulong(n);
if (base != BN_MASK2 && 2 <= base && base <= 16)
if (base != ULONG_MAX && 2 <= base && base <= 16)
bmachine.ibase = (u_int)base;
else
warnx("input base must be a number between 2 and 16 "
@ -889,7 +889,7 @@ load_array(void)
idx = get_ulong(inumber);
if (BN_is_negative(inumber->number))
warnx("negative idx");
else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX)
else if (idx == ULONG_MAX || idx > MAX_ARRAY_INDEX)
warnx("idx too big");
else {
stack = &bmachine.reg[reg];
@ -929,7 +929,7 @@ store_array(void)
if (BN_is_negative(inumber->number)) {
warnx("negative idx");
stack_free_value(value);
} else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX) {
} else if (idx == ULONG_MAX || idx > MAX_ARRAY_INDEX) {
warnx("idx too big");
stack_free_value(value);
} else {
@ -1218,7 +1218,7 @@ bexp(void)
b = BN_get_word(p->number);
m = max(a->scale, bmachine.scale);
rscale = a->scale * (u_int)b;
if (rscale > m || (a->scale > 0 && (b == BN_MASK2 ||
if (rscale > m || (a->scale > 0 && (b == ULONG_MAX ||
b > UINT_MAX)))
rscale = m;
}
@ -1587,7 +1587,7 @@ quitN(void)
return;
i = get_ulong(n);
free_number(n);
if (i == BN_MASK2 || i == 0)
if (i == ULONG_MAX || i == 0)
warnx("Q command requires a number >= 1");
else if (bmachine.readsp < i)
warnx("Q command argument exceeded string execution depth");
@ -1609,7 +1609,7 @@ skipN(void)
if (n == NULL)
return;
i = get_ulong(n);
if (i == BN_MASK2)
if (i == ULONG_MAX)
warnx("J command requires a number >= 0");
else if (i > 0 && bmachine.readsp < i)
warnx("J command argument exceeded string execution depth");

View File

@ -362,19 +362,21 @@ printnumber(FILE *f, const struct number *b, u_int base)
stack_clear(&stack);
if (b->scale > 0) {
struct number *num_base;
BIGNUM mult, stop;
BIGNUM *mult, *stop;
putcharwrap(f, '.');
num_base = new_number();
bn_check(BN_set_word(num_base->number, base));
BN_init(&mult);
bn_check(BN_one(&mult));
BN_init(&stop);
bn_check(BN_one(&stop));
scale_number(&stop, b->scale);
mult = BN_new();
bn_checkp(mult);
bn_check(BN_one(mult));
stop = BN_new();
bn_checkp(stop);
bn_check(BN_one(stop));
scale_number(stop, b->scale);
i = 0;
while (BN_cmp(&mult, &stop) < 0) {
while (BN_cmp(mult, stop) < 0) {
u_long rem;
if (i && base > 16)
@ -392,11 +394,11 @@ printnumber(FILE *f, const struct number *b, u_int base)
int_part->number));
printwrap(f, p);
free(p);
bn_check(BN_mul_word(&mult, base));
bn_check(BN_mul_word(mult, base));
}
free_number(num_base);
BN_free(&mult);
BN_free(&stop);
BN_free(mult);
BN_free(stop);
}
flushwrap(f);
free_number(int_part);