mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 05:39:18 +02:00
Make write/display output bytevectors with hex constants (issue #483)
This commit is contained in:
parent
3f9dfb7837
commit
f9be5c8d46
2 changed files with 14 additions and 1 deletions
|
@ -568,6 +568,11 @@
|
||||||
#define SEXP_USE_BYTEVECTOR_LITERALS ! SEXP_USE_NO_FEATURES
|
#define SEXP_USE_BYTEVECTOR_LITERALS ! SEXP_USE_NO_FEATURES
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SEXP_BYTEVECTOR_HEX_LITERALS
|
||||||
|
#define SEXP_BYTEVECTOR_HEX_LITERALS SEXP_USE_BYTEVECTOR_LITERALS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef SEXP_USE_SELF_PARAMETER
|
#ifndef SEXP_USE_SELF_PARAMETER
|
||||||
#define SEXP_USE_SELF_PARAMETER 1
|
#define SEXP_USE_SELF_PARAMETER 1
|
||||||
#endif
|
#endif
|
||||||
|
|
8
sexp.c
8
sexp.c
|
@ -1884,6 +1884,9 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
|
||||||
sexp_sint_t i=0;
|
sexp_sint_t i=0;
|
||||||
#if SEXP_USE_FLONUMS
|
#if SEXP_USE_FLONUMS
|
||||||
double f, ftmp;
|
double f, ftmp;
|
||||||
|
#endif
|
||||||
|
#if SEXP_USE_BYTEVECTOR_LITERALS && SEXP_BYTEVECTOR_HEX_LITERALS
|
||||||
|
char buf[5];
|
||||||
#endif
|
#endif
|
||||||
sexp x, *elts;
|
sexp x, *elts;
|
||||||
char *str=NULL, numbuf[NUMBUF_LEN];
|
char *str=NULL, numbuf[NUMBUF_LEN];
|
||||||
|
@ -2065,7 +2068,12 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
|
||||||
len = sexp_bytes_length(obj);
|
len = sexp_bytes_length(obj);
|
||||||
for (i=0; i<(sexp_sint_t)len; i++) {
|
for (i=0; i<(sexp_sint_t)len; i++) {
|
||||||
if (i!=0) sexp_write_char(ctx, ' ', out);
|
if (i!=0) sexp_write_char(ctx, ' ', out);
|
||||||
|
#if SEXP_BYTEVECTOR_HEX_LITERALS
|
||||||
|
sprintf(buf, "#x%02hhX", ((unsigned char*) str)[i]);
|
||||||
|
sexp_write_string(ctx, buf, out);
|
||||||
|
#else
|
||||||
sexp_write(ctx, sexp_make_fixnum(((unsigned char*)str)[i]), out);
|
sexp_write(ctx, sexp_make_fixnum(((unsigned char*)str)[i]), out);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
sexp_write_char(ctx, ')', out);
|
sexp_write_char(ctx, ')', out);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue