Make write/display output bytevectors with hex constants (issue #483)

This commit is contained in:
Marc Nieper-Wisskirchen 2018-11-06 14:22:38 +01:00
parent 3f9dfb7837
commit f9be5c8d46
2 changed files with 14 additions and 1 deletions

View file

@ -568,6 +568,11 @@
#define SEXP_USE_BYTEVECTOR_LITERALS ! SEXP_USE_NO_FEATURES
#endif
#ifndef SEXP_BYTEVECTOR_HEX_LITERALS
#define SEXP_BYTEVECTOR_HEX_LITERALS SEXP_USE_BYTEVECTOR_LITERALS
#endif
#ifndef SEXP_USE_SELF_PARAMETER
#define SEXP_USE_SELF_PARAMETER 1
#endif

8
sexp.c
View file

@ -1884,6 +1884,9 @@ sexp sexp_write_one (sexp ctx, sexp obj, sexp out) {
sexp_sint_t i=0;
#if SEXP_USE_FLONUMS
double f, ftmp;
#endif
#if SEXP_USE_BYTEVECTOR_LITERALS && SEXP_BYTEVECTOR_HEX_LITERALS
char buf[5];
#endif
sexp x, *elts;
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);
for (i=0; i<(sexp_sint_t)len; i++) {
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);
#endif
}
sexp_write_char(ctx, ')', out);
break;