#include <tfm_private.h>
int fp_read_radix(fp_int *a, const char *str, int radix)
{
int y, neg;
char ch;
fp_zero (a);
if (radix < 2 || radix > 64) {
return FP_VAL;
}
if (*str == '-') {
++str;
neg = FP_NEG;
} else {
neg = FP_ZPOS;
}
while (*str) {
ch = (char) ((radix <= 36) ? toupper ((int)*str) : *str);
for (y = 0; y < 64; y++) {
if (ch == fp_s_rmap[y]) {
break;
}
}
if (y < radix) {
fp_mul_d (a, (fp_digit) radix, a);
fp_add_d (a, (fp_digit) y, a);
} else {
break;
}
++str;
}
if (fp_iszero(a) != FP_YES) {
a->sign = neg;
}
return FP_OKAY;
}