projects
/
u
/
mdw
/
catacomb
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Extend the textual format to bases up to 62 by distinguishing case.
[u/mdw/catacomb]
/
mptext.c
diff --git
a/mptext.c
b/mptext.c
index
f6bc2e3
..
c479d78
100644
(file)
--- a/
mptext.c
+++ b/
mptext.c
@@
-1,6
+1,6
@@
/* -*-c-*-
*
/* -*-c-*-
*
- * $Id: mptext.c,v 1.1
1 2001/06/16 23:42:17
mdw Exp $
+ * $Id: mptext.c,v 1.1
2 2002/01/13 19:51:18
mdw Exp $
*
* Textual representation of multiprecision numbers
*
*
* Textual representation of multiprecision numbers
*
@@
-30,6
+30,9
@@
/*----- Revision history --------------------------------------------------*
*
* $Log: mptext.c,v $
/*----- Revision history --------------------------------------------------*
*
* $Log: mptext.c,v $
+ * Revision 1.12 2002/01/13 19:51:18 mdw
+ * Extend the textual format to bases up to 62 by distinguishing case.
+ *
* Revision 1.11 2001/06/16 23:42:17 mdw
* Typesetting fixes.
*
* Revision 1.11 2001/06/16 23:42:17 mdw
* Typesetting fixes.
*
@@
-192,7
+195,7
@@
mp *mp_read(mp *m, int radix, const mptext_ops *ops, void *p)
/* --- If the radix is zero, look for leading zeros --- */
if (radix > 0) {
/* --- If the radix is zero, look for leading zeros --- */
if (radix > 0) {
- assert(((void)"ascii radix must be <=
36", radix <= 36
));
+ assert(((void)"ascii radix must be <=
62", radix <= 62
));
rd = radix;
r = -1;
} else if (radix < 0) {
rd = radix;
r = -1;
} else if (radix < 0) {
@@
-270,9
+273,12
@@
restart:
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
- ch = tolower(ch);
+ if (rd <= 36)
+ ch = tolower(ch);
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ x = ch - 'A' + 36;
else
break;
}
else
break;
}
@@
-364,9
+370,12
@@
restart:
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
if (ch >= '0' && ch <= '9')
x = ch - '0';
else {
- ch = tolower(ch);
+ if (rd <= 36)
+ ch = tolower(ch);
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
if (ch >= 'a' && ch <= 'z') /* ASCII dependent! */
x = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'Z')
+ x = ch - 'A' + 36;
else
break;
}
else
break;
}
@@
-519,8
+528,10
@@
static int simple(mpw n, int radix, unsigned z,
ch = x;
else if (x < 10)
ch = '0' + x;
ch = x;
else if (x < 10)
ch = '0' + x;
- else
+ else
if (x < 36) /* Ascii specific */
ch = 'a' + x - 10;
ch = 'a' + x - 10;
+ else
+ ch = 'A' + x - 36;
buf[--i] = ch;
if (z)
z--;
buf[--i] = ch;
if (z)
z--;
@@
-639,8
+650,10
@@
static int binary(mp *m, int bit, int radix, const mptext_ops *ops, void *p)
ch = x;
else if (x < 10)
ch = '0' + x;
ch = x;
else if (x < 10)
ch = '0' + x;
+ else if (x < 36)
+ ch = 'a' + x - 10; /* Ascii specific */
else
else
- ch = '
a' + x - 10
;
+ ch = '
A' + x - 36
;
*q++ = ch;
if (q >= buf + sizeof(buf)) {
if ((rc = ops->put(buf, sizeof(buf), p)) != 0)
*q++ = ch;
if (q >= buf + sizeof(buf)) {
if ((rc = ops->put(buf, sizeof(buf), p)) != 0)
@@
-655,8
+668,10
@@
static int binary(mp *m, int bit, int radix, const mptext_ops *ops, void *p)
ch = x;
else if (x < 10)
ch = '0' + x;
ch = x;
else if (x < 10)
ch = '0' + x;
+ else if (x < 36)
+ ch = 'a' + x - 10; /* Ascii specific */
else
else
- ch = '
a' + x - 10
;
+ ch = '
A' + x - 36
;
*q++ = ch;
rc = ops->put(buf, q - buf, p);
*q++ = ch;
rc = ops->put(buf, q - buf, p);
@@
-681,7
+696,7
@@
int mp_write(mp *m, int radix, const mptext_ops *ops, void *p)
/* --- Check the radix for sensibleness --- */
if (radix > 0)
/* --- Check the radix for sensibleness --- */
if (radix > 0)
- assert(((void)"ascii radix must be <=
36", radix <= 36
));
+ assert(((void)"ascii radix must be <=
62", radix <= 62
));
else if (radix < 0)
assert(((void)"binary radix must fit in a byte", -radix < UCHAR_MAX));
else
else if (radix < 0)
assert(((void)"binary radix must fit in a byte", -radix < UCHAR_MAX));
else