From fb2877deb18d583791c1d10d43a26822eb2574f7 Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 28 Mar 2022 15:20:44 -0400 Subject: modernize bigxcan() --- big.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/big.c b/big.c index bb72224..642f4b2 100644 --- a/big.c +++ b/big.c @@ -764,23 +764,30 @@ word bigscan(char *p) /* code to handle (unsigned) exponent commented out */ -word bigxscan(p, q) /* read unsigned hex number in '\0'-terminated string p to q */ - /* assumes redundant leading zeros removed */ -char *p, *q; +/* read unsigned hex number in '\0'-terminated string p to q */ +/* assumes redundant leading zeros removed */ +word bigxscan(char *p, char *q) { + if (*p == '0' && !p[1]) { + return make(INT, 0, 0); + } + word r; /* will hold result */ word *x = &r; - if (*p == '0' && !p[1]) - return make(INT, 0, 0); + while (q > p) { unsigned long long hold; q = q - p < 15 ? p : q - 15; /* read upto 15 hex digits from small end */ sscanf(q, "%llx", &hold); *q = '\0'; word count = 4; /* 15 hex digits => 4 bignum digits */ - while (count-- && !(hold == 0 && q == p)) - *x = make(INT, hold & MAXDIGIT, 0), hold >>= DIGITWIDTH, x = &rest(*x); + while (count-- && !(hold == 0 && q == p)) { + *x = make(INT, hold & MAXDIGIT, 0); + hold >>= DIGITWIDTH; + x = &rest(*x); + } } + return r; } -- cgit v1.2.1