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
4 changed files with 28 additions and 13 deletions
|
@ -177,7 +177,7 @@
|
||||||
<text locale="en">Wall</text>
|
<text locale="en">Wall</text>
|
||||||
</string>
|
</string>
|
||||||
<string name="wall1_trail">
|
<string name="wall1_trail">
|
||||||
<text locale="de">a solid wall</text>
|
<text locale="en">a solid wall</text>
|
||||||
</string>
|
</string>
|
||||||
<string name="hall1_trail">
|
<string name="hall1_trail">
|
||||||
<text locale="en">the %s</text>
|
<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) {
|
if (i != mtype->nparameters) {
|
||||||
args[i] = v;
|
args[i] = v;
|
||||||
} else {
|
} 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);
|
mtype->name);
|
||||||
assert(!"program aborted.");
|
assert(!"program aborted.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include "base36.h"
|
#include "base36.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -56,6 +57,7 @@ int atoi36(const char *str)
|
||||||
|
|
||||||
const char *itoab(int i, int base)
|
const char *itoab(int i, int base)
|
||||||
{
|
{
|
||||||
|
const int maxlen = 20;
|
||||||
static char **as = NULL; // FIXME: static return value
|
static char **as = NULL; // FIXME: static return value
|
||||||
char *s, *dst;
|
char *s, *dst;
|
||||||
static int index = 0; /* STATIC_XCALL: used across calls */
|
static int index = 0; /* STATIC_XCALL: used across calls */
|
||||||
|
@ -63,34 +65,45 @@ const char *itoab(int i, int base)
|
||||||
|
|
||||||
if (!as) {
|
if (!as) {
|
||||||
int j;
|
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);
|
as = (char **)calloc(sizeof(char *), 4);
|
||||||
for (j = 0; j != 4; ++j)
|
for (j = 0; j != 4; ++j)
|
||||||
as[j] = x + j * 8;
|
as[j] = x + j * maxlen;
|
||||||
}
|
}
|
||||||
s = as[index];
|
s = as[index];
|
||||||
index = (index + 1) & 3; /* quick for % 4 */
|
index = (index + 1) & 3; /* quick for % 4 */
|
||||||
dst = s + 7;
|
dst = s + maxlen - 1;
|
||||||
(*dst--) = 0;
|
(*dst--) = 0;
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
i = -i;
|
i = -i;
|
||||||
neg = 1;
|
neg = 1;
|
||||||
}
|
}
|
||||||
while (i) {
|
while (i && dst>=s) {
|
||||||
int x = i % base;
|
int x = i % base;
|
||||||
i = i / base;
|
i = i / base;
|
||||||
if (x < 10)
|
if (x < 10) {
|
||||||
*(dst--) = (char)('0' + x);
|
*(dst--) = (char)('0' + x);
|
||||||
else if ('a' + x - 10 == 'l')
|
}
|
||||||
|
else if ('a' + x - 10 == 'l') {
|
||||||
*(dst--) = 'L';
|
*(dst--) = 'L';
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
*(dst--) = (char)('a' + (x - 10));
|
*(dst--) = (char)('a' + (x - 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dst > s) {
|
||||||
|
if (neg) {
|
||||||
|
*(dst) = '-';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++dst;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_error("static buffer exhauset, itoab(%d, %d)", i, base);
|
||||||
|
assert(i == 0 || !"itoab: static buffer exhausted");
|
||||||
}
|
}
|
||||||
if (neg)
|
|
||||||
*(dst) = '-';
|
|
||||||
else
|
|
||||||
++dst;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
*dst = '0';
|
*dst = '0';
|
||||||
|
|
|
@ -17,6 +17,8 @@ static void test_itoa36(CuTest * tc)
|
||||||
{
|
{
|
||||||
CuAssertStrEquals(tc, itoa36(0), "0");
|
CuAssertStrEquals(tc, itoa36(0), "0");
|
||||||
CuAssertStrEquals(tc, itoa10(INT_MAX), "2147483647");
|
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, itoab(-1, 5), "-1");
|
||||||
CuAssertStrEquals(tc, itoa36(-1), "-1");
|
CuAssertStrEquals(tc, itoa36(-1), "-1");
|
||||||
CuAssertStrEquals(tc, itoa36(-10), "-a");
|
CuAssertStrEquals(tc, itoa36(-10), "-a");
|
||||||
|
|
Loading…
Reference in a new issue