summaryrefslogtreecommitdiffstats
path: root/mpi
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-04-22 19:55:21 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-04-22 19:55:21 -0700
commit790cbdccac0540d2af12438fc7bccef2e17bc124 (patch)
tree49d4da1ef7dc9b36d6f0816cde6ca290d9496d49 /mpi
parent150e147b77199684b32c327e4d3e2715fd2d7a0f (diff)
downloadtxr-790cbdccac0540d2af12438fc7bccef2e17bc124.tar.gz
txr-790cbdccac0540d2af12438fc7bccef2e17bc124.tar.bz2
txr-790cbdccac0540d2af12438fc7bccef2e17bc124.zip
eliminate-locale-dependencies patch
Eliminating dependencies on locale-dependent C functions. * mpi/mpi.c (s_mp_tovalue, s_mp_todigit): Avoid tolower, toupper, islower and isupper.
Diffstat (limited to 'mpi')
-rw-r--r--mpi/mpi.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index 61575abc..24df7c30 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -4693,17 +4693,22 @@ int s_mp_ispow2d(mp_digit d)
int s_mp_tovalue(int ch, int r)
{
int val, xch;
-
- if(r > 36)
- xch = ch;
+
+ /* For bases up to 36, the letters of the alphabet are
+ case-insensitive and denote digits valued 10 through 36.
+ For bases greater than 36, the lower case letters have
+ their own meaning and denote values past 36. */
+
+ if (r <= 36 && ch >= 'a' && ch <= 'z')
+ xch = ch - 'a' + 'A';
else
- xch = toupper(ch);
+ xch = ch;
- if(isdigit(xch))
+ if(xch >= '0' && xch <= '9')
val = xch - '0';
- else if(isupper(xch))
+ else if(xch >= 'A' && xch <= 'Z')
val = xch - 'A' + 10;
- else if(islower(xch))
+ else if(xch >= 'a' && xch <= 'z')
val = xch - 'a' + 36;
else if(xch == '+')
val = 62;
@@ -4741,8 +4746,8 @@ char s_mp_todigit(int val, int r, int low)
ch = s_dmap_1[val];
- if(r <= 36 && low)
- ch = tolower(ch);
+ if(low && val > 9 && r <= 36)
+ ch = ch - 'A' + 'a';
return ch;