mirror of
https://gitlab.com/embeddable-common-lisp/ecl.git
synced 2026-01-15 05:43:19 -08:00
Avoid using snprintf
This commit is contained in:
parent
499ba269ec
commit
b2a8389730
3 changed files with 35 additions and 22 deletions
|
|
@ -465,9 +465,22 @@ cl_char_name(cl_object c)
|
|||
ecl_character code = ecl_char_code(c);
|
||||
cl_object output;
|
||||
if (code > 127) {
|
||||
char name[20]; /* cleanup */
|
||||
sprintf(name, "U%04x", code);
|
||||
output = make_base_string_copy(name);
|
||||
char name[7];
|
||||
char *start;
|
||||
name[7] = 0;
|
||||
name[6] = ecl_digit_char(code & 0xF, 16); code >>= 4;
|
||||
name[5] = ecl_digit_char(code & 0xF, 16); code >>= 4;
|
||||
name[4] = ecl_digit_char(code & 0xF, 16); code >>= 4;
|
||||
name[3] = ecl_digit_char(code & 0xF, 16); code >>= 4;
|
||||
if (code == 0) {
|
||||
start = name + 2;
|
||||
} else {
|
||||
name[2] = ecl_digit_char(code & 0xF, 16); code >>= 4;
|
||||
name[1] = ecl_digit_char(code & 0xF, 16);
|
||||
start = name;
|
||||
}
|
||||
start[0] = 'U';
|
||||
output = make_base_string_copy(start);
|
||||
} else {
|
||||
output = ecl_gethash_safe(MAKE_FIXNUM(code), cl_core.char_names, Cnil);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,12 @@ is_all_FF(void *ptr, int size) {
|
|||
static void
|
||||
write_sse_float(float v, cl_object stream)
|
||||
{
|
||||
if (is_all_FF(&v, sizeof(float)))
|
||||
if (is_all_FF(&v, sizeof(float))) {
|
||||
writestr_stream(" TRUE", stream);
|
||||
else {
|
||||
char buf[60];
|
||||
sprintf(buf, " %g", v);
|
||||
writestr_stream(buf, stream);
|
||||
} else {
|
||||
ecl_def_ct_single_float(wrapped_f, v, ,);
|
||||
ecl_write_char(' ', stream);
|
||||
si_write_ugly_object(wrapped_f, stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -46,9 +46,9 @@ write_sse_double(double v, cl_object stream)
|
|||
if (is_all_FF(&v, sizeof(double)))
|
||||
writestr_stream(" TRUE", stream);
|
||||
else {
|
||||
char buf[60];
|
||||
sprintf(buf, " %lg", v);
|
||||
writestr_stream(buf, stream);
|
||||
ecl_def_ct_double_float(wrapped_f, v, ,);
|
||||
ecl_write_char(' ', stream);
|
||||
si_write_ugly_object(wrapped_f, stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,14 +74,20 @@ write_sse_pack(cl_object x, cl_object stream)
|
|||
write_sse_double(x->sse.data.df[0], stream);
|
||||
write_sse_double(x->sse.data.df[1], stream);
|
||||
break;
|
||||
default:
|
||||
default: {
|
||||
cl_object buffer = si_get_buffer_string();
|
||||
for (i = 0; i < 16; i++) {
|
||||
char buf[10];
|
||||
int pad = 1 + (i%4 == 0);
|
||||
sprintf(buf, "%*c%02x", pad, ' ', x->sse.data.b8[i]);
|
||||
writestr_stream(buf, stream);
|
||||
ecl_string_push_extend(' ', buffer);
|
||||
if (i%4 == 0) ecl_string_push_extend(' ', buffer);
|
||||
si_integer_to_string(buffer, MAKE_FIXNUM(x->sse.data.b8[i]),
|
||||
MAKE_FIXNUM(16), Cnil, Cnil);
|
||||
}
|
||||
break;
|
||||
si_do_write_sequence(buffer, stream, MAKE_FIXNUM(0), Cnil);
|
||||
si_put_buffer_string(buffer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -127,15 +127,9 @@ write_character(cl_object x, cl_object stream)
|
|||
ecl_write_char(i, stream);
|
||||
} else {
|
||||
writestr_stream("#\\", stream);
|
||||
if (i < 32 || i == 127) {
|
||||
if (i < 32 || i >= 127) {
|
||||
cl_object name = cl_char_name(CODE_CHAR(i));
|
||||
writestr_stream((char*)name->base_string.self, stream);
|
||||
} else if (i >= 128) {
|
||||
int index = 0;
|
||||
char name[20];
|
||||
sprintf(name, "U%04x", i); /* cleanup */
|
||||
while(name[index])
|
||||
ecl_write_char(name[index++], stream);
|
||||
} else {
|
||||
ecl_write_char(i, stream);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue