forked from github/server
support for itoab with smaller bases and larger numbers.
also a missing English message (museum-related)
This commit is contained in:
parent
8432a6369d
commit
3e829e2880
|
@ -177,7 +177,7 @@
|
|||
<text locale="en">Wall</text>
|
||||
</string>
|
||||
<string name="wall1_trail">
|
||||
<text locale="de">a solid wall</text>
|
||||
<text locale="en">a solid wall</text>
|
||||
</string>
|
||||
<string name="hall1_trail">
|
||||
<text locale="en">the %s</text>
|
||||
|
|
|
@ -69,7 +69,7 @@ arg_set(variant args[], const message_type * mtype, const char *buffer,
|
|||
if (i != mtype->nparameters) {
|
||||
args[i] = v;
|
||||
} else {
|
||||
fprintf(stderr, "invalid parameter %s for message type %s\n", buffer,
|
||||
log_error("invalid parameter %s for message type %s\n", buffer,
|
||||
mtype->name);
|
||||
assert(!"program aborted.");
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#include <platform.h>
|
||||
#include "base36.h"
|
||||
#include "log.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
@ -56,6 +57,7 @@ int atoi36(const char *str)
|
|||
|
||||
const char *itoab(int i, int base)
|
||||
{
|
||||
const int maxlen = 20;
|
||||
static char **as = NULL; // FIXME: static return value
|
||||
char *s, *dst;
|
||||
static int index = 0; /* STATIC_XCALL: used across calls */
|
||||
|
@ -63,35 +65,46 @@ const char *itoab(int i, int base)
|
|||
|
||||
if (!as) {
|
||||
int j;
|
||||
char *x = (char *)calloc(sizeof(char), 8 * 4); /* STATIC_LEAK: malloc in static variable */
|
||||
char *x = (char *)calloc(sizeof(char), maxlen * 4); /* STATIC_LEAK: malloc in static variable */
|
||||
as = (char **)calloc(sizeof(char *), 4);
|
||||
for (j = 0; j != 4; ++j)
|
||||
as[j] = x + j * 8;
|
||||
as[j] = x + j * maxlen;
|
||||
}
|
||||
s = as[index];
|
||||
index = (index + 1) & 3; /* quick for % 4 */
|
||||
dst = s + 7;
|
||||
dst = s + maxlen - 1;
|
||||
(*dst--) = 0;
|
||||
if (i != 0) {
|
||||
if (i < 0) {
|
||||
i = -i;
|
||||
neg = 1;
|
||||
}
|
||||
while (i) {
|
||||
while (i && dst>=s) {
|
||||
int x = i % base;
|
||||
i = i / base;
|
||||
if (x < 10)
|
||||
if (x < 10) {
|
||||
*(dst--) = (char)('0' + x);
|
||||
else if ('a' + x - 10 == 'l')
|
||||
}
|
||||
else if ('a' + x - 10 == 'l') {
|
||||
*(dst--) = 'L';
|
||||
else
|
||||
}
|
||||
else {
|
||||
*(dst--) = (char)('a' + (x - 10));
|
||||
}
|
||||
if (neg)
|
||||
}
|
||||
if (dst > s) {
|
||||
if (neg) {
|
||||
*(dst) = '-';
|
||||
else
|
||||
}
|
||||
else {
|
||||
++dst;
|
||||
}
|
||||
}
|
||||
else {
|
||||
log_error("static buffer exhauset, itoab(%d, %d)", i, base);
|
||||
assert(i == 0 || !"itoab: static buffer exhausted");
|
||||
}
|
||||
}
|
||||
else
|
||||
*dst = '0';
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ static void test_itoa36(CuTest * tc)
|
|||
{
|
||||
CuAssertStrEquals(tc, itoa36(0), "0");
|
||||
CuAssertStrEquals(tc, itoa10(INT_MAX), "2147483647");
|
||||
CuAssertStrEquals(tc, itoab(INT_MAX, 8), "17777777777");
|
||||
CuAssertStrEquals(tc, itoab(INT_MAX, 4), "1333333333333333");
|
||||
CuAssertStrEquals(tc, itoab(-1, 5), "-1");
|
||||
CuAssertStrEquals(tc, itoa36(-1), "-1");
|
||||
CuAssertStrEquals(tc, itoa36(-10), "-a");
|
||||
|
|
Loading…
Reference in New Issue