mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2024-11-27 14:12:36 +00:00
better labelling in ast_function_labeling, this time the number is even printed forward rather than backward... ;)
This commit is contained in:
parent
2524d9c31b
commit
7fec608417
1 changed files with 11 additions and 28 deletions
39
ast.c
39
ast.c
|
@ -718,37 +718,20 @@ void ast_function_delete(ast_function *self)
|
||||||
mem_d(self);
|
mem_d(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ast_util_hexitoa(char *buf, size_t size, unsigned int num)
|
|
||||||
{
|
|
||||||
unsigned int base = 10;
|
|
||||||
#define checknul() do { if (size == 1) { *buf = 0; return; } } while (0)
|
|
||||||
#define addch(x) do { *buf++ = (x); --size; checknul(); } while (0)
|
|
||||||
if (size < 1)
|
|
||||||
return;
|
|
||||||
checknul();
|
|
||||||
if (!num)
|
|
||||||
addch('0');
|
|
||||||
else {
|
|
||||||
while (num)
|
|
||||||
{
|
|
||||||
int digit = num % base;
|
|
||||||
num /= base;
|
|
||||||
addch('0' + digit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*buf = 0;
|
|
||||||
#undef addch
|
|
||||||
#undef checknul
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* ast_function_label(ast_function *self, const char *prefix)
|
const char* ast_function_label(ast_function *self, const char *prefix)
|
||||||
{
|
{
|
||||||
size_t id = (self->labelcount++);
|
size_t id = (self->labelcount++);
|
||||||
size_t len = strlen(prefix);
|
size_t len = strlen(prefix);
|
||||||
strncpy(self->labelbuf, prefix, sizeof(self->labelbuf));
|
|
||||||
ast_util_hexitoa(self->labelbuf + len, sizeof(self->labelbuf)-len, id);
|
char *from = self->labelbuf + sizeof(self->labelbuf)-1;
|
||||||
return self->labelbuf;
|
*from-- = 0;
|
||||||
|
do {
|
||||||
|
unsigned int digit = id % 10;
|
||||||
|
*from = digit + '0';
|
||||||
|
id /= 10;
|
||||||
|
} while (id);
|
||||||
|
memcpy(from - len, prefix, len);
|
||||||
|
return from - len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
Loading…
Reference in a new issue