summaryrefslogtreecommitdiffstats
path: root/contrib/groff/troff/reg.cc
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/groff/troff/reg.cc')
-rw-r--r--contrib/groff/troff/reg.cc25
1 files changed, 20 insertions, 5 deletions
diff --git a/contrib/groff/troff/reg.cc b/contrib/groff/troff/reg.cc
index a9eec05..79e7806 100644
--- a/contrib/groff/troff/reg.cc
+++ b/contrib/groff/troff/reg.cc
@@ -66,15 +66,29 @@ general_reg::general_reg() : format('1'), width(0), inc(0)
{
}
+static char uppercase_array[] = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z',
+};
+
+static char lowercase_array[] = {
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
+ 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
+ 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+ 'y', 'z',
+};
+
static const char *number_value_to_ascii(int value, char format, int width)
{
static char buf[128]; // must be at least 21
switch(format) {
case '1':
if (width <= 0)
- return itoa(value);
+ return i_to_a(value);
else if (width > sizeof(buf) - 2)
- sprintf(buf, "%.*d", sizeof(buf) - 2, int(value));
+ sprintf(buf, "%.*d", int(sizeof(buf) - 2), int(value));
else
sprintf(buf, "%.*d", width, int(value));
break;
@@ -88,7 +102,7 @@ static const char *number_value_to_ascii(int value, char format, int width)
int n = int(value);
if (n >= 40000 || n <= -40000) {
error("magnitude of `%1' too big for i or I format", n);
- return itoa(n);
+ return i_to_a(n);
}
if (n == 0) {
*p++ = '0';
@@ -167,10 +181,11 @@ static const char *number_value_to_ascii(int value, char format, int width)
d = 26;
n -= d;
n /= 26;
- *p++ = format + d - 1;
+ *p++ = format == 'a' ? lowercase_array[d - 1] :
+ uppercase_array[d - 1];
}
*p-- = 0;
- char *q = buf[0] == '-' ? buf+1 : buf;
+ char *q = buf[0] == '-' ? buf + 1 : buf;
while (q < p) {
char temp = *q;
*q = *p;
OpenPOWER on IntegriCloud